Release 20010510.
[wine/multimedia.git] / scheduler / thread.c
blob5475e435f2da9ef34a043d68b4afbfa554f6a15a
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);
33 DECLARE_DEBUG_CHANNEL(relay);
35 /* TEB of the initial thread */
36 static TEB initial_teb;
38 extern struct _PDB current_process;
40 /***********************************************************************
41 * THREAD_IsWin16
43 BOOL THREAD_IsWin16( TEB *teb )
45 return !teb || !(teb->tibflags & TEBF_WIN32);
48 /***********************************************************************
49 * THREAD_IdToTEB
51 * Convert a thread id to a TEB, making sure it is valid.
53 TEB *THREAD_IdToTEB( DWORD id )
55 TEB *ret = NULL;
57 if (!id || id == GetCurrentThreadId()) return NtCurrentTeb();
59 SERVER_START_REQ( get_thread_info )
61 req->handle = 0;
62 req->tid_in = (void *)id;
63 if (!SERVER_CALL()) 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 = TASK_GetPtr( 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->request_fd = -1;
94 teb->reply_fd = -1;
95 teb->wait_fd[0] = -1;
96 teb->wait_fd[1] = -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 close( teb->request_fd );
119 close( teb->reply_fd );
120 close( teb->wait_fd[0] );
121 close( teb->wait_fd[1] );
122 if (teb->stack_sel) FreeSelector16( teb->stack_sel );
123 FreeSelector16( teb->teb_sel );
124 if (teb->buffer) munmap( (void *)teb->buffer, teb->buffer_size );
125 if (teb->debug_info) HeapFree( GetProcessHeap(), 0, teb->debug_info );
126 VirtualFree( teb->stack_base, 0, MEM_RELEASE );
130 /***********************************************************************
131 * THREAD_InitStack
133 * Allocate the stack of a thread.
135 TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
137 DWORD old_prot, total_size;
138 DWORD page_size = getpagesize();
139 void *base;
141 /* Allocate the stack */
143 if (stack_size >= 16*1024*1024)
144 WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024);
146 /* if size is smaller than default, get stack size from parent */
147 if (stack_size < 1024 * 1024)
149 if (teb)
150 stack_size = 1024 * 1024; /* no parent */
151 else
152 stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->stack_base
153 - SIGNAL_STACK_SIZE - 3 * page_size);
156 /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */
157 stack_size += 64 * 1024;
159 /* Memory layout in allocated block:
161 * size contents
162 * 1 page NOACCESS guard page
163 * SIGNAL_STACK_SIZE signal stack
164 * 1 page NOACCESS guard page
165 * 1 page PAGE_GUARD guard page
166 * stack_size normal stack
167 * 64Kb 16-bit stack (optional)
168 * 1 page TEB (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 += 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 - page_size);
182 if (!THREAD_InitTEB( teb ))
184 VirtualFree( base, 0, MEM_RELEASE );
185 return NULL;
189 teb->stack_low = base;
190 teb->stack_base = base;
191 teb->signal_stack = (char *)base + page_size;
192 teb->stack_top = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size;
194 /* Setup guard pages */
196 VirtualProtect( base, 1, PAGE_NOACCESS, &old_prot );
197 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot );
198 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1,
199 PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
201 /* Allocate the 16-bit stack selector */
203 teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, WINE_LDT_FLAGS_DATA );
204 if (!teb->stack_sel) goto error;
205 teb->cur_stack = MAKESEGPTR( teb->stack_sel, 0x10000 - sizeof(STACK16FRAME) );
207 return teb;
209 error:
210 THREAD_FreeTEB( teb );
211 return NULL;
215 /***********************************************************************
216 * thread_errno_location
218 * Get the per-thread errno location.
220 static int *thread_errno_location(void)
222 return &NtCurrentTeb()->thread_errno;
225 /***********************************************************************
226 * thread_h_errno_location
228 * Get the per-thread h_errno location.
230 static int *thread_h_errno_location(void)
232 return &NtCurrentTeb()->thread_h_errno;
235 /***********************************************************************
236 * THREAD_Init
238 * Setup the initial thread.
240 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
242 void THREAD_Init(void)
244 if (!initial_teb.self) /* do it only once */
246 THREAD_InitTEB( &initial_teb );
247 assert( initial_teb.teb_sel );
248 initial_teb.process = &current_process;
249 SYSDEPS_SetCurThread( &initial_teb );
250 wine_errno_location = thread_errno_location;
251 wine_h_errno_location = thread_h_errno_location;
255 DECL_GLOBAL_CONSTRUCTOR(thread_init) { THREAD_Init(); }
258 /***********************************************************************
259 * THREAD_Start
261 * Start execution of a newly created thread. Does not return.
263 static void THREAD_Start(void)
265 HANDLE cleanup_object;
266 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point;
268 /* install cleanup handler */
269 if (DuplicateHandle( GetCurrentProcess(), GetCurrentThread(),
270 GetCurrentProcess(), &cleanup_object,
271 0, FALSE, DUPLICATE_SAME_ACCESS ))
272 NtCurrentTeb()->cleanup = SERVICE_AddObject( cleanup_object, (PAPCFUNC)THREAD_FreeTEB,
273 (ULONG_PTR)NtCurrentTeb() );
275 if (TRACE_ON(relay))
276 DPRINTF("%08lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func );
278 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
279 PE_InitTls();
280 MODULE_DllThreadAttach( NULL );
281 ExitThread( func( NtCurrentTeb()->entry_arg ) );
285 /***********************************************************************
286 * CreateThread (KERNEL32.@)
288 HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
289 LPTHREAD_START_ROUTINE start, LPVOID param,
290 DWORD flags, LPDWORD id )
292 HANDLE handle = 0;
293 TEB *teb;
294 void *tid = 0;
295 int request_pipe[2];
297 if (pipe( request_pipe ) == -1)
299 SetLastError( ERROR_TOO_MANY_OPEN_FILES );
300 return 0;
302 fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
303 wine_server_send_fd( request_pipe[0] );
305 SERVER_START_REQ( new_thread )
307 req->suspend = ((flags & CREATE_SUSPENDED) != 0);
308 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
309 req->request_fd = request_pipe[0];
310 if (!SERVER_CALL_ERR())
312 handle = req->handle;
313 tid = req->tid;
315 close( request_pipe[0] );
317 SERVER_END_REQ;
319 if (!handle || !(teb = THREAD_InitStack( NULL, stack )))
321 close( request_pipe[1] );
322 return 0;
325 teb->process = NtCurrentTeb()->process;
326 teb->tid = tid;
327 teb->request_fd = request_pipe[1];
328 teb->entry_point = start;
329 teb->entry_arg = param;
330 teb->startup = THREAD_Start;
331 teb->htask16 = GetCurrentTask();
333 if (id) *id = (DWORD)tid;
334 if (SYSDEPS_SpawnThread( teb ) == -1)
336 CloseHandle( handle );
337 THREAD_FreeTEB( teb );
338 return 0;
340 return handle;
343 /***********************************************************************
344 * CreateThread16 (KERNEL.441)
346 static DWORD CALLBACK THREAD_StartThread16( LPVOID threadArgs )
348 FARPROC16 start = ((FARPROC16 *)threadArgs)[0];
349 DWORD param = ((DWORD *)threadArgs)[1];
350 HeapFree( GetProcessHeap(), 0, threadArgs );
352 ((LPDWORD)CURRENT_STACK16)[-1] = param;
353 return wine_call_to_16_long( start, sizeof(DWORD) );
355 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
356 FARPROC16 start, SEGPTR param,
357 DWORD flags, LPDWORD id )
359 DWORD *threadArgs = HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD) );
360 if (!threadArgs) return INVALID_HANDLE_VALUE;
361 threadArgs[0] = (DWORD)start;
362 threadArgs[1] = (DWORD)param;
364 return CreateThread( sa, stack, THREAD_StartThread16, threadArgs, flags, id );
368 /***********************************************************************
369 * ExitThread [KERNEL32.215] Ends a thread
371 * RETURNS
372 * None
374 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
376 BOOL last;
377 SERVER_START_REQ( terminate_thread )
379 /* send the exit code to the server */
380 req->handle = GetCurrentThread();
381 req->exit_code = code;
382 SERVER_CALL();
383 last = req->last;
385 SERVER_END_REQ;
387 if (last)
389 MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
390 exit( code );
392 else
394 MODULE_DllThreadDetach( NULL );
395 if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
396 SYSDEPS_ExitThread( code );
401 /***********************************************************************
402 * SetThreadContext [KERNEL32.670] Sets context of thread.
404 * RETURNS
405 * Success: TRUE
406 * Failure: FALSE
408 BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
409 const CONTEXT *context ) /* [in] Address of context structure */
411 BOOL ret;
412 SERVER_START_VAR_REQ( set_thread_context, sizeof(*context) )
414 req->handle = handle;
415 req->flags = context->ContextFlags;
416 memcpy( server_data_ptr(req), context, sizeof(*context) );
417 ret = !SERVER_CALL_ERR();
419 SERVER_END_VAR_REQ;
420 return ret;
424 /***********************************************************************
425 * GetThreadContext [KERNEL32.@] Retrieves context of thread.
427 * RETURNS
428 * Success: TRUE
429 * Failure: FALSE
431 BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
432 CONTEXT *context ) /* [out] Address of context structure */
434 BOOL ret;
435 SERVER_START_VAR_REQ( get_thread_context, sizeof(*context) )
437 req->handle = handle;
438 req->flags = context->ContextFlags;
439 memcpy( server_data_ptr(req), context, sizeof(*context) );
440 if ((ret = !SERVER_CALL_ERR()))
441 memcpy( context, server_data_ptr(req), sizeof(*context) );
443 SERVER_END_VAR_REQ;
444 return ret;
448 /**********************************************************************
449 * GetThreadPriority [KERNEL32.@] Returns priority for thread.
451 * RETURNS
452 * Success: Thread's priority level.
453 * Failure: THREAD_PRIORITY_ERROR_RETURN
455 INT WINAPI GetThreadPriority(
456 HANDLE hthread) /* [in] Handle to thread */
458 INT ret = THREAD_PRIORITY_ERROR_RETURN;
459 SERVER_START_REQ( get_thread_info )
461 req->handle = hthread;
462 req->tid_in = 0;
463 if (!SERVER_CALL_ERR()) ret = req->priority;
465 SERVER_END_REQ;
466 return ret;
470 /**********************************************************************
471 * SetThreadPriority [KERNEL32.@] Sets priority for thread.
473 * RETURNS
474 * Success: TRUE
475 * Failure: FALSE
477 BOOL WINAPI SetThreadPriority(
478 HANDLE hthread, /* [in] Handle to thread */
479 INT priority) /* [in] Thread priority level */
481 BOOL ret;
482 SERVER_START_REQ( set_thread_info )
484 req->handle = hthread;
485 req->priority = priority;
486 req->mask = SET_THREAD_INFO_PRIORITY;
487 ret = !SERVER_CALL_ERR();
489 SERVER_END_REQ;
490 return ret;
494 /**********************************************************************
495 * GetThreadPriorityBoost [KERNEL32.877] Returns priority boost for thread.
497 * Always reports that priority boost is disabled.
499 * RETURNS
500 * Success: TRUE.
501 * Failure: FALSE
503 BOOL WINAPI GetThreadPriorityBoost(
504 HANDLE hthread, /* [in] Handle to thread */
505 PBOOL pstate) /* [out] pointer to var that receives the boost state */
507 if (pstate) *pstate = FALSE;
508 return NO_ERROR;
512 /**********************************************************************
513 * SetThreadPriorityBoost [KERNEL32.893] Sets priority boost for thread.
515 * Priority boost is not implemented. Thsi function always returns
516 * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
518 * RETURNS
519 * Always returns FALSE to indicate a failure
521 BOOL WINAPI SetThreadPriorityBoost(
522 HANDLE hthread, /* [in] Handle to thread */
523 BOOL disable) /* [in] TRUE to disable priority boost */
525 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
526 return FALSE;
530 /**********************************************************************
531 * SetThreadAffinityMask (KERNEL32.669)
533 DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
535 DWORD ret;
536 SERVER_START_REQ( set_thread_info )
538 req->handle = hThread;
539 req->affinity = dwThreadAffinityMask;
540 req->mask = SET_THREAD_INFO_AFFINITY;
541 ret = !SERVER_CALL_ERR();
542 /* FIXME: should return previous value */
544 SERVER_END_REQ;
545 return ret;
549 /**********************************************************************
550 * TerminateThread [KERNEL32.685] Terminates a thread
552 * RETURNS
553 * Success: TRUE
554 * Failure: FALSE
556 BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */
557 DWORD exit_code) /* [in] Exit code for thread */
559 NTSTATUS status = NtTerminateThread( handle, exit_code );
560 if (status) SetLastError( RtlNtStatusToDosError(status) );
561 return !status;
565 /**********************************************************************
566 * GetExitCodeThread (KERNEL32.@)
567 * GetExitCodeThread (WIN32S16.13)
569 * Gets termination status of thread.
571 * RETURNS
572 * Success: TRUE
573 * Failure: FALSE
575 BOOL WINAPI GetExitCodeThread(
576 HANDLE hthread, /* [in] Handle to thread */
577 LPDWORD exitcode) /* [out] Address to receive termination status */
579 BOOL ret;
580 SERVER_START_REQ( get_thread_info )
582 req->handle = hthread;
583 req->tid_in = 0;
584 ret = !SERVER_CALL_ERR();
585 if (ret && exitcode) *exitcode = req->exit_code;
587 SERVER_END_REQ;
588 return ret;
592 /**********************************************************************
593 * ResumeThread [KERNEL32.587] Resumes a thread.
595 * Decrements a thread's suspend count. When count is zero, the
596 * execution of the thread is resumed.
598 * RETURNS
599 * Success: Previous suspend count
600 * Failure: 0xFFFFFFFF
601 * Already running: 0
603 DWORD WINAPI ResumeThread(
604 HANDLE hthread) /* [in] Identifies thread to restart */
606 DWORD ret = 0xffffffff;
607 SERVER_START_REQ( resume_thread )
609 req->handle = hthread;
610 if (!SERVER_CALL_ERR()) ret = req->count;
612 SERVER_END_REQ;
613 return ret;
617 /**********************************************************************
618 * SuspendThread [KERNEL32.681] Suspends a thread.
620 * RETURNS
621 * Success: Previous suspend count
622 * Failure: 0xFFFFFFFF
624 DWORD WINAPI SuspendThread(
625 HANDLE hthread) /* [in] Handle to the thread */
627 DWORD ret = 0xffffffff;
628 SERVER_START_REQ( suspend_thread )
630 req->handle = hthread;
631 if (!SERVER_CALL_ERR()) ret = req->count;
633 SERVER_END_REQ;
634 return ret;
638 /***********************************************************************
639 * QueueUserAPC (KERNEL32.566)
641 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
643 DWORD ret;
644 SERVER_START_REQ( queue_apc )
646 req->handle = hthread;
647 req->user = 1;
648 req->func = func;
649 req->param = (void *)data;
650 ret = !SERVER_CALL_ERR();
652 SERVER_END_REQ;
653 return ret;
657 /**********************************************************************
658 * GetThreadTimes [KERNEL32.@] Obtains timing information.
660 * NOTES
661 * What are the fields where these values are stored?
663 * RETURNS
664 * Success: TRUE
665 * Failure: FALSE
667 BOOL WINAPI GetThreadTimes(
668 HANDLE thread, /* [in] Specifies the thread of interest */
669 LPFILETIME creationtime, /* [out] When the thread was created */
670 LPFILETIME exittime, /* [out] When the thread was destroyed */
671 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
672 LPFILETIME usertime) /* [out] Time thread spent in user mode */
674 FIXME("(0x%08x): stub\n",thread);
675 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
676 return FALSE;
680 /**********************************************************************
681 * VWin32_BoostThreadGroup [KERNEL.535]
683 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
685 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
688 /**********************************************************************
689 * VWin32_BoostThreadStatic [KERNEL.536]
691 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
693 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
697 /***********************************************************************
698 * GetThreadLocale (KERNEL32.@)
700 LCID WINAPI GetThreadLocale(void)
702 LCID ret = NtCurrentTeb()->CurrentLocale;
703 if (!ret) NtCurrentTeb()->CurrentLocale = ret = GetUserDefaultLCID();
704 return ret;
708 /**********************************************************************
709 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
711 * RETURNS
712 * Success: TRUE
713 * Failure: FALSE
715 * FIXME
716 * check if lcid is a valid cp
718 BOOL WINAPI SetThreadLocale(
719 LCID lcid) /* [in] Locale identifier */
721 switch (lcid)
723 case LOCALE_SYSTEM_DEFAULT:
724 lcid = GetSystemDefaultLCID();
725 break;
726 case LOCALE_USER_DEFAULT:
727 case LOCALE_NEUTRAL:
728 lcid = GetUserDefaultLCID();
729 break;
731 NtCurrentTeb()->CurrentLocale = lcid;
732 return TRUE;
736 /***********************************************************************
737 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
739 * RETURNS
740 * Pseudohandle for the current thread
742 #undef GetCurrentThread
743 HANDLE WINAPI GetCurrentThread(void)
745 return 0xfffffffe;
749 /***********************************************************************
750 * ProcessIdToSessionId (KERNEL32.@)
751 * This function is available on Terminal Server 4SP4 and Windows 2000
753 BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
755 /* According to MSDN, if the calling process is not in a terminal
756 * services environment, then the sessionid returned is zero.
758 *sessionid_ptr = 0;
759 return TRUE;
762 /***********************************************************************
763 * SetThreadExecutionState (KERNEL32.@)
765 * Informs the system that activity is taking place for
766 * power management purposes.
768 EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags)
770 FIXME("(%ld): stub\n", flags);
771 return 0;
775 #ifdef __i386__
777 /* void WINAPI SetLastError( DWORD error ); */
778 __ASM_GLOBAL_FUNC( SetLastError,
779 "movl 4(%esp),%eax\n\t"
780 ".byte 0x64\n\t"
781 "movl %eax,0x60\n\t"
782 "ret $4" );
784 /* DWORD WINAPI GetLastError(void); */
785 __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
787 /* DWORD WINAPI GetCurrentProcessId(void) */
788 __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
790 /* DWORD WINAPI GetCurrentThreadId(void) */
791 __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
793 #else /* __i386__ */
795 /**********************************************************************
796 * SetLastError (KERNEL.147)
797 * SetLastError (KERNEL32.@)
799 * Sets the last-error code.
801 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
803 NtCurrentTeb()->last_error = error;
806 /**********************************************************************
807 * GetLastError (KERNEL.10)
808 * GetLastError (KERNEL32.@)
809 * GetLastError (WIN32S16.10)
811 * Returns last-error code.
813 DWORD WINAPI GetLastError(void)
815 return NtCurrentTeb()->last_error;
818 /***********************************************************************
819 * GetCurrentProcessId (KERNEL.471)
820 * GetCurrentProcessId (KERNEL32.@)
822 * Returns process identifier.
824 DWORD WINAPI GetCurrentProcessId(void)
826 return (DWORD)NtCurrentTeb()->pid;
829 /***********************************************************************
830 * GetCurrentThreadId (KERNEL.462)
831 * GetCurrentThreadId (KERNEL32.@)
833 * Returns thread identifier.
835 DWORD WINAPI GetCurrentThreadId(void)
837 return (DWORD)NtCurrentTeb()->tid;
840 #endif /* __i386__ */