public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Use VxWorks 7 APIs for accessing environment variables in kernel mode
@ 2020-10-21  7:23 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-10-21  7:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: Patrick Bernardi

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]

VxWorks 7 provides newer APIs for kernel mode for accessing environment
variables that lead to smaller and more efficient code.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* env.c (__gnat_setenv): call setenv for VxWorks 7 kernel mode.
	(__gnat_environ): envGet takes an int instead of a NULL pointer.
	(__gnat_unsetenv): call unsetenv for VxWorks 7 kernel mode.
	(__gnat_clearenv): use __gnat_unsetenv to clear environment
	variables.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 3595 bytes --]

diff --git a/gcc/ada/env.c b/gcc/ada/env.c
--- a/gcc/ada/env.c
+++ b/gcc/ada/env.c
@@ -99,7 +99,8 @@ __gnat_getenv (char *name, int *len, char **value)
 void
 __gnat_setenv (char *name, char *value)
 {
-#if (defined (__vxworks) && defined (__RTP__)) || defined (__APPLE__)
+#if (defined (__vxworks) && (defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7)) \
+    || defined (__APPLE__)
   setenv (name, value, 1);
 
 #else
@@ -110,9 +111,9 @@ __gnat_setenv (char *name, char *value)
 
   sprintf (expression, "%s=%s", name, value);
   putenv (expression);
-#if defined (__MINGW32__) || (defined (__vxworks) && ! defined (__RTP__))
-  /* On some systems like MacOS X and Windows, putenv is making a copy of the
-     expression string so we can free it after the call to putenv */
+#if defined (__MINGW32__) || defined (__vxworks)
+  /* putenv for Windows and VxWorks 6 kernel modules makes a copy of the
+     expression string, so we need to free it after the call to putenv. */
   free (expression);
 #endif
 #endif
@@ -138,8 +139,13 @@ __gnat_environ (void)
   #if defined (__RTP__) || defined (VTHREADS)
     return environ;
   #else
-    /* Kernel mode */
-    return envGet (NULL);
+    /* For VxWorks kernel modules use envGet to get the task's environment
+       (either the task's private environment if it has one or the global
+       environment otherwise). taskId parameter of 0 refers to the current
+       task (the VxWorks documentation says to use NULL but the compiler
+       complains that taskId is an int rather than a pointer. Internally,
+       VxWorks uses 0 as well). */
+    return envGet (0);
   #endif
 #endif
 }
@@ -147,7 +153,8 @@ __gnat_environ (void)
 void __gnat_unsetenv (char *name)
 {
 #if defined (__hpux__) || defined (__sun__) \
-     || (defined (__vxworks) && ! defined (__RTP__)) \
+     || (defined (__vxworks) && ! defined (__RTP__) \
+          && _WRS_VXWORKS_MAJOR <= 6) \
      || defined (_AIX) || defined (__Lynx__)
 
   /* On Solaris and HP-UX there is no function to clear an environment
@@ -170,7 +177,7 @@ void __gnat_unsetenv (char *name)
      if (strlen (env[index]) > size) {
        if (strstr (env[index], name) == env[index] &&
 	   env[index][size] == '=') {
-#if defined (__vxworks) && ! defined (__RTP__)
+#if defined (__vxworks)
          /* on Vxworks we are sure that the string has been allocated using
             malloc */
          free (env[index]);
@@ -203,9 +210,10 @@ void __gnat_unsetenv (char *name)
 void __gnat_clearenv (void)
 {
 #if defined (__sun__) \
-  || (defined (__vxworks) && ! defined (__RTP__)) || defined (__Lynx__) \
+  || (defined (__vxworks) && !defined (__RTP__) && _WRS_VXWORKS_MAJOR <= 6) \
+  || defined (__Lynx__) \
   || defined (__PikeOS__)
-  /* On Solaris, VxWorks (not RTPs), and Lynx there is no system
+  /* On Solaris, VxWorks kernel pre 7, and Lynx there is no system
      call to unset a variable or to clear the environment so set all
      the entries in the environ table to NULL (see comment in
      __gnat_unsetenv for more explanation). */
@@ -217,7 +225,8 @@ void __gnat_clearenv (void)
     index++;
   }
 #elif defined (__MINGW32__) || defined (__FreeBSD__) || defined (__APPLE__) \
-   || (defined (__vxworks) && defined (__RTP__)) || defined (__CYGWIN__) \
+   || (defined (__vxworks) && defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7) \
+   || defined (__CYGWIN__) \
    || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__rtems__) \
    || defined (__DragonFly__) || defined (__DJGPP__)
   /* On Windows, FreeBSD and MacOS there is no function to clean all the



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-21  7:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21  7:23 [Ada] Use VxWorks 7 APIs for accessing environment variables in kernel mode Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).