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
22 #include "wine/port.h"
27 #include <sys/types.h>
33 #define WIN32_NO_STATUS
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
67 * Success: Handle to the new thread.
68 * Failure: NULL. Use GetLastError() to find the error cause.
71 * Improper memory allocation: there's no ability to free new_thread_info
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
)
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
))
99 if (NtResumeThread( handle
, &ret
))
102 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
109 SetLastError( RtlNtStatusToDosError(status
) );
116 /***********************************************************************
117 * OpenThread [KERNEL32.@] Retrieves a handle to a thread from its thread id
119 HANDLE WINAPI
OpenThread( DWORD dwDesiredAccess
, BOOL bInheritHandle
, DWORD dwThreadId
)
123 OBJECT_ATTRIBUTES attr
;
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
);
138 SetLastError( RtlNtStatusToDosError(status
) );
145 /***********************************************************************
146 * ExitThread [KERNEL32.@] Ends a thread
151 void WINAPI
ExitThread( DWORD code
) /* [in] Exit code for this thread */
153 RtlExitUserThread( code
);
157 /**********************************************************************
158 * TerminateThread [KERNEL32.@] Terminates a thread
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
) );
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.
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
);
202 SetLastError( RtlNtStatusToDosError(status
) );
205 if (exitcode
) *exitcode
= info
.ExitStatus
;
210 /***********************************************************************
211 * SetThreadContext [KERNEL32.@] Sets context of thread.
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
) );
226 /***********************************************************************
227 * GetThreadContext [KERNEL32.@] Retrieves context of thread.
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
) );
242 /**********************************************************************
243 * SuspendThread [KERNEL32.@] Suspends a thread.
246 * Success: Previous suspend count
247 * Failure: 0xFFFFFFFF
249 DWORD WINAPI
SuspendThread( HANDLE hthread
) /* [in] Handle to the thread */
252 NTSTATUS status
= NtSuspendThread( hthread
, &ret
);
257 SetLastError( RtlNtStatusToDosError(status
) );
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.
270 * Success: Previous suspend count
271 * Failure: 0xFFFFFFFF
274 DWORD WINAPI
ResumeThread( HANDLE hthread
) /* [in] Identifies thread to restart */
277 NTSTATUS status
= NtResumeThread( hthread
, &ret
);
282 SetLastError( RtlNtStatusToDosError(status
) );
288 /**********************************************************************
289 * GetThreadPriority [KERNEL32.@] Returns priority for thread.
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
);
304 SetLastError( RtlNtStatusToDosError(status
) );
305 return THREAD_PRIORITY_ERROR_RETURN
;
307 return info
.Priority
;
311 /**********************************************************************
312 * SetThreadPriority [KERNEL32.@] Sets priority for thread.
318 BOOL WINAPI
SetThreadPriority(
319 HANDLE hthread
, /* [in] Handle to thread */
320 INT priority
) /* [in] Thread priority level */
322 DWORD prio
= priority
;
325 status
= NtSetInformationThread(hthread
, ThreadBasePriority
,
326 &prio
, sizeof(prio
));
330 SetLastError( RtlNtStatusToDosError(status
) );
338 /**********************************************************************
339 * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread.
341 * Always reports that priority boost is disabled.
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
;
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 */
370 /**********************************************************************
371 * SetThreadStackGuarantee (KERNEL32.@)
373 BOOL WINAPI
SetThreadStackGuarantee(PULONG stacksize
)
377 FIXME("(%p): stub\n", stacksize
);
381 /***********************************************************************
382 * GetThreadGroupAffinity (KERNEL32.@)
384 BOOL WINAPI
GetThreadGroupAffinity( HANDLE thread
, GROUP_AFFINITY
*affinity
)
390 SetLastError( ERROR_INVALID_PARAMETER
);
394 status
= NtQueryInformationThread( thread
, ThreadGroupInformation
,
395 affinity
, sizeof(*affinity
), NULL
);
398 SetLastError( RtlNtStatusToDosError(status
) );
405 /***********************************************************************
406 * SetThreadGroupAffinity (KERNEL32.@)
408 BOOL WINAPI
SetThreadGroupAffinity( HANDLE thread
, const GROUP_AFFINITY
*affinity_new
,
409 GROUP_AFFINITY
*affinity_old
)
413 if (affinity_old
&& !GetThreadGroupAffinity( thread
, affinity_old
))
416 status
= NtSetInformationThread( thread
, ThreadGroupInformation
,
417 affinity_new
, sizeof(*affinity_new
) );
420 SetLastError( RtlNtStatusToDosError(status
) );
427 /**********************************************************************
428 * SetThreadAffinityMask (KERNEL32.@)
430 DWORD_PTR WINAPI
SetThreadAffinityMask( HANDLE hThread
, DWORD_PTR dwThreadAffinityMask
)
433 THREAD_BASIC_INFORMATION tbi
;
435 status
= NtQueryInformationThread( hThread
, ThreadBasicInformation
,
436 &tbi
, sizeof(tbi
), NULL
);
439 SetLastError( RtlNtStatusToDosError(status
) );
442 status
= NtSetInformationThread( hThread
, ThreadAffinityMask
,
443 &dwThreadAffinityMask
,
444 sizeof(dwThreadAffinityMask
));
447 SetLastError( RtlNtStatusToDosError(status
) );
450 return tbi
.AffinityMask
;
454 /**********************************************************************
455 * SetThreadIdealProcessor [KERNEL32.@] Sets preferred processor for thread.
458 * Success: Value of last call to SetThreadIdealProcessor
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
);
474 /***********************************************************************
475 * SetThreadIdealProcessorEx (KERNEL32.@)
477 BOOL WINAPI
SetThreadIdealProcessorEx( HANDLE thread
, PROCESSOR_NUMBER
*ideal
, PROCESSOR_NUMBER
*previous
)
479 FIXME("(%p %p %p): stub\n", thread
, ideal
, previous
);
480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
484 /***********************************************************************
485 * GetThreadSelectorEntry (KERNEL32.@)
487 BOOL WINAPI
GetThreadSelectorEntry( HANDLE hthread
, DWORD sel
, LPLDT_ENTRY ldtent
)
489 THREAD_DESCRIPTOR_INFORMATION tdi
;
493 status
= NtQueryInformationThread( hthread
, ThreadDescriptorTableEntry
, &tdi
, sizeof(tdi
), NULL
);
496 SetLastError( RtlNtStatusToDosError(status
) );
504 /* callback for QueueUserAPC */
505 static void CALLBACK
call_user_apc( ULONG_PTR arg1
, ULONG_PTR arg2
, ULONG_PTR arg3
)
507 PAPCFUNC func
= (PAPCFUNC
)arg1
;
511 /***********************************************************************
512 * QueueUserAPC (KERNEL32.@)
514 DWORD WINAPI
QueueUserAPC( PAPCFUNC func
, HANDLE hthread
, ULONG_PTR data
)
516 NTSTATUS status
= NtQueueApcThread( hthread
, call_user_apc
, (ULONG_PTR
)func
, data
, 0 );
518 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
522 /***********************************************************************
523 * QueueUserWorkItem (KERNEL32.@)
525 BOOL WINAPI
QueueUserWorkItem( LPTHREAD_START_ROUTINE Function
, PVOID Context
, ULONG Flags
)
529 TRACE("(%p,%p,0x%08x)\n", Function
, Context
, Flags
);
531 status
= RtlQueueWorkItem( Function
, Context
, Flags
);
533 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
537 /**********************************************************************
538 * GetThreadTimes [KERNEL32.@] Obtains timing information.
544 BOOL WINAPI
GetThreadTimes(
545 HANDLE thread
, /* [in] Specifies the thread of interest */
546 LPFILETIME creationtime
, /* [out] When the thread was created */
547 LPFILETIME exittime
, /* [out] When the thread was destroyed */
548 LPFILETIME kerneltime
, /* [out] Time thread spent in kernel mode */
549 LPFILETIME usertime
) /* [out] Time thread spent in user mode */
551 KERNEL_USER_TIMES kusrt
;
554 status
= NtQueryInformationThread(thread
, ThreadTimes
, &kusrt
,
555 sizeof(kusrt
), NULL
);
558 SetLastError( RtlNtStatusToDosError(status
) );
563 creationtime
->dwLowDateTime
= kusrt
.CreateTime
.u
.LowPart
;
564 creationtime
->dwHighDateTime
= kusrt
.CreateTime
.u
.HighPart
;
568 exittime
->dwLowDateTime
= kusrt
.ExitTime
.u
.LowPart
;
569 exittime
->dwHighDateTime
= kusrt
.ExitTime
.u
.HighPart
;
573 kerneltime
->dwLowDateTime
= kusrt
.KernelTime
.u
.LowPart
;
574 kerneltime
->dwHighDateTime
= kusrt
.KernelTime
.u
.HighPart
;
578 usertime
->dwLowDateTime
= kusrt
.UserTime
.u
.LowPart
;
579 usertime
->dwHighDateTime
= kusrt
.UserTime
.u
.HighPart
;
585 /**********************************************************************
586 * GetThreadId [KERNEL32.@]
588 * Retrieve the identifier of a thread.
591 * Thread [I] The thread to retrieve the identifier of.
594 * Success: Identifier of the target thread.
597 DWORD WINAPI
GetThreadId(HANDLE Thread
)
599 THREAD_BASIC_INFORMATION tbi
;
602 TRACE("(%p)\n", Thread
);
604 status
= NtQueryInformationThread(Thread
, ThreadBasicInformation
, &tbi
,
608 SetLastError( RtlNtStatusToDosError(status
) );
612 return HandleToULong(tbi
.ClientId
.UniqueThread
);
615 /**********************************************************************
616 * GetProcessIdOfThread [KERNEL32.@]
618 * Retrieve process identifier given thread belongs to.
621 * Thread [I] The thread identifier.
624 * Success: Process identifier
627 DWORD WINAPI
GetProcessIdOfThread(HANDLE Thread
)
629 THREAD_BASIC_INFORMATION tbi
;
632 TRACE("(%p)\n", Thread
);
634 status
= NtQueryInformationThread(Thread
, ThreadBasicInformation
, &tbi
,
638 SetLastError( RtlNtStatusToDosError(status
) );
642 return HandleToULong(tbi
.ClientId
.UniqueProcess
);
645 /***********************************************************************
646 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
649 * Pseudohandle for the current thread
651 #undef GetCurrentThread
652 HANDLE WINAPI
GetCurrentThread(void)
654 return (HANDLE
)~(ULONG_PTR
)1;
660 /***********************************************************************
661 * SetLastError (KERNEL32.@)
663 /* void WINAPI SetLastError( DWORD error ); */
664 __ASM_STDCALL_FUNC( SetLastError
, 4,
665 "movl 4(%esp),%eax\n\t"
670 /***********************************************************************
671 * GetLastError (KERNEL32.@)
673 /* DWORD WINAPI GetLastError(void); */
674 __ASM_STDCALL_FUNC( GetLastError
, 0, ".byte 0x64\n\tmovl 0x34,%eax\n\tret" )
676 /***********************************************************************
677 * GetCurrentProcessId (KERNEL32.@)
679 /* DWORD WINAPI GetCurrentProcessId(void) */
680 __ASM_STDCALL_FUNC( GetCurrentProcessId
, 0, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" )
682 /***********************************************************************
683 * GetCurrentThreadId (KERNEL32.@)
685 /* DWORD WINAPI GetCurrentThreadId(void) */
686 __ASM_STDCALL_FUNC( GetCurrentThreadId
, 0, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" )
688 /***********************************************************************
689 * GetProcessHeap (KERNEL32.@)
691 /* HANDLE WINAPI GetProcessHeap(void) */
692 __ASM_STDCALL_FUNC( GetProcessHeap
, 0, ".byte 0x64\n\tmovl 0x30,%eax\n\tmovl 0x18(%eax),%eax\n\tret");
694 #elif defined(__x86_64__)
698 /***********************************************************************
699 * SetLastError (KERNEL32.@)
701 /* void WINAPI SetLastError( DWORD error ); */
702 __ASM_STDCALL_FUNC( SetLastError
, 8, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl %ecx,0x68(%rax)\n\tret" );
704 /***********************************************************************
705 * GetLastError (KERNEL32.@)
707 /* DWORD WINAPI GetLastError(void); */
708 __ASM_STDCALL_FUNC( GetLastError
, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl 0x68(%rax),%eax\n\tret" );
710 /***********************************************************************
711 * GetCurrentProcessId (KERNEL32.@)
713 /* DWORD WINAPI GetCurrentProcessId(void) */
714 __ASM_STDCALL_FUNC( GetCurrentProcessId
, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl 0x40(%rax),%eax\n\tret" );
716 /***********************************************************************
717 * GetCurrentThreadId (KERNEL32.@)
719 /* DWORD WINAPI GetCurrentThreadId(void) */
720 __ASM_STDCALL_FUNC( GetCurrentThreadId
, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl 0x48(%rax),%eax\n\tret" );
722 /***********************************************************************
723 * GetProcessHeap (KERNEL32.@)
725 /* HANDLE WINAPI GetProcessHeap(void) */
726 __ASM_STDCALL_FUNC( GetProcessHeap
, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovq 0x60(%rax),%rax\n\tmovq 0x30(%rax),%rax\n\tret");
730 /***********************************************************************
731 * SetLastError (KERNEL32.@)
733 /* void WINAPI SetLastError( DWORD error ); */
734 __ASM_STDCALL_FUNC( SetLastError
, 8, ".byte 0x65\n\tmovl %ecx,0x68\n\tret" );
736 /***********************************************************************
737 * GetLastError (KERNEL32.@)
739 /* DWORD WINAPI GetLastError(void); */
740 __ASM_STDCALL_FUNC( GetLastError
, 0, ".byte 0x65\n\tmovl 0x68,%eax\n\tret" );
742 /***********************************************************************
743 * GetCurrentProcessId (KERNEL32.@)
745 /* DWORD WINAPI GetCurrentProcessId(void) */
746 __ASM_STDCALL_FUNC( GetCurrentProcessId
, 0, ".byte 0x65\n\tmovl 0x40,%eax\n\tret" );
748 /***********************************************************************
749 * GetCurrentThreadId (KERNEL32.@)
751 /* DWORD WINAPI GetCurrentThreadId(void) */
752 __ASM_STDCALL_FUNC( GetCurrentThreadId
, 0, ".byte 0x65\n\tmovl 0x48,%eax\n\tret" );
754 /***********************************************************************
755 * GetProcessHeap (KERNEL32.@)
757 /* HANDLE WINAPI GetProcessHeap(void) */
758 __ASM_STDCALL_FUNC( GetProcessHeap
, 0, ".byte 0x65\n\tmovq 0x60,%rax\n\tmovq 0x30(%rax),%rax\n\tret");
760 #endif /* __APPLE__ */
762 #else /* __x86_64__ */
764 /**********************************************************************
765 * SetLastError (KERNEL32.@)
767 * Sets the last-error code.
772 void WINAPI
SetLastError( DWORD error
) /* [in] Per-thread error code */
774 NtCurrentTeb()->LastErrorValue
= error
;
777 /**********************************************************************
778 * GetLastError (KERNEL32.@)
780 * Get the last-error code.
785 DWORD WINAPI
GetLastError(void)
787 return NtCurrentTeb()->LastErrorValue
;
790 /***********************************************************************
791 * GetCurrentProcessId (KERNEL32.@)
793 * Get the current process identifier.
796 * current process identifier
798 DWORD WINAPI
GetCurrentProcessId(void)
800 return HandleToULong(NtCurrentTeb()->ClientId
.UniqueProcess
);
803 /***********************************************************************
804 * GetCurrentThreadId (KERNEL32.@)
806 * Get the current thread identifier.
809 * current thread identifier
811 DWORD WINAPI
GetCurrentThreadId(void)
813 return HandleToULong(NtCurrentTeb()->ClientId
.UniqueThread
);
816 /***********************************************************************
817 * GetProcessHeap (KERNEL32.@)
819 HANDLE WINAPI
GetProcessHeap(void)
821 return NtCurrentTeb()->Peb
->ProcessHeap
;
824 #endif /* __i386__ */
826 /*************************************************************************
827 * rtlmode_to_win32mode
829 static DWORD
rtlmode_to_win32mode( DWORD rtlmode
)
834 win32mode
|= SEM_FAILCRITICALERRORS
;
836 win32mode
|= SEM_NOGPFAULTERRORBOX
;
838 win32mode
|= SEM_NOOPENFILEERRORBOX
;
843 /***********************************************************************
844 * SetThreadErrorMode (KERNEL32.@)
846 * Set the thread local error mode.
849 * mode [I] The new error mode, a bitwise or of SEM_FAILCRITICALERRORS,
850 * SEM_NOGPFAULTERRORBOX and SEM_NOOPENFILEERRORBOX.
851 * oldmode [O] Destination of the old error mode (may be NULL)
855 * Failure: FALSE, check GetLastError
857 BOOL WINAPI
SetThreadErrorMode( DWORD mode
, LPDWORD oldmode
)
862 if (mode
& ~(SEM_FAILCRITICALERRORS
|
863 SEM_NOGPFAULTERRORBOX
|
864 SEM_NOOPENFILEERRORBOX
))
866 SetLastError( ERROR_INVALID_PARAMETER
);
870 if (mode
& SEM_FAILCRITICALERRORS
)
872 if (mode
& SEM_NOGPFAULTERRORBOX
)
874 if (mode
& SEM_NOOPENFILEERRORBOX
)
877 status
= RtlSetThreadErrorMode( tmp
, oldmode
);
880 SetLastError( RtlNtStatusToDosError(status
) );
885 *oldmode
= rtlmode_to_win32mode(*oldmode
);
890 /***********************************************************************
891 * GetThreadErrorMode (KERNEL32.@)
893 * Get the thread local error mode.
899 * The current thread local error mode.
901 DWORD WINAPI
GetThreadErrorMode( void )
903 return rtlmode_to_win32mode( RtlGetThreadErrorMode() );
906 /***********************************************************************
907 * GetThreadUILanguage (KERNEL32.@)
909 * Get the current thread's language identifier.
915 * The current thread's language identifier.
917 LANGID WINAPI
GetThreadUILanguage( void )
920 NtQueryDefaultUILanguage( &lang
);
921 FIXME(": stub, returning default language.\n");
925 /***********************************************************************
926 * GetThreadIOPendingFlag (KERNEL32.@)
928 BOOL WINAPI
GetThreadIOPendingFlag( HANDLE thread
, PBOOL io_pending
)
932 TRACE("%p, %p\n", thread
, io_pending
);
934 status
= NtQueryInformationThread( thread
, ThreadIsIoPending
,
935 io_pending
, sizeof(*io_pending
), NULL
);
938 SetLastError( RtlNtStatusToDosError(status
) );
944 /***********************************************************************
945 * CallbackMayRunLong (KERNEL32.@)
947 BOOL WINAPI
CallbackMayRunLong( TP_CALLBACK_INSTANCE
*instance
)
951 TRACE( "%p\n", instance
);
953 status
= TpCallbackMayRunLong( instance
);
956 SetLastError( RtlNtStatusToDosError(status
) );
963 /***********************************************************************
964 * CreateThreadpool (KERNEL32.@)
966 PTP_POOL WINAPI
CreateThreadpool( PVOID reserved
)
971 TRACE( "%p\n", reserved
);
973 status
= TpAllocPool( &pool
, reserved
);
976 SetLastError( RtlNtStatusToDosError(status
) );
983 /***********************************************************************
984 * CreateThreadpoolCleanupGroup (KERNEL32.@)
986 PTP_CLEANUP_GROUP WINAPI
CreateThreadpoolCleanupGroup( void )
988 TP_CLEANUP_GROUP
*group
;
993 status
= TpAllocCleanupGroup( &group
);
996 SetLastError( RtlNtStatusToDosError(status
) );
1003 /***********************************************************************
1004 * CreateThreadpoolTimer (KERNEL32.@)
1006 PTP_TIMER WINAPI
CreateThreadpoolTimer( PTP_TIMER_CALLBACK callback
, PVOID userdata
,
1007 TP_CALLBACK_ENVIRON
*environment
)
1012 TRACE( "%p, %p, %p\n", callback
, userdata
, environment
);
1014 status
= TpAllocTimer( &timer
, callback
, userdata
, environment
);
1017 SetLastError( RtlNtStatusToDosError(status
) );
1024 /***********************************************************************
1025 * CreateThreadpoolWait (KERNEL32.@)
1027 PTP_WAIT WINAPI
CreateThreadpoolWait( PTP_WAIT_CALLBACK callback
, PVOID userdata
,
1028 TP_CALLBACK_ENVIRON
*environment
)
1033 TRACE( "%p, %p, %p\n", callback
, userdata
, environment
);
1035 status
= TpAllocWait( &wait
, callback
, userdata
, environment
);
1038 SetLastError( RtlNtStatusToDosError(status
) );
1045 /***********************************************************************
1046 * CreateThreadpoolWork (KERNEL32.@)
1048 PTP_WORK WINAPI
CreateThreadpoolWork( PTP_WORK_CALLBACK callback
, PVOID userdata
,
1049 TP_CALLBACK_ENVIRON
*environment
)
1054 TRACE( "%p, %p, %p\n", callback
, userdata
, environment
);
1056 status
= TpAllocWork( &work
, callback
, userdata
, environment
);
1059 SetLastError( RtlNtStatusToDosError(status
) );
1066 /***********************************************************************
1067 * SetThreadpoolTimer (KERNEL32.@)
1069 VOID WINAPI
SetThreadpoolTimer( TP_TIMER
*timer
, FILETIME
*due_time
,
1070 DWORD period
, DWORD window_length
)
1072 LARGE_INTEGER timeout
;
1074 TRACE( "%p, %p, %u, %u\n", timer
, due_time
, period
, window_length
);
1078 timeout
.u
.LowPart
= due_time
->dwLowDateTime
;
1079 timeout
.u
.HighPart
= due_time
->dwHighDateTime
;
1082 TpSetTimer( timer
, due_time
? &timeout
: NULL
, period
, window_length
);
1085 /***********************************************************************
1086 * SetThreadpoolWait (KERNEL32.@)
1088 VOID WINAPI
SetThreadpoolWait( TP_WAIT
*wait
, HANDLE handle
, FILETIME
*due_time
)
1090 LARGE_INTEGER timeout
;
1092 TRACE( "%p, %p, %p\n", wait
, handle
, due_time
);
1100 timeout
.u
.LowPart
= due_time
->dwLowDateTime
;
1101 timeout
.u
.HighPart
= due_time
->dwHighDateTime
;
1104 TpSetWait( wait
, handle
, due_time
? &timeout
: NULL
);
1107 /***********************************************************************
1108 * TrySubmitThreadpoolCallback (KERNEL32.@)
1110 BOOL WINAPI
TrySubmitThreadpoolCallback( PTP_SIMPLE_CALLBACK callback
, PVOID userdata
,
1111 TP_CALLBACK_ENVIRON
*environment
)
1115 TRACE( "%p, %p, %p\n", callback
, userdata
, environment
);
1117 status
= TpSimpleTryPost( callback
, userdata
, environment
);
1120 SetLastError( RtlNtStatusToDosError(status
) );