2003-04-05 00:26:34 +02:00
|
|
|
/*
|
|
|
|
* NT threads support
|
|
|
|
*
|
|
|
|
* Copyright 1996, 2003 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* 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
|
2003-04-05 00:26:34 +02:00
|
|
|
*/
|
|
|
|
|
2003-10-09 06:59:03 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2006-07-21 20:20:30 +02:00
|
|
|
#include <assert.h>
|
2003-11-04 05:50:18 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
2005-09-13 00:01:33 +02:00
|
|
|
#ifdef HAVE_SYS_TIMES_H
|
|
|
|
#include <sys/times.h>
|
|
|
|
#endif
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2005-11-05 11:43:50 +01:00
|
|
|
#define NONAMELESSUNION
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2003-08-28 21:57:35 +02:00
|
|
|
#include "thread.h"
|
2003-04-05 00:26:34 +02:00
|
|
|
#include "winternl.h"
|
2003-10-09 06:59:03 +02:00
|
|
|
#include "wine/library.h"
|
2003-04-05 00:26:34 +02:00
|
|
|
#include "wine/server.h"
|
2003-11-06 00:31:11 +01:00
|
|
|
#include "wine/pthread.h"
|
2003-07-09 04:57:57 +02:00
|
|
|
#include "wine/debug.h"
|
2003-11-04 05:50:18 +01:00
|
|
|
#include "ntdll_misc.h"
|
2006-03-14 15:35:21 +01:00
|
|
|
#include "wine/exception.h"
|
2003-07-09 04:57:57 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(thread);
|
2003-04-05 00:26:34 +02:00
|
|
|
|
2003-11-25 04:42:05 +01:00
|
|
|
/* info passed to a starting thread */
|
|
|
|
struct startup_info
|
|
|
|
{
|
|
|
|
struct wine_pthread_thread_info pthread_info;
|
|
|
|
PRTL_THREAD_START_ROUTINE entry_point;
|
|
|
|
void *entry_arg;
|
|
|
|
};
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
static PEB_LDR_DATA ldr;
|
|
|
|
static RTL_USER_PROCESS_PARAMETERS params; /* default parameters if no parent */
|
2005-07-14 14:33:30 +02:00
|
|
|
static WCHAR current_dir[MAX_NT_PATH_LENGTH];
|
2003-11-04 05:50:18 +01:00
|
|
|
static RTL_BITMAP tls_bitmap;
|
2005-03-19 18:14:12 +01:00
|
|
|
static RTL_BITMAP tls_expansion_bitmap;
|
2003-11-04 05:50:18 +01:00
|
|
|
static LIST_ENTRY tls_links;
|
2005-09-14 12:36:58 +02:00
|
|
|
static size_t sigstack_total_size;
|
2006-07-21 20:20:30 +02:00
|
|
|
static ULONG sigstack_zero_bits;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2005-09-03 17:11:29 +02:00
|
|
|
struct wine_pthread_functions pthread_functions = { NULL };
|
2003-11-04 05:50:18 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2005-08-09 12:43:47 +02:00
|
|
|
* init_teb
|
2003-11-04 05:50:18 +01:00
|
|
|
*/
|
2005-08-09 12:43:47 +02:00
|
|
|
static inline NTSTATUS init_teb( TEB *teb )
|
2003-11-04 05:50:18 +01:00
|
|
|
{
|
2005-08-09 12:43:47 +02:00
|
|
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
2006-01-20 16:18:06 +01:00
|
|
|
struct ntdll_thread_regs *thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
|
|
|
teb->Tib.ExceptionList = (void *)~0UL;
|
2003-11-06 00:31:11 +01:00
|
|
|
teb->Tib.StackBase = (void *)~0UL;
|
2003-11-04 05:50:18 +01:00
|
|
|
teb->Tib.Self = &teb->Tib;
|
|
|
|
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
|
|
|
|
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
|
2005-08-09 12:43:47 +02:00
|
|
|
|
2006-01-20 16:18:06 +01:00
|
|
|
if (!(thread_regs->fs = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
|
2005-08-09 12:43:47 +02:00
|
|
|
thread_data->request_fd = -1;
|
|
|
|
thread_data->reply_fd = -1;
|
|
|
|
thread_data->wait_fd[0] = -1;
|
|
|
|
thread_data->wait_fd[1] = -1;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2003-11-04 05:50:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* free_teb
|
|
|
|
*/
|
|
|
|
static inline void free_teb( TEB *teb )
|
|
|
|
{
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T size = 0;
|
2003-11-04 05:50:18 +01:00
|
|
|
void *addr = teb;
|
2006-01-20 16:18:06 +01:00
|
|
|
struct ntdll_thread_regs *thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2005-02-22 20:33:50 +01:00
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
|
2006-01-20 16:18:06 +01:00
|
|
|
wine_ldt_free_fs( thread_regs->fs );
|
2005-09-14 12:36:58 +02:00
|
|
|
munmap( teb, sigstack_total_size );
|
2003-11-04 05:50:18 +01:00
|
|
|
}
|
|
|
|
|
2003-04-05 00:26:34 +02:00
|
|
|
|
2006-02-22 09:57:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fix_unicode_string
|
|
|
|
*
|
|
|
|
* Make sure the unicode string doesn't point beyond the end pointer
|
|
|
|
*/
|
|
|
|
static inline void fix_unicode_string( UNICODE_STRING *str, char *end_ptr )
|
|
|
|
{
|
|
|
|
if ((char *)str->Buffer >= end_ptr)
|
|
|
|
{
|
|
|
|
str->Length = str->MaximumLength = 0;
|
|
|
|
str->Buffer = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((char *)str->Buffer + str->MaximumLength > end_ptr)
|
|
|
|
{
|
|
|
|
str->MaximumLength = (end_ptr - (char *)str->Buffer) & ~(sizeof(WCHAR) - 1);
|
|
|
|
}
|
|
|
|
if (str->Length >= str->MaximumLength)
|
|
|
|
{
|
|
|
|
if (str->MaximumLength >= sizeof(WCHAR))
|
|
|
|
str->Length = str->MaximumLength - sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
str->Length = str->MaximumLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* init_user_process_params
|
|
|
|
*
|
|
|
|
* Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
|
|
|
|
*/
|
|
|
|
static NTSTATUS init_user_process_params( SIZE_T info_size, HANDLE *exe_file )
|
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
SIZE_T env_size;
|
|
|
|
NTSTATUS status;
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = NULL;
|
|
|
|
|
|
|
|
status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)¶ms, 0, &info_size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE );
|
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
|
|
|
|
params->AllocationSize = info_size;
|
2006-07-24 15:19:32 +02:00
|
|
|
NtCurrentTeb()->Peb->ProcessParameters = params;
|
2006-02-22 09:57:19 +01:00
|
|
|
|
|
|
|
SERVER_START_REQ( get_startup_info )
|
|
|
|
{
|
|
|
|
wine_server_set_reply( req, params, info_size );
|
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
info_size = wine_server_reply_size( reply );
|
|
|
|
*exe_file = reply->exe_file;
|
|
|
|
params->hStdInput = reply->hstdin;
|
|
|
|
params->hStdOutput = reply->hstdout;
|
|
|
|
params->hStdError = reply->hstderr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
|
|
|
|
if (params->Size > info_size) params->Size = info_size;
|
|
|
|
|
|
|
|
/* make sure the strings are valid */
|
|
|
|
fix_unicode_string( ¶ms->CurrentDirectory.DosPath, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->DllPath, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->ImagePathName, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->CommandLine, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->WindowTitle, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->Desktop, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->ShellInfo, (char *)info_size );
|
|
|
|
fix_unicode_string( ¶ms->RuntimeInfo, (char *)info_size );
|
|
|
|
|
|
|
|
/* environment needs to be a separate memory block */
|
|
|
|
env_size = info_size - params->Size;
|
|
|
|
if (!env_size) env_size = 1;
|
|
|
|
ptr = NULL;
|
|
|
|
status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &env_size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE );
|
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
memcpy( ptr, (char *)params + params->Size, info_size - params->Size );
|
|
|
|
params->Environment = ptr;
|
|
|
|
|
|
|
|
RtlNormalizeProcessParams( params );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-09 06:59:03 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* thread_init
|
|
|
|
*
|
|
|
|
* Setup the initial thread.
|
|
|
|
*
|
|
|
|
* NOTES: The first allocated TEB on NT is at 0x7ffde000.
|
|
|
|
*/
|
2006-02-22 09:57:19 +01:00
|
|
|
HANDLE thread_init(void)
|
2003-10-09 06:59:03 +02:00
|
|
|
{
|
2006-07-24 15:19:32 +02:00
|
|
|
PEB *peb;
|
2003-11-04 05:50:18 +01:00
|
|
|
TEB *teb;
|
|
|
|
void *addr;
|
2006-07-24 15:19:32 +02:00
|
|
|
SIZE_T size, info_size;
|
2006-02-22 09:57:19 +01:00
|
|
|
HANDLE exe_file = 0;
|
2005-06-06 22:04:33 +02:00
|
|
|
struct ntdll_thread_data *thread_data;
|
2006-01-20 16:18:06 +01:00
|
|
|
struct ntdll_thread_regs *thread_regs;
|
2003-11-09 02:25:23 +01:00
|
|
|
struct wine_pthread_thread_info thread_info;
|
2003-11-06 01:08:05 +01:00
|
|
|
static struct debug_info debug_info; /* debug info for initial thread */
|
2003-10-09 06:59:03 +02:00
|
|
|
|
2006-07-24 15:19:32 +02:00
|
|
|
virtual_init();
|
|
|
|
|
|
|
|
/* reserve space for shared user data */
|
|
|
|
|
|
|
|
addr = (void *)0x7ffe0000;
|
|
|
|
size = 0x10000;
|
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, &size, MEM_RESERVE, PAGE_READONLY );
|
|
|
|
|
|
|
|
/* allocate and initialize the PEB */
|
|
|
|
|
|
|
|
addr = NULL;
|
|
|
|
size = sizeof(*peb);
|
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 1, &size,
|
|
|
|
MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE );
|
|
|
|
peb = addr;
|
|
|
|
|
|
|
|
peb->NumberOfProcessors = 1;
|
|
|
|
peb->ProcessParameters = ¶ms;
|
|
|
|
peb->TlsBitmap = &tls_bitmap;
|
|
|
|
peb->TlsExpansionBitmap = &tls_expansion_bitmap;
|
|
|
|
peb->LdrData = &ldr;
|
2005-07-14 14:33:30 +02:00
|
|
|
params.CurrentDirectory.DosPath.Buffer = current_dir;
|
|
|
|
params.CurrentDirectory.DosPath.MaximumLength = sizeof(current_dir);
|
2005-11-14 12:21:13 +01:00
|
|
|
params.wShowWindow = 1; /* SW_SHOWNORMAL */
|
2006-07-24 15:19:32 +02:00
|
|
|
RtlInitializeBitMap( &tls_bitmap, peb->TlsBitmapBits, sizeof(peb->TlsBitmapBits) * 8 );
|
|
|
|
RtlInitializeBitMap( &tls_expansion_bitmap, peb->TlsExpansionBitmapBits,
|
|
|
|
sizeof(peb->TlsExpansionBitmapBits) * 8 );
|
2003-10-09 06:59:03 +02:00
|
|
|
InitializeListHead( &ldr.InLoadOrderModuleList );
|
|
|
|
InitializeListHead( &ldr.InMemoryOrderModuleList );
|
|
|
|
InitializeListHead( &ldr.InInitializationOrderModuleList );
|
2003-11-04 05:50:18 +01:00
|
|
|
InitializeListHead( &tls_links );
|
|
|
|
|
2006-07-24 15:19:32 +02:00
|
|
|
/* allocate and initialize the initial TEB */
|
|
|
|
|
2005-09-14 12:36:58 +02:00
|
|
|
sigstack_total_size = get_signal_stack_total_size();
|
2006-07-21 20:20:30 +02:00
|
|
|
while (1 << sigstack_zero_bits < sigstack_total_size) sigstack_zero_bits++;
|
|
|
|
assert( 1 << sigstack_zero_bits == sigstack_total_size ); /* must be a power of 2 */
|
2005-09-14 12:36:58 +02:00
|
|
|
thread_info.teb_size = sigstack_total_size;
|
2006-07-24 15:19:32 +02:00
|
|
|
|
|
|
|
addr = NULL;
|
|
|
|
size = sigstack_total_size;
|
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
|
|
|
|
&size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE );
|
2005-08-09 12:43:47 +02:00
|
|
|
teb = addr;
|
2006-07-24 15:19:32 +02:00
|
|
|
teb->Peb = peb;
|
|
|
|
thread_info.teb_size = size;
|
2005-08-09 12:43:47 +02:00
|
|
|
init_teb( teb );
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
2006-01-20 16:18:06 +01:00
|
|
|
thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data->debug_info = &debug_info;
|
2003-11-04 05:50:18 +01:00
|
|
|
InsertHeadList( &tls_links, &teb->TlsLinks );
|
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
thread_info.stack_base = NULL;
|
|
|
|
thread_info.stack_size = 0;
|
|
|
|
thread_info.teb_base = teb;
|
2006-01-20 16:18:06 +01:00
|
|
|
thread_info.teb_sel = thread_regs->fs;
|
2005-09-03 17:11:29 +02:00
|
|
|
wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) );
|
|
|
|
pthread_functions.init_current_teb( &thread_info );
|
|
|
|
pthread_functions.init_thread( &thread_info );
|
2006-07-24 15:19:32 +02:00
|
|
|
virtual_init_threading();
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2004-01-07 05:50:11 +01:00
|
|
|
debug_info.str_pos = debug_info.strings;
|
|
|
|
debug_info.out_pos = debug_info.output;
|
|
|
|
debug_init();
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
/* setup the server connection */
|
2003-11-06 01:08:05 +01:00
|
|
|
server_init_process();
|
2005-07-13 21:43:35 +02:00
|
|
|
info_size = server_init_thread( thread_info.pid, thread_info.tid, NULL );
|
2003-10-09 06:59:03 +02:00
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
/* create the process heap */
|
2006-07-24 15:19:32 +02:00
|
|
|
if (!(peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
|
2003-11-04 05:50:18 +01:00
|
|
|
{
|
|
|
|
MESSAGE( "wine: failed to create the process heap\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-07-14 14:33:30 +02:00
|
|
|
|
|
|
|
/* allocate user parameters */
|
|
|
|
if (info_size)
|
|
|
|
{
|
2006-02-22 09:57:19 +01:00
|
|
|
init_user_process_params( info_size, &exe_file );
|
2005-07-14 14:33:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is wine specific: we have no parent (we're started from unix)
|
|
|
|
* so, create a simple console with bare handles to unix stdio
|
|
|
|
*/
|
2005-12-09 12:22:35 +01:00
|
|
|
wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, OBJ_INHERIT, ¶ms.hStdInput );
|
|
|
|
wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, ¶ms.hStdOutput );
|
|
|
|
wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, ¶ms.hStdError );
|
2005-07-14 14:33:30 +02:00
|
|
|
}
|
2006-02-22 09:57:19 +01:00
|
|
|
return exe_file;
|
2003-10-09 06:59:03 +02:00
|
|
|
}
|
|
|
|
|
2006-09-20 11:26:59 +02:00
|
|
|
typedef LONG (WINAPI *PUNHANDLED_EXCEPTION_FILTER)(PEXCEPTION_POINTERS);
|
2006-03-14 15:35:21 +01:00
|
|
|
static PUNHANDLED_EXCEPTION_FILTER get_unhandled_exception_filter(void)
|
|
|
|
{
|
|
|
|
static PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter;
|
|
|
|
static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
|
|
|
|
UNICODE_STRING module_name;
|
|
|
|
ANSI_STRING func_name;
|
|
|
|
HMODULE kernel32_handle;
|
|
|
|
|
|
|
|
if (unhandled_exception_filter) return unhandled_exception_filter;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&module_name, kernel32W);
|
|
|
|
RtlInitAnsiString( &func_name, "UnhandledExceptionFilter" );
|
|
|
|
|
|
|
|
if (LdrGetDllHandle( 0, 0, &module_name, &kernel32_handle ) == STATUS_SUCCESS)
|
|
|
|
LdrGetProcedureAddress( kernel32_handle, &func_name, 0,
|
|
|
|
(void **)&unhandled_exception_filter );
|
|
|
|
|
|
|
|
return unhandled_exception_filter;
|
|
|
|
}
|
2003-10-09 06:59:03 +02:00
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* start_thread
|
|
|
|
*
|
|
|
|
* Startup routine for a newly created thread.
|
|
|
|
*/
|
2003-11-06 00:31:11 +01:00
|
|
|
static void start_thread( struct wine_pthread_thread_info *info )
|
2003-10-31 01:16:20 +01:00
|
|
|
{
|
2003-11-06 00:31:11 +01:00
|
|
|
TEB *teb = info->teb_base;
|
2005-06-06 22:04:33 +02:00
|
|
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
2003-11-25 04:42:05 +01:00
|
|
|
struct startup_info *startup_info = (struct startup_info *)info;
|
|
|
|
PRTL_THREAD_START_ROUTINE func = startup_info->entry_point;
|
|
|
|
void *arg = startup_info->entry_arg;
|
2003-11-06 00:31:11 +01:00
|
|
|
struct debug_info debug_info;
|
2005-12-12 17:28:32 +01:00
|
|
|
SIZE_T size, page_size = getpagesize();
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2003-11-06 00:31:11 +01:00
|
|
|
debug_info.str_pos = debug_info.strings;
|
|
|
|
debug_info.out_pos = debug_info.output;
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data->debug_info = &debug_info;
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2005-09-03 17:11:29 +02:00
|
|
|
pthread_functions.init_current_teb( info );
|
2003-10-31 01:16:20 +01:00
|
|
|
SIGNAL_Init();
|
2003-11-25 04:42:05 +01:00
|
|
|
server_init_thread( info->pid, info->tid, func );
|
2005-09-03 17:11:29 +02:00
|
|
|
pthread_functions.init_thread( info );
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2003-11-06 00:31:11 +01:00
|
|
|
/* allocate a memory view for the stack */
|
|
|
|
size = info->stack_size;
|
2004-10-11 22:59:06 +02:00
|
|
|
teb->DeallocationStack = info->stack_base;
|
2005-02-22 20:33:50 +01:00
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, 0,
|
2005-06-21 11:57:53 +02:00
|
|
|
&size, MEM_SYSTEM, PAGE_READWRITE );
|
2003-11-06 00:31:11 +01:00
|
|
|
/* limit is lower than base since the stack grows down */
|
|
|
|
teb->Tib.StackBase = (char *)info->stack_base + info->stack_size;
|
2005-12-12 17:28:32 +01:00
|
|
|
teb->Tib.StackLimit = (char *)info->stack_base + page_size;
|
2003-11-06 00:31:11 +01:00
|
|
|
|
|
|
|
/* setup the guard page */
|
2005-12-12 17:28:32 +01:00
|
|
|
size = page_size;
|
2005-12-17 18:47:03 +01:00
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size, PAGE_NOACCESS, NULL );
|
2003-11-06 00:31:11 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
InsertHeadList( &tls_links, &teb->TlsLinks );
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
2006-03-14 15:35:21 +01:00
|
|
|
/* NOTE: Windows does not have an exception handler around the call to
|
|
|
|
* the thread attach. We do for ease of debugging */
|
|
|
|
if (get_unhandled_exception_filter())
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
MODULE_DllThreadAttach( NULL );
|
|
|
|
}
|
|
|
|
__EXCEPT(get_unhandled_exception_filter())
|
|
|
|
{
|
|
|
|
NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
}
|
|
|
|
else
|
|
|
|
MODULE_DllThreadAttach( NULL );
|
|
|
|
|
2003-11-25 04:42:05 +01:00
|
|
|
func( arg );
|
2003-10-31 01:16:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlCreateUserThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *descr,
|
|
|
|
BOOLEAN suspended, PVOID stack_addr,
|
|
|
|
SIZE_T stack_reserve, SIZE_T stack_commit,
|
|
|
|
PRTL_THREAD_START_ROUTINE start, void *param,
|
|
|
|
HANDLE *handle_ptr, CLIENT_ID *id )
|
|
|
|
{
|
2006-01-20 16:18:06 +01:00
|
|
|
struct ntdll_thread_data *thread_data;
|
|
|
|
struct ntdll_thread_regs *thread_regs = NULL;
|
2003-11-25 04:42:05 +01:00
|
|
|
struct startup_info *info = NULL;
|
2006-04-11 06:32:33 +02:00
|
|
|
void *addr = NULL;
|
2003-10-31 01:16:20 +01:00
|
|
|
HANDLE handle = 0;
|
2005-08-09 12:43:47 +02:00
|
|
|
TEB *teb;
|
2003-10-31 01:16:20 +01:00
|
|
|
DWORD tid = 0;
|
|
|
|
int request_pipe[2];
|
|
|
|
NTSTATUS status;
|
2006-07-21 20:20:30 +02:00
|
|
|
SIZE_T size, page_size = getpagesize();
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2004-09-21 02:23:50 +02:00
|
|
|
if( ! is_current_process( process ) )
|
|
|
|
{
|
|
|
|
ERR("Unsupported on other process\n");
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
2003-10-31 01:16:20 +01:00
|
|
|
if (pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
|
|
|
|
fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
|
|
|
|
wine_server_send_fd( request_pipe[0] );
|
|
|
|
|
|
|
|
SERVER_START_REQ( new_thread )
|
|
|
|
{
|
2005-12-09 12:13:11 +01:00
|
|
|
req->access = THREAD_ALL_ACCESS;
|
|
|
|
req->attributes = 0; /* FIXME */
|
2003-10-31 01:16:20 +01:00
|
|
|
req->suspend = suspended;
|
|
|
|
req->request_fd = request_pipe[0];
|
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
handle = reply->handle;
|
|
|
|
tid = reply->tid;
|
|
|
|
}
|
|
|
|
close( request_pipe[0] );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (status) goto error;
|
|
|
|
|
2003-11-06 00:31:11 +01:00
|
|
|
if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) )))
|
|
|
|
{
|
|
|
|
status = STATUS_NO_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-07-21 20:20:30 +02:00
|
|
|
addr = NULL;
|
|
|
|
size = sigstack_total_size;
|
|
|
|
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
|
|
|
|
&size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE )))
|
|
|
|
goto error;
|
2005-08-09 12:43:47 +02:00
|
|
|
teb = addr;
|
2006-07-24 15:19:32 +02:00
|
|
|
teb->Peb = NtCurrentTeb()->Peb;
|
2006-07-21 20:20:30 +02:00
|
|
|
info->pthread_info.teb_size = size;
|
2005-08-09 12:43:47 +02:00
|
|
|
if ((status = init_teb( teb ))) goto error;
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId();
|
|
|
|
teb->ClientId.UniqueThread = (HANDLE)tid;
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
2006-01-20 16:18:06 +01:00
|
|
|
thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data->request_fd = request_pipe[1];
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2004-10-11 22:59:06 +02:00
|
|
|
info->pthread_info.teb_base = teb;
|
2006-01-20 16:18:06 +01:00
|
|
|
info->pthread_info.teb_sel = thread_regs->fs;
|
|
|
|
|
|
|
|
/* inherit debug registers from parent thread */
|
|
|
|
thread_regs->dr0 = ntdll_get_thread_regs()->dr0;
|
|
|
|
thread_regs->dr1 = ntdll_get_thread_regs()->dr1;
|
|
|
|
thread_regs->dr2 = ntdll_get_thread_regs()->dr2;
|
|
|
|
thread_regs->dr3 = ntdll_get_thread_regs()->dr3;
|
|
|
|
thread_regs->dr6 = ntdll_get_thread_regs()->dr6;
|
|
|
|
thread_regs->dr7 = ntdll_get_thread_regs()->dr7;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
|
|
|
if (!stack_reserve || !stack_commit)
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress );
|
|
|
|
if (!stack_reserve) stack_reserve = nt->OptionalHeader.SizeOfStackReserve;
|
|
|
|
if (!stack_commit) stack_commit = nt->OptionalHeader.SizeOfStackCommit;
|
|
|
|
}
|
|
|
|
if (stack_reserve < stack_commit) stack_reserve = stack_commit;
|
2005-12-12 17:28:32 +01:00
|
|
|
stack_reserve += page_size; /* for the guard page */
|
2003-11-04 05:50:18 +01:00
|
|
|
stack_reserve = (stack_reserve + 0xffff) & ~0xffff; /* round to 64K boundary */
|
2003-11-18 01:14:17 +01:00
|
|
|
if (stack_reserve < 1024 * 1024) stack_reserve = 1024 * 1024; /* Xlib needs a large stack */
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2003-11-25 04:42:05 +01:00
|
|
|
info->pthread_info.stack_base = NULL;
|
|
|
|
info->pthread_info.stack_size = stack_reserve;
|
|
|
|
info->pthread_info.entry = start_thread;
|
|
|
|
info->entry_point = start;
|
|
|
|
info->entry_arg = param;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2005-09-03 17:11:29 +02:00
|
|
|
if (pthread_functions.create_thread( &info->pthread_info ) == -1)
|
2003-10-31 01:16:20 +01:00
|
|
|
{
|
2003-11-06 00:31:11 +01:00
|
|
|
status = STATUS_NO_MEMORY;
|
2003-10-31 01:16:20 +01:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id) id->UniqueThread = (HANDLE)tid;
|
|
|
|
if (handle_ptr) *handle_ptr = handle;
|
|
|
|
else NtClose( handle );
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
2006-01-20 16:18:06 +01:00
|
|
|
if (thread_regs) wine_ldt_free_fs( thread_regs->fs );
|
2005-08-09 12:43:47 +02:00
|
|
|
if (addr)
|
|
|
|
{
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T size = 0;
|
2005-08-09 12:43:47 +02:00
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
|
|
|
|
}
|
2006-05-01 22:44:43 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
2003-10-31 01:16:20 +01:00
|
|
|
if (handle) NtClose( handle );
|
|
|
|
close( request_pipe[1] );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-02 11:55:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlExitUserThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlExitUserThread( ULONG status )
|
|
|
|
{
|
|
|
|
LdrShutdownThread();
|
|
|
|
server_exit_thread( status );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-05 00:26:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtOpenThread (NTDLL.@)
|
|
|
|
* ZwOpenThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtOpenThread( HANDLE *handle, ACCESS_MASK access,
|
|
|
|
const OBJECT_ATTRIBUTES *attr, const CLIENT_ID *id )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( open_thread )
|
|
|
|
{
|
2005-12-09 12:13:11 +01:00
|
|
|
req->tid = (thread_id_t)id->UniqueThread;
|
|
|
|
req->access = access;
|
|
|
|
req->attributes = attr ? attr->Attributes : 0;
|
2003-04-05 00:26:34 +02:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
*handle = reply->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtSuspendThread (NTDLL.@)
|
|
|
|
* ZwSuspendThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( suspend_thread )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
if (!(ret = wine_server_call( req ))) *count = reply->count;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtResumeThread (NTDLL.@)
|
|
|
|
* ZwResumeThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtResumeThread( HANDLE handle, PULONG count )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( resume_thread )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
if (!(ret = wine_server_call( req ))) *count = reply->count;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-18 13:47:17 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* NtAlertResumeThread (NTDLL.@)
|
|
|
|
* ZwAlertResumeThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtAlertResumeThread( HANDLE handle, PULONG count )
|
|
|
|
{
|
|
|
|
FIXME( "stub: should alert thread %p\n", handle );
|
|
|
|
return NtResumeThread( handle, count );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtAlertThread (NTDLL.@)
|
|
|
|
* ZwAlertThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtAlertThread( HANDLE handle )
|
|
|
|
{
|
|
|
|
FIXME( "stub: %p\n", handle );
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-05 00:26:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* NtTerminateThread (NTDLL.@)
|
|
|
|
* ZwTerminateThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
BOOL self, last;
|
|
|
|
|
|
|
|
SERVER_START_REQ( terminate_thread )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->exit_code = exit_code;
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
self = !ret && reply->self;
|
|
|
|
last = reply->last;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
if (last) exit( exit_code );
|
2003-11-06 01:08:05 +01:00
|
|
|
else server_abort_thread( exit_code );
|
2003-04-05 00:26:34 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtQueueApcThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1,
|
|
|
|
ULONG_PTR arg2, ULONG_PTR arg3 )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
SERVER_START_REQ( queue_apc )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->user = 1;
|
|
|
|
req->func = func;
|
|
|
|
req->arg1 = (void *)arg1;
|
|
|
|
req->arg2 = (void *)arg2;
|
|
|
|
req->arg3 = (void *)arg3;
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NtSetContextThread (NTDLL.@)
|
|
|
|
* ZwSetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
2005-11-02 21:54:12 +01:00
|
|
|
DWORD dummy, i;
|
2006-01-11 20:20:32 +01:00
|
|
|
BOOL self = FALSE;
|
2003-04-05 00:26:34 +02:00
|
|
|
|
2006-01-11 20:20:32 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
/* on i386 debug registers always require a server call */
|
2006-01-13 13:58:14 +01:00
|
|
|
self = (handle == GetCurrentThread());
|
|
|
|
if (self && (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)))
|
|
|
|
{
|
|
|
|
struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
|
|
|
|
self = (regs->dr0 == context->Dr0 && regs->dr1 == context->Dr1 &&
|
|
|
|
regs->dr2 == context->Dr2 && regs->dr3 == context->Dr3 &&
|
|
|
|
regs->dr6 == context->Dr6 && regs->dr7 == context->Dr7);
|
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
#endif
|
2005-11-02 21:54:12 +01:00
|
|
|
|
2006-01-11 20:20:32 +01:00
|
|
|
if (!self)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-01-11 20:20:32 +01:00
|
|
|
SERVER_START_REQ( set_thread_context )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-01-11 20:20:32 +01:00
|
|
|
req->handle = handle;
|
|
|
|
req->flags = context->ContextFlags;
|
|
|
|
req->suspend = 0;
|
|
|
|
wine_server_add_data( req, context, sizeof(*context) );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
self = reply->self;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (ret == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-01-11 20:20:32 +01:00
|
|
|
for (i = 0; i < 100; i++)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-01-11 20:20:32 +01:00
|
|
|
SERVER_START_REQ( set_thread_context )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = context->ContextFlags;
|
|
|
|
req->suspend = 0;
|
|
|
|
wine_server_add_data( req, context, sizeof(*context) );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret != STATUS_PENDING) break;
|
|
|
|
NtYieldExecution();
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
NtResumeThread( handle, &dummy );
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
|
|
|
|
if (ret) return ret;
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
|
|
|
|
2006-01-11 20:20:32 +01:00
|
|
|
if (self) set_cpu_context( context );
|
|
|
|
return STATUS_SUCCESS;
|
2003-04-05 00:26:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 22:41:26 +01:00
|
|
|
/* copy a context structure according to the flags */
|
|
|
|
static inline void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
|
|
|
|
{
|
|
|
|
#ifdef __i386__
|
2005-11-03 10:54:47 +01:00
|
|
|
flags &= ~CONTEXT_i386; /* get rid of CPU id */
|
2005-11-01 22:41:26 +01:00
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->Eax = from->Eax;
|
|
|
|
to->Ebx = from->Ebx;
|
|
|
|
to->Ecx = from->Ecx;
|
|
|
|
to->Edx = from->Edx;
|
|
|
|
to->Esi = from->Esi;
|
|
|
|
to->Edi = from->Edi;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
to->Ebp = from->Ebp;
|
|
|
|
to->Esp = from->Esp;
|
|
|
|
to->Eip = from->Eip;
|
|
|
|
to->SegCs = from->SegCs;
|
|
|
|
to->SegSs = from->SegSs;
|
|
|
|
to->EFlags = from->EFlags;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_SEGMENTS)
|
|
|
|
{
|
|
|
|
to->SegDs = from->SegDs;
|
|
|
|
to->SegEs = from->SegEs;
|
|
|
|
to->SegFs = from->SegFs;
|
|
|
|
to->SegGs = from->SegGs;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS)
|
|
|
|
{
|
|
|
|
to->Dr0 = from->Dr0;
|
|
|
|
to->Dr1 = from->Dr1;
|
|
|
|
to->Dr2 = from->Dr2;
|
|
|
|
to->Dr3 = from->Dr3;
|
|
|
|
to->Dr6 = from->Dr6;
|
|
|
|
to->Dr7 = from->Dr7;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->FloatSave = from->FloatSave;
|
|
|
|
}
|
|
|
|
#elif defined(__x86_64__)
|
2005-11-03 10:54:47 +01:00
|
|
|
flags &= ~CONTEXT_AMD64; /* get rid of CPU id */
|
2005-11-01 22:41:26 +01:00
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
to->Rbp = from->Rbp;
|
|
|
|
to->Rip = from->Rip;
|
|
|
|
to->Rsp = from->Rsp;
|
|
|
|
to->SegCs = from->SegCs;
|
|
|
|
to->SegSs = from->SegSs;
|
|
|
|
to->EFlags = from->EFlags;
|
|
|
|
to->MxCsr = from->MxCsr;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->Rax = from->Rax;
|
|
|
|
to->Rcx = from->Rcx;
|
|
|
|
to->Rdx = from->Rdx;
|
|
|
|
to->Rbx = from->Rbx;
|
|
|
|
to->Rsi = from->Rsi;
|
|
|
|
to->Rdi = from->Rdi;
|
|
|
|
to->R8 = from->R8;
|
|
|
|
to->R9 = from->R9;
|
|
|
|
to->R10 = from->R10;
|
|
|
|
to->R11 = from->R11;
|
|
|
|
to->R12 = from->R12;
|
|
|
|
to->R13 = from->R13;
|
|
|
|
to->R14 = from->R14;
|
|
|
|
to->R15 = from->R15;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_SEGMENTS)
|
|
|
|
{
|
|
|
|
to->SegDs = from->SegDs;
|
|
|
|
to->SegEs = from->SegEs;
|
|
|
|
to->SegFs = from->SegFs;
|
|
|
|
to->SegGs = from->SegGs;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->u.FltSave = from->u.FltSave;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS)
|
|
|
|
{
|
|
|
|
to->Dr0 = from->Dr0;
|
|
|
|
to->Dr1 = from->Dr1;
|
|
|
|
to->Dr2 = from->Dr2;
|
|
|
|
to->Dr3 = from->Dr3;
|
|
|
|
to->Dr6 = from->Dr6;
|
|
|
|
to->Dr7 = from->Dr7;
|
|
|
|
}
|
|
|
|
#elif defined(__sparc__)
|
2005-11-03 10:54:47 +01:00
|
|
|
flags &= ~CONTEXT_SPARC; /* get rid of CPU id */
|
2005-11-01 22:41:26 +01:00
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
to->psr = from->psr;
|
|
|
|
to->pc = from->pc;
|
|
|
|
to->npc = from->npc;
|
|
|
|
to->y = from->y;
|
|
|
|
to->wim = from->wim;
|
|
|
|
to->tbr = from->tbr;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->g0 = from->g0;
|
|
|
|
to->g1 = from->g1;
|
|
|
|
to->g2 = from->g2;
|
|
|
|
to->g3 = from->g3;
|
|
|
|
to->g4 = from->g4;
|
|
|
|
to->g5 = from->g5;
|
|
|
|
to->g6 = from->g6;
|
|
|
|
to->g7 = from->g7;
|
|
|
|
to->o0 = from->o0;
|
|
|
|
to->o1 = from->o1;
|
|
|
|
to->o2 = from->o2;
|
|
|
|
to->o3 = from->o3;
|
|
|
|
to->o4 = from->o4;
|
|
|
|
to->o5 = from->o5;
|
|
|
|
to->o6 = from->o6;
|
|
|
|
to->o7 = from->o7;
|
|
|
|
to->l0 = from->l0;
|
|
|
|
to->l1 = from->l1;
|
|
|
|
to->l2 = from->l2;
|
|
|
|
to->l3 = from->l3;
|
|
|
|
to->l4 = from->l4;
|
|
|
|
to->l5 = from->l5;
|
|
|
|
to->l6 = from->l6;
|
|
|
|
to->l7 = from->l7;
|
|
|
|
to->i0 = from->i0;
|
|
|
|
to->i1 = from->i1;
|
|
|
|
to->i2 = from->i2;
|
|
|
|
to->i3 = from->i3;
|
|
|
|
to->i4 = from->i4;
|
|
|
|
to->i5 = from->i5;
|
|
|
|
to->i6 = from->i6;
|
|
|
|
to->i7 = from->i7;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
}
|
|
|
|
#elif defined(__powerpc__)
|
2005-11-03 10:54:47 +01:00
|
|
|
/* Has no CPU id */
|
2005-11-01 22:41:26 +01:00
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
to->Msr = from->Msr;
|
|
|
|
to->Ctr = from->Ctr;
|
|
|
|
to->Iar = from->Iar;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->Gpr0 = from->Gpr0;
|
|
|
|
to->Gpr1 = from->Gpr1;
|
|
|
|
to->Gpr2 = from->Gpr2;
|
|
|
|
to->Gpr3 = from->Gpr3;
|
|
|
|
to->Gpr4 = from->Gpr4;
|
|
|
|
to->Gpr5 = from->Gpr5;
|
|
|
|
to->Gpr6 = from->Gpr6;
|
|
|
|
to->Gpr7 = from->Gpr7;
|
|
|
|
to->Gpr8 = from->Gpr8;
|
|
|
|
to->Gpr9 = from->Gpr9;
|
|
|
|
to->Gpr10 = from->Gpr10;
|
|
|
|
to->Gpr11 = from->Gpr11;
|
|
|
|
to->Gpr12 = from->Gpr12;
|
|
|
|
to->Gpr13 = from->Gpr13;
|
|
|
|
to->Gpr14 = from->Gpr14;
|
|
|
|
to->Gpr15 = from->Gpr15;
|
|
|
|
to->Gpr16 = from->Gpr16;
|
|
|
|
to->Gpr17 = from->Gpr17;
|
|
|
|
to->Gpr18 = from->Gpr18;
|
|
|
|
to->Gpr19 = from->Gpr19;
|
|
|
|
to->Gpr20 = from->Gpr20;
|
|
|
|
to->Gpr21 = from->Gpr21;
|
|
|
|
to->Gpr22 = from->Gpr22;
|
|
|
|
to->Gpr23 = from->Gpr23;
|
|
|
|
to->Gpr24 = from->Gpr24;
|
|
|
|
to->Gpr25 = from->Gpr25;
|
|
|
|
to->Gpr26 = from->Gpr26;
|
|
|
|
to->Gpr27 = from->Gpr27;
|
|
|
|
to->Gpr28 = from->Gpr28;
|
|
|
|
to->Gpr29 = from->Gpr29;
|
|
|
|
to->Gpr30 = from->Gpr30;
|
|
|
|
to->Gpr31 = from->Gpr31;
|
|
|
|
to->Xer = from->Xer;
|
|
|
|
to->Cr = from->Cr;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->Fpr0 = from->Fpr0;
|
|
|
|
to->Fpr1 = from->Fpr1;
|
|
|
|
to->Fpr2 = from->Fpr2;
|
|
|
|
to->Fpr3 = from->Fpr3;
|
|
|
|
to->Fpr4 = from->Fpr4;
|
|
|
|
to->Fpr5 = from->Fpr5;
|
|
|
|
to->Fpr6 = from->Fpr6;
|
|
|
|
to->Fpr7 = from->Fpr7;
|
|
|
|
to->Fpr8 = from->Fpr8;
|
|
|
|
to->Fpr9 = from->Fpr9;
|
|
|
|
to->Fpr10 = from->Fpr10;
|
|
|
|
to->Fpr11 = from->Fpr11;
|
|
|
|
to->Fpr12 = from->Fpr12;
|
|
|
|
to->Fpr13 = from->Fpr13;
|
|
|
|
to->Fpr14 = from->Fpr14;
|
|
|
|
to->Fpr15 = from->Fpr15;
|
|
|
|
to->Fpr16 = from->Fpr16;
|
|
|
|
to->Fpr17 = from->Fpr17;
|
|
|
|
to->Fpr18 = from->Fpr18;
|
|
|
|
to->Fpr19 = from->Fpr19;
|
|
|
|
to->Fpr20 = from->Fpr20;
|
|
|
|
to->Fpr21 = from->Fpr21;
|
|
|
|
to->Fpr22 = from->Fpr22;
|
|
|
|
to->Fpr23 = from->Fpr23;
|
|
|
|
to->Fpr24 = from->Fpr24;
|
|
|
|
to->Fpr25 = from->Fpr25;
|
|
|
|
to->Fpr26 = from->Fpr26;
|
|
|
|
to->Fpr27 = from->Fpr27;
|
|
|
|
to->Fpr28 = from->Fpr28;
|
|
|
|
to->Fpr29 = from->Fpr29;
|
|
|
|
to->Fpr30 = from->Fpr30;
|
|
|
|
to->Fpr31 = from->Fpr31;
|
|
|
|
to->Fpscr = from->Fpscr;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#error You must implement context copying for your CPU
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-05 00:26:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtGetContextThread (NTDLL.@)
|
|
|
|
* ZwGetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
2005-11-01 22:41:26 +01:00
|
|
|
CONTEXT ctx;
|
2005-11-02 21:54:12 +01:00
|
|
|
DWORD dummy, i;
|
2006-04-20 15:40:28 +02:00
|
|
|
DWORD needed_flags = context->ContextFlags;
|
|
|
|
BOOL self = (handle == GetCurrentThread());
|
2003-04-05 00:26:34 +02:00
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
/* on i386 debug registers always require a server call */
|
|
|
|
if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)) self = FALSE;
|
|
|
|
#endif
|
2005-11-02 21:54:12 +01:00
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
if (!self)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-04-20 15:40:28 +02:00
|
|
|
SERVER_START_REQ( get_thread_context )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = context->ContextFlags;
|
|
|
|
req->suspend = 0;
|
|
|
|
wine_server_set_reply( req, &ctx, sizeof(ctx) );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
self = reply->self;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (ret == STATUS_PENDING)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-04-20 15:40:28 +02:00
|
|
|
if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-04-20 15:40:28 +02:00
|
|
|
for (i = 0; i < 100; i++)
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-04-20 15:40:28 +02:00
|
|
|
SERVER_START_REQ( get_thread_context )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = context->ContextFlags;
|
|
|
|
req->suspend = 0;
|
|
|
|
wine_server_set_reply( req, &ctx, sizeof(ctx) );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret != STATUS_PENDING) break;
|
|
|
|
NtYieldExecution();
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
2006-04-20 15:40:28 +02:00
|
|
|
NtResumeThread( handle, &dummy );
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
2006-04-20 15:40:28 +02:00
|
|
|
if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
2006-04-20 15:40:28 +02:00
|
|
|
if (ret) return ret;
|
|
|
|
copy_context( context, &ctx, context->ContextFlags & ctx.ContextFlags );
|
|
|
|
needed_flags &= ~ctx.ContextFlags;
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
if (self)
|
2006-01-13 13:58:14 +01:00
|
|
|
{
|
2006-04-20 15:40:28 +02:00
|
|
|
if (needed_flags)
|
|
|
|
{
|
|
|
|
get_cpu_context( &ctx );
|
|
|
|
copy_context( context, &ctx, ctx.ContextFlags & needed_flags );
|
|
|
|
}
|
2006-01-13 13:58:14 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
/* update the cached version of the debug registers */
|
2006-04-20 15:40:28 +02:00
|
|
|
if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386))
|
2006-01-13 13:58:14 +01:00
|
|
|
{
|
|
|
|
struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
|
|
|
|
regs->dr0 = context->Dr0;
|
|
|
|
regs->dr1 = context->Dr1;
|
|
|
|
regs->dr2 = context->Dr2;
|
|
|
|
regs->dr3 = context->Dr3;
|
|
|
|
regs->dr6 = context->Dr6;
|
|
|
|
regs->dr7 = context->Dr7;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2006-04-20 15:40:28 +02:00
|
|
|
return STATUS_SUCCESS;
|
2003-04-05 00:26:34 +02:00
|
|
|
}
|
2003-07-09 04:57:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtQueryInformationThread (NTDLL.@)
|
|
|
|
* ZwQueryInformationThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
|
|
|
|
void *data, ULONG length, ULONG *ret_len )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
switch(class)
|
|
|
|
{
|
|
|
|
case ThreadBasicInformation:
|
|
|
|
{
|
|
|
|
THREAD_BASIC_INFORMATION info;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->tid_in = 0;
|
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
info.ExitStatus = reply->exit_code;
|
|
|
|
info.TebBaseAddress = reply->teb;
|
|
|
|
info.ClientId.UniqueProcess = (HANDLE)reply->pid;
|
|
|
|
info.ClientId.UniqueThread = (HANDLE)reply->tid;
|
|
|
|
info.AffinityMask = reply->affinity;
|
|
|
|
info.Priority = reply->priority;
|
|
|
|
info.BasePriority = reply->priority; /* FIXME */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (data) memcpy( data, &info, min( length, sizeof(info) ));
|
|
|
|
if (ret_len) *ret_len = min( length, sizeof(info) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
case ThreadTimes:
|
2005-09-13 00:01:33 +02:00
|
|
|
{
|
|
|
|
KERNEL_USER_TIMES kusrt;
|
|
|
|
/* We need to do a server call to get the creation time or exit time */
|
|
|
|
/* This works on any thread */
|
|
|
|
SERVER_START_REQ( get_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->tid_in = 0;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
2006-07-26 14:49:55 +02:00
|
|
|
NTDLL_from_server_abstime( &kusrt.CreateTime, &reply->creation_time );
|
|
|
|
NTDLL_from_server_abstime( &kusrt.ExitTime, &reply->exit_time );
|
2005-09-13 00:01:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* We call times(2) for kernel time or user time */
|
|
|
|
/* We can only (portably) do this for the current thread */
|
|
|
|
if (handle == GetCurrentThread())
|
|
|
|
{
|
|
|
|
struct tms time_buf;
|
|
|
|
long clocks_per_sec = sysconf(_SC_CLK_TCK);
|
|
|
|
|
|
|
|
times(&time_buf);
|
|
|
|
kusrt.KernelTime.QuadPart = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
|
|
|
|
kusrt.UserTime.QuadPart = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kusrt.KernelTime.QuadPart = 0;
|
|
|
|
kusrt.UserTime.QuadPart = 0;
|
|
|
|
FIXME("Cannot get kerneltime or usertime of other threads\n");
|
|
|
|
}
|
|
|
|
if (data) memcpy( data, &kusrt, min( length, sizeof(kusrt) ));
|
|
|
|
if (ret_len) *ret_len = min( length, sizeof(kusrt) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
2006-05-26 12:10:57 +02:00
|
|
|
case ThreadDescriptorTableEntry:
|
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
THREAD_DESCRIPTOR_INFORMATION* tdi = data;
|
|
|
|
if (length < sizeof(*tdi))
|
|
|
|
status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
else if (!(tdi->Selector & 4)) /* GDT selector */
|
|
|
|
{
|
|
|
|
unsigned sel = tdi->Selector & ~3; /* ignore RPL */
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
if (!sel) /* null selector */
|
|
|
|
memset( &tdi->Entry, 0, sizeof(tdi->Entry) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tdi->Entry.BaseLow = 0;
|
|
|
|
tdi->Entry.HighWord.Bits.BaseMid = 0;
|
|
|
|
tdi->Entry.HighWord.Bits.BaseHi = 0;
|
|
|
|
tdi->Entry.LimitLow = 0xffff;
|
|
|
|
tdi->Entry.HighWord.Bits.LimitHi = 0xf;
|
|
|
|
tdi->Entry.HighWord.Bits.Dpl = 3;
|
|
|
|
tdi->Entry.HighWord.Bits.Sys = 0;
|
|
|
|
tdi->Entry.HighWord.Bits.Pres = 1;
|
|
|
|
tdi->Entry.HighWord.Bits.Granularity = 1;
|
|
|
|
tdi->Entry.HighWord.Bits.Default_Big = 1;
|
|
|
|
tdi->Entry.HighWord.Bits.Type = 0x12;
|
|
|
|
/* it has to be one of the system GDT selectors */
|
|
|
|
if (sel != (wine_get_ds() & ~3) && sel != (wine_get_ss() & ~3))
|
|
|
|
{
|
|
|
|
if (sel == (wine_get_cs() & ~3))
|
|
|
|
tdi->Entry.HighWord.Bits.Type |= 8; /* code segment */
|
|
|
|
else status = STATUS_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( get_selector_entry )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->entry = tdi->Selector >> 3;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
if (!(reply->flags & WINE_LDT_FLAGS_ALLOCATED))
|
|
|
|
status = STATUS_INVALID_LDT_OFFSET;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wine_ldt_set_base ( &tdi->Entry, (void *)reply->base );
|
|
|
|
wine_ldt_set_limit( &tdi->Entry, reply->limit );
|
|
|
|
wine_ldt_set_flags( &tdi->Entry, reply->flags );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
2006-06-08 22:32:59 +02:00
|
|
|
if (status == STATUS_SUCCESS && ret_len) *ret_len = sizeof(*tdi);
|
2006-05-26 12:10:57 +02:00
|
|
|
#else
|
|
|
|
status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
2003-07-09 04:57:57 +02:00
|
|
|
case ThreadPriority:
|
|
|
|
case ThreadBasePriority:
|
|
|
|
case ThreadAffinityMask:
|
|
|
|
case ThreadImpersonationToken:
|
|
|
|
case ThreadEnableAlignmentFaultFixup:
|
|
|
|
case ThreadEventPair_Reusable:
|
|
|
|
case ThreadQuerySetWin32StartAddress:
|
|
|
|
case ThreadZeroTlsCell:
|
|
|
|
case ThreadPerformanceCount:
|
|
|
|
case ThreadAmILastThread:
|
|
|
|
case ThreadIdealProcessor:
|
|
|
|
case ThreadPriorityBoost:
|
|
|
|
case ThreadSetTlsArrayAddress:
|
|
|
|
case ThreadIsIoPending:
|
|
|
|
default:
|
|
|
|
FIXME( "info class %d not supported yet\n", class );
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
2003-09-08 21:02:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtSetInformationThread (NTDLL.@)
|
|
|
|
* ZwSetInformationThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
|
|
|
|
LPCVOID data, ULONG length )
|
|
|
|
{
|
2005-06-20 15:18:38 +02:00
|
|
|
NTSTATUS status;
|
2003-09-08 21:02:01 +02:00
|
|
|
switch(class)
|
|
|
|
{
|
|
|
|
case ThreadZeroTlsCell:
|
|
|
|
if (handle == GetCurrentThread())
|
|
|
|
{
|
2003-11-04 05:50:18 +01:00
|
|
|
LIST_ENTRY *entry;
|
2003-09-08 21:02:01 +02:00
|
|
|
DWORD index;
|
|
|
|
|
|
|
|
if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
|
2004-06-15 02:52:03 +02:00
|
|
|
index = *(const DWORD *)data;
|
2005-03-19 18:14:12 +01:00
|
|
|
if (index < TLS_MINIMUM_AVAILABLE)
|
2003-09-08 21:02:01 +02:00
|
|
|
{
|
2005-03-19 18:14:12 +01:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
|
|
|
|
teb->TlsSlots[index] = 0;
|
|
|
|
}
|
|
|
|
RtlReleasePebLock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index -= TLS_MINIMUM_AVAILABLE;
|
|
|
|
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
|
|
|
|
{
|
|
|
|
TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
|
|
|
|
if (teb->TlsExpansionSlots) teb->TlsExpansionSlots[index] = 0;
|
|
|
|
}
|
|
|
|
RtlReleasePebLock();
|
2003-11-04 05:50:18 +01:00
|
|
|
}
|
2003-09-08 21:02:01 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
FIXME( "ZeroTlsCell not supported on other threads\n" );
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
2004-08-14 01:20:27 +02:00
|
|
|
case ThreadImpersonationToken:
|
|
|
|
{
|
|
|
|
const HANDLE *phToken = data;
|
|
|
|
if (length != sizeof(HANDLE)) return STATUS_INVALID_PARAMETER;
|
2005-06-20 15:18:38 +02:00
|
|
|
TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken );
|
|
|
|
SERVER_START_REQ( set_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->token = *phToken;
|
|
|
|
req->mask = SET_THREAD_INFO_TOKEN;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2004-08-14 01:20:27 +02:00
|
|
|
}
|
2005-09-07 15:25:35 +02:00
|
|
|
return status;
|
|
|
|
case ThreadBasePriority:
|
|
|
|
{
|
|
|
|
const DWORD *pprio = data;
|
|
|
|
if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
|
|
|
|
SERVER_START_REQ( set_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->priority = *pprio;
|
|
|
|
req->mask = SET_THREAD_INFO_PRIORITY;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
return status;
|
2006-01-11 12:32:19 +01:00
|
|
|
case ThreadAffinityMask:
|
|
|
|
{
|
|
|
|
const DWORD *paff = data;
|
|
|
|
if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
|
|
|
|
SERVER_START_REQ( set_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->affinity = *paff;
|
|
|
|
req->mask = SET_THREAD_INFO_AFFINITY;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
return status;
|
2003-09-08 21:02:01 +02:00
|
|
|
case ThreadBasicInformation:
|
|
|
|
case ThreadTimes:
|
|
|
|
case ThreadPriority:
|
|
|
|
case ThreadDescriptorTableEntry:
|
|
|
|
case ThreadEnableAlignmentFaultFixup:
|
|
|
|
case ThreadEventPair_Reusable:
|
|
|
|
case ThreadQuerySetWin32StartAddress:
|
|
|
|
case ThreadPerformanceCount:
|
|
|
|
case ThreadAmILastThread:
|
|
|
|
case ThreadIdealProcessor:
|
|
|
|
case ThreadPriorityBoost:
|
|
|
|
case ThreadSetTlsArrayAddress:
|
|
|
|
case ThreadIsIoPending:
|
|
|
|
default:
|
|
|
|
FIXME( "info class %d not supported yet\n", class );
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
2003-11-09 02:25:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* NtCurrentTeb (NTDLL.@)
|
|
|
|
*/
|
|
|
|
#if defined(__i386__) && defined(__GNUC__)
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
__ASM_GLOBAL_FUNC( NtCurrentTeb, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" );
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
#elif defined(__i386__) && defined(_MSC_VER)
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
/* Nothing needs to be done. MS C "magically" exports the inline version from winnt.h */
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
#else
|
2004-05-17 23:08:31 +02:00
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
TEB * WINAPI NtCurrentTeb(void)
|
|
|
|
{
|
2005-09-03 17:11:29 +02:00
|
|
|
return pthread_functions.get_current_teb();
|
2003-11-09 02:25:23 +01:00
|
|
|
}
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
#endif /* __i386__ */
|