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>
|
2008-03-01 11:57:00 +01:00
|
|
|
#include <stdarg.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-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-07-09 04:57:57 +02:00
|
|
|
#include "wine/debug.h"
|
2003-11-04 05:50:18 +01:00
|
|
|
#include "ntdll_misc.h"
|
2007-05-18 18:09:03 +02:00
|
|
|
#include "ddk/wdm.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);
|
2007-01-18 15:02:11 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
2003-04-05 00:26:34 +02:00
|
|
|
|
2007-05-18 18:09:03 +02:00
|
|
|
struct _KUSER_SHARED_DATA *user_shared_data = NULL;
|
|
|
|
|
2008-02-12 22:39:19 +01:00
|
|
|
PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter = NULL;
|
|
|
|
|
2003-11-25 04:42:05 +01:00
|
|
|
/* info passed to a starting thread */
|
|
|
|
struct startup_info
|
|
|
|
{
|
2009-02-23 14:24:59 +01:00
|
|
|
TEB *teb;
|
2003-11-25 04:42:05 +01:00
|
|
|
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;
|
2008-02-29 19:55:34 +01:00
|
|
|
static RTL_BITMAP fls_bitmap;
|
2003-11-04 05:50:18 +01:00
|
|
|
static LIST_ENTRY tls_links;
|
2009-02-20 11:45:47 +01:00
|
|
|
static int nb_threads = 1;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2007-01-18 15:01:45 +01:00
|
|
|
static RTL_CRITICAL_SECTION ldt_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &ldt_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": ldt_section") }
|
|
|
|
};
|
|
|
|
static RTL_CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
static sigset_t ldt_sigset;
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* locking for LDT routines
|
|
|
|
*/
|
|
|
|
static void ldt_lock(void)
|
|
|
|
{
|
|
|
|
sigset_t sigset;
|
|
|
|
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_BLOCK, &server_block_set, &sigset );
|
2007-01-18 15:01:45 +01:00
|
|
|
RtlEnterCriticalSection( &ldt_section );
|
|
|
|
if (ldt_section.RecursionCount == 1) ldt_sigset = sigset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ldt_unlock(void)
|
|
|
|
{
|
|
|
|
if (ldt_section.RecursionCount == 1)
|
|
|
|
{
|
|
|
|
sigset_t sigset = ldt_sigset;
|
|
|
|
RtlLeaveCriticalSection( &ldt_section );
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_SETMASK, &sigset, NULL );
|
2007-01-18 15:01:45 +01:00
|
|
|
}
|
|
|
|
else RtlLeaveCriticalSection( &ldt_section );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-22 09:57:19 +01:00
|
|
|
/***********************************************************************
|
2009-08-20 20:05:21 +02:00
|
|
|
* get_unicode_string
|
2006-02-22 09:57:19 +01:00
|
|
|
*
|
2009-08-20 20:05:21 +02:00
|
|
|
* Copy a unicode string from the startup info.
|
2006-02-22 09:57:19 +01:00
|
|
|
*/
|
2009-08-20 20:05:21 +02:00
|
|
|
static inline void get_unicode_string( UNICODE_STRING *str, WCHAR **src, WCHAR **dst, UINT len )
|
2006-02-22 09:57:19 +01:00
|
|
|
{
|
2009-08-20 20:05:21 +02:00
|
|
|
str->Buffer = *dst;
|
|
|
|
str->Length = len;
|
|
|
|
str->MaximumLength = len + sizeof(WCHAR);
|
|
|
|
memcpy( str->Buffer, *src, len );
|
|
|
|
str->Buffer[len / sizeof(WCHAR)] = 0;
|
|
|
|
*src += len / sizeof(WCHAR);
|
|
|
|
*dst += len / sizeof(WCHAR) + 1;
|
2006-02-22 09:57:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* init_user_process_params
|
|
|
|
*
|
|
|
|
* Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
|
|
|
|
*/
|
2009-08-20 20:05:21 +02:00
|
|
|
static NTSTATUS init_user_process_params( SIZE_T data_size, HANDLE *exe_file )
|
2006-02-22 09:57:19 +01:00
|
|
|
{
|
|
|
|
void *ptr;
|
2009-08-20 20:05:21 +02:00
|
|
|
WCHAR *src, *dst;
|
|
|
|
SIZE_T info_size, env_size, size, alloc_size;
|
2006-02-22 09:57:19 +01:00
|
|
|
NTSTATUS status;
|
2009-08-20 20:05:21 +02:00
|
|
|
startup_info_t *info;
|
2006-02-22 09:57:19 +01:00
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = NULL;
|
|
|
|
|
2009-08-20 20:05:21 +02:00
|
|
|
if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, data_size )))
|
|
|
|
return STATUS_NO_MEMORY;
|
2006-02-22 09:57:19 +01:00
|
|
|
|
|
|
|
SERVER_START_REQ( get_startup_info )
|
|
|
|
{
|
2009-08-20 20:05:21 +02:00
|
|
|
wine_server_set_reply( req, info, data_size );
|
2006-02-22 09:57:19 +01:00
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
2009-08-20 20:05:21 +02:00
|
|
|
data_size = wine_server_reply_size( reply );
|
|
|
|
info_size = reply->info_size;
|
|
|
|
env_size = data_size - info_size;
|
2008-12-08 16:05:17 +01:00
|
|
|
*exe_file = wine_server_ptr_handle( reply->exe_file );
|
2006-02-22 09:57:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2009-08-25 00:25:04 +02:00
|
|
|
if (status != STATUS_SUCCESS) goto done;
|
2006-02-22 09:57:19 +01:00
|
|
|
|
2009-08-20 20:05:21 +02:00
|
|
|
size = sizeof(*params);
|
|
|
|
size += MAX_NT_PATH_LENGTH * sizeof(WCHAR);
|
|
|
|
size += info->dllpath_len + sizeof(WCHAR);
|
|
|
|
size += info->imagepath_len + sizeof(WCHAR);
|
|
|
|
size += info->cmdline_len + sizeof(WCHAR);
|
|
|
|
size += info->title_len + sizeof(WCHAR);
|
|
|
|
size += info->desktop_len + sizeof(WCHAR);
|
|
|
|
size += info->shellinfo_len + sizeof(WCHAR);
|
|
|
|
size += info->runtime_len + sizeof(WCHAR);
|
|
|
|
|
|
|
|
alloc_size = size;
|
|
|
|
status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)¶ms, 0, &alloc_size,
|
|
|
|
MEM_COMMIT, PAGE_READWRITE );
|
|
|
|
if (status != STATUS_SUCCESS) goto done;
|
2006-02-22 09:57:19 +01:00
|
|
|
|
2009-08-20 20:05:21 +02:00
|
|
|
NtCurrentTeb()->Peb->ProcessParameters = params;
|
|
|
|
params->AllocationSize = alloc_size;
|
|
|
|
params->Size = size;
|
|
|
|
params->Flags = PROCESS_PARAMS_FLAG_NORMALIZED;
|
|
|
|
params->DebugFlags = info->debug_flags;
|
|
|
|
params->ConsoleHandle = wine_server_ptr_handle( info->console );
|
|
|
|
params->ConsoleFlags = info->console_flags;
|
|
|
|
params->hStdInput = wine_server_ptr_handle( info->hstdin );
|
|
|
|
params->hStdOutput = wine_server_ptr_handle( info->hstdout );
|
|
|
|
params->hStdError = wine_server_ptr_handle( info->hstderr );
|
|
|
|
params->dwX = info->x;
|
|
|
|
params->dwY = info->y;
|
|
|
|
params->dwXSize = info->xsize;
|
|
|
|
params->dwYSize = info->ysize;
|
|
|
|
params->dwXCountChars = info->xchars;
|
|
|
|
params->dwYCountChars = info->ychars;
|
|
|
|
params->dwFillAttribute = info->attribute;
|
|
|
|
params->dwFlags = info->flags;
|
|
|
|
params->wShowWindow = info->show;
|
|
|
|
|
|
|
|
src = (WCHAR *)(info + 1);
|
|
|
|
dst = (WCHAR *)(params + 1);
|
|
|
|
|
|
|
|
/* current directory needs more space */
|
|
|
|
get_unicode_string( ¶ms->CurrentDirectory.DosPath, &src, &dst, info->curdir_len );
|
|
|
|
params->CurrentDirectory.DosPath.MaximumLength = MAX_NT_PATH_LENGTH * sizeof(WCHAR);
|
|
|
|
dst = (WCHAR *)(params + 1) + MAX_NT_PATH_LENGTH;
|
|
|
|
|
|
|
|
get_unicode_string( ¶ms->DllPath, &src, &dst, info->dllpath_len );
|
|
|
|
get_unicode_string( ¶ms->ImagePathName, &src, &dst, info->imagepath_len );
|
|
|
|
get_unicode_string( ¶ms->CommandLine, &src, &dst, info->cmdline_len );
|
|
|
|
get_unicode_string( ¶ms->WindowTitle, &src, &dst, info->title_len );
|
|
|
|
get_unicode_string( ¶ms->Desktop, &src, &dst, info->desktop_len );
|
|
|
|
get_unicode_string( ¶ms->ShellInfo, &src, &dst, info->shellinfo_len );
|
|
|
|
|
|
|
|
/* runtime info isn't a real string */
|
|
|
|
params->RuntimeInfo.Buffer = dst;
|
|
|
|
params->RuntimeInfo.Length = params->RuntimeInfo.MaximumLength = info->runtime_len;
|
|
|
|
memcpy( dst, src, info->runtime_len );
|
2006-02-22 09:57:19 +01:00
|
|
|
|
|
|
|
/* environment needs to be a separate memory block */
|
|
|
|
ptr = NULL;
|
2009-08-20 20:05:21 +02:00
|
|
|
alloc_size = max( 1, env_size );
|
|
|
|
status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &alloc_size,
|
2006-02-22 09:57:19 +01:00
|
|
|
MEM_COMMIT, PAGE_READWRITE );
|
2009-08-20 20:05:21 +02:00
|
|
|
if (status != STATUS_SUCCESS) goto done;
|
|
|
|
memcpy( ptr, (char *)info + info_size, env_size );
|
2006-02-22 09:57:19 +01:00
|
|
|
params->Environment = ptr;
|
|
|
|
|
2009-08-20 20:05:21 +02:00
|
|
|
done:
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
2006-02-22 09:57:19 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-11-24 02:24:23 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_global_flag
|
|
|
|
*
|
|
|
|
* This is called before the process heap is created,
|
|
|
|
* but after the connection to the server is established.
|
|
|
|
* No windows heap allocation is permitted.
|
|
|
|
*/
|
|
|
|
static DWORD get_global_flag(void)
|
|
|
|
{
|
|
|
|
static const WCHAR sessionman_keyW[] = {'M','a','c','h','i','n','e','\\',
|
|
|
|
'S','y','s','t','e','m','\\',
|
|
|
|
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
|
|
|
'C','o','n','t','r','o','l','\\',
|
|
|
|
'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
|
|
|
|
static const WCHAR global_flagW[] = {'G','l','o','b','a','l','F','l','a','g',0};
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW, valueW;
|
|
|
|
HANDLE hkey;
|
|
|
|
char tmp[32];
|
|
|
|
DWORD count;
|
|
|
|
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, sessionman_keyW );
|
|
|
|
|
|
|
|
status = NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
RtlInitUnicodeString( &valueW, global_flagW );
|
|
|
|
status = NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Some documents say this can be a string, so handle either type */
|
|
|
|
if (info->Type == REG_DWORD)
|
|
|
|
return *(DWORD *)info->Data;
|
|
|
|
if (info->Type == REG_SZ)
|
|
|
|
return strtol((char *)info->Data, NULL, 16);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-22 09:57:19 +01:00
|
|
|
|
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;
|
2007-05-18 18:09:03 +02:00
|
|
|
LARGE_INTEGER now;
|
2005-06-06 22:04:33 +02:00
|
|
|
struct ntdll_thread_data *thread_data;
|
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;
|
2007-05-18 18:09:03 +02:00
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, &size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE );
|
|
|
|
user_shared_data = addr;
|
2006-07-24 15:19:32 +02:00
|
|
|
|
|
|
|
/* 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->ProcessParameters = ¶ms;
|
|
|
|
peb->TlsBitmap = &tls_bitmap;
|
|
|
|
peb->TlsExpansionBitmap = &tls_expansion_bitmap;
|
2008-02-29 19:55:34 +01:00
|
|
|
peb->FlsBitmap = &fls_bitmap;
|
2006-07-24 15:19:32 +02:00
|
|
|
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 );
|
2008-02-29 19:55:34 +01:00
|
|
|
RtlInitializeBitMap( &fls_bitmap, peb->FlsBitmapBits, sizeof(peb->FlsBitmapBits) * 8 );
|
|
|
|
InitializeListHead( &peb->FlsListHead );
|
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 */
|
|
|
|
|
2009-11-19 12:25:52 +01:00
|
|
|
signal_alloc_thread( &teb );
|
2006-07-24 15:19:32 +02:00
|
|
|
teb->Peb = peb;
|
2009-11-19 12:25:52 +01:00
|
|
|
teb->Tib.StackBase = (void *)~0UL;
|
|
|
|
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
|
|
|
|
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
|
|
|
|
|
2009-11-19 12:27:09 +01:00
|
|
|
thread_data = (struct ntdll_thread_data *)teb->SpareBytes1;
|
2009-11-19 12:25:52 +01:00
|
|
|
thread_data->request_fd = -1;
|
|
|
|
thread_data->reply_fd = -1;
|
|
|
|
thread_data->wait_fd[0] = -1;
|
|
|
|
thread_data->wait_fd[1] = -1;
|
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 );
|
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
signal_init_thread( teb );
|
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();
|
2009-04-03 14:30:34 +02:00
|
|
|
info_size = server_init_thread( peb );
|
2003-10-09 06:59:03 +02:00
|
|
|
|
2009-11-24 02:24:23 +01:00
|
|
|
/* retrieve the global flags settings from the registry */
|
|
|
|
peb->NtGlobalFlag = get_global_flag();
|
|
|
|
|
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
|
|
|
}
|
2007-01-18 15:01:45 +01:00
|
|
|
|
|
|
|
/* initialize LDT locking */
|
|
|
|
wine_ldt_init_locking( ldt_lock, ldt_unlock );
|
|
|
|
|
2007-05-18 18:09:03 +02:00
|
|
|
/* initialize time values in user_shared_data */
|
|
|
|
NtQuerySystemTime( &now );
|
2007-05-20 12:08:48 +02:00
|
|
|
user_shared_data->SystemTime.LowPart = now.u.LowPart;
|
|
|
|
user_shared_data->SystemTime.High1Time = user_shared_data->SystemTime.High2Time = now.u.HighPart;
|
2007-05-18 18:09:03 +02:00
|
|
|
user_shared_data->u.TickCountQuad = (now.QuadPart - server_start_time) / 10000;
|
|
|
|
user_shared_data->u.TickCount.High2Time = user_shared_data->u.TickCount.High1Time;
|
|
|
|
user_shared_data->TickCountLowDeprecated = user_shared_data->u.TickCount.LowPart;
|
|
|
|
user_shared_data->TickCountMultiplier = 1 << 24;
|
|
|
|
|
2009-09-15 21:38:23 +02:00
|
|
|
fill_cpu_info();
|
|
|
|
|
2006-02-22 09:57:19 +01:00
|
|
|
return exe_file;
|
2003-10-09 06:59:03 +02:00
|
|
|
}
|
|
|
|
|
2009-02-20 11:23:08 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2009-08-28 11:52:21 +02:00
|
|
|
* terminate_thread
|
2009-02-20 11:23:08 +01:00
|
|
|
*/
|
2009-08-28 11:52:21 +02:00
|
|
|
void terminate_thread( int status )
|
2009-02-20 11:23:08 +01:00
|
|
|
{
|
2009-02-23 14:02:16 +01:00
|
|
|
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
|
2009-02-20 11:45:47 +01:00
|
|
|
if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) _exit( status );
|
|
|
|
|
2009-02-20 11:23:08 +01:00
|
|
|
close( ntdll_get_thread_data()->wait_fd[0] );
|
|
|
|
close( ntdll_get_thread_data()->wait_fd[1] );
|
|
|
|
close( ntdll_get_thread_data()->reply_fd );
|
|
|
|
close( ntdll_get_thread_data()->request_fd );
|
2009-02-20 11:45:47 +01:00
|
|
|
pthread_exit( UIntToPtr(status) );
|
2009-02-20 11:23:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* exit_thread
|
|
|
|
*/
|
2009-06-18 16:50:34 +02:00
|
|
|
void exit_thread( int status )
|
2009-02-20 11:23:08 +01:00
|
|
|
{
|
2009-02-23 14:02:16 +01:00
|
|
|
static void *prev_teb;
|
|
|
|
TEB *teb;
|
2009-02-20 11:23:08 +01:00
|
|
|
|
2009-06-18 16:50:34 +02:00
|
|
|
if (status) /* send the exit code to the server (0 is already the default) */
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( terminate_thread )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( GetCurrentThread() );
|
|
|
|
req->exit_code = status;
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interlocked_xchg_add( &nb_threads, -1 ) <= 1)
|
|
|
|
{
|
|
|
|
LdrShutdownProcess();
|
|
|
|
exit( status );
|
|
|
|
}
|
|
|
|
|
|
|
|
LdrShutdownThread();
|
2009-02-20 11:23:08 +01:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
RemoveEntryList( &NtCurrentTeb()->TlsLinks );
|
|
|
|
RtlReleasePebLock();
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots );
|
|
|
|
|
|
|
|
pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
|
|
|
|
|
2009-02-23 14:02:16 +01:00
|
|
|
if ((teb = interlocked_xchg_ptr( &prev_teb, NtCurrentTeb() )))
|
|
|
|
{
|
2009-11-19 12:27:09 +01:00
|
|
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SpareBytes1;
|
2009-02-23 14:02:16 +01:00
|
|
|
|
|
|
|
pthread_join( thread_data->pthread_id, NULL );
|
2009-11-19 12:25:52 +01:00
|
|
|
signal_free_thread( teb );
|
2009-02-23 14:02:16 +01:00
|
|
|
}
|
2009-02-20 11:45:47 +01:00
|
|
|
|
2009-02-23 14:02:16 +01:00
|
|
|
close( ntdll_get_thread_data()->wait_fd[0] );
|
|
|
|
close( ntdll_get_thread_data()->wait_fd[1] );
|
|
|
|
close( ntdll_get_thread_data()->reply_fd );
|
|
|
|
close( ntdll_get_thread_data()->request_fd );
|
2009-02-20 11:45:47 +01:00
|
|
|
pthread_exit( UIntToPtr(status) );
|
2009-02-20 11:23:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* start_thread
|
|
|
|
*
|
|
|
|
* Startup routine for a newly created thread.
|
|
|
|
*/
|
2009-02-23 14:24:59 +01:00
|
|
|
static void start_thread( struct startup_info *info )
|
2003-10-31 01:16:20 +01:00
|
|
|
{
|
2009-02-23 14:24:59 +01:00
|
|
|
TEB *teb = info->teb;
|
2009-11-19 12:27:09 +01:00
|
|
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SpareBytes1;
|
2009-02-23 14:24:59 +01:00
|
|
|
PRTL_THREAD_START_ROUTINE func = info->entry_point;
|
|
|
|
void *arg = info->entry_arg;
|
2003-11-06 00:31:11 +01:00
|
|
|
struct debug_info debug_info;
|
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;
|
2009-02-23 14:02:16 +01:00
|
|
|
thread_data->pthread_id = pthread_self();
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
signal_init_thread( teb );
|
2009-02-18 12:30:01 +01:00
|
|
|
server_init_thread( func );
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
|
2007-01-18 12:23:04 +01:00
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
InsertHeadList( &tls_links, &teb->TlsLinks );
|
|
|
|
RtlReleasePebLock();
|
|
|
|
|
2009-06-18 16:38:30 +02:00
|
|
|
MODULE_DllThreadAttach( NULL );
|
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), func, arg );
|
|
|
|
|
|
|
|
call_thread_entry_point( (LPTHREAD_START_ROUTINE)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 )
|
|
|
|
{
|
2007-01-18 12:23:04 +01:00
|
|
|
sigset_t sigset;
|
2009-02-20 11:45:47 +01:00
|
|
|
pthread_t pthread_id;
|
|
|
|
pthread_attr_t attr;
|
2009-11-19 12:25:52 +01:00
|
|
|
struct ntdll_thread_data *thread_data;
|
2003-11-25 04:42:05 +01:00
|
|
|
struct startup_info *info = NULL;
|
2003-10-31 01:16:20 +01:00
|
|
|
HANDLE handle = 0;
|
2009-11-19 12:25:52 +01:00
|
|
|
TEB *teb = NULL;
|
2003-10-31 01:16:20 +01:00
|
|
|
DWORD tid = 0;
|
|
|
|
int request_pipe[2];
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2007-01-18 15:02:55 +01:00
|
|
|
if (process != NtCurrentProcess())
|
2004-09-21 02:23:50 +02:00
|
|
|
{
|
2007-01-18 15:02:55 +01:00
|
|
|
apc_call_t call;
|
|
|
|
apc_result_t result;
|
|
|
|
|
2007-12-11 15:07:42 +01:00
|
|
|
memset( &call, 0, sizeof(call) );
|
|
|
|
|
2007-01-18 15:02:55 +01:00
|
|
|
call.create_thread.type = APC_CREATE_THREAD;
|
2008-12-30 15:30:11 +01:00
|
|
|
call.create_thread.func = wine_server_client_ptr( start );
|
|
|
|
call.create_thread.arg = wine_server_client_ptr( param );
|
2007-01-18 15:02:55 +01:00
|
|
|
call.create_thread.reserve = stack_reserve;
|
|
|
|
call.create_thread.commit = stack_commit;
|
|
|
|
call.create_thread.suspend = suspended;
|
|
|
|
status = NTDLL_queue_process_apc( process, &call, &result );
|
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
|
|
|
|
if (result.create_thread.status == STATUS_SUCCESS)
|
|
|
|
{
|
2007-05-23 09:36:29 +02:00
|
|
|
if (id) id->UniqueThread = ULongToHandle(result.create_thread.tid);
|
2008-12-08 16:05:17 +01:00
|
|
|
if (handle_ptr) *handle_ptr = wine_server_ptr_handle( result.create_thread.handle );
|
|
|
|
else NtClose( wine_server_ptr_handle( result.create_thread.handle ));
|
2007-01-18 15:02:55 +01:00
|
|
|
}
|
|
|
|
return result.create_thread.status;
|
2004-09-21 02:23:50 +02:00
|
|
|
}
|
|
|
|
|
2009-07-01 12:13:34 +02:00
|
|
|
if (server_pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
|
2003-10-31 01:16:20 +01:00
|
|
|
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 )))
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
handle = wine_server_ptr_handle( reply->handle );
|
2003-10-31 01:16:20 +01:00
|
|
|
tid = reply->tid;
|
|
|
|
}
|
|
|
|
close( request_pipe[0] );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2007-01-18 12:23:04 +01:00
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
close( request_pipe[1] );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_BLOCK, &server_block_set, &sigset );
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2009-11-19 12:25:52 +01:00
|
|
|
if ((status = signal_alloc_thread( &teb ))) goto error;
|
|
|
|
|
2006-07-24 15:19:32 +02:00
|
|
|
teb->Peb = NtCurrentTeb()->Peb;
|
2009-11-19 12:25:52 +01:00
|
|
|
teb->ClientId.UniqueProcess = ULongToHandle(GetCurrentProcessId());
|
|
|
|
teb->ClientId.UniqueThread = ULongToHandle(tid);
|
|
|
|
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
|
|
|
|
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
|
|
|
|
|
2007-01-18 12:20:10 +01:00
|
|
|
info = (struct startup_info *)(teb + 1);
|
2009-02-23 14:24:59 +01:00
|
|
|
info->teb = teb;
|
|
|
|
info->entry_point = start;
|
|
|
|
info->entry_arg = param;
|
|
|
|
|
2009-11-19 12:27:09 +01:00
|
|
|
thread_data = (struct ntdll_thread_data *)teb->SpareBytes1;
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data->request_fd = request_pipe[1];
|
2009-11-19 12:25:52 +01:00
|
|
|
thread_data->reply_fd = -1;
|
|
|
|
thread_data->wait_fd[0] = -1;
|
|
|
|
thread_data->wait_fd[1] = -1;
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2009-02-23 14:24:59 +01:00
|
|
|
if ((status = virtual_alloc_thread_stack( teb, stack_reserve, stack_commit ))) goto error;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2009-02-20 11:45:47 +01:00
|
|
|
pthread_attr_init( &attr );
|
2009-02-23 14:24:59 +01:00
|
|
|
pthread_attr_setstack( &attr, teb->DeallocationStack,
|
|
|
|
(char *)teb->Tib.StackBase - (char *)teb->DeallocationStack );
|
2009-02-20 11:45:47 +01:00
|
|
|
pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); /* force creating a kernel thread */
|
|
|
|
interlocked_xchg_add( &nb_threads, 1 );
|
|
|
|
if (pthread_create( &pthread_id, &attr, (void * (*)(void *))start_thread, info ))
|
2003-10-31 01:16:20 +01:00
|
|
|
{
|
2009-02-20 11:45:47 +01:00
|
|
|
interlocked_xchg_add( &nb_threads, -1 );
|
|
|
|
pthread_attr_destroy( &attr );
|
2003-11-06 00:31:11 +01:00
|
|
|
status = STATUS_NO_MEMORY;
|
2003-10-31 01:16:20 +01:00
|
|
|
goto error;
|
|
|
|
}
|
2009-02-20 11:45:47 +01:00
|
|
|
pthread_attr_destroy( &attr );
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_SETMASK, &sigset, NULL );
|
2003-10-31 01:16:20 +01:00
|
|
|
|
2007-05-23 09:36:29 +02:00
|
|
|
if (id) id->UniqueThread = ULongToHandle(tid);
|
2003-10-31 01:16:20 +01:00
|
|
|
if (handle_ptr) *handle_ptr = handle;
|
|
|
|
else NtClose( handle );
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
2009-11-19 12:25:52 +01:00
|
|
|
if (teb) signal_free_thread( teb );
|
2003-10-31 01:16:20 +01:00
|
|
|
if (handle) NtClose( handle );
|
2009-02-20 11:15:06 +01:00
|
|
|
pthread_sigmask( SIG_SETMASK, &sigset, NULL );
|
2003-10-31 01:16:20 +01:00
|
|
|
close( request_pipe[1] );
|
|
|
|
return 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 )
|
|
|
|
{
|
2007-05-23 09:36:29 +02:00
|
|
|
req->tid = HandleToULong(id->UniqueThread);
|
2005-12-09 12:13:11 +01:00
|
|
|
req->access = access;
|
|
|
|
req->attributes = attr ? attr->Attributes : 0;
|
2003-04-05 00:26:34 +02:00
|
|
|
ret = wine_server_call( req );
|
2008-12-08 16:05:17 +01:00
|
|
|
*handle = wine_server_ptr_handle( reply->handle );
|
2003-04-05 00:26:34 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* NtSuspendThread (NTDLL.@)
|
|
|
|
* ZwSuspendThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( suspend_thread )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2003-04-05 00:26:34 +02:00
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2003-04-05 00:26:34 +02:00
|
|
|
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;
|
2009-08-28 11:52:21 +02:00
|
|
|
BOOL self;
|
2003-04-05 00:26:34 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( terminate_thread )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2003-04-05 00:26:34 +02:00
|
|
|
req->exit_code = exit_code;
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
self = !ret && reply->self;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
2009-08-28 11:52:21 +02:00
|
|
|
if (self) 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 )
|
|
|
|
{
|
2008-12-26 12:19:41 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2007-01-04 13:40:09 +01:00
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
req->call.type = APC_USER;
|
2008-12-30 21:09:41 +01:00
|
|
|
req->call.user.func = wine_server_client_ptr( func );
|
2007-01-04 13:40:09 +01:00
|
|
|
req->call.user.args[0] = arg1;
|
|
|
|
req->call.user.args[1] = arg2;
|
|
|
|
req->call.user.args[2] = arg3;
|
|
|
|
}
|
|
|
|
else req->call.type = APC_NONE; /* wake up only */
|
2003-04-05 00:26:34 +02:00
|
|
|
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)))
|
|
|
|
{
|
2009-11-19 12:27:09 +01:00
|
|
|
self = (ntdll_get_thread_data()->dr0 == context->Dr0 &&
|
|
|
|
ntdll_get_thread_data()->dr1 == context->Dr1 &&
|
|
|
|
ntdll_get_thread_data()->dr2 == context->Dr2 &&
|
|
|
|
ntdll_get_thread_data()->dr3 == context->Dr3 &&
|
|
|
|
ntdll_get_thread_data()->dr6 == context->Dr6 &&
|
|
|
|
ntdll_get_thread_data()->dr7 == context->Dr7);
|
2006-01-13 13:58:14 +01:00
|
|
|
}
|
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
|
|
|
{
|
2009-04-08 19:38:02 +02:00
|
|
|
context_t server_context;
|
|
|
|
|
|
|
|
context_to_server( &server_context, context );
|
|
|
|
|
2006-01-11 20:20:32 +01:00
|
|
|
SERVER_START_REQ( set_thread_context )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2006-01-11 20:20:32 +01:00
|
|
|
req->suspend = 0;
|
2009-04-08 19:38:02 +02:00
|
|
|
wine_server_add_data( req, &server_context, sizeof(server_context) );
|
2006-01-11 20:20:32 +01:00
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2006-01-11 20:20:32 +01:00
|
|
|
req->suspend = 0;
|
2009-04-08 19:38:02 +02:00
|
|
|
wine_server_add_data( req, &server_context, sizeof(server_context) );
|
2006-01-11 20:20:32 +01:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2007-12-03 13:55:25 +01:00
|
|
|
if (ret == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
timeout.QuadPart = -10000;
|
|
|
|
NtDelayExecution( FALSE, &timeout );
|
|
|
|
}
|
|
|
|
else break;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-08 19:38:02 +02:00
|
|
|
/* convert CPU-specific flags to generic server flags */
|
|
|
|
static inline unsigned int get_server_context_flags( DWORD flags )
|
|
|
|
{
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
2009-07-25 14:23:31 +02:00
|
|
|
flags &= 0x3f; /* mask CPU id flags */
|
2009-04-08 19:38:02 +02:00
|
|
|
if (flags & CONTEXT_CONTROL) ret |= SERVER_CTX_CONTROL;
|
|
|
|
if (flags & CONTEXT_INTEGER) ret |= SERVER_CTX_INTEGER;
|
|
|
|
#ifdef CONTEXT_SEGMENTS
|
|
|
|
if (flags & CONTEXT_SEGMENTS) ret |= SERVER_CTX_SEGMENTS;
|
|
|
|
#endif
|
|
|
|
#ifdef CONTEXT_FLOATING_POINT
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT) ret |= SERVER_CTX_FLOATING_POINT;
|
|
|
|
#endif
|
|
|
|
#ifdef CONTEXT_DEBUG_REGISTERS
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS) ret |= SERVER_CTX_DEBUG_REGISTERS;
|
|
|
|
#endif
|
|
|
|
#ifdef CONTEXT_EXTENDED_REGISTERS
|
|
|
|
if (flags & CONTEXT_EXTENDED_REGISTERS) ret |= SERVER_CTX_EXTENDED_REGISTERS;
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-04-05 00:26:34 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtGetContextThread (NTDLL.@)
|
|
|
|
* ZwGetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
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
|
|
|
{
|
2009-04-08 19:38:02 +02:00
|
|
|
unsigned int server_flags = get_server_context_flags( context->ContextFlags );
|
|
|
|
context_t server_context;
|
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
SERVER_START_REQ( get_thread_context )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2009-04-08 19:38:02 +02:00
|
|
|
req->flags = server_flags;
|
2006-04-20 15:40:28 +02:00
|
|
|
req->suspend = 0;
|
2009-04-08 19:38:02 +02:00
|
|
|
wine_server_set_reply( req, &server_context, sizeof(server_context) );
|
2006-04-20 15:40:28 +02:00
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2009-04-08 19:38:02 +02:00
|
|
|
req->flags = server_flags;
|
2006-04-20 15:40:28 +02:00
|
|
|
req->suspend = 0;
|
2009-04-08 19:38:02 +02:00
|
|
|
wine_server_set_reply( req, &server_context, sizeof(server_context) );
|
2006-04-20 15:40:28 +02:00
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2007-12-03 13:55:25 +01:00
|
|
|
if (ret == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
timeout.QuadPart = -10000;
|
|
|
|
NtDelayExecution( FALSE, &timeout );
|
|
|
|
}
|
|
|
|
else break;
|
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
|
|
|
}
|
2009-04-08 19:38:02 +02:00
|
|
|
if (!ret) ret = context_from_server( context, &server_context );
|
2006-04-20 15:40:28 +02:00
|
|
|
if (ret) return ret;
|
2009-04-08 19:38:02 +02:00
|
|
|
needed_flags &= ~context->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)
|
|
|
|
{
|
2009-04-08 19:38:02 +02:00
|
|
|
CONTEXT ctx;
|
2009-01-06 17:50:34 +01:00
|
|
|
RtlCaptureContext( &ctx );
|
2006-04-20 15:40:28 +02:00
|
|
|
copy_context( context, &ctx, ctx.ContextFlags & needed_flags );
|
2009-04-08 19:38:02 +02:00
|
|
|
context->ContextFlags |= ctx.ContextFlags & needed_flags;
|
2006-04-20 15:40:28 +02:00
|
|
|
}
|
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
|
|
|
{
|
2009-11-19 12:27:09 +01:00
|
|
|
ntdll_get_thread_data()->dr0 = context->Dr0;
|
|
|
|
ntdll_get_thread_data()->dr1 = context->Dr1;
|
|
|
|
ntdll_get_thread_data()->dr2 = context->Dr2;
|
|
|
|
ntdll_get_thread_data()->dr3 = context->Dr3;
|
|
|
|
ntdll_get_thread_data()->dr6 = context->Dr6;
|
|
|
|
ntdll_get_thread_data()->dr7 = context->Dr7;
|
2006-01-13 13:58:14 +01:00
|
|
|
}
|
|
|
|
#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;
|
2009-01-19 14:15:51 +01:00
|
|
|
const ULONG_PTR affinity_mask = ((ULONG_PTR)1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
|
2003-07-09 04:57:57 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( get_thread_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2003-07-09 04:57:57 +02:00
|
|
|
req->tid_in = 0;
|
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
{
|
|
|
|
info.ExitStatus = reply->exit_code;
|
2008-12-30 23:02:33 +01:00
|
|
|
info.TebBaseAddress = wine_server_get_ptr( reply->teb );
|
2007-05-23 09:36:29 +02:00
|
|
|
info.ClientId.UniqueProcess = ULongToHandle(reply->pid);
|
|
|
|
info.ClientId.UniqueThread = ULongToHandle(reply->tid);
|
2008-01-16 21:02:04 +01:00
|
|
|
info.AffinityMask = reply->affinity & affinity_mask;
|
2003-07-09 04:57:57 +02:00
|
|
|
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;
|
2009-01-21 18:51:49 +01:00
|
|
|
case ThreadAffinityMask:
|
|
|
|
{
|
|
|
|
const ULONG_PTR affinity_mask = ((ULONG_PTR)1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
|
|
|
|
ULONG_PTR affinity = 0;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->tid_in = 0;
|
|
|
|
if (!(status = wine_server_call( req )))
|
|
|
|
affinity = reply->affinity & affinity_mask;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
if (data) memcpy( data, &affinity, min( length, sizeof(affinity) ));
|
|
|
|
if (ret_len) *ret_len = min( length, sizeof(affinity) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
2003-07-09 04:57:57 +02:00
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2005-09-13 00:01:33 +02:00
|
|
|
req->tid_in = 0;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
2007-04-17 20:08:59 +02:00
|
|
|
kusrt.CreateTime.QuadPart = reply->creation_time;
|
|
|
|
kusrt.ExitTime.QuadPart = 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
|
|
|
|
{
|
2007-10-29 14:11:23 +01:00
|
|
|
static BOOL reported = FALSE;
|
|
|
|
|
2005-09-13 00:01:33 +02:00
|
|
|
kusrt.KernelTime.QuadPart = 0;
|
|
|
|
kusrt.UserTime.QuadPart = 0;
|
2007-10-29 14:11:23 +01:00
|
|
|
if (reported)
|
|
|
|
TRACE("Cannot get kerneltime or usertime of other threads\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Cannot get kerneltime or usertime of other threads\n");
|
|
|
|
reported = TRUE;
|
|
|
|
}
|
2005-09-13 00:01:33 +02:00
|
|
|
}
|
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2006-05-26 12:10:57 +02:00
|
|
|
req->entry = tdi->Selector >> 3;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
if (!(reply->flags & WINE_LDT_FLAGS_ALLOCATED))
|
2006-11-04 11:52:44 +01:00
|
|
|
status = STATUS_ACCESS_VIOLATION;
|
2006-05-26 12:10:57 +02:00
|
|
|
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-11-04 11:52:44 +01:00
|
|
|
if (status == STATUS_SUCCESS && ret_len)
|
|
|
|
/* yes, that's a bit strange, but it's the way it is */
|
|
|
|
*ret_len = sizeof(LDT_ENTRY);
|
2006-05-26 12:10:57 +02:00
|
|
|
#else
|
|
|
|
status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
2006-10-01 08:17:27 +02:00
|
|
|
case ThreadAmILastThread:
|
|
|
|
{
|
|
|
|
SERVER_START_REQ(get_thread_info)
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2006-10-01 08:17:27 +02:00
|
|
|
req->tid_in = 0;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
BOOLEAN last = reply->last;
|
|
|
|
if (data) memcpy( data, &last, min( length, sizeof(last) ));
|
|
|
|
if (ret_len) *ret_len = min( length, sizeof(last) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
2003-07-09 04:57:57 +02:00
|
|
|
case ThreadPriority:
|
|
|
|
case ThreadBasePriority:
|
|
|
|
case ThreadImpersonationToken:
|
|
|
|
case ThreadEnableAlignmentFaultFixup:
|
|
|
|
case ThreadEventPair_Reusable:
|
|
|
|
case ThreadQuerySetWin32StartAddress:
|
|
|
|
case ThreadZeroTlsCell:
|
|
|
|
case ThreadPerformanceCount:
|
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->token = wine_server_obj_handle( *phToken );
|
2005-06-20 15:18:38 +02:00
|
|
|
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 )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2005-09-07 15:25:35 +02:00
|
|
|
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:
|
|
|
|
{
|
2009-01-19 14:15:51 +01:00
|
|
|
const ULONG_PTR affinity_mask = ((ULONG_PTR)1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
|
|
|
|
const ULONG_PTR *paff = data;
|
|
|
|
if (length != sizeof(ULONG_PTR)) return STATUS_INVALID_PARAMETER;
|
2008-01-16 21:02:04 +01:00
|
|
|
if (*paff & ~affinity_mask) return STATUS_INVALID_PARAMETER;
|
2009-09-28 17:25:16 +02:00
|
|
|
if (!*paff) return STATUS_INVALID_PARAMETER;
|
2006-01-11 12:32:19 +01:00
|
|
|
SERVER_START_REQ( set_thread_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2006-01-11 12:32:19 +01:00
|
|
|
req->affinity = *paff;
|
|
|
|
req->mask = SET_THREAD_INFO_AFFINITY;
|
|
|
|
status = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
return status;
|
2009-10-06 11:34:48 +02:00
|
|
|
case ThreadHideFromDebugger:
|
|
|
|
/* pretend the call succeeded to satisfy some code protectors */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|