4 * Copyright 1996, 2003 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
27 #include <sys/types.h>
28 #ifdef HAVE_SYS_MMAN_H
31 #ifdef HAVE_SYS_TIMES_H
32 #include <sys/times.h>
34 #ifdef HAVE_SYS_SYSCALL_H
35 #include <sys/syscall.h>
38 #define NONAMELESSUNION
40 #define WIN32_NO_STATUS
42 #include "wine/library.h"
43 #include "wine/server.h"
44 #include "wine/debug.h"
45 #include "ntdll_misc.h"
47 #include "wine/exception.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(thread
);
51 #ifndef PTHREAD_STACK_MIN
52 #define PTHREAD_STACK_MIN 16384
55 struct _KUSER_SHARED_DATA
*user_shared_data
= NULL
;
56 static const WCHAR default_windirW
[] = {'C',':','\\','w','i','n','d','o','w','s',0};
58 PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter
= NULL
;
59 void (WINAPI
*kernel32_start_process
)(LPTHREAD_START_ROUTINE
,void*) = NULL
;
61 /* info passed to a starting thread */
65 PRTL_THREAD_START_ROUTINE entry_point
;
70 static PEB_LDR_DATA ldr
;
71 static RTL_USER_PROCESS_PARAMETERS params
; /* default parameters if no parent */
72 static WCHAR current_dir
[MAX_NT_PATH_LENGTH
];
73 static RTL_BITMAP tls_bitmap
;
74 static RTL_BITMAP tls_expansion_bitmap
;
75 static RTL_BITMAP fls_bitmap
;
76 static int nb_threads
= 1;
78 static RTL_CRITICAL_SECTION peb_lock
;
79 static RTL_CRITICAL_SECTION_DEBUG critsect_debug
=
82 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
83 0, 0, { (DWORD_PTR
)(__FILE__
": peb_lock") }
85 static RTL_CRITICAL_SECTION peb_lock
= { &critsect_debug
, -1, 0, 0, 0, 0 };
87 /***********************************************************************
90 * Copy a unicode string from the startup info.
92 static inline void get_unicode_string( UNICODE_STRING
*str
, WCHAR
**src
, WCHAR
**dst
, UINT len
)
96 str
->MaximumLength
= len
+ sizeof(WCHAR
);
97 memcpy( str
->Buffer
, *src
, len
);
98 str
->Buffer
[len
/ sizeof(WCHAR
)] = 0;
99 *src
+= len
/ sizeof(WCHAR
);
100 *dst
+= len
/ sizeof(WCHAR
) + 1;
103 /***********************************************************************
104 * init_user_process_params
106 * Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
108 static NTSTATUS
init_user_process_params( SIZE_T data_size
, HANDLE
*exe_file
)
112 SIZE_T info_size
, env_size
, size
, alloc_size
;
114 startup_info_t
*info
;
115 RTL_USER_PROCESS_PARAMETERS
*params
= NULL
;
117 if (!(info
= RtlAllocateHeap( GetProcessHeap(), 0, data_size
)))
118 return STATUS_NO_MEMORY
;
120 SERVER_START_REQ( get_startup_info
)
122 wine_server_set_reply( req
, info
, data_size
);
123 if (!(status
= wine_server_call( req
)))
125 data_size
= wine_server_reply_size( reply
);
126 info_size
= reply
->info_size
;
127 env_size
= data_size
- info_size
;
128 *exe_file
= wine_server_ptr_handle( reply
->exe_file
);
132 if (status
!= STATUS_SUCCESS
) goto done
;
134 size
= sizeof(*params
);
135 size
+= MAX_NT_PATH_LENGTH
* sizeof(WCHAR
);
136 size
+= info
->dllpath_len
+ sizeof(WCHAR
);
137 size
+= info
->imagepath_len
+ sizeof(WCHAR
);
138 size
+= info
->cmdline_len
+ sizeof(WCHAR
);
139 size
+= info
->title_len
+ sizeof(WCHAR
);
140 size
+= info
->desktop_len
+ sizeof(WCHAR
);
141 size
+= info
->shellinfo_len
+ sizeof(WCHAR
);
142 size
+= info
->runtime_len
+ sizeof(WCHAR
);
145 status
= NtAllocateVirtualMemory( NtCurrentProcess(), (void **)¶ms
, 0, &alloc_size
,
146 MEM_COMMIT
, PAGE_READWRITE
);
147 if (status
!= STATUS_SUCCESS
) goto done
;
149 NtCurrentTeb()->Peb
->ProcessParameters
= params
;
150 params
->AllocationSize
= alloc_size
;
152 params
->Flags
= PROCESS_PARAMS_FLAG_NORMALIZED
;
153 params
->DebugFlags
= info
->debug_flags
;
154 params
->ConsoleHandle
= wine_server_ptr_handle( info
->console
);
155 params
->ConsoleFlags
= info
->console_flags
;
156 params
->hStdInput
= wine_server_ptr_handle( info
->hstdin
);
157 params
->hStdOutput
= wine_server_ptr_handle( info
->hstdout
);
158 params
->hStdError
= wine_server_ptr_handle( info
->hstderr
);
159 params
->dwX
= info
->x
;
160 params
->dwY
= info
->y
;
161 params
->dwXSize
= info
->xsize
;
162 params
->dwYSize
= info
->ysize
;
163 params
->dwXCountChars
= info
->xchars
;
164 params
->dwYCountChars
= info
->ychars
;
165 params
->dwFillAttribute
= info
->attribute
;
166 params
->dwFlags
= info
->flags
;
167 params
->wShowWindow
= info
->show
;
169 src
= (WCHAR
*)(info
+ 1);
170 dst
= (WCHAR
*)(params
+ 1);
172 /* current directory needs more space */
173 get_unicode_string( ¶ms
->CurrentDirectory
.DosPath
, &src
, &dst
, info
->curdir_len
);
174 params
->CurrentDirectory
.DosPath
.MaximumLength
= MAX_NT_PATH_LENGTH
* sizeof(WCHAR
);
175 dst
= (WCHAR
*)(params
+ 1) + MAX_NT_PATH_LENGTH
;
177 get_unicode_string( ¶ms
->DllPath
, &src
, &dst
, info
->dllpath_len
);
178 get_unicode_string( ¶ms
->ImagePathName
, &src
, &dst
, info
->imagepath_len
);
179 get_unicode_string( ¶ms
->CommandLine
, &src
, &dst
, info
->cmdline_len
);
180 get_unicode_string( ¶ms
->WindowTitle
, &src
, &dst
, info
->title_len
);
181 get_unicode_string( ¶ms
->Desktop
, &src
, &dst
, info
->desktop_len
);
182 get_unicode_string( ¶ms
->ShellInfo
, &src
, &dst
, info
->shellinfo_len
);
184 /* runtime info isn't a real string */
185 params
->RuntimeInfo
.Buffer
= dst
;
186 params
->RuntimeInfo
.Length
= params
->RuntimeInfo
.MaximumLength
= info
->runtime_len
;
187 memcpy( dst
, src
, info
->runtime_len
);
189 /* environment needs to be a separate memory block */
191 alloc_size
= max( 1, env_size
);
192 status
= NtAllocateVirtualMemory( NtCurrentProcess(), &ptr
, 0, &alloc_size
,
193 MEM_COMMIT
, PAGE_READWRITE
);
194 if (status
!= STATUS_SUCCESS
) goto done
;
195 memcpy( ptr
, (char *)info
+ info_size
, env_size
);
196 params
->Environment
= ptr
;
199 RtlFreeHeap( GetProcessHeap(), 0, info
);
211 #ifdef HAVE_SYS_AUXV_H
212 # include <sys/auxv.h>
214 #ifndef HAVE_GETAUXVAL
215 static unsigned long getauxval( unsigned long id
)
217 extern char **__wine_main_environ
;
218 char **ptr
= __wine_main_environ
;
223 for (auxv
= (ElfW(auxv_t
) *)ptr
; auxv
->a_type
; auxv
++)
224 if (auxv
->a_type
== id
) return auxv
->a_un
.a_val
;
229 static ULONG_PTR
get_image_addr(void)
231 ULONG_PTR size
, num
, phdr_addr
= getauxval( AT_PHDR
);
234 if (!phdr_addr
) return 0;
235 phdr
= (ElfW(Phdr
) *)phdr_addr
;
236 size
= getauxval( AT_PHENT
);
237 num
= getauxval( AT_PHNUM
);
240 if (phdr
->p_type
== PT_PHDR
) return phdr_addr
- phdr
->p_offset
;
241 phdr
= (ElfW(Phdr
) *)((char *)phdr
+ size
);
246 #elif defined(__APPLE__)
247 #include <mach/mach.h>
248 #include <mach/mach_error.h>
250 static ULONG_PTR
get_image_addr(void)
253 #ifdef TASK_DYLD_INFO
254 struct task_dyld_info dyld_info
;
255 mach_msg_type_number_t size
= TASK_DYLD_INFO_COUNT
;
256 if (task_info(mach_task_self(), TASK_DYLD_INFO
, (task_info_t
)&dyld_info
, &size
) == KERN_SUCCESS
)
257 ret
= dyld_info
.all_image_info_addr
;
263 static ULONG_PTR
get_image_addr(void)
269 /***********************************************************************
272 * Setup the initial thread.
274 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
276 HANDLE
thread_init(void)
281 SIZE_T size
, info_size
;
285 struct ntdll_thread_data
*thread_data
;
286 static struct debug_info debug_info
; /* debug info for initial thread */
290 /* reserve space for shared user data */
292 addr
= (void *)0x7ffe0000;
294 status
= NtAllocateVirtualMemory( NtCurrentProcess(), &addr
, 0, &size
,
295 MEM_RESERVE
|MEM_COMMIT
, PAGE_READWRITE
);
298 MESSAGE( "wine: failed to map the shared user data: %08x\n", status
);
301 user_shared_data
= addr
;
302 memcpy( user_shared_data
->NtSystemRoot
, default_windirW
, sizeof(default_windirW
) );
304 /* allocate and initialize the PEB */
308 NtAllocateVirtualMemory( NtCurrentProcess(), &addr
, 1, &size
,
309 MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
);
312 peb
->FastPebLock
= &peb_lock
;
313 peb
->ProcessParameters
= ¶ms
;
314 peb
->TlsBitmap
= &tls_bitmap
;
315 peb
->TlsExpansionBitmap
= &tls_expansion_bitmap
;
316 peb
->FlsBitmap
= &fls_bitmap
;
318 peb
->OSMajorVersion
= 5;
319 peb
->OSMinorVersion
= 1;
320 peb
->OSBuildNumber
= 0xA28;
321 peb
->OSPlatformId
= VER_PLATFORM_WIN32_NT
;
322 params
.CurrentDirectory
.DosPath
.Buffer
= current_dir
;
323 params
.CurrentDirectory
.DosPath
.MaximumLength
= sizeof(current_dir
);
324 params
.wShowWindow
= 1; /* SW_SHOWNORMAL */
325 ldr
.Length
= sizeof(ldr
);
326 ldr
.Initialized
= TRUE
;
327 RtlInitializeBitMap( &tls_bitmap
, peb
->TlsBitmapBits
, sizeof(peb
->TlsBitmapBits
) * 8 );
328 RtlInitializeBitMap( &tls_expansion_bitmap
, peb
->TlsExpansionBitmapBits
,
329 sizeof(peb
->TlsExpansionBitmapBits
) * 8 );
330 RtlInitializeBitMap( &fls_bitmap
, peb
->FlsBitmapBits
, sizeof(peb
->FlsBitmapBits
) * 8 );
331 RtlSetBits( peb
->TlsBitmap
, 0, 1 ); /* TLS index 0 is reserved and should be initialized to NULL. */
332 RtlSetBits( peb
->FlsBitmap
, 0, 1 );
333 InitializeListHead( &peb
->FlsListHead
);
334 InitializeListHead( &ldr
.InLoadOrderModuleList
);
335 InitializeListHead( &ldr
.InMemoryOrderModuleList
);
336 InitializeListHead( &ldr
.InInitializationOrderModuleList
);
337 *(ULONG_PTR
*)peb
->Reserved
= get_image_addr();
340 * Starting with Vista, the first user to log on has session id 1.
341 * Session id 0 is for processes that don't interact with the user (like services).
345 /* allocate and initialize the initial TEB */
347 signal_alloc_thread( &teb
);
349 teb
->Tib
.StackBase
= (void *)~0UL;
350 teb
->StaticUnicodeString
.Buffer
= teb
->StaticUnicodeBuffer
;
351 teb
->StaticUnicodeString
.MaximumLength
= sizeof(teb
->StaticUnicodeBuffer
);
353 thread_data
= (struct ntdll_thread_data
*)&teb
->GdiTebBatch
;
354 thread_data
->request_fd
= -1;
355 thread_data
->reply_fd
= -1;
356 thread_data
->wait_fd
[0] = -1;
357 thread_data
->wait_fd
[1] = -1;
358 thread_data
->debug_info
= &debug_info
;
360 signal_init_thread( teb
);
361 virtual_init_threading();
363 debug_info
.str_pos
= debug_info
.strings
;
364 debug_info
.out_pos
= debug_info
.output
;
367 /* setup the server connection */
368 server_init_process();
369 info_size
= server_init_thread( peb
, &suspend
);
371 /* create the process heap */
372 if (!(peb
->ProcessHeap
= RtlCreateHeap( HEAP_GROWABLE
, NULL
, 0, 0, NULL
, NULL
)))
374 MESSAGE( "wine: failed to create the process heap\n" );
378 /* allocate user parameters */
381 init_user_process_params( info_size
, &exe_file
);
385 if (isatty(0) || isatty(1) || isatty(2))
386 params
.ConsoleHandle
= (HANDLE
)2; /* see kernel32/kernel_private.h */
388 wine_server_fd_to_handle( 0, GENERIC_READ
|SYNCHRONIZE
, OBJ_INHERIT
, ¶ms
.hStdInput
);
390 wine_server_fd_to_handle( 1, GENERIC_WRITE
|SYNCHRONIZE
, OBJ_INHERIT
, ¶ms
.hStdOutput
);
392 wine_server_fd_to_handle( 2, GENERIC_WRITE
|SYNCHRONIZE
, OBJ_INHERIT
, ¶ms
.hStdError
);
395 /* initialize time values in user_shared_data */
396 NtQuerySystemTime( &now
);
397 user_shared_data
->SystemTime
.LowPart
= now
.u
.LowPart
;
398 user_shared_data
->SystemTime
.High1Time
= user_shared_data
->SystemTime
.High2Time
= now
.u
.HighPart
;
399 user_shared_data
->u
.TickCountQuad
= (now
.QuadPart
- server_start_time
) / 10000;
400 user_shared_data
->u
.TickCount
.High2Time
= user_shared_data
->u
.TickCount
.High1Time
;
401 user_shared_data
->TickCountLowDeprecated
= user_shared_data
->u
.TickCount
.LowPart
;
402 user_shared_data
->TickCountMultiplier
= 1 << 24;
406 NtCreateKeyedEvent( &keyed_event
, GENERIC_READ
| GENERIC_WRITE
, NULL
, 0 );
412 /***********************************************************************
415 static void free_thread_data( TEB
*teb
)
417 struct ntdll_thread_data
*thread_data
= (struct ntdll_thread_data
*)&teb
->GdiTebBatch
;
420 if (teb
->DeallocationStack
)
423 NtFreeVirtualMemory( GetCurrentProcess(), &teb
->DeallocationStack
, &size
, MEM_RELEASE
);
425 if (thread_data
->start_stack
)
428 NtFreeVirtualMemory( GetCurrentProcess(), &thread_data
->start_stack
, &size
, MEM_RELEASE
);
430 signal_free_thread( teb
);
434 /***********************************************************************
437 void abort_thread( int status
)
439 pthread_sigmask( SIG_BLOCK
, &server_block_set
, NULL
);
440 if (interlocked_xchg_add( &nb_threads
, -1 ) <= 1) _exit( status
);
441 signal_exit_thread( status
);
445 /***********************************************************************
448 void exit_thread( int status
)
450 close( ntdll_get_thread_data()->wait_fd
[0] );
451 close( ntdll_get_thread_data()->wait_fd
[1] );
452 close( ntdll_get_thread_data()->reply_fd
);
453 close( ntdll_get_thread_data()->request_fd
);
454 pthread_exit( UIntToPtr(status
) );
458 /***********************************************************************
459 * RtlExitUserThread (NTDLL.@)
461 void WINAPI
RtlExitUserThread( ULONG status
)
463 static void *prev_teb
;
466 if (status
) /* send the exit code to the server (0 is already the default) */
468 SERVER_START_REQ( terminate_thread
)
470 req
->handle
= wine_server_obj_handle( GetCurrentThread() );
471 req
->exit_code
= status
;
472 wine_server_call( req
);
477 if (interlocked_xchg_add( &nb_threads
, -1 ) <= 1)
479 LdrShutdownProcess();
480 pthread_sigmask( SIG_BLOCK
, &server_block_set
, NULL
);
481 signal_exit_process( status
);
485 RtlFreeThreadActivationContextStack();
487 pthread_sigmask( SIG_BLOCK
, &server_block_set
, NULL
);
489 if ((teb
= interlocked_xchg_ptr( &prev_teb
, NtCurrentTeb() )))
491 struct ntdll_thread_data
*thread_data
= (struct ntdll_thread_data
*)&teb
->GdiTebBatch
;
493 if (thread_data
->pthread_id
)
495 pthread_join( thread_data
->pthread_id
, NULL
);
496 free_thread_data( teb
);
500 signal_exit_thread( status
);
504 /***********************************************************************
507 * Startup routine for a newly created thread.
509 static void start_thread( struct startup_info
*info
)
512 TEB
*teb
= info
->teb
;
513 struct ntdll_thread_data
*thread_data
= (struct ntdll_thread_data
*)&teb
->GdiTebBatch
;
514 struct debug_info debug_info
;
516 debug_info
.str_pos
= debug_info
.strings
;
517 debug_info
.out_pos
= debug_info
.output
;
518 thread_data
->debug_info
= &debug_info
;
519 thread_data
->pthread_id
= pthread_self();
521 signal_init_thread( teb
);
522 server_init_thread( info
->entry_point
, &suspend
);
523 signal_start_thread( (LPTHREAD_START_ROUTINE
)info
->entry_point
, info
->entry_arg
, suspend
);
527 /***********************************************************************
528 * NtCreateThreadEx (NTDLL.@)
530 NTSTATUS WINAPI
NtCreateThreadEx( HANDLE
*handle_ptr
, ACCESS_MASK access
, OBJECT_ATTRIBUTES
*attr
,
531 HANDLE process
, LPTHREAD_START_ROUTINE start
, void *param
,
532 ULONG flags
, ULONG zero_bits
, ULONG stack_commit
,
533 ULONG stack_reserve
, void *attribute_list
)
535 FIXME( "%p, %x, %p, %p, %p, %p, %x, %x, %x, %x, %p semi-stub!\n", handle_ptr
, access
, attr
,
536 process
, start
, param
, flags
, zero_bits
, stack_commit
, stack_reserve
, attribute_list
);
538 return RtlCreateUserThread( process
, NULL
, flags
& THREAD_CREATE_FLAGS_CREATE_SUSPENDED
,
539 NULL
, stack_reserve
, stack_commit
, (PRTL_THREAD_START_ROUTINE
)start
,
540 param
, handle_ptr
, NULL
);
544 /***********************************************************************
545 * RtlCreateUserThread (NTDLL.@)
547 NTSTATUS WINAPI
RtlCreateUserThread( HANDLE process
, const SECURITY_DESCRIPTOR
*descr
,
548 BOOLEAN suspended
, PVOID stack_addr
,
549 SIZE_T stack_reserve
, SIZE_T stack_commit
,
550 PRTL_THREAD_START_ROUTINE start
, void *param
,
551 HANDLE
*handle_ptr
, CLIENT_ID
*id
)
554 pthread_t pthread_id
;
556 struct ntdll_thread_data
*thread_data
;
557 struct startup_info
*info
;
558 HANDLE handle
= 0, actctx
= 0;
563 SIZE_T extra_stack
= PTHREAD_STACK_MIN
;
565 if (process
!= NtCurrentProcess())
570 memset( &call
, 0, sizeof(call
) );
572 call
.create_thread
.type
= APC_CREATE_THREAD
;
573 call
.create_thread
.func
= wine_server_client_ptr( start
);
574 call
.create_thread
.arg
= wine_server_client_ptr( param
);
575 call
.create_thread
.reserve
= stack_reserve
;
576 call
.create_thread
.commit
= stack_commit
;
577 call
.create_thread
.suspend
= suspended
;
578 status
= server_queue_process_apc( process
, &call
, &result
);
579 if (status
!= STATUS_SUCCESS
) return status
;
581 if (result
.create_thread
.status
== STATUS_SUCCESS
)
583 if (id
) id
->UniqueThread
= ULongToHandle(result
.create_thread
.tid
);
584 if (handle_ptr
) *handle_ptr
= wine_server_ptr_handle( result
.create_thread
.handle
);
585 else NtClose( wine_server_ptr_handle( result
.create_thread
.handle
));
587 return result
.create_thread
.status
;
590 if (server_pipe( request_pipe
) == -1) return STATUS_TOO_MANY_OPENED_FILES
;
591 wine_server_send_fd( request_pipe
[0] );
593 SERVER_START_REQ( new_thread
)
595 req
->access
= THREAD_ALL_ACCESS
;
596 req
->attributes
= 0; /* FIXME */
597 req
->suspend
= suspended
;
598 req
->request_fd
= request_pipe
[0];
599 if (!(status
= wine_server_call( req
)))
601 handle
= wine_server_ptr_handle( reply
->handle
);
604 close( request_pipe
[0] );
610 close( request_pipe
[1] );
614 pthread_sigmask( SIG_BLOCK
, &server_block_set
, &sigset
);
616 if ((status
= signal_alloc_thread( &teb
))) goto error
;
618 teb
->Peb
= NtCurrentTeb()->Peb
;
619 teb
->ClientId
.UniqueProcess
= ULongToHandle(GetCurrentProcessId());
620 teb
->ClientId
.UniqueThread
= ULongToHandle(tid
);
621 teb
->StaticUnicodeString
.Buffer
= teb
->StaticUnicodeBuffer
;
622 teb
->StaticUnicodeString
.MaximumLength
= sizeof(teb
->StaticUnicodeBuffer
);
624 /* create default activation context frame for new thread */
625 RtlGetActiveActivationContext(&actctx
);
628 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
630 frame
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof(*frame
));
631 frame
->Previous
= NULL
;
632 frame
->ActivationContext
= actctx
;
634 teb
->ActivationContextStack
.ActiveFrame
= frame
;
637 info
= (struct startup_info
*)(teb
+ 1);
639 info
->entry_point
= start
;
640 info
->entry_arg
= param
;
642 if ((status
= virtual_alloc_thread_stack( teb
, stack_reserve
, stack_commit
, &extra_stack
)))
645 thread_data
= (struct ntdll_thread_data
*)&teb
->GdiTebBatch
;
646 thread_data
->request_fd
= request_pipe
[1];
647 thread_data
->reply_fd
= -1;
648 thread_data
->wait_fd
[0] = -1;
649 thread_data
->wait_fd
[1] = -1;
650 thread_data
->start_stack
= (char *)teb
->Tib
.StackBase
;
652 pthread_attr_init( &attr
);
653 pthread_attr_setstack( &attr
, teb
->DeallocationStack
,
654 (char *)teb
->Tib
.StackBase
+ extra_stack
- (char *)teb
->DeallocationStack
);
655 pthread_attr_setscope( &attr
, PTHREAD_SCOPE_SYSTEM
); /* force creating a kernel thread */
656 interlocked_xchg_add( &nb_threads
, 1 );
657 if (pthread_create( &pthread_id
, &attr
, (void * (*)(void *))start_thread
, info
))
659 interlocked_xchg_add( &nb_threads
, -1 );
660 pthread_attr_destroy( &attr
);
661 status
= STATUS_NO_MEMORY
;
664 pthread_attr_destroy( &attr
);
665 pthread_sigmask( SIG_SETMASK
, &sigset
, NULL
);
667 if (id
) id
->UniqueThread
= ULongToHandle(tid
);
668 if (handle_ptr
) *handle_ptr
= handle
;
669 else NtClose( handle
);
671 return STATUS_SUCCESS
;
674 if (teb
) free_thread_data( teb
);
675 if (handle
) NtClose( handle
);
676 pthread_sigmask( SIG_SETMASK
, &sigset
, NULL
);
677 close( request_pipe
[1] );
682 /******************************************************************************
683 * RtlGetNtGlobalFlags (NTDLL.@)
685 ULONG WINAPI
RtlGetNtGlobalFlags(void)
687 if (!peb
) return 0; /* init not done yet */
688 return peb
->NtGlobalFlag
;
692 /***********************************************************************
693 * NtOpenThread (NTDLL.@)
694 * ZwOpenThread (NTDLL.@)
696 NTSTATUS WINAPI
NtOpenThread( HANDLE
*handle
, ACCESS_MASK access
,
697 const OBJECT_ATTRIBUTES
*attr
, const CLIENT_ID
*id
)
701 SERVER_START_REQ( open_thread
)
703 req
->tid
= HandleToULong(id
->UniqueThread
);
704 req
->access
= access
;
705 req
->attributes
= attr
? attr
->Attributes
: 0;
706 ret
= wine_server_call( req
);
707 *handle
= wine_server_ptr_handle( reply
->handle
);
714 /******************************************************************************
715 * NtSuspendThread (NTDLL.@)
716 * ZwSuspendThread (NTDLL.@)
718 NTSTATUS WINAPI
NtSuspendThread( HANDLE handle
, PULONG count
)
722 SERVER_START_REQ( suspend_thread
)
724 req
->handle
= wine_server_obj_handle( handle
);
725 if (!(ret
= wine_server_call( req
)))
727 if (count
) *count
= reply
->count
;
735 /******************************************************************************
736 * NtResumeThread (NTDLL.@)
737 * ZwResumeThread (NTDLL.@)
739 NTSTATUS WINAPI
NtResumeThread( HANDLE handle
, PULONG count
)
743 SERVER_START_REQ( resume_thread
)
745 req
->handle
= wine_server_obj_handle( handle
);
746 if (!(ret
= wine_server_call( req
)))
748 if (count
) *count
= reply
->count
;
756 /******************************************************************************
757 * NtAlertResumeThread (NTDLL.@)
758 * ZwAlertResumeThread (NTDLL.@)
760 NTSTATUS WINAPI
NtAlertResumeThread( HANDLE handle
, PULONG count
)
762 FIXME( "stub: should alert thread %p\n", handle
);
763 return NtResumeThread( handle
, count
);
767 /******************************************************************************
768 * NtAlertThread (NTDLL.@)
769 * ZwAlertThread (NTDLL.@)
771 NTSTATUS WINAPI
NtAlertThread( HANDLE handle
)
773 FIXME( "stub: %p\n", handle
);
774 return STATUS_NOT_IMPLEMENTED
;
778 /******************************************************************************
779 * NtTerminateThread (NTDLL.@)
780 * ZwTerminateThread (NTDLL.@)
782 NTSTATUS WINAPI
NtTerminateThread( HANDLE handle
, LONG exit_code
)
787 SERVER_START_REQ( terminate_thread
)
789 req
->handle
= wine_server_obj_handle( handle
);
790 req
->exit_code
= exit_code
;
791 ret
= wine_server_call( req
);
792 self
= !ret
&& reply
->self
;
796 if (self
) abort_thread( exit_code
);
801 /******************************************************************************
802 * NtQueueApcThread (NTDLL.@)
804 NTSTATUS WINAPI
NtQueueApcThread( HANDLE handle
, PNTAPCFUNC func
, ULONG_PTR arg1
,
805 ULONG_PTR arg2
, ULONG_PTR arg3
)
808 SERVER_START_REQ( queue_apc
)
810 req
->handle
= wine_server_obj_handle( handle
);
813 req
->call
.type
= APC_USER
;
814 req
->call
.user
.func
= wine_server_client_ptr( func
);
815 req
->call
.user
.args
[0] = arg1
;
816 req
->call
.user
.args
[1] = arg2
;
817 req
->call
.user
.args
[2] = arg3
;
819 else req
->call
.type
= APC_NONE
; /* wake up only */
820 ret
= wine_server_call( req
);
827 /******************************************************************************
828 * RtlPushFrame (NTDLL.@)
830 void WINAPI
RtlPushFrame( TEB_ACTIVE_FRAME
*frame
)
832 frame
->Previous
= NtCurrentTeb()->ActiveFrame
;
833 NtCurrentTeb()->ActiveFrame
= frame
;
837 /******************************************************************************
838 * RtlPopFrame (NTDLL.@)
840 void WINAPI
RtlPopFrame( TEB_ACTIVE_FRAME
*frame
)
842 NtCurrentTeb()->ActiveFrame
= frame
->Previous
;
846 /******************************************************************************
847 * RtlGetFrame (NTDLL.@)
849 TEB_ACTIVE_FRAME
* WINAPI
RtlGetFrame(void)
851 return NtCurrentTeb()->ActiveFrame
;
855 /***********************************************************************
858 NTSTATUS
set_thread_context( HANDLE handle
, const context_t
*context
, BOOL
*self
)
863 SERVER_START_REQ( set_thread_context
)
865 req
->handle
= wine_server_obj_handle( handle
);
867 wine_server_add_data( req
, context
, sizeof(*context
) );
868 ret
= wine_server_call( req
);
873 if (ret
== STATUS_PENDING
)
875 for (i
= 0; i
< 100; i
++)
877 SERVER_START_REQ( set_thread_context
)
879 req
->handle
= wine_server_obj_handle( handle
);
881 wine_server_add_data( req
, context
, sizeof(*context
) );
882 ret
= wine_server_call( req
);
885 if (ret
== STATUS_PENDING
)
887 LARGE_INTEGER timeout
;
888 timeout
.QuadPart
= -10000;
889 NtDelayExecution( FALSE
, &timeout
);
893 NtResumeThread( handle
, &dummy
);
894 if (ret
== STATUS_PENDING
) ret
= STATUS_ACCESS_DENIED
;
901 /***********************************************************************
904 NTSTATUS
get_thread_context( HANDLE handle
, context_t
*context
, unsigned int flags
, BOOL
*self
)
909 SERVER_START_REQ( get_thread_context
)
911 req
->handle
= wine_server_obj_handle( handle
);
914 wine_server_set_reply( req
, context
, sizeof(*context
) );
915 ret
= wine_server_call( req
);
920 if (ret
== STATUS_PENDING
)
922 for (i
= 0; i
< 100; i
++)
924 SERVER_START_REQ( get_thread_context
)
926 req
->handle
= wine_server_obj_handle( handle
);
929 wine_server_set_reply( req
, context
, sizeof(*context
) );
930 ret
= wine_server_call( req
);
933 if (ret
== STATUS_PENDING
)
935 LARGE_INTEGER timeout
;
936 timeout
.QuadPart
= -10000;
937 NtDelayExecution( FALSE
, &timeout
);
941 NtResumeThread( handle
, &dummy
);
942 if (ret
== STATUS_PENDING
) ret
= STATUS_ACCESS_DENIED
;
948 /******************************************************************************
949 * NtQueryInformationThread (NTDLL.@)
950 * ZwQueryInformationThread (NTDLL.@)
952 NTSTATUS WINAPI
NtQueryInformationThread( HANDLE handle
, THREADINFOCLASS
class,
953 void *data
, ULONG length
, ULONG
*ret_len
)
959 case ThreadBasicInformation
:
961 THREAD_BASIC_INFORMATION info
;
962 const ULONG_PTR affinity_mask
= get_system_affinity_mask();
964 SERVER_START_REQ( get_thread_info
)
966 req
->handle
= wine_server_obj_handle( handle
);
968 if (!(status
= wine_server_call( req
)))
970 info
.ExitStatus
= reply
->exit_code
;
971 info
.TebBaseAddress
= wine_server_get_ptr( reply
->teb
);
972 info
.ClientId
.UniqueProcess
= ULongToHandle(reply
->pid
);
973 info
.ClientId
.UniqueThread
= ULongToHandle(reply
->tid
);
974 info
.AffinityMask
= reply
->affinity
& affinity_mask
;
975 info
.Priority
= reply
->priority
;
976 info
.BasePriority
= reply
->priority
; /* FIXME */
980 if (status
== STATUS_SUCCESS
)
982 if (data
) memcpy( data
, &info
, min( length
, sizeof(info
) ));
983 if (ret_len
) *ret_len
= min( length
, sizeof(info
) );
987 case ThreadAffinityMask
:
989 const ULONG_PTR affinity_mask
= get_system_affinity_mask();
990 ULONG_PTR affinity
= 0;
992 SERVER_START_REQ( get_thread_info
)
994 req
->handle
= wine_server_obj_handle( handle
);
996 if (!(status
= wine_server_call( req
)))
997 affinity
= reply
->affinity
& affinity_mask
;
1000 if (status
== STATUS_SUCCESS
)
1002 if (data
) memcpy( data
, &affinity
, min( length
, sizeof(affinity
) ));
1003 if (ret_len
) *ret_len
= min( length
, sizeof(affinity
) );
1009 KERNEL_USER_TIMES kusrt
;
1011 SERVER_START_REQ( get_thread_times
)
1013 req
->handle
= wine_server_obj_handle( handle
);
1014 status
= wine_server_call( req
);
1015 if (status
== STATUS_SUCCESS
)
1017 kusrt
.CreateTime
.QuadPart
= reply
->creation_time
;
1018 kusrt
.ExitTime
.QuadPart
= reply
->exit_time
;
1022 if (status
== STATUS_SUCCESS
)
1024 /* We call times(2) for kernel time or user time */
1025 /* We can only (portably) do this for the current thread */
1026 if (handle
== GetCurrentThread())
1028 struct tms time_buf
;
1029 long clocks_per_sec
= sysconf(_SC_CLK_TCK
);
1032 kusrt
.KernelTime
.QuadPart
= (ULONGLONG
)time_buf
.tms_stime
* 10000000 / clocks_per_sec
;
1033 kusrt
.UserTime
.QuadPart
= (ULONGLONG
)time_buf
.tms_utime
* 10000000 / clocks_per_sec
;
1037 static BOOL reported
= FALSE
;
1039 kusrt
.KernelTime
.QuadPart
= 0;
1040 kusrt
.UserTime
.QuadPart
= 0;
1042 TRACE("Cannot get kerneltime or usertime of other threads\n");
1045 FIXME("Cannot get kerneltime or usertime of other threads\n");
1049 if (data
) memcpy( data
, &kusrt
, min( length
, sizeof(kusrt
) ));
1050 if (ret_len
) *ret_len
= min( length
, sizeof(kusrt
) );
1054 case ThreadDescriptorTableEntry
:
1057 THREAD_DESCRIPTOR_INFORMATION
* tdi
= data
;
1058 if (length
< sizeof(*tdi
))
1059 status
= STATUS_INFO_LENGTH_MISMATCH
;
1060 else if (!(tdi
->Selector
& 4)) /* GDT selector */
1062 unsigned sel
= LOWORD(tdi
->Selector
) & ~3; /* ignore RPL */
1063 status
= STATUS_SUCCESS
;
1064 if (!sel
) /* null selector */
1065 memset( &tdi
->Entry
, 0, sizeof(tdi
->Entry
) );
1068 tdi
->Entry
.BaseLow
= 0;
1069 tdi
->Entry
.HighWord
.Bits
.BaseMid
= 0;
1070 tdi
->Entry
.HighWord
.Bits
.BaseHi
= 0;
1071 tdi
->Entry
.LimitLow
= 0xffff;
1072 tdi
->Entry
.HighWord
.Bits
.LimitHi
= 0xf;
1073 tdi
->Entry
.HighWord
.Bits
.Dpl
= 3;
1074 tdi
->Entry
.HighWord
.Bits
.Sys
= 0;
1075 tdi
->Entry
.HighWord
.Bits
.Pres
= 1;
1076 tdi
->Entry
.HighWord
.Bits
.Granularity
= 1;
1077 tdi
->Entry
.HighWord
.Bits
.Default_Big
= 1;
1078 tdi
->Entry
.HighWord
.Bits
.Type
= 0x12;
1079 tdi
->Entry
.HighWord
.Bits
.Reserved_0
= 0;
1080 /* it has to be one of the system GDT selectors */
1081 if (sel
!= (wine_get_ds() & ~3) && sel
!= (wine_get_ss() & ~3))
1083 if (sel
== (wine_get_cs() & ~3))
1084 tdi
->Entry
.HighWord
.Bits
.Type
|= 8; /* code segment */
1085 else if (sel
== (wine_get_fs() & ~3))
1087 ULONG_PTR fs_base
= (ULONG_PTR
)NtCurrentTeb();
1088 tdi
->Entry
.BaseLow
= fs_base
& 0xffff;
1089 tdi
->Entry
.HighWord
.Bits
.BaseMid
= (fs_base
>> 16) & 0xff;
1090 tdi
->Entry
.HighWord
.Bits
.BaseHi
= (fs_base
>> 24) & 0xff;
1091 tdi
->Entry
.LimitLow
= 0x0fff;
1092 tdi
->Entry
.HighWord
.Bits
.LimitHi
= 0;
1093 tdi
->Entry
.HighWord
.Bits
.Granularity
= 0;
1095 else status
= STATUS_ACCESS_DENIED
;
1101 SERVER_START_REQ( get_selector_entry
)
1103 req
->handle
= wine_server_obj_handle( handle
);
1104 req
->entry
= LOWORD(tdi
->Selector
) >> 3;
1105 status
= wine_server_call( req
);
1108 if (!(reply
->flags
& WINE_LDT_FLAGS_ALLOCATED
))
1109 status
= STATUS_ACCESS_VIOLATION
;
1112 wine_ldt_set_base ( &tdi
->Entry
, (void *)reply
->base
);
1113 wine_ldt_set_limit( &tdi
->Entry
, reply
->limit
);
1114 wine_ldt_set_flags( &tdi
->Entry
, reply
->flags
);
1120 if (status
== STATUS_SUCCESS
&& ret_len
)
1121 /* yes, that's a bit strange, but it's the way it is */
1122 *ret_len
= sizeof(LDT_ENTRY
);
1124 status
= STATUS_NOT_IMPLEMENTED
;
1128 case ThreadAmILastThread
:
1130 SERVER_START_REQ(get_thread_info
)
1132 req
->handle
= wine_server_obj_handle( handle
);
1134 status
= wine_server_call( req
);
1135 if (status
== STATUS_SUCCESS
)
1137 BOOLEAN last
= reply
->last
;
1138 if (data
) memcpy( data
, &last
, min( length
, sizeof(last
) ));
1139 if (ret_len
) *ret_len
= min( length
, sizeof(last
) );
1145 case ThreadQuerySetWin32StartAddress
:
1147 SERVER_START_REQ( get_thread_info
)
1149 req
->handle
= wine_server_obj_handle( handle
);
1151 status
= wine_server_call( req
);
1152 if (status
== STATUS_SUCCESS
)
1154 PRTL_THREAD_START_ROUTINE entry
= wine_server_get_ptr( reply
->entry_point
);
1155 if (data
) memcpy( data
, &entry
, min( length
, sizeof(entry
) ) );
1156 if (ret_len
) *ret_len
= min( length
, sizeof(entry
) );
1162 case ThreadGroupInformation
:
1164 const ULONG_PTR affinity_mask
= get_system_affinity_mask();
1165 GROUP_AFFINITY affinity
;
1167 memset(&affinity
, 0, sizeof(affinity
));
1168 affinity
.Group
= 0; /* Wine only supports max 64 processors */
1170 SERVER_START_REQ( get_thread_info
)
1172 req
->handle
= wine_server_obj_handle( handle
);
1174 if (!(status
= wine_server_call( req
)))
1175 affinity
.Mask
= reply
->affinity
& affinity_mask
;
1178 if (status
== STATUS_SUCCESS
)
1180 if (data
) memcpy( data
, &affinity
, min( length
, sizeof(affinity
) ));
1181 if (ret_len
) *ret_len
= min( length
, sizeof(affinity
) );
1185 case ThreadIsIoPending
:
1186 FIXME( "ThreadIsIoPending info class not supported yet\n" );
1187 if (length
!= sizeof(BOOL
)) return STATUS_INFO_LENGTH_MISMATCH
;
1188 if (!data
) return STATUS_ACCESS_DENIED
;
1190 *(BOOL
*)data
= FALSE
;
1191 if (ret_len
) *ret_len
= sizeof(BOOL
);
1192 return STATUS_SUCCESS
;
1193 case ThreadPriority
:
1194 case ThreadBasePriority
:
1195 case ThreadImpersonationToken
:
1196 case ThreadEnableAlignmentFaultFixup
:
1197 case ThreadEventPair_Reusable
:
1198 case ThreadZeroTlsCell
:
1199 case ThreadPerformanceCount
:
1200 case ThreadIdealProcessor
:
1201 case ThreadPriorityBoost
:
1202 case ThreadSetTlsArrayAddress
:
1204 FIXME( "info class %d not supported yet\n", class );
1205 return STATUS_NOT_IMPLEMENTED
;
1210 /******************************************************************************
1211 * NtSetInformationThread (NTDLL.@)
1212 * ZwSetInformationThread (NTDLL.@)
1214 NTSTATUS WINAPI
NtSetInformationThread( HANDLE handle
, THREADINFOCLASS
class,
1215 LPCVOID data
, ULONG length
)
1220 case ThreadZeroTlsCell
:
1221 if (handle
== GetCurrentThread())
1226 if (length
!= sizeof(DWORD
)) return STATUS_INVALID_PARAMETER
;
1227 index
= *(const DWORD
*)data
;
1228 if (index
< TLS_MINIMUM_AVAILABLE
)
1230 RtlAcquirePebLock();
1231 for (entry
= tls_links
.Flink
; entry
!= &tls_links
; entry
= entry
->Flink
)
1233 TEB
*teb
= CONTAINING_RECORD(entry
, TEB
, TlsLinks
);
1234 teb
->TlsSlots
[index
] = 0;
1236 RtlReleasePebLock();
1240 index
-= TLS_MINIMUM_AVAILABLE
;
1241 if (index
>= 8 * sizeof(NtCurrentTeb()->Peb
->TlsExpansionBitmapBits
))
1242 return STATUS_INVALID_PARAMETER
;
1243 RtlAcquirePebLock();
1244 for (entry
= tls_links
.Flink
; entry
!= &tls_links
; entry
= entry
->Flink
)
1246 TEB
*teb
= CONTAINING_RECORD(entry
, TEB
, TlsLinks
);
1247 if (teb
->TlsExpansionSlots
) teb
->TlsExpansionSlots
[index
] = 0;
1249 RtlReleasePebLock();
1251 return STATUS_SUCCESS
;
1253 FIXME( "ZeroTlsCell not supported on other threads\n" );
1254 return STATUS_NOT_IMPLEMENTED
;
1256 case ThreadImpersonationToken
:
1258 const HANDLE
*phToken
= data
;
1259 if (length
!= sizeof(HANDLE
)) return STATUS_INVALID_PARAMETER
;
1260 TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken
);
1261 SERVER_START_REQ( set_thread_info
)
1263 req
->handle
= wine_server_obj_handle( handle
);
1264 req
->token
= wine_server_obj_handle( *phToken
);
1265 req
->mask
= SET_THREAD_INFO_TOKEN
;
1266 status
= wine_server_call( req
);
1271 case ThreadBasePriority
:
1273 const DWORD
*pprio
= data
;
1274 if (length
!= sizeof(DWORD
)) return STATUS_INVALID_PARAMETER
;
1275 SERVER_START_REQ( set_thread_info
)
1277 req
->handle
= wine_server_obj_handle( handle
);
1278 req
->priority
= *pprio
;
1279 req
->mask
= SET_THREAD_INFO_PRIORITY
;
1280 status
= wine_server_call( req
);
1285 case ThreadAffinityMask
:
1287 const ULONG_PTR affinity_mask
= get_system_affinity_mask();
1290 if (length
!= sizeof(ULONG_PTR
)) return STATUS_INVALID_PARAMETER
;
1291 req_aff
= *(const ULONG_PTR
*)data
;
1292 if ((ULONG
)req_aff
== ~0u) req_aff
= affinity_mask
;
1293 else if (req_aff
& ~affinity_mask
) return STATUS_INVALID_PARAMETER
;
1294 else if (!req_aff
) return STATUS_INVALID_PARAMETER
;
1295 SERVER_START_REQ( set_thread_info
)
1297 req
->handle
= wine_server_obj_handle( handle
);
1298 req
->affinity
= req_aff
;
1299 req
->mask
= SET_THREAD_INFO_AFFINITY
;
1300 status
= wine_server_call( req
);
1305 case ThreadHideFromDebugger
:
1306 /* pretend the call succeeded to satisfy some code protectors */
1307 return STATUS_SUCCESS
;
1308 case ThreadQuerySetWin32StartAddress
:
1310 const PRTL_THREAD_START_ROUTINE
*entry
= data
;
1311 if (length
!= sizeof(PRTL_THREAD_START_ROUTINE
)) return STATUS_INVALID_PARAMETER
;
1312 SERVER_START_REQ( set_thread_info
)
1314 req
->handle
= wine_server_obj_handle( handle
);
1315 req
->mask
= SET_THREAD_INFO_ENTRYPOINT
;
1316 req
->entry_point
= wine_server_client_ptr( *entry
);
1317 status
= wine_server_call( req
);
1322 case ThreadGroupInformation
:
1324 const ULONG_PTR affinity_mask
= get_system_affinity_mask();
1325 const GROUP_AFFINITY
*req_aff
;
1327 if (length
!= sizeof(*req_aff
)) return STATUS_INVALID_PARAMETER
;
1328 if (!data
) return STATUS_ACCESS_VIOLATION
;
1331 /* On Windows the request fails if the reserved fields are set */
1332 if (req_aff
->Reserved
[0] || req_aff
->Reserved
[1] || req_aff
->Reserved
[2])
1333 return STATUS_INVALID_PARAMETER
;
1335 /* Wine only supports max 64 processors */
1336 if (req_aff
->Group
) return STATUS_INVALID_PARAMETER
;
1337 if (req_aff
->Mask
& ~affinity_mask
) return STATUS_INVALID_PARAMETER
;
1338 if (!req_aff
->Mask
) return STATUS_INVALID_PARAMETER
;
1339 SERVER_START_REQ( set_thread_info
)
1341 req
->handle
= wine_server_obj_handle( handle
);
1342 req
->affinity
= req_aff
->Mask
;
1343 req
->mask
= SET_THREAD_INFO_AFFINITY
;
1344 status
= wine_server_call( req
);
1349 case ThreadBasicInformation
:
1351 case ThreadPriority
:
1352 case ThreadDescriptorTableEntry
:
1353 case ThreadEnableAlignmentFaultFixup
:
1354 case ThreadEventPair_Reusable
:
1355 case ThreadPerformanceCount
:
1356 case ThreadAmILastThread
:
1357 case ThreadIdealProcessor
:
1358 case ThreadPriorityBoost
:
1359 case ThreadSetTlsArrayAddress
:
1360 case ThreadIsIoPending
:
1362 FIXME( "info class %d not supported yet\n", class );
1363 return STATUS_NOT_IMPLEMENTED
;
1367 /******************************************************************************
1368 * NtGetCurrentProcessorNumber (NTDLL.@)
1370 * Return the processor, on which the thread is running
1373 ULONG WINAPI
NtGetCurrentProcessorNumber(void)
1377 #if defined(__linux__) && defined(__NR_getcpu)
1378 int res
= syscall(__NR_getcpu
, &processor
, NULL
, NULL
);
1379 if (res
!= -1) return processor
;
1382 if (NtCurrentTeb()->Peb
->NumberOfProcessors
> 1)
1384 ULONG_PTR thread_mask
, processor_mask
;
1387 status
= NtQueryInformationThread(GetCurrentThread(), ThreadAffinityMask
,
1388 &thread_mask
, sizeof(thread_mask
), NULL
);
1389 if (status
== STATUS_SUCCESS
)
1391 for (processor
= 0; processor
< NtCurrentTeb()->Peb
->NumberOfProcessors
; processor
++)
1393 processor_mask
= (1 << processor
);
1394 if (thread_mask
& processor_mask
)
1396 if (thread_mask
!= processor_mask
)
1397 FIXME("need multicore support (%d processors)\n",
1398 NtCurrentTeb()->Peb
->NumberOfProcessors
);
1405 /* fallback to the first processor */