blob: 62e4dc77e96c69a61503c9faad478554635f2659 [file] [log] [blame]
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00001/*
2 * Win32 threads
3 *
4 * Copyright 1996 Alexandre Julliard
5 */
6
7#include <assert.h>
Alexandre Julliardf0167521999-03-21 19:26:25 +00008#include <fcntl.h>
Alexandre Julliard13e55191999-02-21 18:34:18 +00009#include <sys/types.h>
10#include <sys/socket.h>
Alexandre Julliard0a860a01999-06-22 11:43:42 +000011#include <sys/mman.h>
Alexandre Julliard02e90081998-01-04 17:49:09 +000012#include <unistd.h>
Marcus Meissner317af321999-02-17 13:51:06 +000013#include "wine/winbase16.h"
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000014#include "thread.h"
Alexandre Julliard02e90081998-01-04 17:49:09 +000015#include "process.h"
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000016#include "task.h"
17#include "module.h"
18#include "user.h"
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000019#include "winerror.h"
20#include "heap.h"
21#include "selectors.h"
22#include "winnt.h"
Alexandre Julliard642d3131998-07-12 19:29:36 +000023#include "server.h"
Ulrich Weigand36a1a251999-05-08 10:48:03 +000024#include "services.h"
Alexandre Julliard767e6f61998-08-09 12:47:43 +000025#include "stackframe.h"
Alexandre Julliard15657091999-05-23 10:25:25 +000026#include "debugtools.h"
Noel Borthwickb4278561999-02-05 10:37:53 +000027#include "queue.h"
28#include "hook.h"
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000029
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000030DEFAULT_DEBUG_CHANNEL(thread)
31
Alexandre Julliard0a860a01999-06-22 11:43:42 +000032/* TEB of the initial thread */
33static TEB initial_teb;
Alexandre Julliard13e55191999-02-21 18:34:18 +000034
Alexandre Julliard8feb3bc1999-02-28 12:25:03 +000035/* Global thread list (FIXME: not thread-safe) */
Alexandre Julliard0a860a01999-06-22 11:43:42 +000036TEB *THREAD_First = &initial_teb;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000037
38/***********************************************************************
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000039 * THREAD_IsWin16
40 */
Alexandre Julliard0a860a01999-06-22 11:43:42 +000041BOOL THREAD_IsWin16( TEB *teb )
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000042{
Alexandre Julliard0a860a01999-06-22 11:43:42 +000043 return !teb || !(teb->flags & TEBF_WIN32);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000044}
45
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000046/***********************************************************************
Alexandre Julliard0a860a01999-06-22 11:43:42 +000047 * THREAD_IdToTEB
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000048 *
Alexandre Julliard0a860a01999-06-22 11:43:42 +000049 * Convert a thread id to a TEB, making sure it is valid.
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000050 */
Alexandre Julliard0a860a01999-06-22 11:43:42 +000051TEB *THREAD_IdToTEB( DWORD id )
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000052{
Alexandre Julliard0a860a01999-06-22 11:43:42 +000053 TEB *teb = THREAD_First;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000054
Alexandre Julliard0a860a01999-06-22 11:43:42 +000055 if (!id) return NtCurrentTeb();
56 while (teb)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000057 {
Alexandre Julliard0a860a01999-06-22 11:43:42 +000058 if ((DWORD)teb->tid == id) return teb;
59 teb = teb->next;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000060 }
Alexandre Julliard8feb3bc1999-02-28 12:25:03 +000061 /* Allow task handles to be used; convert to main thread */
62 if ( IsTask16( id ) )
63 {
64 TDB *pTask = (TDB *)GlobalLock16( id );
Alexandre Julliard0a860a01999-06-22 11:43:42 +000065 if (pTask) return pTask->teb;
Alexandre Julliard8feb3bc1999-02-28 12:25:03 +000066 }
67 SetLastError( ERROR_INVALID_PARAMETER );
68 return NULL;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000069}
70
71
Alexandre Julliard02e90081998-01-04 17:49:09 +000072/***********************************************************************
Alexandre Julliard0a860a01999-06-22 11:43:42 +000073 * THREAD_InitTEB
Alexandre Julliard02e90081998-01-04 17:49:09 +000074 *
Alexandre Julliard0a860a01999-06-22 11:43:42 +000075 * Initialization of a newly created TEB.
Alexandre Julliard02e90081998-01-04 17:49:09 +000076 */
Alexandre Julliard0a860a01999-06-22 11:43:42 +000077static BOOL THREAD_InitTEB( TEB *teb, DWORD stack_size, BOOL alloc_stack16,
78 LPSECURITY_ATTRIBUTES sa )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000079{
Alexandre Julliard21979011997-03-05 08:22:35 +000080 DWORD old_prot;
Alexandre Julliard02e90081998-01-04 17:49:09 +000081
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000082 /* Allocate the stack */
83
Alexandre Julliarda11d7b11998-03-01 20:05:02 +000084 /* 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.)
91 */
92 if (stack_size<1024*1024)
93 stack_size = 1024 * 1024;
94 if (stack_size >= 16*1024*1024)
Alexandre Julliard15657091999-05-23 10:25:25 +000095 WARN("Thread stack size is %ld MB.\n",stack_size/1024/1024);
Alexandre Julliard0a860a01999-06-22 11:43:42 +000096 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;
Alexandre Julliard21979011997-03-05 08:22:35 +0000100 /* Set a guard page at the bottom of the stack */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000101 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 */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000105
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000106 /* Allocate the 16-bit stack selector */
107
108 if (alloc_stack16)
109 {
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000110 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;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000116 }
117
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000118 /* Create the thread event */
119
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000120 if (!(teb->event = CreateEventA( NULL, FALSE, FALSE, NULL ))) goto error;
121 teb->event = ConvertToGlobalHandle( teb->event );
Alexandre Julliard13e55191999-02-21 18:34:18 +0000122 return TRUE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000123
124error:
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000125 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 );
Alexandre Julliard13e55191999-02-21 18:34:18 +0000128 return FALSE;
129}
130
131
132/***********************************************************************
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000133 * THREAD_FreeTEB
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000134 *
135 * Free data structures associated with a thread.
136 * Must be called from the context of another thread.
137 */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000138void CALLBACK THREAD_FreeTEB( ULONG_PTR arg )
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000139{
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000140 TEB *teb = (TEB *)arg;
141 TEB **pptr = &THREAD_First;
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000142
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000143 TRACE("(%p) called\n", teb );
144 SERVICE_Delete( teb->cleanup );
Ulrich Weigand36a1a251999-05-08 10:48:03 +0000145
Alexandre Julliardbda39691999-05-24 15:01:05 +0000146 PROCESS_CallUserSignalProc( USIG_THREAD_EXIT, 0 );
Ulrich Weigand8139c301999-04-01 11:43:05 +0000147
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000148 CloseHandle( teb->event );
149 while (*pptr && (*pptr != teb)) pptr = &(*pptr)->next;
150 if (*pptr) *pptr = teb->next;
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000151
152 /* Free the associated memory */
153
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000154 if (teb->stack_sel) SELECTOR_FreeBlock( teb->stack_sel, 1 );
155 SELECTOR_FreeBlock( teb->teb_sel, 1 );
156 close( teb->socket );
Alexandre Julliard5bc78081999-06-22 17:26:53 +0000157 if (teb->buffer) munmap( teb->buffer, teb->buffer_size );
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000158 VirtualFree( teb->stack_base, 0, MEM_RELEASE );
159 HeapFree( SystemHeap, 0, teb );
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000160}
161
162
163/***********************************************************************
Alexandre Julliard13e55191999-02-21 18:34:18 +0000164 * THREAD_CreateInitialThread
165 *
166 * Create the initial thread.
167 */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000168TEB *THREAD_CreateInitialThread( PDB *pdb, int server_fd )
Alexandre Julliard13e55191999-02-21 18:34:18 +0000169{
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000170 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;
Alexandre Julliard13e55191999-02-21 18:34:18 +0000177
178 /* Allocate the TEB selector (%fs register) */
179
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000180 if (!(initial_teb.teb_sel = SELECTOR_AllocBlock( &initial_teb, 0x1000,
181 SEGMENT_DATA, TRUE, FALSE )))
Alexandre Julliard13e55191999-02-21 18:34:18 +0000182 {
Alexandre Julliard15657091999-05-23 10:25:25 +0000183 MESSAGE("Could not allocate fs register for initial thread\n" );
Alexandre Julliard13e55191999-02-21 18:34:18 +0000184 return NULL;
185 }
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000186 SYSDEPS_SetCurThread( &initial_teb );
Alexandre Julliard13e55191999-02-21 18:34:18 +0000187
188 /* Now proceed with normal initialization */
189
Alexandre Julliard875c4b31999-03-23 14:09:41 +0000190 if (CLIENT_InitThread()) return NULL;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000191 if (!THREAD_InitTEB( &initial_teb, 0, TRUE, NULL )) return NULL;
192 return &initial_teb;
Alexandre Julliard13e55191999-02-21 18:34:18 +0000193}
194
195
196/***********************************************************************
197 * THREAD_Create
198 */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000199TEB *THREAD_Create( PDB *pdb, DWORD flags, DWORD stack_size, BOOL alloc_stack16,
Alexandre Julliardf0167521999-03-21 19:26:25 +0000200 LPSECURITY_ATTRIBUTES sa, int *server_handle )
Alexandre Julliard13e55191999-02-21 18:34:18 +0000201{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000202 struct new_thread_request *req = get_req_buffer();
Alexandre Julliardf0167521999-03-21 19:26:25 +0000203 int fd[2];
Eric Pouech63c7cdf1999-06-12 08:24:23 +0000204 HANDLE cleanup_object;
Alexandre Julliardf0167521999-03-21 19:26:25 +0000205
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000206 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;
Alexandre Julliard13e55191999-02-21 18:34:18 +0000216
217 /* Allocate the TEB selector (%fs register) */
218
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000219 *server_handle = -1;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000220 teb->teb_sel = SELECTOR_AllocBlock( teb, 0x1000, SEGMENT_DATA, TRUE, FALSE );
221 if (!teb->teb_sel) goto error;
Alexandre Julliard13e55191999-02-21 18:34:18 +0000222
Alexandre Julliardf0167521999-03-21 19:26:25 +0000223 /* Create the socket pair for server communication */
224
225 if (socketpair( AF_UNIX, SOCK_STREAM, 0, fd ) == -1)
226 {
227 SetLastError( ERROR_TOO_MANY_OPEN_FILES ); /* FIXME */
228 goto error;
229 }
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000230 teb->socket = fd[0];
Alexandre Julliardf0167521999-03-21 19:26:25 +0000231 fcntl( fd[0], F_SETFD, 1 ); /* set close on exec flag */
232
233 /* Create the thread on the server side */
234
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000235 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;
Alexandre Julliardf0167521999-03-21 19:26:25 +0000241
Alexandre Julliard13e55191999-02-21 18:34:18 +0000242 /* Do the rest of the initialization */
243
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000244 if (!THREAD_InitTEB( teb, stack_size, alloc_stack16, sa )) goto error;
245 teb->next = THREAD_First;
246 THREAD_First = teb;
Ulrich Weigand36a1a251999-05-08 10:48:03 +0000247
248 /* Install cleanup handler */
Eric Pouech63c7cdf1999-06-12 08:24:23 +0000249 if ( !DuplicateHandle( GetCurrentProcess(), *server_handle,
250 GetCurrentProcess(), &cleanup_object,
251 0, FALSE, DUPLICATE_SAME_ACCESS ) ) goto error;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000252 teb->cleanup = SERVICE_AddObject( cleanup_object, THREAD_FreeTEB, (ULONG_PTR)teb );
Ulrich Weigand36a1a251999-05-08 10:48:03 +0000253
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000254 return teb;
Alexandre Julliard13e55191999-02-21 18:34:18 +0000255
256error:
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000257 if (*server_handle != -1) CloseHandle( *server_handle );
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000258 if (teb->teb_sel) SELECTOR_FreeBlock( teb->teb_sel, 1 );
259 if (teb->socket != -1) close( teb->socket );
260 HeapFree( SystemHeap, 0, teb );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000261 return NULL;
262}
263
264
265/***********************************************************************
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000266 * THREAD_Start
267 *
268 * Start execution of a newly created thread. Does not return.
269 */
Alexandre Julliardf0167521999-03-21 19:26:25 +0000270static void THREAD_Start(void)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000271{
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000272 LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)NtCurrentTeb()->entry_point;
Alexandre Julliardbda39691999-05-24 15:01:05 +0000273 PROCESS_CallUserSignalProc( USIG_THREAD_INIT, 0 );
Ulrich Weigande469a581999-03-27 16:45:57 +0000274 PE_InitTls();
Bertho Stultiensc1d1cfe1999-04-18 12:14:06 +0000275 MODULE_DllThreadAttach( NULL );
Alexandre Julliardd131a171999-05-23 20:02:04 +0000276
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000277 if (NtCurrentTeb()->process->flags & PDB32_DEBUGGED) DEBUG_SendCreateThreadEvent( func );
Alexandre Julliardd131a171999-05-23 20:02:04 +0000278
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000279 ExitThread( func( NtCurrentTeb()->entry_arg ) );
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000280}
281
282
283/***********************************************************************
Alexandre Julliard349a9531997-02-02 19:01:52 +0000284 * CreateThread (KERNEL32.63)
Alexandre Julliard349a9531997-02-02 19:01:52 +0000285 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000286HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
Ulrich Weigand4526f2e1999-03-16 16:28:59 +0000287 LPTHREAD_START_ROUTINE start, LPVOID param,
288 DWORD flags, LPDWORD id )
Alexandre Julliard349a9531997-02-02 19:01:52 +0000289{
Alexandre Julliard96c08d81999-02-28 13:27:56 +0000290 int handle = -1;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000291 TEB *teb = THREAD_Create( PROCESS_Current(), flags, stack, TRUE, sa, &handle );
292 if (!teb) return INVALID_HANDLE_VALUE;
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)
Alexandre Julliard96c08d81999-02-28 13:27:56 +0000298 {
299 CloseHandle( handle );
300 return INVALID_HANDLE_VALUE;
301 }
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000302 if (id) *id = (DWORD)teb->tid;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000303 return handle;
304}
305
306
307/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000308 * ExitThread [KERNEL32.215] Ends a thread
309 *
310 * RETURNS
311 * None
Alexandre Julliard02e90081998-01-04 17:49:09 +0000312 */
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000313void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
Alexandre Julliard02e90081998-01-04 17:49:09 +0000314{
Bertho Stultiensc1d1cfe1999-04-18 12:14:06 +0000315 MODULE_DllThreadDetach( NULL );
Alexandre Julliard301f2c61999-03-14 19:48:04 +0000316 TerminateThread( GetCurrentThread(), code );
Alexandre Julliard02e90081998-01-04 17:49:09 +0000317}
318
319
320/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000321 * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
322 *
323 * RETURNS
324 * Pseudohandle for the current thread
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000325 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000326HANDLE WINAPI GetCurrentThread(void)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000327{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000328 return CURRENT_THREAD_PSEUDOHANDLE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000329}
330
331
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000332/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000333 * GetLastError [KERNEL.148] [KERNEL32.227] Returns last-error code.
334 *
335 * RETURNS
336 * Calling thread's last error code value.
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000337 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000338DWORD WINAPI GetLastError(void)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000339{
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000340 return NtCurrentTeb()->last_error;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000341}
342
343
344/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000345 * SetLastErrorEx [USER32.485] Sets the last-error code.
346 *
347 * RETURNS
348 * None.
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000349 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000350void WINAPI SetLastErrorEx(
351 DWORD error, /* [in] Per-thread error code */
352 DWORD type) /* [in] Error type */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000353{
Alexandre Julliard15657091999-05-23 10:25:25 +0000354 TRACE("(0x%08lx, 0x%08lx)\n", error,type);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000355 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:
Alexandre Julliard15657091999-05-23 10:25:25 +0000363 FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error,type);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000364 break;
365 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000366 SetLastError( error );
367}
368
369
370/**********************************************************************
Ulrich Weigande469a581999-03-27 16:45:57 +0000371 * TlsAlloc [KERNEL32.530] Allocates a TLS index.
372 *
373 * Allocates a thread local storage index
374 *
375 * RETURNS
376 * Success: TLS Index
377 * Failure: 0xFFFFFFFF
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000378 */
Ulrich Weigande469a581999-03-27 16:45:57 +0000379DWORD WINAPI TlsAlloc( void )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000380{
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000381 PDB *process = PROCESS_Current();
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000382 DWORD i, mask, ret = 0;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000383 DWORD *bits = process->tls_bits;
384 EnterCriticalSection( &process->crit_section );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000385 if (*bits == 0xffffffff)
386 {
387 bits++;
388 ret = 32;
389 if (*bits == 0xffffffff)
390 {
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000391 LeaveCriticalSection( &process->crit_section );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000392 SetLastError( ERROR_NO_MORE_ITEMS );
393 return 0xffffffff;
394 }
395 }
396 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
397 *bits |= mask;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000398 LeaveCriticalSection( &process->crit_section );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000399 return ret + i;
400}
401
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000402
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000403/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000404 * TlsFree [KERNEL32.531] Releases a TLS index.
405 *
406 * Releases a thread local storage index, making it available for reuse
407 *
408 * RETURNS
409 * Success: TRUE
410 * Failure: FALSE
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000411 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000412BOOL WINAPI TlsFree(
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000413 DWORD index) /* [in] TLS Index to free */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000414{
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000415 PDB *process = PROCESS_Current();
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000416 DWORD mask;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000417 DWORD *bits = process->tls_bits;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000418 if (index >= 64)
419 {
420 SetLastError( ERROR_INVALID_PARAMETER );
421 return FALSE;
422 }
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000423 EnterCriticalSection( &process->crit_section );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000424 if (index >= 32) bits++;
425 mask = (1 << (index & 31));
426 if (!(*bits & mask)) /* already free? */
427 {
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000428 LeaveCriticalSection( &process->crit_section );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000429 SetLastError( ERROR_INVALID_PARAMETER );
430 return FALSE;
431 }
432 *bits &= ~mask;
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000433 NtCurrentTeb()->tls_array[index] = 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000434 /* FIXME: should zero all other thread values */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000435 LeaveCriticalSection( &process->crit_section );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000436 return TRUE;
437}
438
439
440/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000441 * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
442 *
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000443 * RETURNS
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000444 * Success: Value stored in calling thread's TLS slot for index
445 * Failure: 0 and GetLastError returns NO_ERROR
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000446 */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000447LPVOID WINAPI TlsGetValue(
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000448 DWORD index) /* [in] TLS index to retrieve value for */
449{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000450 if (index >= 64)
451 {
452 SetLastError( ERROR_INVALID_PARAMETER );
453 return NULL;
454 }
455 SetLastError( ERROR_SUCCESS );
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000456 return NtCurrentTeb()->tls_array[index];
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000457}
458
459
460/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000461 * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
462 *
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000463 * RETURNS
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000464 * Success: TRUE
465 * Failure: FALSE
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000466 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000467BOOL WINAPI TlsSetValue(
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000468 DWORD index, /* [in] TLS index to set value for */
469 LPVOID value) /* [in] Value to be stored */
470{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000471 if (index >= 64)
472 {
473 SetLastError( ERROR_INVALID_PARAMETER );
474 return FALSE;
475 }
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000476 NtCurrentTeb()->tls_array[index] = value;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000477 return TRUE;
478}
479
480
481/***********************************************************************
Alexandre Julliarda845b881998-06-01 10:44:35 +0000482 * SetThreadContext [KERNEL32.670] Sets context of thread.
483 *
484 * RETURNS
485 * Success: TRUE
486 * Failure: FALSE
487 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000488BOOL WINAPI SetThreadContext(
489 HANDLE handle, /* [in] Handle to thread with context */
Alexandre Julliarda845b881998-06-01 10:44:35 +0000490 CONTEXT *context) /* [out] Address of context structure */
491{
Alexandre Julliard15657091999-05-23 10:25:25 +0000492 FIXME("not implemented\n" );
Alexandre Julliarda845b881998-06-01 10:44:35 +0000493 return TRUE;
494}
495
496/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000497 * GetThreadContext [KERNEL32.294] Retrieves context of thread.
498 *
499 * RETURNS
500 * Success: TRUE
501 * Failure: FALSE
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000502 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000503BOOL WINAPI GetThreadContext(
504 HANDLE handle, /* [in] Handle to thread with context */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000505 CONTEXT *context) /* [out] Address of context structure */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000506{
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000507 WORD cs, ds;
508
Alexandre Julliard15657091999-05-23 10:25:25 +0000509 FIXME("returning dummy info\n" );
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000510
511 /* make up some plausible values for segment registers */
512 GET_CS(cs);
513 GET_DS(ds);
514 context->SegCs = cs;
515 context->SegDs = ds;
516 context->SegEs = ds;
517 context->SegGs = ds;
518 context->SegSs = ds;
519 context->SegFs = ds;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000520 return TRUE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000521}
522
523
524/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000525 * GetThreadPriority [KERNEL32.296] Returns priority for thread.
526 *
527 * RETURNS
528 * Success: Thread's priority level.
529 * Failure: THREAD_PRIORITY_ERROR_RETURN
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000530 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000531INT WINAPI GetThreadPriority(
532 HANDLE hthread) /* [in] Handle to thread */
Alexandre Julliard349a9531997-02-02 19:01:52 +0000533{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000534 INT ret = THREAD_PRIORITY_ERROR_RETURN;
535 struct get_thread_info_request *req = get_req_buffer();
536 req->handle = hthread;
537 if (!server_call( REQ_GET_THREAD_INFO )) ret = req->priority;
538 return ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000539}
540
Alexandre Julliard349a9531997-02-02 19:01:52 +0000541
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000542/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000543 * SetThreadPriority [KERNEL32.514] Sets priority for thread.
544 *
545 * RETURNS
546 * Success: TRUE
547 * Failure: FALSE
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000548 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000549BOOL WINAPI SetThreadPriority(
550 HANDLE hthread, /* [in] Handle to thread */
551 INT priority) /* [in] Thread priority level */
Alexandre Julliard349a9531997-02-02 19:01:52 +0000552{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000553 struct set_thread_info_request *req = get_req_buffer();
554 req->handle = hthread;
555 req->priority = priority;
556 req->mask = SET_THREAD_INFO_PRIORITY;
557 return !server_call( REQ_SET_THREAD_INFO );
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000558}
559
560
561/**********************************************************************
562 * SetThreadAffinityMask (KERNEL32.669)
563 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000564DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000565{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000566 struct set_thread_info_request *req = get_req_buffer();
567 req->handle = hThread;
568 req->affinity = dwThreadAffinityMask;
569 req->mask = SET_THREAD_INFO_AFFINITY;
570 if (server_call( REQ_SET_THREAD_INFO )) return 0;
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000571 return 1; /* FIXME: should return previous value */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000572}
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000573
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000574
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000575/**********************************************************************
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000576 * TerminateThread [KERNEL32.685] Terminates a thread
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000577 *
578 * RETURNS
579 * Success: TRUE
580 * Failure: FALSE
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000581 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000582BOOL WINAPI TerminateThread(
583 HANDLE handle, /* [in] Handle to thread */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000584 DWORD exitcode) /* [in] Exit code for thread */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000585{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000586 struct terminate_thread_request *req = get_req_buffer();
587 req->handle = handle;
588 req->exit_code = exitcode;
589 return !server_call( REQ_TERMINATE_THREAD );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000590}
Alexandre Julliard77b99181997-09-14 17:17:23 +0000591
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000592
Alexandre Julliard77b99181997-09-14 17:17:23 +0000593/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000594 * GetExitCodeThread [KERNEL32.???] Gets termination status of thread.
595 *
596 * RETURNS
597 * Success: TRUE
598 * Failure: FALSE
Alexandre Julliard77b99181997-09-14 17:17:23 +0000599 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000600BOOL WINAPI GetExitCodeThread(
601 HANDLE hthread, /* [in] Handle to thread */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000602 LPDWORD exitcode) /* [out] Address to receive termination status */
Alexandre Julliard77b99181997-09-14 17:17:23 +0000603{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000604 BOOL ret = FALSE;
605 struct get_thread_info_request *req = get_req_buffer();
606 req->handle = hthread;
607 if (!server_call( REQ_GET_THREAD_INFO ))
608 {
609 if (exitcode) *exitcode = req->exit_code;
610 ret = TRUE;
611 }
612 return ret;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000613}
614
Alexandre Julliard77b99181997-09-14 17:17:23 +0000615
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000616/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000617 * ResumeThread [KERNEL32.587] Resumes a thread.
618 *
619 * Decrements a thread's suspend count. When count is zero, the
620 * execution of the thread is resumed.
621 *
622 * RETURNS
623 * Success: Previous suspend count
624 * Failure: 0xFFFFFFFF
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000625 * Already running: 0
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000626 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000627DWORD WINAPI ResumeThread(
Alexandre Julliarda3960291999-02-26 11:11:13 +0000628 HANDLE hthread) /* [in] Identifies thread to restart */
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000629{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000630 DWORD ret = 0xffffffff;
631 struct resume_thread_request *req = get_req_buffer();
632 req->handle = hthread;
633 if (!server_call( REQ_RESUME_THREAD )) ret = req->count;
634 return ret;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000635}
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000636
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000637
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000638/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000639 * SuspendThread [KERNEL32.681] Suspends a thread.
640 *
641 * RETURNS
642 * Success: Previous suspend count
643 * Failure: 0xFFFFFFFF
644 */
645DWORD WINAPI SuspendThread(
Alexandre Julliarda3960291999-02-26 11:11:13 +0000646 HANDLE hthread) /* [in] Handle to the thread */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000647{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000648 DWORD ret = 0xffffffff;
649 struct suspend_thread_request *req = get_req_buffer();
650 req->handle = hthread;
651 if (!server_call( REQ_SUSPEND_THREAD )) ret = req->count;
652 return ret;
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000653}
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000654
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000655
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000656/***********************************************************************
657 * QueueUserAPC (KERNEL32.566)
658 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000659DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000660{
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000661 struct queue_apc_request *req = get_req_buffer();
662 req->handle = hthread;
663 req->func = func;
664 req->param = (void *)data;
665 return !server_call( REQ_QUEUE_APC );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000666}
667
668
669/**********************************************************************
670 * GetThreadTimes [KERNEL32.???] Obtains timing information.
671 *
672 * NOTES
673 * What are the fields where these values are stored?
674 *
675 * RETURNS
676 * Success: TRUE
677 * Failure: FALSE
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000678 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000679BOOL WINAPI GetThreadTimes(
680 HANDLE thread, /* [in] Specifies the thread of interest */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000681 LPFILETIME creationtime, /* [out] When the thread was created */
682 LPFILETIME exittime, /* [out] When the thread was destroyed */
683 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
684 LPFILETIME usertime) /* [out] Time thread spent in user mode */
685{
Alexandre Julliard15657091999-05-23 10:25:25 +0000686 FIXME("(0x%08x): stub\n",thread);
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000687 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
688 return FALSE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000689}
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000690
691
692/**********************************************************************
693 * AttachThreadInput [KERNEL32.8] Attaches input of 1 thread to other
694 *
695 * Attaches the input processing mechanism of one thread to that of
696 * another thread.
697 *
698 * RETURNS
699 * Success: TRUE
700 * Failure: FALSE
Noel Borthwickb4278561999-02-05 10:37:53 +0000701 *
702 * TODO:
703 * 1. Reset the Key State (currenly per thread key state is not maintained)
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000704 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000705BOOL WINAPI AttachThreadInput(
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000706 DWORD idAttach, /* [in] Thread to attach */
707 DWORD idAttachTo, /* [in] Thread to attach to */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000708 BOOL fAttach) /* [in] Attach or detach */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000709{
Noel Borthwickb4278561999-02-05 10:37:53 +0000710 MESSAGEQUEUE *pSrcMsgQ = 0, *pTgtMsgQ = 0;
711 BOOL16 bRet = 0;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000712
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000713 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
Noel Borthwickb4278561999-02-05 10:37:53 +0000714
715 /* A thread cannot attach to itself */
716 if ( idAttach == idAttachTo )
717 goto CLEANUP;
718
719 /* According to the docs this method should fail if a
720 * "Journal record" hook is installed. (attaches all input queues together)
721 */
722 if ( HOOK_IsHooked( WH_JOURNALRECORD ) )
723 goto CLEANUP;
724
725 /* Retrieve message queues corresponding to the thread id's */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000726 pTgtMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetThreadQueue16( idAttach ) );
727 pSrcMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetThreadQueue16( idAttachTo ) );
Noel Borthwickb4278561999-02-05 10:37:53 +0000728
729 /* Ensure we have message queues and that Src and Tgt threads
730 * are not system threads.
731 */
732 if ( !pSrcMsgQ || !pTgtMsgQ || !pSrcMsgQ->pQData || !pTgtMsgQ->pQData )
733 goto CLEANUP;
734
735 if (fAttach) /* Attach threads */
736 {
737 /* Only attach if currently detached */
738 if ( pTgtMsgQ->pQData != pSrcMsgQ->pQData )
739 {
740 /* First release the target threads perQData */
741 PERQDATA_Release( pTgtMsgQ->pQData );
742
743 /* Share a reference to the source threads perQDATA */
744 PERQDATA_Addref( pSrcMsgQ->pQData );
745 pTgtMsgQ->pQData = pSrcMsgQ->pQData;
746 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000747 }
Noel Borthwickb4278561999-02-05 10:37:53 +0000748 else /* Detach threads */
749 {
750 /* Only detach if currently attached */
751 if ( pTgtMsgQ->pQData == pSrcMsgQ->pQData )
752 {
753 /* First release the target threads perQData */
754 PERQDATA_Release( pTgtMsgQ->pQData );
755
756 /* Give the target thread its own private perQDATA once more */
757 pTgtMsgQ->pQData = PERQDATA_CreateInstance();
758 }
759 }
760
761 /* TODO: Reset the Key State */
762
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000763 bRet = 1; /* Success */
Noel Borthwickb4278561999-02-05 10:37:53 +0000764
765CLEANUP:
766
767 /* Unlock the queues before returning */
768 if ( pSrcMsgQ )
769 QUEUE_Unlock( pSrcMsgQ );
770 if ( pTgtMsgQ )
771 QUEUE_Unlock( pTgtMsgQ );
772
773 return bRet;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000774}
775
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000776/**********************************************************************
777 * VWin32_BoostThreadGroup [KERNEL.535]
778 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000779VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000780{
Alexandre Julliard15657091999-05-23 10:25:25 +0000781 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000782}
783
784/**********************************************************************
785 * VWin32_BoostThreadStatic [KERNEL.536]
786 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000787VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000788{
Alexandre Julliard15657091999-05-23 10:25:25 +0000789 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000790}
791
Guy Albertellic66f5d51999-01-24 09:59:14 +0000792/**********************************************************************
793 * SetThreadLocale [KERNEL32.671] Sets the calling threads current locale.
794 *
795 * RETURNS
796 * Success: TRUE
797 * Failure: FALSE
798 *
799 * NOTES
800 * Implemented in NT only (3.1 and above according to MS
801 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000802BOOL WINAPI SetThreadLocale(
Guy Albertellic66f5d51999-01-24 09:59:14 +0000803 LCID lcid) /* [in] Locale identifier */
804{
805 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
806 return FALSE;
807}
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000808
809
810/**********************************************************************
811 * SetLastError [KERNEL.147] [KERNEL32.497] Sets the last-error code.
812 *
813 * RETURNS
814 * None.
815 */
816#undef SetLastError
817void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
818{
819 NtCurrentTeb()->last_error = error;
820}
821
822
823/***********************************************************************
824 * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
825 *
826 * RETURNS
827 * Thread identifier of calling thread
828 */
829#undef GetCurrentThreadId
830DWORD WINAPI GetCurrentThreadId(void)
831{
832 return (DWORD)NtCurrentTeb()->tid;
833}