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>
35 #include "wine/library.h"
36 #include "wine/server.h"
37 #include "wine/pthread.h"
38 #include "wine/debug.h"
39 #include "ntdll_misc.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(thread);
43 /* info passed to a starting thread */
46 struct wine_pthread_thread_info pthread_info;
47 PRTL_THREAD_START_ROUTINE entry_point;
52 static PEB_LDR_DATA ldr;
53 static RTL_USER_PROCESS_PARAMETERS params; /* default parameters if no parent */
54 static WCHAR current_dir[MAX_NT_PATH_LENGTH];
55 static RTL_BITMAP tls_bitmap;
56 static RTL_BITMAP tls_expansion_bitmap;
57 static LIST_ENTRY tls_links;
58 static size_t sigstack_total_size;
60 struct wine_pthread_functions pthread_functions = { NULL };
62 /***********************************************************************
65 static inline NTSTATUS init_teb( TEB *teb )
67 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
69 teb->Tib.ExceptionList = (void *)~0UL;
70 teb->Tib.StackBase = (void *)~0UL;
71 teb->Tib.Self = &teb->Tib;
73 teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer;
74 teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
76 if (!(thread_data->teb_sel = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
77 thread_data->request_fd = -1;
78 thread_data->reply_fd = -1;
79 thread_data->wait_fd[0] = -1;
80 thread_data->wait_fd[1] = -1;
82 return STATUS_SUCCESS;
86 /***********************************************************************
89 static inline void free_teb( TEB *teb )
93 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
95 NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
96 wine_ldt_free_fs( thread_data->teb_sel );
97 munmap( teb, sigstack_total_size );
101 /***********************************************************************
104 * Setup the initial thread.
106 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
108 void thread_init(void)
113 struct ntdll_thread_data *thread_data;
114 struct wine_pthread_thread_info thread_info;
115 static struct debug_info debug_info; /* debug info for initial thread */
117 peb.NumberOfProcessors = 1;
118 peb.ProcessParameters = ¶ms;
119 peb.TlsBitmap = &tls_bitmap;
120 peb.TlsExpansionBitmap = &tls_expansion_bitmap;
122 params.CurrentDirectory.DosPath.Buffer = current_dir;
123 params.CurrentDirectory.DosPath.MaximumLength = sizeof(current_dir);
124 RtlInitializeBitMap( &tls_bitmap, peb.TlsBitmapBits, sizeof(peb.TlsBitmapBits) * 8 );
125 RtlInitializeBitMap( &tls_expansion_bitmap, peb.TlsExpansionBitmapBits,
126 sizeof(peb.TlsExpansionBitmapBits) * 8 );
127 InitializeListHead( &ldr.InLoadOrderModuleList );
128 InitializeListHead( &ldr.InMemoryOrderModuleList );
129 InitializeListHead( &ldr.InInitializationOrderModuleList );
130 InitializeListHead( &tls_links );
132 sigstack_total_size = get_signal_stack_total_size();
133 thread_info.teb_size = sigstack_total_size;
134 VIRTUAL_alloc_teb( &addr, thread_info.teb_size, TRUE );
137 thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
138 thread_data->debug_info = &debug_info;
139 InsertHeadList( &tls_links, &teb->TlsLinks );
141 thread_info.stack_base = NULL;
142 thread_info.stack_size = 0;
143 thread_info.teb_base = teb;
144 thread_info.teb_sel = thread_data->teb_sel;
145 wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) );
146 pthread_functions.init_current_teb( &thread_info );
147 pthread_functions.init_thread( &thread_info );
149 debug_info.str_pos = debug_info.strings;
150 debug_info.out_pos = debug_info.output;
153 /* setup the server connection */
154 server_init_process();
155 info_size = server_init_thread( thread_info.pid, thread_info.tid, NULL );
157 /* create the process heap */
158 if (!(peb.ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL )))
160 MESSAGE( "wine: failed to create the process heap\n" );
164 /* allocate user parameters */
167 RTL_USER_PROCESS_PARAMETERS *params = NULL;
169 if (NtAllocateVirtualMemory( NtCurrentProcess(), (void **)¶ms, 0, &info_size,
170 MEM_COMMIT, PAGE_READWRITE ) == STATUS_SUCCESS)
172 params->AllocationSize = info_size;
173 NtCurrentTeb()->Peb->ProcessParameters = params;
178 /* This is wine specific: we have no parent (we're started from unix)
179 * so, create a simple console with bare handles to unix stdio
181 wine_server_fd_to_handle( 0, GENERIC_READ|SYNCHRONIZE, TRUE, ¶ms.hStdInput );
182 wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, ¶ms.hStdOutput );
183 wine_server_fd_to_handle( 2, GENERIC_WRITE|SYNCHRONIZE, TRUE, ¶ms.hStdError );
188 /***********************************************************************
191 * Startup routine for a newly created thread.
193 static void start_thread( struct wine_pthread_thread_info *info )
195 TEB *teb = info->teb_base;
196 struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
197 struct startup_info *startup_info = (struct startup_info *)info;
198 PRTL_THREAD_START_ROUTINE func = startup_info->entry_point;
199 void *arg = startup_info->entry_arg;
200 struct debug_info debug_info;
203 debug_info.str_pos = debug_info.strings;
204 debug_info.out_pos = debug_info.output;
205 thread_data->debug_info = &debug_info;
207 pthread_functions.init_current_teb( info );
209 server_init_thread( info->pid, info->tid, func );
210 pthread_functions.init_thread( info );
212 /* allocate a memory view for the stack */
213 size = info->stack_size;
214 teb->DeallocationStack = info->stack_base;
215 NtAllocateVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, 0,
216 &size, MEM_SYSTEM, PAGE_READWRITE );
217 /* limit is lower than base since the stack grows down */
218 teb->Tib.StackBase = (char *)info->stack_base + info->stack_size;
219 teb->Tib.StackLimit = info->stack_base;
221 /* setup the guard page */
223 NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size,
224 PAGE_READWRITE | PAGE_GUARD, NULL );
225 RtlFreeHeap( GetProcessHeap(), 0, info );
228 InsertHeadList( &tls_links, &teb->TlsLinks );
235 /***********************************************************************
236 * RtlCreateUserThread (NTDLL.@)
238 NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, const SECURITY_DESCRIPTOR *descr,
239 BOOLEAN suspended, PVOID stack_addr,
240 SIZE_T stack_reserve, SIZE_T stack_commit,
241 PRTL_THREAD_START_ROUTINE start, void *param,
242 HANDLE *handle_ptr, CLIENT_ID *id )
244 struct ntdll_thread_data *thread_data = NULL;
245 struct startup_info *info = NULL;
253 if( ! is_current_process( process ) )
255 ERR("Unsupported on other process\n");
256 return STATUS_ACCESS_DENIED;
259 if (pipe( request_pipe ) == -1) return STATUS_TOO_MANY_OPENED_FILES;
260 fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
261 wine_server_send_fd( request_pipe[0] );
263 SERVER_START_REQ( new_thread )
265 req->suspend = suspended;
266 req->inherit = 0; /* FIXME */
267 req->request_fd = request_pipe[0];
268 if (!(status = wine_server_call( req )))
270 handle = reply->handle;
273 close( request_pipe[0] );
277 if (status) goto error;
279 if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) )))
281 status = STATUS_NO_MEMORY;
285 info->pthread_info.teb_size = sigstack_total_size;
286 if ((status = VIRTUAL_alloc_teb( &addr, info->pthread_info.teb_size, FALSE ))) goto error;
288 if ((status = init_teb( teb ))) goto error;
290 teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId();
291 teb->ClientId.UniqueThread = (HANDLE)tid;
293 thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
294 thread_data->request_fd = request_pipe[1];
296 info->pthread_info.teb_base = teb;
297 info->pthread_info.teb_sel = thread_data->teb_sel;
299 if (!stack_reserve || !stack_commit)
301 IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress );
302 if (!stack_reserve) stack_reserve = nt->OptionalHeader.SizeOfStackReserve;
303 if (!stack_commit) stack_commit = nt->OptionalHeader.SizeOfStackCommit;
305 if (stack_reserve < stack_commit) stack_reserve = stack_commit;
306 stack_reserve = (stack_reserve + 0xffff) & ~0xffff; /* round to 64K boundary */
307 if (stack_reserve < 1024 * 1024) stack_reserve = 1024 * 1024; /* Xlib needs a large stack */
309 info->pthread_info.stack_base = NULL;
310 info->pthread_info.stack_size = stack_reserve;
311 info->pthread_info.entry = start_thread;
312 info->entry_point = start;
313 info->entry_arg = param;
315 if (pthread_functions.create_thread( &info->pthread_info ) == -1)
317 status = STATUS_NO_MEMORY;
321 if (id) id->UniqueThread = (HANDLE)tid;
322 if (handle_ptr) *handle_ptr = handle;
323 else NtClose( handle );
325 return STATUS_SUCCESS;
328 if (thread_data) wine_ldt_free_fs( thread_data->teb_sel );
332 NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
334 if (info) RtlFreeHeap( GetProcessHeap(), 0, info );
335 if (handle) NtClose( handle );
336 close( request_pipe[1] );
341 /***********************************************************************
342 * RtlExitUserThread (NTDLL.@)
344 void WINAPI RtlExitUserThread( ULONG status )
347 server_exit_thread( status );
351 /***********************************************************************
352 * NtOpenThread (NTDLL.@)
353 * ZwOpenThread (NTDLL.@)
355 NTSTATUS WINAPI NtOpenThread( HANDLE *handle, ACCESS_MASK access,
356 const OBJECT_ATTRIBUTES *attr, const CLIENT_ID *id )
360 SERVER_START_REQ( open_thread )
362 req->tid = (thread_id_t)id->UniqueThread;
363 req->access = access;
364 req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
365 ret = wine_server_call( req );
366 *handle = reply->handle;
373 /******************************************************************************
374 * NtSuspendThread (NTDLL.@)
375 * ZwSuspendThread (NTDLL.@)
377 NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
381 SERVER_START_REQ( suspend_thread )
383 req->handle = handle;
384 if (!(ret = wine_server_call( req ))) *count = reply->count;
391 /******************************************************************************
392 * NtResumeThread (NTDLL.@)
393 * ZwResumeThread (NTDLL.@)
395 NTSTATUS WINAPI NtResumeThread( HANDLE handle, PULONG count )
399 SERVER_START_REQ( resume_thread )
401 req->handle = handle;
402 if (!(ret = wine_server_call( req ))) *count = reply->count;
409 /******************************************************************************
410 * NtAlertResumeThread (NTDLL.@)
411 * ZwAlertResumeThread (NTDLL.@)
413 NTSTATUS WINAPI NtAlertResumeThread( HANDLE handle, PULONG count )
415 FIXME( "stub: should alert thread %p\n", handle );
416 return NtResumeThread( handle, count );
420 /******************************************************************************
421 * NtAlertThread (NTDLL.@)
422 * ZwAlertThread (NTDLL.@)
424 NTSTATUS WINAPI NtAlertThread( HANDLE handle )
426 FIXME( "stub: %p\n", handle );
427 return STATUS_NOT_IMPLEMENTED;
431 /******************************************************************************
432 * NtTerminateThread (NTDLL.@)
433 * ZwTerminateThread (NTDLL.@)
435 NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
440 SERVER_START_REQ( terminate_thread )
442 req->handle = handle;
443 req->exit_code = exit_code;
444 ret = wine_server_call( req );
445 self = !ret && reply->self;
452 if (last) exit( exit_code );
453 else server_abort_thread( exit_code );
459 /******************************************************************************
460 * NtQueueApcThread (NTDLL.@)
462 NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1,
463 ULONG_PTR arg2, ULONG_PTR arg3 )
466 SERVER_START_REQ( queue_apc )
468 req->handle = handle;
471 req->arg1 = (void *)arg1;
472 req->arg2 = (void *)arg2;
473 req->arg3 = (void *)arg3;
474 ret = wine_server_call( req );
481 /***********************************************************************
482 * NtSetContextThread (NTDLL.@)
483 * ZwSetContextThread (NTDLL.@)
485 NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
489 SERVER_START_REQ( set_thread_context )
491 req->handle = handle;
492 req->flags = context->ContextFlags;
493 wine_server_add_data( req, context, sizeof(*context) );
494 ret = wine_server_call( req );
501 /* copy a context structure according to the flags */
502 static inline void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
505 if (flags & CONTEXT_INTEGER)
514 if (flags & CONTEXT_CONTROL)
519 to->SegCs = from->SegCs;
520 to->SegSs = from->SegSs;
521 to->EFlags = from->EFlags;
523 if (flags & CONTEXT_SEGMENTS)
525 to->SegDs = from->SegDs;
526 to->SegEs = from->SegEs;
527 to->SegFs = from->SegFs;
528 to->SegGs = from->SegGs;
530 if (flags & CONTEXT_DEBUG_REGISTERS)
539 if (flags & CONTEXT_FLOATING_POINT)
541 to->FloatSave = from->FloatSave;
543 #elif defined(__x86_64__)
544 if (flags & CONTEXT_CONTROL)
549 to->SegCs = from->SegCs;
550 to->SegSs = from->SegSs;
551 to->EFlags = from->EFlags;
552 to->MxCsr = from->MxCsr;
554 if (flags & CONTEXT_INTEGER)
571 if (flags & CONTEXT_SEGMENTS)
573 to->SegDs = from->SegDs;
574 to->SegEs = from->SegEs;
575 to->SegFs = from->SegFs;
576 to->SegGs = from->SegGs;
578 if (flags & CONTEXT_FLOATING_POINT)
580 to->u.FltSave = from->u.FltSave;
582 if (flags & CONTEXT_DEBUG_REGISTERS)
591 #elif defined(__sparc__)
592 if (flags & CONTEXT_CONTROL)
601 if (flags & CONTEXT_INTEGER)
636 if (flags & CONTEXT_FLOATING_POINT)
640 #elif defined(__powerpc__)
641 if (flags & CONTEXT_CONTROL)
647 if (flags & CONTEXT_INTEGER)
649 to->Gpr0 = from->Gpr0;
650 to->Gpr1 = from->Gpr1;
651 to->Gpr2 = from->Gpr2;
652 to->Gpr3 = from->Gpr3;
653 to->Gpr4 = from->Gpr4;
654 to->Gpr5 = from->Gpr5;
655 to->Gpr6 = from->Gpr6;
656 to->Gpr7 = from->Gpr7;
657 to->Gpr8 = from->Gpr8;
658 to->Gpr9 = from->Gpr9;
659 to->Gpr10 = from->Gpr10;
660 to->Gpr11 = from->Gpr11;
661 to->Gpr12 = from->Gpr12;
662 to->Gpr13 = from->Gpr13;
663 to->Gpr14 = from->Gpr14;
664 to->Gpr15 = from->Gpr15;
665 to->Gpr16 = from->Gpr16;
666 to->Gpr17 = from->Gpr17;
667 to->Gpr18 = from->Gpr18;
668 to->Gpr19 = from->Gpr19;
669 to->Gpr20 = from->Gpr20;
670 to->Gpr21 = from->Gpr21;
671 to->Gpr22 = from->Gpr22;
672 to->Gpr23 = from->Gpr23;
673 to->Gpr24 = from->Gpr24;
674 to->Gpr25 = from->Gpr25;
675 to->Gpr26 = from->Gpr26;
676 to->Gpr27 = from->Gpr27;
677 to->Gpr28 = from->Gpr28;
678 to->Gpr29 = from->Gpr29;
679 to->Gpr30 = from->Gpr30;
680 to->Gpr31 = from->Gpr31;
684 if (flags & CONTEXT_FLOATING_POINT)
686 to->Fpr0 = from->Fpr0;
687 to->Fpr1 = from->Fpr1;
688 to->Fpr2 = from->Fpr2;
689 to->Fpr3 = from->Fpr3;
690 to->Fpr4 = from->Fpr4;
691 to->Fpr5 = from->Fpr5;
692 to->Fpr6 = from->Fpr6;
693 to->Fpr7 = from->Fpr7;
694 to->Fpr8 = from->Fpr8;
695 to->Fpr9 = from->Fpr9;
696 to->Fpr10 = from->Fpr10;
697 to->Fpr11 = from->Fpr11;
698 to->Fpr12 = from->Fpr12;
699 to->Fpr13 = from->Fpr13;
700 to->Fpr14 = from->Fpr14;
701 to->Fpr15 = from->Fpr15;
702 to->Fpr16 = from->Fpr16;
703 to->Fpr17 = from->Fpr17;
704 to->Fpr18 = from->Fpr18;
705 to->Fpr19 = from->Fpr19;
706 to->Fpr20 = from->Fpr20;
707 to->Fpr21 = from->Fpr21;
708 to->Fpr22 = from->Fpr22;
709 to->Fpr23 = from->Fpr23;
710 to->Fpr24 = from->Fpr24;
711 to->Fpr25 = from->Fpr25;
712 to->Fpr26 = from->Fpr26;
713 to->Fpr27 = from->Fpr27;
714 to->Fpr28 = from->Fpr28;
715 to->Fpr29 = from->Fpr29;
716 to->Fpr30 = from->Fpr30;
717 to->Fpr31 = from->Fpr31;
718 to->Fpscr = from->Fpscr;
721 #error You must implement context copying for your CPU
726 /***********************************************************************
727 * NtGetContextThread (NTDLL.@)
728 * ZwGetContextThread (NTDLL.@)
730 NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
735 SERVER_START_REQ( get_thread_context )
737 req->handle = handle;
738 req->flags = context->ContextFlags;
739 wine_server_set_reply( req, &ctx, sizeof(ctx) );
740 ret = wine_server_call( req );
743 if (ret == STATUS_SUCCESS) copy_context( context, &ctx, context->ContextFlags );
748 /******************************************************************************
749 * NtQueryInformationThread (NTDLL.@)
750 * ZwQueryInformationThread (NTDLL.@)
752 NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
753 void *data, ULONG length, ULONG *ret_len )
759 case ThreadBasicInformation:
761 THREAD_BASIC_INFORMATION info;
763 SERVER_START_REQ( get_thread_info )
765 req->handle = handle;
767 if (!(status = wine_server_call( req )))
769 info.ExitStatus = reply->exit_code;
770 info.TebBaseAddress = reply->teb;
771 info.ClientId.UniqueProcess = (HANDLE)reply->pid;
772 info.ClientId.UniqueThread = (HANDLE)reply->tid;
773 info.AffinityMask = reply->affinity;
774 info.Priority = reply->priority;
775 info.BasePriority = reply->priority; /* FIXME */
779 if (status == STATUS_SUCCESS)
781 if (data) memcpy( data, &info, min( length, sizeof(info) ));
782 if (ret_len) *ret_len = min( length, sizeof(info) );
788 KERNEL_USER_TIMES kusrt;
789 /* We need to do a server call to get the creation time or exit time */
790 /* This works on any thread */
791 SERVER_START_REQ( get_thread_info )
793 req->handle = handle;
795 status = wine_server_call( req );
796 if (status == STATUS_SUCCESS)
798 RtlSecondsSince1970ToTime( reply->creation_time, &kusrt.CreateTime );
799 RtlSecondsSince1970ToTime( reply->exit_time, &kusrt.ExitTime );
803 if (status == STATUS_SUCCESS)
805 /* We call times(2) for kernel time or user time */
806 /* We can only (portably) do this for the current thread */
807 if (handle == GetCurrentThread())
810 long clocks_per_sec = sysconf(_SC_CLK_TCK);
813 kusrt.KernelTime.QuadPart = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
814 kusrt.UserTime.QuadPart = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
818 kusrt.KernelTime.QuadPart = 0;
819 kusrt.UserTime.QuadPart = 0;
820 FIXME("Cannot get kerneltime or usertime of other threads\n");
822 if (data) memcpy( data, &kusrt, min( length, sizeof(kusrt) ));
823 if (ret_len) *ret_len = min( length, sizeof(kusrt) );
828 case ThreadBasePriority:
829 case ThreadAffinityMask:
830 case ThreadImpersonationToken:
831 case ThreadDescriptorTableEntry:
832 case ThreadEnableAlignmentFaultFixup:
833 case ThreadEventPair_Reusable:
834 case ThreadQuerySetWin32StartAddress:
835 case ThreadZeroTlsCell:
836 case ThreadPerformanceCount:
837 case ThreadAmILastThread:
838 case ThreadIdealProcessor:
839 case ThreadPriorityBoost:
840 case ThreadSetTlsArrayAddress:
841 case ThreadIsIoPending:
843 FIXME( "info class %d not supported yet\n", class );
844 return STATUS_NOT_IMPLEMENTED;
849 /******************************************************************************
850 * NtSetInformationThread (NTDLL.@)
851 * ZwSetInformationThread (NTDLL.@)
853 NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
854 LPCVOID data, ULONG length )
859 case ThreadZeroTlsCell:
860 if (handle == GetCurrentThread())
865 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
866 index = *(const DWORD *)data;
867 if (index < TLS_MINIMUM_AVAILABLE)
870 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
872 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
873 teb->TlsSlots[index] = 0;
879 index -= TLS_MINIMUM_AVAILABLE;
880 if (index >= 8 * sizeof(NtCurrentTeb()->Peb->TlsExpansionBitmapBits))
881 return STATUS_INVALID_PARAMETER;
883 for (entry = tls_links.Flink; entry != &tls_links; entry = entry->Flink)
885 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
886 if (teb->TlsExpansionSlots) teb->TlsExpansionSlots[index] = 0;
890 return STATUS_SUCCESS;
892 FIXME( "ZeroTlsCell not supported on other threads\n" );
893 return STATUS_NOT_IMPLEMENTED;
895 case ThreadImpersonationToken:
897 const HANDLE *phToken = data;
898 if (length != sizeof(HANDLE)) return STATUS_INVALID_PARAMETER;
899 TRACE("Setting ThreadImpersonationToken handle to %p\n", *phToken );
900 SERVER_START_REQ( set_thread_info )
902 req->handle = handle;
903 req->token = *phToken;
904 req->mask = SET_THREAD_INFO_TOKEN;
905 status = wine_server_call( req );
910 case ThreadBasePriority:
912 const DWORD *pprio = data;
913 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
914 SERVER_START_REQ( set_thread_info )
916 req->handle = handle;
917 req->priority = *pprio;
918 req->mask = SET_THREAD_INFO_PRIORITY;
919 status = wine_server_call( req );
924 case ThreadBasicInformation:
927 case ThreadAffinityMask:
928 case ThreadDescriptorTableEntry:
929 case ThreadEnableAlignmentFaultFixup:
930 case ThreadEventPair_Reusable:
931 case ThreadQuerySetWin32StartAddress:
932 case ThreadPerformanceCount:
933 case ThreadAmILastThread:
934 case ThreadIdealProcessor:
935 case ThreadPriorityBoost:
936 case ThreadSetTlsArrayAddress:
937 case ThreadIsIoPending:
939 FIXME( "info class %d not supported yet\n", class );
940 return STATUS_NOT_IMPLEMENTED;
945 /**********************************************************************
946 * NtCurrentTeb (NTDLL.@)
948 #if defined(__i386__) && defined(__GNUC__)
950 __ASM_GLOBAL_FUNC( NtCurrentTeb, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" );
952 #elif defined(__i386__) && defined(_MSC_VER)
954 /* Nothing needs to be done. MS C "magically" exports the inline version from winnt.h */
958 /**********************************************************************/
960 TEB * WINAPI NtCurrentTeb(void)
962 return pthread_functions.get_current_teb();
965 #endif /* __i386__ */