From 96ed53c10fc84e7ed7f9329697fac0c378932cfa Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 9 Jul 2014 12:06:08 +0000 Subject: * thread.cc (pthread::create): Use PTHREAD_DEFAULT_STACKSIZE stacksize if attr.stacksize is 0. (pthread_attr::pthread_attr): Initialize stacksize to 0 to align more closely to Linux. (pthread_attr_getstack): Fix incorrect stackaddr computation. Return stackaddr just like pthread_attr_getstackaddr. Remove slightly off comment. (pthread_attr_getstackaddr): Remove slightly off comment. (pthread_getattr_np): Return stackaddr and stacksize based on the full allocated stackarea. --- winsup/cygwin/ChangeLog | 13 +++++++++++++ winsup/cygwin/thread.cc | 23 ++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'winsup/cygwin') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d940017fe..d7266b16f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2014-07-09 Corinna Vinschen + + * thread.cc (pthread::create): Use PTHREAD_DEFAULT_STACKSIZE stacksize + if attr.stacksize is 0. + (pthread_attr::pthread_attr): Initialize stacksize to 0 to align more + closely to Linux. + (pthread_attr_getstack): Fix incorrect stackaddr computation. Return + stackaddr just like pthread_attr_getstackaddr. Remove slightly off + comment. + (pthread_attr_getstackaddr): Remove slightly off comment. + (pthread_getattr_np): Return stackaddr and stacksize based on the full + allocated stackarea. + 2014-07-09 Corinna Vinschen * exceptions.cc (exception::myfault_handle): Rephrase comment. diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index e411301cb..0a167fa4d 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -473,9 +473,9 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr, arg = threadarg; mutex.lock (); - win32_obj_id = CygwinCreateThread (thread_init_wrapper, this, - attr.stackaddr, attr.stacksize, - attr.guardsize, 0, &thread_id); + win32_obj_id = CygwinCreateThread (thread_init_wrapper, this, attr.stackaddr, + attr.stacksize ?: PTHREAD_DEFAULT_STACKSIZE, + attr.guardsize, 0, &thread_id); if (!win32_obj_id) { @@ -1083,8 +1083,8 @@ pthread::resume () pthread_attr::pthread_attr ():verifyable_object (PTHREAD_ATTR_MAGIC), joinable (PTHREAD_CREATE_JOINABLE), contentionscope (PTHREAD_SCOPE_PROCESS), -inheritsched (PTHREAD_INHERIT_SCHED), stackaddr (NULL), -stacksize (PTHREAD_DEFAULT_STACKSIZE), guardsize (PTHREAD_DEFAULT_GUARDSIZE) +inheritsched (PTHREAD_INHERIT_SCHED), stackaddr (NULL), stacksize (0), +guardsize (PTHREAD_DEFAULT_GUARDSIZE) { schedparam.sched_priority = 0; } @@ -2263,8 +2263,7 @@ pthread_attr_getstack (const pthread_attr_t *attr, void **addr, size_t *size) { if (!pthread_attr::is_good_object (attr)) return EINVAL; - /* uses lowest address of stack on all platforms */ - *addr = (void *)((ptrdiff_t)(*attr)->stackaddr - (*attr)->stacksize); + *addr = (*attr)->stackaddr; *size = (*attr)->stacksize; return 0; } @@ -2285,8 +2284,6 @@ pthread_attr_getstackaddr (const pthread_attr_t *attr, void **addr) { if (!pthread_attr::is_good_object (attr)) return EINVAL; - /* uses stack address, which is the higher address on platforms - where the stack grows downwards, such as x86 */ *addr = (*attr)->stackaddr; return 0; } @@ -2488,11 +2485,11 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) tbi, sizeof_tbi, NULL); if (NT_SUCCESS (status)) { - PNT_TIB tib = tbi->TebBaseAddress; - (*attr)->stackaddr = tib->StackBase; + PTEB teb = (PTEB) tbi->TebBaseAddress; + (*attr)->stackaddr = teb->DeallocationStack ?: teb->Tib.StackLimit; /* stack grows downwards on x86 systems */ - (*attr)->stacksize = (uintptr_t) tib->StackBase - - (uintptr_t) tib->StackLimit; + (*attr)->stacksize = (uintptr_t) teb->Tib.StackBase + - (uintptr_t) (*attr)->stackaddr; } else { -- cgit v1.2.3