ReactOS  0.4.12-dev-945-g5a2911d
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
 

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 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 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 15 of file thread.c.

◆ SXS_SUPPORT_FIXME

#define SXS_SUPPORT_FIXME

Definition at line 18 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 20 of file thread.c.

Function Documentation

◆ __declspec()

__declspec ( noreturn  )

Definition at line 29 of file thread.c.

34 {
35  /* Attempt to call the Thread Start Address */
36  _SEH2_TRY
37  {
38  /* Legacy check which is still used today for Win32 threads */
39  if (NtCurrentTeb()->NtTib.Version == (30 << 8)) // OS/2 V3.0 ("Cruiser")
40  {
41  /* This registers the termination port with CSRSS */
43  }
44 
45  /* Get the exit code from the Thread Start */
46  ExitThread((lpStartAddress)((PVOID)lpParameter));
47  }
49  {
50  /* Get the Exit code from the SEH Handler */
52  {
53  /* Kill the whole process, usually */
55  }
56  else
57  {
58  /* If running inside CSRSS, kill just this thread */
60  }
61  }
62  _SEH2_END;
63 }
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
_SEH2_TRY
Definition: create.c:4250
LONG WINAPI UnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: except.c:262
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:327
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
LPVOID lpParameter
Definition: kernel32.h:234
NTSTATUS NTAPI CsrNewThread(VOID)
Definition: api.c:27
_SEH2_END
Definition: create.c:4424
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12

◆ BaseDispatchApc()

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

Definition at line 67 of file thread.c.

70 {
71  RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActivationFrame;
72 
73  /* Setup the activation context */
74  ActivationFrame.Size = sizeof(ActivationFrame);
76 
77  /* Check if caller wanted one */
78  if (ActivationContext == INVALID_ACTIVATION_CONTEXT)
79  {
80  /* Do the APC directly */
82  return;
83  }
84 
85  /* Then activate it */
86  RtlActivateActivationContextUnsafeFast(&ActivationFrame, ActivationContext);
87 
88  /* Call the routine under SEH */
89  _SEH2_TRY
90  {
92  }
94  {
95 
96  }
97  _SEH2_END;
98 
99  /* Now de-activate and release the activation context */
101  RtlReleaseActivationContext(ActivationContext);
102 }
NTSYSAPI void WINAPI RtlReleaseActivationContext(HANDLE)
Definition: actctx.c:5267
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER
Definition: rtltypes.h:101
PRTL_ACTIVATION_CONTEXT_STACK_FRAME FASTCALL RtlDeactivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame)
Definition: actctx.c:5934
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:719
_SEH2_END
Definition: create.c:4424
PRTL_ACTIVATION_CONTEXT_STACK_FRAME FASTCALL RtlActivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame, IN PVOID Context)
Definition: actctx.c:5857
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by QueueUserAPC().

◆ BasepNotifyCsrOfThread()

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

Definition at line 484 of file proc.c.

486 {
487  BASE_API_MESSAGE ApiMessage;
488  PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest;
489 
490  DPRINT("BasepNotifyCsrOfThread: Thread: %p, Handle %p\n",
491  ClientId->UniqueThread, ThreadHandle);
492 
493  /* Fill out the request */
494  CreateThreadRequest->ClientId = *ClientId;
495  CreateThreadRequest->ThreadHandle = ThreadHandle;
496 
497  /* Call CSR */
499  NULL,
501  sizeof(*CreateThreadRequest));
502  if (!NT_SUCCESS(ApiMessage.Status))
503  {
504  DPRINT1("Failed to tell CSRSS about new thread: %lx\n", ApiMessage.Status);
505  return ApiMessage.Status;
506  }
507 
508  /* Return Success */
509  return STATUS_SUCCESS;
510 }
BASE_CREATE_THREAD CreateThreadRequest
Definition: basemsg.h:284
union _BASE_API_MESSAGE::@3379 Data
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:360
NTSTATUS Status
Definition: csrmsg.h:112
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
HANDLE ThreadHandle
Definition: basemsg.h:104
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: basemsg.h:105
HANDLE UniqueThread
Definition: compat.h:475
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by CreateRemoteThread().

◆ 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 134 of file thread.c.

141 {
143  INITIAL_TEB InitialTeb;
146  OBJECT_ATTRIBUTES LocalObjectAttributes;
148  HANDLE hThread;
149  ULONG Dummy;
150  PTEB Teb;
151  THREAD_BASIC_INFORMATION ThreadBasicInfo;
152  PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL;
153  ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
156  SIZE_T ReturnSize;
157  DPRINT("CreateRemoteThread: hProcess: %p dwStackSize: %lu lpStartAddress"
158  ": %p lpParameter: %p, dwCreationFlags: %lx\n", hProcess,
159  dwStackSize, lpStartAddress, lpParameter, dwCreationFlags);
160 
161  /* Clear the Context */
162  RtlZeroMemory(&Context, sizeof(CONTEXT));
163 
164  /* Write PID */
166 
167  /* Create the Stack */
169  dwStackSize,
170  dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION ?
171  dwStackSize : 0,
172  &InitialTeb);
173  if (!NT_SUCCESS(Status))
174  {
176  return NULL;
177  }
178 
179  /* Create Initial Context */
181  lpParameter,
182  lpStartAddress,
183  InitialTeb.StackBase,
184  1);
185 
186  /* initialize the attributes for the thread object */
187  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
188  lpThreadAttributes,
189  NULL);
190 
191  /* Create the Kernel Thread Object */
195  hProcess,
196  &ClientId,
197  &Context,
198  &InitialTeb,
199  TRUE);
200  if (!NT_SUCCESS(Status))
201  {
202  /* Fail the kernel create */
203  BaseFreeThreadStack(hProcess, &InitialTeb);
205  return NULL;
206  }
207 
208  /* Are we in the same process? */
209  if (hProcess == NtCurrentProcess())
210  {
211  /* Get the TEB */
214  &ThreadBasicInfo,
215  sizeof(ThreadBasicInfo),
216  &ReturnLength);
217  if (!NT_SUCCESS(Status))
218  {
219  /* Fail */
220  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
221  "NtQueryInformationThread() failed with status %08lx\n",
223  return NULL;
224  }
225 
226  /* Allocate the Activation Context Stack */
227  Status = RtlAllocateActivationContextStack(&ActivationContextStack);
228  if (!NT_SUCCESS(Status))
229  {
230  /* Fail */
231  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
232  "RtlAllocateActivationContextStack() failed with status %08lx\n",
234  return NULL;
235  }
236 
237  /* Save it */
238  Teb = ThreadBasicInfo.TebBaseAddress;
239  Teb->ActivationContextStackPointer = ActivationContextStack;
240 
241  /* Query the Context */
243  NULL,
244  0,
245  ActivationContextBasicInformation,
246  &ActCtxInfo,
247  sizeof(ActCtxInfo),
248  &ReturnSize);
249  if (!NT_SUCCESS(Status))
250  {
251  /* Fail */
252  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
253  "RtlQueryInformationActivationContext() failed with status %08lx\n",
255 
256  /* Free the activation context stack */
257  // RtlFreeThreadActivationContextStack();
259 
260  return NULL;
261  }
262 
263  /* Does it need to be activated? */
264  if ((ActCtxInfo.hActCtx) && !(ActCtxInfo.dwFlags & 1))
265  {
266  /* Activate it */
268  Teb,
269  ActCtxInfo.hActCtx,
270  &Cookie);
271  if (!NT_SUCCESS(Status))
272  {
273  /* Fail */
274  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
275  "RtlActivateActivationContextEx() failed with status %08lx\n",
277 
278  /* Free the activation context stack */
279  // RtlFreeThreadActivationContextStack();
281 
282  return NULL;
283  }
284  }
285  }
286 
287  /* Notify CSR */
289  {
292  }
293  else
294  {
295  if (hProcess != NtCurrentProcess())
296  {
298 
299  /* Get the direct CSRSRV export */
302  "CsrCreateRemoteThread");
304  {
305  /* Call it instead of going through LPC */
308  }
309  }
310  }
311 
312  /* Success */
313  if (lpThreadId) *lpThreadId = HandleToUlong(ClientId.UniqueThread);
314 
315  /* Resume it if asked */
316  if (!(dwCreationFlags & CREATE_SUSPENDED)) NtResumeThread(hThread, &Dummy);
317 
318  /* Return handle to thread */
319  return hThread;
320 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:503
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:79
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
HANDLE UniqueProcess
Definition: compat.h:474
#define RTL_ACTIVATE_ACTIVATION_CONTEXT_EX_FLAG_RELEASE_ON_STACK_DEALLOCATION
Definition: rtltypes.h:106
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define CREATE_SUSPENDED
Definition: winbase.h:178
#define ERROR_DBGBREAK(...)
Definition: debug.h:221
smooth NULL
Definition: ftsmooth.c:416
PVOID StackBase
Definition: pstypes.h:678
void DPRINT(...)
Definition: polytest.cpp:61
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STACK_SIZE_PARAM_IS_A_RESERVATION
Definition: winbase.h:558
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:13
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
HANDLE UniqueThread
Definition: compat.h:475
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSTATUS NTAPI CsrCreateRemoteThread(IN HANDLE hThread, IN PCLIENT_ID ClientId)
Definition: thredsup.c:568
NTSTATUS WINAPI BaseCreateStack(HANDLE hProcess, SIZE_T StackCommit, SIZE_T StackReserve, PINITIAL_TEB InitialTeb)
Definition: utils.c:353
LPVOID lpParameter
Definition: kernel32.h:234
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:819
POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes, IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, IN PUNICODE_STRING ObjectName)
Definition: utils.c:304
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
Definition: compat.h:484
NTSTATUS WINAPI BasepNotifyCsrOfThread(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
Definition: proc.c:484
NTSTATUS NTAPI NtCreateThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ProcessHandle, OUT PCLIENT_ID ClientId, IN PCONTEXT ThreadContext, IN PINITIAL_TEB InitialTeb, IN BOOLEAN CreateSuspended)
Definition: thread.c:941
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG, HANDLE, PVOID, ULONG, PVOID, SIZE_T, SIZE_T *)
Definition: actctx.c:5438
HANDLE hThread
Definition: wizard.c:27
#define RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT
Definition: rtltypes.h:116
NTSTATUS(NTAPI * PCSR_CREATE_REMOTE_THREAD)(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
Definition: thread.c:20
NTSTATUS NTAPI RtlActivateActivationContextEx(ULONG flags, PTEB tebAddress, HANDLE handle, PULONG_PTR cookie)
Definition: actctx.c:5291
NTSTATUS NTAPI RtlAllocateActivationContextStack(IN PACTIVATION_CONTEXT_STACK *Stack)
Definition: actctx.c:5829
struct tagContext Context
Definition: acpixf.h:1012
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define GetProcAddress(x, y)
Definition: compat.h:410
PVOID ActivationContextStackPointer
Definition: compat.h:503
#define __FUNCTION__
Definition: types.h:112
VOID WINAPI BaseFreeThreadStack(IN HANDLE hProcess, IN PINITIAL_TEB InitialTeb)
Definition: utils.c:486
VOID NTAPI RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack)
Definition: actctx.c:5363

Referenced by _DoDLLInjection(), BaseCreateThreadPoolThread(), ConDrvConsoleCtrlEventTimeout(), ConSrvConsoleCtrlEventTimeout(), CreateThread(), dll_entry_point(), GuiConsoleShowConsoleProperties(), test_CreateRemoteThread(), 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 112 of file thread.c.

118 {
119  /* Act as if we're going to create a remote thread in ourselves */
121  lpThreadAttributes,
122  dwStackSize,
123  lpStartAddress,
124  lpParameter,
125  dwCreationFlags,
126  lpThreadId);
127 }
#define NtCurrentProcess()
Definition: nt_native.h:1657
LPVOID lpParameter
Definition: kernel32.h:234
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:134

Referenced by _beginthread(), _beginthreadex(), _ServiceMain(), _test_flush_async(), _tWinMain(), AcceptConnections(), ANIMATE_Play(), apartment_hostobject_in_hostapt(), ApplicationPageWndProc(), AVISplitter_first_request(), cache_connection(), check_hook_thread(), check_thread_instance(), child_process(), clipboard_wnd_proc(), CommonInstall(), create_child_thread(), CreateClientProcess(), CreateLobbyMessageReceptionThread(), CreateRenderingSubsystem(), CreateRenderingWindow(), CreateServers(), CreateServiceThread(), CreateSidCacheMgr(), CreateSoundThread(), CSysTray::CreateSysTrayThread(), CreateTestThread(), CThread::CThread(), DbgkCreateThread(), DbgkpPostFakeThreadMessages(), DbgUiConvertStateChangeStructure(), CTrayWindow::DisplayProperties(), CTrayWindow::DisplayRunFileDlg(), dll_entry_point(), do_msidbCustomActionTypeDll(), do_msidbCustomActionTypeScript(), do_wait_idle_child(), DosStartProcess32(), CDownloadManager::DownloadDlgProc(), EmulatorInitialize(), ensurePlayerThread(), ExitWindowsWorker(), GUIDisplayStatusMessage(), GuiInit(), HandleLogoff(), HandleShutdown(), http_release_netconn(), IDirectPlay4Impl_EnumSessions(), IDirectSoundCaptureBufferImpl_Start(), init(), InitDialog(), CDesktopThread::Initialize(), BtrfsPropSheet::Initialize(), COutputPin::InitializeIOThread(), InitializeScreenSaver(), InitiateSoundStreaming(), InstallDrvDlgProc(), installer_proc(), InstallReactOS(), CZipFolder::InvokeCommand(), iocp_async_read_thread(), iocp_async_read_thread_closesocket(), KmtRunKernelTest(), LocalScheduleJob(), LS_ThreadProc(), LsapRmInitializeServer(), MailSlotReader(), main(), MainDialogProc(), MCI_SendCommandAsync(), MCIAVI_mciPlay_async(), MCICDA_Play(), MCIQTZ_mciPlay(), midiStreamOpen(), MMDevEnum_RegisterEndpointNotificationCallback(), mmTaskCreate(), StringTest::mt(), MULTIMEDIA_PlaySound(), Netbios(), netconn_resolve(), NotifyTopLevelWindow(), Telnet::Open(), audio_waveout::open(), audio_wavein::open(), OpenDevice(), OutputQueue_Construct(), CKsClockForwarder::Pause(), PdhCollectQueryDataEx(), PerformancePageWndProc(), PipeInit(), PlayLogonSound(), ProcessDlgProc(), ProcessPageWndProc(), Protocol_Start(), protocol_start(), PullPin_InitProcessing(), queue_task(), BtrfsRecv::RecvProgressDlgProc(), ReferenceClock_AdvisePeriodic(), ReferenceClock_AdviseTime(), RegisterGPNotification(), report(), RPC_StartLocalServer(), RpcReadFile(), rpcrt4_ncacn_http_open(), RPCRT4_new_client(), RPCRT4_start_listen_protseq(), run_LS_tests(), run_thread(), RunSelectedTest(), RunSetup(), RunShell(), ScStartService(), SearchDrvDlgProc(), ServiceInit(), ServiceMain(), BtrfsPropSheet::set_cmdline(), SHCreateThread(), SHOpenFolderWindow(), SockCreateOrReferenceAsyncThread(), start_dummy_thread(), start_host_object2(), start_installation(), START_TEST(), StartAdapterDiscovery(), StartAuthenticationPort(), StartClients(), StartComponentRegistration(), StartNotificationThread(), CProgressDialog::StartProgressDialog(), BtrfsSend::StartSend(), StartServer(), StartServiceThread(), StartStopEnumEventsThread(), StartSystemShutdown(), StartTestCORE10188(), CHardErrorThread::StartThread(), SystemClockPostMessageToAdviseThread(), test(), test_AbortWaitCts(), test_accept(), test_activateapp(), test_alertable(), test_alertable_wait(), test_apc_deadlock(), test_attach_input(), test_bsc_marshaling(), Test_CloseWhileSelectDuplicatedSocket(), Test_CloseWhileSelectSameSocket(), test_CoFreeUnusedLibraries(), 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_dde_default_app(), test_default_ime_window_creation(), test_defwinproc(), test_deletecontext(), test_DragQueryFile(), test_enum_thread_windows(), test_events(), test_ffcn_directory_overlap(), test_ffcnMultipleThreads(), test_foregroundwindow(), test_GetKeyState(), test_getservbyname(), test_gettext(), test_GetThreadExitCode(), test_GetThreadTimes(), test_globalinterfacetable(), test_handles(), test_http_connection(), test_ImmDefaultHwnd(), test_ImmThreads(), test_ImpersonateNamedPipeClient(), test_implicit_mta(), test_inet_ntoa(), test_Input_mouse(), test_InSendMessage(), test_interthread_messages(), test_keyed_events(), test_layered_window(), test_menu_input(), test_MessageBox(), test_messages(), test_multithreaded_clipboard(), test_mutant(), test_NamedPipe_2(), test_no_couninitialize_client(), test_no_couninitialize_server(), test_nonalertable(), test_NtAtom(), test_overlapped(), test_PeekMessage(), test_proxy_used_in_wrong_thread(), test_reader_info(), test_reconnect(), test_registered_object_thread_affinity(), test_render_with_multithread(), test_RtlIsCriticalSectionLocked(), test_runner(), test_select(), test_send(), test_SendMessage_other_thread(), test_SendMessageTimeout(), test_set_clipboard_DRAWCLIPBOARD(), test_SetCursor(), test_SetFocus(), test_SetForegroundWindow(), test_ShowCursor(), test_smresult(), test_srwlock_base(), test_srwlock_example(), test_stop_wait_for_call(), test_SuspendThread(), test_tableweak_and_normal_marshal_and_releasedata(), test_tableweak_and_normal_marshal_and_unmarshal(), test_TerminateThread(), test_thread_actctx(), test_thread_objects(), test_thread_security(), test_thread_start_address(), test_threads(), test_timers(), test_two_tableweak_marshal_and_releasedata(), test_WaitBreak(), test_WaitCts(), test_WaitDcd(), test_WaitDsr(), test_WaitForInputIdle(), test_WaitRing(), test_winevents(), test_write_watch(), test_WSAPoll(), test_WSARecv(), TestMessages(), TestRecursiveInterThreadMessages(), thread(), TIME_MMTimeStart(), UserLogin(), WahOpenHandleHelper(), wave_out_test_deviceOut(), WdmAudCommitWaveBufferByMMixer(), WdmAudSetMixerDeviceFormatByLegacy(), wined3d_cs_create(), winhttp_request_Send(), WinMain(), wmain(), WriterThread::WriterThread(), WsAsyncCheckAndInitThread(), WshShell3_Popup(), and wWinMain().

◆ ExitThread()

VOID WINAPI ExitThread ( IN DWORD  uExitCode)

Definition at line 327 of file thread.c.

328 {
331  PRTL_CRITICAL_SECTION LoaderLock;
332 
333  /* Make sure loader lock isn't held */
334  LoaderLock = NtCurrentPeb()->LoaderLock;
335  if (LoaderLock) ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
336 
337  /*
338  * Terminate process if this is the last thread
339  * of the current process
340  */
343  &LastThread,
344  sizeof(LastThread),
345  NULL);
346  if ((NT_SUCCESS(Status)) && (LastThread)) ExitProcess(uExitCode);
347 
348  /* Notify DLLs and TLS Callbacks of termination */
350 
351  /* Tell the Kernel to free the Stack */
352  NtCurrentTeb()->FreeStackOnTermination = TRUE;
353  NtTerminateThread(NULL, uExitCode);
354 
355  /* We should never reach this place */
356  ERROR_FATAL("It should not happen\n");
357  while (TRUE); /* 'noreturn' function */
358 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define NtCurrentThread()
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
#define ERROR_FATAL(...)
Definition: debug.h:238
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
Definition: kill.c:1278
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
HANDLE UniqueThread
Definition: compat.h:475
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
PETHREAD LastThread
Definition: pinsup.c:109
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define NtCurrentPeb()
Definition: FLS.c:19
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI LdrShutdownThread(VOID)
Definition: ldrinit.c:1078

Referenced by __declspec(), _endthread(), _endthreadex(), BaseExitThreadPoolThread(), BaseProcessStartup(), ChargenHandler(), client_stop(), collect_query_thread(), ConsoleControlDispatcher(), CreateSystemThreads(), DaytimeHandler(), DbgkExitThread(), ddeThread(), DeleteFiber(), DiscardHandler(), EchoHandler(), ExitWindowsThread(), FreeLibraryAndExitThread(), MMSYSTEM_MidiStream_Player(), NotificationThread(), PullPin_Thread_Stop(), QotdHandler(), server_stop(), StartServer(), test_thread_func(), WaveActivateSoundStreaming(), wmain(), and wWinMain().

◆ GetCurrentThreadId()

DWORD WINAPI GetCurrentThreadId ( VOID  )

Definition at line 421 of file thread.c.

422 {
424 }
#define HandleToUlong(h)
Definition: basetsd.h:79
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
HANDLE UniqueThread
Definition: compat.h:475
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

Referenced by __security_init_cookie(), __threadid(), alloc_msi_remote_handle(), alloc_msihandle(), ANIMATE_DoStop(), apartment_construct(), AtlModuleAddCreateWndData(), AtlModuleExtractCreateWndData(), ATL::AtlWinModuleAddCreateWndData(), ATL::AtlWinModuleExtractCreateWndData(), callback(), callback_func(), cbt_global_hook_proc(), cbt_hook_proc(), check_active_state_(), check_dinput_hooks(), check_notification(), check_wnd_state_(), clipboard_thread(), clnt_cb_thread(), clnt_vc_create(), clnt_vc_destroy(), CMenuFocusManager::CMenuFocusManager(), context_create(), context_destroy(), context_reacquire(), create_binding_protocol(), create_child_window(), Window::create_mdi_child(), create_test_windows(), CreateD3D9(), dialog_proc(), dialog_register_class(), dialog_run_message_loop(), DlgMainProc(), DllThread(), do_InitialDesktop_child(), do_wait_idle_child(), dprintf(), enum_thread(), EnumThreadWindows(), eprintf(), event_client(), fetch_thread_info(), get_default_context(), get_ime_window(), get_or_create_threaddata(), 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(), image_lock(), IMM_FreeThreadData(), IMM_GetThreadData(), IMM_IsCrossThreadAccess(), ImmCreateContext(), init_tests(), InitChildWindow(), InitD3D9BaseDevice(), InitThreads(), is_apartment_thread(), JScript_AddNamedItem(), JScript_Close(), JScript_GetScriptDispatch(), JScript_GetScriptState(), JScript_SetScriptSite(), JScript_SetScriptState(), JScriptParse_ParseScriptText(), JScriptParseProcedure_ParseProcedureText(), load_gecko(), log_debug(), log_hexdump(), MainDialogProc(), MainWndProc(), MCI_LoadMciDriver(), 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(), OLEMenu_CallWndProc(), OLEMenu_GetMsgProc(), OLEMenu_InstallHooks(), OleSetMenuDescriptor(), oob_client(), oob_server(), PersistMoniker_Load(), print_sr_status_flags(), Protocol_Continue(), Rs232Thread(), rtl_wait_cb(), ScriptThread(), select_server(), semaphore_thread_proc(), server_stop(), set_cursor_thread(), SetupWindowsHook(), show_cursor_thread(), simple_client(), simple_mixed_client(), simple_server(), SPY_EnterMessage(), START_TEST(), statusclb_GetBindInfo(), statusclb_OnDataAvailable(), statusclb_OnProgress(), statusclb_OnStartBinding(), statusclb_OnStopBinding(), statusclb_QueryInterface(), Stream_Read(), sw_SetContext(), swapchain_create_context(), swapchain_get_context(), test_alertable(), test_async_HttpSendRequestEx(), test_attach_input(), test_capture_4_proc(), 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_foregroundwindow(), test_fragmentsize(), test_handles(), test_IInitializeSpy(), test_Input_mouse(), test_inputdesktop(), test_inputdesktop2(), test_IsDialogMessage(), test_keyboard_input(), test_message_conversion(), test_MessageBox(), test_notify_message(), test_ole_initialization(), Test_OpenInputDesktop(), test_process_security_child(), test_quit_message(), test_recursive_hook(), Test_References(), test_RtlLeaveCriticalSection(), test_set_hook(), test_SetCursor(), Test_SetCursorPos(), test_SetFocus(), test_ShowCursor(), test_thread_info(), test_thread_priority(), test_tp_group_cancel(), test_winmodule(), test_wiznavigation(), TestGetUserObjectInfoA(), TestGetUserObjectInfoW(), thread(), thread_proc(), threadFunc1(), ThreadShutdownNotify(), TIME_TriggerCallBack(), 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(), win_event_proc(), WindowThreadProc(), wined3d_cs_mt_check_space(), 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(), xmlGetThreadId(), and xmlIsMainThread().

◆ GetExitCodeThread()

BOOL WINAPI GetExitCodeThread ( IN HANDLE  hThread,
OUT LPDWORD  lpExitCode 
)

Definition at line 503 of file thread.c.

505 {
506  THREAD_BASIC_INFORMATION ThreadBasic;
508 
511  &ThreadBasic,
512  sizeof(THREAD_BASIC_INFORMATION),
513  NULL);
514  if (!NT_SUCCESS(Status))
515  {
517  return FALSE;
518  }
519 
520  *lpExitCode = ThreadBasic.ExitStatus;
521  return TRUE;
522 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27

Referenced by child_process(), custom_get_thread_return(), dll_entry_point(), DosStartProcess32(), EndLocalThread(), ExitWindowsWorker(), FinishNotificationThread(), HandleLogoff(), HandleShutdown(), init(), MIDI_mciPlay(), netconn_resolve(), NotifyTopLevelWindow(), pattern_fork(), test_CreateRemoteThread(), test_CreateThread_basic(), test_ExitProcess(), test_ffcnMultipleThreads(), test_GetThreadExitCode(), test_registered_object_thread_affinity(), test_SetCursor(), test_ShowCursor(), test_SuspendFlag(), test_SuspendThread(), test_TerminateThread(), test_thread_priority(), and TestRecursiveInterThreadMessages().

◆ GetProcessIdOfThread()

DWORD WINAPI GetProcessIdOfThread ( IN HANDLE  Thread)

Definition at line 851 of file thread.c.

852 {
853  THREAD_BASIC_INFORMATION ThreadBasic;
855 
858  &ThreadBasic,
859  sizeof(THREAD_BASIC_INFORMATION),
860  NULL);
861  if (!NT_SUCCESS(Status))
862  {
864  return 0;
865  }
866 
867  return HandleToUlong(ThreadBasic.ClientId.UniqueProcess);
868 }
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:79
HANDLE UniqueProcess
Definition: compat.h:474
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24

Referenced by IMM_GetThreadData().

◆ GetTeb()

PTEB GetTeb ( VOID  )

Definition at line 400 of file thread.c.

401 {
402  return NtCurrentTeb();
403 }
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

◆ GetThreadContext()

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

Definition at line 463 of file thread.c.

465 {
467 
468  Status = NtGetContextThread(hThread, lpContext);
469  if (!NT_SUCCESS(Status))
470  {
472  return FALSE;
473  }
474 
475  return TRUE;
476 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
NTSTATUS NTAPI NtGetContextThread(IN HANDLE ThreadHandle, IN OUT PCONTEXT ThreadContext)
Definition: debug.c:334

Referenced by fetch_thread_info(), main(), START_TEST(), test_ExitProcess(), test_thread_info(), and ThreadData::Update().

◆ GetThreadId()

DWORD WINAPI GetThreadId ( IN HANDLE  Thread)

Definition at line 875 of file thread.c.

876 {
877  THREAD_BASIC_INFORMATION ThreadBasic;
879 
882  &ThreadBasic,
883  sizeof(THREAD_BASIC_INFORMATION),
884  NULL);
885  if (!NT_SUCCESS(Status))
886  {
888  return 0;
889  }
890 
891  return HandleToUlong(ThreadBasic.ClientId.UniqueThread);
892 }
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:79
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
HANDLE UniqueThread
Definition: compat.h:475
Status
Definition: gdiplustypes.h:24

Referenced by _tWinMain(), CommonInstall(), InstallReactOS(), RpcCancelThreadEx(), and RpcMgmtWaitServerListen().

◆ GetThreadIOPendingFlag()

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

Definition at line 970 of file thread.c.

972 {
973  ULONG IoPending;
975 
976  /* Query the flag */
979  &IoPending,
980  sizeof(IoPending),
981  NULL);
982  if (NT_SUCCESS(Status))
983  {
984  /* Return the flag */
985  *lpIOIsPending = IoPending ? TRUE : FALSE;
986  return TRUE;
987  }
988 
989  /* Fail */
991  return FALSE;
992 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1

◆ GetThreadPriority()

int WINAPI GetThreadPriority ( IN HANDLE  hThread)

Definition at line 701 of file thread.c.

702 {
703  THREAD_BASIC_INFORMATION ThreadBasic;
705 
706  /* Query the Base Priority Increment */
709  &ThreadBasic,
710  sizeof(THREAD_BASIC_INFORMATION),
711  NULL);
712  if (!NT_SUCCESS(Status))
713  {
714  /* Failure */
717  }
718 
719  /* Do some conversions for saturation values */
720  if (ThreadBasic.BasePriority == ((HIGH_PRIORITY + 1) / 2))
721  {
722  /* Win32 calls this "time critical" */
724  }
725  else if (ThreadBasic.BasePriority == -((HIGH_PRIORITY + 1) / 2))
726  {
727  /* Win32 calls this "idle" */
728  ThreadBasic.BasePriority = THREAD_PRIORITY_IDLE;
729  }
730 
731  /* Return the final result */
732  return ThreadBasic.BasePriority;
733 }
#define THREAD_PRIORITY_ERROR_RETURN
Definition: winbase.h:279
LONG NTSTATUS
Definition: precomp.h:26
KPRIORITY BasePriority
Definition: compat.h:581
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define HIGH_PRIORITY
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:278
#define THREAD_PRIORITY_IDLE
Definition: winbase.h:275
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27

Referenced by priorityTimeProc(), and test_thread_priority().

◆ GetThreadPriorityBoost()

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

Definition at line 740 of file thread.c.

742 {
745 
748  &PriorityBoost,
749  sizeof(ULONG),
750  NULL);
751  if (!NT_SUCCESS(Status))
752  {
754  return FALSE;
755  }
756 
757  *pDisablePriorityBoost = PriorityBoost;
758  return TRUE;
759 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ CCHAR PriorityBoost
Definition: iofuncs.h:763
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1

Referenced by init_funcs().

◆ GetThreadSelectorEntry()

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

Definition at line 792 of file thread.c.

795 {
796 #ifdef _M_IX86
797  DESCRIPTOR_TABLE_ENTRY DescriptionTableEntry;
799 
800  /* Set the selector and do the query */
801  DescriptionTableEntry.Selector = dwSelector;
804  &DescriptionTableEntry,
805  sizeof(DESCRIPTOR_TABLE_ENTRY),
806  NULL);
807  if (!NT_SUCCESS(Status))
808  {
809  /* Fail */
811  return FALSE;
812  }
813 
814  /* Success, return the selector */
815  *lpSelectorEntry = DescriptionTableEntry.Descriptor;
816  return TRUE;
817 #else
818  DPRINT1("Calling GetThreadSelectorEntry!\n");
819  return FALSE;
820 #endif
821 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8

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 431 of file thread.c.

436 {
437  KERNEL_USER_TIMES KernelUserTimes;
439 
441  ThreadTimes,
442  &KernelUserTimes,
443  sizeof(KERNEL_USER_TIMES),
444  NULL);
445  if (!NT_SUCCESS(Status))
446  {
448  return FALSE;
449  }
450 
451  *lpCreationTime = *(LPFILETIME)&KernelUserTimes.CreateTime;
452  *lpExitTime = *(LPFILETIME)&KernelUserTimes.ExitTime;
453  *lpKernelTime = *(LPFILETIME)&KernelUserTimes.KernelTime;
454  *lpUserTime = *(LPFILETIME)&KernelUserTimes.UserTime;
455  return TRUE;
456 }
#define TRUE
Definition: types.h:120
struct _FILETIME * LPFILETIME
Definition: time.c:29
LONG NTSTATUS
Definition: precomp.h:26
LARGE_INTEGER UserTime
Definition: winternl.h:1063
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
LARGE_INTEGER KernelTime
Definition: winternl.h:1062

Referenced by test_GetThreadTimes().

◆ OpenThread()

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

Definition at line 365 of file thread.c.

368 {
370  HANDLE ThreadHandle;
373 
376 
378  NULL,
379  (bInheritHandle ? OBJ_INHERIT : 0),
380  NULL,
381  NULL);
382 
383  Status = NtOpenThread(&ThreadHandle,
384  dwDesiredAccess,
386  &ClientId);
387  if (!NT_SUCCESS(Status))
388  {
390  return NULL;
391  }
392 
393  return ThreadHandle;
394 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define ULongToHandle(h)
Definition: basetsd.h:81
NTSTATUS NTAPI NtOpenThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId OPTIONAL)
Definition: thread.c:1013
LONG NTSTATUS
Definition: precomp.h:26
HANDLE UniqueProcess
Definition: compat.h:474
static BOOL bInheritHandle
Definition: pipe.c:82
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_INHERIT
Definition: winternl.h:225
HANDLE UniqueThread
Definition: compat.h:475
DWORD dwThreadId
Definition: fdebug.c:31
Status
Definition: gdiplustypes.h:24
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by fetch_thread_info(), IMM_GetThreadData(), init_funcs(), test_process_security_child(), test_RtlRegisterWait(), and test_Toolhelp().

◆ QueueUserAPC()

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

Definition at line 910 of file thread.c.

913 {
915  ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
916 
917  /* Zero the activation context and query information on it */
918  RtlZeroMemory(&ActCtxInfo, sizeof(ActCtxInfo));
920  NULL,
921  0,
922  ActivationContextBasicInformation,
923  &ActCtxInfo,
924  sizeof(ActCtxInfo),
925  NULL);
926  if (!NT_SUCCESS(Status))
927  {
928  /* Fail due to SxS */
929  DbgPrint("SXS: %s failing because RtlQueryInformationActivationContext()"
930  "returned status %08lx\n", __FUNCTION__, Status);
932  return FALSE;
933  }
934 
935  /* Queue the APC */
938  pfnAPC,
939  (PVOID)dwData,
940  (ActCtxInfo.dwFlags & 1) ?
941  INVALID_ACTIVATION_CONTEXT : ActCtxInfo.hActCtx);
942  if (!NT_SUCCESS(Status))
943  {
945  return FALSE;
946  }
947 
948  /* All good */
949  return TRUE;
950 }
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
LONG NTSTATUS
Definition: precomp.h:26
static HANDLE ULONG_PTR dwData
Definition: file.c:35
NTSTATUS NTAPI NtQueueApcThread(IN HANDLE ThreadHandle, IN PKNORMAL_ROUTINE ApcRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: state.c:500
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI BaseDispatchApc(IN PAPCFUNC ApcRoutine, IN PVOID Data, IN PACTIVATION_CONTEXT ActivationContext)
Definition: thread.c:67
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG, HANDLE, PVOID, ULONG, PVOID, SIZE_T, SIZE_T *)
Definition: actctx.c:5438
HANDLE hThread
Definition: wizard.c:27
#define RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT
Definition: rtltypes.h:116
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:632
#define __FUNCTION__
Definition: types.h:112

Referenced by async_notifier_proc(), DeleteNode(), FreeChangeNotifications(), SHChangeNotifyRegister(), test_alertable_wait(), test_CoWaitForMultipleHandles(), test_MsgWaitForMultipleObjects(), test_RtlRegisterWait(), WahCloseHandleHelper(), and WahQueueUserApc().

◆ QueueUserWorkItem()

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

Definition at line 999 of file thread.c.

1002 {
1003  NTSTATUS Status;
1004 
1005  /* NOTE: Rtl needs to safely call the function using a trampoline */
1007  if (!NT_SUCCESS(Status))
1008  {
1009  /* Failed */
1011  return FALSE;
1012  }
1013 
1014  /* All good */
1015  return TRUE;
1016 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlQueueWorkItem(_In_ WORKERCALLBACKFUNC Function, _In_opt_ PVOID Context, _In_ ULONG Flags)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID(NTAPI * WORKERCALLBACKFUNC)(_In_ PVOID Context)
Definition: rtltypes.h:509

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

◆ ResumeThread()

DWORD WINAPI ResumeThread ( IN HANDLE  hThread)

Definition at line 529 of file thread.c.

530 {
531  ULONG PreviousResumeCount;
533 
534  Status = NtResumeThread(hThread, &PreviousResumeCount);
535  if (!NT_SUCCESS(Status))
536  {
538  return -1;
539  }
540 
541  return PreviousResumeCount;
542 }
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1

Referenced by _beginthread(), cmd_start(), CommandThreadProc(), cordebugprocess_Continue(), CreateProcessAsUserCommon(), CreateSoundThread(), fetch_thread_info(), IDirectPlayLobby3AImpl_RunApplication(), main(), midiStreamRestart(), Netbios(), ProcessDlgProc(), ScmStartUserModeService(), StartStopEnumEventsThread(), test_apc_deadlock(), test_CreateRemoteThread(), test_CreateThread_suspended(), test_end_to_end_server(), test_GetThreadTimes(), test_msg_server(), test_query_process_debug_flags(), test_SuspendFlag(), test_SuspendThread(), test_Toolhelp(), TestRecursiveInterThreadMessages(), Thread1(), and WahOpenHandleHelper().

◆ SetThreadAffinityMask()

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

Definition at line 624 of file thread.c.

626 {
627  THREAD_BASIC_INFORMATION ThreadBasic;
628  KAFFINITY AffinityMask;
630 
631  AffinityMask = (KAFFINITY)dwThreadAffinityMask;
632 
635  &ThreadBasic,
636  sizeof(THREAD_BASIC_INFORMATION),
637  NULL);
638  if (!NT_SUCCESS(Status))
639  {
641  return 0;
642  }
643 
646  &AffinityMask,
647  sizeof(KAFFINITY));
648  if (!NT_SUCCESS(Status))
649  {
651  ThreadBasic.AffinityMask = 0;
652  }
653 
654  return ThreadBasic.AffinityMask;
655 }
KAFFINITY AffinityMask
Definition: compat.h:579
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1967
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
Status
Definition: gdiplustypes.h:24
ULONG_PTR KAFFINITY
Definition: compat.h:75
HANDLE hThread
Definition: wizard.c:27

Referenced by test_thread_processor(), and wmain().

◆ SetThreadContext()

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

Definition at line 483 of file thread.c.

485 {
487 
488  Status = NtSetContextThread(hThread, (PCONTEXT)lpContext);
489  if (!NT_SUCCESS(Status))
490  {
492  return FALSE;
493  }
494 
495  return TRUE;
496 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetContextThread(IN HANDLE ThreadHandle, IN PCONTEXT ThreadContext)
Definition: debug.c:371
HANDLE hThread
Definition: wizard.c:27

Referenced by test_ExitProcess().

◆ SetThreadIdealProcessor()

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

Definition at line 828 of file thread.c.

830 {
832 
835  &dwIdealProcessor,
836  sizeof(ULONG));
837  if (!NT_SUCCESS(Status))
838  {
840  return -1;
841  }
842 
843  return (DWORD)Status;
844 }
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1967
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1

Referenced by init_funcs().

◆ SetThreadPriority()

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

Definition at line 662 of file thread.c.

664 {
665  LONG Prio = nPriority;
667 
668  /* Check if values forcing saturation should be used */
669  if (Prio == THREAD_PRIORITY_TIME_CRITICAL)
670  {
671  /* This is 16 */
672  Prio = (HIGH_PRIORITY + 1) / 2;
673  }
674  else if (Prio == THREAD_PRIORITY_IDLE)
675  {
676  /* This is -16 */
677  Prio = -((HIGH_PRIORITY + 1) / 2);
678  }
679 
680  /* Set the Base Priority */
683  &Prio,
684  sizeof(LONG));
685  if (!NT_SUCCESS(Status))
686  {
687  /* Failure */
689  return FALSE;
690  }
691 
692  /* Return */
693  return TRUE;
694 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
long LONG
Definition: pedump.c:60
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1967
#define HIGH_PRIORITY
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define THREAD_PRIORITY_TIME_CRITICAL
Definition: winbase.h:278
#define THREAD_PRIORITY_IDLE
Definition: winbase.h:275
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27

Referenced by ConsoleControlDispatcher(), ensurePlayerThread(), GuiInit(), main(), MCI_SendCommandAsync(), MCIAVI_mciPlay_async(), midiStreamOpen(), mmTaskCreate(), MULTIMEDIA_PlaySound(), Telnet::Open(), OutputQueue_Construct(), SockAsyncThread(), SystemClockPostMessageToAdviseThread(), test_ExitProcess(), test_thread_priority(), TIME_MMTimeStart(), WaveThread(), and WriterThread::WriterThread().

◆ SetThreadPriorityBoost()

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

Definition at line 766 of file thread.c.

768 {
771 
772  PriorityBoost = bDisablePriorityBoost != FALSE;
773 
776  &PriorityBoost,
777  sizeof(ULONG));
778  if (!NT_SUCCESS(Status))
779  {
781  return FALSE;
782  }
783 
784  return TRUE;
785 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ CCHAR PriorityBoost
Definition: iofuncs.h:763
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1967
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1

Referenced by init_funcs().

◆ SetThreadStackGuarantee()

BOOL WINAPI SetThreadStackGuarantee ( IN OUT PULONG  StackSizeInBytes)

Definition at line 957 of file thread.c.

958 {
959  static int once;
960  if (once++ == 0)
961  DPRINT1("SetThreadStackGuarantee(%p): stub\n", StackSizeInBytes);
962  return TRUE;
963 }
#define TRUE
Definition: types.h:120
#define DPRINT1
Definition: precomp.h:8

◆ SetThreadUILanguage()

LANGID WINAPI SetThreadUILanguage ( IN LANGID  LangId)

Definition at line 899 of file thread.c.

900 {
902  return (LANGID)NtCurrentTeb()->CurrentLocale;
903 }
WORD LANGID
Definition: typedefs.h:79
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define UNIMPLEMENTED
Definition: debug.h:114

◆ SuspendThread()

DWORD WINAPI SuspendThread ( IN HANDLE  hThread)

Definition at line 604 of file thread.c.

605 {
606  ULONG PreviousSuspendCount;
608 
609  Status = NtSuspendThread(hThread, &PreviousSuspendCount);
610  if (!NT_SUCCESS(Status))
611  {
613  return -1;
614  }
615 
616  return PreviousSuspendCount;
617 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtSuspendThread(IN HANDLE ThreadHandle, OUT PULONG PreviousSuspendCount OPTIONAL)
Definition: state.c:352
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
HANDLE hThread
Definition: wizard.c:27
unsigned int ULONG
Definition: retypes.h:1

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

◆ SwitchToThread()

BOOL WINAPI SwitchToThread ( VOID  )

Definition at line 410 of file thread.c.

411 {
413 }
#define STATUS_NO_YIELD_PERFORMED
Definition: ntstatus.h:150
NTSTATUS NTAPI NtYieldExecution(VOID)
Definition: thrdschd.c:744

Referenced by _Init_thread_header(), and DoWaitForReaders().

◆ TerminateThread()

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

Definition at line 549 of file thread.c.

551 {
553 #if DBG
554  PRTL_CRITICAL_SECTION LoaderLock;
556 #endif /* DBG */
557 
558  /* Check for invalid thread handle */
559  if (!hThread)
560  {
561  /* Fail if one was passed */
563  return FALSE;
564  }
565 
566 #if DBG
567  /* Get the loader lock */
568  LoaderLock = NtCurrentPeb()->LoaderLock;
569  if (LoaderLock)
570  {
571  /* Get our TID */
574  &ThreadInfo,
575  sizeof(ThreadInfo),
576  NULL);
577  if (NT_SUCCESS(Status))
578  {
579  /* If terminating the current thread, we must not hold the loader lock */
580  if (NtCurrentTeb()->ClientId.UniqueThread == ThreadInfo.ClientId.UniqueThread)
582  }
583  }
584 #endif /* DBG */
585 
586  /* Now terminate the thread */
587  Status = NtTerminateThread(hThread, dwExitCode);
588  if (!NT_SUCCESS(Status))
589  {
590  /* Fail */
592  return FALSE;
593  }
594 
595  /* All done */
596  return TRUE;
597 }
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
struct _ThreadInfo ThreadInfo
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
Definition: kill.c:1278
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2450
HANDLE UniqueThread
Definition: compat.h:475
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define NtCurrentPeb()
Definition: FLS.c:19
HANDLE hThread
Definition: wizard.c:27

Referenced by do_test(), DP_DestroyDirectPlay2(), main(), nfs41_session_free(), NotifyTopLevelWindow(), NotifyUserProcessForShutdown(), BtrfsSend::SendDlgProc(), test_bsc_marshaling(), test_CreateThread_basic(), test_CreateThread_suspended(), test_ExitProcess(), 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 1023 of file thread.c.

1024 {
1025  ULONG Index;
1026  PTEB Teb;
1027  PPEB Peb;
1028 
1029  /* Get the PEB and TEB, lock the PEB */
1030  Teb = NtCurrentTeb();
1033 
1034  /* Try to get regular TEB slot */
1036  if (Index != 0xFFFFFFFF)
1037  {
1038  /* Clear the value. */
1039  Teb->TlsSlots[Index] = 0;
1041  return Index;
1042  }
1043 
1044  /* If it fails, try to find expansion TEB slot. */
1046  if (Index != 0xFFFFFFFF)
1047  {
1048  /* Is there no expansion slot yet? */
1049  if (!Teb->TlsExpansionSlots)
1050  {
1051  /* Allocate an array */
1052  Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1055  sizeof(PVOID));
1056  }
1057 
1058  /* Did we get an array? */
1059  if (!Teb->TlsExpansionSlots)
1060  {
1061  /* Fail */
1063  Index = 0xFFFFFFFF;
1065  }
1066  else
1067  {
1068  /* Clear the value. */
1069  Teb->TlsExpansionSlots[Index] = 0;
1071  }
1072  }
1073  else
1074  {
1075  /* Fail */
1077  }
1078 
1079  /* Release the lock and return */
1081  return Index;
1082 }
PRTL_BITMAP TlsExpansionBitmap
Definition: winternl.h:346
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
PPEB Peb
Definition: dllmain.c:27
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
#define TLS_EXPANSION_SLOTS
Definition: pstypes.h:294
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
static const UCHAR Index[8]
Definition: usbohci.c:18
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
unsigned int ULONG
Definition: retypes.h:1
PVOID TlsSlots[64]
Definition: compat.h:528
PVOID * TlsExpansionSlots
Definition: compat.h:543
PVOID TlsBitmap
Definition: ntddk_ex.h:259
#define TLS_MINIMUM_AVAILABLE
Definition: ntddk_ex.h:236

Referenced by __nc_error(), __rpc_createerr(), __rpc_getconfip(), CMenuFocusManager::AcquireManager(), ClientThreadSetupHelper(), COMDLG32_SetCommDlgExtendedError(), DllMain(), get_thread_data(), get_tls_data(), I_CryptAllocTls(), Init(), msvcrt_init_tls(), spy_init(), test_CreateThread_basic(), test_reserved_tls(), test_TLS(), and wined3d_dll_init().

◆ TlsFree()

BOOL WINAPI TlsFree ( IN DWORD  Index)

Definition at line 1089 of file thread.c.

1090 {
1091  BOOL BitSet;
1092  PPEB Peb;
1093  ULONG TlsIndex;
1094  PVOID TlsBitmap;
1095  NTSTATUS Status;
1096 
1097  /* Acquire the PEB lock and grab the PEB */
1098  Peb = NtCurrentPeb();
1100 
1101  /* Check if the index is too high */
1103  {
1104  /* Check if it can fit in the expansion slots */
1107  {
1108  /* It's invalid */
1111  return FALSE;
1112  }
1113  else
1114  {
1115  /* Use the expansion bitmap */
1116  TlsBitmap = Peb->TlsExpansionBitmap;
1117  Index = TlsIndex;
1118  }
1119  }
1120  else
1121  {
1122  /* Use the normal bitmap */
1123  TlsBitmap = Peb->TlsBitmap;
1124  }
1125 
1126  /* Check if the index was set */
1127  BitSet = RtlAreBitsSet(TlsBitmap, Index, 1);
1128  if (BitSet)
1129  {
1130  /* Tell the kernel to free the TLS cells */
1133  &Index,
1134  sizeof(DWORD));
1135  if (!NT_SUCCESS(Status))
1136  {
1139  return FALSE;
1140  }
1141 
1142  /* Clear the bit */
1143  RtlClearBits(TlsBitmap, Index, 1);
1144  }
1145  else
1146  {
1147  /* Fail */
1150  return FALSE;
1151  }
1152 
1153  /* Done! */
1155  return TRUE;
1156 }
PRTL_BITMAP TlsExpansionBitmap
Definition: winternl.h:346
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
#define TRUE
Definition: types.h:120
PPEB Peb
Definition: dllmain.c:27
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define TLS_EXPANSION_SLOTS
Definition: pstypes.h:294
LONG NTSTATUS
Definition: precomp.h:26
#define NtCurrentThread()
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:1967
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TlsIndex
Definition: ws2_32p.h:277
Status
Definition: gdiplustypes.h:24
NTSYSAPI BOOLEAN WINAPI RtlAreBitsSet(PCRTL_BITMAP, ULONG, ULONG)
#define NtCurrentPeb()
Definition: FLS.c:19
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
unsigned int ULONG
Definition: retypes.h:1
PVOID TlsBitmap
Definition: ntddk_ex.h:259
#define TLS_MINIMUM_AVAILABLE
Definition: ntddk_ex.h:236

Referenced by Cleanup(), ClientThreadSetupHelper(), DllMain(), Exit(), free_tls_list(), get_thread_data(), get_tls_data(), I_CryptFreeTls(), msvcrt_free_tls(), process_detach(), spy_init(), test_CreateThread_basic(), test_reserved_tls(), test_TLS(), wined3d_dll_destroy(), wined3d_dll_init(), and xmlCleanupThreads().

◆ TlsGetValue()

LPVOID WINAPI TlsGetValue ( IN DWORD  Index)

Definition at line 1163 of file thread.c.

1164 {
1165  PTEB Teb;
1166 
1167  /* Get the TEB and clear the last error */
1168  Teb = NtCurrentTeb();
1169  Teb->LastErrorValue = 0;
1170 
1171  /* Check for simple TLS index */
1173  {
1174  /* Return it */
1175  return Teb->TlsSlots[Index];
1176  }
1177 
1178  /* Check for valid index */
1180  {
1181  /* Fail */
1183  return NULL;
1184  }
1185 
1186  /* The expansion slots are allocated on demand, so check for it. */
1187  Teb->LastErrorValue = 0;
1188  if (!Teb->TlsExpansionSlots) return NULL;
1189 
1190  /* Return the value from the expansion slots */
1192 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define TLS_EXPANSION_SLOTS
Definition: pstypes.h:294
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
ULONG LastErrorValue
Definition: compat.h:492
PVOID TlsSlots[64]
Definition: compat.h:528
PVOID * TlsExpansionSlots
Definition: compat.h:543
#define TLS_MINIMUM_AVAILABLE
Definition: ntddk_ex.h:236

Referenced by __mingwthr_run_key_dtors(), add_active_textservice(), client_stop(), CommDlgExtendedError(), context_get_current(), detach_thread(), DllMain(), enum_locales_proc(), event_client(), get_indent_level(), get_thread_data(), get_tls_data(), CMenuFocusManager::GetManager(), I_CryptDetachTls(), I_CryptGetTls(), INTERNET_GetLastError(), INTERNET_GetResponseBuffer(), INTERNET_SetLastError(), INTERNET_WorkerThreadFunc(), InternetGetLastResponseInfoA(), InternetGetLastResponseInfoW(), msvcrt_free_tls_mem(), msvcrt_get_thread_data(), oob_client(), oob_server(), select_server(), server_stop(), SHGetThreadRef(), simple_client(), simple_mixed_client(), simple_server(), test_reserved_tls(), test_TLS(), TF_GetThreadMgr(), ThreadFocusHookProc(), threadFunc1(), ThreadMgr_Constructor(), VirtualChannelInit(), WsSockInitialize(), WsThreadBlockingCallback(), WsThreadDestroyCurrentThread(), WsThreadGetCurrentThread(), WsThreadGetThreadId(), and xmlGetGlobalState().

◆ TlsSetValue()

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

Definition at line 1199 of file thread.c.

1201 {
1202  DWORD TlsIndex;
1203  PTEB Teb = NtCurrentTeb();
1204 
1205  /* Check for simple TLS index */
1207  {
1208  /* Return it */
1209  Teb->TlsSlots[Index] = Value;
1210  return TRUE;
1211  }
1212 
1213  /* Check if this is an expansion slot */
1216  {
1217  /* Fail */
1219  return FALSE;
1220  }
1221 
1222  /* Do we not have expansion slots? */
1223  if (!Teb->TlsExpansionSlots)
1224  {
1225  /* Get the PEB lock to see if we still need them */
1227  if (!Teb->TlsExpansionSlots)
1228  {
1229  /* Allocate them */
1230  Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1233  sizeof(PVOID));
1234  if (!Teb->TlsExpansionSlots)
1235  {
1236  /* Fail */
1239  return FALSE;
1240  }
1241  }
1242 
1243  /* Release the lock */
1245  }
1246 
1247  /* Write the value */
1249 
1250  /* Success */
1251  return TRUE;
1252 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define TLS_EXPANSION_SLOTS
Definition: pstypes.h:294
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TlsIndex
Definition: ws2_32p.h:277
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
PVOID TlsSlots[64]
Definition: compat.h:528
PVOID * TlsExpansionSlots
Definition: compat.h:543
#define TLS_MINIMUM_AVAILABLE
Definition: ntddk_ex.h:236

Referenced by CMenuFocusManager::AcquireManager(), client_start(), COMDLG32_SetCommDlgExtendedError(), context_destroy(), context_set_current(), DllMain(), EnumRfc1766_create(), get_thread_data(), get_tls_data(), I_CryptDetachTls(), I_CryptSetTls(), INTERNET_AllocThreadError(), INTERNET_WorkerThreadFunc(), msvcrt_get_thread_data(), CMenuFocusManager::ReleaseManager(), server_start(), set_indent_level(), SHSetThreadRef(), test_reserved_tls(), test_TLS(), threadFunc1(), ThreadMgr_Constructor(), ThreadMgr_Destructor(), WsThreadCreate(), WsThreadDelete(), WsThreadDestroyCurrentThread(), and xmlGetGlobalState().