* commit '059f5c3f6ce2a1783b5d96b4059df1b9104101d5': Simplify main thread stack size initialization
This commit is contained in:
commit
4105fcdb3c
3 changed files with 18 additions and 19 deletions
|
@ -64,19 +64,15 @@ uintptr_t __stack_chk_guard = 0;
|
|||
unsigned int __page_size = PAGE_SIZE;
|
||||
unsigned int __page_shift = PAGE_SHIFT;
|
||||
|
||||
static size_t get_stack_size() {
|
||||
const size_t minimal_stack_size = 128 * 1024;
|
||||
size_t stack_size = minimal_stack_size;
|
||||
struct rlimit stack_limit;
|
||||
static size_t get_main_thread_stack_size() {
|
||||
rlimit stack_limit;
|
||||
int rlimit_result = getrlimit(RLIMIT_STACK, &stack_limit);
|
||||
if ((rlimit_result == 0) && (stack_limit.rlim_cur != RLIM_INFINITY)) {
|
||||
stack_size = stack_limit.rlim_cur;
|
||||
stack_size = (stack_size & ~(PAGE_SIZE - 1));
|
||||
if (stack_size < minimal_stack_size) {
|
||||
stack_size = minimal_stack_size;
|
||||
}
|
||||
if ((rlimit_result == 0) &&
|
||||
(stack_limit.rlim_cur != RLIM_INFINITY) &&
|
||||
(stack_limit.rlim_cur > PTHREAD_STACK_MIN)) {
|
||||
return (stack_limit.rlim_cur & ~(PAGE_SIZE - 1));
|
||||
}
|
||||
return stack_size;
|
||||
return PTHREAD_STACK_SIZE_DEFAULT;
|
||||
}
|
||||
|
||||
/* Init TLS for the initial thread. Called by the linker _before_ libc is mapped
|
||||
|
@ -94,7 +90,7 @@ void __libc_init_tls(KernelArgumentBlock& args) {
|
|||
__libc_auxv = args.auxv;
|
||||
|
||||
uintptr_t stack_top = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE;
|
||||
size_t stack_size = get_stack_size();
|
||||
size_t stack_size = get_main_thread_stack_size();
|
||||
uintptr_t stack_bottom = stack_top - stack_size;
|
||||
|
||||
static void* tls[BIONIC_TLS_SLOTS];
|
||||
|
|
|
@ -30,16 +30,10 @@
|
|||
|
||||
#include "pthread_internal.h"
|
||||
|
||||
// Traditionally we give threads a 1MiB stack. When we started allocating per-thread
|
||||
// alternate signal stacks to ease debugging of stack overflows, we subtracted the
|
||||
// same amount we were using there from the default thread stack size. This should
|
||||
// keep memory usage roughly constant.
|
||||
#define DEFAULT_THREAD_STACK_SIZE ((1 * 1024 * 1024) - SIGSTKSZ)
|
||||
|
||||
int pthread_attr_init(pthread_attr_t* attr) {
|
||||
attr->flags = 0;
|
||||
attr->stack_base = NULL;
|
||||
attr->stack_size = DEFAULT_THREAD_STACK_SIZE;
|
||||
attr->stack_size = PTHREAD_STACK_SIZE_DEFAULT;
|
||||
attr->guard_size = PAGE_SIZE;
|
||||
attr->sched_policy = SCHED_NORMAL;
|
||||
attr->sched_priority = 0;
|
||||
|
|
|
@ -77,6 +77,15 @@ __LIBC_HIDDEN__ void _pthread_internal_remove_locked(pthread_internal_t* thread)
|
|||
/* Has the thread already exited but not been joined? */
|
||||
#define PTHREAD_ATTR_FLAG_ZOMBIE 0x00000008
|
||||
|
||||
/*
|
||||
* Traditionally we give threads a 1MiB stack. When we started
|
||||
* allocating per-thread alternate signal stacks to ease debugging of
|
||||
* stack overflows, we subtracted the same amount we were using there
|
||||
* from the default thread stack size. This should keep memory usage
|
||||
* roughly constant.
|
||||
*/
|
||||
#define PTHREAD_STACK_SIZE_DEFAULT ((1 * 1024 * 1024) - SIGSTKSZ)
|
||||
|
||||
__LIBC_HIDDEN__ extern pthread_internal_t* gThreadList;
|
||||
__LIBC_HIDDEN__ extern pthread_mutex_t gThreadListLock;
|
||||
|
||||
|
|
Loading…
Reference in a new issue