20 #ifndef WINPR_THREAD_H
21 #define WINPR_THREAD_H
23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
26 #include <winpr/spec.h>
27 #include <winpr/handle.h>
48 DWORD dwFillAttribute;
70 DWORD dwFillAttribute;
88 #define STARTF_USESHOWWINDOW 0x00000001
89 #define STARTF_USESIZE 0x00000002
90 #define STARTF_USEPOSITION 0x00000004
91 #define STARTF_USECOUNTCHARS 0x00000008
92 #define STARTF_USEFILLATTRIBUTE 0x00000010
93 #define STARTF_RUNFULLSCREEN 0x00000020
94 #define STARTF_FORCEONFEEDBACK 0x00000040
95 #define STARTF_FORCEOFFFEEDBACK 0x00000080
96 #define STARTF_USESTDHANDLES 0x00000100
97 #define STARTF_USEHOTKEY 0x00000200
98 #define STARTF_TITLEISLINKNAME 0x00000800
99 #define STARTF_TITLEISAPPID 0x00001000
100 #define STARTF_PREVENTPINNING 0x00002000
104 #define LOGON_WITH_PROFILE 0x00000001
105 #define LOGON_NETCREDENTIALS_ONLY 0x00000002
106 #define LOGON_ZERO_PASSWORD_BUFFER 0x80000000
108 WINPR_API BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine,
109 LPSECURITY_ATTRIBUTES lpProcessAttributes,
110 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
111 DWORD dwCreationFlags, LPVOID lpEnvironment,
113 LPPROCESS_INFORMATION lpProcessInformation);
115 WINPR_API BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
116 LPSECURITY_ATTRIBUTES lpProcessAttributes,
117 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
118 DWORD dwCreationFlags, LPVOID lpEnvironment,
120 LPPROCESS_INFORMATION lpProcessInformation);
122 WINPR_API BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName,
124 LPSECURITY_ATTRIBUTES lpProcessAttributes,
125 LPSECURITY_ATTRIBUTES lpThreadAttributes,
126 BOOL bInheritHandles, DWORD dwCreationFlags,
127 LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
129 LPPROCESS_INFORMATION lpProcessInformation);
131 WINPR_API BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName,
132 LPWSTR lpCommandLine,
133 LPSECURITY_ATTRIBUTES lpProcessAttributes,
134 LPSECURITY_ATTRIBUTES lpThreadAttributes,
135 BOOL bInheritHandles, DWORD dwCreationFlags,
136 LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory,
138 LPPROCESS_INFORMATION lpProcessInformation);
140 WINPR_API BOOL CreateProcessWithLogonA(LPCSTR lpUsername, LPCSTR lpDomain, LPCSTR lpPassword,
141 DWORD dwLogonFlags, LPCSTR lpApplicationName,
142 LPSTR lpCommandLine, DWORD dwCreationFlags,
143 LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
145 LPPROCESS_INFORMATION lpProcessInformation);
147 WINPR_API BOOL CreateProcessWithLogonW(LPCWSTR lpUsername, LPCWSTR lpDomain, LPCWSTR lpPassword,
148 DWORD dwLogonFlags, LPCWSTR lpApplicationName,
149 LPWSTR lpCommandLine, DWORD dwCreationFlags,
150 LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory,
152 LPPROCESS_INFORMATION lpProcessInformation);
154 WINPR_API BOOL CreateProcessWithTokenA(HANDLE hToken, DWORD dwLogonFlags,
155 LPCSTR lpApplicationName, LPSTR lpCommandLine,
156 DWORD dwCreationFlags, LPVOID lpEnvironment,
158 LPPROCESS_INFORMATION lpProcessInformation);
160 WINPR_API BOOL CreateProcessWithTokenW(HANDLE hToken, DWORD dwLogonFlags,
161 LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
162 DWORD dwCreationFlags, LPVOID lpEnvironment,
164 LPPROCESS_INFORMATION lpProcessInformation);
167 #define CreateProcess CreateProcessW
168 #define CreateProcessAsUser CreateProcessAsUserW
169 #define CreateProcessWithLogon CreateProcessWithLogonW
170 #define CreateProcessWithToken CreateProcessWithTokenW
172 #define CreateProcess CreateProcessA
173 #define CreateProcessAsUser CreateProcessAsUserA
174 #define CreateProcessWithLogon CreateProcessWithLogonA
175 #define CreateProcessWithToken CreateProcessWithTokenA
178 DECLSPEC_NORETURN WINPR_API VOID ExitProcess(UINT uExitCode);
179 WINPR_API BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode);
181 WINPR_PRAGMA_DIAG_PUSH
182 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
184 WINPR_API HANDLE _GetCurrentProcess(
void);
186 WINPR_PRAGMA_DIAG_POP
188 WINPR_API DWORD GetCurrentProcessId(
void);
190 WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode);
194 WINPR_API LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine,
int* pNumArgs);
197 #define CommandLineToArgv CommandLineToArgvW
199 #define CommandLineToArgv CommandLineToArgvA
203 #define THREAD_MODE_BACKGROUND_BEGIN 0x00010000
204 #define THREAD_MODE_BACKGROUND_END 0x00020000
211 #define THREAD_PRIORITY_ABOVE_NORMAL 1
212 #define THREAD_PRIORITY_BELOW_NORMAL -1
213 #define THREAD_PRIORITY_HIGHEST 2
214 #define THREAD_PRIORITY_IDLE -15
215 #define THREAD_PRIORITY_LOWEST -2
216 #define THREAD_PRIORITY_NORMAL 0
217 #define THREAD_PRIORITY_TIME_CRITICAL 15
228 WINPR_API BOOL SetThreadPriority(HANDLE hThread,
int nPriority);
230 #define CREATE_SUSPENDED 0x00000004
231 #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
233 WINPR_ATTR_MALLOC(CloseHandle, 1)
234 WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,
size_t dwStackSize,
235 LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter,
236 DWORD dwCreationFlags, LPDWORD lpThreadId);
238 WINPR_ATTR_MALLOC(CloseHandle, 1)
239 WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes,
240 size_t dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
241 LPVOID lpParameter, DWORD dwCreationFlags,
244 WINPR_API VOID ExitThread(DWORD dwExitCode);
245 WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
247 WINPR_PRAGMA_DIAG_PUSH
248 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
249 WINPR_API HANDLE _GetCurrentThread(
void);
250 WINPR_PRAGMA_DIAG_POP
252 WINPR_API DWORD GetCurrentThreadId(
void);
254 typedef
void (*PAPCFUNC)(ULONG_PTR Parameter);
255 WINPR_API DWORD QueueUserAPC(PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData);
257 WINPR_API DWORD ResumeThread(HANDLE hThread);
258 WINPR_API DWORD SuspendThread(HANDLE hThread);
259 WINPR_API BOOL SwitchToThread(
void);
261 WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode);
265 WINPR_API DWORD GetCurrentProcessorNumber(
void);
269 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
271 WINPR_API DWORD TlsAlloc(
void);
272 WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex);
273 WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
274 WINPR_API BOOL TlsFree(DWORD dwTlsIndex);
281 WINPR_PRAGMA_DIAG_PUSH
282 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
284 #define _GetCurrentProcess GetCurrentProcess
285 #define _GetCurrentThread GetCurrentThread
287 WINPR_PRAGMA_DIAG_POP
293 WINPR_API LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine,
int* pNumArgs);
294 WINPR_API VOID DumpThreadHandles(
void);