Fix existing string functions, implement a bunch of new ones.
[wine/hacks.git] / scheduler / thread.c
blob574324c0fb8657fcac2599b444c23cbe19efab99
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_UNISTD_H
31 # include <unistd.h>
32 #endif
33 #include "wine/winbase16.h"
34 #include "thread.h"
35 #include "task.h"
36 #include "module.h"
37 #include "winerror.h"
38 #include "selectors.h"
39 #include "winnt.h"
40 #include "wine/server.h"
41 #include "stackframe.h"
42 #include "wine/debug.h"
43 #include "winnls.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(thread);
46 WINE_DECLARE_DEBUG_CHANNEL(relay);
48 /* TEB of the initial thread */
49 static TEB initial_teb;
51 extern struct _PDB current_process;
53 /***********************************************************************
54 * THREAD_IdToTEB
56 * Convert a thread id to a TEB, making sure it is valid.
58 TEB *THREAD_IdToTEB( DWORD id )
60 TEB *ret = NULL;
62 if (!id || id == GetCurrentThreadId()) return NtCurrentTeb();
64 SERVER_START_REQ( get_thread_info )
66 req->handle = 0;
67 req->tid_in = (void *)id;
68 if (!wine_server_call( req )) ret = reply->teb;
70 SERVER_END_REQ;
72 if (!ret)
74 /* Allow task handles to be used; convert to main thread */
75 if ( IsTask16( id ) )
77 TDB *pTask = TASK_GetPtr( id );
78 if (pTask) return pTask->teb;
80 SetLastError( ERROR_INVALID_PARAMETER );
82 return ret;
86 /***********************************************************************
87 * THREAD_InitTEB
89 * Initialization of a newly created TEB.
91 static BOOL THREAD_InitTEB( TEB *teb )
93 teb->except = (void *)~0UL;
94 teb->self = teb;
95 teb->tibflags = TEBF_WIN32;
96 teb->tls_ptr = teb->tls_array;
97 teb->exit_code = STILL_ACTIVE;
98 teb->request_fd = -1;
99 teb->reply_fd = -1;
100 teb->wait_fd[0] = -1;
101 teb->wait_fd[1] = -1;
102 teb->stack_top = (void *)~0UL;
103 teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
104 teb->StaticUnicodeString.Buffer = (PWSTR)teb->StaticUnicodeBuffer;
105 teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, WINE_LDT_FLAGS_DATA|WINE_LDT_FLAGS_32BIT );
106 return (teb->teb_sel != 0);
110 /***********************************************************************
111 * THREAD_FreeTEB
113 * Free data structures associated with a thread.
114 * Must be called from the context of another thread.
116 static void THREAD_FreeTEB( TEB *teb )
118 TRACE("(%p) called\n", teb );
119 /* Free the associated memory */
120 FreeSelector16( teb->stack_sel );
121 FreeSelector16( teb->teb_sel );
122 VirtualFree( teb->stack_base, 0, MEM_RELEASE );
126 /***********************************************************************
127 * THREAD_InitStack
129 * Allocate the stack of a thread.
131 TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
133 DWORD old_prot, total_size;
134 DWORD page_size = getpagesize();
135 void *base;
137 /* Allocate the stack */
139 if (stack_size >= 16*1024*1024)
140 WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024);
142 /* if size is smaller than default, get stack size from parent */
143 if (stack_size < 1024 * 1024)
145 if (teb)
146 stack_size = 1024 * 1024; /* no parent */
147 else
148 stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->stack_base
149 - SIGNAL_STACK_SIZE - 3 * page_size);
152 /* FIXME: some Wine functions use a lot of stack, so we add 64Kb here */
153 stack_size += 64 * 1024;
155 /* Memory layout in allocated block:
157 * size contents
158 * 1 page NOACCESS guard page
159 * SIGNAL_STACK_SIZE signal stack
160 * 1 page NOACCESS guard page
161 * 1 page PAGE_GUARD guard page
162 * stack_size normal stack
163 * 64Kb 16-bit stack (optional)
164 * 1 page TEB (except for initial thread)
165 * 1 page debug info (except for initial thread)
168 stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
169 total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size;
170 total_size += 0x10000; /* 16-bit stack */
171 if (!teb) total_size += 2 * page_size;
173 if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
174 return NULL;
176 if (!teb)
178 teb = (TEB *)((char *)base + total_size - 2 * page_size);
179 if (!THREAD_InitTEB( teb )) goto error;
180 teb->debug_info = (char *)teb + page_size;
183 teb->stack_low = base;
184 teb->stack_base = base;
185 teb->signal_stack = (char *)base + page_size;
186 teb->stack_top = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size;
188 /* Setup guard pages */
190 VirtualProtect( base, 1, PAGE_NOACCESS, &old_prot );
191 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot );
192 VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1,
193 PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
195 /* Allocate the 16-bit stack selector */
197 teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, WINE_LDT_FLAGS_DATA );
198 if (!teb->stack_sel) goto error;
199 teb->cur_stack = MAKESEGPTR( teb->stack_sel, 0x10000 - sizeof(STACK16FRAME) );
201 return teb;
203 error:
204 FreeSelector16( teb->teb_sel );
205 VirtualFree( base, 0, MEM_RELEASE );
206 return NULL;
210 /***********************************************************************
211 * thread_errno_location
213 * Get the per-thread errno location.
215 static int *thread_errno_location(void)
217 return &NtCurrentTeb()->thread_errno;
220 /***********************************************************************
221 * thread_h_errno_location
223 * Get the per-thread h_errno location.
225 static int *thread_h_errno_location(void)
227 return &NtCurrentTeb()->thread_h_errno;
230 /***********************************************************************
231 * THREAD_Init
233 * Setup the initial thread.
235 * NOTES: The first allocated TEB on NT is at 0x7ffde000.
237 void THREAD_Init(void)
239 if (!initial_teb.self) /* do it only once */
241 THREAD_InitTEB( &initial_teb );
242 assert( initial_teb.teb_sel );
243 initial_teb.process = &current_process;
244 SYSDEPS_SetCurThread( &initial_teb );
245 wine_errno_location = thread_errno_location;
246 wine_h_errno_location = thread_h_errno_location;
250 DECL_GLOBAL_CONSTRUCTOR(thread_init) { THREAD_Init(); }
253 /***********************************************************************
254 * THREAD_Start
256 * Start execution of a newly created thread. Does not return.
258 static void THREAD_Start(void)
260 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point;
262 if (TRACE_ON(relay))
263 DPRINTF("%08lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func );
265 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
266 MODULE_DllThreadAttach( NULL );
267 ExitThread( func( NtCurrentTeb()->entry_arg ) );
271 /***********************************************************************
272 * CreateThread (KERNEL32.@)
274 HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
275 LPTHREAD_START_ROUTINE start, LPVOID param,
276 DWORD flags, LPDWORD id )
278 HANDLE handle = 0;
279 TEB *teb;
280 void *tid = 0;
281 int request_pipe[2];
283 if (pipe( request_pipe ) == -1)
285 SetLastError( ERROR_TOO_MANY_OPEN_FILES );
286 return 0;
288 fcntl( request_pipe[1], F_SETFD, 1 ); /* set close on exec flag */
289 wine_server_send_fd( request_pipe[0] );
291 SERVER_START_REQ( new_thread )
293 req->suspend = ((flags & CREATE_SUSPENDED) != 0);
294 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
295 req->request_fd = request_pipe[0];
296 if (!wine_server_call_err( req ))
298 handle = reply->handle;
299 tid = reply->tid;
301 close( request_pipe[0] );
303 SERVER_END_REQ;
305 if (!handle || !(teb = THREAD_InitStack( NULL, stack )))
307 close( request_pipe[1] );
308 return 0;
311 teb->process = NtCurrentTeb()->process;
312 teb->tid = tid;
313 teb->request_fd = request_pipe[1];
314 teb->entry_point = start;
315 teb->entry_arg = param;
316 teb->startup = THREAD_Start;
317 teb->htask16 = GetCurrentTask();
319 if (id) *id = (DWORD)tid;
320 if (SYSDEPS_SpawnThread( teb ) == -1)
322 CloseHandle( handle );
323 close( request_pipe[1] );
324 THREAD_FreeTEB( teb );
325 return 0;
327 return handle;
330 /***********************************************************************
331 * CreateThread16 (KERNEL.441)
333 static DWORD CALLBACK THREAD_StartThread16( LPVOID threadArgs )
335 FARPROC16 start = ((FARPROC16 *)threadArgs)[0];
336 DWORD param = ((DWORD *)threadArgs)[1];
337 HeapFree( GetProcessHeap(), 0, threadArgs );
339 ((LPDWORD)CURRENT_STACK16)[-1] = param;
340 return wine_call_to_16_long( start, sizeof(DWORD) );
342 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
343 FARPROC16 start, SEGPTR param,
344 DWORD flags, LPDWORD id )
346 DWORD *threadArgs = HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD) );
347 if (!threadArgs) return INVALID_HANDLE_VALUE;
348 threadArgs[0] = (DWORD)start;
349 threadArgs[1] = (DWORD)param;
351 return CreateThread( sa, stack, THREAD_StartThread16, threadArgs, flags, id );
355 /***********************************************************************
356 * ExitThread [KERNEL32.@] Ends a thread
358 * RETURNS
359 * None
361 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
363 BOOL last;
364 SERVER_START_REQ( terminate_thread )
366 /* send the exit code to the server */
367 req->handle = GetCurrentThread();
368 req->exit_code = code;
369 wine_server_call( req );
370 last = reply->last;
372 SERVER_END_REQ;
374 if (last)
376 MODULE_DllProcessDetach( TRUE, (LPVOID)1 );
377 exit( code );
379 else
381 MODULE_DllThreadDetach( NULL );
382 if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
383 SYSDEPS_ExitThread( code );
387 /***********************************************************************
388 * OpenThread Retrieves a handle to a thread from its thread id
390 * RETURNS
391 * None
393 HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId )
395 HANDLE ret = 0;
396 SERVER_START_REQ( open_thread )
398 req->tid = (void *)dwThreadId;
399 req->access = dwDesiredAccess;
400 req->inherit = bInheritHandle;
401 if (!wine_server_call_err( req )) ret = reply->handle;
403 SERVER_END_REQ;
404 return ret;
407 /***********************************************************************
408 * SetThreadContext [KERNEL32.@] Sets context of thread.
410 * RETURNS
411 * Success: TRUE
412 * Failure: FALSE
414 BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
415 const CONTEXT *context ) /* [in] Address of context structure */
417 BOOL ret;
418 SERVER_START_REQ( set_thread_context )
420 req->handle = handle;
421 req->flags = context->ContextFlags;
422 wine_server_add_data( req, context, sizeof(*context) );
423 ret = !wine_server_call_err( req );
425 SERVER_END_REQ;
426 return ret;
430 /***********************************************************************
431 * GetThreadContext [KERNEL32.@] Retrieves context of thread.
433 * RETURNS
434 * Success: TRUE
435 * Failure: FALSE
437 BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
438 CONTEXT *context ) /* [out] Address of context structure */
440 BOOL ret;
441 SERVER_START_REQ( get_thread_context )
443 req->handle = handle;
444 req->flags = context->ContextFlags;
445 wine_server_add_data( req, context, sizeof(*context) );
446 wine_server_set_reply( req, context, sizeof(*context) );
447 ret = !wine_server_call_err( req );
449 SERVER_END_REQ;
450 return ret;
454 /**********************************************************************
455 * GetThreadPriority [KERNEL32.@] Returns priority for thread.
457 * RETURNS
458 * Success: Thread's priority level.
459 * Failure: THREAD_PRIORITY_ERROR_RETURN
461 INT WINAPI GetThreadPriority(
462 HANDLE hthread) /* [in] Handle to thread */
464 INT ret = THREAD_PRIORITY_ERROR_RETURN;
465 SERVER_START_REQ( get_thread_info )
467 req->handle = hthread;
468 req->tid_in = 0;
469 if (!wine_server_call_err( req )) ret = reply->priority;
471 SERVER_END_REQ;
472 return ret;
476 /**********************************************************************
477 * SetThreadPriority [KERNEL32.@] Sets priority for thread.
479 * RETURNS
480 * Success: TRUE
481 * Failure: FALSE
483 BOOL WINAPI SetThreadPriority(
484 HANDLE hthread, /* [in] Handle to thread */
485 INT priority) /* [in] Thread priority level */
487 BOOL ret;
488 SERVER_START_REQ( set_thread_info )
490 req->handle = hthread;
491 req->priority = priority;
492 req->mask = SET_THREAD_INFO_PRIORITY;
493 ret = !wine_server_call_err( req );
495 SERVER_END_REQ;
496 return ret;
500 /**********************************************************************
501 * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread.
503 * Always reports that priority boost is disabled.
505 * RETURNS
506 * Success: TRUE.
507 * Failure: FALSE
509 BOOL WINAPI GetThreadPriorityBoost(
510 HANDLE hthread, /* [in] Handle to thread */
511 PBOOL pstate) /* [out] pointer to var that receives the boost state */
513 if (pstate) *pstate = FALSE;
514 return NO_ERROR;
518 /**********************************************************************
519 * SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread.
521 * Priority boost is not implemented. Thsi function always returns
522 * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
524 * RETURNS
525 * Always returns FALSE to indicate a failure
527 BOOL WINAPI SetThreadPriorityBoost(
528 HANDLE hthread, /* [in] Handle to thread */
529 BOOL disable) /* [in] TRUE to disable priority boost */
531 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
532 return FALSE;
536 /**********************************************************************
537 * SetThreadAffinityMask (KERNEL32.@)
539 DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
541 DWORD ret;
542 SERVER_START_REQ( set_thread_info )
544 req->handle = hThread;
545 req->affinity = dwThreadAffinityMask;
546 req->mask = SET_THREAD_INFO_AFFINITY;
547 ret = !wine_server_call_err( req );
548 /* FIXME: should return previous value */
550 SERVER_END_REQ;
551 return ret;
554 /**********************************************************************
555 * SetThreadIdealProcessor [KERNEL32.@] Obtains timing information.
557 * RETURNS
558 * Success: Value of last call to SetThreadIdealProcessor
559 * Failure: -1
561 DWORD WINAPI SetThreadIdealProcessor(
562 HANDLE hThread, /* [in] Specifies the thread of interest */
563 DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */
565 FIXME("(0x%08x): stub\n",hThread);
566 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
567 return -1L;
570 /**********************************************************************
571 * TerminateThread [KERNEL32.@] Terminates a thread
573 * RETURNS
574 * Success: TRUE
575 * Failure: FALSE
577 BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */
578 DWORD exit_code) /* [in] Exit code for thread */
580 NTSTATUS status = NtTerminateThread( handle, exit_code );
581 if (status) SetLastError( RtlNtStatusToDosError(status) );
582 return !status;
586 /**********************************************************************
587 * GetExitCodeThread (KERNEL32.@)
589 * Gets termination status of thread.
591 * RETURNS
592 * Success: TRUE
593 * Failure: FALSE
595 BOOL WINAPI GetExitCodeThread(
596 HANDLE hthread, /* [in] Handle to thread */
597 LPDWORD exitcode) /* [out] Address to receive termination status */
599 BOOL ret;
600 SERVER_START_REQ( get_thread_info )
602 req->handle = hthread;
603 req->tid_in = 0;
604 ret = !wine_server_call_err( req );
605 if (ret && exitcode) *exitcode = reply->exit_code;
607 SERVER_END_REQ;
608 return ret;
612 /**********************************************************************
613 * ResumeThread [KERNEL32.@] Resumes a thread.
615 * Decrements a thread's suspend count. When count is zero, the
616 * execution of the thread is resumed.
618 * RETURNS
619 * Success: Previous suspend count
620 * Failure: 0xFFFFFFFF
621 * Already running: 0
623 DWORD WINAPI ResumeThread(
624 HANDLE hthread) /* [in] Identifies thread to restart */
626 DWORD ret = 0xffffffff;
627 SERVER_START_REQ( resume_thread )
629 req->handle = hthread;
630 if (!wine_server_call_err( req )) ret = reply->count;
632 SERVER_END_REQ;
633 return ret;
637 /**********************************************************************
638 * SuspendThread [KERNEL32.@] Suspends a thread.
640 * RETURNS
641 * Success: Previous suspend count
642 * Failure: 0xFFFFFFFF
644 DWORD WINAPI SuspendThread(
645 HANDLE hthread) /* [in] Handle to the thread */
647 DWORD ret = 0xffffffff;
648 SERVER_START_REQ( suspend_thread )
650 req->handle = hthread;
651 if (!wine_server_call_err( req )) ret = reply->count;
653 SERVER_END_REQ;
654 return ret;
658 /***********************************************************************
659 * QueueUserAPC (KERNEL32.@)
661 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
663 DWORD ret;
664 SERVER_START_REQ( queue_apc )
666 req->handle = hthread;
667 req->user = 1;
668 req->func = func;
669 req->param = (void *)data;
670 ret = !wine_server_call_err( req );
672 SERVER_END_REQ;
673 return ret;
677 /**********************************************************************
678 * GetThreadTimes [KERNEL32.@] Obtains timing information.
680 * NOTES
681 * What are the fields where these values are stored?
683 * RETURNS
684 * Success: TRUE
685 * Failure: FALSE
687 BOOL WINAPI GetThreadTimes(
688 HANDLE thread, /* [in] Specifies the thread of interest */
689 LPFILETIME creationtime, /* [out] When the thread was created */
690 LPFILETIME exittime, /* [out] When the thread was destroyed */
691 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
692 LPFILETIME usertime) /* [out] Time thread spent in user mode */
694 FIXME("(0x%08x): stub\n",thread);
695 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
696 return FALSE;
700 /**********************************************************************
701 * VWin32_BoostThreadGroup [KERNEL.535]
703 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
705 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
708 /**********************************************************************
709 * VWin32_BoostThreadStatic [KERNEL.536]
711 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
713 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
717 /***********************************************************************
718 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
720 * RETURNS
721 * Pseudohandle for the current thread
723 #undef GetCurrentThread
724 HANDLE WINAPI GetCurrentThread(void)
726 return (HANDLE)0xfffffffe;
730 /***********************************************************************
731 * ProcessIdToSessionId (KERNEL32.@)
732 * This function is available on Terminal Server 4SP4 and Windows 2000
734 BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr )
736 /* According to MSDN, if the calling process is not in a terminal
737 * services environment, then the sessionid returned is zero.
739 *sessionid_ptr = 0;
740 return TRUE;
743 /***********************************************************************
744 * SetThreadExecutionState (KERNEL32.@)
746 * Informs the system that activity is taking place for
747 * power management purposes.
749 EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags)
751 static EXECUTION_STATE current =
752 ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED|ES_USER_PRESENT;
753 EXECUTION_STATE old = current;
755 if (!(current & ES_CONTINUOUS) || (flags & ES_CONTINUOUS))
756 current = flags;
757 FIXME("(0x%lx): stub, harmless (power management).\n", flags);
758 return old;
762 #ifdef __i386__
764 /***********************************************************************
765 * SetLastError (KERNEL.147)
766 * SetLastError (KERNEL32.@)
768 /* void WINAPI SetLastError( DWORD error ); */
769 __ASM_GLOBAL_FUNC( SetLastError,
770 "movl 4(%esp),%eax\n\t"
771 ".byte 0x64\n\t"
772 "movl %eax,0x60\n\t"
773 "ret $4" );
775 /***********************************************************************
776 * GetLastError (KERNEL.148)
777 * GetLastError (KERNEL32.@)
779 /* DWORD WINAPI GetLastError(void); */
780 __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
782 /***********************************************************************
783 * GetCurrentProcessId (KERNEL.471)
784 * GetCurrentProcessId (KERNEL32.@)
786 /* DWORD WINAPI GetCurrentProcessId(void) */
787 __ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
789 /***********************************************************************
790 * GetCurrentThreadId (KERNEL.462)
791 * GetCurrentThreadId (KERNEL32.@)
793 /* DWORD WINAPI GetCurrentThreadId(void) */
794 __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
796 #else /* __i386__ */
798 /**********************************************************************
799 * SetLastError (KERNEL.147)
800 * SetLastError (KERNEL32.@)
802 * Sets the last-error code.
804 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
806 NtCurrentTeb()->last_error = error;
809 /**********************************************************************
810 * GetLastError (KERNEL.148)
811 * GetLastError (KERNEL32.@)
813 * Returns last-error code.
815 DWORD WINAPI GetLastError(void)
817 return NtCurrentTeb()->last_error;
820 /***********************************************************************
821 * GetCurrentProcessId (KERNEL.471)
822 * GetCurrentProcessId (KERNEL32.@)
824 * Returns process identifier.
826 DWORD WINAPI GetCurrentProcessId(void)
828 return (DWORD)NtCurrentTeb()->pid;
831 /***********************************************************************
832 * GetCurrentThreadId (KERNEL.462)
833 * GetCurrentThreadId (KERNEL32.@)
835 * Returns thread identifier.
837 DWORD WINAPI GetCurrentThreadId(void)
839 return (DWORD)NtCurrentTeb()->tid;
842 #endif /* __i386__ */