Move setjmp cookie to a shared globals struct.

Change-Id: I59a4c187d61524c4e48655c4c6376dba0d41eee2
This commit is contained in:
Josh Gao 2015-10-07 14:32:36 -07:00
parent 93c0f5ee00
commit fe9d0ed6cb
3 changed files with 14 additions and 12 deletions

View File

@ -51,7 +51,6 @@
#include "pthread_internal.h" #include "pthread_internal.h"
extern "C" abort_msg_t** __abort_message_ptr; 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 __system_properties_init(void);
extern "C" int __set_tls(void* ptr); extern "C" int __set_tls(void* ptr);
extern "C" int __set_tid_address(int* tid_address); extern "C" int __set_tid_address(int* tid_address);
@ -114,6 +113,7 @@ void __libc_init_globals(KernelArgumentBlock& args) {
__libc_globals.initialize(); __libc_globals.initialize();
__libc_globals.mutate([&args](libc_globals* globals) { __libc_globals.mutate([&args](libc_globals* globals) {
__libc_init_vdso(globals, args); __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); __pthread_internal_add(main_thread);
__system_properties_init(); // Requires 'environ'. __system_properties_init(); // Requires 'environ'.
__bionic_setjmp_cookie_init();
} }
__noreturn static void __early_abort(int line) { __noreturn static void __early_abort(int line) {

View File

@ -34,30 +34,30 @@
#include <sys/auxv.h> #include <sys/auxv.h>
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include "private/bionic_globals.h"
#include "private/libc_logging.h" #include "private/libc_logging.h"
#include "private/KernelArgumentBlock.h"
extern "C" __LIBC_HIDDEN__ int getentropy(void*, size_t); void __libc_init_setjmp_cookie(libc_globals* globals,
static long __bionic_setjmp_cookie; KernelArgumentBlock& args) {
char* random_data = reinterpret_cast<char*>(args.getauxval(AT_RANDOM));
extern "C" void __bionic_setjmp_cookie_init() {
char* random_data = reinterpret_cast<char*>(getauxval(AT_RANDOM));
long value = *reinterpret_cast<long*>(random_data + 8); long value = *reinterpret_cast<long*>(random_data + 8);
// Mask off the last bit to store the signal flag. // 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) { if (sigflag & ~1) {
__libc_fatal("unexpected sigflag value: %ld", sigflag); __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. // Aborts if cookie doesn't match, returns the signal flag otherwise.
extern "C" long __bionic_setjmp_cookie_check(long cookie) { extern "C" __LIBC_HIDDEN__ long __bionic_setjmp_cookie_check(long cookie) {
if (__bionic_setjmp_cookie != (cookie & ~1)) { if (__libc_globals->setjmp_cookie != (cookie & ~1)) {
__libc_fatal("setjmp cookie mismatch"); __libc_fatal("setjmp cookie mismatch");
} }

View File

@ -34,6 +34,7 @@
struct libc_globals { struct libc_globals {
vdso_entry vdso[VDSO_END]; vdso_entry vdso[VDSO_END];
long setjmp_cookie;
}; };
__LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals; __LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals;
@ -41,5 +42,7 @@ __LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals;
class KernelArgumentBlock; class KernelArgumentBlock;
__LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals, __LIBC_HIDDEN__ void __libc_init_vdso(libc_globals* globals,
KernelArgumentBlock& args); KernelArgumentBlock& args);
__LIBC_HIDDEN__ void __libc_init_setjmp_cookie(libc_globals* globals,
KernelArgumentBlock& args);
#endif #endif