From d7ef0f73170a1b40741767aa3c75fcaebf013e95 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 26 May 2005 22:19:19 +0000 Subject: This commit breaks the entire world (yet again). Calculate the position of envp in C code based on argv and argp. No need to caclulate that in asm for N arches. This way, we better match what glibc does. All arches will need to be fixed to match up with this change. --- libc/misc/internals/__uClibc_main.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c index 63302c3a2..69a03d345 100644 --- a/libc/misc/internals/__uClibc_main.c +++ b/libc/misc/internals/__uClibc_main.c @@ -164,11 +164,9 @@ void attribute_hidden (*__rtld_fini)(void) = NULL; * are initialized, just before we call the application's main function. */ void __attribute__ ((__noreturn__)) -__uClibc_start_main(int (*main)(int argc, char **argv, char **envp), - int argc, char **argv, char **envp, - void (*app_init)(void), void (*app_fini)(void), - void (*rtld_fini)(void), - void *stack_end) +__uClibc_start_main(int (*main)(int, char **, char **), int argc, + char **argv, void (*app_init)(void), void (*app_fini)(void), + void (*rtld_fini)(void), void *stack_end) { #ifdef __ARCH_HAS_MMU__ unsigned long *aux_dat; @@ -182,15 +180,19 @@ __uClibc_start_main(int (*main)(int argc, char **argv, char **envp), __rtld_fini = rtld_fini; - /* If we are dynamically linked, then ldso already did this for us. */ - if (__environ==NULL) { - /* Statically linked. */ - __environ = envp; + /* The environment begins right after argv. */ + __environ = &argv[argc + 1]; + + /* If the first thing after argv is the arguments + * the the environment is empty. */ + if ((char *) __environ == *argv) { + /* Make __environ point to the NULL at argv[argc] */ + __environ = &argv[argc]; } /* Pull stuff from the ELF header when possible */ #ifdef __ARCH_HAS_MMU__ - aux_dat = (unsigned long*)envp; + aux_dat = (unsigned long*)__environ; while (*aux_dat) { aux_dat++; } @@ -249,5 +251,5 @@ __uClibc_start_main(int (*main)(int argc, char **argv, char **envp), /* * Finally, invoke application's main and then exit. */ - exit(main(argc, argv, envp)); + exit(main(argc, argv, __environ)); } -- cgit v1.2.3