]> sourceware.org Git - newlib-cygwin.git/commitdiff
* cygwin.din (pthread_attr_getstack): Export.
authorYaakov Selkowitz <yselkowi@redhat.com>
Tue, 3 May 2011 01:13:37 +0000 (01:13 +0000)
committerYaakov Selkowitz <yselkowi@redhat.com>
Tue, 3 May 2011 01:13:37 +0000 (01:13 +0000)
(pthread_attr_getstackaddr): Export.
(pthread_getattr_np): Export.
* ntdll.h (enum _THREAD_INFORMATION_CLASS): Add ThreadBasicInformation.
(struct _THREAD_BASIC_INFORMATION): Define.
(NtQueryInformationThread): Declare.
* posix.sgml (std-susv4): Add pthread_attr_getstack.
(std-gnu): Add pthread_getattr_np.
(std-deprec): Add pthread_attr_getstackaddr.
(std-notimpl): Remove pthread_attr_[gs]etstackaddr, as they were
removed from SUSv4.
* thread.cc (pthread_attr::pthread_attr): Initialize stackaddr.
(pthread_attr_getstack): New function.
(pthread_attr_getstackaddr): New function.
(pthread_attr_setstacksize): Return EINVAL if passed size less than
PTHREAD_STACK_MIN, as required by POSIX.
(pthread_getattr_np): New function.
* thread.h (class pthread_attr): Add stackaddr member.
* include/pthread.h (pthread_attr_getstack): Declare.
(pthread_attr_getstackaddr): Declare unconditionally.
(pthread_attr_setstack): Declare inside false conditional for reference.
(pthread_getattr_np): Declare.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.

winsup/cygwin/ChangeLog
winsup/cygwin/cygwin.din
winsup/cygwin/include/cygwin/version.h
winsup/cygwin/include/pthread.h
winsup/cygwin/ntdll.h
winsup/cygwin/posix.sgml
winsup/cygwin/thread.cc
winsup/cygwin/thread.h

index 547c5e5c446a4301e8f8e67e2226731cb31faeb6..379e694c4d86763fda8ecd8a0b9793360b09b749 100644 (file)
@@ -1,3 +1,29 @@
+2011-05-02  Yaakov Selkowitz  <yselkowitz@users.sourceforge.net>
+
+       * cygwin.din (pthread_attr_getstack): Export.
+       (pthread_attr_getstackaddr): Export.
+       (pthread_getattr_np): Export.
+       * ntdll.h (enum _THREAD_INFORMATION_CLASS): Add ThreadBasicInformation.
+       (struct _THREAD_BASIC_INFORMATION): Define.
+       (NtQueryInformationThread): Declare.
+       * posix.sgml (std-susv4): Add pthread_attr_getstack.
+       (std-gnu): Add pthread_getattr_np.
+       (std-deprec): Add pthread_attr_getstackaddr.
+       (std-notimpl): Remove pthread_attr_[gs]etstackaddr, as they were
+       removed from SUSv4.
+       * thread.cc (pthread_attr::pthread_attr): Initialize stackaddr.
+       (pthread_attr_getstack): New function.
+       (pthread_attr_getstackaddr): New function.
+       (pthread_attr_setstacksize): Return EINVAL if passed size less than
+       PTHREAD_STACK_MIN, as required by POSIX.
+       (pthread_getattr_np): New function.
+       * thread.h (class pthread_attr): Add stackaddr member.
+       * include/pthread.h (pthread_attr_getstack): Declare.
+       (pthread_attr_getstackaddr): Declare unconditionally.
+       (pthread_attr_setstack): Declare inside false conditional for reference.
+       (pthread_getattr_np): Declare.
+       * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
+
 2011-05-02  Christopher Faylor  <me.cygwin2011@cgf.cx>
 
        * Makefile.in: Allow CFLAGS to be overridden from the environment.
index 823776d602ac4dc497c412f38632dc51f847fe27..31f0004fa328fcdbfa38b3c8bfd319476216480c 100644 (file)
@@ -1174,6 +1174,8 @@ pthread_attr_getinheritsched SIGFE
 pthread_attr_getschedparam SIGFE
 pthread_attr_getschedpolicy SIGFE
 pthread_attr_getscope SIGFE
+pthread_attr_getstack SIGFE
+pthread_attr_getstackaddr SIGFE
 pthread_attr_getstacksize SIGFE
 pthread_attr_init SIGFE
 pthread_attr_setdetachstate SIGFE
@@ -1200,6 +1202,7 @@ pthread_create SIGFE
 pthread_detach SIGFE
 pthread_equal SIGFE
 pthread_exit SIGFE
+pthread_getattr_np SIGFE
 pthread_getconcurrency SIGFE
 pthread_getschedparam SIGFE
 pthread_getsequence_np SIGFE
index 95e5876dafebec07511843b7a4039168ce057383..8279e3a81d864dbc6e746a6be77d391e7038cfec 100644 (file)
@@ -405,12 +405,14 @@ details. */
           pthread_spin_trylock, pthread_spin_unlock.
       239: Export pthread_setschedprio.
       240: Export ppoll.
+      241: Export pthread_attr_getstack, pthread_attr_getstackaddr,
+          pthread_getattr_np.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 240
+#define CYGWIN_VERSION_API_MINOR 241
 
      /* There is also a compatibity version number associated with the
        shared memory regions.  It is incremented when incompatible
index 221d242d3d70f1a6b7096fcb48e1b2f03da14939..c76cd670b53c5da1a6eab3b56e74c2d8f20095ad 100644 (file)
@@ -76,6 +76,8 @@ int pthread_attr_getinheritsched (const pthread_attr_t *, int *);
 int pthread_attr_getschedparam (const pthread_attr_t *, struct sched_param *);
 int pthread_attr_getschedpolicy (const pthread_attr_t *, int *);
 int pthread_attr_getscope (const pthread_attr_t *, int *);
+int pthread_attr_getstack (const pthread_attr_t *, void **, size_t *);
+int pthread_attr_getstackaddr (const pthread_attr_t *, void **);
 int pthread_attr_init (pthread_attr_t *);
 int pthread_attr_setdetachstate (pthread_attr_t *, int);
 int pthread_attr_setinheritsched (pthread_attr_t *, int);
@@ -88,7 +90,7 @@ int pthread_attr_setscope (pthread_attr_t *, int);
  * Not supported or implemented. The prototypes are here so if someone greps the
  * source they will see these comments
  */
-int pthread_attr_getstackaddr (const pthread_attr_t *, void **);
+int pthread_attr_setstack (pthread_attr_t *, void *, size_t);
 int pthread_attr_setstackaddr (pthread_attr_t *, void *);
 #endif
 
@@ -200,6 +202,7 @@ void pthread_testcancel (void);
 
 /* Non posix calls */
 
+int pthread_getattr_np (pthread_t, pthread_attr_t *);
 int pthread_suspend (pthread_t);
 int pthread_continue (pthread_t);
 int pthread_yield (void);
index b420f02d5a5a4ede972a5d44ff4f02abe8382daf..75ba1a5e89189570ae51e11686278e51f9094e37 100644 (file)
@@ -898,9 +898,19 @@ typedef enum _EVENT_INFORMATION_CLASS
 
 typedef enum _THREAD_INFORMATION_CLASS
 {
+  ThreadBasicInformation = 0,
   ThreadImpersonationToken = 5
 } THREAD_INFORMATION_CLASS, *PTHREAD_INFORMATION_CLASS;
 
+typedef struct _THREAD_BASIC_INFORMATION {
+    NTSTATUS  ExitStatus;
+    PNT_TIB  TebBaseAddress;
+    CLIENT_ID  ClientId;
+    KAFFINITY  AffinityMask;
+    KPRIORITY  Priority;
+    KPRIORITY  BasePriority;
+} THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION;
+
 #define RTL_QUERY_REGISTRY_SUBKEY 0x01
 #define RTL_QUERY_REGISTRY_TOPKEY 0x02
 #define RTL_QUERY_REGISTRY_REQUIRED 0x04
@@ -1058,6 +1068,8 @@ extern "C"
                                         ULONG, FILE_INFORMATION_CLASS);
   NTSTATUS NTAPI NtQueryInformationProcess (HANDLE, PROCESSINFOCLASS,
                                            PVOID, ULONG, PULONG);
+  NTSTATUS NTAPI NtQueryInformationThread (HANDLE, THREAD_INFORMATION_CLASS,
+                                           PVOID, ULONG, PULONG);
   NTSTATUS NTAPI NtQueryInformationToken (HANDLE, TOKEN_INFORMATION_CLASS,
                                          PVOID, ULONG, PULONG);
   NTSTATUS NTAPI NtQueryObject (HANDLE, OBJECT_INFORMATION_CLASS, VOID *,
index 47cbcab6f913e8b3721455b4e47c007cfd2a4cdb..67d958b97436471427b423918c4362739c13b297 100644 (file)
@@ -534,6 +534,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
     pthread_attr_getschedparam
     pthread_attr_getschedpolicy
     pthread_attr_getscope
+    pthread_attr_getstack
     pthread_attr_getstacksize
     pthread_attr_init
     pthread_attr_setdetachstate
@@ -1117,6 +1118,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
     pow10
     pow10f
     ppoll
+    pthread_getattr_np
     removexattr
     setxattr
     strchrnul
@@ -1230,6 +1232,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
     mallopt                    (SVID)
     mktemp                     (SUSv3)
     on_exit                    (SunOS)
+    pthread_attr_getstackaddr  (SUSv3)
     pthread_continue           (XPG2)
     pthread_getsequence_np     (Tru64)
     pthread_suspend            (XPG2)
@@ -1375,11 +1378,8 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
     psiginfo
     psignal
     pthread_attr_getguardsize
-    pthread_attr_getstack
-    pthread_attr_getstackaddr
     pthread_attr_setguardsize
     pthread_attr_setstack
-    pthread_attr_setstackaddr
     pthread_barrier[...]
     pthread_condattr_getclock
     pthread_condattr_setclock
index 0ac8101173672e0efe51fdff38d8b0e20e1426ec..0085320ade95da9363c4a246c011e4b94b00ebdf 100644 (file)
@@ -1085,7 +1085,7 @@ pthread::resume ()
 
 pthread_attr::pthread_attr ():verifyable_object (PTHREAD_ATTR_MAGIC),
 joinable (PTHREAD_CREATE_JOINABLE), contentionscope (PTHREAD_SCOPE_PROCESS),
-inheritsched (PTHREAD_INHERIT_SCHED), stacksize (0)
+inheritsched (PTHREAD_INHERIT_SCHED), stackaddr (NULL), stacksize (0)
 {
   schedparam.sched_priority = 0;
 }
@@ -2237,11 +2237,35 @@ pthread_attr_setscope (pthread_attr_t *attr, int contentionscope)
   return 0;
 }
 
+extern "C" int
+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 *)((int)(*attr)->stackaddr - (*attr)->stacksize);
+  *size = (*attr)->stacksize;
+  return 0;
+}
+
+extern "C" int
+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;
+}
+
 extern "C" int
 pthread_attr_setstacksize (pthread_attr_t *attr, size_t size)
 {
   if (!pthread_attr::is_good_object (attr))
     return EINVAL;
+  if (size < PTHREAD_STACK_MIN)
+    return EINVAL;    
   (*attr)->stacksize = size;
   return 0;
 }
@@ -2381,6 +2405,51 @@ pthread::resume (pthread_t *thread)
   return 0;
 }
 
+extern "C" int
+pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
+{
+  const size_t sizeof_tbi = sizeof (THREAD_BASIC_INFORMATION);
+  PTHREAD_BASIC_INFORMATION tbi;
+  NTSTATUS ret;
+
+  if (!pthread::is_good_object (&thread))
+    return ESRCH;
+
+  /* attr may not be pre-initialized */
+  if (!pthread_attr::is_good_object (attr))
+  {
+    int rv = pthread_attr_init (attr);
+    if (rv != 0)
+      return rv;
+  }
+
+  (*attr)->joinable = thread->attr.joinable;
+  (*attr)->contentionscope = thread->attr.contentionscope;
+  (*attr)->inheritsched = thread->attr.inheritsched;
+  (*attr)->schedparam = thread->attr.schedparam;
+
+  tbi = (PTHREAD_BASIC_INFORMATION) malloc (sizeof_tbi);
+  ret = NtQueryInformationThread (thread->win32_obj_id, ThreadBasicInformation,
+                                  tbi, sizeof_tbi, NULL);
+
+  if (NT_SUCCESS (ret))
+    {
+      PNT_TIB tib = tbi->TebBaseAddress;
+      (*attr)->stackaddr = tib->StackBase;
+      /* stack grows downwards on x86 systems */
+      (*attr)->stacksize = (int)tib->StackBase - (int)tib->StackLimit;
+    }
+  else
+    {
+      debug_printf ("NtQueryInformationThread(ThreadBasicInformation), "
+                    "status %p", ret);
+      (*attr)->stackaddr = thread->attr.stackaddr;
+      (*attr)->stacksize = thread->attr.stacksize;
+    }
+
+  return 0;
+}
+
 /* provided for source level compatability.
    See http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_getconcurrency.html
 */
index 4ffbc4c01c7f3b1a4e4fc262c6fa1a2936f6281c..37296e5e5caa6f3fe35456ba3d1d2a3bdd372992 100644 (file)
@@ -250,6 +250,7 @@ public:
   int contentionscope;
   int inheritsched;
   struct sched_param schedparam;
+  void *stackaddr;
   size_t stacksize;
 
   pthread_attr ();
This page took 0.047183 seconds and 5 git commands to generate.