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"
35 DEFAULT_DEBUG_CHANNEL(thread
);
37 /* TEB of the initial thread */
38 static TEB initial_teb
;
40 /* The initial process PDB */
41 static PDB initial_pdb
;
43 /***********************************************************************
46 BOOL
THREAD_IsWin16( TEB
*teb
)
48 return !teb
|| !(teb
->tibflags
& TEBF_WIN32
);
51 /***********************************************************************
54 * Convert a thread id to a TEB, making sure it is valid.
56 TEB
*THREAD_IdToTEB( DWORD id
)
58 struct get_thread_info_request
*req
= get_req_buffer();
60 if (!id
|| id
== GetCurrentThreadId()) return NtCurrentTeb();
62 req
->tid_in
= (void *)id
;
63 if (!server_call_noerr( REQ_GET_THREAD_INFO
)) return req
->teb
;
65 /* Allow task handles to be used; convert to main thread */
68 TDB
*pTask
= (TDB
*)GlobalLock16( id
);
69 if (pTask
) return pTask
->teb
;
71 SetLastError( ERROR_INVALID_PARAMETER
);
76 /***********************************************************************
79 * Initialization of a newly created TEB.
81 static BOOL
THREAD_InitTEB( TEB
*teb
)
83 teb
->except
= (void *)~0UL;
85 teb
->tibflags
= TEBF_WIN32
;
86 teb
->tls_ptr
= teb
->tls_array
;
87 teb
->exit_code
= STILL_ACTIVE
;
89 teb
->stack_top
= (void *)~0UL;
90 teb
->StaticUnicodeString
.MaximumLength
= sizeof(teb
->StaticUnicodeBuffer
);
91 teb
->StaticUnicodeString
.Buffer
= (PWSTR
)teb
->StaticUnicodeBuffer
;
92 teb
->teb_sel
= SELECTOR_AllocBlock( teb
, 0x1000, SEGMENT_DATA
, TRUE
, FALSE
);
93 return (teb
->teb_sel
!= 0);
97 /***********************************************************************
100 * Free data structures associated with a thread.
101 * Must be called from the context of another thread.
103 static void CALLBACK
THREAD_FreeTEB( TEB
*teb
)
105 TRACE("(%p) called\n", teb
);
106 if (teb
->cleanup
) SERVICE_Delete( teb
->cleanup
);
108 /* Free the associated memory */
110 if (teb
->socket
!= -1) close( teb
->socket
);
111 if (teb
->stack_sel
) SELECTOR_FreeBlock( teb
->stack_sel
, 1 );
112 SELECTOR_FreeBlock( teb
->teb_sel
, 1 );
113 if (teb
->buffer
) munmap( teb
->buffer
, teb
->buffer_size
);
114 if (teb
->debug_info
) HeapFree( GetProcessHeap(), 0, teb
->debug_info
);
115 VirtualFree( teb
->stack_base
, 0, MEM_RELEASE
);
119 /***********************************************************************
122 * Allocate the stack of a thread.
124 TEB
*THREAD_InitStack( TEB
*teb
, DWORD stack_size
, BOOL alloc_stack16
)
126 DWORD old_prot
, total_size
;
127 DWORD page_size
= VIRTUAL_GetPageSize();
130 /* Allocate the stack */
132 if (stack_size
>= 16*1024*1024)
133 WARN("Thread stack size is %ld MB.\n",stack_size
/1024/1024);
135 /* if size is smaller than default, get stack size from parent */
136 if (stack_size
< 1024 * 1024)
139 stack_size
= 1024 * 1024; /* no parent */
141 stack_size
= ((char *)NtCurrentTeb()->stack_top
- (char *)NtCurrentTeb()->stack_base
142 - SIGNAL_STACK_SIZE
- 3 * page_size
);
145 /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */
146 stack_size
+= 64 * 1024;
148 /* Memory layout in allocated block:
151 * 1 page NOACCESS guard page
152 * SIGNAL_STACK_SIZE signal stack
153 * 1 page NOACCESS guard page
154 * 1 page PAGE_GUARD guard page
155 * stack_size normal stack
156 * 64Kb 16-bit stack (optional)
157 * 1 page TEB (except for initial thread)
160 stack_size
= (stack_size
+ (page_size
- 1)) & ~(page_size
- 1);
161 total_size
= stack_size
+ SIGNAL_STACK_SIZE
+ 3 * page_size
;
162 if (alloc_stack16
) total_size
+= 0x10000;
163 if (!teb
) total_size
+= page_size
;
165 if (!(base
= VirtualAlloc( NULL
, total_size
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
)))
170 teb
= (TEB
*)((char *)base
+ total_size
- page_size
);
171 if (!THREAD_InitTEB( teb
))
173 VirtualFree( base
, 0, MEM_RELEASE
);
178 teb
->stack_low
= base
;
179 teb
->stack_base
= base
;
180 teb
->signal_stack
= (char *)base
+ page_size
;
181 teb
->stack_top
= (char *)base
+ 3 * page_size
+ SIGNAL_STACK_SIZE
+ stack_size
;
183 /* Setup guard pages */
185 VirtualProtect( base
, 1, PAGE_NOACCESS
, &old_prot
);
186 VirtualProtect( (char *)teb
->signal_stack
+ SIGNAL_STACK_SIZE
, 1, PAGE_NOACCESS
, &old_prot
);
187 VirtualProtect( (char *)teb
->signal_stack
+ SIGNAL_STACK_SIZE
+ page_size
, 1,
188 PAGE_EXECUTE_READWRITE
| PAGE_GUARD
, &old_prot
);
190 /* Allocate the 16-bit stack selector */
194 teb
->stack_sel
= SELECTOR_AllocBlock( teb
->stack_top
, 0x10000, SEGMENT_DATA
,
196 if (!teb
->stack_sel
) goto error
;
197 teb
->cur_stack
= PTR_SEG_OFF_TO_SEGPTR( teb
->stack_sel
,
198 0x10000 - sizeof(STACK16FRAME
) );
203 THREAD_FreeTEB( teb
);
208 /***********************************************************************
211 * Setup the initial thread.
213 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
215 void THREAD_Init(void)
217 if (!initial_teb
.self
) /* do it only once */
219 THREAD_InitTEB( &initial_teb
);
220 assert( initial_teb
.teb_sel
);
221 initial_teb
.process
= &initial_pdb
;
222 SYSDEPS_SetCurThread( &initial_teb
);
226 DECL_GLOBAL_CONSTRUCTOR(thread_init
) { THREAD_Init(); }
228 /***********************************************************************
232 TEB
*THREAD_Create( int fd
, DWORD stack_size
, BOOL alloc_stack16
)
236 if ((teb
= THREAD_InitStack( NULL
, stack_size
, alloc_stack16
)))
238 teb
->tibflags
= (PROCESS_Current()->flags
& PDB32_WIN16_PROC
) ? 0 : TEBF_WIN32
;
239 teb
->process
= PROCESS_Current();
241 fcntl( fd
, F_SETFD
, 1 ); /* set close on exec flag */
242 TRACE("(%p) succeeded\n", teb
);
248 /***********************************************************************
251 * Start execution of a newly created thread. Does not return.
253 static void THREAD_Start(void)
255 HANDLE cleanup_object
;
256 LPTHREAD_START_ROUTINE func
= (LPTHREAD_START_ROUTINE
)NtCurrentTeb()->entry_point
;
258 /* install cleanup handler */
259 if (DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
260 GetCurrentProcess(), &cleanup_object
,
261 0, FALSE
, DUPLICATE_SAME_ACCESS
))
262 NtCurrentTeb()->cleanup
= SERVICE_AddObject( cleanup_object
, (PAPCFUNC
)THREAD_FreeTEB
,
263 (ULONG_PTR
)NtCurrentTeb() );
265 PROCESS_CallUserSignalProc( USIG_THREAD_INIT
, 0 );
267 MODULE_DllThreadAttach( NULL
);
268 ExitThread( func( NtCurrentTeb()->entry_arg
) );
272 /***********************************************************************
273 * CreateThread (KERNEL32.63)
275 HANDLE WINAPI
CreateThread( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
276 LPTHREAD_START_ROUTINE start
, LPVOID param
,
277 DWORD flags
, LPDWORD id
)
279 struct new_thread_request
*req
= get_req_buffer();
280 int socket
, handle
= -1;
284 req
->suspend
= ((flags
& CREATE_SUSPENDED
) != 0);
285 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
286 if (server_call_fd( REQ_NEW_THREAD
, -1, &socket
)) return 0;
287 handle
= req
->handle
;
290 if (!(teb
= THREAD_Create( socket
, stack
, TRUE
)))
295 teb
->tibflags
|= TEBF_WIN32
;
296 teb
->entry_point
= start
;
297 teb
->entry_arg
= param
;
298 teb
->startup
= THREAD_Start
;
299 teb
->htask16
= GetCurrentTask();
300 teb
->CurrentLocale
= GetUserDefaultLCID(); /* for threads in user context */
301 if (id
) *id
= (DWORD
)tid
;
302 if (SYSDEPS_SpawnThread( teb
) == -1)
304 CloseHandle( handle
);
310 /***********************************************************************
311 * CreateThread16 (KERNEL.441)
313 static DWORD CALLBACK
THREAD_StartThread16( LPVOID threadArgs
)
315 FARPROC16 start
= ((FARPROC16
*)threadArgs
)[0];
316 DWORD param
= ((DWORD
*)threadArgs
)[1];
317 HeapFree( GetProcessHeap(), 0, threadArgs
);
319 ((LPDWORD
)CURRENT_STACK16
)[-1] = param
;
320 return CallTo16Long( start
, sizeof(DWORD
) );
322 HANDLE WINAPI
CreateThread16( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
323 FARPROC16 start
, SEGPTR param
,
324 DWORD flags
, LPDWORD id
)
326 DWORD
*threadArgs
= HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD
) );
327 if (!threadArgs
) return INVALID_HANDLE_VALUE
;
328 threadArgs
[0] = (DWORD
)start
;
329 threadArgs
[1] = (DWORD
)param
;
331 return CreateThread( sa
, stack
, THREAD_StartThread16
, threadArgs
, flags
, id
);
335 /***********************************************************************
336 * ExitThread [KERNEL32.215] Ends a thread
341 void WINAPI
ExitThread( DWORD code
) /* [in] Exit code for this thread */
343 struct terminate_thread_request
*req
= get_req_buffer();
345 /* send the exit code to the server */
346 req
->handle
= GetCurrentThread();
347 req
->exit_code
= code
;
348 server_call( REQ_TERMINATE_THREAD
);
351 MODULE_DllProcessDetach( TRUE
, (LPVOID
)1 );
356 MODULE_DllThreadDetach( NULL
);
357 if (!(NtCurrentTeb()->tibflags
& TEBF_WIN32
)) TASK_KillTask( 0 );
358 SYSDEPS_ExitThread( code
);
363 /**********************************************************************
364 * SetLastErrorEx [USER32.485] Sets the last-error code.
369 void WINAPI
SetLastErrorEx(
370 DWORD error
, /* [in] Per-thread error code */
371 DWORD type
) /* [in] Error type */
373 TRACE("(0x%08lx, 0x%08lx)\n", error
,type
);
380 /* Fall through for now */
382 FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error
,type
);
385 SetLastError( error
);
389 /**********************************************************************
390 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
392 * Allocates a thread local storage index
396 * Failure: 0xFFFFFFFF
398 DWORD WINAPI
TlsAlloc( void )
400 PDB
*process
= PROCESS_Current();
401 DWORD i
, mask
, ret
= 0;
402 DWORD
*bits
= process
->tls_bits
;
403 EnterCriticalSection( &process
->crit_section
);
404 if (*bits
== 0xffffffff)
408 if (*bits
== 0xffffffff)
410 LeaveCriticalSection( &process
->crit_section
);
411 SetLastError( ERROR_NO_MORE_ITEMS
);
415 for (i
= 0, mask
= 1; i
< 32; i
++, mask
<<= 1) if (!(*bits
& mask
)) break;
417 LeaveCriticalSection( &process
->crit_section
);
422 /**********************************************************************
423 * TlsFree [KERNEL32.531] Releases a TLS index.
425 * Releases a thread local storage index, making it available for reuse
432 DWORD index
) /* [in] TLS Index to free */
434 PDB
*process
= PROCESS_Current();
436 DWORD
*bits
= process
->tls_bits
;
439 SetLastError( ERROR_INVALID_PARAMETER
);
442 EnterCriticalSection( &process
->crit_section
);
443 if (index
>= 32) bits
++;
444 mask
= (1 << (index
& 31));
445 if (!(*bits
& mask
)) /* already free? */
447 LeaveCriticalSection( &process
->crit_section
);
448 SetLastError( ERROR_INVALID_PARAMETER
);
452 NtCurrentTeb()->tls_array
[index
] = 0;
453 /* FIXME: should zero all other thread values */
454 LeaveCriticalSection( &process
->crit_section
);
459 /**********************************************************************
460 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
463 * Success: Value stored in calling thread's TLS slot for index
464 * Failure: 0 and GetLastError returns NO_ERROR
466 LPVOID WINAPI
TlsGetValue(
467 DWORD index
) /* [in] TLS index to retrieve value for */
471 SetLastError( ERROR_INVALID_PARAMETER
);
474 SetLastError( ERROR_SUCCESS
);
475 return NtCurrentTeb()->tls_array
[index
];
479 /**********************************************************************
480 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
486 BOOL WINAPI
TlsSetValue(
487 DWORD index
, /* [in] TLS index to set value for */
488 LPVOID value
) /* [in] Value to be stored */
492 SetLastError( ERROR_INVALID_PARAMETER
);
495 NtCurrentTeb()->tls_array
[index
] = value
;
500 /***********************************************************************
501 * SetThreadContext [KERNEL32.670] Sets context of thread.
507 BOOL WINAPI
SetThreadContext( HANDLE handle
, /* [in] Handle to thread with context */
508 const CONTEXT
*context
) /* [in] Address of context structure */
510 struct set_thread_context_request
*req
= get_req_buffer();
511 req
->handle
= handle
;
512 req
->flags
= context
->ContextFlags
;
513 memcpy( &req
->context
, context
, sizeof(*context
) );
514 return !server_call( REQ_SET_THREAD_CONTEXT
);
518 /***********************************************************************
519 * GetThreadContext [KERNEL32.294] Retrieves context of thread.
525 BOOL WINAPI
GetThreadContext( HANDLE handle
, /* [in] Handle to thread with context */
526 CONTEXT
*context
) /* [out] Address of context structure */
528 struct get_thread_context_request
*req
= get_req_buffer();
529 req
->handle
= handle
;
530 req
->flags
= context
->ContextFlags
;
531 memcpy( &req
->context
, context
, sizeof(*context
) );
532 if (server_call( REQ_GET_THREAD_CONTEXT
)) return FALSE
;
533 memcpy( context
, &req
->context
, sizeof(*context
) );
538 /**********************************************************************
539 * GetThreadPriority [KERNEL32.296] Returns priority for thread.
542 * Success: Thread's priority level.
543 * Failure: THREAD_PRIORITY_ERROR_RETURN
545 INT WINAPI
GetThreadPriority(
546 HANDLE hthread
) /* [in] Handle to thread */
548 INT ret
= THREAD_PRIORITY_ERROR_RETURN
;
549 struct get_thread_info_request
*req
= get_req_buffer();
550 req
->handle
= hthread
;
552 if (!server_call( REQ_GET_THREAD_INFO
)) ret
= req
->priority
;
557 /**********************************************************************
558 * SetThreadPriority [KERNEL32.514] Sets priority for thread.
564 BOOL WINAPI
SetThreadPriority(
565 HANDLE hthread
, /* [in] Handle to thread */
566 INT priority
) /* [in] Thread priority level */
568 struct set_thread_info_request
*req
= get_req_buffer();
569 req
->handle
= hthread
;
570 req
->priority
= priority
;
571 req
->mask
= SET_THREAD_INFO_PRIORITY
;
572 return !server_call( REQ_SET_THREAD_INFO
);
576 /**********************************************************************
577 * SetThreadAffinityMask (KERNEL32.669)
579 DWORD WINAPI
SetThreadAffinityMask( HANDLE hThread
, DWORD dwThreadAffinityMask
)
581 struct set_thread_info_request
*req
= get_req_buffer();
582 req
->handle
= hThread
;
583 req
->affinity
= dwThreadAffinityMask
;
584 req
->mask
= SET_THREAD_INFO_AFFINITY
;
585 if (server_call( REQ_SET_THREAD_INFO
)) return 0;
586 return 1; /* FIXME: should return previous value */
590 /**********************************************************************
591 * TerminateThread [KERNEL32.685] Terminates a thread
597 BOOL WINAPI
TerminateThread(
598 HANDLE handle
, /* [in] Handle to thread */
599 DWORD exitcode
) /* [in] Exit code for thread */
602 struct terminate_thread_request
*req
= get_req_buffer();
603 req
->handle
= handle
;
604 req
->exit_code
= exitcode
;
605 if ((ret
= !server_call( REQ_TERMINATE_THREAD
)) && req
->self
)
607 PROCESS_CallUserSignalProc( USIG_THREAD_EXIT
, 0 );
608 if (req
->last
) exit( exitcode
);
609 else SYSDEPS_ExitThread( exitcode
);
615 /**********************************************************************
616 * GetExitCodeThread [KERNEL32.???] Gets termination status of thread.
622 BOOL WINAPI
GetExitCodeThread(
623 HANDLE hthread
, /* [in] Handle to thread */
624 LPDWORD exitcode
) /* [out] Address to receive termination status */
627 struct get_thread_info_request
*req
= get_req_buffer();
628 req
->handle
= hthread
;
630 if (!server_call( REQ_GET_THREAD_INFO
))
632 if (exitcode
) *exitcode
= req
->exit_code
;
639 /**********************************************************************
640 * ResumeThread [KERNEL32.587] Resumes a thread.
642 * Decrements a thread's suspend count. When count is zero, the
643 * execution of the thread is resumed.
646 * Success: Previous suspend count
647 * Failure: 0xFFFFFFFF
650 DWORD WINAPI
ResumeThread(
651 HANDLE hthread
) /* [in] Identifies thread to restart */
653 DWORD ret
= 0xffffffff;
654 struct resume_thread_request
*req
= get_req_buffer();
655 req
->handle
= hthread
;
656 if (!server_call( REQ_RESUME_THREAD
)) ret
= req
->count
;
661 /**********************************************************************
662 * SuspendThread [KERNEL32.681] Suspends a thread.
665 * Success: Previous suspend count
666 * Failure: 0xFFFFFFFF
668 DWORD WINAPI
SuspendThread(
669 HANDLE hthread
) /* [in] Handle to the thread */
671 DWORD ret
= 0xffffffff;
672 struct suspend_thread_request
*req
= get_req_buffer();
673 req
->handle
= hthread
;
674 if (!server_call( REQ_SUSPEND_THREAD
)) ret
= req
->count
;
679 /***********************************************************************
680 * QueueUserAPC (KERNEL32.566)
682 DWORD WINAPI
QueueUserAPC( PAPCFUNC func
, HANDLE hthread
, ULONG_PTR data
)
684 struct queue_apc_request
*req
= get_req_buffer();
685 req
->handle
= hthread
;
687 req
->param
= (void *)data
;
688 return !server_call( REQ_QUEUE_APC
);
692 /**********************************************************************
693 * GetThreadTimes [KERNEL32.???] Obtains timing information.
696 * What are the fields where these values are stored?
702 BOOL WINAPI
GetThreadTimes(
703 HANDLE thread
, /* [in] Specifies the thread of interest */
704 LPFILETIME creationtime
, /* [out] When the thread was created */
705 LPFILETIME exittime
, /* [out] When the thread was destroyed */
706 LPFILETIME kerneltime
, /* [out] Time thread spent in kernel mode */
707 LPFILETIME usertime
) /* [out] Time thread spent in user mode */
709 FIXME("(0x%08x): stub\n",thread
);
710 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
715 /**********************************************************************
716 * AttachThreadInput [KERNEL32.8] Attaches input of 1 thread to other
718 * Attaches the input processing mechanism of one thread to that of
726 * 1. Reset the Key State (currenly per thread key state is not maintained)
728 BOOL WINAPI
AttachThreadInput(
729 DWORD idAttach
, /* [in] Thread to attach */
730 DWORD idAttachTo
, /* [in] Thread to attach to */
731 BOOL fAttach
) /* [in] Attach or detach */
733 MESSAGEQUEUE
*pSrcMsgQ
= 0, *pTgtMsgQ
= 0;
736 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
738 /* A thread cannot attach to itself */
739 if ( idAttach
== idAttachTo
)
742 /* According to the docs this method should fail if a
743 * "Journal record" hook is installed. (attaches all input queues together)
745 if ( HOOK_IsHooked( WH_JOURNALRECORD
) )
748 /* Retrieve message queues corresponding to the thread id's */
749 pTgtMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttach
) );
750 pSrcMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttachTo
) );
752 /* Ensure we have message queues and that Src and Tgt threads
753 * are not system threads.
755 if ( !pSrcMsgQ
|| !pTgtMsgQ
|| !pSrcMsgQ
->pQData
|| !pTgtMsgQ
->pQData
)
758 if (fAttach
) /* Attach threads */
760 /* Only attach if currently detached */
761 if ( pTgtMsgQ
->pQData
!= pSrcMsgQ
->pQData
)
763 /* First release the target threads perQData */
764 PERQDATA_Release( pTgtMsgQ
->pQData
);
766 /* Share a reference to the source threads perQDATA */
767 PERQDATA_Addref( pSrcMsgQ
->pQData
);
768 pTgtMsgQ
->pQData
= pSrcMsgQ
->pQData
;
771 else /* Detach threads */
773 /* Only detach if currently attached */
774 if ( pTgtMsgQ
->pQData
== pSrcMsgQ
->pQData
)
776 /* First release the target threads perQData */
777 PERQDATA_Release( pTgtMsgQ
->pQData
);
779 /* Give the target thread its own private perQDATA once more */
780 pTgtMsgQ
->pQData
= PERQDATA_CreateInstance();
784 /* TODO: Reset the Key State */
786 bRet
= 1; /* Success */
790 /* Unlock the queues before returning */
792 QUEUE_Unlock( pSrcMsgQ
);
794 QUEUE_Unlock( pTgtMsgQ
);
799 /**********************************************************************
800 * VWin32_BoostThreadGroup [KERNEL.535]
802 VOID WINAPI
VWin32_BoostThreadGroup( DWORD threadId
, INT boost
)
804 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
807 /**********************************************************************
808 * VWin32_BoostThreadStatic [KERNEL.536]
810 VOID WINAPI
VWin32_BoostThreadStatic( DWORD threadId
, INT boost
)
812 FIXME("(0x%08lx,%d): stub\n", threadId
, boost
);
816 /***********************************************************************
817 * GetThreadLocale (KERNEL32.295)
819 LCID WINAPI
GetThreadLocale(void)
821 return NtCurrentTeb()->CurrentLocale
;
825 /**********************************************************************
826 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
833 * check if lcid is a valid cp
835 BOOL WINAPI
SetThreadLocale(
836 LCID lcid
) /* [in] Locale identifier */
840 case LOCALE_SYSTEM_DEFAULT
:
841 lcid
= GetSystemDefaultLCID();
843 case LOCALE_USER_DEFAULT
:
845 lcid
= GetUserDefaultLCID();
848 NtCurrentTeb()->CurrentLocale
= lcid
;
853 /***********************************************************************
854 * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
857 * Pseudohandle for the current thread
859 #undef GetCurrentThread
860 HANDLE WINAPI
GetCurrentThread(void)
868 /* void WINAPI SetLastError( DWORD error ); */
869 __ASM_GLOBAL_FUNC( SetLastError
,
870 "movl 4(%esp),%eax\n\t"
875 /* DWORD WINAPI GetLastError(void); */
876 __ASM_GLOBAL_FUNC( GetLastError
, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
878 /* DWORD WINAPI GetCurrentProcessId(void) */
879 __ASM_GLOBAL_FUNC( GetCurrentProcessId
, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
881 /* DWORD WINAPI GetCurrentThreadId(void) */
882 __ASM_GLOBAL_FUNC( GetCurrentThreadId
, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
886 /**********************************************************************
887 * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code.
889 void WINAPI
SetLastError( DWORD error
) /* [in] Per-thread error code */
891 NtCurrentTeb()->last_error
= error
;
894 /**********************************************************************
895 * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code.
897 DWORD WINAPI
GetLastError(void)
899 return NtCurrentTeb()->last_error
;
902 /***********************************************************************
903 * GetCurrentProcessId [KERNEL32.199] Returns process identifier.
905 DWORD WINAPI
GetCurrentProcessId(void)
907 return (DWORD
)NtCurrentTeb()->pid
;
910 /***********************************************************************
911 * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
913 DWORD WINAPI
GetCurrentThreadId(void)
915 return (DWORD
)NtCurrentTeb()->tid
;
918 #endif /* __i386__ */