2 * msvcrt.dll thread functions
4 * Copyright 2000 Jon Griffiths
8 #include "msvcrt/malloc.h"
9 #include "msvcrt/process.h"
11 DEFAULT_DEBUG_CHANNEL(msvcrt);
13 /********************************************************************/
16 _beginthread_start_routine_t start_address;
18 } _beginthread_trampoline_t;
20 /*********************************************************************
21 * _beginthread_trampoline
23 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
25 _beginthread_trampoline_t local_trampoline;
27 /* Maybe it's just being paranoid, but freeing arg right
30 memcpy(&local_trampoline,arg,sizeof(local_trampoline));
33 local_trampoline.start_address(local_trampoline.arglist);
37 /*********************************************************************
38 * _beginthread (MSVCRT.@)
40 unsigned long _beginthread(
41 _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
42 unsigned int stack_size, /* [in] Stack size for new thread or 0 */
43 void *arglist) /* [in] Argument list to be passed to new thread or NULL */
45 _beginthread_trampoline_t* trampoline;
47 TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
49 /* Allocate the trampoline here so that it is still valid when the thread
50 * starts... typically after this function has returned.
51 * _beginthread_trampoline is responsible for freeing the trampoline
53 trampoline=MSVCRT_malloc(sizeof(*trampoline));
54 trampoline->start_address = start_address;
55 trampoline->arglist = arglist;
58 return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
61 /*********************************************************************
62 * _beginthreadex (MSVCRT.@)
64 unsigned long _beginthreadex(
65 void *security, /* [in] Security descriptor for new thread; must be NULL for Windows 9x applications */
66 unsigned int stack_size, /* [in] Stack size for new thread or 0 */
67 _beginthreadex_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
68 void *arglist, /* [in] Argument list to be passed to new thread or NULL */
69 unsigned int initflag, /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
70 unsigned int *thrdaddr) /* [out] Points to a 32-bit variable that receives the thread identifier */
72 TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
75 return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
76 arglist, initflag, (LPDWORD) thrdaddr);
79 /*********************************************************************
80 * _endthread (MSVCRT.@)
90 /*********************************************************************
91 * _endthreadex (MSVCRT.@)
94 unsigned int retval) /* [in] Thread exit code */
96 TRACE("(%d)\n", retval);