Implemented NtQueueApcThread, and changed the server APC interface to
[wine/wine64.git] / scheduler / thread.c
blob6d5ad887ba2632a7357b1933e1e37c84f7bb6bc8
1 /*
2 * Win32 threads
4 * Copyright 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #ifdef HAVE_SYS_MMAN_H
28 #include <sys/mman.h>
29 #endif
30 #ifdef HAVE_SYS_TIMES_H
31 #include <sys/times.h>
32 #endif
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include "wine/winbase16.h"
37 #include "thread.h"
38 #include "task.h"
39 #include "module.h"
40 #include "winerror.h"
41 #include "selectors.h"
42 #include "winnt.h"
43 #include "wine/server.h"
44 #include "stackframe.h"
45 #include "wine/debug.h"
46 #include "winnls.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(thread);
49 WINE_DECLARE_DEBUG_CHANNEL(relay);
51 /* TEB of the initial thread */
52 static TEB initial_teb;
54 extern struct _PDB current_process;
56 /***********************************************************************
57 * THREAD_IdToTEB
59 * Convert a thread id to a TEB, making sure it is valid.
61 TEB *THREAD_IdToTEB( DWORD id )
63 TEB *ret = NULL;
65 if (!id || id == GetCurrentThreadId()) return NtCurrentTeb();
67 SERVER_START_REQ( get_thread_info )
69 req->handle = 0;
70 req->tid_in = id;
71 if (!wine_server_call( req )) ret = reply->teb;
73 SERVER_END_REQ;
75 if (!ret)
77 /* Allow task handles to be used; convert to main thread */
78 if ( IsTask16( id ) )
80 TDB *pTask = TASK_GetPtr( id );
81 if (pTask) return pTask->teb;
83 SetLastError( ERROR_INVALID_PARAMETER );
85 return ret;
89 /***********************************************************************
90 * THREAD_InitTEB
92 * Initialization of a newly created TEB.
94 static BOOL THREAD_InitTEB( TEB *teb )
96 teb->except = (void *)~0UL;
97 teb->self = teb;
98 teb->tibflags = TEBF_WIN32;
99 teb->tls_ptr = teb->tls_array;
100 teb->exit_code = STILL_ACTIVE;
101 teb->request_fd = -1;
102 teb->reply_fd = -1;
103 teb->wait_fd[0] = -1;
104 teb->wait_fd[1] = -1;
105 teb->stack_top = (void *)~0UL;
106 teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
107 teb->StaticUnicodeString.Buffer = (PWSTR)teb->StaticUnicodeBuffer;
108 teb->teb_sel = wine_ldt_alloc_fs();
109 return (teb->teb_sel != 0);
113 /***********************************************************************
114 * THREAD_FreeTEB
116 * Free data structures associated with a thread.
117 * Must be called from the context of another thread.
119 static void THREAD_FreeTEB( TEB *teb )
121 TRACE("(%p) called\n", teb );
122 /* Free the associated memory */
123 wine_ldt_free_entries( teb->stack_sel, 1 );
124 wine_ldt_free_fs( teb->teb_sel );
125 VirtualFree( teb->stack_base, 0, MEM_RELEASE );
129 /***********************************************************************
130 * THREAD_InitStack
132 * Allocate the stack of a thread.
134 TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
136 DWORD old_prot, total_size;
137 DWORD page_size = getpagesize();
138 void *base;
140 /* Allocate the stack */
142 if (stack_size >= 16*1024*1024)
143 WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024);
145 /* if size is smaller than default, get stack size from parent */
146 if (stack_size < 1024 * 1024)
148 if (teb)
149 stack_size = 1024 * 1024; /* no parent */
150 else
151 stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->stack_base
152 - SIGNAL_STACK_SIZE - 3 * page_size);
155 /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */
156 stack_size += 64 * 1024;
158 /* Memory layout in allocated block:
160 * size contents
161 * 1 page NOACCESS guard page
162 * SIGNAL_STACK_SIZE signal stack
163 * 1 page NOACCESS guard page
164 * 1 page PAGE_GUARD guard page
165 * stack_size normal stack
166 * 64Kb 16-bit stack (optional)
167 * 1 page TEB (except for initial thread)
168 * 1 page debug info (except for initial thread)
171 stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
172 total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size;
173 total_size += 0x10000; /* 16-bit stack */
174 if (!teb) total_size += 2 * page_size;
176 if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
177 return NULL;
179 if (!teb)
181 teb = (TEB *)((char *)base + total_size - 2 * page_size);
182 if (!THREAD_InitTEB( teb )) goto error;
183 teb->debug_info = (char *)teb + page_size;
186 teb->stack_low = base;
187 teb->stack_base = base;
188 teb->signal_stack = (char *)base + page_size;
189 teb->stack_top = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size;
191 /* Setup guard pages */
193 VirtualProtect( base, 1, PAGE_NOACCESS, &old_prot );
194 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot );
195 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1,
196 PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
198 /* Allocate the 16-bit stack selector */
200 teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, WINE_LDT_FLAGS_DATA );
201 if (!teb->stack_sel) goto error;
202 teb->cur_stack = MAKESEGPTR( teb->stack_sel, 0x10000 - sizeof(STACK16FRAME) );
204 return teb;
206 error:
207 wine_ldt_free_fs( teb->teb_sel );
208 VirtualFree( base, 0, MEM_RELEASE );
209 return NULL;
213 /***********************************************************************
214 * THREAD_Init
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 = &current_process;
227 SYSDEPS_SetCurThread( &initial_teb );
228 SYSDEPS_InitErrno();
232 DECL_GLOBAL_CONSTRUCTOR(thread_init) { THREAD_Init(); }
235 /***********************************************************************
236 * THREAD_Start
238 * Start execution of a newly created thread. Does not return.
240 static void THREAD_Start(void)
242 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point;
244 if (TRACE_ON(relay))
245 DPRINTF("%04lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func );
247 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
248 MODULE_DllThreadAttach( NULL );
249 ExitThread( func( NtCurrentTeb()->entry_arg ) );
253 /***********************************************************************
254 * CreateThread (KERNEL32.@)
256 HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, SIZE_T stack,
257 LPTHREAD_START_ROUTINE start, LPVOID param,
258 DWORD flags, LPDWORD id )
260 HANDLE handle = 0;
261 TEB *teb;
262 DWORD tid = 0;
263 int request_pipe[2];
265 if (pipe( request_pipe ) == -1)
267 SetLastError( ERROR_TOO_MANY_OPEN_FILES );
268 return 0;
270 fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
271 wine_server_send_fd( request_pipe[0] );
273 SERVER_START_REQ( new_thread )
275 req->suspend = ((flags & CREATE_SUSPENDED) != 0);
276 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
277 req->request_fd = request_pipe[0];
278 if (!wine_server_call_err( req ))
280 handle = reply->handle;
281 tid = reply->tid;
283 close( request_pipe[0] );
285 SERVER_END_REQ;
287 if (!handle || !(teb = THREAD_InitStack( NULL, stack )))
289 close( request_pipe[1] );
290 return 0;
293 teb->process = NtCurrentTeb()->process;
294 teb->tid = tid;
295 teb->request_fd = request_pipe[1];
296 teb->entry_point = start;
297 teb->entry_arg = param;
298 teb->startup = THREAD_Start;
299 teb->htask16 = GetCurrentTask();
301 if (id) *id = tid;
302 if (SYSDEPS_SpawnThread( teb ) == -1)
304 CloseHandle( handle );
305 close( request_pipe[1] );
306 THREAD_FreeTEB( teb );
307 return 0;
309 return handle;
312 /***********************************************************************
313 * ExitThread [KERNEL32.@] Ends a thread
315 * RETURNS
316 * None
318 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
320 BOOL last;
321 SERVER_START_REQ( terminate_thread )
323 /* send the exit code to the server */
324 req->handle = GetCurrentThread();
325 req->exit_code = code;
326 wine_server_call( req );
327 last = reply->last;
329 SERVER_END_REQ;
331 if (last)
333 LdrShutdownProcess();
334 exit( code );
336 else
338 LdrShutdownThread();
339 if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
340 SYSDEPS_ExitThread( code );
344 /***********************************************************************
345 * OpenThread Retrieves a handle to a thread from its thread id
347 * RETURNS
348 * None
350 HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId )
352 HANDLE ret = 0;
353 SERVER_START_REQ( open_thread )
355 req->tid = dwThreadId;
356 req->access = dwDesiredAccess;
357 req->inherit = bInheritHandle;
358 if (!wine_server_call_err( req )) ret = reply->handle;
360 SERVER_END_REQ;
361 return ret;
364 /***********************************************************************
365 * SetThreadContext [KERNEL32.@] Sets context of thread.
367 * RETURNS
368 * Success: TRUE
369 * Failure: FALSE
371 BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
372 const CONTEXT *context ) /* [in] Address of context structure */
374 NTSTATUS status = NtSetContextThread( handle, context );
375 if (status) SetLastError( RtlNtStatusToDosError(status) );
376 return !status;
380 /***********************************************************************
381 * GetThreadContext [KERNEL32.@] Retrieves context of thread.
383 * RETURNS
384 * Success: TRUE
385 * Failure: FALSE
387 BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
388 CONTEXT *context ) /* [out] Address of context structure */
390 NTSTATUS status = NtGetContextThread( handle, context );
391 if (status) SetLastError( RtlNtStatusToDosError(status) );
392 return !status;
396 /**********************************************************************
397 * GetThreadPriority [KERNEL32.@] Returns priority for thread.
399 * RETURNS
400 * Success: Thread's priority level.
401 * Failure: THREAD_PRIORITY_ERROR_RETURN
403 INT WINAPI GetThreadPriority(
404 HANDLE hthread) /* [in] Handle to thread */
406 INT ret = THREAD_PRIORITY_ERROR_RETURN;
407 SERVER_START_REQ( get_thread_info )
409 req->handle = hthread;
410 req->tid_in = 0;
411 if (!wine_server_call_err( req )) ret = reply->priority;
413 SERVER_END_REQ;
414 return ret;
418 /**********************************************************************
419 * SetThreadPriority [KERNEL32.@] Sets priority for thread.
421 * RETURNS
422 * Success: TRUE
423 * Failure: FALSE
425 BOOL WINAPI SetThreadPriority(
426 HANDLE hthread, /* [in] Handle to thread */
427 INT priority) /* [in] Thread priority level */
429 BOOL ret;
430 SERVER_START_REQ( set_thread_info )
432 req->handle = hthread;
433 req->priority = priority;
434 req->mask = SET_THREAD_INFO_PRIORITY;
435 ret = !wine_server_call_err( req );
437 SERVER_END_REQ;
438 return ret;
442 /**********************************************************************
443 * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread.
445 * Always reports that priority boost is disabled.
447 * RETURNS
448 * Success: TRUE.
449 * Failure: FALSE
451 BOOL WINAPI GetThreadPriorityBoost(
452 HANDLE hthread, /* [in] Handle to thread */
453 PBOOL pstate) /* [out] pointer to var that receives the boost state */
455 if (pstate) *pstate = FALSE;
456 return NO_ERROR;
460 /**********************************************************************
461 * SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread.
463 * Priority boost is not implemented. Thsi function always returns
464 * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
466 * RETURNS
467 * Always returns FALSE to indicate a failure
469 BOOL WINAPI SetThreadPriorityBoost(
470 HANDLE hthread, /* [in] Handle to thread */
471 BOOL disable) /* [in] TRUE to disable priority boost */
473 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
474 return FALSE;
478 /**********************************************************************
479 * SetThreadAffinityMask (KERNEL32.@)
481 DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
483 DWORD ret;
484 SERVER_START_REQ( set_thread_info )
486 req->handle = hThread;
487 req->affinity = dwThreadAffinityMask;
488 req->mask = SET_THREAD_INFO_AFFINITY;
489 ret = !wine_server_call_err( req );
490 /* FIXME: should return previous value */
492 SERVER_END_REQ;
493 return ret;
496 /**********************************************************************
497 * SetThreadIdealProcessor [KERNEL32.@] Obtains timing information.
499 * RETURNS
500 * Success: Value of last call to SetThreadIdealProcessor
501 * Failure: -1
503 DWORD WINAPI SetThreadIdealProcessor(
504 HANDLE hThread, /* [in] Specifies the thread of interest */
505 DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */
507 FIXME("(%p): stub\n",hThread);
508 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
509 return -1L;
512 /**********************************************************************
513 * TerminateThread [KERNEL32.@] Terminates a thread
515 * RETURNS
516 * Success: TRUE
517 * Failure: FALSE
519 BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */
520 DWORD exit_code) /* [in] Exit code for thread */
522 NTSTATUS status = NtTerminateThread( handle, exit_code );
523 if (status) SetLastError( RtlNtStatusToDosError(status) );
524 return !status;
528 /**********************************************************************
529 * GetExitCodeThread (KERNEL32.@)
531 * Gets termination status of thread.
533 * RETURNS
534 * Success: TRUE
535 * Failure: FALSE
537 BOOL WINAPI GetExitCodeThread(
538 HANDLE hthread, /* [in] Handle to thread */
539 LPDWORD exitcode) /* [out] Address to receive termination status */
541 BOOL ret;
542 SERVER_START_REQ( get_thread_info )
544 req->handle = hthread;
545 req->tid_in = 0;
546 ret = !wine_server_call_err( req );
547 if (ret && exitcode) *exitcode = reply->exit_code;
549 SERVER_END_REQ;
550 return ret;
554 /**********************************************************************
555 * ResumeThread [KERNEL32.@] Resumes a thread.
557 * Decrements a thread's suspend count. When count is zero, the
558 * execution of the thread is resumed.
560 * RETURNS
561 * Success: Previous suspend count
562 * Failure: 0xFFFFFFFF
563 * Already running: 0
565 DWORD WINAPI ResumeThread( HANDLE hthread ) /* [in] Identifies thread to restart */
567 DWORD ret;
568 NTSTATUS status = NtResumeThread( hthread, &ret );
570 if (status)
572 ret = ~0U;
573 SetLastError( RtlNtStatusToDosError(status) );
575 return ret;
579 /**********************************************************************
580 * SuspendThread [KERNEL32.@] Suspends a thread.
582 * RETURNS
583 * Success: Previous suspend count
584 * Failure: 0xFFFFFFFF
586 DWORD WINAPI SuspendThread( HANDLE hthread ) /* [in] Handle to the thread */
588 DWORD ret;
589 NTSTATUS status = NtSuspendThread( hthread, &ret );
591 if (status)
593 ret = ~0U;
594 SetLastError( RtlNtStatusToDosError(status) );
596 return ret;
600 /* callback for QueueUserAPC */
601 static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
603 PAPCFUNC func = (PAPCFUNC)arg1;
604 func( arg2 );
607 /***********************************************************************
608 * QueueUserAPC (KERNEL32.@)
610 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
612 NTSTATUS status = NtQueueApcThread( hthread, call_user_apc, (ULONG_PTR)func, data, 0 );
614 if (status) SetLastError( RtlNtStatusToDosError(status) );
615 return !status;
619 /**********************************************************************
620 * GetThreadTimes [KERNEL32.@] Obtains timing information.
622 * RETURNS
623 * Success: TRUE
624 * Failure: FALSE
626 BOOL WINAPI GetThreadTimes(
627 HANDLE thread, /* [in] Specifies the thread of interest */
628 LPFILETIME creationtime, /* [out] When the thread was created */
629 LPFILETIME exittime, /* [out] When the thread was destroyed */
630 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
631 LPFILETIME usertime) /* [out] Time thread spent in user mode */
633 BOOL ret = TRUE;
635 if (creationtime || exittime)
637 /* We need to do a server call to get the creation time or exit time */
638 /* This works on any thread */
640 SERVER_START_REQ( get_thread_info )
642 req->handle = thread;
643 req->tid_in = 0;
644 if ((ret = !wine_server_call_err( req )))
646 if (creationtime)
647 RtlSecondsSince1970ToTime( reply->creation_time, (LARGE_INTEGER*)creationtime );
648 if (exittime)
649 RtlSecondsSince1970ToTime( reply->exit_time, (LARGE_INTEGER*)exittime );
652 SERVER_END_REQ;
654 if (ret && (kerneltime || usertime))
656 /* We call times(2) for kernel time or user time */
657 /* We can only (portably) do this for the current thread */
658 if (thread == GetCurrentThread())
660 ULONGLONG time;
661 struct tms time_buf;
662 long clocks_per_sec = sysconf(_SC_CLK_TCK);
664 times(&time_buf);
665 if (kerneltime)
667 time = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
668 kerneltime->dwHighDateTime = time >> 32;
669 kerneltime->dwLowDateTime = (DWORD)time;
671 if (usertime)
673 time = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
674 usertime->dwHighDateTime = time >> 32;
675 usertime->dwLowDateTime = (DWORD)time;
678 else
680 if (kerneltime) kerneltime->dwHighDateTime = kerneltime->dwLowDateTime = 0;
681 if (usertime) usertime->dwHighDateTime = usertime->dwLowDateTime = 0;
682 FIXME("Cannot get kerneltime or usertime of other threads\n");
685 return ret;
689 /**********************************************************************
690 * VWin32_BoostThreadGroup [KERNEL.535]
692 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
694 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
697 /**********************************************************************
698 * VWin32_BoostThreadStatic [KERNEL.536]
700 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
702 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
706 /***********************************************************************
707 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
709 * RETURNS
710 * Pseudohandle for the current thread
712 #undef GetCurrentThread
713 HANDLE WINAPI GetCurrentThread(void)
715 return (HANDLE)0xfffffffe;
719 /***********************************************************************
720 * ProcessIdToSessionId (KERNEL32.@)
721 * This function is available on Terminal Server 4SP4 and Windows 2000
723 BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
725 /* According to MSDN, if the calling process is not in a terminal
726 * services environment, then the sessionid returned is zero.
728 *sessionid_ptr = 0;
729 return TRUE;
732 /***********************************************************************
733 * SetThreadExecutionState (KERNEL32.@)
735 * Informs the system that activity is taking place for
736 * power management purposes.
738 EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags)
740 static EXECUTION_STATE current =
741 ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED|ES_USER_PRESENT;
742 EXECUTION_STATE old = current;
744 if (!(current & ES_CONTINUOUS) || (flags & ES_CONTINUOUS))
745 current = flags;
746 FIXME("(0x%lx): stub, harmless (power management).\n", flags);
747 return old;
751 #ifdef __i386__
753 /***********************************************************************
754 * SetLastError (KERNEL.147)
755 * SetLastError (KERNEL32.@)
757 /* void WINAPI SetLastError( DWORD error ); */
758 __ASM_GLOBAL_FUNC( SetLastError,
759 "movl 4(%esp),%eax\n\t"
760 ".byte 0x64\n\t"
761 "movl %eax,0x60\n\t"
762 "ret $4" );
764 /***********************************************************************
765 * GetLastError (KERNEL.148)
766 * GetLastError (KERNEL32.@)
768 /* DWORD WINAPI GetLastError(void); */
769 __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
771 /***********************************************************************
772 * GetCurrentProcessId (KERNEL.471)
773 * GetCurrentProcessId (KERNEL32.@)
775 /* DWORD WINAPI GetCurrentProcessId(void) */
776 __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
778 /***********************************************************************
779 * GetCurrentThreadId (KERNEL.462)
780 * GetCurrentThreadId (KERNEL32.@)
782 /* DWORD WINAPI GetCurrentThreadId(void) */
783 __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
785 #else /* __i386__ */
787 /**********************************************************************
788 * SetLastError (KERNEL.147)
789 * SetLastError (KERNEL32.@)
791 * Sets the last-error code.
793 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
795 NtCurrentTeb()->last_error = error;
798 /**********************************************************************
799 * GetLastError (KERNEL.148)
800 * GetLastError (KERNEL32.@)
802 * Returns last-error code.
804 DWORD WINAPI GetLastError(void)
806 return NtCurrentTeb()->last_error;
809 /***********************************************************************
810 * GetCurrentProcessId (KERNEL.471)
811 * GetCurrentProcessId (KERNEL32.@)
813 * Returns process identifier.
815 DWORD WINAPI GetCurrentProcessId(void)
817 return (DWORD)NtCurrentTeb()->pid;
820 /***********************************************************************
821 * GetCurrentThreadId (KERNEL.462)
822 * GetCurrentThreadId (KERNEL32.@)
824 * Returns thread identifier.
826 DWORD WINAPI GetCurrentThreadId(void)
828 return NtCurrentTeb()->tid;
831 #endif /* __i386__ */