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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2003-10-09 06:59:03 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
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"
|
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 peb;
|
|
|
|
static PEB_LDR_DATA ldr;
|
|
|
|
static RTL_USER_PROCESS_PARAMETERS params; /* default parameters if no parent */
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* alloc_teb
|
|
|
|
*/
|
|
|
|
static TEB *alloc_teb( ULONG *size )
|
|
|
|
{
|
|
|
|
TEB *teb;
|
2005-06-06 22:04:33 +02:00
|
|
|
struct ntdll_thread_data *thread_data;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
|
|
|
*size = SIGNAL_STACK_SIZE + sizeof(TEB);
|
2005-06-17 14:15:44 +02:00
|
|
|
teb = wine_anon_mmap( NULL, *size, PROT_READ | PROT_WRITE, 0 );
|
2003-11-04 05:50:18 +01:00
|
|
|
if (teb == (TEB *)-1) return NULL;
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
|
|
|
if (!(thread_data->teb_sel = wine_ldt_alloc_fs()))
|
2003-11-04 05:50:18 +01:00
|
|
|
{
|
|
|
|
munmap( teb, *size );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
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->Peb = &peb;
|
|
|
|
teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
|
|
|
|
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
|
|
|
|
return teb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* free_teb
|
|
|
|
*/
|
|
|
|
static inline void free_teb( TEB *teb )
|
|
|
|
{
|
|
|
|
ULONG size = 0;
|
|
|
|
void *addr = teb;
|
2005-06-06 22:04:33 +02:00
|
|
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
2003-11-04 05:50:18 +01:00
|
|
|
|
2005-02-22 20:33:50 +01:00
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
|
2005-06-06 22:04:33 +02:00
|
|
|
wine_ldt_free_fs( thread_data->teb_sel );
|
2003-11-04 05:50:18 +01:00
|
|
|
munmap( teb, SIGNAL_STACK_SIZE + sizeof(TEB) );
|
|
|
|
}
|
|
|
|
|
2003-04-05 00:26:34 +02: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.
|
|
|
|
*/
|
2003-11-04 05:50:18 +01:00
|
|
|
void thread_init(void)
|
2003-10-09 06:59:03 +02:00
|
|
|
{
|
2003-11-04 05:50:18 +01:00
|
|
|
TEB *teb;
|
|
|
|
void *addr;
|
|
|
|
ULONG size;
|
2005-06-06 22:04:33 +02:00
|
|
|
struct ntdll_thread_data *thread_data;
|
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
|
|
|
|
2004-06-15 02:52:03 +02:00
|
|
|
peb.NumberOfProcessors = 1;
|
|
|
|
peb.ProcessParameters = ¶ms;
|
|
|
|
peb.TlsBitmap = &tls_bitmap;
|
2005-03-19 18:14:12 +01:00
|
|
|
peb.TlsExpansionBitmap = &tls_expansion_bitmap;
|
2004-06-15 02:52:03 +02:00
|
|
|
peb.LdrData = &ldr;
|
2004-08-23 20:52:54 +02:00
|
|
|
RtlInitializeBitMap( &tls_bitmap, peb.TlsBitmapBits, sizeof(peb.TlsBitmapBits) * 8 );
|
2005-03-19 18:14:12 +01:00
|
|
|
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 );
|
|
|
|
|
|
|
|
teb = alloc_teb( &size );
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
|
|
|
thread_data->request_fd = -1;
|
|
|
|
thread_data->reply_fd = -1;
|
|
|
|
thread_data->wait_fd[0] = -1;
|
|
|
|
thread_data->wait_fd[1] = -1;
|
|
|
|
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;
|
|
|
|
thread_info.teb_size = size;
|
2005-06-06 22:04:33 +02:00
|
|
|
thread_info.teb_sel = thread_data->teb_sel;
|
2004-02-05 03:01:35 +01:00
|
|
|
wine_pthread_init_current_teb( &thread_info );
|
2003-11-09 02:25:23 +01:00
|
|
|
wine_pthread_init_thread( &thread_info );
|
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();
|
|
|
|
virtual_init();
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
/* setup the server connection */
|
2003-11-06 01:08:05 +01:00
|
|
|
server_init_process();
|
2003-11-25 04:42:05 +01:00
|
|
|
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 a memory view for the TEB */
|
2004-10-11 22:59:06 +02:00
|
|
|
addr = teb;
|
2005-02-22 20:33:50 +01:00
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, &size,
|
2005-06-17 14:15:44 +02:00
|
|
|
MEM_SYSTEM, PAGE_READWRITE );
|
2003-11-04 05:50:18 +01:00
|
|
|
|
|
|
|
/* create the process heap */
|
|
|
|
if (!(peb.ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
|
|
|
|
{
|
|
|
|
MESSAGE( "wine: failed to create the process heap\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
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;
|
|
|
|
ULONG size;
|
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
|
|
|
|
2004-02-05 03:01:35 +01:00
|
|
|
wine_pthread_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 );
|
2004-02-05 03:01:35 +01:00
|
|
|
wine_pthread_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;
|
|
|
|
teb->Tib.StackLimit = info->stack_base;
|
|
|
|
|
|
|
|
/* setup the guard page */
|
|
|
|
size = 1;
|
2005-02-22 20:33:50 +01:00
|
|
|
NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size,
|
2005-06-21 11:57:53 +02:00
|
|
|
PAGE_READWRITE | PAGE_GUARD, 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();
|
|
|
|
|
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 )
|
|
|
|
{
|
2005-06-06 22:04:33 +02: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;
|
2003-11-04 05:50:18 +01:00
|
|
|
TEB *teb = NULL;
|
2003-10-31 01:16:20 +01:00
|
|
|
DWORD tid = 0;
|
2003-11-04 05:50:18 +01:00
|
|
|
ULONG size;
|
2003-10-31 01:16:20 +01:00
|
|
|
int request_pipe[2];
|
|
|
|
NTSTATUS status;
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
req->suspend = suspended;
|
|
|
|
req->inherit = 0; /* FIXME */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-04 05:50:18 +01:00
|
|
|
if (!(teb = alloc_teb( &size )))
|
2003-10-31 01:16:20 +01:00
|
|
|
{
|
2003-11-04 05:50:18 +01:00
|
|
|
status = STATUS_NO_MEMORY;
|
2003-10-31 01:16:20 +01:00
|
|
|
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;
|
|
|
|
thread_data->request_fd = request_pipe[1];
|
|
|
|
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
|
|
|
|
2004-10-11 22:59:06 +02:00
|
|
|
info->pthread_info.teb_base = teb;
|
2005-02-22 20:33:50 +01:00
|
|
|
NtAllocateVirtualMemory( NtCurrentProcess(), &info->pthread_info.teb_base, 0, &size,
|
2005-06-17 14:15:44 +02:00
|
|
|
MEM_SYSTEM, PAGE_READWRITE );
|
2003-11-25 04:42:05 +01:00
|
|
|
info->pthread_info.teb_size = size;
|
2005-06-06 22:04:33 +02:00
|
|
|
info->pthread_info.teb_sel = thread_data->teb_sel;
|
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;
|
|
|
|
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
|
|
|
|
2003-11-25 04:42:05 +01:00
|
|
|
if (wine_pthread_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:
|
2003-11-04 05:50:18 +01:00
|
|
|
if (teb) free_teb( teb );
|
2003-11-06 00:31:11 +01:00
|
|
|
if (info) RtlFreeHeap( GetProcessHeap(), 0, info );
|
2003-10-31 01:16:20 +01:00
|
|
|
if (handle) NtClose( handle );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
req->tid = (thread_id_t)id->UniqueThread;
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_thread_context )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = context->ContextFlags;
|
|
|
|
wine_server_add_data( req, context, sizeof(*context) );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NtGetContextThread (NTDLL.@)
|
|
|
|
* ZwGetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_thread_context )
|
|
|
|
{
|
|
|
|
req->handle = handle;
|
|
|
|
req->flags = context->ContextFlags;
|
|
|
|
wine_server_add_data( req, context, sizeof(*context) );
|
|
|
|
wine_server_set_reply( req, context, sizeof(*context) );
|
|
|
|
ret = wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
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:
|
|
|
|
case ThreadPriority:
|
|
|
|
case ThreadBasePriority:
|
|
|
|
case ThreadAffinityMask:
|
|
|
|
case ThreadImpersonationToken:
|
|
|
|
case ThreadDescriptorTableEntry:
|
|
|
|
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;
|
|
|
|
return status;
|
2004-08-14 01:20:27 +02:00
|
|
|
}
|
2003-09-08 21:02:01 +02:00
|
|
|
case ThreadBasicInformation:
|
|
|
|
case ThreadTimes:
|
|
|
|
case ThreadPriority:
|
|
|
|
case ThreadBasePriority:
|
|
|
|
case ThreadAffinityMask:
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return wine_pthread_get_current_teb();
|
|
|
|
}
|
2004-05-17 23:08:31 +02:00
|
|
|
|
2003-11-09 02:25:23 +01:00
|
|
|
#endif /* __i386__ */
|