4 * Copyright 1996 Alexandre Julliard
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #ifdef HAVE_SYS_MMAN_H
17 #include "wine/winbase16.h"
25 #include "selectors.h"
29 #include "stackframe.h"
30 #include "builtin16.h"
31 #include "debugtools.h"
35 DEFAULT_DEBUG_CHANNEL(thread
)
37 /* TEB of the initial thread */
38 static TEB initial_teb
;
40 /* Global thread list (FIXME: not thread-safe) */
41 TEB
*THREAD_First
= &initial_teb
;
43 /***********************************************************************
46 BOOL
THREAD_IsWin16( TEB
*teb
)
48 return !teb
|| !(teb
->flags
& TEBF_WIN32
);
51 /***********************************************************************
54 * Convert a thread id to a TEB, making sure it is valid.
56 TEB
*THREAD_IdToTEB( DWORD id
)
58 TEB
*teb
= THREAD_First
;
60 if (!id
) return NtCurrentTeb();
63 if ((DWORD
)teb
->tid
== id
) return teb
;
66 /* Allow task handles to be used; convert to main thread */
69 TDB
*pTask
= (TDB
*)GlobalLock16( id
);
70 if (pTask
) return pTask
->teb
;
72 SetLastError( ERROR_INVALID_PARAMETER
);
77 /***********************************************************************
80 * Initialization of a newly created TEB.
82 static BOOL
THREAD_InitTEB( TEB
*teb
, DWORD stack_size
, BOOL alloc_stack16
,
83 LPSECURITY_ATTRIBUTES sa
)
87 /* Allocate the stack */
90 * If stacksize smaller than 1 MB, allocate 1MB
91 * (one program wanted only 10 kB, which is recommendable, but some WINE
92 * functions, noteably in the files subdir, push HUGE structures and
93 * arrays on the stack. They probably shouldn't.)
94 * If stacksize larger than 16 MB, warn the user. (We could shrink the stack
95 * but this could give more or less unexplainable crashes.)
97 if (stack_size
<1024*1024)
98 stack_size
= 1024 * 1024;
99 if (stack_size
>= 16*1024*1024)
100 WARN("Thread stack size is %ld MB.\n",stack_size
/1024/1024);
101 teb
->stack_base
= VirtualAlloc(NULL
, stack_size
+ SIGNAL_STACK_SIZE
+
102 (alloc_stack16
? 0x10000 : 0),
103 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
104 if (!teb
->stack_base
) goto error
;
105 /* Set a guard page at the bottom of the stack */
106 VirtualProtect( teb
->stack_base
, 1, PAGE_EXECUTE_READWRITE
| PAGE_GUARD
, &old_prot
);
107 teb
->stack_top
= (char *)teb
->stack_base
+ stack_size
;
108 teb
->stack_low
= teb
->stack_base
;
109 teb
->signal_stack
= teb
->stack_top
; /* start of signal stack */
111 /* Allocate the 16-bit stack selector */
115 teb
->stack_sel
= SELECTOR_AllocBlock( teb
->stack_top
, 0x10000, SEGMENT_DATA
,
117 if (!teb
->stack_sel
) goto error
;
118 teb
->cur_stack
= PTR_SEG_OFF_TO_SEGPTR( teb
->stack_sel
,
119 0x10000 - sizeof(STACK16FRAME
) );
120 teb
->signal_stack
= (char *)teb
->signal_stack
+ 0x10000;
123 /* Create the thread event */
125 if (!(teb
->event
= CreateEventA( NULL
, FALSE
, FALSE
, NULL
))) goto error
;
126 teb
->event
= ConvertToGlobalHandle( teb
->event
);
130 if (teb
->event
) CloseHandle( teb
->event
);
131 if (teb
->stack_sel
) SELECTOR_FreeBlock( teb
->stack_sel
, 1 );
132 if (teb
->stack_base
) VirtualFree( teb
->stack_base
, 0, MEM_RELEASE
);
137 /***********************************************************************
140 * Free data structures associated with a thread.
141 * Must be called from the context of another thread.
143 void CALLBACK
THREAD_FreeTEB( ULONG_PTR arg
)
145 TEB
*teb
= (TEB
*)arg
;
146 TEB
**pptr
= &THREAD_First
;
148 TRACE("(%p) called\n", teb
);
149 SERVICE_Delete( teb
->cleanup
);
151 PROCESS_CallUserSignalProc( USIG_THREAD_EXIT
, 0 );
153 CloseHandle( teb
->event
);
154 while (*pptr
&& (*pptr
!= teb
)) pptr
= &(*pptr
)->next
;
155 if (*pptr
) *pptr
= teb
->next
;
157 /* Free the associated memory */
159 if (teb
->stack_sel
) SELECTOR_FreeBlock( teb
->stack_sel
, 1 );
160 SELECTOR_FreeBlock( teb
->teb_sel
, 1 );
161 close( teb
->socket
);
162 if (teb
->buffer
) munmap( teb
->buffer
, teb
->buffer_size
);
163 VirtualFree( teb
->stack_base
, 0, MEM_RELEASE
);
164 HeapFree( SystemHeap
, 0, teb
);
168 /***********************************************************************
169 * THREAD_CreateInitialThread
171 * Create the initial thread.
173 TEB
*THREAD_CreateInitialThread( PDB
*pdb
, int server_fd
)
175 initial_teb
.except
= (void *)-1;
176 initial_teb
.self
= &initial_teb
;
177 initial_teb
.flags
= /* TEBF_WIN32 */ 0;
178 initial_teb
.tls_ptr
= initial_teb
.tls_array
;
179 initial_teb
.process
= pdb
;
180 initial_teb
.exit_code
= 0x103; /* STILL_ACTIVE */
181 initial_teb
.socket
= server_fd
;
183 /* Allocate the TEB selector (%fs register) */
185 if (!(initial_teb
.teb_sel
= SELECTOR_AllocBlock( &initial_teb
, 0x1000,
186 SEGMENT_DATA
, TRUE
, FALSE
)))
188 MESSAGE("Could not allocate fs register for initial thread\n" );
191 SYSDEPS_SetCurThread( &initial_teb
);
193 /* Now proceed with normal initialization */
195 if (CLIENT_InitThread()) return NULL
;
196 if (!THREAD_InitTEB( &initial_teb
, 0, TRUE
, NULL
)) return NULL
;
201 /***********************************************************************
204 TEB
*THREAD_Create( PDB
*pdb
, DWORD flags
, DWORD stack_size
, BOOL alloc_stack16
,
205 LPSECURITY_ATTRIBUTES sa
, int *server_handle
)
207 struct new_thread_request
*req
= get_req_buffer();
209 HANDLE cleanup_object
;
211 TEB
*teb
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(TEB
) );
212 if (!teb
) return NULL
;
213 teb
->except
= (void *)-1;
214 teb
->htask16
= pdb
->task
;
216 teb
->flags
= (pdb
->flags
& PDB32_WIN16_PROC
)? 0 : TEBF_WIN32
;
217 teb
->tls_ptr
= teb
->tls_array
;
219 teb
->exit_code
= 0x103; /* STILL_ACTIVE */
222 /* Allocate the TEB selector (%fs register) */
225 teb
->teb_sel
= SELECTOR_AllocBlock( teb
, 0x1000, SEGMENT_DATA
, TRUE
, FALSE
);
226 if (!teb
->teb_sel
) goto error
;
228 /* Create the socket pair for server communication */
230 if (socketpair( AF_UNIX
, SOCK_STREAM
, 0, fd
) == -1)
232 SetLastError( ERROR_TOO_MANY_OPEN_FILES
); /* FIXME */
236 fcntl( fd
[0], F_SETFD
, 1 ); /* set close on exec flag */
238 /* Create the thread on the server side */
240 req
->pid
= teb
->process
->server_pid
;
241 req
->suspend
= ((flags
& CREATE_SUSPENDED
) != 0);
242 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
243 if (server_call_fd( REQ_NEW_THREAD
, fd
[1], NULL
)) goto error
;
245 *server_handle
= req
->handle
;
247 /* Do the rest of the initialization */
249 if (!THREAD_InitTEB( teb
, stack_size
, alloc_stack16
, sa
)) goto error
;
250 teb
->next
= THREAD_First
;
253 /* Install cleanup handler */
254 if ( !DuplicateHandle( GetCurrentProcess(), *server_handle
,
255 GetCurrentProcess(), &cleanup_object
,
256 0, FALSE
, DUPLICATE_SAME_ACCESS
) ) goto error
;
257 teb
->cleanup
= SERVICE_AddObject( cleanup_object
, THREAD_FreeTEB
, (ULONG_PTR
)teb
);
262 if (*server_handle
!= -1) CloseHandle( *server_handle
);
263 if (teb
->teb_sel
) SELECTOR_FreeBlock( teb
->teb_sel
, 1 );
264 if (teb
->socket
!= -1) close( teb
->socket
);
265 HeapFree( SystemHeap
, 0, teb
);
270 /***********************************************************************
273 * Start execution of a newly created thread. Does not return.
275 static void THREAD_Start(void)
277 LPTHREAD_START_ROUTINE func
= (LPTHREAD_START_ROUTINE
)NtCurrentTeb()->entry_point
;
278 PROCESS_CallUserSignalProc( USIG_THREAD_INIT
, 0 );
280 MODULE_DllThreadAttach( NULL
);
282 if (NtCurrentTeb()->process
->flags
& PDB32_DEBUGGED
) DEBUG_SendCreateThreadEvent( func
);
284 ExitThread( func( NtCurrentTeb()->entry_arg
) );
288 /***********************************************************************
289 * CreateThread (KERNEL32.63)
291 HANDLE WINAPI
CreateThread( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
292 LPTHREAD_START_ROUTINE start
, LPVOID param
,
293 DWORD flags
, LPDWORD id
)
296 TEB
*teb
= THREAD_Create( PROCESS_Current(), flags
, stack
, TRUE
, sa
, &handle
);
298 teb
->flags
|= TEBF_WIN32
;
299 teb
->entry_point
= start
;
300 teb
->entry_arg
= param
;
301 teb
->startup
= THREAD_Start
;
302 if (SYSDEPS_SpawnThread( teb
) == -1)
304 CloseHandle( handle
);
307 if (id
) *id
= (DWORD
)teb
->tid
;
311 /***********************************************************************
312 * CreateThread16 (KERNEL.441)
314 static DWORD CALLBACK
THREAD_StartThread16( LPVOID threadArgs
)
316 FARPROC16 start
= ((FARPROC16
*)threadArgs
)[0];
317 DWORD param
= ((DWORD
*)threadArgs
)[1];
318 HeapFree( GetProcessHeap(), 0, threadArgs
);
320 ((LPDWORD
)CURRENT_STACK16
)[-1] = param
;
321 return CallTo16Long( start
, sizeof(DWORD
) );
323 HANDLE WINAPI
CreateThread16( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
324 FARPROC16 start
, SEGPTR param
,
325 DWORD flags
, LPDWORD id
)
327 DWORD
*threadArgs
= HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD
) );
328 if (!threadArgs
) return INVALID_HANDLE_VALUE
;
329 threadArgs
[0] = (DWORD
)start
;
330 threadArgs
[1] = (DWORD
)param
;
332 return CreateThread( sa
, stack
, THREAD_StartThread16
, threadArgs
, flags
, id
);
336 /***********************************************************************
337 * ExitThread [KERNEL32.215] Ends a thread
342 void WINAPI
ExitThread( DWORD code
) /* [in] Exit code for this thread */
344 MODULE_DllThreadDetach( NULL
);
345 TerminateThread( GetCurrentThread(), code
);
349 /***********************************************************************
350 * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
353 * Pseudohandle for the current thread
355 HANDLE WINAPI
GetCurrentThread(void)
357 return CURRENT_THREAD_PSEUDOHANDLE
;
361 /**********************************************************************
362 * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code.
365 * Calling thread's last error code value.
367 DWORD WINAPI
GetLastError(void)
369 return NtCurrentTeb()->last_error
;
373 /**********************************************************************
374 * SetLastErrorEx [USER32.485] Sets the last-error code.
379 void WINAPI
SetLastErrorEx(
380 DWORD error
, /* [in] Per-thread error code */
381 DWORD type
) /* [in] Error type */
383 TRACE("(0x%08lx, 0x%08lx)\n", error
,type
);
390 /* Fall through for now */
392 FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error
,type
);
395 SetLastError( error
);
399 /**********************************************************************
400 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
402 * Allocates a thread local storage index
406 * Failure: 0xFFFFFFFF
408 DWORD WINAPI
TlsAlloc( void )
410 PDB
*process
= PROCESS_Current();
411 DWORD i
, mask
, ret
= 0;
412 DWORD
*bits
= process
->tls_bits
;
413 EnterCriticalSection( &process
->crit_section
);
414 if (*bits
== 0xffffffff)
418 if (*bits
== 0xffffffff)
420 LeaveCriticalSection( &process
->crit_section
);
421 SetLastError( ERROR_NO_MORE_ITEMS
);
425 for (i
= 0, mask
= 1; i
< 32; i
++, mask
<<= 1) if (!(*bits
& mask
)) break;
427 LeaveCriticalSection( &process
->crit_section
);
432 /**********************************************************************
433 * TlsFree [KERNEL32.531] Releases a TLS index.
435 * Releases a thread local storage index, making it available for reuse
442 DWORD index
) /* [in] TLS Index to free */
444 PDB
*process
= PROCESS_Current();
446 DWORD
*bits
= process
->tls_bits
;
449 SetLastError( ERROR_INVALID_PARAMETER
);
452 EnterCriticalSection( &process
->crit_section
);
453 if (index
>= 32) bits
++;
454 mask
= (1 << (index
& 31));
455 if (!(*bits
& mask
)) /* already free? */
457 LeaveCriticalSection( &process
->crit_section
);
458 SetLastError( ERROR_INVALID_PARAMETER
);
462 NtCurrentTeb()->tls_array
[index
] = 0;
463 /* FIXME: should zero all other thread values */
464 LeaveCriticalSection( &process
->crit_section
);
469 /**********************************************************************
470 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
473 * Success: Value stored in calling thread's TLS slot for index
474 * Failure: 0 and GetLastError returns NO_ERROR
476 LPVOID WINAPI
TlsGetValue(
477 DWORD index
) /* [in] TLS index to retrieve value for */
481 SetLastError( ERROR_INVALID_PARAMETER
);
484 SetLastError( ERROR_SUCCESS
);
485 return NtCurrentTeb()->tls_array
[index
];
489 /**********************************************************************
490 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
496 BOOL WINAPI
TlsSetValue(
497 DWORD index
, /* [in] TLS index to set value for */
498 LPVOID value
) /* [in] Value to be stored */
502 SetLastError( ERROR_INVALID_PARAMETER
);
505 NtCurrentTeb()->tls_array
[index
] = value
;
510 /***********************************************************************
511 * SetThreadContext [KERNEL32.670] Sets context of thread.
517 BOOL WINAPI
SetThreadContext(
518 HANDLE handle
, /* [in] Handle to thread with context */
519 const CONTEXT
*context
) /* [out] Address of context structure */
521 FIXME("not implemented\n" );
525 /***********************************************************************
526 * GetThreadContext [KERNEL32.294] Retrieves context of thread.
532 BOOL WINAPI
GetThreadContext(
533 HANDLE handle
, /* [in] Handle to thread with context */
534 CONTEXT
*context
) /* [out] Address of context structure */
539 FIXME("returning dummy info\n" );
541 /* make up some plausible values for segment registers */
555 /**********************************************************************
556 * GetThreadPriority [KERNEL32.296] Returns priority for thread.
559 * Success: Thread's priority level.
560 * Failure: THREAD_PRIORITY_ERROR_RETURN
562 INT WINAPI
GetThreadPriority(
563 HANDLE hthread
) /* [in] Handle to thread */
565 INT ret
= THREAD_PRIORITY_ERROR_RETURN
;
566 struct get_thread_info_request
*req
= get_req_buffer();
567 req
->handle
= hthread
;
568 if (!server_call( REQ_GET_THREAD_INFO
)) ret
= req
->priority
;
573 /**********************************************************************
574 * SetThreadPriority [KERNEL32.514] Sets priority for thread.
580 BOOL WINAPI
SetThreadPriority(
581 HANDLE hthread
, /* [in] Handle to thread */
582 INT priority
) /* [in] Thread priority level */
584 struct set_thread_info_request
*req
= get_req_buffer();
585 req
->handle
= hthread
;
586 req
->priority
= priority
;
587 req
->mask
= SET_THREAD_INFO_PRIORITY
;
588 return !server_call( REQ_SET_THREAD_INFO
);
592 /**********************************************************************
593 * SetThreadAffinityMask (KERNEL32.669)
595 DWORD WINAPI
SetThreadAffinityMask( HANDLE hThread
, DWORD dwThreadAffinityMask
)
597 struct set_thread_info_request
*req
= get_req_buffer();
598 req
->handle
= hThread
;
599 req
->affinity
= dwThreadAffinityMask
;
600 req
->mask
= SET_THREAD_INFO_AFFINITY
;
601 if (server_call( REQ_SET_THREAD_INFO
)) return 0;
602 return 1; /* FIXME: should return previous value */
606 /**********************************************************************
607 * TerminateThread [KERNEL32.685] Terminates a thread
613 BOOL WINAPI
TerminateThread(
614 HANDLE handle
, /* [in] Handle to thread */
615 DWORD exitcode
) /* [in] Exit code for thread */
617 struct terminate_thread_request
*req
= get_req_buffer();
618 req
->handle
= handle
;
619 req
->exit_code
= exitcode
;
620 return !server_call( REQ_TERMINATE_THREAD
);
624 /**********************************************************************
625 * GetExitCodeThread [KERNEL32.???] Gets termination status of thread.
631 BOOL WINAPI
GetExitCodeThread(
632 HANDLE hthread
, /* [in] Handle to thread */
633 LPDWORD exitcode
) /* [out] Address to receive termination status */
636 struct get_thread_info_request
*req
= get_req_buffer();
637 req
->handle
= hthread
;
638 if (!server_call( REQ_GET_THREAD_INFO
))
640 if (exitcode
) *exitcode
= req
->exit_code
;
647 /**********************************************************************
648 * ResumeThread [KERNEL32.587] Resumes a thread.
650 * Decrements a thread's suspend count. When count is zero, the
651 * execution of the thread is resumed.
654 * Success: Previous suspend count
655 * Failure: 0xFFFFFFFF
658 DWORD WINAPI
ResumeThread(
659 HANDLE hthread
) /* [in] Identifies thread to restart */
661 DWORD ret
= 0xffffffff;
662 struct resume_thread_request
*req
= get_req_buffer();
663 req
->handle
= hthread
;
664 if (!server_call( REQ_RESUME_THREAD
)) ret
= req
->count
;
669 /**********************************************************************
670 * SuspendThread [KERNEL32.681] Suspends a thread.
673 * Success: Previous suspend count
674 * Failure: 0xFFFFFFFF
676 DWORD WINAPI
SuspendThread(
677 HANDLE hthread
) /* [in] Handle to the thread */
679 DWORD ret
= 0xffffffff;
680 struct suspend_thread_request
*req
= get_req_buffer();
681 req
->handle
= hthread
;
682 if (!server_call( REQ_SUSPEND_THREAD
)) ret
= req
->count
;
687 /***********************************************************************
688 * QueueUserAPC (KERNEL32.566)
690 DWORD WINAPI
QueueUserAPC( PAPCFUNC func
, HANDLE hthread
, ULONG_PTR data
)
692 struct queue_apc_request
*req
= get_req_buffer();
693 req
->handle
= hthread
;
695 req
->param
= (void *)data
;
696 return !server_call( REQ_QUEUE_APC
);
700 /**********************************************************************
701 * GetThreadTimes [KERNEL32.???] Obtains timing information.
704 * What are the fields where these values are stored?
710 BOOL WINAPI
GetThreadTimes(
711 HANDLE thread
, /* [in] Specifies the thread of interest */
712 LPFILETIME creationtime
, /* [out] When the thread was created */
713 LPFILETIME exittime
, /* [out] When the thread was destroyed */
714 LPFILETIME kerneltime
, /* [out] Time thread spent in kernel mode */
715 LPFILETIME usertime
) /* [out] Time thread spent in user mode */
717 FIXME("(0x%08x): stub\n",thread
);
718 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
723 /**********************************************************************
724 * AttachThreadInput [KERNEL32.8] Attaches input of 1 thread to other
726 * Attaches the input processing mechanism of one thread to that of
734 * 1. Reset the Key State (currenly per thread key state is not maintained)
736 BOOL WINAPI
AttachThreadInput(
737 DWORD idAttach
, /* [in] Thread to attach */
738 DWORD idAttachTo
, /* [in] Thread to attach to */
739 BOOL fAttach
) /* [in] Attach or detach */
741 MESSAGEQUEUE
*pSrcMsgQ
= 0, *pTgtMsgQ
= 0;
744 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
746 /* A thread cannot attach to itself */
747 if ( idAttach
== idAttachTo
)
750 /* According to the docs this method should fail if a
751 * "Journal record" hook is installed. (attaches all input queues together)
753 if ( HOOK_IsHooked( WH_JOURNALRECORD
) )
756 /* Retrieve message queues corresponding to the thread id's */
757 pTgtMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttach
) );
758 pSrcMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttachTo
) );
760 /* Ensure we have message queues and that Src and Tgt threads
761 * are not system threads.
763 if ( !pSrcMsgQ
|| !pTgtMsgQ
|| !pSrcMsgQ
->pQData
|| !pTgtMsgQ
->pQData
)
766 if (fAttach
) /* Attach threads */
768 /* Only attach if currently detached */
769 if ( pTgtMsgQ
->pQData
!= pSrcMsgQ
->pQData
)
771 /* First release the target threads perQData */
772 PERQDATA_Release( pTgtMsgQ
->pQData
);
774 /* Share a reference to the source threads perQDATA */
775 PERQDATA_Addref( pSrcMsgQ
->pQData
);
776 pTgtMsgQ
->pQData
= pSrcMsgQ
->pQData
;
779 else /* Detach threads */
781 /* Only detach if currently attached */
782 if ( pTgtMsgQ
->pQData
== pSrcMsgQ
->pQData
)
784 /* First release the target threads perQData */
785 PERQDATA_Release( pTgtMsgQ
->pQData
);
787 /* Give the target thread its own private perQDATA once more */
788 pTgtMsgQ
->pQData
= PERQDATA_CreateInstance();
792 /* TODO: Reset the Key State */
794 bRet
= 1; /* Success */
798 /* Unlock the queues before returning */
800 QUEUE_Unlock( pSrcMsgQ
);
802 QUEUE_Unlock( pTgtMsgQ
);
807 /**********************************************************************
808 * VWin32_BoostThreadGroup [KERNEL.535]
810 VOID WINAPI
VWin32_BoostThreadGroup( DWORD threadId
, INT boost
)
812 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
815 /**********************************************************************
816 * VWin32_BoostThreadStatic [KERNEL.536]
818 VOID WINAPI
VWin32_BoostThreadStatic( DWORD threadId
, INT boost
)
820 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
823 /**********************************************************************
824 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
831 * Implemented in NT only (3.1 and above according to MS
833 BOOL WINAPI
SetThreadLocale(
834 LCID lcid
) /* [in] Locale identifier */
836 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
841 /**********************************************************************
842 * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code.
848 void WINAPI
SetLastError( DWORD error
) /* [in] Per-thread error code */
850 NtCurrentTeb()->last_error
= error
;
854 /***********************************************************************
855 * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
858 * Thread identifier of calling thread
860 #undef GetCurrentThreadId
861 DWORD WINAPI
GetCurrentThreadId(void)
863 return (DWORD
)NtCurrentTeb()->tid
;