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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
24 #include <sys/types.h>
25 #ifdef HAVE_SYS_MMAN_H
28 #ifdef HAVE_SYS_TIMES_H
29 #include <sys/times.h>
32 #define NONAMELESSUNION
34 #define WIN32_NO_STATUS
37 #include "wine/library.h"
38 #include "wine/server.h"
39 #include "wine/pthread.h"
40 #include "wine/debug.h"
41 #include "ntdll_misc.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(thread);
45 /* info passed to a starting thread */
48 struct wine_pthread_thread_info pthread_info;
49 PRTL_THREAD_START_ROUTINE entry_point;
54 static PEB_LDR_DATA ldr;
55 static RTL_USER_PROCESS_PARAMETERS params; /* default parameters if no parent */
56 static WCHAR current_dir[MAX_NT_PATH_LENGTH];
57 static RTL_BITMAP tls_bitmap;
58 static RTL_BITMAP tls_expansion_bitmap;
59 static LIST_ENTRY tls_links;
60 static size_t sigstack_total_size;
62 struct wine_pthread_functions pthread_functions = { NULL };
64 /***********************************************************************
67 static inline NTSTATUS init_teb( TEB *teb )
69 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
71 teb->Tib.ExceptionList = (void *)~0UL;
72 teb->Tib.StackBase = (void *)~0UL;
73 teb->Tib.Self = &teb->Tib;
75 teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
76 teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
78 if (!(thread_data->teb_sel = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
79 thread_data->request_fd = -1;
80 thread_data->reply_fd = -1;
81 thread_data->wait_fd[0] = -1;
82 thread_data->wait_fd[1] = -1;
84 return STATUS_SUCCESS;
88 /***********************************************************************
91 static inline void free_teb( TEB *teb )
95 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
97 NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
98 wine_ldt_free_fs( thread_data->teb_sel );
99 munmap( teb, sigstack_total_size );
103 /***********************************************************************
106 * Setup the initial thread.
108 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
110 void thread_init(void)
115 struct ntdll_thread_data *thread_data;
116 struct wine_pthread_thread_info thread_info;
117 static struct debug_info debug_info; /* debug info for initial thread */
119 peb.NumberOfProcessors = 1;
120 peb.ProcessParameters = ¶ms;
121 peb.TlsBitmap = &tls_bitmap;
122 peb.TlsExpansionBitmap = &tls_expansion_bitmap;
124 params.CurrentDirectory.DosPath.Buffer = current_dir;
125 params.CurrentDirectory.DosPath.MaximumLength = sizeof(current_dir);
126 params.wShowWindow = 1; /* SW_SHOWNORMAL */
127 RtlInitializeBitMap( &tls_bitmap, peb.TlsBitmapBits, sizeof(peb.TlsBitmapBits) * 8 );
128 RtlInitializeBitMap( &tls_expansion_bitmap, peb.TlsExpansionBitmapBits,
129 sizeof(peb.TlsExpansionBitmapBits) * 8 );
130 InitializeListHead( &ldr.InLoadOrderModuleList );
131 InitializeListHead( &ldr.InMemoryOrderModuleList );
132 InitializeListHead( &ldr.InInitializationOrderModuleList );
133 InitializeListHead( &tls_links );
135 sigstack_total_size = get_signal_stack_total_size();
136 thread_info.teb_size = sigstack_total_size;
137 VIRTUAL_alloc_teb( &addr, thread_info.teb_size, TRUE );
140 thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
141 thread_data->debug_info = &debug_info;
142 InsertHeadList( &tls_links, &teb->TlsLinks );
144 thread_info.stack_base = NULL;
145 thread_info.stack_size = 0;
146 thread_info.teb_base = teb;
147 thread_info.teb_sel = thread_data->teb_sel;
148 wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) );
149 pthread_functions.init_current_teb( &thread_info );
150 pthread_functions.init_thread( &thread_info );
152 debug_info.str_pos = debug_info.strings;
153 debug_info.out_pos = debug_info.output;
156 /* setup the server connection */
157 server_init_process();
158 info_size = server_init_thread( thread_info.pid, thread_info.tid, NULL );
160 /* create the process heap */
161 if (!(peb.ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
163 MESSAGE( "wine: failed to create the process heap\n" );
167 /* allocate user parameters */
170 RTL_USER_PROCESS_PARAMETERS *params = NULL;
172 if (NtAllocateVirtualMemory( NtCurrentProcess(), (void **)¶ms, 0, &info_size,
173 MEM_COMMIT, PAGE_READWRITE ) == STATUS_SUCCESS)
175 params->AllocationSize = info_size;
176 NtCurrentTeb()->Peb->ProcessParameters = params;
181 /* This is wine specific: we have no parent (we're started from unix)
182 * so, create a simple console with bare handles to unix stdio
184 wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, OBJ_INHERIT, ¶ms.hStdInput );
185 wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, ¶ms.hStdOutput );
186 wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, OBJ_INHERIT, ¶ms.hStdError );
191 /***********************************************************************
194 * Startup routine for a newly created thread.
196 static void start_thread( struct wine_pthread_thread_info *info )
198 TEB *teb = info->teb_base;
199 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
200 struct startup_info *startup_info = (struct startup_info *)info;
201 PRTL_THREAD_START_ROUTINE func = startup_info->entry_point;
202 void *arg = startup_info->entry_arg;
203 struct debug_info debug_info;
204 SIZE_T size, page_size = getpagesize();
206 debug_info.str_pos = debug_info.strings;
207 debug_info.out_pos = debug_info.output;
208 thread_data->debug_info = &debug_info;
210 pthread_functions.init_current_teb( info );
212 server_init_thread( info->pid, info->tid, func );
213 pthread_functions.init_thread( info );
215 /* allocate a memory view for the stack */
216 size = info->stack_size;
217 teb->DeallocationStack = info->stack_base;
218 NtAllocateVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, 0,
219 &size, MEM_SYSTEM, PAGE_READWRITE );
220 /* limit is lower than base since the stack grows down */
221 teb->Tib.StackBase = (char *)info->stack_base + info->stack_size;
222 teb->Tib.StackLimit = (char *)info->stack_base + page_size;
224 /* setup the guard page */
226 NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size, PAGE_NOACCESS, NULL );
227 RtlFreeHeap( GetProcessHeap(), 0, info );
230 InsertHeadList( &tls_links, &teb->TlsLinks );
237 /***********************************************************************
238 * RtlCreateUserThread (NTDLL.@)
240 NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *descr,
241 BOOLEAN suspended, PVOID stack_addr,
242 SIZE_T stack_reserve, SIZE_T stack_commit,
243 PRTL_THREAD_START_ROUTINE start, void *param,
244 HANDLE *handle_ptr, CLIENT_ID *id )
246 struct ntdll_thread_data *thread_data = NULL;
247 struct startup_info *info = NULL;
254 SIZE_T page_size = getpagesize();
256 if( ! is_current_process( process ) )
258 ERR("Unsupported on other process\n");
259 return STATUS_ACCESS_DENIED;
262 if (pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
263 fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
264 wine_server_send_fd( request_pipe[0] );
266 SERVER_START_REQ( new_thread )
268 req->access = THREAD_ALL_ACCESS;
269 req->attributes = 0; /* FIXME */
270 req->suspend = suspended;
271 req->request_fd = request_pipe[0];
272 if (!(status = wine_server_call( req )))
274 handle = reply->handle;
277 close( request_pipe[0] );
281 if (status) goto error;
283 if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) )))
285 status = STATUS_NO_MEMORY;
289 info->pthread_info.teb_size = sigstack_total_size;
290 if ((status = VIRTUAL_alloc_teb( &addr, info->pthread_info.teb_size, FALSE ))) goto error;
292 if ((status = init_teb( teb ))) goto error;
294 teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId();
295 teb->ClientId.UniqueThread = (HANDLE)tid;
297 thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
298 thread_data->request_fd = request_pipe[1];
300 info->pthread_info.teb_base = teb;
301 info->pthread_info.teb_sel = thread_data->teb_sel;
303 if (!stack_reserve || !stack_commit)
305 IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress );
306 if (!stack_reserve) stack_reserve = nt->OptionalHeader.SizeOfStackReserve;
307 if (!stack_commit) stack_commit = nt->OptionalHeader.SizeOfStackCommit;
309 if (stack_reserve < stack_commit) stack_reserve = stack_commit;
310 stack_reserve += page_size; /* for the guard page */
311 stack_reserve = (stack_reserve + 0xffff) & ~0xffff; /* round to 64K boundary */
312 if (stack_reserve < 1024 * 1024) stack_reserve = 1024 * 1024; /* Xlib needs a large stack */
314 info->pthread_info.stack_base = NULL;
315 info->pthread_info.stack_size = stack_reserve;
316 info->pthread_info.entry = start_thread;
317 info->entry_point = start;
318 info->entry_arg = param;
320 if (pthread_functions.create_thread( &info->pthread_info ) == -1)
322 status = STATUS_NO_MEMORY;
326 if (id) id->UniqueThread = (HANDLE)tid;
327 if (handle_ptr) *handle_ptr = handle;
328 else NtClose( handle );
330 return STATUS_SUCCESS;
333 if (thread_data) wine_ldt_free_fs( thread_data->teb_sel );
337 NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
339 if (info) RtlFreeHeap( GetProcessHeap(), 0, info );
340 if (handle) NtClose( handle );
341 close( request_pipe[1] );
346 /***********************************************************************
347 * RtlExitUserThread (NTDLL.@)
349 void WINAPI RtlExitUserThread( ULONG status )
352 server_exit_thread( status );
356 /***********************************************************************
357 * NtOpenThread (NTDLL.@)
358 * ZwOpenThread (NTDLL.@)
360 NTSTATUS WINAPI NtOpenThread( HANDLE *handle, ACCESS_MASK access,
361 const OBJECT_ATTRIBUTES *attr, const CLIENT_ID *id )
365 SERVER_START_REQ( open_thread )
367 req->tid = (thread_id_t)id->UniqueThread;
368 req->access = access;
369 req->attributes = attr ? attr->Attributes : 0;
370 ret = wine_server_call( req );
371 *handle = reply->handle;
378 /******************************************************************************
379 * NtSuspendThread (NTDLL.@)
380 * ZwSuspendThread (NTDLL.@)
382 NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
386 SERVER_START_REQ( suspend_thread )
388 req->handle = handle;
389 if (!(ret = wine_server_call( req ))) *count = reply->count;
396 /******************************************************************************
397 * NtResumeThread (NTDLL.@)
398 * ZwResumeThread (NTDLL.@)
400 NTSTATUS WINAPI NtResumeThread( HANDLE handle, PULONG count )
404 SERVER_START_REQ( resume_thread )
406 req->handle = handle;
407 if (!(ret = wine_server_call( req ))) *count = reply->count;
414 /******************************************************************************
415 * NtAlertResumeThread (NTDLL.@)
416 * ZwAlertResumeThread (NTDLL.@)
418 NTSTATUS WINAPI NtAlertResumeThread( HANDLE handle, PULONG count )
420 FIXME( "stub: should alert thread %p\n", handle );
421 return NtResumeThread( handle, count );
425 /******************************************************************************
426 * NtAlertThread (NTDLL.@)
427 * ZwAlertThread (NTDLL.@)
429 NTSTATUS WINAPI NtAlertThread( HANDLE handle )
431 FIXME( "stub: %p\n", handle );
432 return STATUS_NOT_IMPLEMENTED;
436 /******************************************************************************
437 * NtTerminateThread (NTDLL.@)
438 * ZwTerminateThread (NTDLL.@)
440 NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
445 SERVER_START_REQ( terminate_thread )
447 req->handle = handle;
448 req->exit_code = exit_code;
449 ret = wine_server_call( req );
450 self = !ret && reply->self;
457 if (last) exit( exit_code );
458 else server_abort_thread( exit_code );
464 /******************************************************************************
465 * NtQueueApcThread (NTDLL.@)
467 NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1,
468 ULONG_PTR arg2, ULONG_PTR arg3 )
471 SERVER_START_REQ( queue_apc )
473 req->handle = handle;
476 req->arg1 = (void *)arg1;
477 req->arg2 = (void *)arg2;
478 req->arg3 = (void *)arg3;
479 ret = wine_server_call( req );
486 /***********************************************************************
487 * NtSetContextThread (NTDLL.@)
488 * ZwSetContextThread (NTDLL.@)
490 NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
495 SERVER_START_REQ( set_thread_context )
497 req->handle = handle;
498 req->flags = context->ContextFlags;
500 wine_server_add_data( req, context, sizeof(*context) );
501 ret = wine_server_call( req );
505 if (ret == STATUS_PENDING)
507 if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
509 for (i = 0; i < 100; i++)
511 SERVER_START_REQ( set_thread_context )
513 req->handle = handle;
514 req->flags = context->ContextFlags;
516 wine_server_add_data( req, context, sizeof(*context) );
517 ret = wine_server_call( req );
520 if (ret != STATUS_PENDING) break;
523 NtResumeThread( handle, &dummy );
527 if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
532 /* copy a context structure according to the flags */
533 static inline void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
536 flags &= ~CONTEXT_i386; /* get rid of CPU id */
537 if (flags & CONTEXT_INTEGER)
546 if (flags & CONTEXT_CONTROL)
551 to->SegCs = from->SegCs;
552 to->SegSs = from->SegSs;
553 to->EFlags = from->EFlags;
555 if (flags & CONTEXT_SEGMENTS)
557 to->SegDs = from->SegDs;
558 to->SegEs = from->SegEs;
559 to->SegFs = from->SegFs;
560 to->SegGs = from->SegGs;
562 if (flags & CONTEXT_DEBUG_REGISTERS)
571 if (flags & CONTEXT_FLOATING_POINT)
573 to->FloatSave = from->FloatSave;
575 #elif defined(__x86_64__)
576 flags &= ~CONTEXT_AMD64; /* get rid of CPU id */
577 if (flags & CONTEXT_CONTROL)
582 to->SegCs = from->SegCs;
583 to->SegSs = from->SegSs;
584 to->EFlags = from->EFlags;
585 to->MxCsr = from->MxCsr;
587 if (flags & CONTEXT_INTEGER)
604 if (flags & CONTEXT_SEGMENTS)
606 to->SegDs = from->SegDs;
607 to->SegEs = from->SegEs;
608 to->SegFs = from->SegFs;
609 to->SegGs = from->SegGs;
611 if (flags & CONTEXT_FLOATING_POINT)
613 to->u.FltSave = from->u.FltSave;
615 if (flags & CONTEXT_DEBUG_REGISTERS)
624 #elif defined(__sparc__)
625 flags &= ~CONTEXT_SPARC; /* get rid of CPU id */
626 if (flags & CONTEXT_CONTROL)
635 if (flags & CONTEXT_INTEGER)
670 if (flags & CONTEXT_FLOATING_POINT)
674 #elif defined(__powerpc__)
676 if (flags & CONTEXT_CONTROL)
682 if (flags & CONTEXT_INTEGER)
684 to->Gpr0 = from->Gpr0;
685 to->Gpr1 = from->Gpr1;
686 to->Gpr2 = from->Gpr2;
687 to->Gpr3 = from->Gpr3;
688 to->Gpr4 = from->Gpr4;
689 to->Gpr5 = from->Gpr5;
690 to->Gpr6 = from->Gpr6;
691 to->Gpr7 = from->Gpr7;
692 to->Gpr8 = from->Gpr8;
693 to->Gpr9 = from->Gpr9;
694 to->Gpr10 = from->Gpr10;
695 to->Gpr11 = from->Gpr11;
696 to->Gpr12 = from->Gpr12;
697 to->Gpr13 = from->Gpr13;
698 to->Gpr14 = from->Gpr14;
699 to->Gpr15 = from->Gpr15;
700 to->Gpr16 = from->Gpr16;
701 to->Gpr17 = from->Gpr17;
702 to->Gpr18 = from->Gpr18;
703 to->Gpr19 = from->Gpr19;
704 to->Gpr20 = from->Gpr20;
705 to->Gpr21 = from->Gpr21;
706 to->Gpr22 = from->Gpr22;
707 to->Gpr23 = from->Gpr23;
708 to->Gpr24 = from->Gpr24;
709 to->Gpr25 = from->Gpr25;
710 to->Gpr26 = from->Gpr26;
711 to->Gpr27 = from->Gpr27;
712 to->Gpr28 = from->Gpr28;
713 to->Gpr29 = from->Gpr29;
714 to->Gpr30 = from->Gpr30;
715 to->Gpr31 = from->Gpr31;
719 if (flags & CONTEXT_FLOATING_POINT)
721 to->Fpr0 = from->Fpr0;
722 to->Fpr1 = from->Fpr1;
723 to->Fpr2 = from->Fpr2;
724 to->Fpr3 = from->Fpr3;
725 to->Fpr4 = from->Fpr4;
726 to->Fpr5 = from->Fpr5;
727 to->Fpr6 = from->Fpr6;
728 to->Fpr7 = from->Fpr7;
729 to->Fpr8 = from->Fpr8;
730 to->Fpr9 = from->Fpr9;
731 to->Fpr10 = from->Fpr10;
732 to->Fpr11 = from->Fpr11;
733 to->Fpr12 = from->Fpr12;
734 to->Fpr13 = from->Fpr13;
735 to->Fpr14 = from->Fpr14;
736 to->Fpr15 = from->Fpr15;
737 to->Fpr16 = from->Fpr16;
738 to->Fpr17 = from->Fpr17;
739 to->Fpr18 = from->Fpr18;
740 to->Fpr19 = from->Fpr19;
741 to->Fpr20 = from->Fpr20;
742 to->Fpr21 = from->Fpr21;
743 to->Fpr22 = from->Fpr22;
744 to->Fpr23 = from->Fpr23;
745 to->Fpr24 = from->Fpr24;
746 to->Fpr25 = from->Fpr25;
747 to->Fpr26 = from->Fpr26;
748 to->Fpr27 = from->Fpr27;
749 to->Fpr28 = from->Fpr28;
750 to->Fpr29 = from->Fpr29;
751 to->Fpr30 = from->Fpr30;
752 to->Fpr31 = from->Fpr31;
753 to->Fpscr = from->Fpscr;
756 #error You must implement context copying for your CPU
761 /***********************************************************************
762 * NtGetContextThread (NTDLL.@)
763 * ZwGetContextThread (NTDLL.@)
765 NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
771 SERVER_START_REQ( get_thread_context )
773 req->handle = handle;
774 req->flags = context->ContextFlags;
776 wine_server_set_reply( req, &ctx, sizeof(ctx) );
777 ret = wine_server_call( req );
781 if (ret == STATUS_PENDING)
783 if (NtSuspendThread( handle, &dummy ) == STATUS_SUCCESS)
785 for (i = 0; i < 100; i++)
787 SERVER_START_REQ( get_thread_context )
789 req->handle = handle;
790 req->flags = context->ContextFlags;
792 wine_server_set_reply( req, &ctx, sizeof(ctx) );
793 ret = wine_server_call( req );
796 if (ret != STATUS_PENDING) break;
799 NtResumeThread( handle, &dummy );
803 if (ret == STATUS_SUCCESS) copy_context( context, &ctx, context->ContextFlags );
804 else if (ret == STATUS_PENDING) ret = STATUS_ACCESS_DENIED;
809 /******************************************************************************
810 * NtQueryInformationThread (NTDLL.@)
811 * ZwQueryInformationThread (NTDLL.@)
813 NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
814 void *data, ULONG length, ULONG *ret_len )
820 case ThreadBasicInformation:
822 THREAD_BASIC_INFORMATION info;
824 SERVER_START_REQ( get_thread_info )
826 req->handle = handle;
828 if (!(status = wine_server_call( req )))
830 info.ExitStatus = reply->exit_code;
831 info.TebBaseAddress = reply->teb;
832 info.ClientId.UniqueProcess = (HANDLE)reply->pid;
833 info.ClientId.UniqueThread = (HANDLE)reply->tid;
834 info.AffinityMask = reply->affinity;
835 info.Priority = reply->priority;
836 info.BasePriority = reply->priority; /* FIXME */
840 if (status == STATUS_SUCCESS)
842 if (data) memcpy( data, &info, min( length, sizeof(info) ));
843 if (ret_len) *ret_len = min( length, sizeof(info) );
849 KERNEL_USER_TIMES kusrt;
850 /* We need to do a server call to get the creation time or exit time */
851 /* This works on any thread */
852 SERVER_START_REQ( get_thread_info )
854 req->handle = handle;
856 status = wine_server_call( req );
857 if (status == STATUS_SUCCESS)
859 RtlSecondsSince1970ToTime( reply->creation_time, &kusrt.CreateTime );
860 RtlSecondsSince1970ToTime( reply->exit_time, &kusrt.ExitTime );
864 if (status == STATUS_SUCCESS)
866 /* We call times(2) for kernel time or user time */
867 /* We can only (portably) do this for the current thread */
868 if (handle == GetCurrentThread())
871 long clocks_per_sec = sysconf(_SC_CLK_TCK);
874 kusrt.KernelTime.QuadPart = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
875 kusrt.UserTime.QuadPart = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
879 kusrt.KernelTime.QuadPart = 0;
880 kusrt.UserTime.QuadPart = 0;
881 FIXME("Cannot get kerneltime or usertime of other threads\n");
883 if (data) memcpy( data, &kusrt, min( length, sizeof(kusrt) ));
884 if (ret_len) *ret_len = min( length, sizeof(kusrt) );
889 case ThreadBasePriority:
890 case ThreadAffinityMask:
891 case ThreadImpersonationToken:
892 case ThreadDescriptorTableEntry:
893 case ThreadEnableAlignmentFaultFixup:
894 case ThreadEventPair_Reusable:
895 case ThreadQuerySetWin32StartAddress:
896 case ThreadZeroTlsCell:
897 case ThreadPerformanceCount:
898 case ThreadAmILastThread:
899 case ThreadIdealProcessor:
900 case ThreadPriorityBoost:
901 case ThreadSetTlsArrayAddress:
902 case ThreadIsIoPending:
904 FIXME( "info class %d not supported yet\n", class );
905 return STATUS_NOT_IMPLEMENTED;
910 /******************************************************************************
911 * NtSetInformationThread (NTDLL.@)
912 * ZwSetInformationThread (NTDLL.@)
914 NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
915 LPCVOID data, ULONG length )
920 case ThreadZeroTlsCell:
921 if (handle == GetCurrentThread())
926 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
927 index = *(const DWORD *)data;
928 if (index < TLS_MINIMUM_AVAILABLE)
931 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
933 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
934 teb->TlsSlots[index] = 0;
940 index -= TLS_MINIMUM_AVAILABLE;
941 if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
942 return STATUS_INVALID_PARAMETER;
944 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
946 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
947 if (teb->TlsExpansionSlots) teb->TlsExpansionSlots[index] = 0;
951 return STATUS_SUCCESS;
953 FIXME( "ZeroTlsCell not supported on other threads\n" );
954 return STATUS_NOT_IMPLEMENTED;
956 case ThreadImpersonationToken:
958 const HANDLE *phToken = data;
959 if (length != sizeof(HANDLE)) return STATUS_INVALID_PARAMETER;
960 TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken );
961 SERVER_START_REQ( set_thread_info )
963 req->handle = handle;
964 req->token = *phToken;
965 req->mask = SET_THREAD_INFO_TOKEN;
966 status = wine_server_call( req );
971 case ThreadBasePriority:
973 const DWORD *pprio = data;
974 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
975 SERVER_START_REQ( set_thread_info )
977 req->handle = handle;
978 req->priority = *pprio;
979 req->mask = SET_THREAD_INFO_PRIORITY;
980 status = wine_server_call( req );
985 case ThreadBasicInformation:
988 case ThreadAffinityMask:
989 case ThreadDescriptorTableEntry:
990 case ThreadEnableAlignmentFaultFixup:
991 case ThreadEventPair_Reusable:
992 case ThreadQuerySetWin32StartAddress:
993 case ThreadPerformanceCount:
994 case ThreadAmILastThread:
995 case ThreadIdealProcessor:
996 case ThreadPriorityBoost:
997 case ThreadSetTlsArrayAddress:
998 case ThreadIsIoPending:
1000 FIXME( "info class %d not supported yet\n", class );
1001 return STATUS_NOT_IMPLEMENTED;
1006 /**********************************************************************
1007 * NtCurrentTeb (NTDLL.@)
1009 #if defined(__i386__) && defined(__GNUC__)
1011 __ASM_GLOBAL_FUNC( NtCurrentTeb, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" );
1013 #elif defined(__i386__) && defined(_MSC_VER)
1015 /* Nothing needs to be done. MS C "magically" exports the inline version from winnt.h */
1019 /**********************************************************************/
1021 TEB * WINAPI NtCurrentTeb(void)
1023 return pthread_functions.get_current_teb();
1026 #endif /* __i386__ */