ReactOS  0.4.13-dev-249-gcba1a2f
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 14 of file thread.c.

◆ SXS_SUPPORT_FIXME

#define SXS_SUPPORT_FIXME

Definition at line 17 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

◆ __declspec()

__declspec ( noreturn  )

Definition at line 28 of file thread.c.

33 {
34  /* Attempt to call the Thread Start Address */
35  _SEH2_TRY
36  {
37  /* Legacy check which is still used today for Win32 threads */
38  if (NtCurrentTeb()->NtTib.Version == (30 << 8)) // OS/2 V3.0 ("Cruiser")
39  {
40  /* This registers the termination port with CSRSS */
42  }
43 
44  /* Get the exit code from the Thread Start */
45  ExitThread((lpStartAddress)((PVOID)lpParameter));
46  }
48  {
49  /* Get the Exit code from the SEH Handler */
51  {
52  /* Kill the whole process, usually */
54  }
55  else
56  {
57  /* If running inside CSRSS, kill just this thread */
59  }
60  }
61  _SEH2_END;
62 }
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:326
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 66 of file thread.c.

69 {
70  RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActivationFrame;
71 
72  /* Setup the activation context */
73  ActivationFrame.Size = sizeof(ActivationFrame);
75 
76  /* Check if caller wanted one */
77  if (ActivationContext == INVALID_ACTIVATION_CONTEXT)
78  {
79  /* Do the APC directly */
81  return;
82  }
83 
84  /* Then activate it */
85  RtlActivateActivationContextUnsafeFast(&ActivationFrame, ActivationContext);
86 
87  /* Call the routine under SEH */
88  _SEH2_TRY
89  {
91  }
93  {
94 
95  }
96  _SEH2_END;
97 
98  /* Now de-activate and release the activation context */
100  RtlReleaseActivationContext(ActivationContext);
101 }
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:2745

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

140 {
142  INITIAL_TEB InitialTeb;
145  OBJECT_ATTRIBUTES LocalObjectAttributes;
147  HANDLE hThread;
148  ULONG Dummy;
149  PTEB Teb;
150  THREAD_BASIC_INFORMATION ThreadBasicInfo;
151  PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL;
152  ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
155  SIZE_T ReturnSize;
156  DPRINT("CreateRemoteThread: hProcess: %p dwStackSize: %lu lpStartAddress"
157  ": %p lpParameter: %p, dwCreationFlags: %lx\n", hProcess,
158  dwStackSize, lpStartAddress, lpParameter, dwCreationFlags);
159 
160  /* Clear the Context */
161  RtlZeroMemory(&Context, sizeof(CONTEXT));
162 
163  /* Write PID */
165 
166  /* Create the Stack */
168  dwStackSize,
169  dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION ?
170  dwStackSize : 0,
171  &InitialTeb);
172  if (!NT_SUCCESS(Status))
173  {
175  return NULL;
176  }
177 
178  /* Create Initial Context */
180  lpParameter,
181  lpStartAddress,
182  InitialTeb.StackBase,
183  1);
184 
185  /* initialize the attributes for the thread object */
186  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
187  lpThreadAttributes,
188  NULL);
189 
190  /* Create the Kernel Thread Object */
194  hProcess,
195  &ClientId,
196  &Context,
197  &InitialTeb,
198  TRUE);
199  if (!NT_SUCCESS(Status))
200  {
201  /* Fail the kernel create */
202  BaseFreeThreadStack(hProcess, &InitialTeb);
204  return NULL;
205  }
206 
207  /* Are we in the same process? */
208  if (hProcess == NtCurrentProcess())
209  {
210  /* Get the TEB */
213  &ThreadBasicInfo,
214  sizeof(ThreadBasicInfo),
215  &ReturnLength);
216  if (!NT_SUCCESS(Status))
217  {
218  /* Fail */
219  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
220  "NtQueryInformationThread() failed with status %08lx\n",
222  return NULL;
223  }
224 
225  /* Allocate the Activation Context Stack */
226  Status = RtlAllocateActivationContextStack(&ActivationContextStack);
227  if (!NT_SUCCESS(Status))
228  {
229  /* Fail */
230  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
231  "RtlAllocateActivationContextStack() failed with status %08lx\n",
233  return NULL;
234  }
235 
236  /* Save it */
237  Teb = ThreadBasicInfo.TebBaseAddress;
238  Teb->ActivationContextStackPointer = ActivationContextStack;
239 
240  /* Query the Context */
242  NULL,
243  0,
244  ActivationContextBasicInformation,
245  &ActCtxInfo,
246  sizeof(ActCtxInfo),
247  &ReturnSize);
248  if (!NT_SUCCESS(Status))
249  {
250  /* Fail */
251  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
252  "RtlQueryInformationActivationContext() failed with status %08lx\n",
254 
255  /* Free the activation context stack */
256  // RtlFreeThreadActivationContextStack();
258 
259  return NULL;
260  }
261 
262  /* Does it need to be activated? */
263  if ((ActCtxInfo.hActCtx) && !(ActCtxInfo.dwFlags & 1))
264  {
265  /* Activate it */
267  Teb,
268  ActCtxInfo.hActCtx,
269  &Cookie);
270  if (!NT_SUCCESS(Status))
271  {
272  /* Fail */
273  ERROR_DBGBREAK("SXS: %s - Failing thread create because "
274  "RtlActivateActivationContextEx() failed with status %08lx\n",
276 
277  /* Free the activation context stack */
278  // RtlFreeThreadActivationContextStack();
280 
281  return NULL;
282  }
283  }
284  }
285 
286  /* Notify CSR */
288  {
291  }
292  else
293  {
294  if (hProcess != NtCurrentProcess())
295  {
297 
298  /* Get the direct CSRSRV export */
301  "CsrCreateRemoteThread");
303  {
304  /* Call it instead of going through LPC */
307  }
308  }
309  }
310 
311  /* Success */
312  if (lpThreadId) *lpThreadId = HandleToUlong(ClientId.UniqueThread);
313 
314  /* Resume it if asked */
315  if (!(dwCreationFlags & CREATE_SUSPENDED)) NtResumeThread(hThread, &Dummy);
316 
317  /* Return handle to thread */
318  return hThread;
319 }
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:19
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 111 of file thread.c.

117 {
118  /* Act as if we're going to create a remote thread in ourselves */
120  lpThreadAttributes,
121  dwStackSize,
122  lpStartAddress,
123  lpParameter,
124  dwCreationFlags,
125  lpThreadId);
126 }
#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:133

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

327 {
330  PRTL_CRITICAL_SECTION LoaderLock;
331 
332  /* Make sure loader lock isn't held */
333  LoaderLock = NtCurrentPeb()->LoaderLock;
334  if (LoaderLock) ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
335 
336  /*
337  * Terminate process if this is the last thread
338  * of the current process
339  */
342  &LastThread,
343  sizeof(LastThread),
344  NULL);
345  if ((NT_SUCCESS(Status)) && (LastThread)) ExitProcess(uExitCode);
346 
347  /* Notify DLLs and TLS Callbacks of termination */
349 
350  /* Tell the Kernel to free the Stack */
351  NtCurrentTeb()->FreeStackOnTermination = TRUE;
352  NtTerminateThread(NULL, uExitCode);
353 
354  /* We should never reach this place */
355  ERROR_FATAL("It should not happen\n");
356  while (TRUE); /* 'noreturn' function */
357 }
#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 420 of file thread.c.

421 {
423 }
#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 502 of file thread.c.

504 {
505  THREAD_BASIC_INFORMATION ThreadBasic;
507 
510  &ThreadBasic,
511  sizeof(THREAD_BASIC_INFORMATION),
512  NULL);
513  if (!NT_SUCCESS(Status))
514  {
516  return FALSE;
517  }
518 
519  *lpExitCode = ThreadBasic.ExitStatus;
520  return TRUE;
521 }
#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 850 of file thread.c.

851 {
852  THREAD_BASIC_INFORMATION ThreadBasic;
854 
857  &ThreadBasic,
858  sizeof(THREAD_BASIC_INFORMATION),
859  NULL);
860  if (!NT_SUCCESS(Status))
861  {
863  return 0;
864  }
865 
866  return HandleToUlong(ThreadBasic.ClientId.UniqueProcess);
867 }
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 399 of file thread.c.

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

◆ GetThreadContext()

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

Definition at line 462 of file thread.c.

464 {
466 
467  Status = NtGetContextThread(hThread, lpContext);
468  if (!NT_SUCCESS(Status))
469  {
471  return FALSE;
472  }
473 
474  return TRUE;
475 }
#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 874 of file thread.c.

875 {
876  THREAD_BASIC_INFORMATION ThreadBasic;
878 
881  &ThreadBasic,
882  sizeof(THREAD_BASIC_INFORMATION),
883  NULL);
884  if (!NT_SUCCESS(Status))
885  {
887  return 0;
888  }
889 
890  return HandleToUlong(ThreadBasic.ClientId.UniqueThread);
891 }
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 997 of file thread.c.

999 {
1000  ULONG IoPending;
1001  NTSTATUS Status;
1002 
1003  /* Query the flag */
1006  &IoPending,
1007  sizeof(IoPending),
1008  NULL);
1009  if (NT_SUCCESS(Status))
1010  {
1011  /* Return the flag */
1012  *lpIOIsPending = IoPending ? TRUE : FALSE;
1013  return TRUE;
1014  }
1015 
1016  /* Fail */
1018  return FALSE;
1019 }
#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 700 of file thread.c.

701 {
702  THREAD_BASIC_INFORMATION ThreadBasic;
704 
705  /* Query the Base Priority Increment */
708  &ThreadBasic,
709  sizeof(THREAD_BASIC_INFORMATION),
710  NULL);
711  if (!NT_SUCCESS(Status))
712  {
713  /* Failure */
716  }
717 
718  /* Do some conversions for saturation values */
719  if (ThreadBasic.BasePriority == ((HIGH_PRIORITY + 1) / 2))
720  {
721  /* Win32 calls this "time critical" */
723  }
724  else if (ThreadBasic.BasePriority == -((HIGH_PRIORITY + 1) / 2))
725  {
726  /* Win32 calls this "idle" */
727  ThreadBasic.BasePriority = THREAD_PRIORITY_IDLE;
728  }
729 
730  /* Return the final result */
731  return ThreadBasic.BasePriority;
732 }
#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 739 of file thread.c.

741 {
744 
747  &PriorityBoost,
748  sizeof(ULONG),
749  NULL);
750  if (!NT_SUCCESS(Status))
751  {
753  return FALSE;
754  }
755 
756  *pDisablePriorityBoost = PriorityBoost;
757  return TRUE;
758 }
#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 791 of file thread.c.

794 {
795 #ifdef _M_IX86
796  DESCRIPTOR_TABLE_ENTRY DescriptionTableEntry;
798 
799  /* Set the selector and do the query */
800  DescriptionTableEntry.Selector = dwSelector;
803  &DescriptionTableEntry,
804  sizeof(DESCRIPTOR_TABLE_ENTRY),
805  NULL);
806  if (!NT_SUCCESS(Status))
807  {
808  /* Fail */
810  return FALSE;
811  }
812 
813  /* Success, return the selector */
814  *lpSelectorEntry = DescriptionTableEntry.Descriptor;
815  return TRUE;
816 #else
817  DPRINT1("Calling GetThreadSelectorEntry!\n");
818  return FALSE;
819 #endif
820 }
#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 430 of file thread.c.

435 {
436  KERNEL_USER_TIMES KernelUserTimes;
438 
440  ThreadTimes,
441  &KernelUserTimes,
442  sizeof(KERNEL_USER_TIMES),
443  NULL);
444  if (!NT_SUCCESS(Status))
445  {
447  return FALSE;
448  }
449 
450  *lpCreationTime = *(LPFILETIME)&KernelUserTimes.CreateTime;
451  *lpExitTime = *(LPFILETIME)&KernelUserTimes.ExitTime;
452  *lpKernelTime = *(LPFILETIME)&KernelUserTimes.KernelTime;
453  *lpUserTime = *(LPFILETIME)&KernelUserTimes.UserTime;
454  return TRUE;
455 }
#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 364 of file thread.c.

367 {
369  HANDLE ThreadHandle;
372 
375 
377  NULL,
378  (bInheritHandle ? OBJ_INHERIT : 0),
379  NULL,
380  NULL);
381 
382  Status = NtOpenThread(&ThreadHandle,
383  dwDesiredAccess,
385  &ClientId);
386  if (!NT_SUCCESS(Status))
387  {
389  return NULL;
390  }
391 
392  return ThreadHandle;
393 }
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 909 of file thread.c.

912 {
914  ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
915 
916  /* Zero the activation context and query information on it */
917  RtlZeroMemory(&ActCtxInfo, sizeof(ActCtxInfo));
919  NULL,
920  0,
921  ActivationContextBasicInformation,
922  &ActCtxInfo,
923  sizeof(ActCtxInfo),
924  NULL);
925  if (!NT_SUCCESS(Status))
926  {
927  /* Fail due to SxS */
928  DbgPrint("SXS: %s failing because RtlQueryInformationActivationContext()"
929  "returned status %08lx\n", __FUNCTION__, Status);
931  return FALSE;
932  }
933 
934  /* Queue the APC */
937  pfnAPC,
938  (PVOID)dwData,
939  (ActCtxInfo.dwFlags & 1) ?
940  INVALID_ACTIVATION_CONTEXT : ActCtxInfo.hActCtx);
941  if (!NT_SUCCESS(Status))
942  {
944  return FALSE;
945  }
946 
947  /* All good */
948  return TRUE;
949 }
#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:66
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 1026 of file thread.c.

1029 {
1030  NTSTATUS Status;
1031 
1032  /* NOTE: Rtl needs to safely call the function using a trampoline */
1034  if (!NT_SUCCESS(Status))
1035  {
1036  /* Failed */
1038  return FALSE;
1039  }
1040 
1041  /* All good */
1042  return TRUE;
1043 }
#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 528 of file thread.c.

529 {
530  ULONG PreviousResumeCount;
532 
533  Status = NtResumeThread(hThread, &PreviousResumeCount);
534  if (!NT_SUCCESS(Status))
535  {
537  return -1;
538  }
539 
540  return PreviousResumeCount;
541 }
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 623 of file thread.c.

625 {
626  THREAD_BASIC_INFORMATION ThreadBasic;
627  KAFFINITY AffinityMask;
629 
630  AffinityMask = (KAFFINITY)dwThreadAffinityMask;
631 
634  &ThreadBasic,
635  sizeof(THREAD_BASIC_INFORMATION),
636  NULL);
637  if (!NT_SUCCESS(Status))
638  {
640  return 0;
641  }
642 
645  &AffinityMask,
646  sizeof(KAFFINITY));
647  if (!NT_SUCCESS(Status))
648  {
650  ThreadBasic.AffinityMask = 0;
651  }
652 
653  return ThreadBasic.AffinityMask;
654 }
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 482 of file thread.c.

484 {
486 
487  Status = NtSetContextThread(hThread, (PCONTEXT)lpContext);
488  if (!NT_SUCCESS(Status))
489  {
491  return FALSE;
492  }
493 
494  return TRUE;
495 }
#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 827 of file thread.c.

829 {
831 
834  &dwIdealProcessor,
835  sizeof(ULONG));
836  if (!NT_SUCCESS(Status))
837  {
839  return -1;
840  }
841 
842  return (DWORD)Status;
843 }
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 661 of file thread.c.

663 {
664  LONG Prio = nPriority;
666 
667  /* Check if values forcing saturation should be used */
668  if (Prio == THREAD_PRIORITY_TIME_CRITICAL)
669  {
670  /* This is 16 */
671  Prio = (HIGH_PRIORITY + 1) / 2;
672  }
673  else if (Prio == THREAD_PRIORITY_IDLE)
674  {
675  /* This is -16 */
676  Prio = -((HIGH_PRIORITY + 1) / 2);
677  }
678 
679  /* Set the Base Priority */
682  &Prio,
683  sizeof(LONG));
684  if (!NT_SUCCESS(Status))
685  {
686  /* Failure */
688  return FALSE;
689  }
690 
691  /* Return */
692  return TRUE;
693 }
#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 765 of file thread.c.

767 {
770 
771  PriorityBoost = bDisablePriorityBoost != FALSE;
772 
775  &PriorityBoost,
776  sizeof(ULONG));
777  if (!NT_SUCCESS(Status))
778  {
780  return FALSE;
781  }
782 
783  return TRUE;
784 }
#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 956 of file thread.c.

957 {
958  PTEB Teb = NtCurrentTeb();
959  ULONG GuaranteedStackBytes;
961 
962  if (!StackSizeInBytes)
963  {
965  return FALSE;
966  }
967 
968  AllocationSize = *StackSizeInBytes;
969 
970  /* Retrieve the current stack size */
971  GuaranteedStackBytes = Teb->GuaranteedStackBytes;
972 
973  /* Return the size of the previous stack */
974  *StackSizeInBytes = GuaranteedStackBytes;
975 
976  /*
977  * If the new stack size is either zero or is less than the current size,
978  * the previous stack size is returned and we return success.
979  */
980  if ((AllocationSize == 0) || (AllocationSize < GuaranteedStackBytes))
981  {
982  return TRUE;
983  }
984 
985  // FIXME: Unimplemented!
987 
988  // Temporary HACK for supporting applications!
989  return TRUE; // FALSE;
990 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define UNIMPLEMENTED_ONCE
Definition: debug.h:138
#define TRUE
Definition: types.h:120
#define SetLastError(x)
Definition: compat.h:409
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
unsigned int ULONG
Definition: retypes.h:1

◆ SetThreadUILanguage()

LANGID WINAPI SetThreadUILanguage ( IN LANGID  LangId)

Definition at line 898 of file thread.c.

899 {
901  return (LANGID)NtCurrentTeb()->CurrentLocale;
902 }
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 603 of file thread.c.

604 {
605  ULONG PreviousSuspendCount;
607 
608  Status = NtSuspendThread(hThread, &PreviousSuspendCount);
609  if (!NT_SUCCESS(Status))
610  {
612  return -1;
613  }
614 
615  return PreviousSuspendCount;
616 }
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 409 of file thread.c.

410 {
412 }
#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 548 of file thread.c.

550 {
552 #if DBG
553  PRTL_CRITICAL_SECTION LoaderLock;
555 #endif /* DBG */
556 
557  /* Check for invalid thread handle */
558  if (!hThread)
559  {
560  /* Fail if one was passed */
562  return FALSE;
563  }
564 
565 #if DBG
566  /* Get the loader lock */
567  LoaderLock = NtCurrentPeb()->LoaderLock;
568  if (LoaderLock)
569  {
570  /* Get our TID */
573  &ThreadInfo,
574  sizeof(ThreadInfo),
575  NULL);
576  if (NT_SUCCESS(Status))
577  {
578  /* If terminating the current thread, we must not hold the loader lock */
579  if (NtCurrentTeb()->ClientId.UniqueThread == ThreadInfo.ClientId.UniqueThread)
581  }
582  }
583 #endif /* DBG */
584 
585  /* Now terminate the thread */
586  Status = NtTerminateThread(hThread, dwExitCode);
587  if (!NT_SUCCESS(Status))
588  {
589  /* Fail */
591  return FALSE;
592  }
593 
594  /* All done */
595  return TRUE;
596 }
#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 1050 of file thread.c.

1051 {
1052  ULONG Index;
1053  PTEB Teb;
1054  PPEB Peb;
1055 
1056  /* Get the PEB and TEB, lock the PEB */
1057  Teb = NtCurrentTeb();
1060 
1061  /* Try to get regular TEB slot */
1063  if (Index != 0xFFFFFFFF)
1064  {
1065  /* Clear the value. */
1066  Teb->TlsSlots[Index] = 0;
1068  return Index;
1069  }
1070 
1071  /* If it fails, try to find expansion TEB slot. */
1073  if (Index != 0xFFFFFFFF)
1074  {
1075  /* Is there no expansion slot yet? */
1076  if (!Teb->TlsExpansionSlots)
1077  {
1078  /* Allocate an array */
1079  Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1082  sizeof(PVOID));
1083  }
1084 
1085  /* Did we get an array? */
1086  if (!Teb->TlsExpansionSlots)
1087  {
1088  /* Fail */
1090  Index = 0xFFFFFFFF;
1092  }
1093  else
1094  {
1095  /* Clear the value. */
1096  Teb->TlsExpansionSlots[Index] = 0;
1098  }
1099  }
1100  else
1101  {
1102  /* Fail */
1104  }
1105 
1106  /* Release the lock and return */
1108  return Index;
1109 }
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 1116 of file thread.c.

1117 {
1118  BOOL BitSet;
1119  PPEB Peb;
1120  ULONG TlsIndex;
1121  PVOID TlsBitmap;
1122  NTSTATUS Status;
1123 
1124  /* Acquire the PEB lock and grab the PEB */
1125  Peb = NtCurrentPeb();
1127 
1128  /* Check if the index is too high */
1130  {
1131  /* Check if it can fit in the expansion slots */
1134  {
1135  /* It's invalid */
1138  return FALSE;
1139  }
1140  else
1141  {
1142  /* Use the expansion bitmap */
1143  TlsBitmap = Peb->TlsExpansionBitmap;
1144  Index = TlsIndex;
1145  }
1146  }
1147  else
1148  {
1149  /* Use the normal bitmap */
1150  TlsBitmap = Peb->TlsBitmap;
1151  }
1152 
1153  /* Check if the index was set */
1154  BitSet = RtlAreBitsSet(TlsBitmap, Index, 1);
1155  if (BitSet)
1156  {
1157  /* Tell the kernel to free the TLS cells */
1160  &Index,
1161  sizeof(DWORD));
1162  if (!NT_SUCCESS(Status))
1163  {
1166  return FALSE;
1167  }
1168 
1169  /* Clear the bit */
1170  RtlClearBits(TlsBitmap, Index, 1);
1171  }
1172  else
1173  {
1174  /* Fail */
1177  return FALSE;
1178  }
1179 
1180  /* Done! */
1182  return TRUE;
1183 }
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 1190 of file thread.c.

1191 {
1192  PTEB Teb;
1193 
1194  /* Get the TEB and clear the last error */
1195  Teb = NtCurrentTeb();
1196  Teb->LastErrorValue = 0;
1197 
1198  /* Check for simple TLS index */
1200  {
1201  /* Return it */
1202  return Teb->TlsSlots[Index];
1203  }
1204 
1205  /* Check for valid index */
1207  {
1208  /* Fail */
1210  return NULL;
1211  }
1212 
1213  /* The expansion slots are allocated on demand, so check for it. */
1214  Teb->LastErrorValue = 0;
1215  if (!Teb->TlsExpansionSlots) return NULL;
1216 
1217  /* Return the value from the expansion slots */
1219 }
#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 1226 of file thread.c.

1228 {
1229  DWORD TlsIndex;
1230  PTEB Teb = NtCurrentTeb();
1231 
1232  /* Check for simple TLS index */
1234  {
1235  /* Return it */
1236  Teb->TlsSlots[Index] = Value;
1237  return TRUE;
1238  }
1239 
1240  /* Check if this is an expansion slot */
1243  {
1244  /* Fail */
1246  return FALSE;
1247  }
1248 
1249  /* Do we not have expansion slots? */
1250  if (!Teb->TlsExpansionSlots)
1251  {
1252  /* Get the PEB lock to see if we still need them */
1254  if (!Teb->TlsExpansionSlots)
1255  {
1256  /* Allocate them */
1257  Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1260  sizeof(PVOID));
1261  if (!Teb->TlsExpansionSlots)
1262  {
1263  /* Fail */
1266  return FALSE;
1267  }
1268  }
1269 
1270  /* Release the lock */
1272  }
1273 
1274  /* Write the value */
1276 
1277  /* Success */
1278  return TRUE;
1279 }
_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().