Assorted spelling fixes.
[wine] / dlls / kernel / thread.c
1 /*
2  * Win32 threads
3  *
4  * Copyright 1996 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <fcntl.h>
26 #include <stdarg.h>
27 #include <signal.h>
28 #include <sys/types.h>
29 #ifdef HAVE_SYS_TIMES_H
30 #include <sys/times.h>
31 #endif
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
35
36 #include "ntstatus.h"
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "winnls.h"
41 #include "module.h"
42 #include "thread.h"
43 #include "wine/winbase16.h"
44 #include "wine/exception.h"
45 #include "wine/library.h"
46 #include "wine/pthread.h"
47 #include "wine/server.h"
48 #include "wine/debug.h"
49
50 WINE_DEFAULT_DEBUG_CHANNEL(thread);
51 WINE_DECLARE_DEBUG_CHANNEL(relay);
52
53
54 /***********************************************************************
55  *           THREAD_InitStack
56  *
57  * Allocate the stack of a thread.
58  */
59 TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
60 {
61     DWORD old_prot;
62     DWORD page_size = getpagesize();
63     void *base;
64
65     stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
66     if (stack_size < 1024 * 1024) stack_size = 1024 * 1024;  /* Xlib needs a large stack */
67
68     if (!(base = VirtualAlloc( NULL, stack_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
69         return NULL;
70
71     teb->DeallocationStack = base;
72     teb->Tib.StackBase     = (char *)base + stack_size;
73     teb->Tib.StackLimit    = base;  /* note: limit is lower than base since the stack grows down */
74
75     /* Setup guard pages */
76
77     VirtualProtect( base, 1, PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
78     return teb;
79 }
80
81
82 struct new_thread_info
83 {
84     LPTHREAD_START_ROUTINE func;
85     void                  *arg;
86 };
87
88 /***********************************************************************
89  *           THREAD_Start
90  *
91  * Start execution of a newly created thread. Does not return.
92  */
93 static void CALLBACK THREAD_Start( void *ptr )
94 {
95     struct new_thread_info *info = ptr;
96     LPTHREAD_START_ROUTINE func = info->func;
97     void *arg = info->arg;
98
99     RtlFreeHeap( GetProcessHeap(), 0, info );
100
101     if (TRACE_ON(relay))
102         DPRINTF("%04lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func );
103
104     __TRY
105     {
106         MODULE_DllThreadAttach( NULL );
107         ExitThread( func( arg ) );
108     }
109     __EXCEPT(UnhandledExceptionFilter)
110     {
111         TerminateThread( GetCurrentThread(), GetExceptionCode() );
112     }
113     __ENDTRY
114 }
115
116
117 /***********************************************************************
118  *           CreateThread   (KERNEL32.@)
119  */
120 HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, SIZE_T stack,
121                             LPTHREAD_START_ROUTINE start, LPVOID param,
122                             DWORD flags, LPDWORD id )
123 {
124      return CreateRemoteThread( GetCurrentProcess(),
125                                 sa, stack, start, param, flags, id );
126 }
127
128
129 /***************************************************************************
130  *                  CreateRemoteThread   (KERNEL32.@)
131  *
132  * Creates a thread that runs in the address space of another process
133  *
134  * PARAMS
135  *
136  * RETURNS
137  *   Success: Handle to the new thread.
138  *   Failure: NULL. Use GetLastError() to find the error cause.
139  *
140  * BUGS
141  *   Improper memory allocation: there's no ability to free new_thread_info
142  *   in other process.
143  *   Bad start address for RtlCreateUserThread because the library
144  *   may be loaded at different address in other process.
145  */
146 HANDLE WINAPI CreateRemoteThread( HANDLE hProcess, SECURITY_ATTRIBUTES *sa, SIZE_T stack,
147                                   LPTHREAD_START_ROUTINE start, LPVOID param,
148                                   DWORD flags, LPDWORD id )
149 {
150     HANDLE handle;
151     CLIENT_ID client_id;
152     NTSTATUS status;
153     SIZE_T stack_reserve = 0, stack_commit = 0;
154     struct new_thread_info *info;
155
156     if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) )))
157     {
158         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
159         return 0;
160     }
161     info->func = start;
162     info->arg  = param;
163
164     if (flags & STACK_SIZE_PARAM_IS_A_RESERVATION) stack_reserve = stack;
165     else stack_commit = stack;
166
167     status = RtlCreateUserThread( hProcess, NULL, (flags & CREATE_SUSPENDED) != 0,
168                                   NULL, stack_reserve, stack_commit,
169                                   THREAD_Start, info, &handle, &client_id );
170     if (status == STATUS_SUCCESS)
171     {
172         if (id) *id = (DWORD)client_id.UniqueThread;
173         if (sa && (sa->nLength >= sizeof(*sa)) && sa->bInheritHandle)
174             SetHandleInformation( handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT );
175     }
176     else
177     {
178         RtlFreeHeap( GetProcessHeap(), 0, info );
179         SetLastError( RtlNtStatusToDosError(status) );
180         handle = 0;
181     }
182     return handle;
183 }
184
185
186 /***********************************************************************
187  * OpenThread  [KERNEL32.@]   Retrieves a handle to a thread from its thread id
188  */
189 HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId )
190 {
191     HANDLE ret = 0;
192     SERVER_START_REQ( open_thread )
193     {
194         req->tid     = dwThreadId;
195         req->access  = dwDesiredAccess;
196         req->inherit = bInheritHandle;
197         if (!wine_server_call_err( req )) ret = reply->handle;
198     }
199     SERVER_END_REQ;
200     return ret;
201 }
202
203
204 /***********************************************************************
205  * ExitThread [KERNEL32.@]  Ends a thread
206  *
207  * RETURNS
208  *    None
209  */
210 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
211 {
212     BOOL last;
213     SERVER_START_REQ( terminate_thread )
214     {
215         /* send the exit code to the server */
216         req->handle    = GetCurrentThread();
217         req->exit_code = code;
218         wine_server_call( req );
219         last = reply->last;
220     }
221     SERVER_END_REQ;
222
223     if (last)
224     {
225         LdrShutdownProcess();
226         exit( code );
227     }
228     else
229     {
230         struct wine_pthread_thread_info info;
231         sigset_t block_set;
232         ULONG size;
233
234         LdrShutdownThread();
235         RtlAcquirePebLock();
236         RemoveEntryList( &NtCurrentTeb()->TlsLinks );
237         RtlReleasePebLock();
238
239         info.stack_base  = NtCurrentTeb()->DeallocationStack;
240         info.teb_base    = NtCurrentTeb();
241         info.teb_sel     = wine_get_fs();
242         info.exit_status = code;
243
244         size = 0;
245         NtFreeVirtualMemory( GetCurrentProcess(), &info.stack_base, &size, MEM_RELEASE | MEM_SYSTEM );
246         info.stack_size = size;
247
248         size = 0;
249         NtFreeVirtualMemory( GetCurrentProcess(), &info.teb_base, &size, MEM_RELEASE | MEM_SYSTEM );
250         info.teb_size = size;
251
252         /* block the async signals */
253         sigemptyset( &block_set );
254         sigaddset( &block_set, SIGALRM );
255         sigaddset( &block_set, SIGIO );
256         sigaddset( &block_set, SIGINT );
257         sigaddset( &block_set, SIGHUP );
258         sigaddset( &block_set, SIGUSR1 );
259         sigaddset( &block_set, SIGUSR2 );
260         sigaddset( &block_set, SIGTERM );
261         sigprocmask( SIG_BLOCK, &block_set, NULL );
262
263         close( NtCurrentTeb()->wait_fd[0] );
264         close( NtCurrentTeb()->wait_fd[1] );
265         close( NtCurrentTeb()->reply_fd );
266         close( NtCurrentTeb()->request_fd );
267
268         wine_pthread_exit_thread( &info );
269     }
270 }
271
272
273 /**********************************************************************
274  * TerminateThread [KERNEL32.@]  Terminates a thread
275  *
276  * RETURNS
277  *    Success: TRUE
278  *    Failure: FALSE
279  */
280 BOOL WINAPI TerminateThread( HANDLE handle,    /* [in] Handle to thread */
281                              DWORD exit_code)  /* [in] Exit code for thread */
282 {
283     NTSTATUS status = NtTerminateThread( handle, exit_code );
284     if (status) SetLastError( RtlNtStatusToDosError(status) );
285     return !status;
286 }
287
288
289 /***********************************************************************
290  *           FreeLibraryAndExitThread (KERNEL32.@)
291  */
292 void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
293 {
294     FreeLibrary(hLibModule);
295     ExitThread(dwExitCode);
296 }
297
298
299 /**********************************************************************
300  *              GetExitCodeThread (KERNEL32.@)
301  *
302  * Gets termination status of thread.
303  *
304  * RETURNS
305  *    Success: TRUE
306  *    Failure: FALSE
307  */
308 BOOL WINAPI GetExitCodeThread(
309     HANDLE hthread, /* [in]  Handle to thread */
310     LPDWORD exitcode) /* [out] Address to receive termination status */
311 {
312     THREAD_BASIC_INFORMATION info;
313     NTSTATUS status = NtQueryInformationThread( hthread, ThreadBasicInformation,
314                                                 &info, sizeof(info), NULL );
315
316     if (status)
317     {
318         SetLastError( RtlNtStatusToDosError(status) );
319         return FALSE;
320     }
321     if (exitcode) *exitcode = info.ExitStatus;
322     return TRUE;
323 }
324
325
326 /***********************************************************************
327  * SetThreadContext [KERNEL32.@]  Sets context of thread.
328  *
329  * RETURNS
330  *    Success: TRUE
331  *    Failure: FALSE
332  */
333 BOOL WINAPI SetThreadContext( HANDLE handle,           /* [in]  Handle to thread with context */
334                               const CONTEXT *context ) /* [in] Address of context structure */
335 {
336     NTSTATUS status = NtSetContextThread( handle, context );
337     if (status) SetLastError( RtlNtStatusToDosError(status) );
338     return !status;
339 }
340
341
342 /***********************************************************************
343  * GetThreadContext [KERNEL32.@]  Retrieves context of thread.
344  *
345  * RETURNS
346  *    Success: TRUE
347  *    Failure: FALSE
348  */
349 BOOL WINAPI GetThreadContext( HANDLE handle,     /* [in]  Handle to thread with context */
350                               CONTEXT *context ) /* [out] Address of context structure */
351 {
352     NTSTATUS status = NtGetContextThread( handle, context );
353     if (status) SetLastError( RtlNtStatusToDosError(status) );
354     return !status;
355 }
356
357
358 /**********************************************************************
359  * SuspendThread [KERNEL32.@]  Suspends a thread.
360  *
361  * RETURNS
362  *    Success: Previous suspend count
363  *    Failure: 0xFFFFFFFF
364  */
365 DWORD WINAPI SuspendThread( HANDLE hthread ) /* [in] Handle to the thread */
366 {
367     DWORD ret;
368     NTSTATUS status = NtSuspendThread( hthread, &ret );
369
370     if (status)
371     {
372         ret = ~0U;
373         SetLastError( RtlNtStatusToDosError(status) );
374     }
375     return ret;
376 }
377
378
379 /**********************************************************************
380  * ResumeThread [KERNEL32.@]  Resumes a thread.
381  *
382  * Decrements a thread's suspend count.  When count is zero, the
383  * execution of the thread is resumed.
384  *
385  * RETURNS
386  *    Success: Previous suspend count
387  *    Failure: 0xFFFFFFFF
388  *    Already running: 0
389  */
390 DWORD WINAPI ResumeThread( HANDLE hthread ) /* [in] Identifies thread to restart */
391 {
392     DWORD ret;
393     NTSTATUS status = NtResumeThread( hthread, &ret );
394
395     if (status)
396     {
397         ret = ~0U;
398         SetLastError( RtlNtStatusToDosError(status) );
399     }
400     return ret;
401 }
402
403
404 /**********************************************************************
405  * GetThreadPriority [KERNEL32.@]  Returns priority for thread.
406  *
407  * RETURNS
408  *    Success: Thread's priority level.
409  *    Failure: THREAD_PRIORITY_ERROR_RETURN
410  */
411 INT WINAPI GetThreadPriority(
412     HANDLE hthread) /* [in] Handle to thread */
413 {
414     THREAD_BASIC_INFORMATION info;
415     NTSTATUS status = NtQueryInformationThread( hthread, ThreadBasicInformation,
416                                                 &info, sizeof(info), NULL );
417
418     if (status)
419     {
420         SetLastError( RtlNtStatusToDosError(status) );
421         return THREAD_PRIORITY_ERROR_RETURN;
422     }
423     return info.Priority;
424 }
425
426
427 /**********************************************************************
428  * SetThreadPriority [KERNEL32.@]  Sets priority for thread.
429  *
430  * RETURNS
431  *    Success: TRUE
432  *    Failure: FALSE
433  */
434 BOOL WINAPI SetThreadPriority(
435     HANDLE hthread, /* [in] Handle to thread */
436     INT priority)   /* [in] Thread priority level */
437 {
438     BOOL ret;
439     SERVER_START_REQ( set_thread_info )
440     {
441         req->handle   = hthread;
442         req->priority = priority;
443         req->mask     = SET_THREAD_INFO_PRIORITY;
444         ret = !wine_server_call_err( req );
445     }
446     SERVER_END_REQ;
447     return ret;
448 }
449
450
451 /**********************************************************************
452  * GetThreadPriorityBoost [KERNEL32.@]  Returns priority boost for thread.
453  *
454  * Always reports that priority boost is disabled.
455  *
456  * RETURNS
457  *    Success: TRUE.
458  *    Failure: FALSE
459  */
460 BOOL WINAPI GetThreadPriorityBoost(
461     HANDLE hthread, /* [in] Handle to thread */
462     PBOOL pstate)   /* [out] pointer to var that receives the boost state */
463 {
464     if (pstate) *pstate = FALSE;
465     return NO_ERROR;
466 }
467
468
469 /**********************************************************************
470  * SetThreadPriorityBoost [KERNEL32.@]  Sets priority boost for thread.
471  *
472  * Priority boost is not implemented. Thsi function always returns
473  * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
474  *
475  * RETURNS
476  *    Always returns FALSE to indicate a failure
477  */
478 BOOL WINAPI SetThreadPriorityBoost(
479     HANDLE hthread, /* [in] Handle to thread */
480     BOOL disable)   /* [in] TRUE to disable priority boost */
481 {
482     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
483     return FALSE;
484 }
485
486
487 /**********************************************************************
488  *           SetThreadAffinityMask   (KERNEL32.@)
489  */
490 DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
491 {
492     DWORD ret;
493     SERVER_START_REQ( set_thread_info )
494     {
495         req->handle   = hThread;
496         req->affinity = dwThreadAffinityMask;
497         req->mask     = SET_THREAD_INFO_AFFINITY;
498         ret = !wine_server_call_err( req );
499         /* FIXME: should return previous value */
500     }
501     SERVER_END_REQ;
502     return ret;
503 }
504
505
506 /**********************************************************************
507  * SetThreadIdealProcessor [KERNEL32.@]  Obtains timing information.
508  *
509  * RETURNS
510  *    Success: Value of last call to SetThreadIdealProcessor
511  *    Failure: -1
512  */
513 DWORD WINAPI SetThreadIdealProcessor(
514     HANDLE hThread,          /* [in] Specifies the thread of interest */
515     DWORD dwIdealProcessor)  /* [in] Specifies the new preferred processor */
516 {
517     FIXME("(%p): stub\n",hThread);
518     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
519     return -1L;
520 }
521
522
523 /* callback for QueueUserAPC */
524 static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
525 {
526     PAPCFUNC func = (PAPCFUNC)arg1;
527     func( arg2 );
528 }
529
530 /***********************************************************************
531  *              QueueUserAPC  (KERNEL32.@)
532  */
533 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
534 {
535     NTSTATUS status = NtQueueApcThread( hthread, call_user_apc, (ULONG_PTR)func, data, 0 );
536
537     if (status) SetLastError( RtlNtStatusToDosError(status) );
538     return !status;
539 }
540
541
542 /**********************************************************************
543  * GetThreadTimes [KERNEL32.@]  Obtains timing information.
544  *
545  * RETURNS
546  *    Success: TRUE
547  *    Failure: FALSE
548  */
549 BOOL WINAPI GetThreadTimes(
550     HANDLE thread,         /* [in]  Specifies the thread of interest */
551     LPFILETIME creationtime, /* [out] When the thread was created */
552     LPFILETIME exittime,     /* [out] When the thread was destroyed */
553     LPFILETIME kerneltime,   /* [out] Time thread spent in kernel mode */
554     LPFILETIME usertime)     /* [out] Time thread spent in user mode */
555 {
556     BOOL ret = TRUE;
557
558     if (creationtime || exittime)
559     {
560         /* We need to do a server call to get the creation time or exit time */
561         /* This works on any thread */
562
563         SERVER_START_REQ( get_thread_info )
564         {
565             req->handle = thread;
566             req->tid_in = 0;
567             if ((ret = !wine_server_call_err( req )))
568             {
569                 if (creationtime)
570                     RtlSecondsSince1970ToTime( reply->creation_time, (LARGE_INTEGER*)creationtime );
571                 if (exittime)
572                     RtlSecondsSince1970ToTime( reply->exit_time, (LARGE_INTEGER*)exittime );
573             }
574         }
575         SERVER_END_REQ;
576     }
577     if (ret && (kerneltime || usertime))
578     {
579         /* We call times(2) for kernel time or user time */
580         /* We can only (portably) do this for the current thread */
581         if (thread == GetCurrentThread())
582         {
583             ULONGLONG time;
584             struct tms time_buf;
585             long clocks_per_sec = sysconf(_SC_CLK_TCK);
586
587             times(&time_buf);
588             if (kerneltime)
589             {
590                 time = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
591                 kerneltime->dwHighDateTime = time >> 32;
592                 kerneltime->dwLowDateTime = (DWORD)time;
593             }
594             if (usertime)
595             {
596                 time = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
597                 usertime->dwHighDateTime = time >> 32;
598                 usertime->dwLowDateTime = (DWORD)time;
599             }
600         }
601         else
602         {
603             if (kerneltime) kerneltime->dwHighDateTime = kerneltime->dwLowDateTime = 0;
604             if (usertime) usertime->dwHighDateTime = usertime->dwLowDateTime = 0;
605             FIXME("Cannot get kerneltime or usertime of other threads\n");
606         }
607     }
608     return ret;
609 }
610
611
612 /**********************************************************************
613  * VWin32_BoostThreadGroup [KERNEL.535]
614  */
615 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
616 {
617     FIXME("(0x%08lx,%d): stub\n", threadId, boost);
618 }
619
620
621 /**********************************************************************
622  * VWin32_BoostThreadStatic [KERNEL.536]
623  */
624 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
625 {
626     FIXME("(0x%08lx,%d): stub\n", threadId, boost);
627 }
628
629
630 /***********************************************************************
631  * GetCurrentThread [KERNEL32.@]  Gets pseudohandle for current thread
632  *
633  * RETURNS
634  *    Pseudohandle for the current thread
635  */
636 #undef GetCurrentThread
637 HANDLE WINAPI GetCurrentThread(void)
638 {
639     return (HANDLE)0xfffffffe;
640 }
641
642
643 #ifdef __i386__
644
645 /***********************************************************************
646  *              SetLastError (KERNEL.147)
647  *              SetLastError (KERNEL32.@)
648  */
649 /* void WINAPI SetLastError( DWORD error ); */
650 __ASM_GLOBAL_FUNC( SetLastError,
651                    "movl 4(%esp),%eax\n\t"
652                    ".byte 0x64\n\t"
653                    "movl %eax,0x34\n\t"
654                    "ret $4" )
655
656 /***********************************************************************
657  *              GetLastError (KERNEL.148)
658  *              GetLastError (KERNEL32.@)
659  */
660 /* DWORD WINAPI GetLastError(void); */
661 __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x34,%eax\n\tret" )
662
663 /***********************************************************************
664  *              GetCurrentProcessId (KERNEL.471)
665  *              GetCurrentProcessId (KERNEL32.@)
666  */
667 /* DWORD WINAPI GetCurrentProcessId(void) */
668 __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" )
669
670 /***********************************************************************
671  *              GetCurrentThreadId (KERNEL.462)
672  *              GetCurrentThreadId (KERNEL32.@)
673  */
674 /* DWORD WINAPI GetCurrentThreadId(void) */
675 __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" )
676
677 #else  /* __i386__ */
678
679 /**********************************************************************
680  *              SetLastError (KERNEL.147)
681  *              SetLastError (KERNEL32.@)
682  *
683  * Sets the last-error code.
684  */
685 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
686 {
687     NtCurrentTeb()->LastErrorValue = error;
688 }
689
690 /**********************************************************************
691  *              GetLastError (KERNEL.148)
692  *              GetLastError (KERNEL32.@)
693  *
694  * Returns last-error code.
695  */
696 DWORD WINAPI GetLastError(void)
697 {
698     return NtCurrentTeb()->LastErrorValue;
699 }
700
701 /***********************************************************************
702  *              GetCurrentProcessId (KERNEL.471)
703  *              GetCurrentProcessId (KERNEL32.@)
704  *
705  * Returns process identifier.
706  */
707 DWORD WINAPI GetCurrentProcessId(void)
708 {
709     return (DWORD)NtCurrentTeb()->ClientId.UniqueProcess;
710 }
711
712 /***********************************************************************
713  *              GetCurrentThreadId (KERNEL.462)
714  *              GetCurrentThreadId (KERNEL32.@)
715  *
716  * Returns thread identifier.
717  */
718 DWORD WINAPI GetCurrentThreadId(void)
719 {
720     return (DWORD)NtCurrentTeb()->ClientId.UniqueThread;
721 }
722
723 #endif  /* __i386__ */