From 97cd7ca0221735c39efb5258926f77f504ad0bbc Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 18 May 2012 19:30:19 +0200 Subject: [PATCH] Hook for passing env pointer to main function The new 'genode_envp' variable declared in '_main.cc' allows libc plugins to supplying custom environment pointers to the main function. This is needed by 3rd-party software such as GNU make, which expects the environment pointer as third argument of the main function. --- base/src/platform/_main.cc | 5 +++-- ports/src/lib/libc_noux/plugin.cc | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/base/src/platform/_main.cc b/base/src/platform/_main.cc index 94014037a..6149242e1 100644 --- a/base/src/platform/_main.cc +++ b/base/src/platform/_main.cc @@ -31,7 +31,7 @@ using namespace Genode; -extern int main(int argc, char **argv); +extern int main(int argc, char **argv, char **envp); extern void init_exception_handling(); /* implemented in base/cxx */ enum { ATEXIT_SIZE = 256 }; @@ -212,6 +212,7 @@ static char *argv[1] = { argv0 }; */ char **genode_argv = argv; int genode_argc = 1; +char **genode_envp = 0; /** @@ -250,7 +251,7 @@ extern "C" int _main() /* now, it is save to call printf */ /* call real main function */ - int ret = main(genode_argc, genode_argv); + int ret = main(genode_argc, genode_argv, genode_envp); genode_exit(ret); diff --git a/ports/src/lib/libc_noux/plugin.cc b/ports/src/lib/libc_noux/plugin.cc index 3020e65b3..ab051d763 100644 --- a/ports/src/lib/libc_noux/plugin.cc +++ b/ports/src/lib/libc_noux/plugin.cc @@ -1025,6 +1025,7 @@ namespace { /* external symbols provided by Genode's startup code */ extern char **genode_argv; extern int genode_argc; +extern char **genode_envp; /* pointer to environment, provided by libc */ extern char **environ; @@ -1108,6 +1109,9 @@ void init_libc_noux(void) /* register list of environment variables at libc 'environ' pointer */ environ = env_array; + /* define env pointer to be passed to main function (in '_main.cc') */ + genode_envp = environ; + /* initialize noux libc plugin */ static Plugin noux_plugin; }