Add cmake variable to set the max app thread stack size (#346)
This commit is contained in:
@ -242,12 +242,19 @@ uint8 *os_thread_get_stack_boundary()
|
||||
uint8 *addr = NULL;
|
||||
size_t stack_size, guard_size;
|
||||
int page_size = getpagesize();
|
||||
size_t max_stack_size = (APP_THREAD_STACK_SIZE_MAX + page_size - 1)
|
||||
& ~(page_size - 1);
|
||||
|
||||
if (max_stack_size < APP_THREAD_STACK_SIZE_DEFAULT)
|
||||
max_stack_size = APP_THREAD_STACK_SIZE_DEFAULT;
|
||||
|
||||
#ifdef __linux__
|
||||
if (pthread_getattr_np(self, &attr) == 0) {
|
||||
pthread_attr_getstack(&attr, (void**)&addr, &stack_size);
|
||||
pthread_attr_getguardsize(&attr, &guard_size);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (stack_size > max_stack_size)
|
||||
addr = addr + stack_size - max_stack_size;
|
||||
if (guard_size < (size_t)page_size)
|
||||
/* Reserved 1 guard page at least for safety */
|
||||
guard_size = (size_t)page_size;
|
||||
@ -257,7 +264,10 @@ uint8 *os_thread_get_stack_boundary()
|
||||
#elif defined(__APPLE__)
|
||||
if ((addr = (uint8*)pthread_get_stackaddr_np(self))) {
|
||||
stack_size = pthread_get_stacksize_np(self);
|
||||
addr -= stack_size;
|
||||
if (stack_size > max_stack_size)
|
||||
addr -= max_stack_size;
|
||||
else
|
||||
addr -= stack_size;
|
||||
/* Reserved 1 guard page at least for safety */
|
||||
addr += page_size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user