ReactOS  0.4.14-dev-583-g2a1ba2c
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 53 of file thread.c.

58 {
59  /* Attempt to call the Thread Start Address */
60  _SEH2_TRY
61  {
62  /* Legacy check which is still used today for Win32 threads */
63  if (NtCurrentTeb()->NtTib.Version == (30 << 8)) // OS/2 V3.0 ("Cruiser")
64  {
65  /* This registers the termination port with CSRSS */
67  }
68 
69  /* Get the exit code from the Thread Start */
70  ExitThread((lpStartAddress)((PVOID)lpParameter));
71  }
73  {
74  /* Get the Exit code from the SEH Handler */
76  {
77  /* Kill the whole process, usually */
79  }
80  else
81  {
82  /* If running inside CSRSS, kill just this thread */
84  }
85  }
86  _SEH2_END;
87 }
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
_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:364
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
LPVOID lpParameter
Definition: kernel32.h:241
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 91 of file thread.c.

94 {
95  RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActivationFrame;
96 
97  /* Setup the activation context */
98  ActivationFrame.Size = sizeof(ActivationFrame);
100 
101  /* Check if caller wanted one */
102  if (ActivationContext == INVALID_ACTIVATION_CONTEXT)
103  {
104  /* Do the APC directly */
106  return;
107  }
108 
109  /* Then activate it */
110  RtlActivateActivationContextUnsafeFast(&ActivationFrame, ActivationContext);
111 
112  /* Call the routine under SEH */
113  _SEH2_TRY
114  {
116  }
118  {
119 
120  }
121  _SEH2_END;
122 
123  /* Now de-activate and release the activation context */
125  RtlReleaseActivationContext(ActivationContext);
126 }
NTSYSAPI void WINAPI RtlReleaseActivationContext(HANDLE)
Definition: actctx.c:5272
_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:5939
_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:5862
#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 25 of file thread.c.

27 {
28  BASE_API_MESSAGE ApiMessage;
29  PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest;
30 
31  DPRINT("BasepNotifyCsrOfThread: Thread: %p, Handle %p\n",
32  ClientId->UniqueThread, ThreadHandle);
33 
34  /* Fill out the request */
35  CreateThreadRequest->ClientId = *ClientId;
36  CreateThreadRequest->ThreadHandle = ThreadHandle;
37 
38  /* Call CSR */
40  NULL,
42  sizeof(*CreateThreadRequest));
43  if (!NT_SUCCESS(ApiMessage.Status))
44  {
45  DPRINT1("Failed to tell CSRSS about new thread: %lx\n", ApiMessage.Status);
46  return ApiMessage.Status;
47  }
48 
49  /* Return Success */
50  return STATUS_SUCCESS;
51 }
BASE_CREATE_THREAD CreateThreadRequest
Definition: basemsg.h:284
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:365
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
union _BASE_API_MESSAGE::@3411 Data
#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:483
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2938

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

165 {
167  INITIAL_TEB InitialTeb;
170  OBJECT_ATTRIBUTES LocalObjectAttributes;
172  HANDLE hThread;
173  ULONG Dummy;
174  PTEB Teb;
175  THREAD_BASIC_INFORMATION ThreadBasicInfo;
176  PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL;
177  ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
180  SIZE_T ReturnSize;
181 
182  DPRINT("CreateRemoteThread: hProcess: %p dwStackSize: %lu lpStartAddress"
183  ": %p lpParameter: %p, dwCreationFlags: %lx\n", hProcess,
184  dwStackSize, lpStartAddress, lpParameter, dwCreationFlags);
185 
186  /* Clear the Context */
187  RtlZeroMemory(&Context, sizeof(Context));
188 
189  /* Write PID */
191 
192  /* Create the Stack */
194  (dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION) ?
195  0 : dwStackSize,
196  (dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION) ?
197  dwStackSize : 0,
198  &InitialTeb);
199  if (!NT_SUCCESS(Status))
200  {
202  return NULL;
203  }
204 
205  /* Create the Initial Context */
207  lpParameter,
208  lpStartAddress,
209  InitialTeb.StackBase,
210  1);
211 
212  /* Initialize the attributes for the thread object */
213  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
214  lpThreadAttributes,
215  NULL);
216 
217  /* Create the Kernel Thread Object */
221  hProcess,
222  &ClientId,
223  &Context,
224  &InitialTeb,
225  TRUE);
226  if (!NT_SUCCESS(Status))
227  {
228  /* Fail the kernel create */
229  BaseFreeThreadStack(hProcess, &InitialTeb);
231  return NULL;
232  }
233 
234  /* Are we in the same process? */
235  if (hProcess == NtCurrentProcess())
236  {
237  /* Get the TEB */
240  &ThreadBasicInfo,
241  sizeof(ThreadBasicInfo),
242  &ReturnLength);
243  if (!NT_SUCCESS(Status))
244  {
245  /* Fail */
246  DPRINT1("SXS: %s - Failing thread create because "
247  "NtQueryInformationThread() failed with status %08lx\n",
249  goto Quit;
250  }
251 
252  /* Allocate the Activation Context Stack */
253  Status = RtlAllocateActivationContextStack(&ActivationContextStack);
254  if (!NT_SUCCESS(Status))
255  {
256  /* Fail */
257  DPRINT1("SXS: %s - Failing thread create because "
258  "RtlAllocateActivationContextStack() failed with status %08lx\n",
260  goto Quit;
261  }
262 
263  /* Save it */
264  Teb = ThreadBasicInfo.TebBaseAddress;
265  Teb->ActivationContextStackPointer = ActivationContextStack;
266 
267  /* Query the Context */
269  NULL,
270  0,
271  ActivationContextBasicInformation,
272  &ActCtxInfo,
273  sizeof(ActCtxInfo),
274  &ReturnSize);
275  if (!NT_SUCCESS(Status))
276  {
277  /* Fail */
278  DPRINT1("SXS: %s - Failing thread create because "
279  "RtlQueryInformationActivationContext() failed with status %08lx\n",
281  goto Quit;
282  }
283 
284  /* Does it need to be activated? */
285  if ((ActCtxInfo.hActCtx) && !(ActCtxInfo.dwFlags & 1))
286  {
287  /* Activate it */
289  Teb,
290  ActCtxInfo.hActCtx,
291  &Cookie);
292  if (!NT_SUCCESS(Status))
293  {
294  /* Fail */
295  DPRINT1("SXS: %s - Failing thread create because "
296  "RtlActivateActivationContextEx() failed with status %08lx\n",
298  goto Quit;
299  }
300  }
301 
302  /* Sync the service tag with the parent thread's one */
303  Teb->SubProcessTag = NtCurrentTeb()->SubProcessTag;
304  }
305 
306  /* Notify CSR */
308  {
310  }
311  else
312  {
313  if (hProcess != NtCurrentProcess())
314  {
316 
317  /* Get the direct CSRSRV export */
320  "CsrCreateRemoteThread");
322  {
323  /* Call it instead of going through LPC */
325  }
326  }
327  }
328 
329 Quit:
330  if (!NT_SUCCESS(Status))
331  {
332  /* Failed to create the thread */
333 
334  /* Free the activation context stack */
335  if (ActivationContextStack)
336  RtlFreeActivationContextStack(ActivationContextStack);
337 
339  // FIXME: Wait for the thread to terminate?
340  BaseFreeThreadStack(hProcess, &InitialTeb);
341  NtClose(hThread);
342 
344  return NULL;
345  }
346 
347  /* Success */
348  if (lpThreadId)
349  *lpThreadId = HandleToUlong(ClientId.UniqueThread);
350 
351  /* Resume the thread if asked */
352  if (!(dwCreationFlags & CREATE_SUSPENDED))
353  NtResumeThread(hThread, &Dummy);
354 
355  /* Return handle to thread */
356  return hThread;
357 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
NTSTATUS WINAPI BaseCreateStack(_In_ HANDLE hProcess, _In_opt_ SIZE_T StackCommit, _In_opt_ SIZE_T StackReserve, _Out_ PINITIAL_TEB InitialTeb)
Definition: utils.c:354
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:513
#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:482
#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
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 NtTerminateThread(IN HANDLE ThreadHandle OPTIONAL, IN NTSTATUS ExitStatus)
Definition: kill.c:1278
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
VOID WINAPI BaseFreeThreadStack(_In_ HANDLE hProcess, _In_ PINITIAL_TEB InitialTeb)
Definition: utils.c:495
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2497
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
HANDLE UniqueThread
Definition: compat.h:483
NTSTATUS NTAPI CsrCreateRemoteThread(IN HANDLE hThread, IN PCLIENT_ID ClientId)
Definition: thredsup.c:568
LPVOID lpParameter
Definition: kernel32.h:241
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
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:492
NTSTATUS WINAPI BasepNotifyCsrOfThread(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId)
Definition: thread.c:25
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
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:5443
HANDLE hThread
Definition: wizard.c:27
#define RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT
Definition: rtltypes.h:116
#define DPRINT1
Definition: precomp.h:8
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:5296
NTSTATUS NTAPI RtlAllocateActivationContextStack(IN PACTIVATION_CONTEXT_STACK *Stack)
Definition: actctx.c:5834
struct tagContext Context
Definition: acpixf.h:1030
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define GetProcAddress(x, y)
Definition: compat.h:418
PVOID ActivationContextStackPointer
Definition: compat.h:511
#define __FUNCTION__
Definition: types.h:112
VOID NTAPI RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack)
Definition: actctx.c:5368

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

142 {
143  /* Act as if we're going to create a remote thread in ourselves */
145  lpThreadAttributes,
146  dwStackSize,
147  lpStartAddress,
148  lpParameter,
149  dwCreationFlags,
150  lpThreadId);
151 }
#define NtCurrentProcess()
Definition: nt_native.h:1657
LPVOID lpParameter
Definition: kernel32.h:241
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:158

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(), 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_IInitializeSpy(), 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_MessageBox_WM_COPY_Test(), test_messages(), test_MultiThreadApartment(), 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 364 of file thread.c.

365 {
368  PRTL_CRITICAL_SECTION LoaderLock;
369 
370  /* Make sure loader lock isn't held */
371  LoaderLock = NtCurrentPeb()->LoaderLock;
372  if (LoaderLock) ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
373 
374  /*
375  * Terminate process if this is the last thread
376  * of the current process
377  */
380  &LastThread,
381  sizeof(LastThread),
382  NULL);
383  if ((NT_SUCCESS(Status)) && (LastThread)) ExitProcess(uExitCode);
384 
385  /* Notify DLLs and TLS Callbacks of termination */
387 
388  /* Tell the Kernel to free the Stack */
389  NtCurrentTeb()->FreeStackOnTermination = TRUE;
390  NtTerminateThread(NULL, uExitCode);
391 
392  /* We should never reach this place */
393  ERROR_FATAL("It should not happen\n");
394  while (TRUE); /* 'noreturn' function */
395 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define NtCurrentThread()
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
#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:2497
HANDLE UniqueThread
Definition: compat.h:483
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:20
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 458 of file thread.c.

459 {
461 }
#define HandleToUlong(h)
Definition: basetsd.h:79
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1176
HANDLE UniqueThread
Definition: compat.h:483
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(), CoRegisterInitializeSpy(), CoRevokeInitializeSpy(), 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_PeekMessage(), 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_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 540 of file thread.c.

542 {
543  THREAD_BASIC_INFORMATION ThreadBasic;
545 
548  &ThreadBasic,
549  sizeof(THREAD_BASIC_INFORMATION),
550  NULL);
551  if (!NT_SUCCESS(Status))
552  {
554  return FALSE;
555  }
556 
557  *lpExitCode = ThreadBasic.ExitStatus;
558  return TRUE;
559 }
#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:2497
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(), NotifyTopLevelWindow(), pattern_fork(), test_CreateRemoteThread(), test_CreateThread_basic(), test_ExitProcess(), test_ffcnMultipleThreads(), test_GetThreadExitCode(), test_MultiThreadApartment(), 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 888 of file thread.c.

889 {
890  THREAD_BASIC_INFORMATION ThreadBasic;
892 
895  &ThreadBasic,
896  sizeof(THREAD_BASIC_INFORMATION),
897  NULL);
898  if (!NT_SUCCESS(Status))
899  {
901  return 0;
902  }
903 
904  return HandleToUlong(ThreadBasic.ClientId.UniqueProcess);
905 }
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToUlong(h)
Definition: basetsd.h:79
HANDLE UniqueProcess
Definition: compat.h:482
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:2497
Status
Definition: gdiplustypes.h:24

Referenced by IMM_GetThreadData().

◆ GetTeb()

PTEB GetTeb ( VOID  )

Definition at line 437 of file thread.c.

438 {
439  return NtCurrentTeb();
440 }
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

◆ GetThreadContext()

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

Definition at line 500 of file thread.c.

502 {
504 
505  Status = NtGetContextThread(hThread, lpContext);
506  if (!NT_SUCCESS(Status))
507  {
509  return FALSE;
510  }
511 
512  return TRUE;
513 }
#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 912 of file thread.c.

913 {
914  THREAD_BASIC_INFORMATION ThreadBasic;
916 
919  &ThreadBasic,
920  sizeof(THREAD_BASIC_INFORMATION),
921  NULL);
922  if (!NT_SUCCESS(Status))
923  {
925  return 0;
926  }
927 
928  return HandleToUlong(ThreadBasic.ClientId.UniqueThread);
929 }
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:2497
HANDLE UniqueThread
Definition: compat.h:483
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 1035 of file thread.c.

1037 {
1038  ULONG IoPending;
1039  NTSTATUS Status;
1040 
1041  /* Query the flag */
1044  &IoPending,
1045  sizeof(IoPending),
1046  NULL);
1047  if (NT_SUCCESS(Status))
1048  {
1049  /* Return the flag */
1050  *lpIOIsPending = IoPending ? TRUE : FALSE;
1051  return TRUE;
1052  }
1053 
1054  /* Fail */
1056  return FALSE;
1057 }
#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:2497
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 738 of file thread.c.

739 {
740  THREAD_BASIC_INFORMATION ThreadBasic;
742 
743  /* Query the Base Priority Increment */
746  &ThreadBasic,
747  sizeof(THREAD_BASIC_INFORMATION),
748  NULL);
749  if (!NT_SUCCESS(Status))
750  {
751  /* Failure */
754  }
755 
756  /* Do some conversions for saturation values */
757  if (ThreadBasic.BasePriority == ((HIGH_PRIORITY + 1) / 2))
758  {
759  /* Win32 calls this "time critical" */
761  }
762  else if (ThreadBasic.BasePriority == -((HIGH_PRIORITY + 1) / 2))
763  {
764  /* Win32 calls this "idle" */
765  ThreadBasic.BasePriority = THREAD_PRIORITY_IDLE;
766  }
767 
768  /* Return the final result */
769  return ThreadBasic.BasePriority;
770 }
#define THREAD_PRIORITY_ERROR_RETURN
Definition: winbase.h:279
LONG NTSTATUS
Definition: precomp.h:26
KPRIORITY BasePriority
Definition: compat.h:589
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:2497
#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 777 of file thread.c.

779 {
782 
785  &PriorityBoost,
786  sizeof(ULONG),
787  NULL);
788  if (!NT_SUCCESS(Status))
789  {
791  return FALSE;
792  }
793 
794  *pDisablePriorityBoost = PriorityBoost;
795  return TRUE;
796 }
#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:2497
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 829 of file thread.c.

832 {
833 #ifdef _M_IX86
834  DESCRIPTOR_TABLE_ENTRY DescriptionTableEntry;
836 
837  /* Set the selector and do the query */
838  DescriptionTableEntry.Selector = dwSelector;
841  &DescriptionTableEntry,
842  sizeof(DESCRIPTOR_TABLE_ENTRY),
843  NULL);
844  if (!NT_SUCCESS(Status))
845  {
846  /* Fail */
848  return FALSE;
849  }
850 
851  /* Success, return the selector */
852  *lpSelectorEntry = DescriptionTableEntry.Descriptor;
853  return TRUE;
854 #else
855  DPRINT1("Calling GetThreadSelectorEntry!\n");
856  return FALSE;
857 #endif
858 }
#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:2497
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 468 of file thread.c.

473 {
474  KERNEL_USER_TIMES KernelUserTimes;
476 
478  ThreadTimes,
479  &KernelUserTimes,
480  sizeof(KERNEL_USER_TIMES),
481  NULL);
482  if (!NT_SUCCESS(Status))
483  {
485  return FALSE;
486  }
487 
488  *lpCreationTime = *(LPFILETIME)&KernelUserTimes.CreateTime;
489  *lpExitTime = *(LPFILETIME)&KernelUserTimes.ExitTime;
490  *lpKernelTime = *(LPFILETIME)&KernelUserTimes.KernelTime;
491  *lpUserTime = *(LPFILETIME)&KernelUserTimes.UserTime;
492  return TRUE;
493 }
#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:2497
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 402 of file thread.c.

405 {
407  HANDLE ThreadHandle;
410 
413 
415  NULL,
416  (bInheritHandle ? OBJ_INHERIT : 0),
417  NULL,
418  NULL);
419 
420  Status = NtOpenThread(&ThreadHandle,
421  dwDesiredAccess,
423  &ClientId);
424  if (!NT_SUCCESS(Status))
425  {
427  return NULL;
428  }
429 
430  return ThreadHandle;
431 }
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:482
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:483
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 947 of file thread.c.

950 {
952  ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
953 
954  /* Zero the activation context and query information on it */
955  RtlZeroMemory(&ActCtxInfo, sizeof(ActCtxInfo));
957  NULL,
958  0,
959  ActivationContextBasicInformation,
960  &ActCtxInfo,
961  sizeof(ActCtxInfo),
962  NULL);
963  if (!NT_SUCCESS(Status))
964  {
965  /* Fail due to SxS */
966  DbgPrint("SXS: %s failing because RtlQueryInformationActivationContext()"
967  "returned status %08lx\n", __FUNCTION__, Status);
969  return FALSE;
970  }
971 
972  /* Queue the APC */
975  pfnAPC,
976  (PVOID)dwData,
977  (ActCtxInfo.dwFlags & 1) ?
978  INVALID_ACTIVATION_CONTEXT : ActCtxInfo.hActCtx);
979  if (!NT_SUCCESS(Status))
980  {
982  return FALSE;
983  }
984 
985  /* All good */
986  return TRUE;
987 }
#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:600
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:91
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG, HANDLE, PVOID, ULONG, PVOID, SIZE_T, SIZE_T *)
Definition: actctx.c:5443
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 1064 of file thread.c.

1067 {
1068  NTSTATUS Status;
1069 
1070  /* NOTE: Rtl needs to safely call the function using a trampoline */
1072  if (!NT_SUCCESS(Status))
1073  {
1074  /* Failed */
1076  return FALSE;
1077  }
1078 
1079  /* All good */
1080  return TRUE;
1081 }
#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 566 of file thread.c.

567 {
568  ULONG PreviousResumeCount;
570 
571  Status = NtResumeThread(hThread, &PreviousResumeCount);
572  if (!NT_SUCCESS(Status))
573  {
575  return -1;
576  }
577 
578  return PreviousResumeCount;
579 }
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 661 of file thread.c.

663 {
664  THREAD_BASIC_INFORMATION ThreadBasic;
665  KAFFINITY AffinityMask;
667 
668  AffinityMask = (KAFFINITY)dwThreadAffinityMask;
669 
672  &ThreadBasic,
673  sizeof(THREAD_BASIC_INFORMATION),
674  NULL);
675  if (!NT_SUCCESS(Status))
676  {
678  return 0;
679  }
680 
683  &AffinityMask,
684  sizeof(KAFFINITY));
685  if (!NT_SUCCESS(Status))
686  {
688  ThreadBasic.AffinityMask = 0;
689  }
690 
691  return ThreadBasic.AffinityMask;
692 }
KAFFINITY AffinityMask
Definition: compat.h:587
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:2014
#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:2497
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 520 of file thread.c.

522 {
524 
525  Status = NtSetContextThread(hThread, (PCONTEXT)lpContext);
526  if (!NT_SUCCESS(Status))
527  {
529  return FALSE;
530  }
531 
532  return TRUE;
533 }
#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 865 of file thread.c.

867 {
869 
872  &dwIdealProcessor,
873  sizeof(ULONG));
874  if (!NT_SUCCESS(Status))
875  {
877  return -1;
878  }
879 
880  return (DWORD)Status;
881 }
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:2014
#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 699 of file thread.c.

701 {
702  LONG Prio = nPriority;
704 
705  /* Check if values forcing saturation should be used */
706  if (Prio == THREAD_PRIORITY_TIME_CRITICAL)
707  {
708  /* This is 16 */
709  Prio = (HIGH_PRIORITY + 1) / 2;
710  }
711  else if (Prio == THREAD_PRIORITY_IDLE)
712  {
713  /* This is -16 */
714  Prio = -((HIGH_PRIORITY + 1) / 2);
715  }
716 
717  /* Set the Base Priority */
720  &Prio,
721  sizeof(LONG));
722  if (!NT_SUCCESS(Status))
723  {
724  /* Failure */
726  return FALSE;
727  }
728 
729  /* Return */
730  return TRUE;
731 }
#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:2014
#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 803 of file thread.c.

805 {
808 
809  PriorityBoost = bDisablePriorityBoost != FALSE;
810 
813  &PriorityBoost,
814  sizeof(ULONG));
815  if (!NT_SUCCESS(Status))
816  {
818  return FALSE;
819  }
820 
821  return TRUE;
822 }
#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:2014
#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 994 of file thread.c.

995 {
996  PTEB Teb = NtCurrentTeb();
997  ULONG GuaranteedStackBytes;
999 
1000  if (!StackSizeInBytes)
1001  {
1003  return FALSE;
1004  }
1005 
1006  AllocationSize = *StackSizeInBytes;
1007 
1008  /* Retrieve the current stack size */
1009  GuaranteedStackBytes = Teb->GuaranteedStackBytes;
1010 
1011  /* Return the size of the previous stack */
1012  *StackSizeInBytes = GuaranteedStackBytes;
1013 
1014  /*
1015  * If the new stack size is either zero or is less than the current size,
1016  * the previous stack size is returned and we return success.
1017  */
1018  if ((AllocationSize == 0) || (AllocationSize < GuaranteedStackBytes))
1019  {
1020  return TRUE;
1021  }
1022 
1023  // FIXME: Unimplemented!
1025 
1026  // Temporary HACK for supporting applications!
1027  return TRUE; // FALSE;
1028 }
#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:417
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
Definition: compat.h:492
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 936 of file thread.c.

937 {
939  return (LANGID)NtCurrentTeb()->CurrentLocale;
940 }
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 641 of file thread.c.

642 {
643  ULONG PreviousSuspendCount;
645 
646  Status = NtSuspendThread(hThread, &PreviousSuspendCount);
647  if (!NT_SUCCESS(Status))
648  {
650  return -1;
651  }
652 
653  return PreviousSuspendCount;
654 }
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 447 of file thread.c.

448 {
450 }
#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 586 of file thread.c.

588 {
590 #if DBG
591  PRTL_CRITICAL_SECTION LoaderLock;
593 #endif /* DBG */
594 
595  /* Check for invalid thread handle */
596  if (!hThread)
597  {
598  /* Fail if one was passed */
600  return FALSE;
601  }
602 
603 #if DBG
604  /* Get the loader lock */
605  LoaderLock = NtCurrentPeb()->LoaderLock;
606  if (LoaderLock)
607  {
608  /* Get our TID */
611  &ThreadInfo,
612  sizeof(ThreadInfo),
613  NULL);
614  if (NT_SUCCESS(Status))
615  {
616  /* If terminating the current thread, we must not hold the loader lock */
617  if (NtCurrentTeb()->ClientId.UniqueThread == ThreadInfo.ClientId.UniqueThread)
619  }
620  }
621 #endif /* DBG */
622 
623  /* Now terminate the thread */
624  Status = NtTerminateThread(hThread, dwExitCode);
625  if (!NT_SUCCESS(Status))
626  {
627  /* Fail */
629  return FALSE;
630  }
631 
632  /* All done */
633  return TRUE;
634 }
#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:417
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2497
HANDLE UniqueThread
Definition: compat.h:483
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:20
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 1088 of file thread.c.

1089 {
1090  ULONG Index;
1091  PTEB Teb;
1092  PPEB Peb;
1093 
1094  /* Get the PEB and TEB, lock the PEB */
1095  Teb = NtCurrentTeb();
1098 
1099  /* Try to get regular TEB slot */
1101  if (Index != 0xFFFFFFFF)
1102  {
1103  /* Clear the value. */
1104  Teb->TlsSlots[Index] = 0;
1106  return Index;
1107  }
1108 
1109  /* If it fails, try to find expansion TEB slot. */
1111  if (Index != 0xFFFFFFFF)
1112  {
1113  /* Is there no expansion slot yet? */
1114  if (!Teb->TlsExpansionSlots)
1115  {
1116  /* Allocate an array */
1117  Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1120  sizeof(PVOID));
1121  }
1122 
1123  /* Did we get an array? */
1124  if (!Teb->TlsExpansionSlots)
1125  {
1126  /* Fail */
1128  Index = 0xFFFFFFFF;
1130  }
1131  else
1132  {
1133  /* Clear the value. */
1134  Teb->TlsExpansionSlots[Index] = 0;
1136  }
1137  }
1138  else
1139  {
1140  /* Fail */
1142  }
1143 
1144  /* Release the lock and return */
1146  return Index;
1147 }
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:588
static const UCHAR Index[8]
Definition: usbohci.c:18
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
Definition: compat.h:492
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:536
PVOID * TlsExpansionSlots
Definition: compat.h:551
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 1154 of file thread.c.

1155 {
1156  BOOL BitSet;
1157  PPEB Peb;
1158  ULONG TlsIndex;
1159  PVOID TlsBitmap;
1160  NTSTATUS Status;
1161 
1162  /* Acquire the PEB lock and grab the PEB */
1163  Peb = NtCurrentPeb();
1165 
1166  /* Check if the index is too high */
1168  {
1169  /* Check if it can fit in the expansion slots */
1172  {
1173  /* It's invalid */
1176  return FALSE;
1177  }
1178  else
1179  {
1180  /* Use the expansion bitmap */
1181  TlsBitmap = Peb->TlsExpansionBitmap;
1182  Index = TlsIndex;
1183  }
1184  }
1185  else
1186  {
1187  /* Use the normal bitmap */
1188  TlsBitmap = Peb->TlsBitmap;
1189  }
1190 
1191  /* Check if the index was set */
1192  BitSet = RtlAreBitsSet(TlsBitmap, Index, 1);
1193  if (BitSet)
1194  {
1195  /* Tell the kernel to free the TLS cells */
1198  &Index,
1199  sizeof(DWORD));
1200  if (!NT_SUCCESS(Status))
1201  {
1204  return FALSE;
1205  }
1206 
1207  /* Clear the bit */
1208  RtlClearBits(TlsBitmap, Index, 1);
1209  }
1210  else
1211  {
1212  /* Fail */
1215  return FALSE;
1216  }
1217 
1218  /* Done! */
1220  return TRUE;
1221 }
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:2014
#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:20
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 1228 of file thread.c.

1229 {
1230  PTEB Teb;
1231 
1232  /* Get the TEB and clear the last error */
1233  Teb = NtCurrentTeb();
1234  Teb->LastErrorValue = 0;
1235 
1236  /* Check for simple TLS index */
1238  {
1239  /* Return it */
1240  return Teb->TlsSlots[Index];
1241  }
1242 
1243  /* Check for valid index */
1245  {
1246  /* Fail */
1248  return NULL;
1249  }
1250 
1251  /* The expansion slots are allocated on demand, so check for it. */
1252  Teb->LastErrorValue = 0;
1253  if (!Teb->TlsExpansionSlots) return NULL;
1254 
1255  /* Return the value from the expansion slots */
1257 }
#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:492
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
ULONG LastErrorValue
Definition: compat.h:500
PVOID TlsSlots[64]
Definition: compat.h:536
PVOID * TlsExpansionSlots
Definition: compat.h:551
#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 1264 of file thread.c.

1266 {
1267  DWORD TlsIndex;
1268  PTEB Teb = NtCurrentTeb();
1269 
1270  /* Check for simple TLS index */
1272  {
1273  /* Return it */
1274  Teb->TlsSlots[Index] = Value;
1275  return TRUE;
1276  }
1277 
1278  /* Check if this is an expansion slot */
1281  {
1282  /* Fail */
1284  return FALSE;
1285  }
1286 
1287  /* Do we not have expansion slots? */
1288  if (!Teb->TlsExpansionSlots)
1289  {
1290  /* Get the PEB lock to see if we still need them */
1292  if (!Teb->TlsExpansionSlots)
1293  {
1294  /* Allocate them */
1295  Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
1298  sizeof(PVOID));
1299  if (!Teb->TlsExpansionSlots)
1300  {
1301  /* Fail */
1304  return FALSE;
1305  }
1306  }
1307 
1308  /* Release the lock */
1310  }
1311 
1312  /* Write the value */
1314 
1315  /* Success */
1316  return TRUE;
1317 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#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:588
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:492
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:536
PVOID * TlsExpansionSlots
Definition: compat.h:551
#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().