_pthread_allocate(const pthread_attr_t *attrs, void **stack)
{
mach_vm_address_t allocaddr = __pthread_stack_hint;
- size_t allocsize, guardsize, stacksize;
+ size_t allocsize, guardsize, stacksize, pthreadoff;
kern_return_t kr;
pthread_t t;
PTHREAD_ASSERT(((uintptr_t)attrs->stackaddr % vm_page_size) == 0);
allocsize = PTHREAD_SIZE;
guardsize = 0;
+ pthreadoff = 0;
// <rdar://problem/42588315> if the attrs struct specifies a custom
// stack address but not a custom size, using ->stacksize here instead
// of _pthread_attr_stacksize stores stacksize as zero, indicating
} else {
guardsize = _pthread_attr_guardsize(attrs);
stacksize = _pthread_attr_stacksize(attrs) + PTHREAD_T_OFFSET;
- allocsize = stacksize + guardsize + PTHREAD_SIZE;
+ pthreadoff = stacksize + guardsize;
+ allocsize = pthreadoff + PTHREAD_SIZE;
allocsize = mach_vm_round_page(allocsize);
}
// Thread structure resides at the top of the stack (when using a
// custom stack, allocsize == PTHREAD_SIZE, so places the pthread_t
// at allocaddr).
- t = (pthread_t)(allocaddr + allocsize - PTHREAD_SIZE);
+ t = (pthread_t)(allocaddr + pthreadoff);
if (attrs->stackaddr) {
*stack = attrs->stackaddr;
} else {