+ if (attrp) attr = *attrp;
+
+ __acquire_ptc();
+
+ if (attr._a_stackaddr) {
+ size_t need = libc.tls_size + __pthread_tsd_size;
+ size = attr._a_stacksize + DEFAULT_STACK_SIZE;
+ stack = (void *)(attr._a_stackaddr & -16);
+ /* Use application-provided stack for TLS only when
+ * it does not take more than ~12% or 2k of the
+ * application's stack space. */
+ if (need < size/8 && need < 2048) {
+ tsd = stack - __pthread_tsd_size;
+ stack = tsd - libc.tls_size;
+ } else {
+ size = ROUND(need);
+ guard = 0;
+ }
+ } else {
+ guard = ROUND(DEFAULT_GUARD_SIZE + attr._a_guardsize);
+ size = guard + ROUND(DEFAULT_STACK_SIZE + attr._a_stacksize
+ + libc.tls_size + __pthread_tsd_size);
+ }