2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll thread functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*/
|
|
|
|
#include "msvcrt.h"
|
|
|
|
|
2001-10-08 22:32:41 +02:00
|
|
|
#include "msvcrt/malloc.h"
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "msvcrt/process.h"
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
DEFAULT_DEBUG_CHANNEL(msvcrt);
|
|
|
|
|
2001-06-19 05:46:27 +02:00
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
_beginthread_start_routine_t start_address;
|
|
|
|
void *arglist;
|
|
|
|
} _beginthread_trampoline_t;
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _beginthread_trampoline
|
|
|
|
*/
|
|
|
|
static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
|
|
|
|
{
|
2001-10-08 22:32:41 +02:00
|
|
|
_beginthread_trampoline_t local_trampoline;
|
|
|
|
|
|
|
|
/* Maybe it's just being paranoid, but freeing arg right
|
|
|
|
* away seems safer.
|
|
|
|
*/
|
|
|
|
memcpy(&local_trampoline,arg,sizeof(local_trampoline));
|
|
|
|
MSVCRT_free(arg);
|
|
|
|
|
|
|
|
local_trampoline.start_address(local_trampoline.arglist);
|
|
|
|
return 0;
|
2001-06-19 05:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _beginthread (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
unsigned long _beginthread(
|
|
|
|
_beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
|
|
|
|
unsigned int stack_size, /* [in] Stack size for new thread or 0 */
|
|
|
|
void *arglist) /* [in] Argument list to be passed to new thread or NULL */
|
|
|
|
{
|
2001-10-08 22:32:41 +02:00
|
|
|
_beginthread_trampoline_t* trampoline;
|
2001-06-19 05:46:27 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
|
|
|
|
|
2001-10-08 22:32:41 +02:00
|
|
|
/* Allocate the trampoline here so that it is still valid when the thread
|
|
|
|
* starts... typically after this function has returned.
|
|
|
|
* _beginthread_trampoline is responsible for freeing the trampoline
|
|
|
|
*/
|
|
|
|
trampoline=MSVCRT_malloc(sizeof(*trampoline));
|
|
|
|
trampoline->start_address = start_address;
|
|
|
|
trampoline->arglist = arglist;
|
2001-06-19 05:46:27 +02:00
|
|
|
|
|
|
|
/* FIXME */
|
2001-10-08 22:32:41 +02:00
|
|
|
return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
|
2001-06-19 05:46:27 +02:00
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _beginthreadex (MSVCRT.@)
|
|
|
|
*/
|
2001-06-19 05:46:27 +02:00
|
|
|
unsigned long _beginthreadex(
|
|
|
|
void *security, /* [in] Security descriptor for new thread; must be NULL for Windows 9x applications */
|
|
|
|
unsigned int stack_size, /* [in] Stack size for new thread or 0 */
|
|
|
|
_beginthreadex_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
|
|
|
|
void *arglist, /* [in] Argument list to be passed to new thread or NULL */
|
|
|
|
unsigned int initflag, /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
|
|
|
|
unsigned int *thrdaddr) /* [out] Points to a 32-bit variable that receives the thread identifier */
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
|
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
|
|
|
|
arglist, initflag, (LPDWORD) thrdaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _endthread (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void _endthread(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-06-19 05:46:27 +02:00
|
|
|
TRACE("(void)\n");
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/* FIXME */
|
2001-06-19 05:46:27 +02:00
|
|
|
ExitThread(0);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _endthreadex (MSVCRT.@)
|
|
|
|
*/
|
2001-06-19 05:46:27 +02:00
|
|
|
void _endthreadex(
|
|
|
|
unsigned int retval) /* [in] Thread exit code */
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2001-06-19 05:46:27 +02:00
|
|
|
TRACE("(%d)\n", retval);
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/* FIXME */
|
|
|
|
ExitThread(retval);
|
|
|
|
}
|
|
|
|
|