2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll thread functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
|
|
|
#include "msvcrt.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-06-19 05:46:27 +02:00
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
2004-06-25 03:19:15 +02:00
|
|
|
MSVCRT__beginthread_start_routine_t start_address;
|
2001-06-19 05:46:27 +02:00
|
|
|
void *arglist;
|
|
|
|
} _beginthread_trampoline_t;
|
|
|
|
|
2002-07-19 05:24:50 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* msvcrt_get_thread_data
|
|
|
|
*
|
|
|
|
* Return the thread local storage structure.
|
|
|
|
*/
|
2004-06-25 03:19:15 +02:00
|
|
|
thread_data_t *msvcrt_get_thread_data(void)
|
2002-07-19 05:24:50 +02:00
|
|
|
{
|
2004-06-25 03:19:15 +02:00
|
|
|
thread_data_t *ptr;
|
2002-07-19 05:24:50 +02:00
|
|
|
DWORD err = GetLastError(); /* need to preserve last error */
|
|
|
|
|
2004-06-25 03:19:15 +02:00
|
|
|
if (!(ptr = TlsGetValue( msvcrt_tls_index )))
|
2002-07-19 05:24:50 +02:00
|
|
|
{
|
|
|
|
if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptr) )))
|
2004-06-25 03:19:15 +02:00
|
|
|
_amsg_exit( _RT_THREAD );
|
|
|
|
if (!TlsSetValue( msvcrt_tls_index, ptr )) _amsg_exit( _RT_THREAD );
|
2006-01-14 17:27:28 +01:00
|
|
|
ptr->random_seed = 1;
|
2002-07-19 05:24:50 +02:00
|
|
|
}
|
|
|
|
SetLastError( err );
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-19 05:46:27 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _beginthread_trampoline
|
|
|
|
*/
|
|
|
|
static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
|
|
|
|
{
|
2001-10-08 22:32:41 +02:00
|
|
|
_beginthread_trampoline_t local_trampoline;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Maybe it's just being paranoid, but freeing arg right
|
|
|
|
* away seems safer.
|
2001-10-08 22:32:41 +02:00
|
|
|
*/
|
|
|
|
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.@)
|
|
|
|
*/
|
2005-11-03 14:17:51 +01:00
|
|
|
MSVCRT_uintptr_t _beginthread(
|
2004-06-25 03:19:15 +02:00
|
|
|
MSVCRT__beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
|
2001-06-19 05:46:27 +02:00
|
|
|
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);
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Allocate the trampoline here so that it is still valid when the thread
|
2001-10-08 22:32:41 +02:00
|
|
|
* 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 */
|
2005-11-03 14:17:51 +01:00
|
|
|
return (MSVCRT_uintptr_t)CreateThread(NULL, stack_size, _beginthread_trampoline,
|
2002-10-25 05:12:01 +02:00
|
|
|
trampoline, 0, NULL);
|
2001-06-19 05:46:27 +02:00
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _beginthreadex (MSVCRT.@)
|
|
|
|
*/
|
2005-11-03 14:17:51 +01:00
|
|
|
MSVCRT_uintptr_t _beginthreadex(
|
2001-06-19 05:46:27 +02:00
|
|
|
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 */
|
2004-06-25 03:19:15 +02:00
|
|
|
MSVCRT__beginthreadex_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
|
2001-06-19 05:46:27 +02:00
|
|
|
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 */
|
2005-11-03 14:17:51 +01:00
|
|
|
return (MSVCRT_uintptr_t)CreateThread(security, stack_size,
|
2002-10-25 05:12:01 +02:00
|
|
|
(LPTHREAD_START_ROUTINE) start_address,
|
|
|
|
arglist, initflag, (LPDWORD) thrdaddr);
|
2001-06-19 05:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _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);
|
|
|
|
}
|