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