www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/09/16/01:47:31

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-developers-unsubscribe-archive-cygwin-developers=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-Id: <199909160435.XAA05754@mercury.xraylith.wisc.edu>
To: cygwin-developers AT sourceware DOT cygnus DOT com
Subject: (patch) makethread stdcall/cdecl confusion
Date: Wed, 15 Sep 1999 23:35:00 -0500
From: Mumit Khan <khan AT xraylith DOT wisc DOT EDU>

The current makethread code confuses stdcall vs cdecl calling conventions
that can lead to subtle stack corruption.

The user thread callbacks (supplied by the callers of makethread) are
cdecl, but those currently incorrectly prototyped in "thread_start"
struct as stdcall.

CreateThread takes a stdcall thread start function, but thread_stub, the
callback is prototyped incorrectly as cdecl.

Basically, turn it upside down.

Wed Sep 15 21:37:15 1999  Mumit Khan  <khan AT xraylith DOT wisc DOT edu>

	* debug.h (makethread): The first parameter is a pointer to a
	cdecl, not stdcall, function. 
	* debug.cc (makethread): Likewise.
	(thread_start): Change type of func to be cdecl.
	(thread_stub): Fix prototype to be stdcall.

Index: winsup/debug.h
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/debug.h,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 debug.h
--- winsup/debug.h	1999/09/16 04:09:02	1.1.1.1
+++ winsup/debug.h	1999/09/16 04:10:02
@@ -24,7 +24,7 @@ DWORD WFMO (DWORD, CONST HANDLE *, BOOL,
 #if !defined(_DEBUG_H_)
 #define _DEBUG_H_
 
-HANDLE makethread (LPTHREAD_START_ROUTINE, LPVOID, DWORD, const char *);
+HANDLE makethread (DWORD (*) (void*), LPVOID, DWORD, const char *);
 const char *threadname (DWORD, int lockit = TRUE);
 void regthread (const char *, DWORD);
 
Index: winsup/debug.cc
===================================================================
RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/debug.cc,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 debug.cc
--- winsup/debug.cc	1999/09/16 04:09:02	1.1.1.1
+++ winsup/debug.cc	1999/09/16 04:10:02
@@ -57,7 +57,7 @@ typedef struct
 
 typedef struct
   {
-    LPTHREAD_START_ROUTINE func;
+    DWORD (*func) (void*);
     VOID *arg;
     HANDLE sync;
   } thread_start;
@@ -80,7 +80,7 @@ regthread (const char *name, DWORD tid)
   __tn.unlock ();
 }
 
-static DWORD
+static DWORD WINAPI
 thread_stub (VOID *arg)
 {
   exception_list except_entry;
@@ -103,7 +103,7 @@ thread_stub (VOID *arg)
 }
 
 HANDLE
-makethread (LPTHREAD_START_ROUTINE start, LPVOID param, DWORD flags,
+makethread (DWORD (*start) (void *), LPVOID param, DWORD flags,
 	    const char *name)
 {
   DWORD tid;

Regards,
Mumit

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019