TESTING -- override pthreads to fix gstreamer v5
[wine/multimedia.git] / dlls / kernel32 / thread.c
blob0e9de8203089c1183fb53824cfe03874d9e52fb3
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <fcntl.h>
26 #include <stdarg.h>
27 #include <sys/types.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "winternl.h"
38 #include "wine/exception.h"
39 #include "wine/library.h"
40 #include "wine/server.h"
41 #include "wine/debug.h"
43 #include "kernel_private.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(thread);
48 /***********************************************************************
49 * CreateThread (KERNEL32.@)
51 HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread( SECURITY_ATTRIBUTES *sa, SIZE_T stack, LPTHREAD_START_ROUTINE start,
52 LPVOID param, DWORD flags, LPDWORD id )
54 return CreateRemoteThread( GetCurrentProcess(),
55 sa, stack, start, param, flags, id );
59 /***************************************************************************
60 * CreateRemoteThread (KERNEL32.@)
62 * Creates a thread that runs in the address space of another process
64 * PARAMS
66 * RETURNS
67 * Success: Handle to the new thread.
68 * Failure: NULL. Use GetLastError() to find the error cause.
70 * BUGS
71 * Improper memory allocation: there's no ability to free new_thread_info
72 * in other process.
73 * Bad start address for RtlCreateUserThread because the library
74 * may be loaded at different address in other process.
76 HANDLE WINAPI CreateRemoteThread( HANDLE hProcess, SECURITY_ATTRIBUTES *sa, SIZE_T stack,
77 LPTHREAD_START_ROUTINE start, LPVOID param,
78 DWORD flags, LPDWORD id )
80 HANDLE handle;
81 CLIENT_ID client_id;
82 NTSTATUS status;
83 SIZE_T stack_reserve = 0, stack_commit = 0;
85 if (flags & STACK_SIZE_PARAM_IS_A_RESERVATION) stack_reserve = stack;
86 else stack_commit = stack;
88 status = RtlCreateUserThread( hProcess, NULL, TRUE,
89 NULL, stack_reserve, stack_commit,
90 (PRTL_THREAD_START_ROUTINE)start, param, &handle, &client_id );
91 if (status == STATUS_SUCCESS)
93 if (id) *id = HandleToULong(client_id.UniqueThread);
94 if (sa && (sa->nLength >= sizeof(*sa)) && sa->bInheritHandle)
95 SetHandleInformation( handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT );
96 if (!(flags & CREATE_SUSPENDED))
98 ULONG ret;
99 if (NtResumeThread( handle, &ret ))
101 NtClose( handle );
102 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
103 handle = 0;
107 else
109 SetLastError( RtlNtStatusToDosError(status) );
110 handle = 0;
112 return handle;
116 /***********************************************************************
117 * OpenThread [KERNEL32.@] Retrieves a handle to a thread from its thread id
119 HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId )
121 NTSTATUS status;
122 HANDLE handle;
123 OBJECT_ATTRIBUTES attr;
124 CLIENT_ID cid;
126 attr.Length = sizeof(attr);
127 attr.RootDirectory = 0;
128 attr.Attributes = bInheritHandle ? OBJ_INHERIT : 0;
129 attr.ObjectName = NULL;
130 attr.SecurityDescriptor = NULL;
131 attr.SecurityQualityOfService = NULL;
133 cid.UniqueProcess = 0; /* FIXME */
134 cid.UniqueThread = ULongToHandle(dwThreadId);
135 status = NtOpenThread( &handle, dwDesiredAccess, &attr, &cid );
136 if (status)
138 SetLastError( RtlNtStatusToDosError(status) );
139 handle = 0;
141 return handle;
145 /***********************************************************************
146 * ExitThread [KERNEL32.@] Ends a thread
148 * RETURNS
149 * None
151 void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
153 RtlExitUserThread( code );
157 /**********************************************************************
158 * TerminateThread [KERNEL32.@] Terminates a thread
160 * RETURNS
161 * Success: TRUE
162 * Failure: FALSE
164 BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */
165 DWORD exit_code) /* [in] Exit code for thread */
167 NTSTATUS status = NtTerminateThread( handle, exit_code );
168 if (status) SetLastError( RtlNtStatusToDosError(status) );
169 return !status;
173 /***********************************************************************
174 * FreeLibraryAndExitThread (KERNEL32.@)
176 void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
178 FreeLibrary(hLibModule);
179 ExitThread(dwExitCode);
183 /**********************************************************************
184 * GetExitCodeThread (KERNEL32.@)
186 * Gets termination status of thread.
188 * RETURNS
189 * Success: TRUE
190 * Failure: FALSE
192 BOOL WINAPI GetExitCodeThread(
193 HANDLE hthread, /* [in] Handle to thread */
194 LPDWORD exitcode) /* [out] Address to receive termination status */
196 THREAD_BASIC_INFORMATION info;
197 NTSTATUS status = NtQueryInformationThread( hthread, ThreadBasicInformation,
198 &info, sizeof(info), NULL );
200 if (status)
202 SetLastError( RtlNtStatusToDosError(status) );
203 return FALSE;
205 if (exitcode) *exitcode = info.ExitStatus;
206 return TRUE;
210 /***********************************************************************
211 * SetThreadContext [KERNEL32.@] Sets context of thread.
213 * RETURNS
214 * Success: TRUE
215 * Failure: FALSE
217 BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
218 const CONTEXT *context ) /* [in] Address of context structure */
220 NTSTATUS status = NtSetContextThread( handle, context );
221 if (status) SetLastError( RtlNtStatusToDosError(status) );
222 return !status;
226 /***********************************************************************
227 * GetThreadContext [KERNEL32.@] Retrieves context of thread.
229 * RETURNS
230 * Success: TRUE
231 * Failure: FALSE
233 BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
234 CONTEXT *context ) /* [out] Address of context structure */
236 NTSTATUS status = NtGetContextThread( handle, context );
237 if (status) SetLastError( RtlNtStatusToDosError(status) );
238 return !status;
242 /**********************************************************************
243 * SuspendThread [KERNEL32.@] Suspends a thread.
245 * RETURNS
246 * Success: Previous suspend count
247 * Failure: 0xFFFFFFFF
249 DWORD WINAPI SuspendThread( HANDLE hthread ) /* [in] Handle to the thread */
251 DWORD ret;
252 NTSTATUS status = NtSuspendThread( hthread, &ret );
254 if (status)
256 ret = ~0U;
257 SetLastError( RtlNtStatusToDosError(status) );
259 return ret;
263 /**********************************************************************
264 * ResumeThread [KERNEL32.@] Resumes a thread.
266 * Decrements a thread's suspend count. When count is zero, the
267 * execution of the thread is resumed.
269 * RETURNS
270 * Success: Previous suspend count
271 * Failure: 0xFFFFFFFF
272 * Already running: 0
274 DWORD WINAPI ResumeThread( HANDLE hthread ) /* [in] Identifies thread to restart */
276 DWORD ret;
277 NTSTATUS status = NtResumeThread( hthread, &ret );
279 if (status)
281 ret = ~0U;
282 SetLastError( RtlNtStatusToDosError(status) );
284 return ret;
288 /**********************************************************************
289 * GetThreadPriority [KERNEL32.@] Returns priority for thread.
291 * RETURNS
292 * Success: Thread's priority level.
293 * Failure: THREAD_PRIORITY_ERROR_RETURN
295 INT WINAPI GetThreadPriority(
296 HANDLE hthread) /* [in] Handle to thread */
298 THREAD_BASIC_INFORMATION info;
299 NTSTATUS status = NtQueryInformationThread( hthread, ThreadBasicInformation,
300 &info, sizeof(info), NULL );
302 if (status)
304 SetLastError( RtlNtStatusToDosError(status) );
305 return THREAD_PRIORITY_ERROR_RETURN;
307 return info.Priority;
311 /**********************************************************************
312 * SetThreadPriority [KERNEL32.@] Sets priority for thread.
314 * RETURNS
315 * Success: TRUE
316 * Failure: FALSE
318 BOOL WINAPI SetThreadPriority(
319 HANDLE hthread, /* [in] Handle to thread */
320 INT priority) /* [in] Thread priority level */
322 DWORD prio = priority;
323 NTSTATUS status;
325 status = NtSetInformationThread(hthread, ThreadBasePriority,
326 &prio, sizeof(prio));
328 if (status)
330 SetLastError( RtlNtStatusToDosError(status) );
331 return FALSE;
334 return TRUE;
338 /**********************************************************************
339 * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread.
341 * Always reports that priority boost is disabled.
343 * RETURNS
344 * Success: TRUE.
345 * Failure: FALSE
347 BOOL WINAPI GetThreadPriorityBoost(
348 HANDLE hthread, /* [in] Handle to thread */
349 PBOOL pstate) /* [out] pointer to var that receives the boost state */
351 if (pstate) *pstate = FALSE;
352 return TRUE;
356 /**********************************************************************
357 * SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread.
359 * Priority boost is not implemented, but we return TRUE
360 * anyway because some games crash otherwise.
362 BOOL WINAPI SetThreadPriorityBoost(
363 HANDLE hthread, /* [in] Handle to thread */
364 BOOL disable) /* [in] TRUE to disable priority boost */
366 return TRUE;
370 /**********************************************************************
371 * SetThreadStackGuarantee (KERNEL32.@)
373 BOOL WINAPI SetThreadStackGuarantee(PULONG stacksize)
375 static int once;
376 if (once++ == 0)
377 FIXME("(%p): stub\n", stacksize);
378 return TRUE;
381 /***********************************************************************
382 * GetThreadGroupAffinity (KERNEL32.@)
384 BOOL WINAPI GetThreadGroupAffinity( HANDLE thread, GROUP_AFFINITY *affinity )
386 NTSTATUS status;
388 if (!affinity)
390 SetLastError( ERROR_INVALID_PARAMETER );
391 return FALSE;
394 status = NtQueryInformationThread( thread, ThreadGroupInformation,
395 affinity, sizeof(*affinity), NULL );
396 if (status)
398 SetLastError( RtlNtStatusToDosError(status) );
399 return FALSE;
402 return TRUE;
405 /***********************************************************************
406 * SetThreadGroupAffinity (KERNEL32.@)
408 BOOL WINAPI SetThreadGroupAffinity( HANDLE thread, const GROUP_AFFINITY *affinity_new,
409 GROUP_AFFINITY *affinity_old )
411 NTSTATUS status;
413 if (affinity_old && !GetThreadGroupAffinity( thread, affinity_old ))
414 return FALSE;
416 status = NtSetInformationThread( thread, ThreadGroupInformation,
417 affinity_new, sizeof(*affinity_new) );
418 if (status)
420 SetLastError( RtlNtStatusToDosError(status) );
421 return FALSE;
424 return TRUE;
427 /**********************************************************************
428 * SetThreadAffinityMask (KERNEL32.@)
430 DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD_PTR dwThreadAffinityMask )
432 NTSTATUS status;
433 THREAD_BASIC_INFORMATION tbi;
435 status = NtQueryInformationThread( hThread, ThreadBasicInformation,
436 &tbi, sizeof(tbi), NULL );
437 if (status)
439 SetLastError( RtlNtStatusToDosError(status) );
440 return 0;
442 status = NtSetInformationThread( hThread, ThreadAffinityMask,
443 &dwThreadAffinityMask,
444 sizeof(dwThreadAffinityMask));
445 if (status)
447 SetLastError( RtlNtStatusToDosError(status) );
448 return 0;
450 return tbi.AffinityMask;
454 /**********************************************************************
455 * SetThreadIdealProcessor [KERNEL32.@] Sets preferred processor for thread.
457 * RETURNS
458 * Success: Value of last call to SetThreadIdealProcessor
459 * Failure: -1
461 DWORD WINAPI SetThreadIdealProcessor(
462 HANDLE hThread, /* [in] Specifies the thread of interest */
463 DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */
465 FIXME("(%p): stub\n",hThread);
466 if (dwIdealProcessor > MAXIMUM_PROCESSORS)
468 SetLastError(ERROR_INVALID_PARAMETER);
469 return ~0u;
471 return 0;
475 /***********************************************************************
476 * GetThreadSelectorEntry (KERNEL32.@)
478 BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldtent )
480 THREAD_DESCRIPTOR_INFORMATION tdi;
481 NTSTATUS status;
483 tdi.Selector = sel;
484 status = NtQueryInformationThread( hthread, ThreadDescriptorTableEntry, &tdi, sizeof(tdi), NULL);
485 if (status)
487 SetLastError( RtlNtStatusToDosError(status) );
488 return FALSE;
490 *ldtent = tdi.Entry;
491 return TRUE;
495 /* callback for QueueUserAPC */
496 static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
498 PAPCFUNC func = (PAPCFUNC)arg1;
499 func( arg2 );
502 /***********************************************************************
503 * QueueUserAPC (KERNEL32.@)
505 DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
507 NTSTATUS status = NtQueueApcThread( hthread, call_user_apc, (ULONG_PTR)func, data, 0 );
509 if (status) SetLastError( RtlNtStatusToDosError(status) );
510 return !status;
513 /***********************************************************************
514 * QueueUserWorkItem (KERNEL32.@)
516 BOOL WINAPI QueueUserWorkItem( LPTHREAD_START_ROUTINE Function, PVOID Context, ULONG Flags )
518 NTSTATUS status;
520 TRACE("(%p,%p,0x%08x)\n", Function, Context, Flags);
522 status = RtlQueueWorkItem( Function, Context, Flags );
524 if (status) SetLastError( RtlNtStatusToDosError(status) );
525 return !status;
528 /**********************************************************************
529 * GetThreadTimes [KERNEL32.@] Obtains timing information.
531 * RETURNS
532 * Success: TRUE
533 * Failure: FALSE
535 BOOL WINAPI GetThreadTimes(
536 HANDLE thread, /* [in] Specifies the thread of interest */
537 LPFILETIME creationtime, /* [out] When the thread was created */
538 LPFILETIME exittime, /* [out] When the thread was destroyed */
539 LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
540 LPFILETIME usertime) /* [out] Time thread spent in user mode */
542 KERNEL_USER_TIMES kusrt;
543 NTSTATUS status;
545 status = NtQueryInformationThread(thread, ThreadTimes, &kusrt,
546 sizeof(kusrt), NULL);
547 if (status)
549 SetLastError( RtlNtStatusToDosError(status) );
550 return FALSE;
552 if (creationtime)
554 creationtime->dwLowDateTime = kusrt.CreateTime.u.LowPart;
555 creationtime->dwHighDateTime = kusrt.CreateTime.u.HighPart;
557 if (exittime)
559 exittime->dwLowDateTime = kusrt.ExitTime.u.LowPart;
560 exittime->dwHighDateTime = kusrt.ExitTime.u.HighPart;
562 if (kerneltime)
564 kerneltime->dwLowDateTime = kusrt.KernelTime.u.LowPart;
565 kerneltime->dwHighDateTime = kusrt.KernelTime.u.HighPart;
567 if (usertime)
569 usertime->dwLowDateTime = kusrt.UserTime.u.LowPart;
570 usertime->dwHighDateTime = kusrt.UserTime.u.HighPart;
573 return TRUE;
576 /**********************************************************************
577 * GetThreadId [KERNEL32.@]
579 * Retrieve the identifier of a thread.
581 * PARAMS
582 * Thread [I] The thread to retrieve the identifier of.
584 * RETURNS
585 * Success: Identifier of the target thread.
586 * Failure: 0
588 DWORD WINAPI GetThreadId(HANDLE Thread)
590 THREAD_BASIC_INFORMATION tbi;
591 NTSTATUS status;
593 TRACE("(%p)\n", Thread);
595 status = NtQueryInformationThread(Thread, ThreadBasicInformation, &tbi,
596 sizeof(tbi), NULL);
597 if (status)
599 SetLastError( RtlNtStatusToDosError(status) );
600 return 0;
603 return HandleToULong(tbi.ClientId.UniqueThread);
606 /**********************************************************************
607 * GetProcessIdOfThread [KERNEL32.@]
609 * Retrieve process identifier given thread belongs to.
611 * PARAMS
612 * Thread [I] The thread identifier.
614 * RETURNS
615 * Success: Process identifier
616 * Failure: 0
618 DWORD WINAPI GetProcessIdOfThread(HANDLE Thread)
620 THREAD_BASIC_INFORMATION tbi;
621 NTSTATUS status;
623 TRACE("(%p)\n", Thread);
625 status = NtQueryInformationThread(Thread, ThreadBasicInformation, &tbi,
626 sizeof(tbi), NULL);
627 if (status)
629 SetLastError( RtlNtStatusToDosError(status) );
630 return 0;
633 return HandleToULong(tbi.ClientId.UniqueProcess);
636 /***********************************************************************
637 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
639 * RETURNS
640 * Pseudohandle for the current thread
642 #undef GetCurrentThread
643 HANDLE WINAPI GetCurrentThread(void)
645 return (HANDLE)~(ULONG_PTR)1;
649 #ifdef __i386__
651 /***********************************************************************
652 * SetLastError (KERNEL32.@)
654 /* void WINAPI SetLastError( DWORD error ); */
655 __ASM_STDCALL_FUNC( SetLastError, 4,
656 "movl 4(%esp),%eax\n\t"
657 ".byte 0x64\n\t"
658 "movl %eax,0x34\n\t"
659 "ret $4" )
661 /***********************************************************************
662 * GetLastError (KERNEL32.@)
664 /* DWORD WINAPI GetLastError(void); */
665 __ASM_STDCALL_FUNC( GetLastError, 0, ".byte 0x64\n\tmovl 0x34,%eax\n\tret" )
667 /***********************************************************************
668 * GetCurrentProcessId (KERNEL32.@)
670 /* DWORD WINAPI GetCurrentProcessId(void) */
671 __ASM_STDCALL_FUNC( GetCurrentProcessId, 0, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" )
673 /***********************************************************************
674 * GetCurrentThreadId (KERNEL32.@)
676 /* DWORD WINAPI GetCurrentThreadId(void) */
677 __ASM_STDCALL_FUNC( GetCurrentThreadId, 0, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" )
679 /***********************************************************************
680 * GetProcessHeap (KERNEL32.@)
682 /* HANDLE WINAPI GetProcessHeap(void) */
683 __ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x64\n\tmovl 0x30,%eax\n\tmovl 0x18(%eax),%eax\n\tret");
685 #elif defined(__x86_64__) && !defined(__APPLE__)
687 /***********************************************************************
688 * SetLastError (KERNEL32.@)
690 /* void WINAPI SetLastError( DWORD error ); */
691 __ASM_STDCALL_FUNC( SetLastError, 8, ".byte 0x65\n\tmovl %ecx,0x68\n\tret" );
693 /***********************************************************************
694 * GetLastError (KERNEL32.@)
696 /* DWORD WINAPI GetLastError(void); */
697 __ASM_STDCALL_FUNC( GetLastError, 0, ".byte 0x65\n\tmovl 0x68,%eax\n\tret" );
699 /***********************************************************************
700 * GetCurrentProcessId (KERNEL32.@)
702 /* DWORD WINAPI GetCurrentProcessId(void) */
703 __ASM_STDCALL_FUNC( GetCurrentProcessId, 0, ".byte 0x65\n\tmovl 0x40,%eax\n\tret" );
705 /***********************************************************************
706 * GetCurrentThreadId (KERNEL32.@)
708 /* DWORD WINAPI GetCurrentThreadId(void) */
709 __ASM_STDCALL_FUNC( GetCurrentThreadId, 0, ".byte 0x65\n\tmovl 0x48,%eax\n\tret" );
711 /***********************************************************************
712 * GetProcessHeap (KERNEL32.@)
714 /* HANDLE WINAPI GetProcessHeap(void) */
715 __ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x65\n\tmovq 0x60,%rax\n\tmovq 0x30(%rax),%rax\n\tret");
717 #else /* __x86_64__ */
719 /**********************************************************************
720 * SetLastError (KERNEL32.@)
722 * Sets the last-error code.
724 * RETURNS
725 * Nothing.
727 void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
729 NtCurrentTeb()->LastErrorValue = error;
732 /**********************************************************************
733 * GetLastError (KERNEL32.@)
735 * Get the last-error code.
737 * RETURNS
738 * last-error code.
740 DWORD WINAPI GetLastError(void)
742 return NtCurrentTeb()->LastErrorValue;
745 /***********************************************************************
746 * GetCurrentProcessId (KERNEL32.@)
748 * Get the current process identifier.
750 * RETURNS
751 * current process identifier
753 DWORD WINAPI GetCurrentProcessId(void)
755 return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
758 /***********************************************************************
759 * GetCurrentThreadId (KERNEL32.@)
761 * Get the current thread identifier.
763 * RETURNS
764 * current thread identifier
766 DWORD WINAPI GetCurrentThreadId(void)
768 return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);
771 /***********************************************************************
772 * GetProcessHeap (KERNEL32.@)
774 HANDLE WINAPI GetProcessHeap(void)
776 return NtCurrentTeb()->Peb->ProcessHeap;
779 #endif /* __i386__ */
781 /*************************************************************************
782 * rtlmode_to_win32mode
784 static DWORD rtlmode_to_win32mode( DWORD rtlmode )
786 DWORD win32mode = 0;
788 if (rtlmode & 0x10)
789 win32mode |= SEM_FAILCRITICALERRORS;
790 if (rtlmode & 0x20)
791 win32mode |= SEM_NOGPFAULTERRORBOX;
792 if (rtlmode & 0x40)
793 win32mode |= SEM_NOOPENFILEERRORBOX;
795 return win32mode;
798 /***********************************************************************
799 * SetThreadErrorMode (KERNEL32.@)
801 * Set the thread local error mode.
803 * PARAMS
804 * mode [I] The new error mode, a bitwise or of SEM_FAILCRITICALERRORS,
805 * SEM_NOGPFAULTERRORBOX and SEM_NOOPENFILEERRORBOX.
806 * oldmode [O] Destination of the old error mode (may be NULL)
808 * RETURNS
809 * Success: TRUE
810 * Failure: FALSE, check GetLastError
812 BOOL WINAPI SetThreadErrorMode( DWORD mode, LPDWORD oldmode )
814 NTSTATUS status;
815 DWORD tmp = 0;
817 if (mode & ~(SEM_FAILCRITICALERRORS |
818 SEM_NOGPFAULTERRORBOX |
819 SEM_NOOPENFILEERRORBOX))
821 SetLastError( ERROR_INVALID_PARAMETER );
822 return FALSE;
825 if (mode & SEM_FAILCRITICALERRORS)
826 tmp |= 0x10;
827 if (mode & SEM_NOGPFAULTERRORBOX)
828 tmp |= 0x20;
829 if (mode & SEM_NOOPENFILEERRORBOX)
830 tmp |= 0x40;
832 status = RtlSetThreadErrorMode( tmp, oldmode );
833 if (status)
835 SetLastError( RtlNtStatusToDosError(status) );
836 return FALSE;
839 if (oldmode)
840 *oldmode = rtlmode_to_win32mode(*oldmode);
842 return TRUE;
845 /***********************************************************************
846 * GetThreadErrorMode (KERNEL32.@)
848 * Get the thread local error mode.
850 * PARAMS
851 * None.
853 * RETURNS
854 * The current thread local error mode.
856 DWORD WINAPI GetThreadErrorMode( void )
858 return rtlmode_to_win32mode( RtlGetThreadErrorMode() );
861 /***********************************************************************
862 * GetThreadUILanguage (KERNEL32.@)
864 * Get the current thread's language identifier.
866 * PARAMS
867 * None.
869 * RETURNS
870 * The current thread's language identifier.
872 LANGID WINAPI GetThreadUILanguage( void )
874 LANGID lang;
875 NtQueryDefaultUILanguage( &lang );
876 FIXME(": stub, returning default language.\n");
877 return lang;
880 /***********************************************************************
881 * GetThreadIOPendingFlag (KERNEL32.@)
883 BOOL WINAPI GetThreadIOPendingFlag( HANDLE thread, PBOOL io_pending )
885 FIXME("%p, %p\n", thread, io_pending);
886 *io_pending = FALSE;
887 return TRUE;
890 /***********************************************************************
891 * SetThreadPreferredUILanguages (KERNEL32.@)
893 BOOL WINAPI SetThreadPreferredUILanguages( DWORD flags, PCZZWSTR buffer, PULONG count )
895 FIXME( "%u, %p, %p\n", flags, buffer, count );
896 return TRUE;
899 /***********************************************************************
900 * GetThreadPreferredUILanguages (KERNEL32.@)
902 BOOL WINAPI GetThreadPreferredUILanguages( DWORD flags, PULONG count, PCZZWSTR buffer, PULONG buffersize )
904 FIXME( "%u, %p, %p %p\n", flags, count, buffer, buffersize );
905 *count = 0;
906 *buffersize = 0;
907 return TRUE;
910 /***********************************************************************
911 * CallbackMayRunLong (KERNEL32.@)
913 BOOL WINAPI CallbackMayRunLong( TP_CALLBACK_INSTANCE *instance )
915 NTSTATUS status;
917 TRACE( "%p\n", instance );
919 status = TpCallbackMayRunLong( instance );
920 if (status)
922 SetLastError( RtlNtStatusToDosError(status) );
923 return FALSE;
926 return TRUE;
929 /***********************************************************************
930 * CreateThreadpool (KERNEL32.@)
932 PTP_POOL WINAPI CreateThreadpool( PVOID reserved )
934 TP_POOL *pool;
935 NTSTATUS status;
937 TRACE( "%p\n", reserved );
939 status = TpAllocPool( &pool, reserved );
940 if (status)
942 SetLastError( RtlNtStatusToDosError(status) );
943 return NULL;
946 return pool;
949 /***********************************************************************
950 * CreateThreadpoolCleanupGroup (KERNEL32.@)
952 PTP_CLEANUP_GROUP WINAPI CreateThreadpoolCleanupGroup( void )
954 TP_CLEANUP_GROUP *group;
955 NTSTATUS status;
957 TRACE( "\n" );
959 status = TpAllocCleanupGroup( &group );
960 if (status)
962 SetLastError( RtlNtStatusToDosError(status) );
963 return NULL;
966 return group;
969 /***********************************************************************
970 * CreateThreadpoolTimer (KERNEL32.@)
972 PTP_TIMER WINAPI CreateThreadpoolTimer( PTP_TIMER_CALLBACK callback, PVOID userdata,
973 TP_CALLBACK_ENVIRON *environment )
975 TP_TIMER *timer;
976 NTSTATUS status;
978 TRACE( "%p, %p, %p\n", callback, userdata, environment );
980 status = TpAllocTimer( &timer, callback, userdata, environment );
981 if (status)
983 SetLastError( RtlNtStatusToDosError(status) );
984 return NULL;
987 return timer;
990 /***********************************************************************
991 * CreateThreadpoolWait (KERNEL32.@)
993 PTP_WAIT WINAPI CreateThreadpoolWait( PTP_WAIT_CALLBACK callback, PVOID userdata,
994 TP_CALLBACK_ENVIRON *environment )
996 TP_WAIT *wait;
997 NTSTATUS status;
999 TRACE( "%p, %p, %p\n", callback, userdata, environment );
1001 status = TpAllocWait( &wait, callback, userdata, environment );
1002 if (status)
1004 SetLastError( RtlNtStatusToDosError(status) );
1005 return NULL;
1008 return wait;
1011 /***********************************************************************
1012 * CreateThreadpoolWork (KERNEL32.@)
1014 PTP_WORK WINAPI CreateThreadpoolWork( PTP_WORK_CALLBACK callback, PVOID userdata,
1015 TP_CALLBACK_ENVIRON *environment )
1017 TP_WORK *work;
1018 NTSTATUS status;
1020 TRACE( "%p, %p, %p\n", callback, userdata, environment );
1022 status = TpAllocWork( &work, callback, userdata, environment );
1023 if (status)
1025 SetLastError( RtlNtStatusToDosError(status) );
1026 return NULL;
1029 return work;
1032 /***********************************************************************
1033 * SetThreadpoolTimer (KERNEL32.@)
1035 VOID WINAPI SetThreadpoolTimer( TP_TIMER *timer, FILETIME *due_time,
1036 DWORD period, DWORD window_length )
1038 LARGE_INTEGER timeout;
1040 TRACE( "%p, %p, %u, %u\n", timer, due_time, period, window_length );
1042 if (due_time)
1044 timeout.u.LowPart = due_time->dwLowDateTime;
1045 timeout.u.HighPart = due_time->dwHighDateTime;
1048 TpSetTimer( timer, due_time ? &timeout : NULL, period, window_length );
1051 /***********************************************************************
1052 * SetThreadpoolWait (KERNEL32.@)
1054 VOID WINAPI SetThreadpoolWait( TP_WAIT *wait, HANDLE handle, FILETIME *due_time )
1056 LARGE_INTEGER timeout;
1058 TRACE( "%p, %p, %p\n", wait, handle, due_time );
1060 if (!handle)
1062 due_time = NULL;
1064 else if (due_time)
1066 timeout.u.LowPart = due_time->dwLowDateTime;
1067 timeout.u.HighPart = due_time->dwHighDateTime;
1070 TpSetWait( wait, handle, due_time ? &timeout : NULL );
1073 /***********************************************************************
1074 * TrySubmitThreadpoolCallback (KERNEL32.@)
1076 BOOL WINAPI TrySubmitThreadpoolCallback( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
1077 TP_CALLBACK_ENVIRON *environment )
1079 NTSTATUS status;
1081 TRACE( "%p, %p, %p\n", callback, userdata, environment );
1083 status = TpSimpleTryPost( callback, userdata, environment );
1084 if (status)
1086 SetLastError( RtlNtStatusToDosError(status) );
1087 return FALSE;
1090 return TRUE;