Revert "add guard pages to the internal signal stacks"

This reverts commit 595752f623.

Change-Id: Iefa66e9049ca0424e53cd5fc320d161b93556dcb
This commit is contained in:
Elliott Hughes 2015-03-31 02:42:39 +00:00
parent 595752f623
commit a3125fd139
3 changed files with 7 additions and 16 deletions

View File

@ -69,23 +69,17 @@ void __init_tls(pthread_internal_t* thread) {
void __init_alternate_signal_stack(pthread_internal_t* thread) {
// Create and set an alternate signal stack.
void* stack_base = mmap(NULL, SIGNAL_STACK_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (stack_base != MAP_FAILED) {
// Create a guard page to catch stack overflows in signal handlers.
if (mprotect(stack_base, PAGE_SIZE, PROT_NONE) == -1) {
munmap(stack_base, SIGNAL_STACK_SIZE);
return;
}
stack_t ss;
ss.ss_sp = stack_base + PAGE_SIZE;
ss.ss_size = SIGNAL_STACK_SIZE - PAGE_SIZE;
stack_t ss;
ss.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (ss.ss_sp != MAP_FAILED) {
ss.ss_size = SIGSTKSZ;
ss.ss_flags = 0;
sigaltstack(&ss, NULL);
thread->alternate_signal_stack = stack_base;
thread->alternate_signal_stack = ss.ss_sp;
// We can only use const static allocated string for mapped region name, as Android kernel
// uses the string pointer directly when dumping /proc/pid/maps.
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, stack_base, SIGNAL_STACK_SIZE, "thread signal stack");
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ss.ss_sp, ss.ss_size, "thread signal stack");
}
}

View File

@ -87,7 +87,7 @@ void pthread_exit(void* return_value) {
sigaltstack(&ss, NULL);
// Free it.
munmap(thread->alternate_signal_stack, SIGNAL_STACK_SIZE);
munmap(thread->alternate_signal_stack, SIGSTKSZ);
thread->alternate_signal_stack = NULL;
}

View File

@ -130,9 +130,6 @@ __LIBC_HIDDEN__ void pthread_key_clean_all(void);
*/
#define PTHREAD_STACK_SIZE_DEFAULT ((1 * 1024 * 1024) - SIGSTKSZ)
/* Leave room for a guard page in the internally created signal stacks. */
#define SIGNAL_STACK_SIZE (SIGSTKSZ + PAGE_SIZE)
/* Needed by fork. */
__LIBC_HIDDEN__ extern void __bionic_atfork_run_prepare();
__LIBC_HIDDEN__ extern void __bionic_atfork_run_child();