diff --git a/src/thread/pthread_attr_get.c b/src/thread/pthread_attr_get.c index 3d296bf3a5e3164ec633133737e74b90fdde4faa..4aa5afdb2881c6ae3aa344784b83b619d76e5a6b 100644 --- a/src/thread/pthread_attr_get.c +++ b/src/thread/pthread_attr_get.c @@ -7,7 +7,7 @@ int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state) } int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) { - *size = a->_a_guardsize + DEFAULT_GUARD_SIZE; + *size = a->_a_guardsize; return 0; } @@ -39,14 +39,14 @@ int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr { if (!a->_a_stackaddr) return EINVAL; - *size = a->_a_stacksize + DEFAULT_STACK_SIZE; + *size = a->_a_stacksize; *addr = (void *)(a->_a_stackaddr - *size); return 0; } int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) { - *size = a->_a_stacksize + DEFAULT_STACK_SIZE; + *size = a->_a_stacksize; return 0; } diff --git a/src/thread/pthread_attr_init.c b/src/thread/pthread_attr_init.c index 969e0a3805e9299070eddd8a2b43cf7d6be160b1..8f6e337452bc57ab95b00d030a5e7c7a95ac8390 100644 --- a/src/thread/pthread_attr_init.c +++ b/src/thread/pthread_attr_init.c @@ -3,5 +3,7 @@ int pthread_attr_init(pthread_attr_t *a) { *a = (pthread_attr_t){0}; + a->_a_stacksize = DEFAULT_STACK_SIZE; + a->_a_guardsize = DEFAULT_GUARD_SIZE; return 0; } diff --git a/src/thread/pthread_attr_setguardsize.c b/src/thread/pthread_attr_setguardsize.c index 9f21d24702fbf3874c26e196943653166bb3f818..1c5c60acbc70ae8bfee9b0499e98119ed34efb6f 100644 --- a/src/thread/pthread_attr_setguardsize.c +++ b/src/thread/pthread_attr_setguardsize.c @@ -3,6 +3,6 @@ int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) { if (size > SIZE_MAX/8) return EINVAL; - a->_a_guardsize = size - DEFAULT_GUARD_SIZE; + a->_a_guardsize = size; return 0; } diff --git a/src/thread/pthread_attr_setstack.c b/src/thread/pthread_attr_setstack.c index 61707a318993339fa48f338de39c5a4ace0549a2..1eddcbd6ebb4f834e54f34f810f8c6795eaa6135 100644 --- a/src/thread/pthread_attr_setstack.c +++ b/src/thread/pthread_attr_setstack.c @@ -4,6 +4,6 @@ int pthread_attr_setstack(pthread_attr_t *a, void *addr, size_t size) { if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL; a->_a_stackaddr = (size_t)addr + size; - a->_a_stacksize = size - DEFAULT_STACK_SIZE; + a->_a_stacksize = size; return 0; } diff --git a/src/thread/pthread_attr_setstacksize.c b/src/thread/pthread_attr_setstacksize.c index 09d3fda72ee055ba93de2e1534d153ea2f6754b3..9c6a8806eefe052e6f0674a3d4795baad942f73f 100644 --- a/src/thread/pthread_attr_setstacksize.c +++ b/src/thread/pthread_attr_setstacksize.c @@ -4,6 +4,6 @@ int pthread_attr_setstacksize(pthread_attr_t *a, size_t size) { if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL; a->_a_stackaddr = 0; - a->_a_stacksize = size - DEFAULT_STACK_SIZE; + a->_a_stacksize = size; return 0; } diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 9f6b98e609863f01a7eecb0a0541cd0b88e951b7..db9e575efcea8e01e6ef63d7c321c5d3ce627c08 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -208,7 +208,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att if (attr._a_stackaddr) { size_t need = libc.tls_size + __pthread_tsd_size; - size = attr._a_stacksize + DEFAULT_STACK_SIZE; + size = attr._a_stacksize; stack = (void *)(attr._a_stackaddr & -16); stack_limit = (void *)(attr._a_stackaddr - size); /* Use application-provided stack for TLS only when @@ -223,8 +223,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att guard = 0; } } else { - guard = ROUND(DEFAULT_GUARD_SIZE + attr._a_guardsize); - size = guard + ROUND(DEFAULT_STACK_SIZE + attr._a_stacksize + guard = ROUND(attr._a_guardsize); + size = guard + ROUND(attr._a_stacksize + libc.tls_size + __pthread_tsd_size); } diff --git a/src/thread/pthread_getattr_np.c b/src/thread/pthread_getattr_np.c index 10ea512733fad390ac5cc699438cf1e4c02f06a2..ae26a5aba686d6f8d880162e9c0fe77de7f391b9 100644 --- a/src/thread/pthread_getattr_np.c +++ b/src/thread/pthread_getattr_np.c @@ -9,7 +9,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a) a->_a_detach = !!t->detached; if (t->stack) { a->_a_stackaddr = (uintptr_t)t->stack; - a->_a_stacksize = t->stack_size - DEFAULT_STACK_SIZE; + a->_a_stacksize = t->stack_size; } else { char *p = (void *)libc.auxv; size_t l = PAGE_SIZE; @@ -17,7 +17,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a) a->_a_stackaddr = (uintptr_t)p; while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM) l += PAGE_SIZE; - a->_a_stacksize = l - DEFAULT_STACK_SIZE; + a->_a_stacksize = l; } return 0; }