fixes bug 216021 "chekesp error if i link against a msvcrt that is built with strict calling rules" patch=wtc r=darin NSPRPUB_PRE_4_2_CLIENT_BRANCH THUNDERBIRD_M3_BASE
authordarin%meer.net
Tue, 18 Nov 2003 09:46:37 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 2974 4ff42520294774cd287925cdd125d4a08da4e690
parent 2972 cb0548eb51be8c082307bcef10615bc3c88c1273
child 2975 b1501160fd1436aeabab2b56165d584a1a057d5e
child 2988 2f0f13ae63dce3bd324a942564abf7b3d795db78
push idunknown
push userunknown
push dateunknown
reviewersdarin
bugs216021
fixes bug 216021 "chekesp error if i link against a msvcrt that is built with strict calling rules" patch=wtc r=darin
config/prdepend.h
pr/include/md/_win95.h
pr/include/md/_winnt.h
pr/src/md/windows/ntthread.c
pr/src/md/windows/w95thred.c
--- a/config/prdepend.h
+++ b/config/prdepend.h
@@ -34,9 +34,8 @@
 
 /*
  * A dummy header file that is a dependency for all the object files.
  * Used to force a full recompilation of NSPR in Mozilla's Tinderbox
  * depend builds.  See comments in rules.mk.
  */
 
 #error "Do not include this header file."
-
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -107,16 +107,19 @@ struct _MDThread {
     HANDLE           handle;            /* Win32 thread handle */
     PRUint32         id;
     void            *sp;                /* only valid when suspended */
     PRUint32         magic;             /* for debugging */
     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
     struct PRThread *prev, *next;       /* used by the cvar wait queue to
                                          * chain the PRThread structures
                                          * together */
+    void (*start)(void *);              /* used by _PR_MD_CREATE_THREAD to
+                                         * pass its 'start' argument to
+                                         * pr_root. */
 };
 
 struct _MDThreadStack {
     PRUint32           magic;          /* for debugging */
 };
 
 struct _MDSegment {
     PRUint32           magic;          /* for debugging */
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -167,16 +167,19 @@ struct _MDThread {
 											thread blocks on this event		*/
 
     /* The following are used only if this is a fiber */
     void            *fiber_id;          /* flag whether or not this is a fiber*/
     FiberFunc        fiber_fn;          /* main fiber routine */
     void            *fiber_arg;         /* arg to main fiber routine */
     PRUint32         fiber_stacksize;   /* stacksize for fiber */
     PRInt32          fiber_last_error;  /* last error for the fiber */
+    void (*start)(void *);              /* used by _PR_MD_CREATE_THREAD to
+                                         * pass its 'start' argument to
+                                         * pr_root. */
 };
 
 struct _MDThreadStack {
     PRUint32           magic;          /* for debugging */
 };
 
 struct _MDSegment {
     PRUint32           magic;          /* for debugging */
--- a/pr/src/md/windows/ntthread.c
+++ b/pr/src/md/windows/ntthread.c
@@ -186,42 +186,41 @@ PRStatus
 				return PR_FAILURE;
 			}
 		}
     }
 
     return PR_SUCCESS;
 }
 
+static unsigned __stdcall
+pr_root(void *arg)
+{
+    PRThread *thread = (PRThread *)arg;
+    thread->md.start(thread);
+    return 0;
+}
+
 PRStatus 
 _PR_MD_CREATE_THREAD(PRThread *thread, 
                   void (*start)(void *), 
                   PRThreadPriority priority, 
                   PRThreadScope scope, 
                   PRThreadState state, 
                   PRUint32 stackSize)
 {
 
-#if 0
-    thread->md.handle = CreateThread(
-                    NULL,                             /* security attrib */
-                    thread->stack->stackSize,         /* stack size      */
-                    (LPTHREAD_START_ROUTINE)start,    /* startup routine */
-                    (void *)thread,                   /* thread param    */
-                    CREATE_SUSPENDED,                 /* create flags    */
-                    &(thread->id) );                  /* thread id       */
-#else
+    thread->md.start = start;
     thread->md.handle = (HANDLE) _beginthreadex(
                     NULL,
                     thread->stack->stackSize,
-                    (unsigned (__stdcall *)(void *))start,
+                    pr_root,
                     (void *)thread,
                     CREATE_SUSPENDED,
                     &(thread->id));
-#endif
     if(!thread->md.handle) {
         PRErrorCode prerror;
         thread->md.fiber_last_error = GetLastError();
         switch (errno) {
             case ENOMEM:
                 prerror = PR_OUT_OF_MEMORY_ERROR;
                 break;
             case EAGAIN:
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -101,33 +101,38 @@ PRStatus
     /* Create the blocking IO semaphore */
     thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
     if (thread->md.blocked_sema == NULL)
         return PR_FAILURE;
 	else
 		return PR_SUCCESS;
 }
 
+static unsigned __stdcall
+pr_root(void *arg)
+{
+    PRThread *thread = (PRThread *)arg;
+    thread->md.start(thread);
+    return 0;
+}
+
 PRStatus 
 _PR_MD_CREATE_THREAD(PRThread *thread, 
                   void (*start)(void *), 
                   PRThreadPriority priority, 
                   PRThreadScope scope, 
                   PRThreadState state, 
                   PRUint32 stackSize)
 {
 
+    thread->md.start = start;
     thread->md.handle = (HANDLE) _beginthreadex(
                     NULL,
                     thread->stack->stackSize,
-#if defined(__MINGW32__)
-                    (void *)start,
-#else
-                    (unsigned (__stdcall *)(void *))start,
-#endif
+                    pr_root,
                     (void *)thread,
                     CREATE_SUSPENDED,
                     &(thread->id));
     if(!thread->md.handle) {
         return PR_FAILURE;
     }
 
     thread->md.id = thread->id;