wnaspi32: Make winaspi.dll into a stand-alone 16-bit module.
[wine] / dlls / ntdll / thread.c
1 /*
2  * NT threads support
3  *
4  * Copyright 1996, 2003 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <stdarg.h>
26 #include <sys/types.h>
27 #ifdef HAVE_SYS_MMAN_H
28 #include <sys/mman.h>
29 #endif
30 #ifdef HAVE_SYS_TIMES_H
31 #include <sys/times.h>
32 #endif
33
34 #define NONAMELESSUNION
35 #include "ntstatus.h"
36 #define WIN32_NO_STATUS
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"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(thread);
47 WINE_DECLARE_DEBUG_CHANNEL(relay);
48
49 struct _KUSER_SHARED_DATA *user_shared_data = NULL;
50
51 PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter = NULL;
52
53 /* info passed to a starting thread */
54 struct startup_info
55 {
56     TEB                            *teb;
57     PRTL_THREAD_START_ROUTINE       entry_point;
58     void                           *entry_arg;
59 };
60
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 RTL_BITMAP fls_bitmap;
67 static LIST_ENTRY tls_links;
68 static size_t sigstack_total_size;
69 static ULONG sigstack_zero_bits;
70 static int nb_threads = 1;
71
72 static struct wine_pthread_functions pthread_functions;
73
74
75 static RTL_CRITICAL_SECTION ldt_section;
76 static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
77 {
78     0, 0, &ldt_section,
79     { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
80       0, 0, { (DWORD_PTR)(__FILE__ ": ldt_section") }
81 };
82 static RTL_CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 };
83 static sigset_t ldt_sigset;
84
85 /***********************************************************************
86  *           locking for LDT routines
87  */
88 static void ldt_lock(void)
89 {
90     sigset_t sigset;
91
92     pthread_sigmask( SIG_BLOCK, &server_block_set, &sigset );
93     RtlEnterCriticalSection( &ldt_section );
94     if (ldt_section.RecursionCount == 1) ldt_sigset = sigset;
95 }
96
97 static void ldt_unlock(void)
98 {
99     if (ldt_section.RecursionCount == 1)
100     {
101         sigset_t sigset = ldt_sigset;
102         RtlLeaveCriticalSection( &ldt_section );
103         pthread_sigmask( SIG_SETMASK, &sigset, NULL );
104     }
105     else RtlLeaveCriticalSection( &ldt_section );
106 }
107
108
109 /***********************************************************************
110  *           init_teb
111  */
112 static inline NTSTATUS init_teb( TEB *teb )
113 {
114     struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
115
116     teb->Tib.ExceptionList = (void *)~0UL;
117     teb->Tib.StackBase     = (void *)~0UL;
118     teb->Tib.Self          = &teb->Tib;
119     teb->StaticUnicodeString.Buffer        = teb->StaticUnicodeBuffer;
120     teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
121
122     if (!(thread_data->fs = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
123     thread_data->request_fd = -1;
124     thread_data->reply_fd   = -1;
125     thread_data->wait_fd[0] = -1;
126     thread_data->wait_fd[1] = -1;
127
128     return STATUS_SUCCESS;
129 }
130
131
132 /***********************************************************************
133  *           fix_unicode_string
134  *
135  * Make sure the unicode string doesn't point beyond the end pointer
136  */
137 static inline void fix_unicode_string( UNICODE_STRING *str, const char *end_ptr )
138 {
139     if ((char *)str->Buffer >= end_ptr)
140     {
141         str->Length = str->MaximumLength = 0;
142         str->Buffer = NULL;
143         return;
144     }
145     if ((char *)str->Buffer + str->MaximumLength > end_ptr)
146     {
147         str->MaximumLength = (end_ptr - (char *)str->Buffer) & ~(sizeof(WCHAR) - 1);
148     }
149     if (str->Length >= str->MaximumLength)
150     {
151         if (str->MaximumLength >= sizeof(WCHAR))
152             str->Length = str->MaximumLength - sizeof(WCHAR);
153         else
154             str->Length = str->MaximumLength = 0;
155     }
156 }
157
158
159 /***********************************************************************
160  *           init_user_process_params
161  *
162  * Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
163  */
164 static NTSTATUS init_user_process_params( SIZE_T info_size, HANDLE *exe_file )
165 {
166     void *ptr;
167     SIZE_T env_size;
168     NTSTATUS status;
169     RTL_USER_PROCESS_PARAMETERS *params = NULL;
170
171     status = NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&params, 0, &info_size,
172                                       MEM_COMMIT, PAGE_READWRITE );
173     if (status != STATUS_SUCCESS) return status;
174
175     params->AllocationSize = info_size;
176     NtCurrentTeb()->Peb->ProcessParameters = params;
177
178     SERVER_START_REQ( get_startup_info )
179     {
180         wine_server_set_reply( req, params, info_size );
181         if (!(status = wine_server_call( req )))
182         {
183             info_size = wine_server_reply_size( reply );
184             *exe_file = wine_server_ptr_handle( reply->exe_file );
185             params->hStdInput  = wine_server_ptr_handle( reply->hstdin );
186             params->hStdOutput = wine_server_ptr_handle( reply->hstdout );
187             params->hStdError  = wine_server_ptr_handle( reply->hstderr );
188         }
189     }
190     SERVER_END_REQ;
191     if (status != STATUS_SUCCESS) return status;
192
193     if (params->Size > info_size) params->Size = info_size;
194
195     /* make sure the strings are valid */
196     fix_unicode_string( &params->CurrentDirectory.DosPath, (char *)info_size );
197     fix_unicode_string( &params->DllPath, (char *)info_size );
198     fix_unicode_string( &params->ImagePathName, (char *)info_size );
199     fix_unicode_string( &params->CommandLine, (char *)info_size );
200     fix_unicode_string( &params->WindowTitle, (char *)info_size );
201     fix_unicode_string( &params->Desktop, (char *)info_size );
202     fix_unicode_string( &params->ShellInfo, (char *)info_size );
203     fix_unicode_string( &params->RuntimeInfo, (char *)info_size );
204
205     /* environment needs to be a separate memory block */
206     env_size = info_size - params->Size;
207     if (!env_size) env_size = 1;
208     ptr = NULL;
209     status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &env_size,
210                                       MEM_COMMIT, PAGE_READWRITE );
211     if (status != STATUS_SUCCESS) return status;
212     memcpy( ptr, (char *)params + params->Size, info_size - params->Size );
213     params->Environment = ptr;
214
215     RtlNormalizeProcessParams( params );
216     return status;
217 }
218
219
220 /***********************************************************************
221  *           thread_init
222  *
223  * Setup the initial thread.
224  *
225  * NOTES: The first allocated TEB on NT is at 0x7ffde000.
226  */
227 HANDLE thread_init(void)
228 {
229     PEB *peb;
230     TEB *teb;
231     void *addr;
232     SIZE_T size, info_size;
233     HANDLE exe_file = 0;
234     LARGE_INTEGER now;
235     struct ntdll_thread_data *thread_data;
236     static struct debug_info debug_info;  /* debug info for initial thread */
237
238     virtual_init();
239
240     /* reserve space for shared user data */
241
242     addr = (void *)0x7ffe0000;
243     size = 0x10000;
244     NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 0, &size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE );
245     user_shared_data = addr;
246
247     /* allocate and initialize the PEB */
248
249     addr = NULL;
250     size = sizeof(*peb);
251     NtAllocateVirtualMemory( NtCurrentProcess(), &addr, 1, &size,
252                              MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE );
253     peb = addr;
254
255     peb->NumberOfProcessors = 1;
256     peb->ProcessParameters  = &params;
257     peb->TlsBitmap          = &tls_bitmap;
258     peb->TlsExpansionBitmap = &tls_expansion_bitmap;
259     peb->FlsBitmap          = &fls_bitmap;
260     peb->LdrData            = &ldr;
261     params.CurrentDirectory.DosPath.Buffer = current_dir;
262     params.CurrentDirectory.DosPath.MaximumLength = sizeof(current_dir);
263     params.wShowWindow = 1; /* SW_SHOWNORMAL */
264     RtlInitializeBitMap( &tls_bitmap, peb->TlsBitmapBits, sizeof(peb->TlsBitmapBits) * 8 );
265     RtlInitializeBitMap( &tls_expansion_bitmap, peb->TlsExpansionBitmapBits,
266                          sizeof(peb->TlsExpansionBitmapBits) * 8 );
267     RtlInitializeBitMap( &fls_bitmap, peb->FlsBitmapBits, sizeof(peb->FlsBitmapBits) * 8 );
268     InitializeListHead( &peb->FlsListHead );
269     InitializeListHead( &ldr.InLoadOrderModuleList );
270     InitializeListHead( &ldr.InMemoryOrderModuleList );
271     InitializeListHead( &ldr.InInitializationOrderModuleList );
272     InitializeListHead( &tls_links );
273
274     /* allocate and initialize the initial TEB */
275
276     sigstack_total_size = get_signal_stack_total_size();
277     while (1U << sigstack_zero_bits < sigstack_total_size) sigstack_zero_bits++;
278     assert( 1U << sigstack_zero_bits == sigstack_total_size );  /* must be a power of 2 */
279     assert( sigstack_total_size >= sizeof(TEB) + sizeof(struct startup_info) );
280
281     addr = NULL;
282     size = sigstack_total_size;
283     NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
284                              &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE );
285     teb = addr;
286     teb->Peb = peb;
287     init_teb( teb );
288     thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
289     thread_data->debug_info = &debug_info;
290     InsertHeadList( &tls_links, &teb->TlsLinks );
291
292     wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) );
293     signal_init_thread( teb );
294     virtual_init_threading();
295
296     debug_info.str_pos = debug_info.strings;
297     debug_info.out_pos = debug_info.output;
298     debug_init();
299
300     /* setup the server connection */
301     server_init_process();
302     info_size = server_init_thread( NULL );
303
304     /* create the process heap */
305     if (!(peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
306     {
307         MESSAGE( "wine: failed to create the process heap\n" );
308         exit(1);
309     }
310
311     /* allocate user parameters */
312     if (info_size)
313     {
314         init_user_process_params( info_size, &exe_file );
315     }
316     else
317     {
318         /* This is wine specific: we have no parent (we're started from unix)
319          * so, create a simple console with bare handles to unix stdio
320          */
321         wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE,  OBJ_INHERIT, &params.hStdInput );
322         wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, &params.hStdOutput );
323         wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, &params.hStdError );
324     }
325
326     /* initialize LDT locking */
327     wine_ldt_init_locking( ldt_lock, ldt_unlock );
328
329     /* initialize time values in user_shared_data */
330     NtQuerySystemTime( &now );
331     user_shared_data->SystemTime.LowPart = now.u.LowPart;
332     user_shared_data->SystemTime.High1Time = user_shared_data->SystemTime.High2Time = now.u.HighPart;
333     user_shared_data->u.TickCountQuad = (now.QuadPart - server_start_time) / 10000;
334     user_shared_data->u.TickCount.High2Time = user_shared_data->u.TickCount.High1Time;
335     user_shared_data->TickCountLowDeprecated = user_shared_data->u.TickCount.LowPart;
336     user_shared_data->TickCountMultiplier = 1 << 24;
337
338     pthread_init();
339     return exe_file;
340 }
341
342
343 /***********************************************************************
344  *           abort_thread
345  */
346 void abort_thread( int status )
347 {
348     pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
349     if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) _exit( status );
350
351     close( ntdll_get_thread_data()->wait_fd[0] );
352     close( ntdll_get_thread_data()->wait_fd[1] );
353     close( ntdll_get_thread_data()->reply_fd );
354     close( ntdll_get_thread_data()->request_fd );
355     pthread_exit( UIntToPtr(status) );
356 }
357
358
359 /***********************************************************************
360  *           exit_thread
361  */
362 static void DECLSPEC_NORETURN exit_thread( int status )
363 {
364     static void *prev_teb;
365     TEB *teb;
366
367     RtlAcquirePebLock();
368     RemoveEntryList( &NtCurrentTeb()->TlsLinks );
369     RtlReleasePebLock();
370     RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots );
371     RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots );
372
373     pthread_sigmask( SIG_BLOCK, &server_block_set, NULL );
374     if (interlocked_xchg_add( &nb_threads, -1 ) <= 1) exit( status );
375
376     if ((teb = interlocked_xchg_ptr( &prev_teb, NtCurrentTeb() )))
377     {
378         struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
379         SIZE_T size;
380
381         pthread_join( thread_data->pthread_id, NULL );
382         wine_ldt_free_fs( thread_data->fs );
383         size = 0;
384         NtFreeVirtualMemory( GetCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE );
385         size = 0;
386         NtFreeVirtualMemory( GetCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
387     }
388
389     close( ntdll_get_thread_data()->wait_fd[0] );
390     close( ntdll_get_thread_data()->wait_fd[1] );
391     close( ntdll_get_thread_data()->reply_fd );
392     close( ntdll_get_thread_data()->request_fd );
393     pthread_exit( UIntToPtr(status) );
394 }
395
396
397 #ifdef __i386__
398 /* wrapper for apps that don't declare the thread function correctly */
399 extern DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg );
400 __ASM_GLOBAL_FUNC(call_thread_entry_point,
401                   "pushl %ebp\n\t"
402                   "movl %esp,%ebp\n\t"
403                   "subl $4,%esp\n\t"
404                   "pushl 12(%ebp)\n\t"
405                   "movl 8(%ebp),%eax\n\t"
406                   "call *%eax\n\t"
407                   "leave\n\t"
408                   "ret" )
409 #else
410 static inline DWORD call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry, void *arg )
411 {
412     LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)entry;
413     return func( arg );
414 }
415 #endif
416
417 /***********************************************************************
418  *           call_thread_func
419  *
420  * Hack to make things compatible with the thread procedures used by kernel32.CreateThread.
421  */
422 static void DECLSPEC_NORETURN call_thread_func( PRTL_THREAD_START_ROUTINE rtl_func, void *arg )
423 {
424     DWORD exit_code;
425     BOOL last;
426
427     MODULE_DllThreadAttach( NULL );
428
429     if (TRACE_ON(relay))
430         DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), rtl_func, arg );
431
432     exit_code = call_thread_entry_point( rtl_func, arg );
433
434     /* send the exit code to the server */
435     SERVER_START_REQ( terminate_thread )
436     {
437         req->handle    = wine_server_obj_handle( GetCurrentThread() );
438         req->exit_code = exit_code;
439         wine_server_call( req );
440         last = reply->last;
441     }
442     SERVER_END_REQ;
443
444     if (last)
445     {
446         LdrShutdownProcess();
447         exit( exit_code );
448     }
449     else
450     {
451         LdrShutdownThread();
452         exit_thread( exit_code );
453     }
454 }
455
456
457 /***********************************************************************
458  *           start_thread
459  *
460  * Startup routine for a newly created thread.
461  */
462 static void start_thread( struct startup_info *info )
463 {
464     TEB *teb = info->teb;
465     struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
466     PRTL_THREAD_START_ROUTINE func = info->entry_point;
467     void *arg = info->entry_arg;
468     struct debug_info debug_info;
469
470     debug_info.str_pos = debug_info.strings;
471     debug_info.out_pos = debug_info.output;
472     thread_data->debug_info = &debug_info;
473     thread_data->pthread_id = pthread_self();
474
475     signal_init_thread( teb );
476     server_init_thread( func );
477     pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
478
479     RtlAcquirePebLock();
480     InsertHeadList( &tls_links, &teb->TlsLinks );
481     RtlReleasePebLock();
482
483     /* NOTE: Windows does not have an exception handler around the call to
484      * the thread attach. We do for ease of debugging */
485     if (unhandled_exception_filter)
486     {
487         __TRY
488         {
489             call_thread_func( func, arg );
490         }
491         __EXCEPT(unhandled_exception_filter)
492         {
493             NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
494         }
495         __ENDTRY
496     }
497     else
498         call_thread_func( func, arg );
499 }
500
501
502 /***********************************************************************
503  *              RtlCreateUserThread   (NTDLL.@)
504  */
505 NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *descr,
506                                      BOOLEAN suspended, PVOID stack_addr,
507                                      SIZE_T stack_reserve, SIZE_T stack_commit,
508                                      PRTL_THREAD_START_ROUTINE start, void *param,
509                                      HANDLE *handle_ptr, CLIENT_ID *id )
510 {
511     sigset_t sigset;
512     pthread_t pthread_id;
513     pthread_attr_t attr;
514     struct ntdll_thread_data *thread_data = NULL;
515     struct ntdll_thread_regs *thread_regs;
516     struct startup_info *info = NULL;
517     void *addr = NULL;
518     HANDLE handle = 0;
519     TEB *teb;
520     DWORD tid = 0;
521     int request_pipe[2];
522     NTSTATUS status;
523     SIZE_T size;
524
525     if (process != NtCurrentProcess())
526     {
527         apc_call_t call;
528         apc_result_t result;
529
530         memset( &call, 0, sizeof(call) );
531
532         call.create_thread.type    = APC_CREATE_THREAD;
533         call.create_thread.func    = wine_server_client_ptr( start );
534         call.create_thread.arg     = wine_server_client_ptr( param );
535         call.create_thread.reserve = stack_reserve;
536         call.create_thread.commit  = stack_commit;
537         call.create_thread.suspend = suspended;
538         status = NTDLL_queue_process_apc( process, &call, &result );
539         if (status != STATUS_SUCCESS) return status;
540
541         if (result.create_thread.status == STATUS_SUCCESS)
542         {
543             if (id) id->UniqueThread = ULongToHandle(result.create_thread.tid);
544             if (handle_ptr) *handle_ptr = wine_server_ptr_handle( result.create_thread.handle );
545             else NtClose( wine_server_ptr_handle( result.create_thread.handle ));
546         }
547         return result.create_thread.status;
548     }
549
550     if (pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
551     fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
552     wine_server_send_fd( request_pipe[0] );
553
554     SERVER_START_REQ( new_thread )
555     {
556         req->access     = THREAD_ALL_ACCESS;
557         req->attributes = 0;  /* FIXME */
558         req->suspend    = suspended;
559         req->request_fd = request_pipe[0];
560         if (!(status = wine_server_call( req )))
561         {
562             handle = wine_server_ptr_handle( reply->handle );
563             tid = reply->tid;
564         }
565         close( request_pipe[0] );
566     }
567     SERVER_END_REQ;
568
569     if (status)
570     {
571         close( request_pipe[1] );
572         return status;
573     }
574
575     pthread_sigmask( SIG_BLOCK, &server_block_set, &sigset );
576
577     addr = NULL;
578     size = sigstack_total_size;
579     if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &addr, sigstack_zero_bits,
580                                            &size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE )))
581         goto error;
582     teb = addr;
583     teb->Peb = NtCurrentTeb()->Peb;
584     info = (struct startup_info *)(teb + 1);
585     info->teb         = teb;
586     info->entry_point = start;
587     info->entry_arg   = param;
588
589     if ((status = init_teb( teb ))) goto error;
590
591     teb->ClientId.UniqueProcess = ULongToHandle(GetCurrentProcessId());
592     teb->ClientId.UniqueThread  = ULongToHandle(tid);
593
594     thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
595     thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
596     thread_data->request_fd  = request_pipe[1];
597
598     /* inherit debug registers from parent thread */
599     thread_regs->dr0 = ntdll_get_thread_regs()->dr0;
600     thread_regs->dr1 = ntdll_get_thread_regs()->dr1;
601     thread_regs->dr2 = ntdll_get_thread_regs()->dr2;
602     thread_regs->dr3 = ntdll_get_thread_regs()->dr3;
603     thread_regs->dr6 = ntdll_get_thread_regs()->dr6;
604     thread_regs->dr7 = ntdll_get_thread_regs()->dr7;
605
606     if ((status = virtual_alloc_thread_stack( teb, stack_reserve, stack_commit ))) goto error;
607
608     pthread_attr_init( &attr );
609     pthread_attr_setstack( &attr, teb->DeallocationStack,
610                            (char *)teb->Tib.StackBase - (char *)teb->DeallocationStack );
611     pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); /* force creating a kernel thread */
612     interlocked_xchg_add( &nb_threads, 1 );
613     if (pthread_create( &pthread_id, &attr, (void * (*)(void *))start_thread, info ))
614     {
615         interlocked_xchg_add( &nb_threads, -1 );
616         pthread_attr_destroy( &attr );
617         size = 0;
618         NtFreeVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size, MEM_RELEASE );
619         status = STATUS_NO_MEMORY;
620         goto error;
621     }
622     pthread_attr_destroy( &attr );
623     pthread_sigmask( SIG_SETMASK, &sigset, NULL );
624
625     if (id) id->UniqueThread = ULongToHandle(tid);
626     if (handle_ptr) *handle_ptr = handle;
627     else NtClose( handle );
628
629     return STATUS_SUCCESS;
630
631 error:
632     if (thread_data) wine_ldt_free_fs( thread_data->fs );
633     if (addr)
634     {
635         size = 0;
636         NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
637     }
638     if (handle) NtClose( handle );
639     pthread_sigmask( SIG_SETMASK, &sigset, NULL );
640     close( request_pipe[1] );
641     return status;
642 }
643
644
645 /***********************************************************************
646  *           RtlExitUserThread  (NTDLL.@)
647  */
648 void WINAPI RtlExitUserThread( ULONG status )
649 {
650     BOOL last;
651
652     SERVER_START_REQ( terminate_thread )
653     {
654         /* send the exit code to the server */
655         req->handle    = wine_server_obj_handle( GetCurrentThread() );
656         req->exit_code = status;
657         wine_server_call( req );
658         last = reply->last;
659     }
660     SERVER_END_REQ;
661
662     if (last)
663     {
664         LdrShutdownProcess();
665         exit( status );
666     }
667     else
668     {
669         LdrShutdownThread();
670         exit_thread( status );
671     }
672 }
673
674
675 /***********************************************************************
676  *              NtOpenThread   (NTDLL.@)
677  *              ZwOpenThread   (NTDLL.@)
678  */
679 NTSTATUS WINAPI NtOpenThread( HANDLE *handle, ACCESS_MASK access,
680                               const OBJECT_ATTRIBUTES *attr, const CLIENT_ID *id )
681 {
682     NTSTATUS ret;
683
684     SERVER_START_REQ( open_thread )
685     {
686         req->tid        = HandleToULong(id->UniqueThread);
687         req->access     = access;
688         req->attributes = attr ? attr->Attributes : 0;
689         ret = wine_server_call( req );
690         *handle = wine_server_ptr_handle( reply->handle );
691     }
692     SERVER_END_REQ;
693     return ret;
694 }
695
696
697 /******************************************************************************
698  *              NtSuspendThread   (NTDLL.@)
699  *              ZwSuspendThread   (NTDLL.@)
700  */
701 NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
702 {
703     NTSTATUS ret;
704
705     SERVER_START_REQ( suspend_thread )
706     {
707         req->handle = wine_server_obj_handle( handle );
708         if (!(ret = wine_server_call( req ))) *count = reply->count;
709     }
710     SERVER_END_REQ;
711     return ret;
712 }
713
714
715 /******************************************************************************
716  *              NtResumeThread   (NTDLL.@)
717  *              ZwResumeThread   (NTDLL.@)
718  */
719 NTSTATUS WINAPI NtResumeThread( HANDLE handle, PULONG count )
720 {
721     NTSTATUS ret;
722
723     SERVER_START_REQ( resume_thread )
724     {
725         req->handle = wine_server_obj_handle( handle );
726         if (!(ret = wine_server_call( req ))) *count = reply->count;
727     }
728     SERVER_END_REQ;
729     return ret;
730 }
731
732
733 /******************************************************************************
734  *              NtAlertResumeThread   (NTDLL.@)
735  *              ZwAlertResumeThread   (NTDLL.@)
736  */
737 NTSTATUS WINAPI NtAlertResumeThread( HANDLE handle, PULONG count )
738 {
739     FIXME( "stub: should alert thread %p\n", handle );
740     return NtResumeThread( handle, count );
741 }
742
743
744 /******************************************************************************
745  *              NtAlertThread   (NTDLL.@)
746  *              ZwAlertThread   (NTDLL.@)
747  */
748 NTSTATUS WINAPI NtAlertThread( HANDLE handle )
749 {
750     FIXME( "stub: %p\n", handle );
751     return STATUS_NOT_IMPLEMENTED;
752 }
753
754
755 /******************************************************************************
756  *              NtTerminateThread  (NTDLL.@)
757  *              ZwTerminateThread  (NTDLL.@)
758  */
759 NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
760 {
761     NTSTATUS ret;
762     BOOL self, last;
763
764     SERVER_START_REQ( terminate_thread )
765     {
766         req->handle    = wine_server_obj_handle( handle );
767         req->exit_code = exit_code;
768         ret = wine_server_call( req );
769         self = !ret && reply->self;
770         last = reply->last;
771     }
772     SERVER_END_REQ;
773
774     if (self)
775     {
776         if (last) _exit( exit_code );
777         else abort_thread( exit_code );
778     }
779     return ret;
780 }
781
782
783 /******************************************************************************
784  *              NtQueueApcThread  (NTDLL.@)
785  */
786 NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1,
787                                   ULONG_PTR arg2, ULONG_PTR arg3 )
788 {
789     NTSTATUS ret;
790     SERVER_START_REQ( queue_apc )
791     {
792         req->handle = wine_server_obj_handle( handle );
793         if (func)
794         {
795             req->call.type         = APC_USER;
796             req->call.user.func    = wine_server_client_ptr( func );
797             req->call.user.args[0] = arg1;
798             req->call.user.args[1] = arg2;
799             req->call.user.args[2] = arg3;
800         }
801         else req->call.type = APC_NONE;  /* wake up only */
802         ret = wine_server_call( req );
803     }
804     SERVER_END_REQ;
805     return ret;
806 }
807
808
809 /***********************************************************************
810  *              NtSetContextThread  (NTDLL.@)
811  *              ZwSetContextThread  (NTDLL.@)
812  */
813 NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
814 {
815     NTSTATUS ret;
816     DWORD dummy, i;
817     BOOL self = FALSE;
818
819 #ifdef __i386__
820     /* on i386 debug registers always require a server call */
821     self = (handle == GetCurrentThread());
822     if (self && (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)))
823     {
824         struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
825         self = (regs->dr0 == context->Dr0 && regs->dr1 == context->Dr1 &&
826                 regs->dr2 == context->Dr2 && regs->dr3 == context->Dr3 &&
827                 regs->dr6 == context->Dr6 && regs->dr7 == context->Dr7);
828     }
829 #endif
830
831     if (!self)
832     {
833         SERVER_START_REQ( set_thread_context )
834         {
835             req->handle  = wine_server_obj_handle( handle );
836             req->flags   = context->ContextFlags;
837             req->suspend = 0;
838             wine_server_add_data( req, context, sizeof(*context) );
839             ret = wine_server_call( req );
840             self = reply->self;
841         }
842         SERVER_END_REQ;
843
844         if (ret == STATUS_PENDING)
845         {
846             if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
847             {
848                 for (i = 0; i < 100; i++)
849                 {
850                     SERVER_START_REQ( set_thread_context )
851                     {
852                         req->handle  = wine_server_obj_handle( handle );
853                         req->flags   = context->ContextFlags;
854                         req->suspend = 0;
855                         wine_server_add_data( req, context, sizeof(*context) );
856                         ret = wine_server_call( req );
857                     }
858                     SERVER_END_REQ;
859                     if (ret == STATUS_PENDING)
860                     {
861                         LARGE_INTEGER timeout;
862                         timeout.QuadPart = -10000;
863                         NtDelayExecution( FALSE, &timeout );
864                     }
865                     else break;
866                 }
867                 NtResumeThread( handle, &dummy );
868             }
869             if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
870         }
871
872         if (ret) return ret;
873     }
874
875     if (self) set_cpu_context( context );
876     return STATUS_SUCCESS;
877 }
878
879
880 /***********************************************************************
881  *              NtGetContextThread  (NTDLL.@)
882  *              ZwGetContextThread  (NTDLL.@)
883  */
884 NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
885 {
886     NTSTATUS ret;
887     CONTEXT ctx;
888     DWORD dummy, i;
889     DWORD needed_flags = context->ContextFlags;
890     BOOL self = (handle == GetCurrentThread());
891
892 #ifdef __i386__
893     /* on i386 debug registers always require a server call */
894     if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)) self = FALSE;
895 #endif
896
897     if (!self)
898     {
899         SERVER_START_REQ( get_thread_context )
900         {
901             req->handle  = wine_server_obj_handle( handle );
902             req->flags   = context->ContextFlags;
903             req->suspend = 0;
904             wine_server_set_reply( req, &ctx, sizeof(ctx) );
905             ret = wine_server_call( req );
906             self = reply->self;
907         }
908         SERVER_END_REQ;
909
910         if (ret == STATUS_PENDING)
911         {
912             if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
913             {
914                 for (i = 0; i < 100; i++)
915                 {
916                     SERVER_START_REQ( get_thread_context )
917                     {
918                         req->handle  = wine_server_obj_handle( handle );
919                         req->flags   = context->ContextFlags;
920                         req->suspend = 0;
921                         wine_server_set_reply( req, &ctx, sizeof(ctx) );
922                         ret = wine_server_call( req );
923                     }
924                     SERVER_END_REQ;
925                     if (ret == STATUS_PENDING)
926                     {
927                         LARGE_INTEGER timeout;
928                         timeout.QuadPart = -10000;
929                         NtDelayExecution( FALSE, &timeout );
930                     }
931                     else break;
932                 }
933                 NtResumeThread( handle, &dummy );
934             }
935             if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
936         }
937         if (ret) return ret;
938         copy_context( context, &ctx, context->ContextFlags & ctx.ContextFlags );
939         needed_flags &= ~ctx.ContextFlags;
940     }
941
942     if (self)
943     {
944         if (needed_flags)
945         {
946             RtlCaptureContext( &ctx );
947             copy_context( context, &ctx, ctx.ContextFlags & needed_flags );
948         }
949 #ifdef __i386__
950         /* update the cached version of the debug registers */
951         if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386))
952         {
953             struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
954             regs->dr0 = context->Dr0;
955             regs->dr1 = context->Dr1;
956             regs->dr2 = context->Dr2;
957             regs->dr3 = context->Dr3;
958             regs->dr6 = context->Dr6;
959             regs->dr7 = context->Dr7;
960         }
961 #endif
962     }
963     return STATUS_SUCCESS;
964 }
965
966
967 /******************************************************************************
968  *              NtQueryInformationThread  (NTDLL.@)
969  *              ZwQueryInformationThread  (NTDLL.@)
970  */
971 NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
972                                           void *data, ULONG length, ULONG *ret_len )
973 {
974     NTSTATUS status;
975
976     switch(class)
977     {
978     case ThreadBasicInformation:
979         {
980             THREAD_BASIC_INFORMATION info;
981             const ULONG_PTR affinity_mask = ((ULONG_PTR)1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
982
983             SERVER_START_REQ( get_thread_info )
984             {
985                 req->handle = wine_server_obj_handle( handle );
986                 req->tid_in = 0;
987                 if (!(status = wine_server_call( req )))
988                 {
989                     info.ExitStatus             = reply->exit_code;
990                     info.TebBaseAddress         = wine_server_get_ptr( reply->teb );
991                     info.ClientId.UniqueProcess = ULongToHandle(reply->pid);
992                     info.ClientId.UniqueThread  = ULongToHandle(reply->tid);
993                     info.AffinityMask           = reply->affinity & affinity_mask;
994                     info.Priority               = reply->priority;
995                     info.BasePriority           = reply->priority;  /* FIXME */
996                 }
997             }
998             SERVER_END_REQ;
999             if (status == STATUS_SUCCESS)
1000             {
1001                 if (data) memcpy( data, &info, min( length, sizeof(info) ));
1002                 if (ret_len) *ret_len = min( length, sizeof(info) );
1003             }
1004         }
1005         return status;
1006     case ThreadAffinityMask:
1007         {
1008             const ULONG_PTR affinity_mask = ((ULONG_PTR)1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
1009             ULONG_PTR affinity = 0;
1010
1011             SERVER_START_REQ( get_thread_info )
1012             {
1013                 req->handle = wine_server_obj_handle( handle );
1014                 req->tid_in = 0;
1015                 if (!(status = wine_server_call( req )))
1016                     affinity = reply->affinity & affinity_mask;
1017             }
1018             SERVER_END_REQ;
1019             if (status == STATUS_SUCCESS)
1020             {
1021                 if (data) memcpy( data, &affinity, min( length, sizeof(affinity) ));
1022                 if (ret_len) *ret_len = min( length, sizeof(affinity) );
1023             }
1024         }
1025         return status;
1026     case ThreadTimes:
1027         {
1028             KERNEL_USER_TIMES   kusrt;
1029             /* We need to do a server call to get the creation time or exit time */
1030             /* This works on any thread */
1031             SERVER_START_REQ( get_thread_info )
1032             {
1033                 req->handle = wine_server_obj_handle( handle );
1034                 req->tid_in = 0;
1035                 status = wine_server_call( req );
1036                 if (status == STATUS_SUCCESS)
1037                 {
1038                     kusrt.CreateTime.QuadPart = reply->creation_time;
1039                     kusrt.ExitTime.QuadPart = reply->exit_time;
1040                 }
1041             }
1042             SERVER_END_REQ;
1043             if (status == STATUS_SUCCESS)
1044             {
1045                 /* We call times(2) for kernel time or user time */
1046                 /* We can only (portably) do this for the current thread */
1047                 if (handle == GetCurrentThread())
1048                 {
1049                     struct tms time_buf;
1050                     long clocks_per_sec = sysconf(_SC_CLK_TCK);
1051
1052                     times(&time_buf);
1053                     kusrt.KernelTime.QuadPart = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
1054                     kusrt.UserTime.QuadPart = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
1055                 }
1056                 else
1057                 {
1058                     static BOOL reported = FALSE;
1059
1060                     kusrt.KernelTime.QuadPart = 0;
1061                     kusrt.UserTime.QuadPart = 0;
1062                     if (reported)
1063                         TRACE("Cannot get kerneltime or usertime of other threads\n");
1064                     else
1065                     {
1066                         FIXME("Cannot get kerneltime or usertime of other threads\n");
1067                         reported = TRUE;
1068                     }
1069                 }
1070                 if (data) memcpy( data, &kusrt, min( length, sizeof(kusrt) ));
1071                 if (ret_len) *ret_len = min( length, sizeof(kusrt) );
1072             }
1073         }
1074         return status;
1075     case ThreadDescriptorTableEntry:
1076         {
1077 #ifdef __i386__
1078             THREAD_DESCRIPTOR_INFORMATION*      tdi = data;
1079             if (length < sizeof(*tdi))
1080                 status = STATUS_INFO_LENGTH_MISMATCH;
1081             else if (!(tdi->Selector & 4))  /* GDT selector */
1082             {
1083                 unsigned sel = tdi->Selector & ~3;  /* ignore RPL */
1084                 status = STATUS_SUCCESS;
1085                 if (!sel)  /* null selector */
1086                     memset( &tdi->Entry, 0, sizeof(tdi->Entry) );
1087                 else
1088                 {
1089                     tdi->Entry.BaseLow                   = 0;
1090                     tdi->Entry.HighWord.Bits.BaseMid     = 0;
1091                     tdi->Entry.HighWord.Bits.BaseHi      = 0;
1092                     tdi->Entry.LimitLow                  = 0xffff;
1093                     tdi->Entry.HighWord.Bits.LimitHi     = 0xf;
1094                     tdi->Entry.HighWord.Bits.Dpl         = 3;
1095                     tdi->Entry.HighWord.Bits.Sys         = 0;
1096                     tdi->Entry.HighWord.Bits.Pres        = 1;
1097                     tdi->Entry.HighWord.Bits.Granularity = 1;
1098                     tdi->Entry.HighWord.Bits.Default_Big = 1;
1099                     tdi->Entry.HighWord.Bits.Type        = 0x12;
1100                     /* it has to be one of the system GDT selectors */
1101                     if (sel != (wine_get_ds() & ~3) && sel != (wine_get_ss() & ~3))
1102                     {
1103                         if (sel == (wine_get_cs() & ~3))
1104                             tdi->Entry.HighWord.Bits.Type |= 8;  /* code segment */
1105                         else status = STATUS_ACCESS_DENIED;
1106                     }
1107                 }
1108             }
1109             else
1110             {
1111                 SERVER_START_REQ( get_selector_entry )
1112                 {
1113                     req->handle = wine_server_obj_handle( handle );
1114                     req->entry = tdi->Selector >> 3;
1115                     status = wine_server_call( req );
1116                     if (!status)
1117                     {
1118                         if (!(reply->flags & WINE_LDT_FLAGS_ALLOCATED))
1119                             status = STATUS_ACCESS_VIOLATION;
1120                         else
1121                         {
1122                             wine_ldt_set_base ( &tdi->Entry, (void *)reply->base );
1123                             wine_ldt_set_limit( &tdi->Entry, reply->limit );
1124                             wine_ldt_set_flags( &tdi->Entry, reply->flags );
1125                         }
1126                     }
1127                 }
1128                 SERVER_END_REQ;
1129             }
1130             if (status == STATUS_SUCCESS && ret_len)
1131                 /* yes, that's a bit strange, but it's the way it is */
1132                 *ret_len = sizeof(LDT_ENTRY);
1133 #else
1134             status = STATUS_NOT_IMPLEMENTED;
1135 #endif
1136             return status;
1137         }
1138     case ThreadAmILastThread:
1139         {
1140             SERVER_START_REQ(get_thread_info)
1141             {
1142                 req->handle = wine_server_obj_handle( handle );
1143                 req->tid_in = 0;
1144                 status = wine_server_call( req );
1145                 if (status == STATUS_SUCCESS)
1146                 {
1147                     BOOLEAN last = reply->last;
1148                     if (data) memcpy( data, &last, min( length, sizeof(last) ));
1149                     if (ret_len) *ret_len = min( length, sizeof(last) );
1150                 }
1151             }
1152             SERVER_END_REQ;
1153             return status;
1154         }
1155     case ThreadPriority:
1156     case ThreadBasePriority:
1157     case ThreadImpersonationToken:
1158     case ThreadEnableAlignmentFaultFixup:
1159     case ThreadEventPair_Reusable:
1160     case ThreadQuerySetWin32StartAddress:
1161     case ThreadZeroTlsCell:
1162     case ThreadPerformanceCount:
1163     case ThreadIdealProcessor:
1164     case ThreadPriorityBoost:
1165     case ThreadSetTlsArrayAddress:
1166     case ThreadIsIoPending:
1167     default:
1168         FIXME( "info class %d not supported yet\n", class );
1169         return STATUS_NOT_IMPLEMENTED;
1170     }
1171 }
1172
1173
1174 /******************************************************************************
1175  *              NtSetInformationThread  (NTDLL.@)
1176  *              ZwSetInformationThread  (NTDLL.@)
1177  */
1178 NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
1179                                         LPCVOID data, ULONG length )
1180 {
1181     NTSTATUS status;
1182     switch(class)
1183     {
1184     case ThreadZeroTlsCell:
1185         if (handle == GetCurrentThread())
1186         {
1187             LIST_ENTRY *entry;
1188             DWORD index;
1189
1190             if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
1191             index = *(const DWORD *)data;
1192             if (index < TLS_MINIMUM_AVAILABLE)
1193             {
1194                 RtlAcquirePebLock();
1195                 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
1196                 {
1197                     TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
1198                     teb->TlsSlots[index] = 0;
1199                 }
1200                 RtlReleasePebLock();
1201             }
1202             else
1203             {
1204                 index -= TLS_MINIMUM_AVAILABLE;
1205                 if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
1206                     return STATUS_INVALID_PARAMETER;
1207                 RtlAcquirePebLock();
1208                 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
1209                 {
1210                     TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
1211                     if (teb->TlsExpansionSlots) teb->TlsExpansionSlots[index] = 0;
1212                 }
1213                 RtlReleasePebLock();
1214             }
1215             return STATUS_SUCCESS;
1216         }
1217         FIXME( "ZeroTlsCell not supported on other threads\n" );
1218         return STATUS_NOT_IMPLEMENTED;
1219
1220     case ThreadImpersonationToken:
1221         {
1222             const HANDLE *phToken = data;
1223             if (length != sizeof(HANDLE)) return STATUS_INVALID_PARAMETER;
1224             TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken );
1225             SERVER_START_REQ( set_thread_info )
1226             {
1227                 req->handle   = wine_server_obj_handle( handle );
1228                 req->token    = wine_server_obj_handle( *phToken );
1229                 req->mask     = SET_THREAD_INFO_TOKEN;
1230                 status = wine_server_call( req );
1231             }
1232             SERVER_END_REQ;
1233         }
1234         return status;
1235     case ThreadBasePriority:
1236         {
1237             const DWORD *pprio = data;
1238             if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
1239             SERVER_START_REQ( set_thread_info )
1240             {
1241                 req->handle   = wine_server_obj_handle( handle );
1242                 req->priority = *pprio;
1243                 req->mask     = SET_THREAD_INFO_PRIORITY;
1244                 status = wine_server_call( req );
1245             }
1246             SERVER_END_REQ;
1247         }
1248         return status;
1249     case ThreadAffinityMask:
1250         {
1251             const ULONG_PTR affinity_mask = ((ULONG_PTR)1 << NtCurrentTeb()->Peb->NumberOfProcessors) - 1;
1252             const ULONG_PTR *paff = data;
1253             if (length != sizeof(ULONG_PTR)) return STATUS_INVALID_PARAMETER;
1254             if (*paff & ~affinity_mask) return STATUS_INVALID_PARAMETER;
1255             SERVER_START_REQ( set_thread_info )
1256             {
1257                 req->handle   = wine_server_obj_handle( handle );
1258                 req->affinity = *paff;
1259                 req->mask     = SET_THREAD_INFO_AFFINITY;
1260                 status = wine_server_call( req );
1261             }
1262             SERVER_END_REQ;
1263         }
1264         return status;
1265     case ThreadBasicInformation:
1266     case ThreadTimes:
1267     case ThreadPriority:
1268     case ThreadDescriptorTableEntry:
1269     case ThreadEnableAlignmentFaultFixup:
1270     case ThreadEventPair_Reusable:
1271     case ThreadQuerySetWin32StartAddress:
1272     case ThreadPerformanceCount:
1273     case ThreadAmILastThread:
1274     case ThreadIdealProcessor:
1275     case ThreadPriorityBoost:
1276     case ThreadSetTlsArrayAddress:
1277     case ThreadIsIoPending:
1278     default:
1279         FIXME( "info class %d not supported yet\n", class );
1280         return STATUS_NOT_IMPLEMENTED;
1281     }
1282 }