Use secure_getenv for GOMP_DEBUG
2017-06-27 Tom de Vries <tom@codesourcery.com> * env.c (parse_unsigned_long_1): Factor out of ... (parse_unsigned_long): ... here. (parse_int_1): Factor out of ... (parse_int): ... here. (parse_int_secure): New function. (initialize_env): Use parse_int_secure for GOMP_DEBUG. * secure_getenv.h: Factor out of ... * plugin/plugin-hsa.c: ... here. * testsuite/libgomp.oacc-c-c++-common/gomp-debug-env.c: New test. From-SVN: r249694
This commit is contained in:
parent
5fee5eca5f
commit
22f1a03704
5 changed files with 125 additions and 34 deletions
|
@ -1,3 +1,15 @@
|
|||
2017-06-27 Tom de Vries <tom@codesourcery.com>
|
||||
|
||||
* env.c (parse_unsigned_long_1): Factor out of ...
|
||||
(parse_unsigned_long): ... here.
|
||||
(parse_int_1): Factor out of ...
|
||||
(parse_int): ... here.
|
||||
(parse_int_secure): New function.
|
||||
(initialize_env): Use parse_int_secure for GOMP_DEBUG.
|
||||
* secure_getenv.h: Factor out of ...
|
||||
* plugin/plugin-hsa.c: ... here.
|
||||
* testsuite/libgomp.oacc-c-c++-common/gomp-debug-env.c: New test.
|
||||
|
||||
2017-06-21 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR c++/81130
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
/* This file defines the OpenMP internal control variables and arranges
|
||||
for them to be initialized from environment variables at startup. */
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "libgomp.h"
|
||||
#include "gomp-constants.h"
|
||||
#include <limits.h>
|
||||
|
@ -58,6 +59,8 @@
|
|||
#endif
|
||||
#endif /* LIBGOMP_OFFLOADED_ONLY */
|
||||
|
||||
#include "secure_getenv.h"
|
||||
|
||||
struct gomp_task_icv gomp_global_icv = {
|
||||
.nthreads_var = 1,
|
||||
.thread_limit_var = UINT_MAX,
|
||||
|
@ -171,15 +174,17 @@ parse_schedule (void)
|
|||
}
|
||||
|
||||
/* Parse an unsigned long environment variable. Return true if one was
|
||||
present and it was successfully parsed. */
|
||||
present and it was successfully parsed. If SECURE, use secure_getenv to the
|
||||
environment variable. */
|
||||
|
||||
static bool
|
||||
parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
|
||||
parse_unsigned_long_1 (const char *name, unsigned long *pvalue, bool allow_zero,
|
||||
bool secure)
|
||||
{
|
||||
char *env, *end;
|
||||
unsigned long value;
|
||||
|
||||
env = getenv (name);
|
||||
env = (secure ? secure_getenv (name) : getenv (name));
|
||||
if (env == NULL)
|
||||
return false;
|
||||
|
||||
|
@ -206,14 +211,23 @@ parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Parse a positive int environment variable. Return true if one was
|
||||
present and it was successfully parsed. */
|
||||
/* As parse_unsigned_long_1, but always use getenv. */
|
||||
|
||||
static bool
|
||||
parse_int (const char *name, int *pvalue, bool allow_zero)
|
||||
parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
|
||||
{
|
||||
return parse_unsigned_long_1 (name, pvalue, allow_zero, false);
|
||||
}
|
||||
|
||||
/* Parse a positive int environment variable. Return true if one was
|
||||
present and it was successfully parsed. If SECURE, use secure_getenv to the
|
||||
environment variable. */
|
||||
|
||||
static bool
|
||||
parse_int_1 (const char *name, int *pvalue, bool allow_zero, bool secure)
|
||||
{
|
||||
unsigned long value;
|
||||
if (!parse_unsigned_long (name, &value, allow_zero))
|
||||
if (!parse_unsigned_long_1 (name, &value, allow_zero, secure))
|
||||
return false;
|
||||
if (value > INT_MAX)
|
||||
{
|
||||
|
@ -224,6 +238,22 @@ parse_int (const char *name, int *pvalue, bool allow_zero)
|
|||
return true;
|
||||
}
|
||||
|
||||
/* As parse_int_1, but use getenv. */
|
||||
|
||||
static bool
|
||||
parse_int (const char *name, int *pvalue, bool allow_zero)
|
||||
{
|
||||
return parse_int_1 (name, pvalue, allow_zero, false);
|
||||
}
|
||||
|
||||
/* As parse_int_1, but use getenv_secure. */
|
||||
|
||||
static bool
|
||||
parse_int_secure (const char *name, int *pvalue, bool allow_zero)
|
||||
{
|
||||
return parse_int_1 (name, pvalue, allow_zero, true);
|
||||
}
|
||||
|
||||
/* Parse an unsigned long list environment variable. Return true if one was
|
||||
present and it was successfully parsed. */
|
||||
|
||||
|
@ -1207,7 +1237,7 @@ initialize_env (void)
|
|||
gomp_global_icv.thread_limit_var
|
||||
= thread_limit_var > INT_MAX ? UINT_MAX : thread_limit_var;
|
||||
}
|
||||
parse_int ("GOMP_DEBUG", &gomp_debug_var, true);
|
||||
parse_int_secure ("GOMP_DEBUG", &gomp_debug_var, true);
|
||||
#ifndef HAVE_SYNC_BUILTINS
|
||||
gomp_mutex_init (&gomp_managed_threads_lock);
|
||||
#endif
|
||||
|
|
|
@ -39,32 +39,7 @@
|
|||
#include <dlfcn.h>
|
||||
#include "libgomp-plugin.h"
|
||||
#include "gomp-constants.h"
|
||||
|
||||
/* Secure getenv() which returns NULL if running as SUID/SGID. */
|
||||
#ifndef HAVE_SECURE_GETENV
|
||||
#ifdef HAVE___SECURE_GETENV
|
||||
#define secure_getenv __secure_getenv
|
||||
#elif defined (HAVE_UNISTD_H) && defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
|
||||
&& defined(HAVE_GETGID) && defined(HAVE_GETEGID)
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/* Implementation of secure_getenv() for targets where it is not provided but
|
||||
we have at least means to test real and effective IDs. */
|
||||
|
||||
static char *
|
||||
secure_getenv (const char *name)
|
||||
{
|
||||
if ((getuid () == geteuid ()) && (getgid () == getegid ()))
|
||||
return getenv (name);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
#define secure_getenv getenv
|
||||
#endif
|
||||
#endif
|
||||
#include "secure-getenv.h"
|
||||
|
||||
/* As an HSA runtime is dlopened, following structure defines function
|
||||
pointers utilized by the HSA plug-in. */
|
||||
|
|
61
libgomp/secure_getenv.h
Normal file
61
libgomp/secure_getenv.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GCC.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
GCC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
Under Section 7 of GPL version 3, you are granted additional
|
||||
permissions described in the GCC Runtime Library Exception, version
|
||||
3.1, as published by the Free Software Foundation.
|
||||
|
||||
You should have received a copy of the GNU General Public License and
|
||||
a copy of the GCC Runtime Library Exception along with this program;
|
||||
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _SECURE_GETENV_H
|
||||
#define _SECURE_GETENV_H 1
|
||||
|
||||
/* Secure getenv() which returns NULL if running as SUID/SGID. */
|
||||
#ifndef HAVE_SECURE_GETENV
|
||||
#if defined (HAVE_UNISTD_H) && defined (HAVE_GETUID) \
|
||||
&& defined (HAVE_GETEUID) && defined (HAVE_GETGID) \
|
||||
&& defined (HAVE_GETEGID)
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#if SUPPORTS_WEAKREF && defined (HAVE___SECURE_GETENV)
|
||||
static char* weak_secure_getenv (const char*)
|
||||
__attribute__((__weakref__("__secure_getenv")));
|
||||
#endif
|
||||
|
||||
/* Implementation of secure_getenv() for targets where it is not provided but
|
||||
we have at least means to test real and effective IDs. */
|
||||
|
||||
static inline char *
|
||||
secure_getenv (const char *name)
|
||||
{
|
||||
#if SUPPORTS_WEAKREF && defined (HAVE___SECURE_GETENV)
|
||||
if (weak_secure_getenv)
|
||||
return weak_secure_getenv (name);
|
||||
#endif
|
||||
|
||||
if ((getuid () == geteuid ()) && (getgid () == getegid ()))
|
||||
return getenv (name);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
#define secure_getenv getenv
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _SECURE_GETENV_H. */
|
13
libgomp/testsuite/libgomp.oacc-c-c++-common/gomp-debug-env.c
Normal file
13
libgomp/testsuite/libgomp.oacc-c-c++-common/gomp-debug-env.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* { dg-do run } */
|
||||
/* { dg-set-target-env-var GOMP_DEBUG "1" } */
|
||||
|
||||
/* Check that GOMP_DEBUG=1 triggers some output. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
#pragma acc parallel
|
||||
;
|
||||
}
|
||||
|
||||
/* { dg-output "GOACC_parallel_keyed" } */
|
Loading…
Add table
Reference in a new issue