Converted to the new debug interface, using script written by Patrik
[wine/wine64.git] / scheduler / thread.c
blob60b51f79db8c96cbd782bf8f7bf3b5f277a5950e
1 /*
2 * Win32 threads
4 * Copyright 1996 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <sys/mman.h>
12 #include <unistd.h>
13 #include "wine/winbase16.h"
14 #include "thread.h"
15 #include "process.h"
16 #include "task.h"
17 #include "module.h"
18 #include "user.h"
19 #include "winerror.h"
20 #include "heap.h"
21 #include "selectors.h"
22 #include "winnt.h"
23 #include "server.h"
24 #include "services.h"
25 #include "stackframe.h"
26 #include "debugtools.h"
27 #include "queue.h"
28 #include "hook.h"
30 DEFAULT_DEBUG_CHANNEL(thread)
32 /* TEB of the initial thread */
33 static TEB initial_teb;
35 /* Global thread list (FIXME: not thread-safe) */
36 TEB *THREAD_First = &initial_teb;
38 /***********************************************************************
39 * THREAD_IsWin16
41 BOOL THREAD_IsWin16( TEB *teb )
43 return !teb || !(teb->flags & TEBF_WIN32);
46 /***********************************************************************
47 * THREAD_IdToTEB
49 * Convert a thread id to a TEB, making sure it is valid.
51 TEB *THREAD_IdToTEB( DWORD id )
53 TEB *teb = THREAD_First;
55 if (!id) return NtCurrentTeb();
56 while (teb)
58 if ((DWORD)teb->tid == id) return teb;
59 teb = teb->next;
61 /* Allow task handles to be used; convert to main thread */
62 if ( IsTask16( id ) )
64 TDB *pTask = (TDB *)GlobalLock16( id );
65 if (pTask) return pTask->teb;
67 SetLastError( ERROR_INVALID_PARAMETER );
68 return NULL;
72 /***********************************************************************
73 * THREAD_InitTEB
75 * Initialization of a newly created TEB.
77 static BOOL THREAD_InitTEB( TEB *teb, DWORD stack_size, BOOL alloc_stack16,
78 LPSECURITY_ATTRIBUTES sa )
80 DWORD old_prot;
82 /* Allocate the stack */
84 /* FIXME:
85 * If stacksize smaller than 1 MB, allocate 1MB
86 * (one program wanted only 10 kB, which is recommendable, but some WINE
87 * functions, noteably in the files subdir, push HUGE structures and
88 * arrays on the stack. They probably shouldn't.)
89 * If stacksize larger than 16 MB, warn the user. (We could shrink the stack
90 * but this could give more or less unexplainable crashes.)
92 if (stack_size<1024*1024)
93 stack_size = 1024 * 1024;
94 if (stack_size >= 16*1024*1024)
95 WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024);
96 teb->stack_base = VirtualAlloc(NULL, stack_size + SIGNAL_STACK_SIZE +
97 (alloc_stack16 ? 0x10000 : 0),
98 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
99 if (!teb->stack_base) goto error;
100 /* Set a guard page at the bottom of the stack */
101 VirtualProtect( teb->stack_base, 1, PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
102 teb->stack_top = (char *)teb->stack_base + stack_size;
103 teb->stack_low = teb->stack_base;
104 teb->signal_stack = teb->stack_top; /* start of signal stack */
106 /* Allocate the 16-bit stack selector */
108 if (alloc_stack16)
110 teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, SEGMENT_DATA,
111 FALSE, FALSE );
112 if (!teb->stack_sel) goto error;
113 teb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( teb->stack_sel,
114 0x10000 - sizeof(STACK16FRAME) );
115 teb->signal_stack = (char *)teb->signal_stack + 0x10000;
118 /* Create the thread event */
120 if (!(teb->event = CreateEventA( NULL, FALSE, FALSE, NULL ))) goto error;
121 teb->event = ConvertToGlobalHandle( teb->event );
122 return TRUE;
124 error:
125 if (teb->event) CloseHandle( teb->event );
126 if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 );
127 if (teb->stack_base) VirtualFree( teb->stack_base, 0, MEM_RELEASE );
128 return FALSE;
132 /***********************************************************************
133 * THREAD_FreeTEB
135 * Free data structures associated with a thread.
136 * Must be called from the context of another thread.
138 void CALLBACK THREAD_FreeTEB( ULONG_PTR arg )
140 TEB *teb = (TEB *)arg;
141 TEB **pptr = &THREAD_First;
143 TRACE("(%p) called\n", teb );
144 SERVICE_Delete( teb->cleanup );
146 PROCESS_CallUserSignalProc( USIG_THREAD_EXIT, 0 );
148 CloseHandle( teb->event );
149 while (*pptr && (*pptr != teb)) pptr = &(*pptr)->next;
150 if (*pptr) *pptr = teb->next;
152 /* Free the associated memory */
154 if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 );
155 SELECTOR_FreeBlock( teb->teb_sel, 1 );
156 close( teb->socket );
157 if (teb->buffer) munmap( teb->buffer, teb->buffer_size );
158 VirtualFree( teb->stack_base, 0, MEM_RELEASE );
159 HeapFree( SystemHeap, 0, teb );
163 /***********************************************************************
164 * THREAD_CreateInitialThread
166 * Create the initial thread.
168 TEB *THREAD_CreateInitialThread( PDB *pdb, int server_fd )
170 initial_teb.except = (void *)-1;
171 initial_teb.self = &initial_teb;
172 initial_teb.flags = /* TEBF_WIN32 */ 0;
173 initial_teb.tls_ptr = initial_teb.tls_array;
174 initial_teb.process = pdb;
175 initial_teb.exit_code = 0x103; /* STILL_ACTIVE */
176 initial_teb.socket = server_fd;
178 /* Allocate the TEB selector (%fs register) */
180 if (!(initial_teb.teb_sel = SELECTOR_AllocBlock( &initial_teb, 0x1000,
181 SEGMENT_DATA, TRUE, FALSE )))
183 MESSAGE("Could not allocate fs register for initial thread\n" );
184 return NULL;
186 SYSDEPS_SetCurThread( &initial_teb );
188 /* Now proceed with normal initialization */
190 if (CLIENT_InitThread()) return NULL;
191 if (!THREAD_InitTEB( &initial_teb, 0, TRUE, NULL )) return NULL;
192 return &initial_teb;
196 /***********************************************************************
197 * THREAD_Create
199 TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
200 LPSECURITY_ATTRIBUTES sa, int *server_handle )
202 struct new_thread_request *req = get_req_buffer();
203 int fd[2];
204 HANDLE cleanup_object;
206 TEB *teb = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(TEB) );
207 if (!teb) return NULL;
208 teb->except = (void *)-1;
209 teb->htask16 = pdb->task;
210 teb->self = teb;
211 teb->flags = (pdb->flags & PDB32_WIN16_PROC)? 0 : TEBF_WIN32;
212 teb->tls_ptr = teb->tls_array;
213 teb->process = pdb;
214 teb->exit_code = 0x103; /* STILL_ACTIVE */
215 teb->socket = -1;
217 /* Allocate the TEB selector (%fs register) */
219 *server_handle = -1;
220 teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, SEGMENT_DATA, TRUE, FALSE );
221 if (!teb->teb_sel) goto error;
223 /* Create the socket pair for server communication */
225 if (socketpair( AF_UNIX, SOCK_STREAM, 0, fd ) == -1)
227 SetLastError( ERROR_TOO_MANY_OPEN_FILES ); /* FIXME */
228 goto error;
230 teb->socket = fd[0];
231 fcntl( fd[0], F_SETFD, 1 ); /* set close on exec flag */
233 /* Create the thread on the server side */
235 req->pid = teb->process->server_pid;
236 req->suspend = ((flags & CREATE_SUSPENDED) != 0);
237 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
238 if (server_call_fd( REQ_NEW_THREAD, fd[1], NULL )) goto error;
239 teb->tid = req->tid;
240 *server_handle = req->handle;
242 /* Do the rest of the initialization */
244 if (!THREAD_InitTEB( teb, stack_size, alloc_stack16, sa )) goto error;
245 teb->next = THREAD_First;
246 THREAD_First = teb;
248 /* Install cleanup handler */
249 if ( !DuplicateHandle( GetCurrentProcess(), *server_handle,
250 GetCurrentProcess(), &cleanup_object,
251 0, FALSE, DUPLICATE_SAME_ACCESS ) ) goto error;
252 teb->cleanup = SERVICE_AddObject( cleanup_object, THREAD_FreeTEB, (ULONG_PTR)teb );
254 return teb;
256 error:
257 if (*server_handle != -1) CloseHandle( *server_handle );
258 if (teb->teb_sel) SELECTOR_FreeBlock( teb->teb_sel, 1 );
259 if (teb->socket != -1) close( teb->socket );
260 HeapFree( SystemHeap, 0, teb );
261 return NULL;
265 /***********************************************************************
266 * THREAD_Start
268 * Start execution of a newly created thread. Does not return.
270 static void THREAD_Start(void)
272 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point;
273 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
274 PE_InitTls();
275 MODULE_DllThreadAttach( NULL );
277 if (NtCurrentTeb()->process->flags & PDB32_DEBUGGED) DEBUG_SendCreateThreadEvent( func );
279 ExitThread( func( NtCurrentTeb()->entry_arg ) );
283 /***********************************************************************
284 * CreateThread (KERNEL32.63)
286 HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
287 LPTHREAD_START_ROUTINE start, LPVOID param,
288 DWORD flags, LPDWORD id )
290 int handle = -1;
291 TEB *teb = THREAD_Create( PROCESS_Current(), flags, stack, TRUE, sa, &handle );
292 if (!teb) return 0;
293 teb->flags |= TEBF_WIN32;
294 teb->entry_point = start;
295 teb->entry_arg = param;
296 teb->startup = THREAD_Start;
297 if (SYSDEPS_SpawnThread( teb ) == -1)
299 CloseHandle( handle );
300 return 0;
302 if (id) *id = (DWORD)teb->tid;
303 return handle;
307 /***********************************************************************
308 * ExitThread [KERNEL32.215] Ends a thread
310 * RETURNS
311 * None
313 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
315 MODULE_DllThreadDetach( NULL );
316 TerminateThread( GetCurrentThread(), code );
320 /***********************************************************************
321 * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
323 * RETURNS
324 * Pseudohandle for the current thread
326 HANDLE WINAPI GetCurrentThread(void)
328 return CURRENT_THREAD_PSEUDOHANDLE;
332 /**********************************************************************
333 * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code.
335 * RETURNS
336 * Calling thread's last error code value.
338 DWORD WINAPI GetLastError(void)
340 return NtCurrentTeb()->last_error;
344 /**********************************************************************
345 * SetLastErrorEx [USER32.485] Sets the last-error code.
347 * RETURNS
348 * None.
350 void WINAPI SetLastErrorEx(
351 DWORD error, /* [in] Per-thread error code */
352 DWORD type) /* [in] Error type */
354 TRACE("(0x%08lx, 0x%08lx)\n", error,type);
355 switch(type) {
356 case 0:
357 break;
358 case SLE_ERROR:
359 case SLE_MINORERROR:
360 case SLE_WARNING:
361 /* Fall through for now */
362 default:
363 FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error,type);
364 break;
366 SetLastError( error );
370 /**********************************************************************
371 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
373 * Allocates a thread local storage index
375 * RETURNS
376 * Success: TLS Index
377 * Failure: 0xFFFFFFFF
379 DWORD WINAPI TlsAlloc( void )
381 PDB *process = PROCESS_Current();
382 DWORD i, mask, ret = 0;
383 DWORD *bits = process->tls_bits;
384 EnterCriticalSection( &process->crit_section );
385 if (*bits == 0xffffffff)
387 bits++;
388 ret = 32;
389 if (*bits == 0xffffffff)
391 LeaveCriticalSection( &process->crit_section );
392 SetLastError( ERROR_NO_MORE_ITEMS );
393 return 0xffffffff;
396 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
397 *bits |= mask;
398 LeaveCriticalSection( &process->crit_section );
399 return ret + i;
403 /**********************************************************************
404 * TlsFree [KERNEL32.531] Releases a TLS index.
406 * Releases a thread local storage index, making it available for reuse
408 * RETURNS
409 * Success: TRUE
410 * Failure: FALSE
412 BOOL WINAPI TlsFree(
413 DWORD index) /* [in] TLS Index to free */
415 PDB *process = PROCESS_Current();
416 DWORD mask;
417 DWORD *bits = process->tls_bits;
418 if (index >= 64)
420 SetLastError( ERROR_INVALID_PARAMETER );
421 return FALSE;
423 EnterCriticalSection( &process->crit_section );
424 if (index >= 32) bits++;
425 mask = (1 << (index & 31));
426 if (!(*bits & mask)) /* already free? */
428 LeaveCriticalSection( &process->crit_section );
429 SetLastError( ERROR_INVALID_PARAMETER );
430 return FALSE;
432 *bits &= ~mask;
433 NtCurrentTeb()->tls_array[index] = 0;
434 /* FIXME: should zero all other thread values */
435 LeaveCriticalSection( &process->crit_section );
436 return TRUE;
440 /**********************************************************************
441 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
443 * RETURNS
444 * Success: Value stored in calling thread's TLS slot for index
445 * Failure: 0 and GetLastError returns NO_ERROR
447 LPVOID WINAPI TlsGetValue(
448 DWORD index) /* [in] TLS index to retrieve value for */
450 if (index >= 64)
452 SetLastError( ERROR_INVALID_PARAMETER );
453 return NULL;
455 SetLastError( ERROR_SUCCESS );
456 return NtCurrentTeb()->tls_array[index];
460 /**********************************************************************
461 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
463 * RETURNS
464 * Success: TRUE
465 * Failure: FALSE
467 BOOL WINAPI TlsSetValue(
468 DWORD index, /* [in] TLS index to set value for */
469 LPVOID value) /* [in] Value to be stored */
471 if (index >= 64)
473 SetLastError( ERROR_INVALID_PARAMETER );
474 return FALSE;
476 NtCurrentTeb()->tls_array[index] = value;
477 return TRUE;
481 /***********************************************************************
482 * SetThreadContext [KERNEL32.670] Sets context of thread.
484 * RETURNS
485 * Success: TRUE
486 * Failure: FALSE
488 BOOL WINAPI SetThreadContext(
489 HANDLE handle, /* [in] Handle to thread with context */
490 CONTEXT *context) /* [out] Address of context structure */
492 FIXME("not implemented\n" );
493 return TRUE;
496 /***********************************************************************
497 * GetThreadContext [KERNEL32.294] Retrieves context of thread.
499 * RETURNS
500 * Success: TRUE
501 * Failure: FALSE
503 BOOL WINAPI GetThreadContext(
504 HANDLE handle, /* [in] Handle to thread with context */
505 CONTEXT *context) /* [out] Address of context structure */
507 #ifdef __i386__
508 WORD cs, ds;
510 FIXME("returning dummy info\n" );
512 /* make up some plausible values for segment registers */
513 GET_CS(cs);
514 GET_DS(ds);
515 context->SegCs = cs;
516 context->SegDs = ds;
517 context->SegEs = ds;
518 context->SegGs = ds;
519 context->SegSs = ds;
520 context->SegFs = ds;
521 #endif
522 return TRUE;
526 /**********************************************************************
527 * GetThreadPriority [KERNEL32.296] Returns priority for thread.
529 * RETURNS
530 * Success: Thread's priority level.
531 * Failure: THREAD_PRIORITY_ERROR_RETURN
533 INT WINAPI GetThreadPriority(
534 HANDLE hthread) /* [in] Handle to thread */
536 INT ret = THREAD_PRIORITY_ERROR_RETURN;
537 struct get_thread_info_request *req = get_req_buffer();
538 req->handle = hthread;
539 if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority;
540 return ret;
544 /**********************************************************************
545 * SetThreadPriority [KERNEL32.514] Sets priority for thread.
547 * RETURNS
548 * Success: TRUE
549 * Failure: FALSE
551 BOOL WINAPI SetThreadPriority(
552 HANDLE hthread, /* [in] Handle to thread */
553 INT priority) /* [in] Thread priority level */
555 struct set_thread_info_request *req = get_req_buffer();
556 req->handle = hthread;
557 req->priority = priority;
558 req->mask = SET_THREAD_INFO_PRIORITY;
559 return !server_call( REQ_SET_THREAD_INFO );
563 /**********************************************************************
564 * SetThreadAffinityMask (KERNEL32.669)
566 DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
568 struct set_thread_info_request *req = get_req_buffer();
569 req->handle = hThread;
570 req->affinity = dwThreadAffinityMask;
571 req->mask = SET_THREAD_INFO_AFFINITY;
572 if (server_call( REQ_SET_THREAD_INFO )) return 0;
573 return 1; /* FIXME: should return previous value */
577 /**********************************************************************
578 * TerminateThread [KERNEL32.685] Terminates a thread
580 * RETURNS
581 * Success: TRUE
582 * Failure: FALSE
584 BOOL WINAPI TerminateThread(
585 HANDLE handle, /* [in] Handle to thread */
586 DWORD exitcode) /* [in] Exit code for thread */
588 struct terminate_thread_request *req = get_req_buffer();
589 req->handle = handle;
590 req->exit_code = exitcode;
591 return !server_call( REQ_TERMINATE_THREAD );
595 /**********************************************************************
596 * GetExitCodeThread [KERNEL32.???] Gets termination status of thread.
598 * RETURNS
599 * Success: TRUE
600 * Failure: FALSE
602 BOOL WINAPI GetExitCodeThread(
603 HANDLE hthread, /* [in] Handle to thread */
604 LPDWORD exitcode) /* [out] Address to receive termination status */
606 BOOL ret = FALSE;
607 struct get_thread_info_request *req = get_req_buffer();
608 req->handle = hthread;
609 if (!server_call( REQ_GET_THREAD_INFO ))
611 if (exitcode) *exitcode = req->exit_code;
612 ret = TRUE;
614 return ret;
618 /**********************************************************************
619 * ResumeThread [KERNEL32.587] Resumes a thread.
621 * Decrements a thread's suspend count. When count is zero, the
622 * execution of the thread is resumed.
624 * RETURNS
625 * Success: Previous suspend count
626 * Failure: 0xFFFFFFFF
627 * Already running: 0
629 DWORD WINAPI ResumeThread(
630 HANDLE hthread) /* [in] Identifies thread to restart */
632 DWORD ret = 0xffffffff;
633 struct resume_thread_request *req = get_req_buffer();
634 req->handle = hthread;
635 if (!server_call( REQ_RESUME_THREAD )) ret = req->count;
636 return ret;
640 /**********************************************************************
641 * SuspendThread [KERNEL32.681] Suspends a thread.
643 * RETURNS
644 * Success: Previous suspend count
645 * Failure: 0xFFFFFFFF
647 DWORD WINAPI SuspendThread(
648 HANDLE hthread) /* [in] Handle to the thread */
650 DWORD ret = 0xffffffff;
651 struct suspend_thread_request *req = get_req_buffer();
652 req->handle = hthread;
653 if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count;
654 return ret;
658 /***********************************************************************
659 * QueueUserAPC (KERNEL32.566)
661 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
663 struct queue_apc_request *req = get_req_buffer();
664 req->handle = hthread;
665 req->func = func;
666 req->param = (void *)data;
667 return !server_call( REQ_QUEUE_APC );
671 /**********************************************************************
672 * GetThreadTimes [KERNEL32.???] Obtains timing information.
674 * NOTES
675 * What are the fields where these values are stored?
677 * RETURNS
678 * Success: TRUE
679 * Failure: FALSE
681 BOOL WINAPI GetThreadTimes(
682 HANDLE thread, /* [in] Specifies the thread of interest */
683 LPFILETIME creationtime, /* [out] When the thread was created */
684 LPFILETIME exittime, /* [out] When the thread was destroyed */
685 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
686 LPFILETIME usertime) /* [out] Time thread spent in user mode */
688 FIXME("(0x%08x): stub\n",thread);
689 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
690 return FALSE;
694 /**********************************************************************
695 * AttachThreadInput [KERNEL32.8] Attaches input of 1 thread to other
697 * Attaches the input processing mechanism of one thread to that of
698 * another thread.
700 * RETURNS
701 * Success: TRUE
702 * Failure: FALSE
704 * TODO:
705 * 1. Reset the Key State (currenly per thread key state is not maintained)
707 BOOL WINAPI AttachThreadInput(
708 DWORD idAttach, /* [in] Thread to attach */
709 DWORD idAttachTo, /* [in] Thread to attach to */
710 BOOL fAttach) /* [in] Attach or detach */
712 MESSAGEQUEUE *pSrcMsgQ = 0, *pTgtMsgQ = 0;
713 BOOL16 bRet = 0;
715 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
717 /* A thread cannot attach to itself */
718 if ( idAttach == idAttachTo )
719 goto CLEANUP;
721 /* According to the docs this method should fail if a
722 * "Journal record" hook is installed. (attaches all input queues together)
724 if ( HOOK_IsHooked( WH_JOURNALRECORD ) )
725 goto CLEANUP;
727 /* Retrieve message queues corresponding to the thread id's */
728 pTgtMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetThreadQueue16( idAttach ) );
729 pSrcMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetThreadQueue16( idAttachTo ) );
731 /* Ensure we have message queues and that Src and Tgt threads
732 * are not system threads.
734 if ( !pSrcMsgQ || !pTgtMsgQ || !pSrcMsgQ->pQData || !pTgtMsgQ->pQData )
735 goto CLEANUP;
737 if (fAttach) /* Attach threads */
739 /* Only attach if currently detached */
740 if ( pTgtMsgQ->pQData != pSrcMsgQ->pQData )
742 /* First release the target threads perQData */
743 PERQDATA_Release( pTgtMsgQ->pQData );
745 /* Share a reference to the source threads perQDATA */
746 PERQDATA_Addref( pSrcMsgQ->pQData );
747 pTgtMsgQ->pQData = pSrcMsgQ->pQData;
750 else /* Detach threads */
752 /* Only detach if currently attached */
753 if ( pTgtMsgQ->pQData == pSrcMsgQ->pQData )
755 /* First release the target threads perQData */
756 PERQDATA_Release( pTgtMsgQ->pQData );
758 /* Give the target thread its own private perQDATA once more */
759 pTgtMsgQ->pQData = PERQDATA_CreateInstance();
763 /* TODO: Reset the Key State */
765 bRet = 1; /* Success */
767 CLEANUP:
769 /* Unlock the queues before returning */
770 if ( pSrcMsgQ )
771 QUEUE_Unlock( pSrcMsgQ );
772 if ( pTgtMsgQ )
773 QUEUE_Unlock( pTgtMsgQ );
775 return bRet;
778 /**********************************************************************
779 * VWin32_BoostThreadGroup [KERNEL.535]
781 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
783 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
786 /**********************************************************************
787 * VWin32_BoostThreadStatic [KERNEL.536]
789 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
791 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
794 /**********************************************************************
795 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
797 * RETURNS
798 * Success: TRUE
799 * Failure: FALSE
801 * NOTES
802 * Implemented in NT only (3.1 and above according to MS
804 BOOL WINAPI SetThreadLocale(
805 LCID lcid) /* [in] Locale identifier */
807 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
808 return FALSE;
812 /**********************************************************************
813 * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code.
815 * RETURNS
816 * None.
818 #undef SetLastError
819 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
821 NtCurrentTeb()->last_error = error;
825 /***********************************************************************
826 * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
828 * RETURNS
829 * Thread identifier of calling thread
831 #undef GetCurrentThreadId
832 DWORD WINAPI GetCurrentThreadId(void)
834 return (DWORD)NtCurrentTeb()->tid;