wgl: Remove the pixel format limitation.
[wine/testsucceed.git] / dlls / ntdll / thread.c
blob55cedc7093c393d8bee976c86c2abdba4f17514b
1 /*
2 * NT threads support
4 * Copyright 1996, 2003 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <sys/types.h>
26 #ifdef HAVE_SYS_MMAN_H
27 #include <sys/mman.h>
28 #endif
29 #ifdef HAVE_SYS_TIMES_H
30 #include <sys/times.h>
31 #endif
33 #define NONAMELESSUNION
34 #include "ntstatus.h"
35 #define WIN32_NO_STATUS
36 #include "thread.h"
37 #include "winternl.h"
38 #include "wine/library.h"
39 #include "wine/server.h"
40 #include "wine/pthread.h"
41 #include "wine/debug.h"
42 #include "ntdll_misc.h"
43 #include "ddk/wdm.h"
44 #include "wine/exception.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(thread);
47 WINE_DECLARE_DEBUG_CHANNEL(relay);
49 struct _KUSER_SHARED_DATA *user_shared_data = NULL;
51 PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter = NULL;
53 /* info passed to a starting thread */
54 struct startup_info
56 struct wine_pthread_thread_info pthread_info;
57 PRTL_THREAD_START_ROUTINE entry_point;
58 void *entry_arg;
61 static PEB_LDR_DATA ldr;
62 static RTL_USER_PROCESS_PARAMETERS params; /* default parameters if no parent */
63 static WCHAR current_dir[MAX_NT_PATH_LENGTH];
64 static RTL_BITMAP tls_bitmap;
65 static RTL_BITMAP tls_expansion_bitmap;
66 static LIST_ENTRY tls_links;
67 static size_t sigstack_total_size;
68 static ULONG sigstack_zero_bits;
70 struct wine_pthread_functions pthread_functions = { NULL };
73 static RTL_CRITICAL_SECTION ldt_section;
74 static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
76 0, 0, &ldt_section,
77 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
78 0, 0, { (DWORD_PTR)(__FILE__ ": ldt_section") }
80 static RTL_CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 };
81 static sigset_t ldt_sigset;
83 /***********************************************************************
84 * locking for LDT routines
86 static void ldt_lock(void)
88 sigset_t sigset;
90 pthread_functions.sigprocmask( SIG_BLOCK, &server_block_set, &sigset );
91 RtlEnterCriticalSection( &ldt_section );
92 if (ldt_section.RecursionCount == 1) ldt_sigset = sigset;
95 static void ldt_unlock(void)
97 if (ldt_section.RecursionCount == 1)
99 sigset_t sigset = ldt_sigset;
100 RtlLeaveCriticalSection( &ldt_section );
101 pthread_functions.sigprocmask( SIG_SETMASK, &sigset, NULL );
103 else RtlLeaveCriticalSection( &ldt_section );
107 /***********************************************************************
108 * init_teb
110 static inline NTSTATUS init_teb( TEB *teb )
112 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
114 teb->Tib.ExceptionList = (void *)~0UL;
115 teb->Tib.StackBase = (void *)~0UL;
116 teb->Tib.Self = &teb->Tib;
117 teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
118 teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
120 if (!(thread_data->fs = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
121 thread_data->request_fd = -1;
122 thread_data->reply_fd = -1;
123 thread_data->wait_fd[0] = -1;
124 thread_data->wait_fd[1] = -1;
126 return STATUS_SUCCESS;
130 /***********************************************************************
131 * fix_unicode_string
133 * Make sure the unicode string doesn't point beyond the end pointer
135 static inline void fix_unicode_string( UNICODE_STRING *str, const char *end_ptr )
137 if ((char *)str->Buffer >= end_ptr)
139 str->Length = str->MaximumLength = 0;
140 str->Buffer = NULL;
141 return;
143 if ((char *)str->Buffer + str->MaximumLength > end_ptr)
145 str->MaximumLength = (end_ptr - (char *)str->Buffer) & ~(sizeof(WCHAR) - 1);
147 if (str->Length >= str->MaximumLength)
149 if (str->MaximumLength >= sizeof(WCHAR))
150 str->Length = str->MaximumLength - sizeof(WCHAR);
151 else
152 str->Length = str->MaximumLength = 0;
157 /***********************************************************************
158 * init_user_process_params
160 * Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
162 static NTSTATUS init_user_process_params( SIZE_T info_size, HANDLE *exe_file )
164 void *ptr;
165 SIZE_T env_size;
166 NTSTATUS status;
167 RTL_USER_PROCESS_PARAMETERS *params = NULL;
169 status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&params, 0, &info_size,
170 MEM_COMMIT, PAGE_READWRITE );
171 if (status != STATUS_SUCCESS) return status;
173 params->AllocationSize = info_size;
174 NtCurrentTeb()->Peb->ProcessParameters = params;
176 SERVER_START_REQ( get_startup_info )
178 wine_server_set_reply( req, params, info_size );
179 if (!(status = wine_server_call( req )))
181 info_size = wine_server_reply_size( reply );
182 *exe_file = reply->exe_file;
183 params->hStdInput = reply->hstdin;
184 params->hStdOutput = reply->hstdout;
185 params->hStdError = reply->hstderr;
188 SERVER_END_REQ;
189 if (status != STATUS_SUCCESS) return status;
191 if (params->Size > info_size) params->Size = info_size;
193 /* make sure the strings are valid */
194 fix_unicode_string( &params->CurrentDirectory.DosPath, (char *)info_size );
195 fix_unicode_string( &params->DllPath, (char *)info_size );
196 fix_unicode_string( &params->ImagePathName, (char *)info_size );
197 fix_unicode_string( &params->CommandLine, (char *)info_size );
198 fix_unicode_string( &params->WindowTitle, (char *)info_size );
199 fix_unicode_string( &params->Desktop, (char *)info_size );
200 fix_unicode_string( &params->ShellInfo, (char *)info_size );
201 fix_unicode_string( &params->RuntimeInfo, (char *)info_size );
203 /* environment needs to be a separate memory block */
204 env_size = info_size - params->Size;
205 if (!env_size) env_size = 1;
206 ptr = NULL;
207 status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &env_size,
208 MEM_COMMIT, PAGE_READWRITE );
209 if (status != STATUS_SUCCESS) return status;
210 memcpy( ptr, (char *)params + params->Size, info_size - params->Size );
211 params->Environment = ptr;
213 RtlNormalizeProcessParams( params );
214 return status;
218 /***********************************************************************
219 * thread_init
221 * Setup the initial thread.
223 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
225 HANDLE thread_init(void)
227 PEB *peb;
228 TEB *teb;
229 void *addr;
230 SIZE_T size, info_size;
231 HANDLE exe_file = 0;
232 LARGE_INTEGER now;
233 struct ntdll_thread_data *thread_data;
234 struct wine_pthread_thread_info thread_info;
235 static struct debug_info debug_info; /* debug info for initial thread */
237 virtual_init();
239 /* reserve space for shared user data */
241 addr = (void *)0x7ffe0000;
242 size = 0x10000;
243 NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, &size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE );
244 user_shared_data = addr;
246 /* allocate and initialize the PEB */
248 addr = NULL;
249 size = sizeof(*peb);
250 NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 1, &size,
251 MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE );
252 peb = addr;
254 peb->NumberOfProcessors = 1;
255 peb->ProcessParameters = &params;
256 peb->TlsBitmap = &tls_bitmap;
257 peb->TlsExpansionBitmap = &tls_expansion_bitmap;
258 peb->LdrData = &ldr;
259 params.CurrentDirectory.DosPath.Buffer = current_dir;
260 params.CurrentDirectory.DosPath.MaximumLength = sizeof(current_dir);
261 params.wShowWindow = 1; /* SW_SHOWNORMAL */
262 RtlInitializeBitMap( &tls_bitmap, peb->TlsBitmapBits, sizeof(peb->TlsBitmapBits) * 8 );
263 RtlInitializeBitMap( &tls_expansion_bitmap, peb->TlsExpansionBitmapBits,
264 sizeof(peb->TlsExpansionBitmapBits) * 8 );
265 InitializeListHead( &ldr.InLoadOrderModuleList );
266 InitializeListHead( &ldr.InMemoryOrderModuleList );
267 InitializeListHead( &ldr.InInitializationOrderModuleList );
268 InitializeListHead( &tls_links );
270 /* allocate and initialize the initial TEB */
272 sigstack_total_size = get_signal_stack_total_size();
273 while (1 << sigstack_zero_bits < sigstack_total_size) sigstack_zero_bits++;
274 assert( 1 << sigstack_zero_bits == sigstack_total_size ); /* must be a power of 2 */
275 assert( sigstack_total_size >= sizeof(TEB) + sizeof(struct startup_info) );
276 thread_info.teb_size = sigstack_total_size;
278 addr = NULL;
279 size = sigstack_total_size;
280 NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
281 &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE );
282 teb = addr;
283 teb->Peb = peb;
284 thread_info.teb_size = size;
285 init_teb( teb );
286 thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
287 thread_data->debug_info = &debug_info;
288 InsertHeadList( &tls_links, &teb->TlsLinks );
290 thread_info.stack_base = NULL;
291 thread_info.stack_size = 0;
292 thread_info.teb_base = teb;
293 thread_info.teb_sel = thread_data->fs;
294 wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) );
295 pthread_functions.init_current_teb( &thread_info );
296 pthread_functions.init_thread( &thread_info );
297 virtual_init_threading();
299 debug_info.str_pos = debug_info.strings;
300 debug_info.out_pos = debug_info.output;
301 debug_init();
303 /* setup the server connection */
304 server_init_process();
305 info_size = server_init_thread( thread_info.pid, thread_info.tid, NULL );
307 /* create the process heap */
308 if (!(peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
310 MESSAGE( "wine: failed to create the process heap\n" );
311 exit(1);
314 /* allocate user parameters */
315 if (info_size)
317 init_user_process_params( info_size, &exe_file );
319 else
321 /* This is wine specific: we have no parent (we're started from unix)
322 * so, create a simple console with bare handles to unix stdio
324 wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, OBJ_INHERIT, &params.hStdInput );
325 wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, &params.hStdOutput );
326 wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, &params.hStdError );
329 /* initialize LDT locking */
330 wine_ldt_init_locking( ldt_lock, ldt_unlock );
332 /* initialize time values in user_shared_data */
333 NtQuerySystemTime( &now );
334 user_shared_data->SystemTime.LowPart = now.u.LowPart;
335 user_shared_data->SystemTime.High1Time = user_shared_data->SystemTime.High2Time = now.u.HighPart;
336 user_shared_data->u.TickCountQuad = (now.QuadPart - server_start_time) / 10000;
337 user_shared_data->u.TickCount.High2Time = user_shared_data->u.TickCount.High1Time;
338 user_shared_data->TickCountLowDeprecated = user_shared_data->u.TickCount.LowPart;
339 user_shared_data->TickCountMultiplier = 1 << 24;
341 return exe_file;
344 #ifdef __i386__
345 /* wrapper for apps that don't declare the thread function correctly */
346 extern DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg );
347 __ASM_GLOBAL_FUNC(call_thread_entry_point,
348 "pushl %ebp\n\t"
349 "movl %esp,%ebp\n\t"
350 "subl $4,%esp\n\t"
351 "pushl 12(%ebp)\n\t"
352 "movl 8(%ebp),%eax\n\t"
353 "call *%eax\n\t"
354 "leave\n\t"
355 "ret" );
356 #else
357 static inline DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg )
359 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)entry;
360 return func( arg );
362 #endif
364 /***********************************************************************
365 * call_thread_func
367 * Hack to make things compatible with the thread procedures used by kernel32.CreateThread.
369 static void DECLSPEC_NORETURN call_thread_func( PRTL_THREAD_START_ROUTINE rtl_func, void *arg )
371 DWORD exit_code;
372 BOOL last;
374 MODULE_DllThreadAttach( NULL );
376 if (TRACE_ON(relay))
377 DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), rtl_func, arg );
379 exit_code = call_thread_entry_point( rtl_func, arg );
381 /* send the exit code to the server */
382 SERVER_START_REQ( terminate_thread )
384 req->handle = GetCurrentThread();
385 req->exit_code = exit_code;
386 wine_server_call( req );
387 last = reply->last;
389 SERVER_END_REQ;
391 if (last)
393 LdrShutdownProcess();
394 exit( exit_code );
396 else
398 LdrShutdownThread();
399 server_exit_thread( exit_code );
404 /***********************************************************************
405 * start_thread
407 * Startup routine for a newly created thread.
409 static void start_thread( struct wine_pthread_thread_info *info )
411 TEB *teb = info->teb_base;
412 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
413 struct startup_info *startup_info = (struct startup_info *)info;
414 PRTL_THREAD_START_ROUTINE func = startup_info->entry_point;
415 void *arg = startup_info->entry_arg;
416 struct debug_info debug_info;
417 SIZE_T size, page_size = getpagesize();
419 debug_info.str_pos = debug_info.strings;
420 debug_info.out_pos = debug_info.output;
421 thread_data->debug_info = &debug_info;
423 pthread_functions.init_current_teb( info );
424 SIGNAL_Init();
425 server_init_thread( info->pid, info->tid, func );
426 pthread_functions.init_thread( info );
428 /* allocate a memory view for the stack */
429 size = info->stack_size;
430 teb->DeallocationStack = info->stack_base;
431 NtAllocateVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, 0,
432 &size, MEM_SYSTEM, PAGE_READWRITE );
433 /* limit is lower than base since the stack grows down */
434 teb->Tib.StackBase = (char *)info->stack_base + info->stack_size;
435 teb->Tib.StackLimit = (char *)info->stack_base + page_size;
437 /* setup the guard page */
438 size = page_size;
439 NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size, PAGE_NOACCESS, NULL );
441 pthread_functions.sigprocmask( SIG_UNBLOCK, &server_block_set, NULL );
443 RtlAcquirePebLock();
444 InsertHeadList( &tls_links, &teb->TlsLinks );
445 RtlReleasePebLock();
447 /* NOTE: Windows does not have an exception handler around the call to
448 * the thread attach. We do for ease of debugging */
449 if (unhandled_exception_filter)
451 __TRY
453 call_thread_func( func, arg );
455 __EXCEPT(unhandled_exception_filter)
457 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
459 __ENDTRY
461 else
462 call_thread_func( func, arg );
466 /***********************************************************************
467 * RtlCreateUserThread (NTDLL.@)
469 NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *descr,
470 BOOLEAN suspended, PVOID stack_addr,
471 SIZE_T stack_reserve, SIZE_T stack_commit,
472 PRTL_THREAD_START_ROUTINE start, void *param,
473 HANDLE *handle_ptr, CLIENT_ID *id )
475 sigset_t sigset;
476 struct ntdll_thread_data *thread_data = NULL;
477 struct ntdll_thread_regs *thread_regs;
478 struct startup_info *info = NULL;
479 void *addr = NULL;
480 HANDLE handle = 0;
481 TEB *teb;
482 DWORD tid = 0;
483 int request_pipe[2];
484 NTSTATUS status;
485 SIZE_T size, page_size = getpagesize();
487 if (process != NtCurrentProcess())
489 apc_call_t call;
490 apc_result_t result;
492 memset( &call, 0, sizeof(call) );
494 call.create_thread.type = APC_CREATE_THREAD;
495 call.create_thread.func = start;
496 call.create_thread.arg = param;
497 call.create_thread.reserve = stack_reserve;
498 call.create_thread.commit = stack_commit;
499 call.create_thread.suspend = suspended;
500 status = NTDLL_queue_process_apc( process, &call, &result );
501 if (status != STATUS_SUCCESS) return status;
503 if (result.create_thread.status == STATUS_SUCCESS)
505 if (id) id->UniqueThread = ULongToHandle(result.create_thread.tid);
506 if (handle_ptr) *handle_ptr = result.create_thread.handle;
507 else NtClose( result.create_thread.handle );
509 return result.create_thread.status;
512 if (pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
513 fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
514 wine_server_send_fd( request_pipe[0] );
516 SERVER_START_REQ( new_thread )
518 req->access = THREAD_ALL_ACCESS;
519 req->attributes = 0; /* FIXME */
520 req->suspend = suspended;
521 req->request_fd = request_pipe[0];
522 if (!(status = wine_server_call( req )))
524 handle = reply->handle;
525 tid = reply->tid;
527 close( request_pipe[0] );
529 SERVER_END_REQ;
531 if (status)
533 close( request_pipe[1] );
534 return status;
537 pthread_functions.sigprocmask( SIG_BLOCK, &server_block_set, &sigset );
539 addr = NULL;
540 size = sigstack_total_size;
541 if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
542 &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE )))
543 goto error;
544 teb = addr;
545 teb->Peb = NtCurrentTeb()->Peb;
546 info = (struct startup_info *)(teb + 1);
547 info->pthread_info.teb_size = size;
548 if ((status = init_teb( teb ))) goto error;
550 teb->ClientId.UniqueProcess = ULongToHandle(GetCurrentProcessId());
551 teb->ClientId.UniqueThread = ULongToHandle(tid);
553 thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
554 thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
555 thread_data->request_fd = request_pipe[1];
557 info->pthread_info.teb_base = teb;
558 info->pthread_info.teb_sel = thread_data->fs;
560 /* inherit debug registers from parent thread */
561 thread_regs->dr0 = ntdll_get_thread_regs()->dr0;
562 thread_regs->dr1 = ntdll_get_thread_regs()->dr1;
563 thread_regs->dr2 = ntdll_get_thread_regs()->dr2;
564 thread_regs->dr3 = ntdll_get_thread_regs()->dr3;
565 thread_regs->dr6 = ntdll_get_thread_regs()->dr6;
566 thread_regs->dr7 = ntdll_get_thread_regs()->dr7;
568 if (!stack_reserve || !stack_commit)
570 IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress );
571 if (!stack_reserve) stack_reserve = nt->OptionalHeader.SizeOfStackReserve;
572 if (!stack_commit) stack_commit = nt->OptionalHeader.SizeOfStackCommit;
574 if (stack_reserve < stack_commit) stack_reserve = stack_commit;
575 stack_reserve += page_size; /* for the guard page */
576 stack_reserve = (stack_reserve + 0xffff) & ~0xffff; /* round to 64K boundary */
577 if (stack_reserve < 1024 * 1024) stack_reserve = 1024 * 1024; /* Xlib needs a large stack */
579 info->pthread_info.stack_base = NULL;
580 info->pthread_info.stack_size = stack_reserve;
581 info->pthread_info.entry = start_thread;
582 info->entry_point = start;
583 info->entry_arg = param;
585 if (pthread_functions.create_thread( &info->pthread_info ) == -1)
587 status = STATUS_NO_MEMORY;
588 goto error;
590 pthread_functions.sigprocmask( SIG_SETMASK, &sigset, NULL );
592 if (id) id->UniqueThread = ULongToHandle(tid);
593 if (handle_ptr) *handle_ptr = handle;
594 else NtClose( handle );
596 return STATUS_SUCCESS;
598 error:
599 if (thread_data) wine_ldt_free_fs( thread_data->fs );
600 if (addr)
602 SIZE_T size = 0;
603 NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
605 if (handle) NtClose( handle );
606 pthread_functions.sigprocmask( SIG_SETMASK, &sigset, NULL );
607 close( request_pipe[1] );
608 return status;
612 /***********************************************************************
613 * RtlExitUserThread (NTDLL.@)
615 void WINAPI RtlExitUserThread( ULONG status )
617 LdrShutdownThread();
618 server_exit_thread( status );
622 /***********************************************************************
623 * NtOpenThread (NTDLL.@)
624 * ZwOpenThread (NTDLL.@)
626 NTSTATUS WINAPI NtOpenThread( HANDLE *handle, ACCESS_MASK access,
627 const OBJECT_ATTRIBUTES *attr, const CLIENT_ID *id )
629 NTSTATUS ret;
631 SERVER_START_REQ( open_thread )
633 req->tid = HandleToULong(id->UniqueThread);
634 req->access = access;
635 req->attributes = attr ? attr->Attributes : 0;
636 ret = wine_server_call( req );
637 *handle = reply->handle;
639 SERVER_END_REQ;
640 return ret;
644 /******************************************************************************
645 * NtSuspendThread (NTDLL.@)
646 * ZwSuspendThread (NTDLL.@)
648 NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
650 NTSTATUS ret;
652 SERVER_START_REQ( suspend_thread )
654 req->handle = handle;
655 if (!(ret = wine_server_call( req ))) *count = reply->count;
657 SERVER_END_REQ;
658 return ret;
662 /******************************************************************************
663 * NtResumeThread (NTDLL.@)
664 * ZwResumeThread (NTDLL.@)
666 NTSTATUS WINAPI NtResumeThread( HANDLE handle, PULONG count )
668 NTSTATUS ret;
670 SERVER_START_REQ( resume_thread )
672 req->handle = handle;
673 if (!(ret = wine_server_call( req ))) *count = reply->count;
675 SERVER_END_REQ;
676 return ret;
680 /******************************************************************************
681 * NtAlertResumeThread (NTDLL.@)
682 * ZwAlertResumeThread (NTDLL.@)
684 NTSTATUS WINAPI NtAlertResumeThread( HANDLE handle, PULONG count )
686 FIXME( "stub: should alert thread %p\n", handle );
687 return NtResumeThread( handle, count );
691 /******************************************************************************
692 * NtAlertThread (NTDLL.@)
693 * ZwAlertThread (NTDLL.@)
695 NTSTATUS WINAPI NtAlertThread( HANDLE handle )
697 FIXME( "stub: %p\n", handle );
698 return STATUS_NOT_IMPLEMENTED;
702 /******************************************************************************
703 * NtTerminateThread (NTDLL.@)
704 * ZwTerminateThread (NTDLL.@)
706 NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
708 NTSTATUS ret;
709 BOOL self, last;
711 SERVER_START_REQ( terminate_thread )
713 req->handle = handle;
714 req->exit_code = exit_code;
715 ret = wine_server_call( req );
716 self = !ret && reply->self;
717 last = reply->last;
719 SERVER_END_REQ;
721 if (self)
723 if (last) exit( exit_code );
724 else server_abort_thread( exit_code );
726 return ret;
730 /******************************************************************************
731 * NtQueueApcThread (NTDLL.@)
733 NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1,
734 ULONG_PTR arg2, ULONG_PTR arg3 )
736 NTSTATUS ret;
737 SERVER_START_REQ( queue_apc )
739 req->thread = handle;
740 if (func)
742 req->call.type = APC_USER;
743 req->call.user.func = func;
744 req->call.user.args[0] = arg1;
745 req->call.user.args[1] = arg2;
746 req->call.user.args[2] = arg3;
748 else req->call.type = APC_NONE; /* wake up only */
749 ret = wine_server_call( req );
751 SERVER_END_REQ;
752 return ret;
756 /***********************************************************************
757 * NtSetContextThread (NTDLL.@)
758 * ZwSetContextThread (NTDLL.@)
760 NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
762 NTSTATUS ret;
763 DWORD dummy, i;
764 BOOL self = FALSE;
766 #ifdef __i386__
767 /* on i386 debug registers always require a server call */
768 self = (handle == GetCurrentThread());
769 if (self && (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)))
771 struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
772 self = (regs->dr0 == context->Dr0 && regs->dr1 == context->Dr1 &&
773 regs->dr2 == context->Dr2 && regs->dr3 == context->Dr3 &&
774 regs->dr6 == context->Dr6 && regs->dr7 == context->Dr7);
776 #endif
778 if (!self)
780 SERVER_START_REQ( set_thread_context )
782 req->handle = handle;
783 req->flags = context->ContextFlags;
784 req->suspend = 0;
785 wine_server_add_data( req, context, sizeof(*context) );
786 ret = wine_server_call( req );
787 self = reply->self;
789 SERVER_END_REQ;
791 if (ret == STATUS_PENDING)
793 if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
795 for (i = 0; i < 100; i++)
797 SERVER_START_REQ( set_thread_context )
799 req->handle = handle;
800 req->flags = context->ContextFlags;
801 req->suspend = 0;
802 wine_server_add_data( req, context, sizeof(*context) );
803 ret = wine_server_call( req );
805 SERVER_END_REQ;
806 if (ret == STATUS_PENDING)
808 LARGE_INTEGER timeout;
809 timeout.QuadPart = -10000;
810 NtDelayExecution( FALSE, &timeout );
812 else break;
814 NtResumeThread( handle, &dummy );
816 if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
819 if (ret) return ret;
822 if (self) set_cpu_context( context );
823 return STATUS_SUCCESS;
827 /* copy a context structure according to the flags */
828 static inline void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
830 #ifdef __i386__
831 flags &= ~CONTEXT_i386; /* get rid of CPU id */
832 if (flags & CONTEXT_INTEGER)
834 to->Eax = from->Eax;
835 to->Ebx = from->Ebx;
836 to->Ecx = from->Ecx;
837 to->Edx = from->Edx;
838 to->Esi = from->Esi;
839 to->Edi = from->Edi;
841 if (flags & CONTEXT_CONTROL)
843 to->Ebp = from->Ebp;
844 to->Esp = from->Esp;
845 to->Eip = from->Eip;
846 to->SegCs = from->SegCs;
847 to->SegSs = from->SegSs;
848 to->EFlags = from->EFlags;
850 if (flags & CONTEXT_SEGMENTS)
852 to->SegDs = from->SegDs;
853 to->SegEs = from->SegEs;
854 to->SegFs = from->SegFs;
855 to->SegGs = from->SegGs;
857 if (flags & CONTEXT_DEBUG_REGISTERS)
859 to->Dr0 = from->Dr0;
860 to->Dr1 = from->Dr1;
861 to->Dr2 = from->Dr2;
862 to->Dr3 = from->Dr3;
863 to->Dr6 = from->Dr6;
864 to->Dr7 = from->Dr7;
866 if (flags & CONTEXT_FLOATING_POINT)
868 to->FloatSave = from->FloatSave;
870 if (flags & CONTEXT_EXTENDED_REGISTERS)
872 memcpy( to->ExtendedRegisters, from->ExtendedRegisters, sizeof(to->ExtendedRegisters) );
874 #elif defined(__x86_64__)
875 flags &= ~CONTEXT_AMD64; /* get rid of CPU id */
876 if (flags & CONTEXT_CONTROL)
878 to->Rbp = from->Rbp;
879 to->Rip = from->Rip;
880 to->Rsp = from->Rsp;
881 to->SegCs = from->SegCs;
882 to->SegSs = from->SegSs;
883 to->EFlags = from->EFlags;
884 to->MxCsr = from->MxCsr;
886 if (flags & CONTEXT_INTEGER)
888 to->Rax = from->Rax;
889 to->Rcx = from->Rcx;
890 to->Rdx = from->Rdx;
891 to->Rbx = from->Rbx;
892 to->Rsi = from->Rsi;
893 to->Rdi = from->Rdi;
894 to->R8 = from->R8;
895 to->R9 = from->R9;
896 to->R10 = from->R10;
897 to->R11 = from->R11;
898 to->R12 = from->R12;
899 to->R13 = from->R13;
900 to->R14 = from->R14;
901 to->R15 = from->R15;
903 if (flags & CONTEXT_SEGMENTS)
905 to->SegDs = from->SegDs;
906 to->SegEs = from->SegEs;
907 to->SegFs = from->SegFs;
908 to->SegGs = from->SegGs;
910 if (flags & CONTEXT_FLOATING_POINT)
912 to->u.FltSave = from->u.FltSave;
914 if (flags & CONTEXT_DEBUG_REGISTERS)
916 to->Dr0 = from->Dr0;
917 to->Dr1 = from->Dr1;
918 to->Dr2 = from->Dr2;
919 to->Dr3 = from->Dr3;
920 to->Dr6 = from->Dr6;
921 to->Dr7 = from->Dr7;
923 #elif defined(__sparc__)
924 flags &= ~CONTEXT_SPARC; /* get rid of CPU id */
925 if (flags & CONTEXT_CONTROL)
927 to->psr = from->psr;
928 to->pc = from->pc;
929 to->npc = from->npc;
930 to->y = from->y;
931 to->wim = from->wim;
932 to->tbr = from->tbr;
934 if (flags & CONTEXT_INTEGER)
936 to->g0 = from->g0;
937 to->g1 = from->g1;
938 to->g2 = from->g2;
939 to->g3 = from->g3;
940 to->g4 = from->g4;
941 to->g5 = from->g5;
942 to->g6 = from->g6;
943 to->g7 = from->g7;
944 to->o0 = from->o0;
945 to->o1 = from->o1;
946 to->o2 = from->o2;
947 to->o3 = from->o3;
948 to->o4 = from->o4;
949 to->o5 = from->o5;
950 to->o6 = from->o6;
951 to->o7 = from->o7;
952 to->l0 = from->l0;
953 to->l1 = from->l1;
954 to->l2 = from->l2;
955 to->l3 = from->l3;
956 to->l4 = from->l4;
957 to->l5 = from->l5;
958 to->l6 = from->l6;
959 to->l7 = from->l7;
960 to->i0 = from->i0;
961 to->i1 = from->i1;
962 to->i2 = from->i2;
963 to->i3 = from->i3;
964 to->i4 = from->i4;
965 to->i5 = from->i5;
966 to->i6 = from->i6;
967 to->i7 = from->i7;
969 if (flags & CONTEXT_FLOATING_POINT)
971 /* FIXME */
973 #elif defined(__powerpc__)
974 /* Has no CPU id */
975 if (flags & CONTEXT_CONTROL)
977 to->Msr = from->Msr;
978 to->Ctr = from->Ctr;
979 to->Iar = from->Iar;
981 if (flags & CONTEXT_INTEGER)
983 to->Gpr0 = from->Gpr0;
984 to->Gpr1 = from->Gpr1;
985 to->Gpr2 = from->Gpr2;
986 to->Gpr3 = from->Gpr3;
987 to->Gpr4 = from->Gpr4;
988 to->Gpr5 = from->Gpr5;
989 to->Gpr6 = from->Gpr6;
990 to->Gpr7 = from->Gpr7;
991 to->Gpr8 = from->Gpr8;
992 to->Gpr9 = from->Gpr9;
993 to->Gpr10 = from->Gpr10;
994 to->Gpr11 = from->Gpr11;
995 to->Gpr12 = from->Gpr12;
996 to->Gpr13 = from->Gpr13;
997 to->Gpr14 = from->Gpr14;
998 to->Gpr15 = from->Gpr15;
999 to->Gpr16 = from->Gpr16;
1000 to->Gpr17 = from->Gpr17;
1001 to->Gpr18 = from->Gpr18;
1002 to->Gpr19 = from->Gpr19;
1003 to->Gpr20 = from->Gpr20;
1004 to->Gpr21 = from->Gpr21;
1005 to->Gpr22 = from->Gpr22;
1006 to->Gpr23 = from->Gpr23;
1007 to->Gpr24 = from->Gpr24;
1008 to->Gpr25 = from->Gpr25;
1009 to->Gpr26 = from->Gpr26;
1010 to->Gpr27 = from->Gpr27;
1011 to->Gpr28 = from->Gpr28;
1012 to->Gpr29 = from->Gpr29;
1013 to->Gpr30 = from->Gpr30;
1014 to->Gpr31 = from->Gpr31;
1015 to->Xer = from->Xer;
1016 to->Cr = from->Cr;
1018 if (flags & CONTEXT_FLOATING_POINT)
1020 to->Fpr0 = from->Fpr0;
1021 to->Fpr1 = from->Fpr1;
1022 to->Fpr2 = from->Fpr2;
1023 to->Fpr3 = from->Fpr3;
1024 to->Fpr4 = from->Fpr4;
1025 to->Fpr5 = from->Fpr5;
1026 to->Fpr6 = from->Fpr6;
1027 to->Fpr7 = from->Fpr7;
1028 to->Fpr8 = from->Fpr8;
1029 to->Fpr9 = from->Fpr9;
1030 to->Fpr10 = from->Fpr10;
1031 to->Fpr11 = from->Fpr11;
1032 to->Fpr12 = from->Fpr12;
1033 to->Fpr13 = from->Fpr13;
1034 to->Fpr14 = from->Fpr14;
1035 to->Fpr15 = from->Fpr15;
1036 to->Fpr16 = from->Fpr16;
1037 to->Fpr17 = from->Fpr17;
1038 to->Fpr18 = from->Fpr18;
1039 to->Fpr19 = from->Fpr19;
1040 to->Fpr20 = from->Fpr20;
1041 to->Fpr21 = from->Fpr21;
1042 to->Fpr22 = from->Fpr22;
1043 to->Fpr23 = from->Fpr23;
1044 to->Fpr24 = from->Fpr24;
1045 to->Fpr25 = from->Fpr25;
1046 to->Fpr26 = from->Fpr26;
1047 to->Fpr27 = from->Fpr27;
1048 to->Fpr28 = from->Fpr28;
1049 to->Fpr29 = from->Fpr29;
1050 to->Fpr30 = from->Fpr30;
1051 to->Fpr31 = from->Fpr31;
1052 to->Fpscr = from->Fpscr;
1054 #else
1055 #error You must implement context copying for your CPU
1056 #endif
1060 /***********************************************************************
1061 * NtGetContextThread (NTDLL.@)
1062 * ZwGetContextThread (NTDLL.@)
1064 NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
1066 NTSTATUS ret;
1067 CONTEXT ctx;
1068 DWORD dummy, i;
1069 DWORD needed_flags = context->ContextFlags;
1070 BOOL self = (handle == GetCurrentThread());
1072 #ifdef __i386__
1073 /* on i386 debug registers always require a server call */
1074 if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)) self = FALSE;
1075 #endif
1077 if (!self)
1079 SERVER_START_REQ( get_thread_context )
1081 req->handle = handle;
1082 req->flags = context->ContextFlags;
1083 req->suspend = 0;
1084 wine_server_set_reply( req, &ctx, sizeof(ctx) );
1085 ret = wine_server_call( req );
1086 self = reply->self;
1088 SERVER_END_REQ;
1090 if (ret == STATUS_PENDING)
1092 if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
1094 for (i = 0; i < 100; i++)
1096 SERVER_START_REQ( get_thread_context )
1098 req->handle = handle;
1099 req->flags = context->ContextFlags;
1100 req->suspend = 0;
1101 wine_server_set_reply( req, &ctx, sizeof(ctx) );
1102 ret = wine_server_call( req );
1104 SERVER_END_REQ;
1105 if (ret == STATUS_PENDING)
1107 LARGE_INTEGER timeout;
1108 timeout.QuadPart = -10000;
1109 NtDelayExecution( FALSE, &timeout );
1111 else break;
1113 NtResumeThread( handle, &dummy );
1115 if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
1117 if (ret) return ret;
1118 copy_context( context, &ctx, context->ContextFlags & ctx.ContextFlags );
1119 needed_flags &= ~ctx.ContextFlags;
1122 if (self)
1124 if (needed_flags)
1126 get_cpu_context( &ctx );
1127 copy_context( context, &ctx, ctx.ContextFlags & needed_flags );
1129 #ifdef __i386__
1130 /* update the cached version of the debug registers */
1131 if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386))
1133 struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
1134 regs->dr0 = context->Dr0;
1135 regs->dr1 = context->Dr1;
1136 regs->dr2 = context->Dr2;
1137 regs->dr3 = context->Dr3;
1138 regs->dr6 = context->Dr6;
1139 regs->dr7 = context->Dr7;
1141 #endif
1143 return STATUS_SUCCESS;
1147 /******************************************************************************
1148 * NtQueryInformationThread (NTDLL.@)
1149 * ZwQueryInformationThread (NTDLL.@)
1151 NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
1152 void *data, ULONG length, ULONG *ret_len )
1154 NTSTATUS status;
1156 switch(class)
1158 case ThreadBasicInformation:
1160 THREAD_BASIC_INFORMATION info;
1161 const unsigned int affinity_mask = (1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
1163 SERVER_START_REQ( get_thread_info )
1165 req->handle = handle;
1166 req->tid_in = 0;
1167 if (!(status = wine_server_call( req )))
1169 info.ExitStatus = reply->exit_code;
1170 info.TebBaseAddress = reply->teb;
1171 info.ClientId.UniqueProcess = ULongToHandle(reply->pid);
1172 info.ClientId.UniqueThread = ULongToHandle(reply->tid);
1173 info.AffinityMask = reply->affinity & affinity_mask;
1174 info.Priority = reply->priority;
1175 info.BasePriority = reply->priority; /* FIXME */
1178 SERVER_END_REQ;
1179 if (status == STATUS_SUCCESS)
1181 if (data) memcpy( data, &info, min( length, sizeof(info) ));
1182 if (ret_len) *ret_len = min( length, sizeof(info) );
1185 return status;
1186 case ThreadTimes:
1188 KERNEL_USER_TIMES kusrt;
1189 /* We need to do a server call to get the creation time or exit time */
1190 /* This works on any thread */
1191 SERVER_START_REQ( get_thread_info )
1193 req->handle = handle;
1194 req->tid_in = 0;
1195 status = wine_server_call( req );
1196 if (status == STATUS_SUCCESS)
1198 kusrt.CreateTime.QuadPart = reply->creation_time;
1199 kusrt.ExitTime.QuadPart = reply->exit_time;
1202 SERVER_END_REQ;
1203 if (status == STATUS_SUCCESS)
1205 /* We call times(2) for kernel time or user time */
1206 /* We can only (portably) do this for the current thread */
1207 if (handle == GetCurrentThread())
1209 struct tms time_buf;
1210 long clocks_per_sec = sysconf(_SC_CLK_TCK);
1212 times(&time_buf);
1213 kusrt.KernelTime.QuadPart = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
1214 kusrt.UserTime.QuadPart = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
1216 else
1218 static BOOL reported = FALSE;
1220 kusrt.KernelTime.QuadPart = 0;
1221 kusrt.UserTime.QuadPart = 0;
1222 if (reported)
1223 TRACE("Cannot get kerneltime or usertime of other threads\n");
1224 else
1226 FIXME("Cannot get kerneltime or usertime of other threads\n");
1227 reported = TRUE;
1230 if (data) memcpy( data, &kusrt, min( length, sizeof(kusrt) ));
1231 if (ret_len) *ret_len = min( length, sizeof(kusrt) );
1234 return status;
1235 case ThreadDescriptorTableEntry:
1237 #ifdef __i386__
1238 THREAD_DESCRIPTOR_INFORMATION* tdi = data;
1239 if (length < sizeof(*tdi))
1240 status = STATUS_INFO_LENGTH_MISMATCH;
1241 else if (!(tdi->Selector & 4)) /* GDT selector */
1243 unsigned sel = tdi->Selector & ~3; /* ignore RPL */
1244 status = STATUS_SUCCESS;
1245 if (!sel) /* null selector */
1246 memset( &tdi->Entry, 0, sizeof(tdi->Entry) );
1247 else
1249 tdi->Entry.BaseLow = 0;
1250 tdi->Entry.HighWord.Bits.BaseMid = 0;
1251 tdi->Entry.HighWord.Bits.BaseHi = 0;
1252 tdi->Entry.LimitLow = 0xffff;
1253 tdi->Entry.HighWord.Bits.LimitHi = 0xf;
1254 tdi->Entry.HighWord.Bits.Dpl = 3;
1255 tdi->Entry.HighWord.Bits.Sys = 0;
1256 tdi->Entry.HighWord.Bits.Pres = 1;
1257 tdi->Entry.HighWord.Bits.Granularity = 1;
1258 tdi->Entry.HighWord.Bits.Default_Big = 1;
1259 tdi->Entry.HighWord.Bits.Type = 0x12;
1260 /* it has to be one of the system GDT selectors */
1261 if (sel != (wine_get_ds() & ~3) && sel != (wine_get_ss() & ~3))
1263 if (sel == (wine_get_cs() & ~3))
1264 tdi->Entry.HighWord.Bits.Type |= 8; /* code segment */
1265 else status = STATUS_ACCESS_DENIED;
1269 else
1271 SERVER_START_REQ( get_selector_entry )
1273 req->handle = handle;
1274 req->entry = tdi->Selector >> 3;
1275 status = wine_server_call( req );
1276 if (!status)
1278 if (!(reply->flags & WINE_LDT_FLAGS_ALLOCATED))
1279 status = STATUS_ACCESS_VIOLATION;
1280 else
1282 wine_ldt_set_base ( &tdi->Entry, (void *)reply->base );
1283 wine_ldt_set_limit( &tdi->Entry, reply->limit );
1284 wine_ldt_set_flags( &tdi->Entry, reply->flags );
1288 SERVER_END_REQ;
1290 if (status == STATUS_SUCCESS && ret_len)
1291 /* yes, that's a bit strange, but it's the way it is */
1292 *ret_len = sizeof(LDT_ENTRY);
1293 #else
1294 status = STATUS_NOT_IMPLEMENTED;
1295 #endif
1296 return status;
1298 case ThreadAmILastThread:
1300 SERVER_START_REQ(get_thread_info)
1302 req->handle = handle;
1303 req->tid_in = 0;
1304 status = wine_server_call( req );
1305 if (status == STATUS_SUCCESS)
1307 BOOLEAN last = reply->last;
1308 if (data) memcpy( data, &last, min( length, sizeof(last) ));
1309 if (ret_len) *ret_len = min( length, sizeof(last) );
1312 SERVER_END_REQ;
1313 return status;
1315 case ThreadPriority:
1316 case ThreadBasePriority:
1317 case ThreadAffinityMask:
1318 case ThreadImpersonationToken:
1319 case ThreadEnableAlignmentFaultFixup:
1320 case ThreadEventPair_Reusable:
1321 case ThreadQuerySetWin32StartAddress:
1322 case ThreadZeroTlsCell:
1323 case ThreadPerformanceCount:
1324 case ThreadIdealProcessor:
1325 case ThreadPriorityBoost:
1326 case ThreadSetTlsArrayAddress:
1327 case ThreadIsIoPending:
1328 default:
1329 FIXME( "info class %d not supported yet\n", class );
1330 return STATUS_NOT_IMPLEMENTED;
1335 /******************************************************************************
1336 * NtSetInformationThread (NTDLL.@)
1337 * ZwSetInformationThread (NTDLL.@)
1339 NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
1340 LPCVOID data, ULONG length )
1342 NTSTATUS status;
1343 switch(class)
1345 case ThreadZeroTlsCell:
1346 if (handle == GetCurrentThread())
1348 LIST_ENTRY *entry;
1349 DWORD index;
1351 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
1352 index = *(const DWORD *)data;
1353 if (index < TLS_MINIMUM_AVAILABLE)
1355 RtlAcquirePebLock();
1356 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
1358 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
1359 teb->TlsSlots[index] = 0;
1361 RtlReleasePebLock();
1363 else
1365 index -= TLS_MINIMUM_AVAILABLE;
1366 if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
1367 return STATUS_INVALID_PARAMETER;
1368 RtlAcquirePebLock();
1369 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
1371 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
1372 if (teb->TlsExpansionSlots) teb->TlsExpansionSlots[index] = 0;
1374 RtlReleasePebLock();
1376 return STATUS_SUCCESS;
1378 FIXME( "ZeroTlsCell not supported on other threads\n" );
1379 return STATUS_NOT_IMPLEMENTED;
1381 case ThreadImpersonationToken:
1383 const HANDLE *phToken = data;
1384 if (length != sizeof(HANDLE)) return STATUS_INVALID_PARAMETER;
1385 TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken );
1386 SERVER_START_REQ( set_thread_info )
1388 req->handle = handle;
1389 req->token = *phToken;
1390 req->mask = SET_THREAD_INFO_TOKEN;
1391 status = wine_server_call( req );
1393 SERVER_END_REQ;
1395 return status;
1396 case ThreadBasePriority:
1398 const DWORD *pprio = data;
1399 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
1400 SERVER_START_REQ( set_thread_info )
1402 req->handle = handle;
1403 req->priority = *pprio;
1404 req->mask = SET_THREAD_INFO_PRIORITY;
1405 status = wine_server_call( req );
1407 SERVER_END_REQ;
1409 return status;
1410 case ThreadAffinityMask:
1412 const DWORD affinity_mask = (1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
1413 const DWORD *paff = data;
1414 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
1415 if (*paff & ~affinity_mask) return STATUS_INVALID_PARAMETER;
1416 SERVER_START_REQ( set_thread_info )
1418 req->handle = handle;
1419 req->affinity = *paff;
1420 req->mask = SET_THREAD_INFO_AFFINITY;
1421 status = wine_server_call( req );
1423 SERVER_END_REQ;
1425 return status;
1426 case ThreadBasicInformation:
1427 case ThreadTimes:
1428 case ThreadPriority:
1429 case ThreadDescriptorTableEntry:
1430 case ThreadEnableAlignmentFaultFixup:
1431 case ThreadEventPair_Reusable:
1432 case ThreadQuerySetWin32StartAddress:
1433 case ThreadPerformanceCount:
1434 case ThreadAmILastThread:
1435 case ThreadIdealProcessor:
1436 case ThreadPriorityBoost:
1437 case ThreadSetTlsArrayAddress:
1438 case ThreadIsIoPending:
1439 default:
1440 FIXME( "info class %d not supported yet\n", class );
1441 return STATUS_NOT_IMPLEMENTED;
1446 /**********************************************************************
1447 * NtCurrentTeb (NTDLL.@)
1449 #if defined(__i386__) && defined(__GNUC__)
1451 __ASM_GLOBAL_FUNC( NtCurrentTeb, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" )
1453 #elif defined(__i386__) && defined(_MSC_VER)
1455 /* Nothing needs to be done. MS C "magically" exports the inline version from winnt.h */
1457 #else
1459 /**********************************************************************/
1461 TEB * WINAPI NtCurrentTeb(void)
1463 return pthread_functions.get_current_teb();
1466 #endif /* __i386__ */