diff options
| author | Mike Frysinger <vapier@gentoo.org> | 2005-11-07 23:41:10 +0000 | 
|---|---|---|
| committer | Mike Frysinger <vapier@gentoo.org> | 2005-11-07 23:41:10 +0000 | 
| commit | f0b4463b7d29b7b22d4dcb49859cbf4acc677afb (patch) | |
| tree | 9a0476c9edb7e8abbc7c7e79aa716b61e52bc4e9 /libpthread/linuxthreads | |
| parent | a39cef86d12223369a06b667da094c9b05a356aa (diff) | |
| download | uClibc-alpine-f0b4463b7d29b7b22d4dcb49859cbf4acc677afb.tar.bz2 uClibc-alpine-f0b4463b7d29b7b22d4dcb49859cbf4acc677afb.tar.xz | |
implement __pthread_init_max_stacksize() which is required for FLOATING_STACKS
Diffstat (limited to 'libpthread/linuxthreads')
| -rw-r--r-- | libpthread/linuxthreads/internals.h | 1 | ||||
| -rw-r--r-- | libpthread/linuxthreads/pthread.c | 47 | 
2 files changed, 48 insertions, 0 deletions
| diff --git a/libpthread/linuxthreads/internals.h b/libpthread/linuxthreads/internals.h index a91682df1..98dcf4db2 100644 --- a/libpthread/linuxthreads/internals.h +++ b/libpthread/linuxthreads/internals.h @@ -283,6 +283,7 @@ extern size_t __pagesize;  void __pthread_destroy_specifics(void);  void __pthread_perform_cleanup(void); +void __pthread_init_max_stacksize (void);  int __pthread_initialize_manager(void);  void __pthread_message(char * fmt, ...);  int __pthread_manager(void *reqfd); diff --git a/libpthread/linuxthreads/pthread.c b/libpthread/linuxthreads/pthread.c index 5b038acb8..ad75b950d 100644 --- a/libpthread/linuxthreads/pthread.c +++ b/libpthread/linuxthreads/pthread.c @@ -214,6 +214,9 @@ char *__pthread_manager_thread_tos = NULL;  int __pthread_exit_requested = 0;  int __pthread_exit_code = 0; +/* Maximum stack size.  */ +size_t __pthread_max_stacksize; +  /* Communicate relevant LinuxThreads constants to gdb */  const int __pthread_threads_max = PTHREAD_THREADS_MAX; @@ -314,6 +317,50 @@ void __pthread_initialize_minimal(void)  } +void +__pthread_init_max_stacksize(void) +{ +  struct rlimit limit; +  size_t max_stack; + +  getrlimit(RLIMIT_STACK, &limit); +#ifdef FLOATING_STACKS +  if (limit.rlim_cur == RLIM_INFINITY) +    limit.rlim_cur = ARCH_STACK_MAX_SIZE; +# ifdef NEED_SEPARATE_REGISTER_STACK +  max_stack = limit.rlim_cur / 2; +# else +  max_stack = limit.rlim_cur; +# endif +#else +  /* Play with the stack size limit to make sure that no stack ever grows +     beyond STACK_SIZE minus one page (to act as a guard page). */ +# ifdef NEED_SEPARATE_REGISTER_STACK +  /* STACK_SIZE bytes hold both the main stack and register backing +     store. The rlimit value applies to each individually.  */ +  max_stack = STACK_SIZE/2 - __getpagesize (); +# else +  max_stack = STACK_SIZE - __getpagesize(); +# endif +  if (limit.rlim_cur > max_stack) { +    limit.rlim_cur = max_stack; +    setrlimit(RLIMIT_STACK, &limit); +  } +#endif +  __pthread_max_stacksize = max_stack; +#define __MAX_ALLOCA_CUTOFF 65536 +  if (max_stack / 4 < __MAX_ALLOCA_CUTOFF) +    { +#ifdef USE_TLS +      pthread_descr self = THREAD_SELF; +      self->p_alloca_cutoff = max_stack / 4; +#else +      __pthread_initial_thread.p_alloca_cutoff = max_stack / 4; +#endif +    } +} + +  static void pthread_initialize(void)  {    struct sigaction sa; | 
