- if (attr) {
- guard = ROUND(attr->_a_guardsize + DEFAULT_GUARD_SIZE);
- size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE);
+ guard = ROUND(DEFAULT_GUARD_SIZE + attr._a_guardsize);
+ size = guard + ROUND(DEFAULT_STACK_SIZE + attr._a_stacksize
+ + libc.tls_size + __pthread_tsd_size);
+ }
+
+ if (!tsd) {
+ if (guard) {
+ map = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
+ if (map == MAP_FAILED) goto fail;
+ if (mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)) {
+ munmap(map, size);
+ goto fail;
+ }
+ } else {
+ map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+ if (map == MAP_FAILED) goto fail;