diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp index 5b9edafb0..4995414b1 100644 --- a/libc/bionic/libc_init_common.cpp +++ b/libc/bionic/libc_init_common.cpp @@ -51,7 +51,6 @@ #include "pthread_internal.h" extern "C" abort_msg_t** __abort_message_ptr; -extern "C" void __bionic_setjmp_cookie_init(void); extern "C" int __system_properties_init(void); extern "C" int __set_tls(void* ptr); extern "C" int __set_tid_address(int* tid_address); @@ -114,6 +113,7 @@ void __libc_init_globals(KernelArgumentBlock& args) { __libc_globals.initialize(); __libc_globals.mutate([&args](libc_globals* globals) { __libc_init_vdso(globals, args); + __libc_init_setjmp_cookie(globals, args); }); } @@ -133,7 +133,6 @@ void __libc_init_common(KernelArgumentBlock& args) { __pthread_internal_add(main_thread); __system_properties_init(); // Requires 'environ'. - __bionic_setjmp_cookie_init(); } __noreturn static void __early_abort(int line) { diff --git a/libc/bionic/setjmp_cookie.cpp b/libc/bionic/setjmp_cookie.cpp index cf79e8361..ce57fd1c2 100644 --- a/libc/bionic/setjmp_cookie.cpp +++ b/libc/bionic/setjmp_cookie.cpp @@ -34,30 +34,30 @@ #include #include +#include "private/bionic_globals.h" #include "private/libc_logging.h" +#include "private/KernelArgumentBlock.h" -extern "C" __LIBC_HIDDEN__ int getentropy(void*, size_t); -static long __bionic_setjmp_cookie; - -extern "C" void __bionic_setjmp_cookie_init() { - char* random_data = reinterpret_cast(getauxval(AT_RANDOM)); +void __libc_init_setjmp_cookie(libc_globals* globals, + KernelArgumentBlock& args) { + char* random_data = reinterpret_cast(args.getauxval(AT_RANDOM)); long value = *reinterpret_cast(random_data + 8); // Mask off the last bit to store the signal flag. - __bionic_setjmp_cookie = value & ~1; + globals->setjmp_cookie = value & ~1; } -extern "C" long __bionic_setjmp_cookie_get(long sigflag) { +extern "C" __LIBC_HIDDEN__ long __bionic_setjmp_cookie_get(long sigflag) { if (sigflag & ~1) { __libc_fatal("unexpected sigflag value: %ld", sigflag); } - return __bionic_setjmp_cookie | sigflag; + return __libc_globals->setjmp_cookie | sigflag; } // Aborts if cookie doesn't match, returns the signal flag otherwise. -extern "C" long __bionic_setjmp_cookie_check(long cookie) { - if (__bionic_setjmp_cookie != (cookie & ~1)) { +extern "C" __LIBC_HIDDEN__ long __bionic_setjmp_cookie_check(long cookie) { + if (__libc_globals->setjmp_cookie != (cookie & ~1)) { __libc_fatal("setjmp cookie mismatch"); } diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h index 788a75901..644b5a4d0 100644 --- a/libc/private/bionic_globals.h +++ b/libc/private/bionic_globals.h @@ -34,6 +34,7 @@ struct libc_globals { vdso_entry vdso[VDSO_END]; + long setjmp_cookie; }; __LIBC_HIDDEN__ extern WriteProtected __libc_globals; @@ -41,5 +42,7 @@ __LIBC_HIDDEN__ extern WriteProtected __libc_globals; class KernelArgumentBlock; __LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args); +__LIBC_HIDDEN__ void __libc_init_setjmp_cookie(libc_globals* globals, + KernelArgumentBlock& args); #endif