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"
26 #include <sys/types.h>
27 #ifdef HAVE_SYS_MMAN_H
30 #ifdef HAVE_SYS_TIMES_H
31 #include <sys/times.h>
34 #define NONAMELESSUNION
36 #define WIN32_NO_STATUS
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"
44 #include "wine/exception.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(thread
);
47 WINE_DECLARE_DEBUG_CHANNEL(relay
);
49 struct _KUSER_SHARED_DATA
*user_shared_data
= NULL
;
51 PUNHANDLED_EXCEPTION_FILTER unhandled_exception_filter
= NULL
;
53 /* info passed to a starting thread */
57 PRTL_THREAD_START_ROUTINE entry_point
;
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;
72 static struct wine_pthread_functions pthread_functions
;
75 static RTL_CRITICAL_SECTION ldt_section
;
76 static RTL_CRITICAL_SECTION_DEBUG critsect_debug
=
79 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
80 0, 0, { (DWORD_PTR
)(__FILE__
": ldt_section") }
82 static RTL_CRITICAL_SECTION ldt_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
83 static sigset_t ldt_sigset
;
85 /***********************************************************************
86 * locking for LDT routines
88 static void ldt_lock(void)
92 pthread_sigmask( SIG_BLOCK
, &server_block_set
, &sigset
);
93 RtlEnterCriticalSection( &ldt_section
);
94 if (ldt_section
.RecursionCount
== 1) ldt_sigset
= sigset
;
97 static void ldt_unlock(void)
99 if (ldt_section
.RecursionCount
== 1)
101 sigset_t sigset
= ldt_sigset
;
102 RtlLeaveCriticalSection( &ldt_section
);
103 pthread_sigmask( SIG_SETMASK
, &sigset
, NULL
);
105 else RtlLeaveCriticalSection( &ldt_section
);
109 /***********************************************************************
112 static inline NTSTATUS
init_teb( TEB
*teb
)
114 struct ntdll_thread_data
*thread_data
= (struct ntdll_thread_data
*)teb
->SystemReserved2
;
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
);
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;
128 return STATUS_SUCCESS
;
132 /***********************************************************************
135 * Make sure the unicode string doesn't point beyond the end pointer
137 static inline void fix_unicode_string( UNICODE_STRING
*str
, const char *end_ptr
)
139 if ((char *)str
->Buffer
>= end_ptr
)
141 str
->Length
= str
->MaximumLength
= 0;
145 if ((char *)str
->Buffer
+ str
->MaximumLength
> end_ptr
)
147 str
->MaximumLength
= (end_ptr
- (char *)str
->Buffer
) & ~(sizeof(WCHAR
) - 1);
149 if (str
->Length
>= str
->MaximumLength
)
151 if (str
->MaximumLength
>= sizeof(WCHAR
))
152 str
->Length
= str
->MaximumLength
- sizeof(WCHAR
);
154 str
->Length
= str
->MaximumLength
= 0;
159 /***********************************************************************
160 * init_user_process_params
162 * Fill the RTL_USER_PROCESS_PARAMETERS structure from the server.
164 static NTSTATUS
init_user_process_params( SIZE_T info_size
, HANDLE
*exe_file
)
169 RTL_USER_PROCESS_PARAMETERS
*params
= NULL
;
171 status
= NtAllocateVirtualMemory( NtCurrentProcess(), (void **)¶ms
, 0, &info_size
,
172 MEM_COMMIT
, PAGE_READWRITE
);
173 if (status
!= STATUS_SUCCESS
) return status
;
175 params
->AllocationSize
= info_size
;
176 NtCurrentTeb()->Peb
->ProcessParameters
= params
;
178 SERVER_START_REQ( get_startup_info
)
180 wine_server_set_reply( req
, params
, info_size
);
181 if (!(status
= wine_server_call( req
)))
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
);
191 if (status
!= STATUS_SUCCESS
) return status
;
193 if (params
->Size
> info_size
) params
->Size
= info_size
;
195 /* make sure the strings are valid */
196 fix_unicode_string( ¶ms
->CurrentDirectory
.DosPath
, (char *)info_size
);
197 fix_unicode_string( ¶ms
->DllPath
, (char *)info_size
);
198 fix_unicode_string( ¶ms
->ImagePathName
, (char *)info_size
);
199 fix_unicode_string( ¶ms
->CommandLine
, (char *)info_size
);
200 fix_unicode_string( ¶ms
->WindowTitle
, (char *)info_size
);
201 fix_unicode_string( ¶ms
->Desktop
, (char *)info_size
);
202 fix_unicode_string( ¶ms
->ShellInfo
, (char *)info_size
);
203 fix_unicode_string( ¶ms
->RuntimeInfo
, (char *)info_size
);
205 /* environment needs to be a separate memory block */
206 env_size
= info_size
- params
->Size
;
207 if (!env_size
) env_size
= 1;
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
;
215 RtlNormalizeProcessParams( params
);
220 /***********************************************************************
223 * Setup the initial thread.
225 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
227 HANDLE
thread_init(void)
232 SIZE_T size
, info_size
;
235 struct ntdll_thread_data
*thread_data
;
236 static struct debug_info debug_info
; /* debug info for initial thread */
240 /* reserve space for shared user data */
242 addr
= (void *)0x7ffe0000;
244 NtAllocateVirtualMemory( NtCurrentProcess(), &addr
, 0, &size
, MEM_RESERVE
|MEM_COMMIT
, PAGE_READWRITE
);
245 user_shared_data
= addr
;
247 /* allocate and initialize the PEB */
251 NtAllocateVirtualMemory( NtCurrentProcess(), &addr
, 1, &size
,
252 MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
);
255 peb
->NumberOfProcessors
= 1;
256 peb
->ProcessParameters
= ¶ms
;
257 peb
->TlsBitmap
= &tls_bitmap
;
258 peb
->TlsExpansionBitmap
= &tls_expansion_bitmap
;
259 peb
->FlsBitmap
= &fls_bitmap
;
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
);
274 /* allocate and initialize the initial TEB */
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
) );
282 size
= sigstack_total_size
;
283 NtAllocateVirtualMemory( NtCurrentProcess(), &addr
, sigstack_zero_bits
,
284 &size
, MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
);
288 thread_data
= (struct ntdll_thread_data
*)teb
->SystemReserved2
;
289 thread_data
->debug_info
= &debug_info
;
290 InsertHeadList( &tls_links
, &teb
->TlsLinks
);
292 wine_pthread_get_functions( &pthread_functions
, sizeof(pthread_functions
) );
293 signal_init_thread( teb
);
294 virtual_init_threading();
296 debug_info
.str_pos
= debug_info
.strings
;
297 debug_info
.out_pos
= debug_info
.output
;
300 /* setup the server connection */
301 server_init_process();
302 info_size
= server_init_thread( NULL
);
304 /* create the process heap */
305 if (!(peb
->ProcessHeap
= RtlCreateHeap( HEAP_GROWABLE
, NULL
, 0, 0, NULL
, NULL
)))
307 MESSAGE( "wine: failed to create the process heap\n" );
311 /* allocate user parameters */
314 init_user_process_params( info_size
, &exe_file
);
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
321 wine_server_fd_to_handle( 0, GENERIC_READ
|SYNCHRONIZE
, OBJ_INHERIT
, ¶ms
.hStdInput
);
322 wine_server_fd_to_handle( 1, GENERIC_WRITE
|SYNCHRONIZE
, OBJ_INHERIT
, ¶ms
.hStdOutput
);
323 wine_server_fd_to_handle( 2, GENERIC_WRITE
|SYNCHRONIZE
, OBJ_INHERIT
, ¶ms
.hStdError
);
326 /* initialize LDT locking */
327 wine_ldt_init_locking( ldt_lock
, ldt_unlock
);
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;
343 /***********************************************************************
346 void abort_thread( int status
)
348 pthread_sigmask( SIG_BLOCK
, &server_block_set
, NULL
);
349 if (interlocked_xchg_add( &nb_threads
, -1 ) <= 1) _exit( status
);
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
) );
359 /***********************************************************************
362 static void DECLSPEC_NORETURN
exit_thread( int status
)
364 static void *prev_teb
;
368 RemoveEntryList( &NtCurrentTeb()->TlsLinks
);
370 RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->FlsSlots
);
371 RtlFreeHeap( GetProcessHeap(), 0, NtCurrentTeb()->TlsExpansionSlots
);
373 pthread_sigmask( SIG_BLOCK
, &server_block_set
, NULL
);
374 if (interlocked_xchg_add( &nb_threads
, -1 ) <= 1) exit( status
);
376 if ((teb
= interlocked_xchg_ptr( &prev_teb
, NtCurrentTeb() )))
378 struct ntdll_thread_data
*thread_data
= (struct ntdll_thread_data
*)teb
->SystemReserved2
;
381 pthread_join( thread_data
->pthread_id
, NULL
);
382 wine_ldt_free_fs( thread_data
->fs
);
384 NtFreeVirtualMemory( GetCurrentProcess(), &teb
->DeallocationStack
, &size
, MEM_RELEASE
);
386 NtFreeVirtualMemory( GetCurrentProcess(), (void **)&teb
, &size
, MEM_RELEASE
);
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
) );
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
,
405 "movl 8(%ebp),%eax\n\t"
410 static inline DWORD
call_thread_entry_point( PRTL_THREAD_START_ROUTINE entry
, void *arg
)
412 LPTHREAD_START_ROUTINE func
= (LPTHREAD_START_ROUTINE
)entry
;
417 /***********************************************************************
420 * Hack to make things compatible with the thread procedures used by kernel32.CreateThread.
422 static void DECLSPEC_NORETURN
call_thread_func( PRTL_THREAD_START_ROUTINE rtl_func
, void *arg
)
427 MODULE_DllThreadAttach( NULL
);
430 DPRINTF( "%04x:Starting thread proc %p (arg=%p)\n", GetCurrentThreadId(), rtl_func
, arg
);
432 exit_code
= call_thread_entry_point( rtl_func
, arg
);
434 /* send the exit code to the server */
435 SERVER_START_REQ( terminate_thread
)
437 req
->handle
= wine_server_obj_handle( GetCurrentThread() );
438 req
->exit_code
= exit_code
;
439 wine_server_call( req
);
446 LdrShutdownProcess();
452 exit_thread( exit_code
);
457 /***********************************************************************
460 * Startup routine for a newly created thread.
462 static void start_thread( struct startup_info
*info
)
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
;
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();
475 signal_init_thread( teb
);
476 server_init_thread( func
);
477 pthread_sigmask( SIG_UNBLOCK
, &server_block_set
, NULL
);
480 InsertHeadList( &tls_links
, &teb
->TlsLinks
);
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
)
489 call_thread_func( func
, arg
);
491 __EXCEPT(unhandled_exception_filter
)
493 NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
498 call_thread_func( func
, arg
);
502 /***********************************************************************
503 * RtlCreateUserThread (NTDLL.@)
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
)
512 pthread_t pthread_id
;
514 struct ntdll_thread_data
*thread_data
= NULL
;
515 struct ntdll_thread_regs
*thread_regs
;
516 struct startup_info
*info
= NULL
;
525 if (process
!= NtCurrentProcess())
530 memset( &call
, 0, sizeof(call
) );
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
;
541 if (result
.create_thread
.status
== STATUS_SUCCESS
)
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
));
547 return result
.create_thread
.status
;
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] );
554 SERVER_START_REQ( new_thread
)
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
)))
562 handle
= wine_server_ptr_handle( reply
->handle
);
565 close( request_pipe
[0] );
571 close( request_pipe
[1] );
575 pthread_sigmask( SIG_BLOCK
, &server_block_set
, &sigset
);
578 size
= sigstack_total_size
;
579 if ((status
= NtAllocateVirtualMemory( NtCurrentProcess(), &addr
, sigstack_zero_bits
,
580 &size
, MEM_COMMIT
| MEM_TOP_DOWN
, PAGE_READWRITE
)))
583 teb
->Peb
= NtCurrentTeb()->Peb
;
584 info
= (struct startup_info
*)(teb
+ 1);
586 info
->entry_point
= start
;
587 info
->entry_arg
= param
;
589 if ((status
= init_teb( teb
))) goto error
;
591 teb
->ClientId
.UniqueProcess
= ULongToHandle(GetCurrentProcessId());
592 teb
->ClientId
.UniqueThread
= ULongToHandle(tid
);
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];
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
;
606 if ((status
= virtual_alloc_thread_stack( teb
, stack_reserve
, stack_commit
))) goto error
;
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
))
615 interlocked_xchg_add( &nb_threads
, -1 );
616 pthread_attr_destroy( &attr
);
618 NtFreeVirtualMemory( NtCurrentProcess(), &teb
->DeallocationStack
, &size
, MEM_RELEASE
);
619 status
= STATUS_NO_MEMORY
;
622 pthread_attr_destroy( &attr
);
623 pthread_sigmask( SIG_SETMASK
, &sigset
, NULL
);
625 if (id
) id
->UniqueThread
= ULongToHandle(tid
);
626 if (handle_ptr
) *handle_ptr
= handle
;
627 else NtClose( handle
);
629 return STATUS_SUCCESS
;
632 if (thread_data
) wine_ldt_free_fs( thread_data
->fs
);
636 NtFreeVirtualMemory( NtCurrentProcess(), &addr
, &size
, MEM_RELEASE
);
638 if (handle
) NtClose( handle
);
639 pthread_sigmask( SIG_SETMASK
, &sigset
, NULL
);
640 close( request_pipe
[1] );
645 /***********************************************************************
646 * RtlExitUserThread (NTDLL.@)
648 void WINAPI
RtlExitUserThread( ULONG status
)
652 SERVER_START_REQ( terminate_thread
)
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
);
664 LdrShutdownProcess();
670 exit_thread( status
);
675 /***********************************************************************
676 * NtOpenThread (NTDLL.@)
677 * ZwOpenThread (NTDLL.@)
679 NTSTATUS WINAPI
NtOpenThread( HANDLE
*handle
, ACCESS_MASK access
,
680 const OBJECT_ATTRIBUTES
*attr
, const CLIENT_ID
*id
)
684 SERVER_START_REQ( open_thread
)
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
);
697 /******************************************************************************
698 * NtSuspendThread (NTDLL.@)
699 * ZwSuspendThread (NTDLL.@)
701 NTSTATUS WINAPI
NtSuspendThread( HANDLE handle
, PULONG count
)
705 SERVER_START_REQ( suspend_thread
)
707 req
->handle
= wine_server_obj_handle( handle
);
708 if (!(ret
= wine_server_call( req
))) *count
= reply
->count
;
715 /******************************************************************************
716 * NtResumeThread (NTDLL.@)
717 * ZwResumeThread (NTDLL.@)
719 NTSTATUS WINAPI
NtResumeThread( HANDLE handle
, PULONG count
)
723 SERVER_START_REQ( resume_thread
)
725 req
->handle
= wine_server_obj_handle( handle
);
726 if (!(ret
= wine_server_call( req
))) *count
= reply
->count
;
733 /******************************************************************************
734 * NtAlertResumeThread (NTDLL.@)
735 * ZwAlertResumeThread (NTDLL.@)
737 NTSTATUS WINAPI
NtAlertResumeThread( HANDLE handle
, PULONG count
)
739 FIXME( "stub: should alert thread %p\n", handle
);
740 return NtResumeThread( handle
, count
);
744 /******************************************************************************
745 * NtAlertThread (NTDLL.@)
746 * ZwAlertThread (NTDLL.@)
748 NTSTATUS WINAPI
NtAlertThread( HANDLE handle
)
750 FIXME( "stub: %p\n", handle
);
751 return STATUS_NOT_IMPLEMENTED
;
755 /******************************************************************************
756 * NtTerminateThread (NTDLL.@)
757 * ZwTerminateThread (NTDLL.@)
759 NTSTATUS WINAPI
NtTerminateThread( HANDLE handle
, LONG exit_code
)
764 SERVER_START_REQ( terminate_thread
)
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
;
776 if (last
) _exit( exit_code
);
777 else abort_thread( exit_code
);
783 /******************************************************************************
784 * NtQueueApcThread (NTDLL.@)
786 NTSTATUS WINAPI
NtQueueApcThread( HANDLE handle
, PNTAPCFUNC func
, ULONG_PTR arg1
,
787 ULONG_PTR arg2
, ULONG_PTR arg3
)
790 SERVER_START_REQ( queue_apc
)
792 req
->handle
= wine_server_obj_handle( handle
);
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
;
801 else req
->call
.type
= APC_NONE
; /* wake up only */
802 ret
= wine_server_call( req
);
809 /***********************************************************************
810 * NtSetContextThread (NTDLL.@)
811 * ZwSetContextThread (NTDLL.@)
813 NTSTATUS WINAPI
NtSetContextThread( HANDLE handle
, const CONTEXT
*context
)
820 /* on i386 debug registers always require a server call */
821 self
= (handle
== GetCurrentThread());
822 if (self
&& (context
->ContextFlags
& (CONTEXT_DEBUG_REGISTERS
& ~CONTEXT_i386
)))
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
);
833 SERVER_START_REQ( set_thread_context
)
835 req
->handle
= wine_server_obj_handle( handle
);
836 req
->flags
= context
->ContextFlags
;
838 wine_server_add_data( req
, context
, sizeof(*context
) );
839 ret
= wine_server_call( req
);
844 if (ret
== STATUS_PENDING
)
846 if (NtSuspendThread( handle
, &dummy
) == STATUS_SUCCESS
)
848 for (i
= 0; i
< 100; i
++)
850 SERVER_START_REQ( set_thread_context
)
852 req
->handle
= wine_server_obj_handle( handle
);
853 req
->flags
= context
->ContextFlags
;
855 wine_server_add_data( req
, context
, sizeof(*context
) );
856 ret
= wine_server_call( req
);
859 if (ret
== STATUS_PENDING
)
861 LARGE_INTEGER timeout
;
862 timeout
.QuadPart
= -10000;
863 NtDelayExecution( FALSE
, &timeout
);
867 NtResumeThread( handle
, &dummy
);
869 if (ret
== STATUS_PENDING
) ret
= STATUS_ACCESS_DENIED
;
875 if (self
) set_cpu_context( context
);
876 return STATUS_SUCCESS
;
880 /* copy a context structure according to the flags */
881 static inline void copy_context( CONTEXT
*to
, const CONTEXT
*from
, DWORD flags
)
884 flags
&= ~CONTEXT_i386
; /* get rid of CPU id */
885 if (flags
& CONTEXT_INTEGER
)
894 if (flags
& CONTEXT_CONTROL
)
899 to
->SegCs
= from
->SegCs
;
900 to
->SegSs
= from
->SegSs
;
901 to
->EFlags
= from
->EFlags
;
903 if (flags
& CONTEXT_SEGMENTS
)
905 to
->SegDs
= from
->SegDs
;
906 to
->SegEs
= from
->SegEs
;
907 to
->SegFs
= from
->SegFs
;
908 to
->SegGs
= from
->SegGs
;
910 if (flags
& CONTEXT_DEBUG_REGISTERS
)
919 if (flags
& CONTEXT_FLOATING_POINT
)
921 to
->FloatSave
= from
->FloatSave
;
923 if (flags
& CONTEXT_EXTENDED_REGISTERS
)
925 memcpy( to
->ExtendedRegisters
, from
->ExtendedRegisters
, sizeof(to
->ExtendedRegisters
) );
927 #elif defined(__x86_64__)
928 flags
&= ~CONTEXT_AMD64
; /* get rid of CPU id */
929 if (flags
& CONTEXT_CONTROL
)
934 to
->SegCs
= from
->SegCs
;
935 to
->SegSs
= from
->SegSs
;
936 to
->EFlags
= from
->EFlags
;
937 to
->MxCsr
= from
->MxCsr
;
939 if (flags
& CONTEXT_INTEGER
)
956 if (flags
& CONTEXT_SEGMENTS
)
958 to
->SegDs
= from
->SegDs
;
959 to
->SegEs
= from
->SegEs
;
960 to
->SegFs
= from
->SegFs
;
961 to
->SegGs
= from
->SegGs
;
963 if (flags
& CONTEXT_FLOATING_POINT
)
965 to
->u
.FltSave
= from
->u
.FltSave
;
967 if (flags
& CONTEXT_DEBUG_REGISTERS
)
976 #elif defined(__sparc__)
977 flags
&= ~CONTEXT_SPARC
; /* get rid of CPU id */
978 if (flags
& CONTEXT_CONTROL
)
987 if (flags
& CONTEXT_INTEGER
)
1022 if (flags
& CONTEXT_FLOATING_POINT
)
1026 #elif defined(__powerpc__)
1028 if (flags
& CONTEXT_CONTROL
)
1030 to
->Msr
= from
->Msr
;
1031 to
->Ctr
= from
->Ctr
;
1032 to
->Iar
= from
->Iar
;
1034 if (flags
& CONTEXT_INTEGER
)
1036 to
->Gpr0
= from
->Gpr0
;
1037 to
->Gpr1
= from
->Gpr1
;
1038 to
->Gpr2
= from
->Gpr2
;
1039 to
->Gpr3
= from
->Gpr3
;
1040 to
->Gpr4
= from
->Gpr4
;
1041 to
->Gpr5
= from
->Gpr5
;
1042 to
->Gpr6
= from
->Gpr6
;
1043 to
->Gpr7
= from
->Gpr7
;
1044 to
->Gpr8
= from
->Gpr8
;
1045 to
->Gpr9
= from
->Gpr9
;
1046 to
->Gpr10
= from
->Gpr10
;
1047 to
->Gpr11
= from
->Gpr11
;
1048 to
->Gpr12
= from
->Gpr12
;
1049 to
->Gpr13
= from
->Gpr13
;
1050 to
->Gpr14
= from
->Gpr14
;
1051 to
->Gpr15
= from
->Gpr15
;
1052 to
->Gpr16
= from
->Gpr16
;
1053 to
->Gpr17
= from
->Gpr17
;
1054 to
->Gpr18
= from
->Gpr18
;
1055 to
->Gpr19
= from
->Gpr19
;
1056 to
->Gpr20
= from
->Gpr20
;
1057 to
->Gpr21
= from
->Gpr21
;
1058 to
->Gpr22
= from
->Gpr22
;
1059 to
->Gpr23
= from
->Gpr23
;
1060 to
->Gpr24
= from
->Gpr24
;
1061 to
->Gpr25
= from
->Gpr25
;
1062 to
->Gpr26
= from
->Gpr26
;
1063 to
->Gpr27
= from
->Gpr27
;
1064 to
->Gpr28
= from
->Gpr28
;
1065 to
->Gpr29
= from
->Gpr29
;
1066 to
->Gpr30
= from
->Gpr30
;
1067 to
->Gpr31
= from
->Gpr31
;
1068 to
->Xer
= from
->Xer
;
1071 if (flags
& CONTEXT_FLOATING_POINT
)
1073 to
->Fpr0
= from
->Fpr0
;
1074 to
->Fpr1
= from
->Fpr1
;
1075 to
->Fpr2
= from
->Fpr2
;
1076 to
->Fpr3
= from
->Fpr3
;
1077 to
->Fpr4
= from
->Fpr4
;
1078 to
->Fpr5
= from
->Fpr5
;
1079 to
->Fpr6
= from
->Fpr6
;
1080 to
->Fpr7
= from
->Fpr7
;
1081 to
->Fpr8
= from
->Fpr8
;
1082 to
->Fpr9
= from
->Fpr9
;
1083 to
->Fpr10
= from
->Fpr10
;
1084 to
->Fpr11
= from
->Fpr11
;
1085 to
->Fpr12
= from
->Fpr12
;
1086 to
->Fpr13
= from
->Fpr13
;
1087 to
->Fpr14
= from
->Fpr14
;
1088 to
->Fpr15
= from
->Fpr15
;
1089 to
->Fpr16
= from
->Fpr16
;
1090 to
->Fpr17
= from
->Fpr17
;
1091 to
->Fpr18
= from
->Fpr18
;
1092 to
->Fpr19
= from
->Fpr19
;
1093 to
->Fpr20
= from
->Fpr20
;
1094 to
->Fpr21
= from
->Fpr21
;
1095 to
->Fpr22
= from
->Fpr22
;
1096 to
->Fpr23
= from
->Fpr23
;
1097 to
->Fpr24
= from
->Fpr24
;
1098 to
->Fpr25
= from
->Fpr25
;
1099 to
->Fpr26
= from
->Fpr26
;
1100 to
->Fpr27
= from
->Fpr27
;
1101 to
->Fpr28
= from
->Fpr28
;
1102 to
->Fpr29
= from
->Fpr29
;
1103 to
->Fpr30
= from
->Fpr30
;
1104 to
->Fpr31
= from
->Fpr31
;
1105 to
->Fpscr
= from
->Fpscr
;
1108 #error You must implement context copying for your CPU
1113 /***********************************************************************
1114 * NtGetContextThread (NTDLL.@)
1115 * ZwGetContextThread (NTDLL.@)
1117 NTSTATUS WINAPI
NtGetContextThread( HANDLE handle
, CONTEXT
*context
)
1122 DWORD needed_flags
= context
->ContextFlags
;
1123 BOOL self
= (handle
== GetCurrentThread());
1126 /* on i386 debug registers always require a server call */
1127 if (context
->ContextFlags
& (CONTEXT_DEBUG_REGISTERS
& ~CONTEXT_i386
)) self
= FALSE
;
1132 SERVER_START_REQ( get_thread_context
)
1134 req
->handle
= wine_server_obj_handle( handle
);
1135 req
->flags
= context
->ContextFlags
;
1137 wine_server_set_reply( req
, &ctx
, sizeof(ctx
) );
1138 ret
= wine_server_call( req
);
1143 if (ret
== STATUS_PENDING
)
1145 if (NtSuspendThread( handle
, &dummy
) == STATUS_SUCCESS
)
1147 for (i
= 0; i
< 100; i
++)
1149 SERVER_START_REQ( get_thread_context
)
1151 req
->handle
= wine_server_obj_handle( handle
);
1152 req
->flags
= context
->ContextFlags
;
1154 wine_server_set_reply( req
, &ctx
, sizeof(ctx
) );
1155 ret
= wine_server_call( req
);
1158 if (ret
== STATUS_PENDING
)
1160 LARGE_INTEGER timeout
;
1161 timeout
.QuadPart
= -10000;
1162 NtDelayExecution( FALSE
, &timeout
);
1166 NtResumeThread( handle
, &dummy
);
1168 if (ret
== STATUS_PENDING
) ret
= STATUS_ACCESS_DENIED
;
1170 if (ret
) return ret
;
1171 copy_context( context
, &ctx
, context
->ContextFlags
& ctx
.ContextFlags
);
1172 needed_flags
&= ~ctx
.ContextFlags
;
1179 RtlCaptureContext( &ctx
);
1180 copy_context( context
, &ctx
, ctx
.ContextFlags
& needed_flags
);
1183 /* update the cached version of the debug registers */
1184 if (context
->ContextFlags
& (CONTEXT_DEBUG_REGISTERS
& ~CONTEXT_i386
))
1186 struct ntdll_thread_regs
* const regs
= ntdll_get_thread_regs();
1187 regs
->dr0
= context
->Dr0
;
1188 regs
->dr1
= context
->Dr1
;
1189 regs
->dr2
= context
->Dr2
;
1190 regs
->dr3
= context
->Dr3
;
1191 regs
->dr6
= context
->Dr6
;
1192 regs
->dr7
= context
->Dr7
;
1196 return STATUS_SUCCESS
;
1200 /******************************************************************************
1201 * NtQueryInformationThread (NTDLL.@)
1202 * ZwQueryInformationThread (NTDLL.@)
1204 NTSTATUS WINAPI
NtQueryInformationThread( HANDLE handle
, THREADINFOCLASS
class,
1205 void *data
, ULONG length
, ULONG
*ret_len
)
1211 case ThreadBasicInformation
:
1213 THREAD_BASIC_INFORMATION info
;
1214 const ULONG_PTR affinity_mask
= ((ULONG_PTR
)1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1;
1216 SERVER_START_REQ( get_thread_info
)
1218 req
->handle
= wine_server_obj_handle( handle
);
1220 if (!(status
= wine_server_call( req
)))
1222 info
.ExitStatus
= reply
->exit_code
;
1223 info
.TebBaseAddress
= wine_server_get_ptr( reply
->teb
);
1224 info
.ClientId
.UniqueProcess
= ULongToHandle(reply
->pid
);
1225 info
.ClientId
.UniqueThread
= ULongToHandle(reply
->tid
);
1226 info
.AffinityMask
= reply
->affinity
& affinity_mask
;
1227 info
.Priority
= reply
->priority
;
1228 info
.BasePriority
= reply
->priority
; /* FIXME */
1232 if (status
== STATUS_SUCCESS
)
1234 if (data
) memcpy( data
, &info
, min( length
, sizeof(info
) ));
1235 if (ret_len
) *ret_len
= min( length
, sizeof(info
) );
1239 case ThreadAffinityMask
:
1241 const ULONG_PTR affinity_mask
= ((ULONG_PTR
)1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1;
1242 ULONG_PTR affinity
= 0;
1244 SERVER_START_REQ( get_thread_info
)
1246 req
->handle
= wine_server_obj_handle( handle
);
1248 if (!(status
= wine_server_call( req
)))
1249 affinity
= reply
->affinity
& affinity_mask
;
1252 if (status
== STATUS_SUCCESS
)
1254 if (data
) memcpy( data
, &affinity
, min( length
, sizeof(affinity
) ));
1255 if (ret_len
) *ret_len
= min( length
, sizeof(affinity
) );
1261 KERNEL_USER_TIMES kusrt
;
1262 /* We need to do a server call to get the creation time or exit time */
1263 /* This works on any thread */
1264 SERVER_START_REQ( get_thread_info
)
1266 req
->handle
= wine_server_obj_handle( handle
);
1268 status
= wine_server_call( req
);
1269 if (status
== STATUS_SUCCESS
)
1271 kusrt
.CreateTime
.QuadPart
= reply
->creation_time
;
1272 kusrt
.ExitTime
.QuadPart
= reply
->exit_time
;
1276 if (status
== STATUS_SUCCESS
)
1278 /* We call times(2) for kernel time or user time */
1279 /* We can only (portably) do this for the current thread */
1280 if (handle
== GetCurrentThread())
1282 struct tms time_buf
;
1283 long clocks_per_sec
= sysconf(_SC_CLK_TCK
);
1286 kusrt
.KernelTime
.QuadPart
= (ULONGLONG
)time_buf
.tms_stime
* 10000000 / clocks_per_sec
;
1287 kusrt
.UserTime
.QuadPart
= (ULONGLONG
)time_buf
.tms_utime
* 10000000 / clocks_per_sec
;
1291 static BOOL reported
= FALSE
;
1293 kusrt
.KernelTime
.QuadPart
= 0;
1294 kusrt
.UserTime
.QuadPart
= 0;
1296 TRACE("Cannot get kerneltime or usertime of other threads\n");
1299 FIXME("Cannot get kerneltime or usertime of other threads\n");
1303 if (data
) memcpy( data
, &kusrt
, min( length
, sizeof(kusrt
) ));
1304 if (ret_len
) *ret_len
= min( length
, sizeof(kusrt
) );
1308 case ThreadDescriptorTableEntry
:
1311 THREAD_DESCRIPTOR_INFORMATION
* tdi
= data
;
1312 if (length
< sizeof(*tdi
))
1313 status
= STATUS_INFO_LENGTH_MISMATCH
;
1314 else if (!(tdi
->Selector
& 4)) /* GDT selector */
1316 unsigned sel
= tdi
->Selector
& ~3; /* ignore RPL */
1317 status
= STATUS_SUCCESS
;
1318 if (!sel
) /* null selector */
1319 memset( &tdi
->Entry
, 0, sizeof(tdi
->Entry
) );
1322 tdi
->Entry
.BaseLow
= 0;
1323 tdi
->Entry
.HighWord
.Bits
.BaseMid
= 0;
1324 tdi
->Entry
.HighWord
.Bits
.BaseHi
= 0;
1325 tdi
->Entry
.LimitLow
= 0xffff;
1326 tdi
->Entry
.HighWord
.Bits
.LimitHi
= 0xf;
1327 tdi
->Entry
.HighWord
.Bits
.Dpl
= 3;
1328 tdi
->Entry
.HighWord
.Bits
.Sys
= 0;
1329 tdi
->Entry
.HighWord
.Bits
.Pres
= 1;
1330 tdi
->Entry
.HighWord
.Bits
.Granularity
= 1;
1331 tdi
->Entry
.HighWord
.Bits
.Default_Big
= 1;
1332 tdi
->Entry
.HighWord
.Bits
.Type
= 0x12;
1333 /* it has to be one of the system GDT selectors */
1334 if (sel
!= (wine_get_ds() & ~3) && sel
!= (wine_get_ss() & ~3))
1336 if (sel
== (wine_get_cs() & ~3))
1337 tdi
->Entry
.HighWord
.Bits
.Type
|= 8; /* code segment */
1338 else status
= STATUS_ACCESS_DENIED
;
1344 SERVER_START_REQ( get_selector_entry
)
1346 req
->handle
= wine_server_obj_handle( handle
);
1347 req
->entry
= tdi
->Selector
>> 3;
1348 status
= wine_server_call( req
);
1351 if (!(reply
->flags
& WINE_LDT_FLAGS_ALLOCATED
))
1352 status
= STATUS_ACCESS_VIOLATION
;
1355 wine_ldt_set_base ( &tdi
->Entry
, (void *)reply
->base
);
1356 wine_ldt_set_limit( &tdi
->Entry
, reply
->limit
);
1357 wine_ldt_set_flags( &tdi
->Entry
, reply
->flags
);
1363 if (status
== STATUS_SUCCESS
&& ret_len
)
1364 /* yes, that's a bit strange, but it's the way it is */
1365 *ret_len
= sizeof(LDT_ENTRY
);
1367 status
= STATUS_NOT_IMPLEMENTED
;
1371 case ThreadAmILastThread
:
1373 SERVER_START_REQ(get_thread_info
)
1375 req
->handle
= wine_server_obj_handle( handle
);
1377 status
= wine_server_call( req
);
1378 if (status
== STATUS_SUCCESS
)
1380 BOOLEAN last
= reply
->last
;
1381 if (data
) memcpy( data
, &last
, min( length
, sizeof(last
) ));
1382 if (ret_len
) *ret_len
= min( length
, sizeof(last
) );
1388 case ThreadPriority
:
1389 case ThreadBasePriority
:
1390 case ThreadImpersonationToken
:
1391 case ThreadEnableAlignmentFaultFixup
:
1392 case ThreadEventPair_Reusable
:
1393 case ThreadQuerySetWin32StartAddress
:
1394 case ThreadZeroTlsCell
:
1395 case ThreadPerformanceCount
:
1396 case ThreadIdealProcessor
:
1397 case ThreadPriorityBoost
:
1398 case ThreadSetTlsArrayAddress
:
1399 case ThreadIsIoPending
:
1401 FIXME( "info class %d not supported yet\n", class );
1402 return STATUS_NOT_IMPLEMENTED
;
1407 /******************************************************************************
1408 * NtSetInformationThread (NTDLL.@)
1409 * ZwSetInformationThread (NTDLL.@)
1411 NTSTATUS WINAPI
NtSetInformationThread( HANDLE handle
, THREADINFOCLASS
class,
1412 LPCVOID data
, ULONG length
)
1417 case ThreadZeroTlsCell
:
1418 if (handle
== GetCurrentThread())
1423 if (length
!= sizeof(DWORD
)) return STATUS_INVALID_PARAMETER
;
1424 index
= *(const DWORD
*)data
;
1425 if (index
< TLS_MINIMUM_AVAILABLE
)
1427 RtlAcquirePebLock();
1428 for (entry
= tls_links
.Flink
; entry
!= &tls_links
; entry
= entry
->Flink
)
1430 TEB
*teb
= CONTAINING_RECORD(entry
, TEB
, TlsLinks
);
1431 teb
->TlsSlots
[index
] = 0;
1433 RtlReleasePebLock();
1437 index
-= TLS_MINIMUM_AVAILABLE
;
1438 if (index
>= 8 * sizeof(NtCurrentTeb()->Peb
->TlsExpansionBitmapBits
))
1439 return STATUS_INVALID_PARAMETER
;
1440 RtlAcquirePebLock();
1441 for (entry
= tls_links
.Flink
; entry
!= &tls_links
; entry
= entry
->Flink
)
1443 TEB
*teb
= CONTAINING_RECORD(entry
, TEB
, TlsLinks
);
1444 if (teb
->TlsExpansionSlots
) teb
->TlsExpansionSlots
[index
] = 0;
1446 RtlReleasePebLock();
1448 return STATUS_SUCCESS
;
1450 FIXME( "ZeroTlsCell not supported on other threads\n" );
1451 return STATUS_NOT_IMPLEMENTED
;
1453 case ThreadImpersonationToken
:
1455 const HANDLE
*phToken
= data
;
1456 if (length
!= sizeof(HANDLE
)) return STATUS_INVALID_PARAMETER
;
1457 TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken
);
1458 SERVER_START_REQ( set_thread_info
)
1460 req
->handle
= wine_server_obj_handle( handle
);
1461 req
->token
= wine_server_obj_handle( *phToken
);
1462 req
->mask
= SET_THREAD_INFO_TOKEN
;
1463 status
= wine_server_call( req
);
1468 case ThreadBasePriority
:
1470 const DWORD
*pprio
= data
;
1471 if (length
!= sizeof(DWORD
)) return STATUS_INVALID_PARAMETER
;
1472 SERVER_START_REQ( set_thread_info
)
1474 req
->handle
= wine_server_obj_handle( handle
);
1475 req
->priority
= *pprio
;
1476 req
->mask
= SET_THREAD_INFO_PRIORITY
;
1477 status
= wine_server_call( req
);
1482 case ThreadAffinityMask
:
1484 const ULONG_PTR affinity_mask
= ((ULONG_PTR
)1 << NtCurrentTeb()->Peb
->NumberOfProcessors
) - 1;
1485 const ULONG_PTR
*paff
= data
;
1486 if (length
!= sizeof(ULONG_PTR
)) return STATUS_INVALID_PARAMETER
;
1487 if (*paff
& ~affinity_mask
) return STATUS_INVALID_PARAMETER
;
1488 SERVER_START_REQ( set_thread_info
)
1490 req
->handle
= wine_server_obj_handle( handle
);
1491 req
->affinity
= *paff
;
1492 req
->mask
= SET_THREAD_INFO_AFFINITY
;
1493 status
= wine_server_call( req
);
1498 case ThreadBasicInformation
:
1500 case ThreadPriority
:
1501 case ThreadDescriptorTableEntry
:
1502 case ThreadEnableAlignmentFaultFixup
:
1503 case ThreadEventPair_Reusable
:
1504 case ThreadQuerySetWin32StartAddress
:
1505 case ThreadPerformanceCount
:
1506 case ThreadAmILastThread
:
1507 case ThreadIdealProcessor
:
1508 case ThreadPriorityBoost
:
1509 case ThreadSetTlsArrayAddress
:
1510 case ThreadIsIoPending
:
1512 FIXME( "info class %d not supported yet\n", class );
1513 return STATUS_NOT_IMPLEMENTED
;