Other winpthreads tests (pthread_cancel and pthread_exit) are already doing it.

It is needed for older msvcrt.dll library used on WinNT and Win9x systems
which indirectly via CreateThread function always dereference passed
address and stores there the thread id. So NULL value with those older
msvcrt.dll version cause process crash and needs to be avoided.
---
 mingw-w64-libraries/winpthreads/src/thread.c              | 3 ++-
 mingw-w64-libraries/winpthreads/tests/clock/t_nanosleep.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/src/thread.c 
b/mingw-w64-libraries/winpthreads/src/thread.c
index 01b093cd461e..3251c2cbb9c5 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -1593,6 +1593,7 @@ pthread_create (pthread_t *th, const pthread_attr_t 
*attr, void *(* func)(void *
   struct _pthread_v *tv;
   unsigned int ssize = 0;
   pthread_spinlock_t new_spin_keys = PTHREAD_SPINLOCK_INITIALIZER;
+  unsigned thrAddr; /* Dummy variable to pass a valid location to 
_beginthreadex (Win98). */
 
   if (attr && attr->s_size > UINT_MAX)
     return EINVAL;
@@ -1649,7 +1650,7 @@ pthread_create (pthread_t *th, const pthread_attr_t 
*attr, void *(* func)(void *
   /* Make sure tv->h has value of INVALID_HANDLE_VALUE */
   _ReadWriteBarrier();
 
-  thrd = (HANDLE) _beginthreadex(NULL, ssize, pthread_create_wrapper, tv, 
0x4/*CREATE_SUSPEND*/, NULL);
+  thrd = (HANDLE) _beginthreadex(NULL, ssize, pthread_create_wrapper, tv, 
0x4/*CREATE_SUSPEND*/, &thrAddr);
   if (thrd == INVALID_HANDLE_VALUE)
     thrd = 0;
   /* Failed */
diff --git a/mingw-w64-libraries/winpthreads/tests/clock/t_nanosleep.c 
b/mingw-w64-libraries/winpthreads/tests/clock/t_nanosleep.c
index 4afe566ad16a..3075bde92f91 100644
--- a/mingw-w64-libraries/winpthreads/tests/clock/t_nanosleep.c
+++ b/mingw-w64-libraries/winpthreads/tests/clock/t_nanosleep.c
@@ -49,8 +49,9 @@ void test_apc()
 {
     long i, rc, data[5];
     HANDLE thread;
+    unsigned thrAddr; /* Dummy variable to pass a valid location to 
_beginthreadex (Win98). */
 
-    thread = (HANDLE) _beginthreadex(NULL, 0, start_address, NULL, 0, NULL);
+    thread = (HANDLE) _beginthreadex(NULL, 0, start_address, NULL, 0, 
&thrAddr);
     if (thread == NULL) {
         exit(1);
     }
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to