mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Bug 966802 - Fix and protect from stack overflow of the threads cloned in the Nuwa process. r=khuey
This commit is contained in:
parent
83fd8dc8be
commit
18af4cf1b7
@ -15,6 +15,7 @@
|
||||
#include <pthread.h>
|
||||
#include <alloca.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@ -141,7 +142,9 @@ TLSInfoList;
|
||||
* methods or do large allocations on the stack to avoid stack overflow.
|
||||
*/
|
||||
#ifndef NUWA_STACK_SIZE
|
||||
#define NUWA_STACK_SIZE (1024 * 32)
|
||||
#define PAGE_SIZE 4096
|
||||
#define PAGE_ALIGN_MASK 0xfffff000
|
||||
#define NUWA_STACK_SIZE (1024 * 128)
|
||||
#endif
|
||||
|
||||
#define NATIVE_THREAD_NAME_LENGTH 16
|
||||
@ -489,7 +492,18 @@ thread_info_new(void) {
|
||||
tinfo->recreatedThreadID = 0;
|
||||
tinfo->recreatedNativeThreadID = 0;
|
||||
tinfo->reacquireMutex = nullptr;
|
||||
tinfo->stk = malloc(NUWA_STACK_SIZE);
|
||||
tinfo->stk = malloc(NUWA_STACK_SIZE + PAGE_SIZE);
|
||||
|
||||
// We use a smaller stack size. Add protection to stack overflow: mprotect()
|
||||
// stack top (the page at the lowest address) so we crash instead of corrupt
|
||||
// other content that is malloc()'d.
|
||||
unsigned long long pageGuard = ((unsigned long long)tinfo->stk);
|
||||
pageGuard &= PAGE_ALIGN_MASK;
|
||||
if (pageGuard != (unsigned long long) tinfo->stk) {
|
||||
pageGuard += PAGE_SIZE; // Round up to be page-aligned.
|
||||
}
|
||||
mprotect((void*)pageGuard, PAGE_SIZE, PROT_READ);
|
||||
|
||||
pthread_attr_init(&tinfo->threadAttr);
|
||||
|
||||
REAL(pthread_mutex_lock)(&sThreadCountLock);
|
||||
|
Loading…
x
Reference in New Issue
Block a user