This is the mail archive of the
mailing list for the Cygwin project.
Re: (patch) makethread stdcall/cdecl confusion
- To: Mumit Khan <khan AT xraylith.wisc.EDU>
- Subject: Re: (patch) makethread stdcall/cdecl confusion
- From: Chris Faylor <cgf AT cygnus dot com>
- Date: Thu, 16 Sep 1999 12:23:11 -0400
- Cc: cygwin-developers AT sourceware.cygnus dot com
- References: <199909160435.XAA05754@mercury.xraylith.wisc.edu>
I don't understand. Why not just fix the functions whose addresses are
being passed to makethread by adding a WINAPI to each of those? The
makethread function was supposed to be similar to CreateThread so I think
it should take the same arguments.
It's interesting that this problem has been in cygwin for a very long time.
Prior to my creation of makethread, all of the functions were being passed
as arguments to CreateThread.
The other question is why didn't the compiler catch this problem?
So, unless I'm missing something, I have added a WINAPI to all of the
functions which are eventually called by thread_stub, as well as to
On Wed, Sep 15, 1999 at 11:35:00PM -0500, Mumit Khan wrote:
>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 <email@example.com>
> * 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.
>RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/debug.h,v
>retrieving revision 22.214.171.124
>diff -u -3 -p -r126.96.36.199 debug.h
>--- winsup/debug.h 1999/09/16 04:09:02 188.8.131.52
>+++ 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);
>RCS file: /homes/khan/src/CVSROOT/cygwin-dev/winsup/debug.cc,v
>retrieving revision 184.108.40.206
>diff -u -3 -p -r220.127.116.11 debug.cc
>--- winsup/debug.cc 1999/09/16 04:09:02 18.104.22.168
>+++ 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 WINAPI
> thread_stub (VOID *arg)
> exception_list except_entry;
>@@ -103,7 +103,7 @@ thread_stub (VOID *arg)
>-makethread (LPTHREAD_START_ROUTINE start, LPVOID param, DWORD flags,
>+makethread (DWORD (*start) (void *), LPVOID param, DWORD flags,
> const char *name)
> DWORD tid;