Added a few missing stubs to KERNEL32 and USER32.
[wine.git] / scheduler / thread.c
blob2410c4c37fac92525a8251481d675bb478ace756
1 /*
2 * Win32 threads
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <assert.h>
10 #include <fcntl.h>
11 #include <sys/types.h>
12 #ifdef HAVE_SYS_MMAN_H
13 #include <sys/mman.h>
14 #endif
15 #include <unistd.h>
16 #include "wine/winbase16.h"
17 #include "wine/port.h"
18 #include "thread.h"
19 #include "task.h"
20 #include "module.h"
21 #include "winerror.h"
22 #include "heap.h"
23 #include "selectors.h"
24 #include "winnt.h"
25 #include "server.h"
26 #include "services.h"
27 #include "stackframe.h"
28 #include "builtin16.h"
29 #include "debugtools.h"
30 #include "winnls.h"
32 DEFAULT_DEBUG_CHANNEL(thread);
34 /* TEB of the initial thread */
35 static TEB initial_teb;
37 extern struct _PDB current_process;
39 /***********************************************************************
40 * THREAD_IsWin16
42 BOOL THREAD_IsWin16( TEB *teb )
44 return !teb || !(teb->tibflags & TEBF_WIN32);
47 /***********************************************************************
48 * THREAD_IdToTEB
50 * Convert a thread id to a TEB, making sure it is valid.
52 TEB *THREAD_IdToTEB( DWORD id )
54 TEB *ret = NULL;
56 if (!id || id == GetCurrentThreadId()) return NtCurrentTeb();
58 SERVER_START_REQ
60 struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 );
61 req->handle = 0;
62 req->tid_in = (void *)id;
63 if (!server_call_noerr( REQ_GET_THREAD_INFO )) ret = req->teb;
65 SERVER_END_REQ;
67 if (!ret)
69 /* Allow task handles to be used; convert to main thread */
70 if ( IsTask16( id ) )
72 TDB *pTask = (TDB *)GlobalLock16( id );
73 if (pTask) return pTask->teb;
75 SetLastError( ERROR_INVALID_PARAMETER );
77 return ret;
81 /***********************************************************************
82 * THREAD_InitTEB
84 * Initialization of a newly created TEB.
86 static BOOL THREAD_InitTEB( TEB *teb )
88 teb->except = (void *)~0UL;
89 teb->self = teb;
90 teb->tibflags = TEBF_WIN32;
91 teb->tls_ptr = teb->tls_array;
92 teb->exit_code = STILL_ACTIVE;
93 teb->socket = -1;
94 teb->request_fd = -1;
95 teb->reply_fd = -1;
96 teb->wait_fd = -1;
97 teb->stack_top = (void *)~0UL;
98 teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
99 teb->StaticUnicodeString.Buffer = (PWSTR)teb->StaticUnicodeBuffer;
100 teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, WINE_LDT_FLAGS_DATA|WINE_LDT_FLAGS_32BIT );
101 return (teb->teb_sel != 0);
105 /***********************************************************************
106 * THREAD_FreeTEB
108 * Free data structures associated with a thread.
109 * Must be called from the context of another thread.
111 static void CALLBACK THREAD_FreeTEB( TEB *teb )
113 TRACE("(%p) called\n", teb );
114 if (teb->cleanup) SERVICE_Delete( teb->cleanup );
116 /* Free the associated memory */
118 if (teb->socket != -1) close( teb->socket );
119 close( teb->request_fd );
120 close( teb->reply_fd );
121 close( teb->wait_fd );
122 if (teb->stack_sel) FreeSelector16( teb->stack_sel );
123 FreeSelector16( teb->teb_sel );
124 if (teb->buffer) munmap( (void *)teb->buffer,
125 (char *)(teb->buffer_info+1) - (char *)teb->buffer );
126 if (teb->debug_info) HeapFree( GetProcessHeap(), 0, teb->debug_info );
127 VirtualFree( teb->stack_base, 0, MEM_RELEASE );
131 /***********************************************************************
132 * THREAD_InitStack
134 * Allocate the stack of a thread.
136 TEB *THREAD_InitStack( TEB *teb, DWORD stack_size, BOOL alloc_stack16 )
138 DWORD old_prot, total_size;
139 DWORD page_size = getpagesize();
140 void *base;
142 /* Allocate the stack */
144 if (stack_size >= 16*1024*1024)
145 WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024);
147 /* if size is smaller than default, get stack size from parent */
148 if (stack_size < 1024 * 1024)
150 if (teb)
151 stack_size = 1024 * 1024; /* no parent */
152 else
153 stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->stack_base
154 - SIGNAL_STACK_SIZE - 3 * page_size);
157 /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */
158 stack_size += 64 * 1024;
160 /* Memory layout in allocated block:
162 * size contents
163 * 1 page NOACCESS guard page
164 * SIGNAL_STACK_SIZE signal stack
165 * 1 page NOACCESS guard page
166 * 1 page PAGE_GUARD guard page
167 * stack_size normal stack
168 * 64Kb 16-bit stack (optional)
169 * 1 page TEB (except for initial thread)
172 stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
173 total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size;
174 if (alloc_stack16) total_size += 0x10000;
175 if (!teb) total_size += page_size;
177 if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
178 return NULL;
180 if (!teb)
182 teb = (TEB *)((char *)base + total_size - page_size);
183 if (!THREAD_InitTEB( teb ))
185 VirtualFree( base, 0, MEM_RELEASE );
186 return NULL;
190 teb->stack_low = base;
191 teb->stack_base = base;
192 teb->signal_stack = (char *)base + page_size;
193 teb->stack_top = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size;
195 /* Setup guard pages */
197 VirtualProtect( base, 1, PAGE_NOACCESS, &old_prot );
198 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot );
199 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1,
200 PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
202 /* Allocate the 16-bit stack selector */
204 if (alloc_stack16)
206 teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, WINE_LDT_FLAGS_DATA );
207 if (!teb->stack_sel) goto error;
208 teb->cur_stack = MAKESEGPTR( teb->stack_sel, 0x10000 - sizeof(STACK16FRAME) );
210 return teb;
212 error:
213 THREAD_FreeTEB( teb );
214 return NULL;
218 /***********************************************************************
219 * thread_errno_location
221 * Get the per-thread errno location.
223 static int *thread_errno_location(void)
225 return &NtCurrentTeb()->thread_errno;
228 /***********************************************************************
229 * thread_h_errno_location
231 * Get the per-thread h_errno location.
233 static int *thread_h_errno_location(void)
235 return &NtCurrentTeb()->thread_h_errno;
238 /***********************************************************************
239 * THREAD_Init
241 * Setup the initial thread.
243 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
245 void THREAD_Init(void)
247 if (!initial_teb.self) /* do it only once */
249 THREAD_InitTEB( &initial_teb );
250 assert( initial_teb.teb_sel );
251 initial_teb.process = &current_process;
252 SYSDEPS_SetCurThread( &initial_teb );
253 wine_errno_location = thread_errno_location;
254 wine_h_errno_location = thread_h_errno_location;
258 DECL_GLOBAL_CONSTRUCTOR(thread_init) { THREAD_Init(); }
260 /***********************************************************************
261 * THREAD_Create
264 TEB *THREAD_Create( int fd, DWORD stack_size, BOOL alloc_stack16 )
266 TEB *teb;
268 if ((teb = THREAD_InitStack( NULL, stack_size, alloc_stack16 )))
270 teb->tibflags = TEBF_WIN32;
271 teb->process = NtCurrentTeb()->process;
272 teb->socket = fd;
273 fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */
274 TRACE("(%p) succeeded\n", teb);
276 return teb;
280 /***********************************************************************
281 * THREAD_Start
283 * Start execution of a newly created thread. Does not return.
285 static void THREAD_Start(void)
287 HANDLE cleanup_object;
288 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point;
290 /* install cleanup handler */
291 if (DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
292 GetCurrentProcess(), &cleanup_object,
293 0, FALSE, DUPLICATE_SAME_ACCESS ))
294 NtCurrentTeb()->cleanup = SERVICE_AddObject( cleanup_object, (PAPCFUNC)THREAD_FreeTEB,
295 (ULONG_PTR)NtCurrentTeb() );
297 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
298 PE_InitTls();
299 MODULE_DllThreadAttach( NULL );
300 ExitThread( func( NtCurrentTeb()->entry_arg ) );
304 /***********************************************************************
305 * CreateThread (KERNEL32.@)
307 HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
308 LPTHREAD_START_ROUTINE start, LPVOID param,
309 DWORD flags, LPDWORD id )
311 int socket = -1;
312 HANDLE handle = 0;
313 TEB *teb;
314 void *tid = 0;
316 SERVER_START_REQ
318 struct new_thread_request *req = server_alloc_req( sizeof(*req), 0 );
320 req->suspend = ((flags & CREATE_SUSPENDED) != 0);
321 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
322 if (!server_call( REQ_NEW_THREAD ))
324 handle = req->handle;
325 tid = req->tid;
326 socket = wine_server_recv_fd( handle, 0 );
329 SERVER_END_REQ;
330 if (!handle) return 0;
332 if (!(teb = THREAD_Create( socket, stack, TRUE )))
334 close( socket );
335 return 0;
337 teb->entry_point = start;
338 teb->entry_arg = param;
339 teb->startup = THREAD_Start;
340 teb->htask16 = GetCurrentTask();
341 if (id) *id = (DWORD)tid;
342 if (SYSDEPS_SpawnThread( teb ) == -1)
344 CloseHandle( handle );
345 THREAD_FreeTEB( teb );
346 return 0;
348 return handle;
351 /***********************************************************************
352 * CreateThread16 (KERNEL.441)
354 static DWORD CALLBACK THREAD_StartThread16( LPVOID threadArgs )
356 FARPROC16 start = ((FARPROC16 *)threadArgs)[0];
357 DWORD param = ((DWORD *)threadArgs)[1];
358 HeapFree( GetProcessHeap(), 0, threadArgs );
360 ((LPDWORD)CURRENT_STACK16)[-1] = param;
361 return wine_call_to_16_long( start, sizeof(DWORD) );
363 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
364 FARPROC16 start, SEGPTR param,
365 DWORD flags, LPDWORD id )
367 DWORD *threadArgs = HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD) );
368 if (!threadArgs) return INVALID_HANDLE_VALUE;
369 threadArgs[0] = (DWORD)start;
370 threadArgs[1] = (DWORD)param;
372 return CreateThread( sa, stack, THREAD_StartThread16, threadArgs, flags, id );
376 /***********************************************************************
377 * ExitThread [KERNEL32.215] Ends a thread
379 * RETURNS
380 * None
382 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
384 BOOL last;
385 SERVER_START_REQ
387 struct terminate_thread_request *req = server_alloc_req( sizeof(*req), 0 );
389 /* send the exit code to the server */
390 req->handle = GetCurrentThread();
391 req->exit_code = code;
392 server_call( REQ_TERMINATE_THREAD );
393 last = req->last;
395 SERVER_END_REQ;
397 if (last)
399 MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
400 exit( code );
402 else
404 MODULE_DllThreadDetach( NULL );
405 if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
406 SYSDEPS_ExitThread( code );
411 /***********************************************************************
412 * SetThreadContext [KERNEL32.670] Sets context of thread.
414 * RETURNS
415 * Success: TRUE
416 * Failure: FALSE
418 BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
419 const CONTEXT *context ) /* [in] Address of context structure */
421 BOOL ret;
422 SERVER_START_REQ
424 struct set_thread_context_request *req = server_alloc_req( sizeof(*req),
425 sizeof(*context) );
426 req->handle = handle;
427 req->flags = context->ContextFlags;
428 memcpy( server_data_ptr(req), context, sizeof(*context) );
429 ret = !server_call( REQ_SET_THREAD_CONTEXT );
431 SERVER_END_REQ;
432 return ret;
436 /***********************************************************************
437 * GetThreadContext [KERNEL32.@] Retrieves context of thread.
439 * RETURNS
440 * Success: TRUE
441 * Failure: FALSE
443 BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
444 CONTEXT *context ) /* [out] Address of context structure */
446 BOOL ret;
447 SERVER_START_REQ
449 struct get_thread_context_request *req = server_alloc_req( sizeof(*req),
450 sizeof(*context) );
451 req->handle = handle;
452 req->flags = context->ContextFlags;
453 memcpy( server_data_ptr(req), context, sizeof(*context) );
454 if ((ret = !server_call( REQ_GET_THREAD_CONTEXT )))
455 memcpy( context, server_data_ptr(req), sizeof(*context) );
457 SERVER_END_REQ;
458 return ret;
462 /**********************************************************************
463 * GetThreadPriority [KERNEL32.@] Returns priority for thread.
465 * RETURNS
466 * Success: Thread's priority level.
467 * Failure: THREAD_PRIORITY_ERROR_RETURN
469 INT WINAPI GetThreadPriority(
470 HANDLE hthread) /* [in] Handle to thread */
472 INT ret = THREAD_PRIORITY_ERROR_RETURN;
473 SERVER_START_REQ
475 struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 );
476 req->handle = hthread;
477 req->tid_in = 0;
478 if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority;
480 SERVER_END_REQ;
481 return ret;
485 /**********************************************************************
486 * SetThreadPriority [KERNEL32.@] Sets priority for thread.
488 * RETURNS
489 * Success: TRUE
490 * Failure: FALSE
492 BOOL WINAPI SetThreadPriority(
493 HANDLE hthread, /* [in] Handle to thread */
494 INT priority) /* [in] Thread priority level */
496 BOOL ret;
497 SERVER_START_REQ
499 struct set_thread_info_request *req = server_alloc_req( sizeof(*req), 0 );
500 req->handle = hthread;
501 req->priority = priority;
502 req->mask = SET_THREAD_INFO_PRIORITY;
503 ret = !server_call( REQ_SET_THREAD_INFO );
505 SERVER_END_REQ;
506 return ret;
510 /**********************************************************************
511 * GetThreadPriorityBoost [KERNEL32.877] Returns priority boost for thread.
513 * Always reports that priority boost is disabled.
515 * RETURNS
516 * Success: TRUE.
517 * Failure: FALSE
519 BOOL WINAPI GetThreadPriorityBoost(
520 HANDLE hthread, /* [in] Handle to thread */
521 PBOOL pstate) /* [out] pointer to var that receives the boost state */
523 if (pstate) *pstate = FALSE;
524 return NO_ERROR;
528 /**********************************************************************
529 * SetThreadPriorityBoost [KERNEL32.893] Sets priority boost for thread.
531 * Priority boost is not implemented. Thsi function always returns
532 * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
534 * RETURNS
535 * Always returns FALSE to indicate a failure
537 BOOL WINAPI SetThreadPriorityBoost(
538 HANDLE hthread, /* [in] Handle to thread */
539 BOOL disable) /* [in] TRUE to disable priority boost */
541 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
542 return FALSE;
546 /**********************************************************************
547 * SetThreadAffinityMask (KERNEL32.669)
549 DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
551 DWORD ret;
552 SERVER_START_REQ
554 struct set_thread_info_request *req = server_alloc_req( sizeof(*req), 0 );
555 req->handle = hThread;
556 req->affinity = dwThreadAffinityMask;
557 req->mask = SET_THREAD_INFO_AFFINITY;
558 ret = !server_call( REQ_SET_THREAD_INFO );
559 /* FIXME: should return previous value */
561 SERVER_END_REQ;
562 return ret;
566 /**********************************************************************
567 * TerminateThread [KERNEL32.685] Terminates a thread
569 * RETURNS
570 * Success: TRUE
571 * Failure: FALSE
573 BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */
574 DWORD exit_code) /* [in] Exit code for thread */
576 NTSTATUS status = NtTerminateThread( handle, exit_code );
577 if (status) SetLastError( RtlNtStatusToDosError(status) );
578 return !status;
582 /**********************************************************************
583 * GetExitCodeThread (KERNEL32.@)
584 * GetExitCodeThread (WIN32S16.13)
586 * Gets termination status of thread.
588 * RETURNS
589 * Success: TRUE
590 * Failure: FALSE
592 BOOL WINAPI GetExitCodeThread(
593 HANDLE hthread, /* [in] Handle to thread */
594 LPDWORD exitcode) /* [out] Address to receive termination status */
596 BOOL ret;
597 SERVER_START_REQ
599 struct get_thread_info_request *req = server_alloc_req( sizeof(*req), 0 );
600 req->handle = hthread;
601 req->tid_in = 0;
602 ret = !server_call( REQ_GET_THREAD_INFO );
603 if (ret && exitcode) *exitcode = req->exit_code;
605 SERVER_END_REQ;
606 return ret;
610 /**********************************************************************
611 * ResumeThread [KERNEL32.587] Resumes a thread.
613 * Decrements a thread's suspend count. When count is zero, the
614 * execution of the thread is resumed.
616 * RETURNS
617 * Success: Previous suspend count
618 * Failure: 0xFFFFFFFF
619 * Already running: 0
621 DWORD WINAPI ResumeThread(
622 HANDLE hthread) /* [in] Identifies thread to restart */
624 DWORD ret = 0xffffffff;
625 SERVER_START_REQ
627 struct resume_thread_request *req = server_alloc_req( sizeof(*req), 0 );
628 req->handle = hthread;
629 if (!server_call( REQ_RESUME_THREAD )) ret = req->count;
631 SERVER_END_REQ;
632 return ret;
636 /**********************************************************************
637 * SuspendThread [KERNEL32.681] Suspends a thread.
639 * RETURNS
640 * Success: Previous suspend count
641 * Failure: 0xFFFFFFFF
643 DWORD WINAPI SuspendThread(
644 HANDLE hthread) /* [in] Handle to the thread */
646 DWORD ret = 0xffffffff;
647 SERVER_START_REQ
649 struct suspend_thread_request *req = server_alloc_req( sizeof(*req), 0 );
650 req->handle = hthread;
651 if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count;
653 SERVER_END_REQ;
654 return ret;
658 /***********************************************************************
659 * QueueUserAPC (KERNEL32.566)
661 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
663 DWORD ret;
664 SERVER_START_REQ
666 struct queue_apc_request *req = server_alloc_req( sizeof(*req), 0 );
667 req->handle = hthread;
668 req->user = 1;
669 req->func = func;
670 req->param = (void *)data;
671 ret = !server_call( REQ_QUEUE_APC );
673 SERVER_END_REQ;
674 return ret;
678 /**********************************************************************
679 * GetThreadTimes [KERNEL32.@] Obtains timing information.
681 * NOTES
682 * What are the fields where these values are stored?
684 * RETURNS
685 * Success: TRUE
686 * Failure: FALSE
688 BOOL WINAPI GetThreadTimes(
689 HANDLE thread, /* [in] Specifies the thread of interest */
690 LPFILETIME creationtime, /* [out] When the thread was created */
691 LPFILETIME exittime, /* [out] When the thread was destroyed */
692 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
693 LPFILETIME usertime) /* [out] Time thread spent in user mode */
695 FIXME("(0x%08x): stub\n",thread);
696 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
697 return FALSE;
701 /**********************************************************************
702 * VWin32_BoostThreadGroup [KERNEL.535]
704 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
706 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
709 /**********************************************************************
710 * VWin32_BoostThreadStatic [KERNEL.536]
712 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
714 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
718 /***********************************************************************
719 * GetThreadLocale (KERNEL32.@)
721 LCID WINAPI GetThreadLocale(void)
723 LCID ret = NtCurrentTeb()->CurrentLocale;
724 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
725 return ret;
729 /**********************************************************************
730 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
732 * RETURNS
733 * Success: TRUE
734 * Failure: FALSE
736 * FIXME
737 * check if lcid is a valid cp
739 BOOL WINAPI SetThreadLocale(
740 LCID lcid) /* [in] Locale identifier */
742 switch (lcid)
744 case LOCALE_SYSTEM_DEFAULT:
745 lcid = GetSystemDefaultLCID();
746 break;
747 case LOCALE_USER_DEFAULT:
748 case LOCALE_NEUTRAL:
749 lcid = GetUserDefaultLCID();
750 break;
752 NtCurrentTeb()->CurrentLocale = lcid;
753 return TRUE;
757 /***********************************************************************
758 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
760 * RETURNS
761 * Pseudohandle for the current thread
763 #undef GetCurrentThread
764 HANDLE WINAPI GetCurrentThread(void)
766 return 0xfffffffe;
770 /***********************************************************************
771 * ProcessIdToSessionId (KERNEL32.@)
772 * This function is available on Terminal Server 4SP4 and Windows 2000
774 BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
776 /* According to MSDN, if the calling process is not in a terminal
777 * services environment, then the sessionid returned is zero.
779 *sessionid_ptr = 0;
780 return TRUE;
784 #ifdef __i386__
786 /* void WINAPI SetLastError( DWORD error ); */
787 __ASM_GLOBAL_FUNC( SetLastError,
788 "movl 4(%esp),%eax\n\t"
789 ".byte 0x64\n\t"
790 "movl %eax,0x60\n\t"
791 "ret $4" );
793 /* DWORD WINAPI GetLastError(void); */
794 __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
796 /* DWORD WINAPI GetCurrentProcessId(void) */
797 __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
799 /* DWORD WINAPI GetCurrentThreadId(void) */
800 __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
802 #else /* __i386__ */
804 /**********************************************************************
805 * SetLastError (KERNEL.147)
806 * SetLastError (KERNEL32.@)
808 * Sets the last-error code.
810 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
812 NtCurrentTeb()->last_error = error;
815 /**********************************************************************
816 * GetLastError (KERNEL.10)
817 * GetLastError (KERNEL32.@)
818 * GetLastError (WIN32S16.10)
820 * Returns last-error code.
822 DWORD WINAPI GetLastError(void)
824 return NtCurrentTeb()->last_error;
827 /***********************************************************************
828 * GetCurrentProcessId (KERNEL.471)
829 * GetCurrentProcessId (KERNEL32.@)
831 * Returns process identifier.
833 DWORD WINAPI GetCurrentProcessId(void)
835 return (DWORD)NtCurrentTeb()->pid;
838 /***********************************************************************
839 * GetCurrentThreadId (KERNEL.462)
840 * GetCurrentThreadId (KERNEL32.@)
842 * Returns thread identifier.
844 DWORD WINAPI GetCurrentThreadId(void)
846 return (DWORD)NtCurrentTeb()->tid;
849 #endif /* __i386__ */