ReactOS 0.4.17-dev-769-g1500a35
thread.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for thread.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define SXS_SUPPORT_FIXME
 
#define THEONLYGROUP   0
 

Typedefs

typedef NTSTATUS(NTAPIPCSR_CREATE_REMOTE_THREAD) (IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
 

Functions

NTSTATUS WINAPI BasepNotifyCsrOfThread (IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
 
DECLSPEC_NORETURN VOID WINAPI BaseThreadStartup (_In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_ LPVOID lpParameter)
 
VOID NTAPI BaseDispatchApc (IN PAPCFUNC ApcRoutine, IN PVOID Data, IN PACTIVATION_CONTEXT ActivationContext)
 
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread (IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
 
HANDLE WINAPI CreateRemoteThread (IN HANDLE hProcess, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
 
VOID WINAPI ExitThread (IN DWORD uExitCode)
 
HANDLE WINAPI OpenThread (IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwThreadId)
 
PTEB GetTeb (VOID)
 
BOOL WINAPI SwitchToThread (VOID)
 
DWORD WINAPI GetCurrentThreadId (VOID)
 
BOOL NTAPI GetThreadTimes (IN HANDLE hThread, OUT LPFILETIME lpCreationTime, OUT LPFILETIME lpExitTime, OUT LPFILETIME lpKernelTime, OUT LPFILETIME lpUserTime)
 
BOOL WINAPI GetThreadContext (IN HANDLE hThread, OUT LPCONTEXT lpContext)
 
BOOL WINAPI SetThreadContext (IN HANDLE hThread, IN CONST CONTEXT *lpContext)
 
BOOL WINAPI GetExitCodeThread (IN HANDLE hThread, OUT LPDWORD lpExitCode)
 
DWORD WINAPI ResumeThread (IN HANDLE hThread)
 
BOOL WINAPI TerminateThread (IN HANDLE hThread, IN DWORD dwExitCode)
 
DWORD WINAPI SuspendThread (IN HANDLE hThread)
 
DWORD_PTR WINAPI SetThreadAffinityMask (IN HANDLE hThread, IN DWORD_PTR dwThreadAffinityMask)
 
BOOL WINAPI GetThreadGroupAffinity (IN HANDLE hThread, OUT PGROUP_AFFINITY GroupAffinity)
 
BOOL WINAPI SetThreadGroupAffinity (IN HANDLE hThread, IN const GROUP_AFFINITY *GroupAffinity, OUT OPTIONAL PGROUP_AFFINITY PreviousGroupAffinity)
 
BOOL WINAPI SetThreadPriority (IN HANDLE hThread, IN int nPriority)
 
int WINAPI GetThreadPriority (IN HANDLE hThread)
 
BOOL WINAPI GetThreadPriorityBoost (IN HANDLE hThread, OUT PBOOL pDisablePriorityBoost)
 
BOOL NTAPI SetThreadPriorityBoost (IN HANDLE hThread, IN BOOL bDisablePriorityBoost)
 
BOOL WINAPI GetThreadSelectorEntry (IN HANDLE hThread, IN DWORD dwSelector, OUT LPLDT_ENTRY lpSelectorEntry)
 
DWORD WINAPI SetThreadIdealProcessor (IN HANDLE hThread, IN DWORD dwIdealProcessor)
 
DWORD WINAPI GetProcessIdOfThread (IN HANDLE Thread)
 
DWORD WINAPI GetThreadId (IN HANDLE Thread)
 
LANGID WINAPI SetThreadUILanguage (IN LANGID LangId)
 
DWORD WINAPI QueueUserAPC (IN PAPCFUNC pfnAPC, IN HANDLE hThread, IN ULONG_PTR dwData)
 
BOOL WINAPI SetThreadStackGuarantee (IN OUT PULONG StackSizeInBytes)
 
BOOL WINAPI GetThreadIOPendingFlag (IN HANDLE hThread, OUT PBOOL lpIOIsPending)
 
BOOL WINAPI QueueUserWorkItem (IN LPTHREAD_START_ROUTINE Function, IN PVOID Context, IN ULONG Flags)
 
DWORD WINAPI TlsAlloc (VOID)
 
BOOL WINAPI TlsFree (IN DWORD Index)
 
LPVOID WINAPI TlsGetValue (IN DWORD Index)
 
BOOL WINAPI TlsSetValue (IN DWORD Index, IN LPVOID Value)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file thread.c.

◆ SXS_SUPPORT_FIXME

#define SXS_SUPPORT_FIXME

Definition at line 17 of file thread.c.

◆ THEONLYGROUP

#define THEONLYGROUP   0

Definition at line 695 of file thread.c.

Typedef Documentation

◆ PCSR_CREATE_REMOTE_THREAD

typedef NTSTATUS(NTAPI * PCSR_CREATE_REMOTE_THREAD) (IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)

Definition at line 19 of file thread.c.

Function Documentation

◆ BaseDispatchApc()

VOID NTAPI BaseDispatchApc ( IN PAPCFUNC  ApcRoutine,
IN PVOID  Data,
IN PACTIVATION_CONTEXT  ActivationContext 
)

Definition at line 92 of file thread.c.

95{
96 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActivationFrame;
97
98 /* Setup the activation context */
99 ActivationFrame.Size = sizeof(ActivationFrame);
101
102 /* Check if caller wanted one */
103 if (ActivationContext == INVALID_ACTIVATION_CONTEXT)
104 {
105 /* Do the APC directly */
107 return;
108 }
109
110 /* Then activate it */
111 RtlActivateActivationContextUnsafeFast(&ActivationFrame, ActivationContext);
112
113 /* Call the routine under SEH */
115 {
117 }
119 {
120
121 }
122 _SEH2_END;
123
124 /* Now de-activate and release the activation context */
125 RtlDeactivateActivationContextUnsafeFast(&ActivationFrame);
126 RtlReleaseActivationContext(ActivationContext);
127}
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:726
#define RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER
Definition: rtltypes.h:109
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
uint32_t ULONG_PTR
Definition: typedefs.h:65
NTSYSAPI void WINAPI RtlReleaseActivationContext(HANDLE)
Definition: actctx.c:5664

Referenced by QueueUserAPC().

◆ BasepNotifyCsrOfThread()

NTSTATUS WINAPI BasepNotifyCsrOfThread ( IN HANDLE  ThreadHandle,
IN PCLIENT_ID  ClientId 
)

Definition at line 25 of file thread.c.

27{
28 BASE_API_MESSAGE ApiMessage;
29 PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest;
30
31 DPRINT("BasepNotifyCsrOfThread: Thread: %p, Handle %p\n",
32 ClientId->UniqueThread, ThreadHandle);
33
34 /* Fill out the request */
35 CreateThreadRequest->ClientId = *ClientId;
36 CreateThreadRequest->ThreadHandle = ThreadHandle;
37
38 /* Call CSR */
40 NULL,
42 sizeof(*CreateThreadRequest));
43 if (!NT_SUCCESS(ApiMessage.Status))
44 {
45 DPRINT1("Failed to tell CSRSS about new thread: %lx\n", ApiMessage.Status);
46 return ApiMessage.Status;
47 }
48
49 /* Return Success */
50 return STATUS_SUCCESS;
51}
#define DPRINT1
Definition: precomp.h:8
@ BasepCreateThread
Definition: basemsg.h:22
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
Definition: connect.c:366
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
union _BASE_API_MESSAGE::@3969 Data
BASE_CREATE_THREAD CreateThreadRequest
Definition: basemsg.h:284
HANDLE ThreadHandle
Definition: basemsg.h:104
CLIENT_ID ClientId
Definition: basemsg.h:105
HANDLE UniqueThread
Definition: compat.h:826
NTSTATUS Status
Definition: csrmsg.h:110
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

Referenced by CreateRemoteThread().

◆ BaseThreadStartup()

DECLSPEC_NORETURN VOID WINAPI BaseThreadStartup ( _In_ LPTHREAD_START_ROUTINE  lpStartAddress,
_In_ LPVOID  lpParameter 
)

Definition at line 56 of file thread.c.

59{
60 /* Attempt to call the Thread Start Address */
62 {
63 /* Legacy check which is still used today for Win32 threads */
64 if (NtCurrentTeb()->NtTib.Version == (30 << 8)) // OS/2 V3.0 ("Cruiser")
65 {
66 /* This registers the termination port with CSRSS */
68 }
69
70 /* Get the exit code from the Thread Start */
71 ExitThread(lpStartAddress(lpParameter));
72 }
74 {
75 /* Get the Exit code from the SEH Handler */
77 {
78 /* Kill the whole process, usually */
80 }
81 else
82 {
83 /* If running inside CSRSS, kill just this thread */
85 }
86 }
88}
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
LONG WINAPI UnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: except.c:269
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1380
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
#define NtCurrentTeb
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:203
NTSTATUS NTAPI CsrNewThread(VOID)
Definition: api.c:26

Referenced by BaseInitializeContext().

◆ CreateRemoteThread()

HANDLE WINAPI CreateRemoteThread ( IN HANDLE  hProcess,
IN LPSECURITY_ATTRIBUTES  lpThreadAttributes,
IN DWORD  dwStackSize,
IN LPTHREAD_START_ROUTINE  lpStartAddress,
IN LPVOID  lpParameter,
IN DWORD  dwCreationFlags,
OUT LPDWORD  lpThreadId 
)

Definition at line 159 of file thread.c.

166{
168 INITIAL_TEB InitialTeb;
171 OBJECT_ATTRIBUTES LocalObjectAttributes;
174 ULONG Dummy;
175 PTEB Teb;
176 THREAD_BASIC_INFORMATION ThreadBasicInfo;
177 PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL;
178 ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
181 SIZE_T ReturnSize;
182
183 DPRINT("CreateRemoteThread: hProcess: %p dwStackSize: %lu lpStartAddress"
184 ": %p lpParameter: %p, dwCreationFlags: %lx\n", hProcess,
185 dwStackSize, lpStartAddress, lpParameter, dwCreationFlags);
186
187 /* Clear the Context */
188 RtlZeroMemory(&Context, sizeof(Context));
189
190 /* Write PID */
192
193 /* Create the Stack */
195 (dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION) ?
196 0 : dwStackSize,
197 (dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION) ?
198 dwStackSize : 0,
199 &InitialTeb);
200 if (!NT_SUCCESS(Status))
201 {
203 return NULL;
204 }
205
206 /* Create the Initial Context */
208 lpParameter,
209 lpStartAddress,
210 InitialTeb.StackBase,
211 1);
212
213 /* Initialize the attributes for the thread object */
214 ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
215 lpThreadAttributes,
216 NULL);
217
218 /* Create the Kernel Thread Object */
222 hProcess,
223 &ClientId,
224 &Context,
225 &InitialTeb,
226 TRUE);
227 if (!NT_SUCCESS(Status))
228 {
229 /* Fail the kernel create */
230 BaseFreeThreadStack(hProcess, &InitialTeb);
232 return NULL;
233 }
234
235 /* Are we in the same process? */
236 if (hProcess == NtCurrentProcess())
237 {
238 /* Get the TEB */
241 &ThreadBasicInfo,
242 sizeof(ThreadBasicInfo),
243 &ReturnLength);
244 if (!NT_SUCCESS(Status))
245 {
246 /* Fail */
247 DPRINT1("SXS: %s - Failing thread create because "
248 "NtQueryInformationThread() failed with status %08lx\n",
250 goto Quit;
251 }
252
253 /* Allocate the Activation Context Stack */
254 Status = RtlAllocateActivationContextStack(&ActivationContextStack);
255 if (!NT_SUCCESS(Status))
256 {
257 /* Fail */
258 DPRINT1("SXS: %s - Failing thread create because "
259 "RtlAllocateActivationContextStack() failed with status %08lx\n",
261 goto Quit;
262 }
263
264 /* Save it */
265 Teb = ThreadBasicInfo.TebBaseAddress;
266 Teb->ActivationContextStackPointer = ActivationContextStack;
267
268 /* Query the Context */
270 NULL,
271 0,
272 ActivationContextBasicInformation,
273 &ActCtxInfo,
274 sizeof(ActCtxInfo),
275 &ReturnSize);
276 if (!NT_SUCCESS(Status))
277 {
278 /* Fail */
279 DPRINT1("SXS: %s - Failing thread create because "
280 "RtlQueryInformationActivationContext() failed with status %08lx\n",
282 goto Quit;
283 }
284
285 /* Does it need to be activated? */
286 if ((ActCtxInfo.hActCtx) && !(ActCtxInfo.dwFlags & 1))
287 {
288 /* Activate it */
290 Teb,
291 ActCtxInfo.hActCtx,
292 &Cookie);
293 if (!NT_SUCCESS(Status))
294 {
295 /* Fail */
296 DPRINT1("SXS: %s - Failing thread create because "
297 "RtlActivateActivationContextEx() failed with status %08lx\n",
299 goto Quit;
300 }
301 }
302
303 /* Sync the service tag with the parent thread's one */
304 Teb->SubProcessTag = NtCurrentTeb()->SubProcessTag;
305 }
306
307 /* Notify CSR */
309 {
311 }
312 else
313 {
314 if (hProcess != NtCurrentProcess())
315 {
317
318 /* Get the direct CSRSRV export */
321 "CsrCreateRemoteThread");
323 {
324 /* Call it instead of going through LPC */
326 }
327 }
328 }
329
330Quit:
331 if (!NT_SUCCESS(Status))
332 {
333 /* Failed to create the thread */
334
335 /* Free the activation context stack */
336 if (ActivationContextStack)
337 RtlFreeActivationContextStack(ActivationContextStack);
338
340 // FIXME: Wait for the thread to terminate?
341 BaseFreeThreadStack(hProcess, &InitialTeb);
343
345 return NULL;
346 }
347
348 /* Success */
349 if (lpThreadId)
350 *lpThreadId = HandleToUlong(ClientId.UniqueThread);
351
352 /* Resume the thread if asked */
353 if (!(dwCreationFlags & CREATE_SUSPENDED))
354 NtResumeThread(hThread, &Dummy);
355
356 /* Return handle to thread */
357 return hThread;
358}
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:73
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
NTSTATUS NTAPI CsrCreateRemoteThread(IN HANDLE hThread, IN PCLIENT_ID ClientId)
Definition: thredsup.c:569
#define TRUE
Definition: types.h:120
#define GetProcAddress(x, y)
Definition: compat.h:753
@ ThreadBasicInformation
Definition: compat.h:935
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
NTSTATUS(NTAPI * PCSR_CREATE_REMOTE_THREAD)(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
Definition: thread.c:19
NTSTATUS WINAPI BasepNotifyCsrOfThread(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
Definition: thread.c:25
NTSTATUS WINAPI BaseCreateStack(_In_ HANDLE hProcess, _In_opt_ SIZE_T StackCommit, _In_opt_ SIZE_T StackReserve, _Out_ PINITIAL_TEB InitialTeb)
Definition: utils.c:355
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:514
POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes, IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, IN PUNICODE_STRING ObjectName)
Definition: utils.c:305
VOID WINAPI BaseFreeThreadStack(_In_ HANDLE hProcess, _In_ PINITIAL_TEB InitialTeb)
Definition: utils.c:496
#define __FUNCTION__
Definition: types.h:116
Status
Definition: gdiplustypes.h:24
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define RTL_ACTIVATE_ACTIVATION_CONTEXT_EX_FLAG_RELEASE_ON_STACK_DEALLOCATION
Definition: rtltypes.h:114
#define RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT
Definition: rtltypes.h:124
HANDLE hThread
Definition: wizard.c:28
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1342
NTSTATUS NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
Definition: kill.c:1310
#define NtCurrentProcess()
Definition: nt_native.h:1660
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3429
NTSYSAPI NTSTATUS NTAPI NtCreateThread(OUT PHANDLE phThread, IN ACCESS_MASK AccessMask, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE hProcess, OUT PCLIENT_ID pClientId, IN PCONTEXT pContext, OUT PSTACKINFO pStackInfo, IN BOOLEAN bSuspended)
NTSTATUS NTAPI NtQueryInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _Out_writes_bytes_to_opt_(ThreadInformationLength, *ReturnLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:3017
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
_In_ PVOID Context
Definition: storport.h:2269
HANDLE UniqueProcess
Definition: compat.h:825
PVOID StackBase
Definition: pstypes.h:757
Definition: compat.h:836
PVOID ActivationContextStackPointer
Definition: compat.h:854
PVOID SubProcessTag
Definition: winternl.h:662
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STACK_SIZE_PARAM_IS_A_RESERVATION
Definition: winbase.h:225
#define CREATE_SUSPENDED
Definition: winbase.h:183
NTSYSAPI NTSTATUS WINAPI RtlActivateActivationContextEx(ULONG, TEB *, HANDLE, ULONG_PTR *)
Definition: actctx.c:5697
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG, HANDLE, PVOID, ULONG, PVOID, SIZE_T, SIZE_T *)
Definition: actctx.c:5833
NTSYSAPI void WINAPI RtlFreeActivationContextStack(ACTIVATION_CONTEXT_STACK *)
Definition: actctx.c:5774
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14

Referenced by _DoDLLInjection(), BaseCreateThreadPoolThread(), ConSrvConsoleCtrlEventTimeout(), CreateThread(), dll_entry_point(), GuiConsoleShowConsoleProperties(), test_CreateRemoteThread(), test_debugger(), test_ExitProcess(), test_TerminateProcess(), and test_thread_actctx().

◆ CreateThread()

HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread ( IN LPSECURITY_ATTRIBUTES  lpThreadAttributes,
IN DWORD  dwStackSize,
IN LPTHREAD_START_ROUTINE  lpStartAddress,
IN LPVOID  lpParameter,
IN DWORD  dwCreationFlags,
OUT LPDWORD  lpThreadId 
)

Definition at line 137 of file thread.c.

143{
144 /* Act as if we're going to create a remote thread in ourselves */
146 lpThreadAttributes,
147 dwStackSize,
148 lpStartAddress,
149 lpParameter,
150 dwCreationFlags,
151 lpThreadId);
152}
HANDLE WINAPI CreateRemoteThread(IN HANDLE hProcess, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:159

Referenced by _beginthread(), _beginthreadex(), _ServiceMain(), _test_flush_async(), _tWinMain(), AcceptConnections(), ANIMATE_Play(), apartment_hostobject_in_hostapt(), ApplicationPageWndProc(), async_wait_pipe(), AVISplitter_first_request(), check_hook_thread(), check_interface_marshal_proxy_creation_(), check_thread_apartment_(), check_thread_instance(), child_process(), clipboard_wnd_proc(), CommonInstall(), create_child_thread(), CreateClientProcess(), CreateLobbyMessageReceptionThread(), CreateRenderingSubsystem(), CreateRenderingWindow(), CreateServers(), CreateServiceThread(), CreateSidCacheMgr(), CreateSoundThread(), CSysTray::CreateSysTrayThread(), CreateTestThread(), CtfImmSetLangBand(), CThread::CThread(), custom_action_server(), DbgkCreateThread(), DbgkpPostFakeThreadMessages(), DbgUiConvertStateChangeStructure(), DECLARE_INTERFACE_(), DIALOG_Printing_DialogProc(), CTrayWindow::DisplayProperties(), CTrayWindow::DisplayRunFileDlg(), dll_entry_point(), do_msidbCustomActionTypeDll(), do_msidbCustomActionTypeScript(), do_wait_idle_child(), DosStartProcess32(), EmulatorInitialize(), ensurePlayerThread(), ExitWindowsWorker(), fiber_actctx_func(), fls_exit_deadlock_child(), get_id_thread(), get_thread_fpu_cw(), GUIDisplayStatusMessage(), HandleLogoff(), http_release_netconn(), IDirectPlay4Impl_EnumSessions(), IDirectSoundCaptureBufferImpl_Start(), SEALED_::IMsTscAx::Connect(), init(), InitDialog(), CDesktopThread::Initialize(), BtrfsPropSheet::Initialize(), COutputPin::InitializeIOThread(), InitializeScreenSaver(), InitiateSoundStreaming(), InitRpc(), InstallDrvDlgProc(), installer_proc(), InstallReactOS(), CZipFolder::InvokeCommand(), JustDoIt(), KmtRunKernelTest(), LocalScheduleJob(), LS_ThreadProc(), LsapRmInitializeServer(), MailSlotReader(), main(), MainDialogProc(), MainWndProc(), MCI_SendCommandAsync(), MCIAVI_mciPlay_async(), MCICDA_Play(), MCIQTZ_mciPlay(), midiStreamOpen(), MMDevEnum_RegisterEndpointNotificationCallback(), mmTaskCreate(), StringTest::mt(), Netbios(), NetworkInitPageDlgProc(), NotifyTopLevelWindow(), Window::OnCommand(), OnCreate(), OnInitDialog(), OnUpdate(), CZipExtract::CExtractSettingsPage::OnWizardNext(), Telnet::Open(), audio_wavein::open(), audio_waveout::open(), OpenDevice(), OSK_Create(), OutputQueue_Construct(), CKsClockForwarder::Pause(), PdhCollectQueryDataEx(), PerformancePageWndProc(), PlayLogonSound(), PowerMeterDlgProc(), proc_PlaySoundAsync(), ProcessDlgProc(), ProcessPageWndProc(), Protocol_Start(), protocol_start(), PullPin_InitProcessing(), rawinput_test_thread(), BtrfsRecv::RecvProgressDlgProc(), ReferenceClock_AdvisePeriodic(), ReferenceClock_AdviseTime(), RegisterGPNotification(), report(), RpcReadFile(), rpcrt4_ncacn_http_open(), RPCRT4_new_client(), RPCRT4_start_listen_protseq(), RSetServiceStatus(), run_background_thread(), run_in_temp_desktop_(), run_LS_tests(), run_thread(), RunItemCompletionThread(), RunLogoffShutdownThread(), RunSelectedTest(), RunSetup(), RunShell(), RunTest(), s_test_I_RpcBindingInqLocalClientPID(), schedule_timeout(), ScStartService(), SearchDrvDlgProc(), ServiceInit(), ServiceMain(), BtrfsPropSheet::set_cmdline(), SHCreateThread(), SHOpenFolderWindow(), SockCreateOrReferenceAsyncThread(), start_dummy_thread(), start_host_object2(), start_installation(), START_TEST(), StartAdapterDiscovery(), StartAuthenticationPort(), StartClients(), StartNotificationThread(), StartPortThread(), CProgressDialog::StartProgressDialog(), BtrfsSend::StartSend(), StartServer(), StartServiceThread(), StartStopEnumEventsThread(), StartSystemShutdown(), CAsyncLoadIcon::StartTasks(), StartTestCORE10188(), StartTestCORE17376(), CUTBLangBarDlg::StartThread(), CHardErrorThread::StartThread(), subtest_fiber_actctx_preservation(), suspend_process_proc(), SystemClockPostMessageToAdviseThread(), test(), test_AbortWaitCts(), Test_Acquire(), test_activateapp(), test_ActivateKeyboardLayout(), test_alertable(), test_alertable_wait(), test_apc_deadlock(), test_attach_input(), Test_AVX(), Test_AVX512(), test_BCryptEncrypt(), test_blocking(), test_bsc_marshaling(), test_CancelSynchronousIo(), test_cancelsynchronousio(), test_ClipCursor_process(), Test_CloseWhileSelectDuplicatedSocket(), Test_CloseWhileSelectSameSocket(), test_CoFreeUnusedLibraries(), test_CoGetCurrentProcess(), test_completion_port_scheduling(), test_condvars_base(), test_condvars_consumer_producer(), test_CoRegisterPSClsid(), test_CoWaitForMultipleHandles(), test_CoWaitForMultipleHandles_thread(), test_crash_couninitialize(), test_CreateThread_basic(), test_CreateThread_stack(), test_CreateThread_suspended(), test_CUIAutomation_event_handlers(), test_dde_default_app(), test_default_client_accessible_object(), test_default_ime_window_creation(), test_defwinproc(), test_deletecontext(), test_destroy_quit(), test_DragQueryFile(), test_duplicate_handle_access(), test_edit_messages(), test_EnableWindow(), test_enum_thread_windows(), test_events(), test_ffcn_directory_overlap(), test_ffcnMultipleThreads(), test_FiberLocalStorage(), test_foregroundwindow(), test_get_next_thread(), test_GetKeyState(), test_GetPointerInfo(), test_gettext(), test_GetThreadExitCode(), test_GetThreadTimes(), test_globalinterfacetable(), test_handles(), test_HeapCreate(), test_HideFromDebugger(), test_hook_cleanup(), test_http_connection(), test_icons(), test_IInitializeSpy(), test_ImmDefaultHwnd(), test_ImmThreads(), test_ImpersonateNamedPipeClient(), test_implicit_mta(), test_import_resolution(), test_InSendMessage(), test_interthread_messages(), test_iosb(), test_IUIAutomationEventHandler(), test_kernel32_tp_io(), test_keyed_events(), test_kill_on_exit(), test_layered_window(), test_main_thread(), test_menu_input(), test_messages(), test_mta_creation_thread_change_apartment(), test_MultiThreadApartment(), test_multithreaded_clipboard(), test_mutant(), test_NamedPipe_2(), test_no_couninitialize_client(), test_no_couninitialize_server(), test_nonalertable(), test_NtAtom(), test_oletlsdata(), test_overlapped(), test_PeekMessage(), test_proxy_used_in_wrong_thread(), test_pseudo_console(), test_QueueUserAPC(), test_rawinput(), test_reader_info(), test_reconnect(), test_registered_object_thread_affinity(), test_RegNotifyChangeKeyValue(), test_render_with_multithread(), test_resource(), test_RoGetAgileReference(), test_RtlCreateUserStack(), test_RtlIsCriticalSectionLocked(), test_runner(), test_select(), test_SendInput_mouse_messages(), test_SendMessage_other_thread(), test_SendMessageTimeout(), test_set_clipboard_DRAWCLIPBOARD(), test_SetCursor(), test_SetFocus(), test_SetForegroundWindow(), test_setparent_status(), test_shell_window(), test_ShowCursor(), test_smresult(), test_srwlock_base(), test_srwlock_example(), Test_SSE(), test_stop_wait_for_call(), test_suspend_thread(), test_SuspendThread(), test_tableweak_and_normal_marshal_and_releasedata(), test_tableweak_and_normal_marshal_and_unmarshal(), test_TerminateThread(), test_thread_actctx(), test_thread_exit_destroy(), test_thread_objects(), test_thread_security(), test_thread_start_address(), test_ThreadIsTerminated(), test_threads(), test_tid_alert(), test_timeouts(), test_timers(), test_tls_links(), test_tp_io(), TEST_Tracking(), test_two_tableweak_marshal_and_releasedata(), test_uia_event_ProxyProviderWinEventHandler(), test_uia_node_from_prov_com_threading(), test_uia_reserved_value_ifaces(), test_UiaAddEvent(), test_UiaNodeFromHandle(), test_WaitBreak(), test_WaitCts(), test_WaitDcd(), test_WaitDsr(), test_WaitForInputIdle(), test_WaitRing(), test_winevents(), test_write_watch(), Test_WS_FORCEMINIMIZE_Sub(), TestMessages(), TestMultipleUserAPCs(), TestRecursiveInterThreadMessages(), thread(), TIME_MMTimeStart(), uia_start_client_thread(), uia_start_event_thread(), uia_start_provider_thread(), UserLogin(), WahOpenHandleHelper(), wave_out_test_deviceOut(), WdmAudSetMixerDeviceFormatByLegacy(), wined3d_cs_create(), WinMain(), wmain(), WriterThread::WriterThread(), WsAsyncCheckAndInitThread(), WshShell3_Popup(), and wWinMain().

◆ ExitThread()

VOID WINAPI ExitThread ( IN DWORD  uExitCode)

Definition at line 365 of file thread.c.

366{
369 PRTL_CRITICAL_SECTION LoaderLock;
370
371 /* Make sure loader lock isn't held */
372 LoaderLock = NtCurrentPeb()->LoaderLock;
373 if (LoaderLock) ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
374
375 /*
376 * Terminate process if this is the last thread
377 * of the current process
378 */
381 &LastThread,
382 sizeof(LastThread),
383 NULL);
384 if ((NT_SUCCESS(Status)) && (LastThread)) ExitProcess(uExitCode);
385
386 /* Notify DLLs and TLS Callbacks of termination */
388
389 /* Tell the Kernel to free the Stack */
390 NtCurrentTeb()->FreeStackOnTermination = TRUE;
391 NtTerminateThread(NULL, uExitCode);
392
393 /* We should never reach this place */
394 ERROR_FATAL("It should not happen\n");
395 while (TRUE); /* 'noreturn' function */
396}
#define NtCurrentPeb()
Definition: FLS.c:22
@ ThreadAmILastThread
Definition: compat.h:947
#define ASSERT(a)
Definition: mode.c:44
PETHREAD LastThread
Definition: pinsup.c:109
#define ERROR_FATAL(...)
Definition: debug.h:238
#define NtCurrentThread()
Definition: winternl.h:5372
NTSYSAPI void WINAPI LdrShutdownThread(void)
Definition: ldrinit.c:1093

Referenced by _endthreadex(), BaseExitThreadPoolThread(), BaseProcessStartup(), BaseThreadStartup(), ChargenHandler(), client_stop(), collect_query_thread(), common_end_thread(), ConsoleControlDispatcher(), create_debug_port(), CreateSystemThreads(), DaytimeHandler(), DbgkExitThread(), ddeThread(), debug_and_exit(), debug_and_wait(), DECLARE_INTERFACE_(), DeleteFiber(), DiscardHandler(), EchoHandler(), exit_thread_fiber_func(), ExitWindowsThread(), FreeLibraryAndExitThread(), MMSYSTEM_MidiStream_Player(), NotificationThread(), PullPin_Thread_Stop(), QotdHandler(), server_stop(), StartServer(), test_stack_growth_thread(), test_thread_func(), thread_proc(), thread_start(), WaveActivateSoundStreaming(), wmain(), and wWinMain().

◆ GetCurrentThreadId()

DWORD WINAPI GetCurrentThreadId ( VOID  )

Definition at line 459 of file thread.c.

460{
462}

Referenced by __security_init_cookie(), __threadid(), CTipbarThread::_UninitItemList(), alloc_msi_remote_handle(), alloc_msihandle(), ANIMATE_DoStop(), AnotherThreadFunc(), apartment_construct(), AtlModuleAddCreateWndData(), AtlModuleExtractCreateWndData(), ATL::AtlWinModuleAddCreateWndData(), ATL::AtlWinModuleExtractCreateWndData(), CTipbarWnd::AttachFocusThread(), callback(), callback_func(), cbt_global_hook_proc(), cbt_hook_proc(), check_active_state_(), check_dinput_hooks(), check_notification(), check_window_style(), check_wnd_state_(), clipboard_thread(), clnt_cb_thread(), clnt_vc_create(), clnt_vc_destroy(), CMenuFocusManager::CMenuFocusManager(), ConIme_InitInstance(), ConIme_OnEnd(), context_create(), context_destroy(), context_reacquire(), CoRegisterInitializeSpy(), CoRevokeInitializeSpy(), create_binding_protocol(), create_test_windows(), CreateD3D9(), CreatePseudoConsole(), CtfImmGenerateMessage(), CtfImmTIMCreateInputContext(), DECLARE_INTERFACE_(), dialog_proc(), dialog_register_class(), dialog_run_message_loop(), DlgMainProc(), DllMain(), do_InitialDesktop_child(), do_wait_idle_child(), dprintf(), DumpNotificationState(), enum_thread(), EnumThreadWindows(), eprintf(), event_client(), fetch_thread_info(), FileOpenDlgProc95(), format_exception_msg(), get_ime_window(), get_or_create_threaddata(), get_thread_data(), GetActiveWindow(), GetCapture(), GetFocus(), GetMessageRedrawWindowTest(), GetSystemUserInfo(), GetThreadFromCurrentProcess(), group_cancel_cleanup_increment_cb(), group_cancel_cleanup_release2_cb(), group_cancel_cleanup_release_cb(), HttpNegotiate_BeginningTransaction(), HttpNegotiate_GetRootSecurityId(), HttpNegotiate_OnResponse(), IDirectSoundBufferImpl_GetStatus(), IDirectSoundCaptureBufferImpl_GetStatus(), Imm32InternalLockIMC(), Imm32IsCrossThreadAccess(), ImmSetCompositionStringAW(), init_tests(), InitChildWindow(), InitD3D9BaseDevice(), InitThreads(), InitUniqueString(), is_apartment_thread(), JScript_AddNamedItem(), JScript_Close(), JScript_GetScriptDispatch(), JScript_GetScriptState(), JScript_SetScriptState(), JScriptParse_ParseScriptText(), JScriptParseProcedure_ParseProcedureText(), load_gecko(), log_debug(), log_hexdump(), MainDialogProc(), MainWndProc(), MCI_Close(), MCI_LoadMciDriver(), MCI_SendCommandFrom32(), mmGetCurrentTask(), msg_spy_init(), msi_dialog_check_messages(), msi_dialog_destroy(), MsiCloseAllHandles(), msvcrt_get_thread_data(), mutex_thread_proc(), new_stub_manager(), nfs41_open(), noop_thread_proc(), notification_callback(), OLEMenu_CallWndProc(), OLEMenu_GetMsgProc(), OLEMenu_InstallHooks(), OleSetMenuDescriptor(), OnInitDialog(), CAutoComplete::OnShowWindow(), oob_client(), oob_server(), PersistMoniker_Load(), print_sr_status_flags(), Protocol_Continue(), ProviderAdviseEvents_AdviseEventAdded(), ProviderAdviseEvents_AdviseEventRemoved(), ProviderFragment_get_BoundingRectangle(), ProviderFragment_get_FragmentRoot(), ProviderFragment_GetEmbeddedFragmentRoots(), ProviderFragment_GetRuntimeId(), ProviderFragment_Navigate(), ProviderFragmentRoot_GetFocus(), ProviderSimple_get_HostRawElementProvider(), ProviderSimple_get_ProviderOptions(), ProviderSimple_GetPatternProvider(), ProviderSimple_GetPropertyValue(), ProviderWinEventHandler_RespondToWinEvent(), CAsyncLoadIcon::Queue(), RegisterConsoleIME(), Rs232Thread(), rtl_wait_cb(), run_in_temp_desktop_thread_func(), ScriptThread(), select_server(), semaphore_thread_proc(), server_stop(), set_cursor_thread(), CTipbarWnd::SetFocusThread(), setup_test(), CThreadMgr::SetupWindowsHook(), show_cursor_thread(), simple_client(), simple_mixed_client(), simple_server(), SPY_EnterMessage(), start_debugger(), START_TEST(), CTipbarWnd::StartModalInput(), statusclb_GetBindInfo(), statusclb_OnDataAvailable(), statusclb_OnProgress(), statusclb_OnStartBinding(), statusclb_OnStopBinding(), statusclb_QueryInterface(), CTipbarWnd::StopModalInput(), Stream_Read(), sw_SetContext(), swapchain_create_context(), swapchain_get_context(), Test_Acquire(), test_alertable(), test_async(), test_async_HttpSendRequestEx(), test_attach_input(), test_capture_4_proc(), test_CoGetCurrentProcess(), test_com_event_data_(), test_CoWaitForMultipleHandles_thread(), test_CreateThread_basic(), test_crypt_ui_wiz_import(), test_dbcs_wm_char(), test_dde_default_app(), test_default_ime_disabled_cb(), Test_DesktopAccess(), test_destroy_quit(), test_EnumDisplayMonitors(), test_foregroundwindow(), test_fragmentsize(), test_get_next_thread(), test_get_security(), test_handles(), test_hook_changing_window_proc(), test_hook_cleanup(), test_hook_cleanup_hook_proc(), test_hook_cleanup_thread_proc(), test_IInitializeSpy(), test_inputdesktop(), test_inputdesktop2(), test_invisible_winstation_child(), test_IsDialogMessage(), test_keyboard_input(), test_message_conversion(), test_MessageBox(), test_notification_cb(), test_notify_message(), test_ole_initialization(), Test_OpenInputDesktop(), test_peb_teb(), test_PeekMessage(), test_process(), test_process_security_child(), test_query_object(), test_query_process(), test_quit_message(), test_recursion(), test_recursion_callback(), test_recursive_hook(), Test_References(), test_RtlLeaveCriticalSection(), test_RtlQueryProcessDebugInformation(), test_RtlRegisterWait(), test_SendInput_mouse_messages(), test_set_hook(), test_SetCursor(), Test_SetCursorPos(), test_SetFocus(), test_ShowCursor(), test_thread_description(), test_thread_info(), test_thread_lookup(), test_thread_priority(), test_tid_alert(), test_tp_group_cancel(), test_uia_node_from_prov_com_threading(), test_UiaAddEvent(), test_UiaNodeFromHandle(), test_window_security(), test_winmodule(), test_wiznavigation(), test_zero_access(), TestGetUserObjectInfoA(), TestGetUserObjectInfoW(), thread(), thread_proc(), threadFunc1(), ThreadShutdownNotify(), throw(), TIME_TriggerCallBack(), tp_object_execute(), TpCallbackMayRunLong(), TpDisassociateCallback(), MxLockNoDynam::TryToAcquire(), uia_add_event_test_thread(), uia_com_event_handler_test_thread(), uia_get_provider_from_hwnd(), uia_node_from_handle_test_thread(), uia_node_from_provider_test_com_thread(), UnregisterConsoleIME(), VBScript_AddNamedItem(), VBScript_Close(), VBScript_GetScriptDispatch(), VBScript_GetScriptState(), VBScript_SetScriptSite(), VBScript_SetScriptState(), VBScriptParse_ParseScriptText(), VBScriptParseProcedure_ParseProcedureText(), wave_out_test_deviceOut(), WDML_GetConv(), WDML_GetInstance(), WDML_Initialize(), WDML_NotifyThreadDetach(), WDML_ServerNameProc(), WDML_SetAllLastError(), wglDeleteContext(), wglMakeCurrent(), win_event_global_hook_proc(), WindowThreadProc(), wined3d_cs_mt_finish(), wined3d_cs_mt_require_space(), wined3d_cs_mt_submit(), wined3d_cs_run(), wined3d_from_cs(), wined3d_not_from_cs(), wined3d_resource_wait_idle(), WndProc(), wWinMain(), xmlGetThreadId(), xmlInitGlobalsInternal(), and xmlIsMainThreadInternal().

◆ GetExitCodeThread()

◆ GetProcessIdOfThread()

DWORD WINAPI GetProcessIdOfThread ( IN HANDLE  Thread)

Definition at line 947 of file thread.c.

948{
949 THREAD_BASIC_INFORMATION ThreadBasic;
951
954 &ThreadBasic,
956 NULL);
957 if (!NT_SUCCESS(Status))
958 {
960 return 0;
961 }
962
963 return HandleToUlong(ThreadBasic.ClientId.UniqueProcess);
964}
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653

◆ GetTeb()

PTEB GetTeb ( VOID  )

Definition at line 438 of file thread.c.

439{
440 return NtCurrentTeb();
441}

◆ GetThreadContext()

BOOL WINAPI GetThreadContext ( IN HANDLE  hThread,
OUT LPCONTEXT  lpContext 
)

Definition at line 501 of file thread.c.

503{
505
506 Status = NtGetContextThread(hThread, lpContext);
507 if (!NT_SUCCESS(Status))
508 {
510 return FALSE;
511 }
512
513 return TRUE;
514}
NTSTATUS NTAPI NtGetContextThread(IN HANDLE ThreadHandle, IN OUT PCONTEXT ThreadContext)
Definition: debug.c:350

Referenced by DECLARE_INTERFACE_(), fetch_thread_context_(), fetch_thread_info(), main(), START_TEST(), test_ExitProcess(), test_selectors(), test_thread_info(), TestThreadProc(), and ThreadData::Update().

◆ GetThreadGroupAffinity()

BOOL WINAPI GetThreadGroupAffinity ( IN HANDLE  hThread,
OUT PGROUP_AFFINITY  GroupAffinity 
)

Definition at line 702 of file thread.c.

704{
706 THREAD_BASIC_INFORMATION ThreadBasic;
707
708 STUB; // FIXME: Real group support
711 &ThreadBasic,
712 sizeof(ThreadBasic),
713 NULL);
714 if (!NT_SUCCESS(Status))
715 {
717 return FALSE;
718 }
719 ZeroMemory(GroupAffinity, sizeof(*GroupAffinity)); // For Reserved
720 GroupAffinity->Mask = ThreadBasic.AffinityMask;
722 return TRUE;
723}
#define THEONLYGROUP
Definition: thread.c:695
#define STUB
Definition: kernel32.h:27
#define ZeroMemory
Definition: minwinbase.h:31
$USHORT Group
Definition: ntbasedef.h:673
KAFFINITY Mask
Definition: ntbasedef.h:672
KAFFINITY AffinityMask
Definition: compat.h:930
_Out_ PGROUP_AFFINITY GroupAffinity
Definition: iofuncs.h:2535

Referenced by init_funcs(), and SetThreadGroupAffinity().

◆ GetThreadId()

DWORD WINAPI GetThreadId ( IN HANDLE  Thread)

Definition at line 971 of file thread.c.

972{
973 THREAD_BASIC_INFORMATION ThreadBasic;
975
978 &ThreadBasic,
980 NULL);
981 if (!NT_SUCCESS(Status))
982 {
984 return 0;
985 }
986
987 return HandleToUlong(ThreadBasic.ClientId.UniqueThread);
988}

Referenced by RpcCancelThreadEx(), RpcMgmtWaitServerListen(), and test_get_next_thread().

◆ GetThreadIOPendingFlag()

BOOL WINAPI GetThreadIOPendingFlag ( IN HANDLE  hThread,
OUT PBOOL  lpIOIsPending 
)

Definition at line 1105 of file thread.c.

1107{
1108 ULONG IoPending;
1110
1111 /* Query the flag */
1114 &IoPending,
1115 sizeof(IoPending),
1116 NULL);
1117 if (NT_SUCCESS(Status))
1118 {
1119 /* Return the flag */
1120 *lpIOIsPending = IoPending ? TRUE : FALSE;
1121 return TRUE;
1122 }
1123
1124 /* Fail */
1126 return FALSE;
1127}
@ ThreadIsIoPending
Definition: compat.h:951

◆ GetThreadPriority()

int WINAPI GetThreadPriority ( IN HANDLE  hThread)

Definition at line 797 of file thread.c.

798{
799 THREAD_BASIC_INFORMATION ThreadBasic;
801
802 /* Query the Base Priority Increment */
805 &ThreadBasic,
807 NULL);
808 if (!NT_SUCCESS(Status))
809 {
810 /* Failure */
813 }
814
815 /* Do some conversions for saturation values */
816 if (ThreadBasic.BasePriority == ((HIGH_PRIORITY + 1) / 2))
817 {
818 /* Win32 calls this "time critical" */
820 }
821 else if (ThreadBasic.BasePriority == -((HIGH_PRIORITY + 1) / 2))
822 {
823 /* Win32 calls this "idle" */
825 }
826
827 /* Return the final result */
828 return ThreadBasic.BasePriority;
829}
#define HIGH_PRIORITY
KPRIORITY BasePriority
Definition: compat.h:932
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:306
#define THREAD_PRIORITY_ERROR_RETURN
Definition: winbase.h:307
#define THREAD_PRIORITY_IDLE
Definition: winbase.h:303

Referenced by priorityTimeProc(), SlideWindow(), and test_thread_priority().

◆ GetThreadPriorityBoost()

BOOL WINAPI GetThreadPriorityBoost ( IN HANDLE  hThread,
OUT PBOOL  pDisablePriorityBoost 
)

Definition at line 836 of file thread.c.

838{
841
845 sizeof(ULONG),
846 NULL);
847 if (!NT_SUCCESS(Status))
848 {
850 return FALSE;
851 }
852
853 *pDisablePriorityBoost = PriorityBoost;
854 return TRUE;
855}
@ ThreadPriorityBoost
Definition: compat.h:949
_In_ WDFREQUEST _In_ NTSTATUS _In_ CCHAR PriorityBoost
Definition: wdfrequest.h:1016

Referenced by init_funcs().

◆ GetThreadSelectorEntry()

BOOL WINAPI GetThreadSelectorEntry ( IN HANDLE  hThread,
IN DWORD  dwSelector,
OUT LPLDT_ENTRY  lpSelectorEntry 
)

Definition at line 888 of file thread.c.

891{
892#ifdef _M_IX86
893 DESCRIPTOR_TABLE_ENTRY DescriptionTableEntry;
895
896 /* Set the selector and do the query */
897 DescriptionTableEntry.Selector = dwSelector;
900 &DescriptionTableEntry,
901 sizeof(DESCRIPTOR_TABLE_ENTRY),
902 NULL);
903 if (!NT_SUCCESS(Status))
904 {
905 /* Fail */
907 return FALSE;
908 }
909
910 /* Success, return the selector */
911 *lpSelectorEntry = DescriptionTableEntry.Descriptor;
912 return TRUE;
913#else
914 DPRINT1("Calling GetThreadSelectorEntry!\n");
915 return FALSE;
916#endif
917}
@ ThreadDescriptorTableEntry
Definition: compat.h:941

Referenced by addr_to_linear(), and i386_stack_walk().

◆ GetThreadTimes()

BOOL NTAPI GetThreadTimes ( IN HANDLE  hThread,
OUT LPFILETIME  lpCreationTime,
OUT LPFILETIME  lpExitTime,
OUT LPFILETIME  lpKernelTime,
OUT LPFILETIME  lpUserTime 
)

Definition at line 469 of file thread.c.

474{
475 KERNEL_USER_TIMES KernelUserTimes;
477
480 &KernelUserTimes,
481 sizeof(KERNEL_USER_TIMES),
482 NULL);
483 if (!NT_SUCCESS(Status))
484 {
486 return FALSE;
487 }
488
489 *lpCreationTime = *(LPFILETIME)&KernelUserTimes.CreateTime;
490 *lpExitTime = *(LPFILETIME)&KernelUserTimes.ExitTime;
491 *lpKernelTime = *(LPFILETIME)&KernelUserTimes.KernelTime;
492 *lpUserTime = *(LPFILETIME)&KernelUserTimes.UserTime;
493 return TRUE;
494}
@ ThreadTimes
Definition: compat.h:936
struct _FILETIME * LPFILETIME
Definition: time.c:29
LARGE_INTEGER UserTime
Definition: winternl.h:2377
LARGE_INTEGER CreateTime
Definition: winternl.h:2374
LARGE_INTEGER KernelTime
Definition: winternl.h:2376
LARGE_INTEGER ExitTime
Definition: winternl.h:2375

Referenced by test_GetThreadTimes().

◆ OpenThread()

HANDLE WINAPI OpenThread ( IN DWORD  dwDesiredAccess,
IN BOOL  bInheritHandle,
IN DWORD  dwThreadId 
)

Definition at line 403 of file thread.c.

406{
408 HANDLE ThreadHandle;
411
414
416 NULL,
418 NULL,
419 NULL);
420
421 Status = NtOpenThread(&ThreadHandle,
422 dwDesiredAccess,
424 &ClientId);
425 if (!NT_SUCCESS(Status))
426 {
428 return NULL;
429 }
430
431 return ThreadHandle;
432}
#define ULongToHandle(h)
Definition: basetsd.h:75
DWORD dwThreadId
Definition: fdebug.c:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
static BOOL bInheritHandle
Definition: pipe.c:110
NTSTATUS NTAPI NtOpenThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId OPTIONAL)
Definition: thread.c:1013
#define OBJ_INHERIT
Definition: winternl.h:225

Referenced by fetch_thread_context_(), fetch_thread_info(), GetThreadFromCurrentProcess(), init_funcs(), test_debugger(), test_process_security_child(), test_RtlRegisterWait(), test_thread_description(), and test_Toolhelp().

◆ QueueUserAPC()

DWORD WINAPI QueueUserAPC ( IN PAPCFUNC  pfnAPC,
IN HANDLE  hThread,
IN ULONG_PTR  dwData 
)

Definition at line 1017 of file thread.c.

1020{
1022 ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
1023
1024 /* Zero the activation context and query information on it */
1025 RtlZeroMemory(&ActCtxInfo, sizeof(ActCtxInfo));
1027 NULL,
1028 0,
1029 ActivationContextBasicInformation,
1030 &ActCtxInfo,
1031 sizeof(ActCtxInfo),
1032 NULL);
1033 if (!NT_SUCCESS(Status))
1034 {
1035 /* Fail due to SxS */
1036 DbgPrint("SXS: %s failing because RtlQueryInformationActivationContext()"
1037 "returned status %08lx\n", __FUNCTION__, Status);
1039 return FALSE;
1040 }
1041
1042 /* Queue the APC */
1045 pfnAPC,
1046 (PVOID)dwData,
1047 (ActCtxInfo.dwFlags & 1) ?
1048 INVALID_ACTIVATION_CONTEXT : ActCtxInfo.hActCtx);
1049 if (!NT_SUCCESS(Status))
1050 {
1052 return FALSE;
1053 }
1054
1055 /* All good */
1056 return TRUE;
1057}
VOID NTAPI BaseDispatchApc(IN PAPCFUNC ApcRoutine, IN PVOID Data, IN PACTIVATION_CONTEXT ActivationContext)
Definition: thread.c:92
#define DbgPrint
Definition: hal.h:12
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:888
static HANDLE ULONG_PTR dwData
Definition: pipe.c:111
NTSTATUS NTAPI NtQueueApcThread(IN HANDLE ThreadHandle, IN PKNORMAL_ROUTINE ApcRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: state.c:600

Referenced by async_notifier_proc(), JustDoIt(), process_work_items(), CDirectoryWatcher::RequestAddWatcher(), CDirectoryWatcher::RequestAllWatchersTermination(), CDirectoryWatcher::RequestTermination(), serverThreadMain2(), SEALED_::TerminateProtocolThread(), test_alertable_wait(), test_CoWaitForMultipleHandles(), test_CreatePipe(), test_GetOverlappedResultEx(), test_MsgWaitForMultipleObjects(), test_post_completion(), test_QueueUserAPC(), test_read_write(), test_RtlRegisterWait(), test_set_io_completion(), TestMultipleUserAPCs(), WahCloseHandleHelper(), and WahQueueUserApc().

◆ QueueUserWorkItem()

BOOL WINAPI QueueUserWorkItem ( IN LPTHREAD_START_ROUTINE  Function,
IN PVOID  Context,
IN ULONG  Flags 
)

Definition at line 1134 of file thread.c.

1137{
1139
1140 /* NOTE: Rtl needs to safely call the function using a trampoline */
1142 if (!NT_SUCCESS(Status))
1143 {
1144 /* Failed */
1146 return FALSE;
1147 }
1148
1149 /* All good */
1150 return TRUE;
1151}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
NTSYSAPI NTSTATUS NTAPI RtlQueueWorkItem(_In_ WORKERCALLBACKFUNC Function, _In_opt_ PVOID Context, _In_ ULONG Flags)
VOID(NTAPI * WORKERCALLBACKFUNC)(_In_ PVOID Context)
Definition: rtltypes.h:515

Referenced by ClientRpcChannelBuffer_SendReceive(), handle_full_cache(), I_RpcSend(), init_funcs(), INTERNET_AsyncCall(), queue_async(), RPCRT4_io_thread(), and SHQueueUserWorkItem().

◆ ResumeThread()

◆ SetThreadAffinityMask()

DWORD_PTR WINAPI SetThreadAffinityMask ( IN HANDLE  hThread,
IN DWORD_PTR  dwThreadAffinityMask 
)

Definition at line 662 of file thread.c.

664{
665 THREAD_BASIC_INFORMATION ThreadBasic;
666 KAFFINITY AffinityMask;
668
669 AffinityMask = (KAFFINITY)dwThreadAffinityMask;
670
673 &ThreadBasic,
675 NULL);
676 if (!NT_SUCCESS(Status))
677 {
679 return 0;
680 }
681
684 &AffinityMask,
685 sizeof(KAFFINITY));
686 if (!NT_SUCCESS(Status))
687 {
689 ThreadBasic.AffinityMask = 0;
690 }
691
692 return ThreadBasic.AffinityMask;
693}
ULONG_PTR KAFFINITY
Definition: compat.h:85
@ ThreadAffinityMask
Definition: compat.h:939
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2301

Referenced by AdjustAffinity(), SetThreadGroupAffinity(), Test_SyscallPerformance(), test_thread_processor(), and wmain().

◆ SetThreadContext()

BOOL WINAPI SetThreadContext ( IN HANDLE  hThread,
IN CONST CONTEXT lpContext 
)

Definition at line 521 of file thread.c.

523{
525
527 if (!NT_SUCCESS(Status))
528 {
530 return FALSE;
531 }
532
533 return TRUE;
534}
NTSTATUS NTAPI NtSetContextThread(IN HANDLE ThreadHandle, IN PCONTEXT ThreadContext)
Definition: debug.c:387

Referenced by DECLARE_INTERFACE_(), set_thread_context_(), and test_ExitProcess().

◆ SetThreadGroupAffinity()

BOOL WINAPI SetThreadGroupAffinity ( IN HANDLE  hThread,
IN const GROUP_AFFINITY GroupAffinity,
OUT OPTIONAL PGROUP_AFFINITY  PreviousGroupAffinity 
)

Definition at line 730 of file thread.c.

733{
734 DWORD_PTR OldMask;
735
736 STUB; // FIXME: Real group support
738 {
740 return FALSE;
741 }
742
744 if (OldMask && PreviousGroupAffinity)
745 {
746 ZeroMemory(PreviousGroupAffinity, sizeof(*PreviousGroupAffinity)); // For Reserved
747 PreviousGroupAffinity->Mask = OldMask;
748 PreviousGroupAffinity->Group = THEONLYGROUP;
749 }
750 return OldMask != 0;
751}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
DWORD_PTR WINAPI SetThreadAffinityMask(IN HANDLE hThread, IN DWORD_PTR dwThreadAffinityMask)
Definition: thread.c:662
uint32_t DWORD_PTR
Definition: typedefs.h:65

Referenced by init_funcs().

◆ SetThreadIdealProcessor()

DWORD WINAPI SetThreadIdealProcessor ( IN HANDLE  hThread,
IN DWORD  dwIdealProcessor 
)

Definition at line 924 of file thread.c.

926{
928
931 &dwIdealProcessor,
932 sizeof(ULONG));
933 if (!NT_SUCCESS(Status))
934 {
936 return -1;
937 }
938
939 return (DWORD)Status;
940}
@ ThreadIdealProcessor
Definition: compat.h:948
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by test_thread_processor().

◆ SetThreadPriority()

BOOL WINAPI SetThreadPriority ( IN HANDLE  hThread,
IN int  nPriority 
)

Definition at line 758 of file thread.c.

760{
761 LONG Prio = nPriority;
763
764 /* Check if values forcing saturation should be used */
766 {
767 /* This is 16 */
768 Prio = (HIGH_PRIORITY + 1) / 2;
769 }
770 else if (Prio == THREAD_PRIORITY_IDLE)
771 {
772 /* This is -16 */
773 Prio = -((HIGH_PRIORITY + 1) / 2);
774 }
775
776 /* Set the Base Priority */
779 &Prio,
780 sizeof(LONG));
781 if (!NT_SUCCESS(Status))
782 {
783 /* Failure */
785 return FALSE;
786 }
787
788 /* Return */
789 return TRUE;
790}
@ ThreadBasePriority
Definition: compat.h:938
long LONG
Definition: pedump.c:60

Referenced by ConsoleControlDispatcher(), ensurePlayerThread(), ImageView_Main(), main(), MCI_SendCommandAsync(), MCIAVI_mciPlay_async(), midiStreamOpen(), mmTaskCreate(), Telnet::Open(), OutputQueue_Construct(), proc_PlaySoundAsync(), CFindFolder::SearchThreadProc(), SlideWindow(), SockAsyncThread(), SystemClockPostMessageToAdviseThread(), test_ExitProcess(), test_thread_priority(), TIME_MMTimeStart(), WaveThread(), WriterThread::WriterThread(), and wWinMain().

◆ SetThreadPriorityBoost()

BOOL NTAPI SetThreadPriorityBoost ( IN HANDLE  hThread,
IN BOOL  bDisablePriorityBoost 
)

Definition at line 862 of file thread.c.

864{
867
868 PriorityBoost = bDisablePriorityBoost != FALSE;
869
873 sizeof(ULONG));
874 if (!NT_SUCCESS(Status))
875 {
877 return FALSE;
878 }
879
880 return TRUE;
881}

Referenced by init_funcs().

◆ SetThreadStackGuarantee()

BOOL WINAPI SetThreadStackGuarantee ( IN OUT PULONG  StackSizeInBytes)

Definition at line 1064 of file thread.c.

1065{
1066 PTEB Teb = NtCurrentTeb();
1067 ULONG GuaranteedStackBytes;
1069
1070 if (!StackSizeInBytes)
1071 {
1073 return FALSE;
1074 }
1075
1076 AllocationSize = *StackSizeInBytes;
1077
1078 /* Retrieve the current stack size */
1079 GuaranteedStackBytes = Teb->GuaranteedStackBytes;
1080
1081 /* Return the size of the previous stack */
1082 *StackSizeInBytes = GuaranteedStackBytes;
1083
1084 /*
1085 * If the new stack size is either zero or is less than the current size,
1086 * the previous stack size is returned and we return success.
1087 */
1088 if ((AllocationSize == 0) || (AllocationSize < GuaranteedStackBytes))
1089 {
1090 return TRUE;
1091 }
1092
1093 // FIXME: Unimplemented!
1095
1096 // Temporary HACK for supporting applications!
1097 return TRUE; // FALSE;
1098}
_In_ ULONG AllocationSize
Definition: dispmprt.h:712
ULONG GuaranteedStackBytes
Definition: winternl.h:668
#define UNIMPLEMENTED_ONCE
Definition: typedefs.h:30

Referenced by init_funcs().

◆ SetThreadUILanguage()

LANGID WINAPI SetThreadUILanguage ( IN LANGID  LangId)

Definition at line 995 of file thread.c.

996{
997#if (NTDDI_VERSION < NTDDI_LONGHORN)
998 /* We only support LangId == 0, for selecting a language
999 * identifier that best supports the NT Console. */
1000 if (LangId != 0)
1001 {
1003 return 0;
1004 }
1005#endif
1006
1008
1009 return LANGIDFROMLCID(NtCurrentTeb()->CurrentLocale);
1010}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define LANGIDFROMLCID(l)
Definition: nls.h:18

Referenced by SetLocale().

◆ SuspendThread()

DWORD WINAPI SuspendThread ( IN HANDLE  hThread)

Definition at line 642 of file thread.c.

643{
644 ULONG PreviousSuspendCount;
646
647 Status = NtSuspendThread(hThread, &PreviousSuspendCount);
648 if (!NT_SUCCESS(Status))
649 {
651 return -1;
652 }
653
654 return PreviousSuspendCount;
655}
NTSTATUS NTAPI NtSuspendThread(IN HANDLE ThreadHandle, OUT PULONG PreviousSuspendCount OPTIONAL)
Definition: state.c:352

Referenced by _check_thread_suspend_count(), fetch_thread_info(), main(), midiStreamPause(), MMSYSTEM_MidiStream_Player(), test_apc_deadlock(), test_CreateRemoteThread(), test_CreateThread_suspended(), test_debugger(), test_query_process_debug_flags(), test_SuspendThread(), and threadFunc3().

◆ SwitchToThread()

BOOL WINAPI SwitchToThread ( VOID  )

Definition at line 448 of file thread.c.

449{
451}
#define STATUS_NO_YIELD_PERFORMED
Definition: ntstatus.h:225
NTSYSAPI NTSTATUS WINAPI NtYieldExecution(void)
Definition: thrdschd.c:887

◆ TerminateThread()

BOOL WINAPI TerminateThread ( IN HANDLE  hThread,
IN DWORD  dwExitCode 
)

Definition at line 587 of file thread.c.

589{
591#if DBG
592 PRTL_CRITICAL_SECTION LoaderLock;
594#endif /* DBG */
595
596 /* Check for invalid thread handle */
597 if (!hThread)
598 {
599 /* Fail if one was passed */
601 return FALSE;
602 }
603
604#if DBG
605 /* Get the loader lock */
606 LoaderLock = NtCurrentPeb()->LoaderLock;
607 if (LoaderLock)
608 {
609 /* Get our TID */
612 &ThreadInfo,
613 sizeof(ThreadInfo),
614 NULL);
615 if (NT_SUCCESS(Status))
616 {
617 /* If terminating the current thread, we must not hold the loader lock */
618 if (NtCurrentTeb()->ClientId.UniqueThread == ThreadInfo.ClientId.UniqueThread)
620 }
621 }
622#endif /* DBG */
623
624 /* Now terminate the thread */
625 Status = NtTerminateThread(hThread, dwExitCode);
626 if (!NT_SUCCESS(Status))
627 {
628 /* Fail */
630 return FALSE;
631 }
632
633 /* All done */
634 return TRUE;
635}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
struct _ThreadInfo ThreadInfo

Referenced by do_test(), DP_DestroyDirectPlay2(), main(), nfs41_session_free(), NotifyTopLevelWindow(), NotifyUserProcessForShutdown(), RunTest(), BtrfsSend::SendDlgProc(), start_fiber(), test_bsc_marshaling(), test_CreateThread_basic(), test_CreateThread_suspended(), test_ExitProcess(), test_kill_on_exit(), test_QueueUserAPC(), test_runner(), Test_SimpleParameters(), test_SuspendThread(), test_TerminateProcess(), test_TerminateThread(), test_thread_security(), ThreadShutdownNotify(), WndProc(), and CHardErrorThread::~CHardErrorThread().

◆ TlsAlloc()

DWORD WINAPI TlsAlloc ( VOID  )

Definition at line 1158 of file thread.c.

1159{
1160 ULONG Index;
1161 PTEB Teb;
1162 PPEB Peb;
1163
1164 /* Get the PEB and TEB, lock the PEB */
1165 Teb = NtCurrentTeb();
1168
1169 /* Try to get regular TEB slot */
1171 if (Index != 0xFFFFFFFF)
1172 {
1173 /* Clear the value. */
1174 Teb->TlsSlots[Index] = 0;
1176 return Index;
1177 }
1178
1179 /* If it fails, try to find expansion TEB slot. */
1181 if (Index != 0xFFFFFFFF)
1182 {
1183 /* Is there no expansion slot yet? */
1184 if (!Teb->TlsExpansionSlots)
1185 {
1186 /* Allocate an array */
1187 Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1190 sizeof(PVOID));
1191 }
1192
1193 /* Did we get an array? */
1194 if (!Teb->TlsExpansionSlots)
1195 {
1196 /* Fail */
1198 Index = 0xFFFFFFFF;
1200 }
1201 else
1202 {
1203 /* Clear the value. */
1204 Teb->TlsExpansionSlots[Index] = 0;
1206 }
1207 }
1208 else
1209 {
1210 /* Fail */
1212 }
1213
1214 /* Release the lock and return */
1216 return Index;
1217}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define RtlClearBits
Definition: dbgbitmap.h:331
#define RtlFindClearBitsAndSet
Definition: dbgbitmap.h:333
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
PPEB Peb
Definition: dllmain.c:27
#define TLS_EXPANSION_SLOTS
Definition: pstypes.h:336
#define TLS_MINIMUM_AVAILABLE
Definition: ntddk_ex.h:236
PVOID TlsBitmap
Definition: ntddk_ex.h:259
PRTL_BITMAP TlsExpansionBitmap
Definition: winternl.h:538
PVOID * TlsExpansionSlots
Definition: compat.h:894
PVOID TlsSlots[64]
Definition: compat.h:879
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
_In_ WDFCOLLECTION _In_ ULONG Index
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:84
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:74

◆ TlsFree()

BOOL WINAPI TlsFree ( IN DWORD  Index)

Definition at line 1224 of file thread.c.

1225{
1226 BOOL BitSet;
1227 PPEB Peb;
1229 PVOID TlsBitmap;
1231
1232 /* Acquire the PEB lock and grab the PEB */
1233 Peb = NtCurrentPeb();
1235
1236 /* Check if the index is too high */
1238 {
1239 /* Check if it can fit in the expansion slots */
1242 {
1243 /* It's invalid */
1246 return FALSE;
1247 }
1248 else
1249 {
1250 /* Use the expansion bitmap */
1251 TlsBitmap = Peb->TlsExpansionBitmap;
1252 Index = TlsIndex;
1253 }
1254 }
1255 else
1256 {
1257 /* Use the normal bitmap */
1258 TlsBitmap = Peb->TlsBitmap;
1259 }
1260
1261 /* Check if the index was set */
1262 BitSet = RtlAreBitsSet(TlsBitmap, Index, 1);
1263 if (BitSet)
1264 {
1265 /* Tell the kernel to free the TLS cells */
1268 &Index,
1269 sizeof(DWORD));
1270 if (!NT_SUCCESS(Status))
1271 {
1274 return FALSE;
1275 }
1276
1277 /* Clear the bit */
1278 RtlClearBits(TlsBitmap, Index, 1);
1279 }
1280 else
1281 {
1282 /* Fail */
1285 return FALSE;
1286 }
1287
1288 /* Done! */
1290 return TRUE;
1291}
#define RtlAreBitsSet
Definition: dbgbitmap.h:328
@ ThreadZeroTlsCell
Definition: compat.h:945
unsigned int BOOL
Definition: ntddk_ex.h:94
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define TlsIndex
Definition: ws2_32p.h:277

Referenced by __acrt_FlsFree(), Cleanup(), ClientThreadSetupHelper(), DllMain(), Exit(), free_tls_list(), get_thread_data(), get_tls_data(), I_CryptFreeTls(), msvcrt_free_tls(), process_detach(), ProcessDetach(), spy_init(), test_CreateThread_basic(), test_reserved_tls(), test_TLS(), TLS::Uninitialize(), UXTHEME_UnInitSystem(), wined3d_dll_destroy(), wined3d_dll_init(), and xmlCleanupGlobalsInternal().

◆ TlsGetValue()

LPVOID WINAPI TlsGetValue ( IN DWORD  Index)

Definition at line 1298 of file thread.c.

1299{
1300 PTEB Teb;
1301
1302 /* Get the TEB and clear the last error */
1303 Teb = NtCurrentTeb();
1304 Teb->LastErrorValue = 0;
1305
1306 /* Check for simple TLS index */
1308 {
1309 /* Return it */
1310 return Teb->TlsSlots[Index];
1311 }
1312
1313 /* Check for valid index */
1315 {
1316 /* Fail */
1318 return NULL;
1319 }
1320
1321 /* The expansion slots are allocated on demand, so check for it. */
1322 Teb->LastErrorValue = 0;
1323 if (!Teb->TlsExpansionSlots) return NULL;
1324
1325 /* Return the value from the expansion slots */
1327}
ULONG LastErrorValue
Definition: compat.h:843

Referenced by __acrt_FlsGetValue(), __mingwthr_run_key_dtors(), _endthread(), _endthreadex(), add_active_textservice(), client_stop(), CommDlgExtendedError(), context_get_current(), CThreadMgr::CreateInstance(), detach_thread(), DllMain(), event_client(), get_indent_level(), get_thread_data(), get_tls_data(), CMenuFocusManager::GetManager(), I_CryptDetachTls(), I_CryptGetTls(), Imm32AllocateTLS(), Imm32GetTLS(), INTERNET_GetLastError(), INTERNET_GetResponseBuffer(), INTERNET_SetLastError(), INTERNET_WorkerThreadFunc(), InternetGetLastResponseInfoA(), InternetGetLastResponseInfoW(), mono_print_handler_fn(), msvcrt_free_tls_mem(), msvcrt_get_thread_data(), oob_client(), oob_server(), TLS::PeekTLS(), select_server(), server_stop(), SHGetThreadRef(), simple_client(), simple_mixed_client(), simple_server(), test_errno(), test_reserved_tls(), test_TLS(), TF_GetThreadMgr(), CThreadMgr::ThreadFocusHookProc(), threadFunc1(), UXTHEME_GetParseErrorInfo(), VirtualChannelInit(), WsSockInitialize(), WsThreadBlockingCallback(), WsThreadDestroyCurrentThread(), WsThreadGetCurrentThread(), and WsThreadGetThreadId().

◆ TlsSetValue()

BOOL WINAPI TlsSetValue ( IN DWORD  Index,
IN LPVOID  Value 
)

Definition at line 1334 of file thread.c.

1336{
1338 PTEB Teb = NtCurrentTeb();
1339
1340 /* Check for simple TLS index */
1342 {
1343 /* Return it */
1344 Teb->TlsSlots[Index] = Value;
1345 return TRUE;
1346 }
1347
1348 /* Check if this is an expansion slot */
1351 {
1352 /* Fail */
1354 return FALSE;
1355 }
1356
1357 /* Do we not have expansion slots? */
1358 if (!Teb->TlsExpansionSlots)
1359 {
1360 /* Get the PEB lock to see if we still need them */
1362 if (!Teb->TlsExpansionSlots)
1363 {
1364 /* Allocate them */
1365 Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1368 sizeof(PVOID));
1369 if (!Teb->TlsExpansionSlots)
1370 {
1371 /* Fail */
1374 return FALSE;
1375 }
1376 }
1377
1378 /* Release the lock */
1380 }
1381
1382 /* Write the value */
1384
1385 /* Success */
1386 return TRUE;
1387}
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by __acrt_FlsSetValue(), CMenuFocusManager::AcquireManager(), client_start(), COMDLG32_SetCommDlgExtendedError(), context_destroy(), context_set_current(), CThreadMgr::CreateInstance(), DllMain(), get_thread_data(), get_tls_data(), I_CryptDetachTls(), I_CryptSetTls(), Imm32AllocateTLS(), TLS::InternalAllocateTLS(), TLS::InternalDestroyTLS(), INTERNET_AllocThreadError(), INTERNET_WorkerThreadFunc(), mono_print_handler_fn(), msvcrt_get_thread_data(), release_thread_data(), CMenuFocusManager::ReleaseManager(), server_start(), set_indent_level(), SHSetThreadRef(), test_reserved_tls(), test_TLS(), threadFunc1(), UXTHEME_DeleteParseErrorInfo(), UXTHEME_GetParseErrorInfo(), WsThreadCreate(), WsThreadDelete(), WsThreadDestroyCurrentThread(), and CThreadMgr::~CThreadMgr().