This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/2] Set default stack size from program environment


>  void
> -__pthread_initialize_minimal_internal (void)
> +__pthread_initialize_minimal_internal (int argc, char **argv, char **envp)

argc and argv are unsed?

>  {
>  #ifndef SHARED
>    /* Unlike in the dynamically linked case the dynamic linker has not
> @@ -401,29 +401,44 @@ __pthread_initialize_minimal_internal (void)
>  
>    __static_tls_size = roundup (__static_tls_size, static_tls_align);
>  
> -  /* Determine the default allowed stack size.  This is the size used
> -     in case the user does not specify one.  */
> -  struct rlimit limit;
> -  if (getrlimit (RLIMIT_STACK, &limit) != 0
> -      || limit.rlim_cur == RLIM_INFINITY)
> -    /* The system limit is not usable.  Use an architecture-specific
> -       default.  */
> -    limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
> -  else if (limit.rlim_cur < PTHREAD_STACK_MIN)
> +  /* Initialize the environment.  libc.so gets initialized after us due to a
> +     circular dependency and hence __environ is not available otherwise.  */
> +    __environ = envp;
> +
> +#ifndef SHARED
> +    __libc_init_secure ();
> +#endif
> +
> +  size_t stacksize = 0;
> +  char *envval = __libc_secure_getenv ("LIBC_PTHREAD_DEFAULT_STACKSIZE_NP");

ok, this environment access ensure to funish before creating multi thread. theresore
this new feature don't introduce any new threading vs environment issue.

I'm not sure LIBC_PTHREAD prefix is good or not. then I have no comments.



> +
> +  if (__glibc_unlikely (envval != NULL && envval[0] != '\0'))
> +    {
> +      char *env_conv = envval;
> +      size_t ret = strtoul (envval, &env_conv, 0);
> +
> +      if (*env_conv == '\0')
> +	stacksize = ret;
> +    }
> +
> +  if (stacksize == 0)
> +    {
> +      /* Determine the default allowed stack size.  This is the size used
> +	 in case the user does not specify one.  */
> +      struct rlimit limit;
> +      if (getrlimit (RLIMIT_STACK, &limit) != 0
> +	  || limit.rlim_cur == RLIM_INFINITY)
> +	/* The system limit is not usable.  Use an architecture-specific
> +	   default.  */
> +	stacksize = ARCH_STACK_DEFAULT_SIZE;
> +      else
> +	stacksize = limit.rlim_cur;
> +    }
> +
> +  if (__pthread_set_default_stacksize_np (stacksize))
>      /* The system limit is unusably small.
>         Use the minimal size acceptable.  */
> -    limit.rlim_cur = PTHREAD_STACK_MIN;
> -
> -  /* Make sure it meets the minimum size that allocate_stack
> -     (allocatestack.c) will demand, which depends on the page size.  */
> -  const uintptr_t pagesz = GLRO(dl_pagesize);
> -  const size_t minstack = pagesz + __static_tls_size + MINIMAL_REST_STACK;
> -  if (limit.rlim_cur < minstack)
> -    limit.rlim_cur = minstack;
> -
> -  /* Round the resource limit up to page size.  */
> -  limit.rlim_cur = (limit.rlim_cur + pagesz - 1) & -pagesz;
> -  __default_stacksize = limit.rlim_cur;
> +    __adjust_and_set_stacksize (PTHREAD_STACK_MIN);

Your __pthread_set_default_stacksize_np() is below.

> +int
> +__pthread_set_default_stacksize_np (size_t stacksize)
> +{
> +  if (stacksize < PTHREAD_STACK_MIN)
> +    return -EINVAL;
> +
> +  __adjust_and_set_stacksize (stacksize);
> +
> +  return 0;
> +}

and here call __adjust_and_set_stacksize() even if __pthread_set_default_stacksize_np()
return -EINVAL. so why do you need to call __pthread_set_default_stacksize_np()?




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]