4 * Copyright 1996 Alexandre Julliard
11 #include <sys/types.h>
12 #ifdef HAVE_SYS_SOCKET_H
13 # include <sys/socket.h>
15 #ifdef HAVE_SYS_MMAN_H
19 #include "wine/winbase16.h"
27 #include "selectors.h"
31 #include "stackframe.h"
32 #include "builtin16.h"
33 #include "debugtools.h"
37 DEFAULT_DEBUG_CHANNEL(thread
)
39 /* TEB of the initial thread */
40 static TEB initial_teb
;
42 /* Global thread list (FIXME: not thread-safe) */
43 TEB
*THREAD_First
= &initial_teb
;
45 /***********************************************************************
48 BOOL
THREAD_IsWin16( TEB
*teb
)
50 return !teb
|| !(teb
->flags
& TEBF_WIN32
);
53 /***********************************************************************
56 * Convert a thread id to a TEB, making sure it is valid.
58 TEB
*THREAD_IdToTEB( DWORD id
)
60 TEB
*teb
= THREAD_First
;
62 if (!id
) return NtCurrentTeb();
65 if ((DWORD
)teb
->tid
== id
) return 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
);
79 /***********************************************************************
82 * Initialization of a newly created TEB.
84 static BOOL
THREAD_InitTEB( TEB
*teb
, DWORD stack_size
, BOOL alloc_stack16
,
85 LPSECURITY_ATTRIBUTES sa
)
89 /* Allocate the stack */
92 * If stacksize smaller than 1 MB, allocate 1MB
93 * (one program wanted only 10 kB, which is recommendable, but some WINE
94 * functions, noteably in the files subdir, push HUGE structures and
95 * arrays on the stack. They probably shouldn't.)
96 * If stacksize larger than 16 MB, warn the user. (We could shrink the stack
97 * but this could give more or less unexplainable crashes.)
99 if (stack_size
<1024*1024)
100 stack_size
= 1024 * 1024;
101 if (stack_size
>= 16*1024*1024)
102 WARN("Thread stack size is %ld MB.\n",stack_size
/1024/1024);
103 teb
->stack_base
= VirtualAlloc(NULL
, stack_size
+ SIGNAL_STACK_SIZE
+
104 (alloc_stack16
? 0x10000 : 0),
105 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
106 if (!teb
->stack_base
) goto error
;
107 /* Set a guard page at the bottom of the stack */
108 VirtualProtect( teb
->stack_base
, 1, PAGE_EXECUTE_READWRITE
| PAGE_GUARD
, &old_prot
);
109 teb
->stack_top
= (char *)teb
->stack_base
+ stack_size
;
110 teb
->stack_low
= teb
->stack_base
;
111 teb
->signal_stack
= teb
->stack_top
; /* start of signal stack */
113 /* Allocate the 16-bit stack selector */
117 teb
->stack_sel
= SELECTOR_AllocBlock( teb
->stack_top
, 0x10000, SEGMENT_DATA
,
119 if (!teb
->stack_sel
) goto error
;
120 teb
->cur_stack
= PTR_SEG_OFF_TO_SEGPTR( teb
->stack_sel
,
121 0x10000 - sizeof(STACK16FRAME
) );
122 teb
->signal_stack
= (char *)teb
->signal_stack
+ 0x10000;
125 /* Create the thread event */
127 if (!(teb
->event
= CreateEventA( NULL
, FALSE
, FALSE
, NULL
))) goto error
;
128 teb
->event
= ConvertToGlobalHandle( teb
->event
);
132 if (teb
->event
) CloseHandle( teb
->event
);
133 if (teb
->stack_sel
) SELECTOR_FreeBlock( teb
->stack_sel
, 1 );
134 if (teb
->stack_base
) VirtualFree( teb
->stack_base
, 0, MEM_RELEASE
);
139 /***********************************************************************
142 * Free data structures associated with a thread.
143 * Must be called from the context of another thread.
145 void CALLBACK
THREAD_FreeTEB( ULONG_PTR arg
)
147 TEB
*teb
= (TEB
*)arg
;
148 TEB
**pptr
= &THREAD_First
;
150 TRACE("(%p) called\n", teb
);
151 SERVICE_Delete( teb
->cleanup
);
153 PROCESS_CallUserSignalProc( USIG_THREAD_EXIT
, 0 );
155 CloseHandle( teb
->event
);
156 while (*pptr
&& (*pptr
!= teb
)) pptr
= &(*pptr
)->next
;
157 if (*pptr
) *pptr
= teb
->next
;
159 /* Free the associated memory */
161 if (teb
->stack_sel
) SELECTOR_FreeBlock( teb
->stack_sel
, 1 );
162 SELECTOR_FreeBlock( teb
->teb_sel
, 1 );
163 close( teb
->socket
);
164 if (teb
->buffer
) munmap( teb
->buffer
, teb
->buffer_size
);
165 VirtualFree( teb
->stack_base
, 0, MEM_RELEASE
);
166 HeapFree( SystemHeap
, 0, teb
);
170 /***********************************************************************
171 * THREAD_CreateInitialThread
173 * Create the initial thread.
175 TEB
*THREAD_CreateInitialThread( PDB
*pdb
, int server_fd
)
177 initial_teb
.except
= (void *)-1;
178 initial_teb
.self
= &initial_teb
;
179 initial_teb
.flags
= /* TEBF_WIN32 */ 0;
180 initial_teb
.tls_ptr
= initial_teb
.tls_array
;
181 initial_teb
.process
= pdb
;
182 initial_teb
.exit_code
= 0x103; /* STILL_ACTIVE */
183 initial_teb
.socket
= server_fd
;
185 /* Allocate the TEB selector (%fs register) */
187 if (!(initial_teb
.teb_sel
= SELECTOR_AllocBlock( &initial_teb
, 0x1000,
188 SEGMENT_DATA
, TRUE
, FALSE
)))
190 MESSAGE("Could not allocate fs register for initial thread\n" );
193 SYSDEPS_SetCurThread( &initial_teb
);
195 /* Now proceed with normal initialization */
197 if (CLIENT_InitThread()) return NULL
;
198 if (!THREAD_InitTEB( &initial_teb
, 0, TRUE
, NULL
)) return NULL
;
203 /***********************************************************************
206 TEB
*THREAD_Create( PDB
*pdb
, DWORD flags
, DWORD stack_size
, BOOL alloc_stack16
,
207 LPSECURITY_ATTRIBUTES sa
, int *server_handle
)
209 struct new_thread_request
*req
= get_req_buffer();
211 HANDLE cleanup_object
;
213 TEB
*teb
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(TEB
) );
214 if (!teb
) return NULL
;
215 teb
->except
= (void *)-1;
216 teb
->htask16
= pdb
->task
;
218 teb
->flags
= (pdb
->flags
& PDB32_WIN16_PROC
)? 0 : TEBF_WIN32
;
219 teb
->tls_ptr
= teb
->tls_array
;
221 teb
->exit_code
= 0x103; /* STILL_ACTIVE */
224 /* Allocate the TEB selector (%fs register) */
227 teb
->teb_sel
= SELECTOR_AllocBlock( teb
, 0x1000, SEGMENT_DATA
, TRUE
, FALSE
);
228 if (!teb
->teb_sel
) goto error
;
230 /* Create the socket pair for server communication */
232 if (socketpair( AF_UNIX
, SOCK_STREAM
, 0, fd
) == -1)
234 SetLastError( ERROR_TOO_MANY_OPEN_FILES
); /* FIXME */
238 fcntl( fd
[0], F_SETFD
, 1 ); /* set close on exec flag */
240 /* Create the thread on the server side */
242 req
->pid
= teb
->process
->server_pid
;
243 req
->suspend
= ((flags
& CREATE_SUSPENDED
) != 0);
244 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
245 if (server_call_fd( REQ_NEW_THREAD
, fd
[1], NULL
)) goto error
;
247 *server_handle
= req
->handle
;
249 /* Do the rest of the initialization */
251 if (!THREAD_InitTEB( teb
, stack_size
, alloc_stack16
, sa
)) goto error
;
252 teb
->next
= THREAD_First
;
255 /* Install cleanup handler */
256 if ( !DuplicateHandle( GetCurrentProcess(), *server_handle
,
257 GetCurrentProcess(), &cleanup_object
,
258 0, FALSE
, DUPLICATE_SAME_ACCESS
) ) goto error
;
259 teb
->cleanup
= SERVICE_AddObject( cleanup_object
, THREAD_FreeTEB
, (ULONG_PTR
)teb
);
264 if (*server_handle
!= -1) CloseHandle( *server_handle
);
265 if (teb
->teb_sel
) SELECTOR_FreeBlock( teb
->teb_sel
, 1 );
266 if (teb
->socket
!= -1) close( teb
->socket
);
267 HeapFree( SystemHeap
, 0, teb
);
272 /***********************************************************************
275 * Start execution of a newly created thread. Does not return.
277 static void THREAD_Start(void)
279 LPTHREAD_START_ROUTINE func
= (LPTHREAD_START_ROUTINE
)NtCurrentTeb()->entry_point
;
280 PROCESS_CallUserSignalProc( USIG_THREAD_INIT
, 0 );
282 MODULE_DllThreadAttach( NULL
);
284 if (NtCurrentTeb()->process
->flags
& PDB32_DEBUGGED
) DEBUG_SendCreateThreadEvent( func
);
286 ExitThread( func( NtCurrentTeb()->entry_arg
) );
290 /***********************************************************************
291 * CreateThread (KERNEL32.63)
293 HANDLE WINAPI
CreateThread( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
294 LPTHREAD_START_ROUTINE start
, LPVOID param
,
295 DWORD flags
, LPDWORD id
)
298 TEB
*teb
= THREAD_Create( PROCESS_Current(), flags
, stack
, TRUE
, sa
, &handle
);
300 teb
->flags
|= TEBF_WIN32
;
301 teb
->entry_point
= start
;
302 teb
->entry_arg
= param
;
303 teb
->startup
= THREAD_Start
;
304 if (SYSDEPS_SpawnThread( teb
) == -1)
306 CloseHandle( handle
);
309 if (id
) *id
= (DWORD
)teb
->tid
;
313 /***********************************************************************
314 * CreateThread16 (KERNEL.441)
316 static DWORD CALLBACK
THREAD_StartThread16( LPVOID threadArgs
)
318 FARPROC16 start
= ((FARPROC16
*)threadArgs
)[0];
319 DWORD param
= ((DWORD
*)threadArgs
)[1];
320 HeapFree( GetProcessHeap(), 0, threadArgs
);
322 ((LPDWORD
)CURRENT_STACK16
)[-1] = param
;
323 return CallTo16Long( start
, sizeof(DWORD
) );
325 HANDLE WINAPI
CreateThread16( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
326 FARPROC16 start
, SEGPTR param
,
327 DWORD flags
, LPDWORD id
)
329 DWORD
*threadArgs
= HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD
) );
330 if (!threadArgs
) return INVALID_HANDLE_VALUE
;
331 threadArgs
[0] = (DWORD
)start
;
332 threadArgs
[1] = (DWORD
)param
;
334 return CreateThread( sa
, stack
, THREAD_StartThread16
, threadArgs
, flags
, id
);
338 /***********************************************************************
339 * ExitThread [KERNEL32.215] Ends a thread
344 void WINAPI
ExitThread( DWORD code
) /* [in] Exit code for this thread */
346 MODULE_DllThreadDetach( NULL
);
347 TerminateThread( GetCurrentThread(), code
);
351 /***********************************************************************
352 * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
355 * Pseudohandle for the current thread
357 HANDLE WINAPI
GetCurrentThread(void)
359 return CURRENT_THREAD_PSEUDOHANDLE
;
363 /**********************************************************************
364 * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code.
367 * Calling thread's last error code value.
369 DWORD WINAPI
GetLastError(void)
371 return NtCurrentTeb()->last_error
;
375 /**********************************************************************
376 * SetLastErrorEx [USER32.485] Sets the last-error code.
381 void WINAPI
SetLastErrorEx(
382 DWORD error
, /* [in] Per-thread error code */
383 DWORD type
) /* [in] Error type */
385 TRACE("(0x%08lx, 0x%08lx)\n", error
,type
);
392 /* Fall through for now */
394 FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error
,type
);
397 SetLastError( error
);
401 /**********************************************************************
402 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
404 * Allocates a thread local storage index
408 * Failure: 0xFFFFFFFF
410 DWORD WINAPI
TlsAlloc( void )
412 PDB
*process
= PROCESS_Current();
413 DWORD i
, mask
, ret
= 0;
414 DWORD
*bits
= process
->tls_bits
;
415 EnterCriticalSection( &process
->crit_section
);
416 if (*bits
== 0xffffffff)
420 if (*bits
== 0xffffffff)
422 LeaveCriticalSection( &process
->crit_section
);
423 SetLastError( ERROR_NO_MORE_ITEMS
);
427 for (i
= 0, mask
= 1; i
< 32; i
++, mask
<<= 1) if (!(*bits
& mask
)) break;
429 LeaveCriticalSection( &process
->crit_section
);
434 /**********************************************************************
435 * TlsFree [KERNEL32.531] Releases a TLS index.
437 * Releases a thread local storage index, making it available for reuse
444 DWORD index
) /* [in] TLS Index to free */
446 PDB
*process
= PROCESS_Current();
448 DWORD
*bits
= process
->tls_bits
;
451 SetLastError( ERROR_INVALID_PARAMETER
);
454 EnterCriticalSection( &process
->crit_section
);
455 if (index
>= 32) bits
++;
456 mask
= (1 << (index
& 31));
457 if (!(*bits
& mask
)) /* already free? */
459 LeaveCriticalSection( &process
->crit_section
);
460 SetLastError( ERROR_INVALID_PARAMETER
);
464 NtCurrentTeb()->tls_array
[index
] = 0;
465 /* FIXME: should zero all other thread values */
466 LeaveCriticalSection( &process
->crit_section
);
471 /**********************************************************************
472 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
475 * Success: Value stored in calling thread's TLS slot for index
476 * Failure: 0 and GetLastError returns NO_ERROR
478 LPVOID WINAPI
TlsGetValue(
479 DWORD index
) /* [in] TLS index to retrieve value for */
483 SetLastError( ERROR_INVALID_PARAMETER
);
486 SetLastError( ERROR_SUCCESS
);
487 return NtCurrentTeb()->tls_array
[index
];
491 /**********************************************************************
492 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
498 BOOL WINAPI
TlsSetValue(
499 DWORD index
, /* [in] TLS index to set value for */
500 LPVOID value
) /* [in] Value to be stored */
504 SetLastError( ERROR_INVALID_PARAMETER
);
507 NtCurrentTeb()->tls_array
[index
] = value
;
512 /***********************************************************************
513 * SetThreadContext [KERNEL32.670] Sets context of thread.
519 BOOL WINAPI
SetThreadContext(
520 HANDLE handle
, /* [in] Handle to thread with context */
521 const CONTEXT
*context
) /* [out] Address of context structure */
523 FIXME("not implemented\n" );
527 /***********************************************************************
528 * GetThreadContext [KERNEL32.294] Retrieves context of thread.
534 BOOL WINAPI
GetThreadContext(
535 HANDLE handle
, /* [in] Handle to thread with context */
536 CONTEXT
*context
) /* [out] Address of context structure */
541 FIXME("returning dummy info\n" );
543 /* make up some plausible values for segment registers */
557 /**********************************************************************
558 * GetThreadPriority [KERNEL32.296] Returns priority for thread.
561 * Success: Thread's priority level.
562 * Failure: THREAD_PRIORITY_ERROR_RETURN
564 INT WINAPI
GetThreadPriority(
565 HANDLE hthread
) /* [in] Handle to thread */
567 INT ret
= THREAD_PRIORITY_ERROR_RETURN
;
568 struct get_thread_info_request
*req
= get_req_buffer();
569 req
->handle
= hthread
;
570 if (!server_call( REQ_GET_THREAD_INFO
)) ret
= req
->priority
;
575 /**********************************************************************
576 * SetThreadPriority [KERNEL32.514] Sets priority for thread.
582 BOOL WINAPI
SetThreadPriority(
583 HANDLE hthread
, /* [in] Handle to thread */
584 INT priority
) /* [in] Thread priority level */
586 struct set_thread_info_request
*req
= get_req_buffer();
587 req
->handle
= hthread
;
588 req
->priority
= priority
;
589 req
->mask
= SET_THREAD_INFO_PRIORITY
;
590 return !server_call( REQ_SET_THREAD_INFO
);
594 /**********************************************************************
595 * SetThreadAffinityMask (KERNEL32.669)
597 DWORD WINAPI
SetThreadAffinityMask( HANDLE hThread
, DWORD dwThreadAffinityMask
)
599 struct set_thread_info_request
*req
= get_req_buffer();
600 req
->handle
= hThread
;
601 req
->affinity
= dwThreadAffinityMask
;
602 req
->mask
= SET_THREAD_INFO_AFFINITY
;
603 if (server_call( REQ_SET_THREAD_INFO
)) return 0;
604 return 1; /* FIXME: should return previous value */
608 /**********************************************************************
609 * TerminateThread [KERNEL32.685] Terminates a thread
615 BOOL WINAPI
TerminateThread(
616 HANDLE handle
, /* [in] Handle to thread */
617 DWORD exitcode
) /* [in] Exit code for thread */
619 struct terminate_thread_request
*req
= get_req_buffer();
620 req
->handle
= handle
;
621 req
->exit_code
= exitcode
;
622 return !server_call( REQ_TERMINATE_THREAD
);
626 /**********************************************************************
627 * GetExitCodeThread [KERNEL32.???] Gets termination status of thread.
633 BOOL WINAPI
GetExitCodeThread(
634 HANDLE hthread
, /* [in] Handle to thread */
635 LPDWORD exitcode
) /* [out] Address to receive termination status */
638 struct get_thread_info_request
*req
= get_req_buffer();
639 req
->handle
= hthread
;
640 if (!server_call( REQ_GET_THREAD_INFO
))
642 if (exitcode
) *exitcode
= req
->exit_code
;
649 /**********************************************************************
650 * ResumeThread [KERNEL32.587] Resumes a thread.
652 * Decrements a thread's suspend count. When count is zero, the
653 * execution of the thread is resumed.
656 * Success: Previous suspend count
657 * Failure: 0xFFFFFFFF
660 DWORD WINAPI
ResumeThread(
661 HANDLE hthread
) /* [in] Identifies thread to restart */
663 DWORD ret
= 0xffffffff;
664 struct resume_thread_request
*req
= get_req_buffer();
665 req
->handle
= hthread
;
666 if (!server_call( REQ_RESUME_THREAD
)) ret
= req
->count
;
671 /**********************************************************************
672 * SuspendThread [KERNEL32.681] Suspends a thread.
675 * Success: Previous suspend count
676 * Failure: 0xFFFFFFFF
678 DWORD WINAPI
SuspendThread(
679 HANDLE hthread
) /* [in] Handle to the thread */
681 DWORD ret
= 0xffffffff;
682 struct suspend_thread_request
*req
= get_req_buffer();
683 req
->handle
= hthread
;
684 if (!server_call( REQ_SUSPEND_THREAD
)) ret
= req
->count
;
689 /***********************************************************************
690 * QueueUserAPC (KERNEL32.566)
692 DWORD WINAPI
QueueUserAPC( PAPCFUNC func
, HANDLE hthread
, ULONG_PTR data
)
694 struct queue_apc_request
*req
= get_req_buffer();
695 req
->handle
= hthread
;
697 req
->param
= (void *)data
;
698 return !server_call( REQ_QUEUE_APC
);
702 /**********************************************************************
703 * GetThreadTimes [KERNEL32.???] Obtains timing information.
706 * What are the fields where these values are stored?
712 BOOL WINAPI
GetThreadTimes(
713 HANDLE thread
, /* [in] Specifies the thread of interest */
714 LPFILETIME creationtime
, /* [out] When the thread was created */
715 LPFILETIME exittime
, /* [out] When the thread was destroyed */
716 LPFILETIME kerneltime
, /* [out] Time thread spent in kernel mode */
717 LPFILETIME usertime
) /* [out] Time thread spent in user mode */
719 FIXME("(0x%08x): stub\n",thread
);
720 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
725 /**********************************************************************
726 * AttachThreadInput [KERNEL32.8] Attaches input of 1 thread to other
728 * Attaches the input processing mechanism of one thread to that of
736 * 1. Reset the Key State (currenly per thread key state is not maintained)
738 BOOL WINAPI
AttachThreadInput(
739 DWORD idAttach
, /* [in] Thread to attach */
740 DWORD idAttachTo
, /* [in] Thread to attach to */
741 BOOL fAttach
) /* [in] Attach or detach */
743 MESSAGEQUEUE
*pSrcMsgQ
= 0, *pTgtMsgQ
= 0;
746 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
748 /* A thread cannot attach to itself */
749 if ( idAttach
== idAttachTo
)
752 /* According to the docs this method should fail if a
753 * "Journal record" hook is installed. (attaches all input queues together)
755 if ( HOOK_IsHooked( WH_JOURNALRECORD
) )
758 /* Retrieve message queues corresponding to the thread id's */
759 pTgtMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttach
) );
760 pSrcMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttachTo
) );
762 /* Ensure we have message queues and that Src and Tgt threads
763 * are not system threads.
765 if ( !pSrcMsgQ
|| !pTgtMsgQ
|| !pSrcMsgQ
->pQData
|| !pTgtMsgQ
->pQData
)
768 if (fAttach
) /* Attach threads */
770 /* Only attach if currently detached */
771 if ( pTgtMsgQ
->pQData
!= pSrcMsgQ
->pQData
)
773 /* First release the target threads perQData */
774 PERQDATA_Release( pTgtMsgQ
->pQData
);
776 /* Share a reference to the source threads perQDATA */
777 PERQDATA_Addref( pSrcMsgQ
->pQData
);
778 pTgtMsgQ
->pQData
= pSrcMsgQ
->pQData
;
781 else /* Detach threads */
783 /* Only detach if currently attached */
784 if ( pTgtMsgQ
->pQData
== pSrcMsgQ
->pQData
)
786 /* First release the target threads perQData */
787 PERQDATA_Release( pTgtMsgQ
->pQData
);
789 /* Give the target thread its own private perQDATA once more */
790 pTgtMsgQ
->pQData
= PERQDATA_CreateInstance();
794 /* TODO: Reset the Key State */
796 bRet
= 1; /* Success */
800 /* Unlock the queues before returning */
802 QUEUE_Unlock( pSrcMsgQ
);
804 QUEUE_Unlock( pTgtMsgQ
);
809 /**********************************************************************
810 * VWin32_BoostThreadGroup [KERNEL.535]
812 VOID WINAPI
VWin32_BoostThreadGroup( DWORD threadId
, INT boost
)
814 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
817 /**********************************************************************
818 * VWin32_BoostThreadStatic [KERNEL.536]
820 VOID WINAPI
VWin32_BoostThreadStatic( DWORD threadId
, INT boost
)
822 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
825 /**********************************************************************
826 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
833 * Implemented in NT only (3.1 and above according to MS
835 BOOL WINAPI
SetThreadLocale(
836 LCID lcid
) /* [in] Locale identifier */
838 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
843 /**********************************************************************
844 * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code.
850 void WINAPI
SetLastError( DWORD error
) /* [in] Per-thread error code */
852 NtCurrentTeb()->last_error
= error
;
856 /***********************************************************************
857 * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
860 * Thread identifier of calling thread
862 #undef GetCurrentThreadId
863 DWORD WINAPI
GetCurrentThreadId(void)
865 return (DWORD
)NtCurrentTeb()->tid
;