4 * Copyright 1996 Alexandre Julliard
11 #include <sys/types.h>
12 #ifdef HAVE_SYS_MMAN_H
16 #include "wine/winbase16.h"
24 #include "selectors.h"
28 #include "stackframe.h"
29 #include "builtin16.h"
30 #include "debugtools.h"
33 DEFAULT_DEBUG_CHANNEL(thread
);
35 /* TEB of the initial thread */
36 static TEB initial_teb
;
38 /***********************************************************************
41 BOOL
THREAD_IsWin16( TEB
*teb
)
43 return !teb
|| !(teb
->tibflags
& TEBF_WIN32
);
46 /***********************************************************************
49 * Convert a thread id to a TEB, making sure it is valid.
51 TEB
*THREAD_IdToTEB( DWORD id
)
55 if (!id
|| id
== GetCurrentThreadId()) return NtCurrentTeb();
59 struct get_thread_info_request
*req
= server_alloc_req( sizeof(*req
), 0 );
61 req
->tid_in
= (void *)id
;
62 if (!server_call_noerr( REQ_GET_THREAD_INFO
)) ret
= req
->teb
;
68 /* Allow task handles to be used; convert to main thread */
71 TDB
*pTask
= (TDB
*)GlobalLock16( id
);
72 if (pTask
) return pTask
->teb
;
74 SetLastError( ERROR_INVALID_PARAMETER
);
80 /***********************************************************************
83 * Initialization of a newly created TEB.
85 static BOOL
THREAD_InitTEB( TEB
*teb
)
87 teb
->except
= (void *)~0UL;
89 teb
->tibflags
= TEBF_WIN32
;
90 teb
->tls_ptr
= teb
->tls_array
;
91 teb
->exit_code
= STILL_ACTIVE
;
93 teb
->stack_top
= (void *)~0UL;
94 teb
->StaticUnicodeString
.MaximumLength
= sizeof(teb
->StaticUnicodeBuffer
);
95 teb
->StaticUnicodeString
.Buffer
= (PWSTR
)teb
->StaticUnicodeBuffer
;
96 teb
->teb_sel
= SELECTOR_AllocBlock( teb
, 0x1000, SEGMENT_DATA
, TRUE
, FALSE
);
97 return (teb
->teb_sel
!= 0);
101 /***********************************************************************
104 * Free data structures associated with a thread.
105 * Must be called from the context of another thread.
107 static void CALLBACK
THREAD_FreeTEB( TEB
*teb
)
109 TRACE("(%p) called\n", teb
);
110 if (teb
->cleanup
) SERVICE_Delete( teb
->cleanup
);
112 /* Free the associated memory */
114 if (teb
->socket
!= -1) close( teb
->socket
);
115 if (teb
->stack_sel
) SELECTOR_FreeBlock( teb
->stack_sel
, 1 );
116 SELECTOR_FreeBlock( teb
->teb_sel
, 1 );
117 if (teb
->buffer
) munmap( (void *)teb
->buffer
,
118 (char *)(teb
->buffer_info
+1) - (char *)teb
->buffer
);
119 if (teb
->debug_info
) HeapFree( GetProcessHeap(), 0, teb
->debug_info
);
120 VirtualFree( teb
->stack_base
, 0, MEM_RELEASE
);
124 /***********************************************************************
127 * Allocate the stack of a thread.
129 TEB
*THREAD_InitStack( TEB
*teb
, DWORD stack_size
, BOOL alloc_stack16
)
131 DWORD old_prot
, total_size
;
132 DWORD page_size
= VIRTUAL_GetPageSize();
135 /* Allocate the stack */
137 if (stack_size
>= 16*1024*1024)
138 WARN("Thread stack size is %ld MB.\n",stack_size
/1024/1024);
140 /* if size is smaller than default, get stack size from parent */
141 if (stack_size
< 1024 * 1024)
144 stack_size
= 1024 * 1024; /* no parent */
146 stack_size
= ((char *)NtCurrentTeb()->stack_top
- (char *)NtCurrentTeb()->stack_base
147 - SIGNAL_STACK_SIZE
- 3 * page_size
);
150 /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */
151 stack_size
+= 64 * 1024;
153 /* Memory layout in allocated block:
156 * 1 page NOACCESS guard page
157 * SIGNAL_STACK_SIZE signal stack
158 * 1 page NOACCESS guard page
159 * 1 page PAGE_GUARD guard page
160 * stack_size normal stack
161 * 64Kb 16-bit stack (optional)
162 * 1 page TEB (except for initial thread)
165 stack_size
= (stack_size
+ (page_size
- 1)) & ~(page_size
- 1);
166 total_size
= stack_size
+ SIGNAL_STACK_SIZE
+ 3 * page_size
;
167 if (alloc_stack16
) total_size
+= 0x10000;
168 if (!teb
) total_size
+= page_size
;
170 if (!(base
= VirtualAlloc( NULL
, total_size
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
)))
175 teb
= (TEB
*)((char *)base
+ total_size
- page_size
);
176 if (!THREAD_InitTEB( teb
))
178 VirtualFree( base
, 0, MEM_RELEASE
);
183 teb
->stack_low
= base
;
184 teb
->stack_base
= base
;
185 teb
->signal_stack
= (char *)base
+ page_size
;
186 teb
->stack_top
= (char *)base
+ 3 * page_size
+ SIGNAL_STACK_SIZE
+ stack_size
;
188 /* Setup guard pages */
190 VirtualProtect( base
, 1, PAGE_NOACCESS
, &old_prot
);
191 VirtualProtect( (char *)teb
->signal_stack
+ SIGNAL_STACK_SIZE
, 1, PAGE_NOACCESS
, &old_prot
);
192 VirtualProtect( (char *)teb
->signal_stack
+ SIGNAL_STACK_SIZE
+ page_size
, 1,
193 PAGE_EXECUTE_READWRITE
| PAGE_GUARD
, &old_prot
);
195 /* Allocate the 16-bit stack selector */
199 teb
->stack_sel
= SELECTOR_AllocBlock( teb
->stack_top
, 0x10000, SEGMENT_DATA
,
201 if (!teb
->stack_sel
) goto error
;
202 teb
->cur_stack
= PTR_SEG_OFF_TO_SEGPTR( teb
->stack_sel
,
203 0x10000 - sizeof(STACK16FRAME
) );
208 THREAD_FreeTEB( teb
);
213 /***********************************************************************
216 * Setup the initial thread.
218 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
220 void THREAD_Init(void)
222 if (!initial_teb
.self
) /* do it only once */
224 THREAD_InitTEB( &initial_teb
);
225 assert( initial_teb
.teb_sel
);
226 initial_teb
.process
= ¤t_process
;
227 SYSDEPS_SetCurThread( &initial_teb
);
231 DECL_GLOBAL_CONSTRUCTOR(thread_init
) { THREAD_Init(); }
233 /***********************************************************************
237 TEB
*THREAD_Create( int fd
, DWORD stack_size
, BOOL alloc_stack16
)
241 if ((teb
= THREAD_InitStack( NULL
, stack_size
, alloc_stack16
)))
243 teb
->tibflags
= (current_process
.flags
& PDB32_WIN16_PROC
) ? 0 : TEBF_WIN32
;
244 teb
->process
= ¤t_process
;
246 fcntl( fd
, F_SETFD
, 1 ); /* set close on exec flag */
247 TRACE("(%p) succeeded\n", teb
);
253 /***********************************************************************
256 * Start execution of a newly created thread. Does not return.
258 static void THREAD_Start(void)
260 HANDLE cleanup_object
;
261 LPTHREAD_START_ROUTINE func
= (LPTHREAD_START_ROUTINE
)NtCurrentTeb()->entry_point
;
263 /* install cleanup handler */
264 if (DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
265 GetCurrentProcess(), &cleanup_object
,
266 0, FALSE
, DUPLICATE_SAME_ACCESS
))
267 NtCurrentTeb()->cleanup
= SERVICE_AddObject( cleanup_object
, (PAPCFUNC
)THREAD_FreeTEB
,
268 (ULONG_PTR
)NtCurrentTeb() );
270 PROCESS_CallUserSignalProc( USIG_THREAD_INIT
, 0 );
272 MODULE_DllThreadAttach( NULL
);
273 ExitThread( func( NtCurrentTeb()->entry_arg
) );
277 /***********************************************************************
278 * CreateThread (KERNEL32.63)
280 HANDLE WINAPI
CreateThread( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
281 LPTHREAD_START_ROUTINE start
, LPVOID param
,
282 DWORD flags
, LPDWORD id
)
284 int socket
, handle
= -1;
290 struct new_thread_request
*req
= server_alloc_req( sizeof(*req
), 0 );
292 req
->suspend
= ((flags
& CREATE_SUSPENDED
) != 0);
293 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
294 if (!server_call_fd( REQ_NEW_THREAD
, -1, &socket
))
296 handle
= req
->handle
;
301 if (handle
== -1) return 0;
303 if (!(teb
= THREAD_Create( socket
, stack
, TRUE
)))
308 teb
->tibflags
|= TEBF_WIN32
;
309 teb
->entry_point
= start
;
310 teb
->entry_arg
= param
;
311 teb
->startup
= THREAD_Start
;
312 teb
->htask16
= GetCurrentTask();
313 if (id
) *id
= (DWORD
)tid
;
314 if (SYSDEPS_SpawnThread( teb
) == -1)
316 CloseHandle( handle
);
317 THREAD_FreeTEB( teb
);
323 /***********************************************************************
324 * CreateThread16 (KERNEL.441)
326 static DWORD CALLBACK
THREAD_StartThread16( LPVOID threadArgs
)
328 FARPROC16 start
= ((FARPROC16
*)threadArgs
)[0];
329 DWORD param
= ((DWORD
*)threadArgs
)[1];
330 HeapFree( GetProcessHeap(), 0, threadArgs
);
332 ((LPDWORD
)CURRENT_STACK16
)[-1] = param
;
333 return CallTo16Long( start
, sizeof(DWORD
) );
335 HANDLE WINAPI
CreateThread16( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
336 FARPROC16 start
, SEGPTR param
,
337 DWORD flags
, LPDWORD id
)
339 DWORD
*threadArgs
= HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD
) );
340 if (!threadArgs
) return INVALID_HANDLE_VALUE
;
341 threadArgs
[0] = (DWORD
)start
;
342 threadArgs
[1] = (DWORD
)param
;
344 return CreateThread( sa
, stack
, THREAD_StartThread16
, threadArgs
, flags
, id
);
348 /***********************************************************************
349 * ExitThread [KERNEL32.215] Ends a thread
354 void WINAPI
ExitThread( DWORD code
) /* [in] Exit code for this thread */
359 struct terminate_thread_request
*req
= server_alloc_req( sizeof(*req
), 0 );
361 /* send the exit code to the server */
362 req
->handle
= GetCurrentThread();
363 req
->exit_code
= code
;
364 server_call( REQ_TERMINATE_THREAD
);
371 MODULE_DllProcessDetach( TRUE
, (LPVOID
)1 );
376 MODULE_DllThreadDetach( NULL
);
377 if (!(NtCurrentTeb()->tibflags
& TEBF_WIN32
)) TASK_KillTask( 0 );
378 SYSDEPS_ExitThread( code
);
383 /**********************************************************************
384 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
386 * Allocates a thread local storage index
390 * Failure: 0xFFFFFFFF
392 DWORD WINAPI
TlsAlloc( void )
394 DWORD i
, mask
, ret
= 0;
395 DWORD
*bits
= current_process
.tls_bits
;
396 EnterCriticalSection( ¤t_process
.crit_section
);
397 if (*bits
== 0xffffffff)
401 if (*bits
== 0xffffffff)
403 LeaveCriticalSection( ¤t_process
.crit_section
);
404 SetLastError( ERROR_NO_MORE_ITEMS
);
408 for (i
= 0, mask
= 1; i
< 32; i
++, mask
<<= 1) if (!(*bits
& mask
)) break;
410 LeaveCriticalSection( ¤t_process
.crit_section
);
415 /**********************************************************************
416 * TlsFree [KERNEL32.531] Releases a TLS index.
418 * Releases a thread local storage index, making it available for reuse
425 DWORD index
) /* [in] TLS Index to free */
428 DWORD
*bits
= current_process
.tls_bits
;
431 SetLastError( ERROR_INVALID_PARAMETER
);
434 EnterCriticalSection( ¤t_process
.crit_section
);
435 if (index
>= 32) bits
++;
436 mask
= (1 << (index
& 31));
437 if (!(*bits
& mask
)) /* already free? */
439 LeaveCriticalSection( ¤t_process
.crit_section
);
440 SetLastError( ERROR_INVALID_PARAMETER
);
444 NtCurrentTeb()->tls_array
[index
] = 0;
445 /* FIXME: should zero all other thread values */
446 LeaveCriticalSection( ¤t_process
.crit_section
);
451 /**********************************************************************
452 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
455 * Success: Value stored in calling thread's TLS slot for index
456 * Failure: 0 and GetLastError returns NO_ERROR
458 LPVOID WINAPI
TlsGetValue(
459 DWORD index
) /* [in] TLS index to retrieve value for */
463 SetLastError( ERROR_INVALID_PARAMETER
);
466 SetLastError( ERROR_SUCCESS
);
467 return NtCurrentTeb()->tls_array
[index
];
471 /**********************************************************************
472 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
478 BOOL WINAPI
TlsSetValue(
479 DWORD index
, /* [in] TLS index to set value for */
480 LPVOID value
) /* [in] Value to be stored */
484 SetLastError( ERROR_INVALID_PARAMETER
);
487 NtCurrentTeb()->tls_array
[index
] = value
;
492 /***********************************************************************
493 * SetThreadContext [KERNEL32.670] Sets context of thread.
499 BOOL WINAPI
SetThreadContext( HANDLE handle
, /* [in] Handle to thread with context */
500 const CONTEXT
*context
) /* [in] Address of context structure */
505 struct set_thread_context_request
*req
= server_alloc_req( sizeof(*req
),
507 req
->handle
= handle
;
508 req
->flags
= context
->ContextFlags
;
509 memcpy( server_data_ptr(req
), context
, sizeof(*context
) );
510 ret
= !server_call( REQ_SET_THREAD_CONTEXT
);
517 /***********************************************************************
518 * GetThreadContext [KERNEL32.294] Retrieves context of thread.
524 BOOL WINAPI
GetThreadContext( HANDLE handle
, /* [in] Handle to thread with context */
525 CONTEXT
*context
) /* [out] Address of context structure */
530 struct get_thread_context_request
*req
= server_alloc_req( sizeof(*req
),
532 req
->handle
= handle
;
533 req
->flags
= context
->ContextFlags
;
534 memcpy( server_data_ptr(req
), context
, sizeof(*context
) );
535 if ((ret
= !server_call( REQ_GET_THREAD_CONTEXT
)))
536 memcpy( context
, server_data_ptr(req
), sizeof(*context
) );
543 /**********************************************************************
544 * GetThreadPriority [KERNEL32.296] Returns priority for thread.
547 * Success: Thread's priority level.
548 * Failure: THREAD_PRIORITY_ERROR_RETURN
550 INT WINAPI
GetThreadPriority(
551 HANDLE hthread
) /* [in] Handle to thread */
553 INT ret
= THREAD_PRIORITY_ERROR_RETURN
;
556 struct get_thread_info_request
*req
= server_alloc_req( sizeof(*req
), 0 );
557 req
->handle
= hthread
;
559 if (!server_call( REQ_GET_THREAD_INFO
)) ret
= req
->priority
;
566 /**********************************************************************
567 * SetThreadPriority [KERNEL32.514] Sets priority for thread.
573 BOOL WINAPI
SetThreadPriority(
574 HANDLE hthread
, /* [in] Handle to thread */
575 INT priority
) /* [in] Thread priority level */
580 struct set_thread_info_request
*req
= server_alloc_req( sizeof(*req
), 0 );
581 req
->handle
= hthread
;
582 req
->priority
= priority
;
583 req
->mask
= SET_THREAD_INFO_PRIORITY
;
584 ret
= !server_call( REQ_SET_THREAD_INFO
);
591 /**********************************************************************
592 * GetThreadPriorityBoost [KERNEL32.877] Returns priority boost for thread.
594 * Always reports that priority boost is disabled.
600 BOOL WINAPI
GetThreadPriorityBoost(
601 HANDLE hthread
, /* [in] Handle to thread */
602 PBOOL pstate
) /* [out] pointer to var that receives the boost state */
604 if (pstate
) *pstate
= FALSE
;
609 /**********************************************************************
610 * SetThreadPriorityBoost [KERNEL32.893] Sets priority boost for thread.
612 * Priority boost is not implemented. Thsi function always returns
613 * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
616 * Always returns FALSE to indicate a failure
618 BOOL WINAPI
SetThreadPriorityBoost(
619 HANDLE hthread
, /* [in] Handle to thread */
620 BOOL disable
) /* [in] TRUE to disable priority boost */
622 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
627 /**********************************************************************
628 * SetThreadAffinityMask (KERNEL32.669)
630 DWORD WINAPI
SetThreadAffinityMask( HANDLE hThread
, DWORD dwThreadAffinityMask
)
635 struct set_thread_info_request
*req
= server_alloc_req( sizeof(*req
), 0 );
636 req
->handle
= hThread
;
637 req
->affinity
= dwThreadAffinityMask
;
638 req
->mask
= SET_THREAD_INFO_AFFINITY
;
639 ret
= !server_call( REQ_SET_THREAD_INFO
);
640 /* FIXME: should return previous value */
647 /**********************************************************************
648 * TerminateThread [KERNEL32.685] Terminates a thread
654 BOOL WINAPI
TerminateThread( HANDLE handle
, /* [in] Handle to thread */
655 DWORD exit_code
) /* [in] Exit code for thread */
657 NTSTATUS status
= NtTerminateThread( handle
, exit_code
);
658 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
663 /**********************************************************************
664 * GetExitCodeThread [KERNEL32.???] Gets termination status of thread.
670 BOOL WINAPI
GetExitCodeThread(
671 HANDLE hthread
, /* [in] Handle to thread */
672 LPDWORD exitcode
) /* [out] Address to receive termination status */
677 struct get_thread_info_request
*req
= server_alloc_req( sizeof(*req
), 0 );
678 req
->handle
= hthread
;
680 ret
= !server_call( REQ_GET_THREAD_INFO
);
681 if (ret
&& exitcode
) *exitcode
= req
->exit_code
;
688 /**********************************************************************
689 * ResumeThread [KERNEL32.587] Resumes a thread.
691 * Decrements a thread's suspend count. When count is zero, the
692 * execution of the thread is resumed.
695 * Success: Previous suspend count
696 * Failure: 0xFFFFFFFF
699 DWORD WINAPI
ResumeThread(
700 HANDLE hthread
) /* [in] Identifies thread to restart */
702 DWORD ret
= 0xffffffff;
705 struct resume_thread_request
*req
= server_alloc_req( sizeof(*req
), 0 );
706 req
->handle
= hthread
;
707 if (!server_call( REQ_RESUME_THREAD
)) ret
= req
->count
;
714 /**********************************************************************
715 * SuspendThread [KERNEL32.681] Suspends a thread.
718 * Success: Previous suspend count
719 * Failure: 0xFFFFFFFF
721 DWORD WINAPI
SuspendThread(
722 HANDLE hthread
) /* [in] Handle to the thread */
724 DWORD ret
= 0xffffffff;
727 struct suspend_thread_request
*req
= server_alloc_req( sizeof(*req
), 0 );
728 req
->handle
= hthread
;
729 if (!server_call( REQ_SUSPEND_THREAD
)) ret
= req
->count
;
736 /***********************************************************************
737 * QueueUserAPC (KERNEL32.566)
739 DWORD WINAPI
QueueUserAPC( PAPCFUNC func
, HANDLE hthread
, ULONG_PTR data
)
744 struct queue_apc_request
*req
= server_alloc_req( sizeof(*req
), 0 );
745 req
->handle
= hthread
;
747 req
->param
= (void *)data
;
748 ret
= !server_call( REQ_QUEUE_APC
);
755 /**********************************************************************
756 * GetThreadTimes [KERNEL32.???] Obtains timing information.
759 * What are the fields where these values are stored?
765 BOOL WINAPI
GetThreadTimes(
766 HANDLE thread
, /* [in] Specifies the thread of interest */
767 LPFILETIME creationtime
, /* [out] When the thread was created */
768 LPFILETIME exittime
, /* [out] When the thread was destroyed */
769 LPFILETIME kerneltime
, /* [out] Time thread spent in kernel mode */
770 LPFILETIME usertime
) /* [out] Time thread spent in user mode */
772 FIXME("(0x%08x): stub\n",thread
);
773 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
778 /**********************************************************************
779 * VWin32_BoostThreadGroup [KERNEL.535]
781 VOID WINAPI
VWin32_BoostThreadGroup( DWORD threadId
, INT boost
)
783 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
786 /**********************************************************************
787 * VWin32_BoostThreadStatic [KERNEL.536]
789 VOID WINAPI
VWin32_BoostThreadStatic( DWORD threadId
, INT boost
)
791 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
795 /***********************************************************************
796 * GetThreadLocale (KERNEL32.295)
798 LCID WINAPI
GetThreadLocale(void)
800 LCID ret
= NtCurrentTeb()->CurrentLocale
;
801 if (!ret
) NtCurrentTeb()->CurrentLocale
= ret
= GetUserDefaultLCID();
806 /**********************************************************************
807 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
814 * check if lcid is a valid cp
816 BOOL WINAPI
SetThreadLocale(
817 LCID lcid
) /* [in] Locale identifier */
821 case LOCALE_SYSTEM_DEFAULT
:
822 lcid
= GetSystemDefaultLCID();
824 case LOCALE_USER_DEFAULT
:
826 lcid
= GetUserDefaultLCID();
829 NtCurrentTeb()->CurrentLocale
= lcid
;
834 /***********************************************************************
835 * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
838 * Pseudohandle for the current thread
840 #undef GetCurrentThread
841 HANDLE WINAPI
GetCurrentThread(void)
847 /***********************************************************************
848 * ProcessIdToSessionId (KERNEL32)
849 * This function is available on Terminal Server 4SP4 and Windows 2000
851 BOOL WINAPI
ProcessIdToSessionId( DWORD procid
, DWORD
*sessionid_ptr
)
853 /* According to MSDN, if the calling process is not in a terminal
854 * services environment, then the sessionid returned is zero.
863 /* void WINAPI SetLastError( DWORD error ); */
864 __ASM_GLOBAL_FUNC( SetLastError
,
865 "movl 4(%esp),%eax\n\t"
870 /* DWORD WINAPI GetLastError(void); */
871 __ASM_GLOBAL_FUNC( GetLastError
, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
873 /* DWORD WINAPI GetCurrentProcessId(void) */
874 __ASM_GLOBAL_FUNC( GetCurrentProcessId
, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
876 /* DWORD WINAPI GetCurrentThreadId(void) */
877 __ASM_GLOBAL_FUNC( GetCurrentThreadId
, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
881 /**********************************************************************
882 * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code.
884 void WINAPI
SetLastError( DWORD error
) /* [in] Per-thread error code */
886 NtCurrentTeb()->last_error
= error
;
889 /**********************************************************************
890 * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code.
892 DWORD WINAPI
GetLastError(void)
894 return NtCurrentTeb()->last_error
;
897 /***********************************************************************
898 * GetCurrentProcessId [KERNEL32.199] Returns process identifier.
900 DWORD WINAPI
GetCurrentProcessId(void)
902 return (DWORD
)NtCurrentTeb()->pid
;
905 /***********************************************************************
906 * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
908 DWORD WINAPI
GetCurrentThreadId(void)
910 return (DWORD
)NtCurrentTeb()->tid
;
913 #endif /* __i386__ */