Use shared globals to init __progname + environ
Initialize the __progname and environ global variables using
libc_shared_globals rather than KernelArgumentBlock.
Also: suppose the linker is invoked on an executable:
linker prog [args...]
The first argument passed to main() and constructor functions is "prog"
rather than "linker". For consistency, this CL changes the BSD
__progname global from "linker" to "prog".
Bug: none
Test: bionic unit tests
Change-Id: I376d76953c9436706dbc53911ef6585c1acc1c31
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index f78a11a..4702e1c 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -91,11 +91,11 @@
__pthread_internal_add(main_thread);
}
-void __libc_init_common(KernelArgumentBlock& args) {
+void __libc_init_common() {
// Initialize various globals.
- environ = args.envp;
+ environ = __libc_shared_globals()->init_environ;
errno = 0;
- __progname = args.argv[0] ? args.argv[0] : "<unknown>";
+ __progname = __libc_shared_globals()->init_progname ?: "<unknown>";
#if !defined(__LP64__)
__check_max_thread_id();
@@ -294,7 +294,7 @@
#endif
}
-void __libc_init_AT_SECURE(KernelArgumentBlock& args) {
+void __libc_init_AT_SECURE(char** env) {
// Check that the kernel provided a value for AT_SECURE.
errno = 0;
unsigned long is_AT_SECURE = getauxval(AT_SECURE);
@@ -305,11 +305,11 @@
// https://www.freebsd.org/security/advisories/FreeBSD-SA-02:23.stdio.asc
__nullify_closed_stdio();
- __sanitize_environment_variables(args.envp);
+ __sanitize_environment_variables(env);
}
// Now the environment has been sanitized, make it available.
- environ = args.envp;
+ environ = __libc_shared_globals()->init_environ = env;
__initialize_personality();
}