2 * msvcrt.dll thread functions
4 * Copyright 2000 Jon Griffiths
8 #include "msvcrt/malloc.h"
9 #include "msvcrt/process.h"
11 #include "wine/debug.h"
13 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
15 /********************************************************************/
18 _beginthread_start_routine_t start_address;
20 } _beginthread_trampoline_t;
22 /*********************************************************************
23 * _beginthread_trampoline
25 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
27 _beginthread_trampoline_t local_trampoline;
29 /* Maybe it's just being paranoid, but freeing arg right
32 memcpy(&local_trampoline,arg,sizeof(local_trampoline));
35 local_trampoline.start_address(local_trampoline.arglist);
39 /*********************************************************************
40 * _beginthread (MSVCRT.@)
42 unsigned long _beginthread(
43 _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
44 unsigned int stack_size, /* [in] Stack size for new thread or 0 */
45 void *arglist) /* [in] Argument list to be passed to new thread or NULL */
47 _beginthread_trampoline_t* trampoline;
49 TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
51 /* Allocate the trampoline here so that it is still valid when the thread
52 * starts... typically after this function has returned.
53 * _beginthread_trampoline is responsible for freeing the trampoline
55 trampoline=MSVCRT_malloc(sizeof(*trampoline));
56 trampoline->start_address = start_address;
57 trampoline->arglist = arglist;
60 return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
63 /*********************************************************************
64 * _beginthreadex (MSVCRT.@)
66 unsigned long _beginthreadex(
67 void *security, /* [in] Security descriptor for new thread; must be NULL for Windows 9x applications */
68 unsigned int stack_size, /* [in] Stack size for new thread or 0 */
69 _beginthreadex_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
70 void *arglist, /* [in] Argument list to be passed to new thread or NULL */
71 unsigned int initflag, /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
72 unsigned int *thrdaddr) /* [out] Points to a 32-bit variable that receives the thread identifier */
74 TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
77 return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
78 arglist, initflag, (LPDWORD) thrdaddr);
81 /*********************************************************************
82 * _endthread (MSVCRT.@)
92 /*********************************************************************
93 * _endthreadex (MSVCRT.@)
96 unsigned int retval) /* [in] Thread exit code */
98 TRACE("(%d)\n", retval);