FreeRDP
Loading...
Searching...
No Matches
include/winpr/thread.h
1
20#ifndef WINPR_THREAD_H
21#define WINPR_THREAD_H
22
23#include <winpr/winpr.h>
24#include <winpr/wtypes.h>
25
26#include <winpr/spec.h>
27#include <winpr/handle.h>
28
29#ifdef __cplusplus
30extern "C"
31{
32#endif
33
34#ifndef _WIN32
35
36 typedef struct
37 {
38 DWORD cb;
39 LPSTR lpReserved;
40 LPSTR lpDesktop;
41 LPSTR lpTitle;
42 DWORD dwX;
43 DWORD dwY;
44 DWORD dwXSize;
45 DWORD dwYSize;
46 DWORD dwXCountChars;
47 DWORD dwYCountChars;
48 DWORD dwFillAttribute;
49 DWORD dwFlags;
50 WORD wShowWindow;
51 WORD cbReserved2;
52 LPBYTE lpReserved2;
53 HANDLE hStdInput;
54 HANDLE hStdOutput;
55 HANDLE hStdError;
57
58 typedef struct
59 {
60 DWORD cb;
61 LPWSTR lpReserved;
62 LPWSTR lpDesktop;
63 LPWSTR lpTitle;
64 DWORD dwX;
65 DWORD dwY;
66 DWORD dwXSize;
67 DWORD dwYSize;
68 DWORD dwXCountChars;
69 DWORD dwYCountChars;
70 DWORD dwFillAttribute;
71 DWORD dwFlags;
72 WORD wShowWindow;
73 WORD cbReserved2;
74 LPBYTE lpReserved2;
75 HANDLE hStdInput;
76 HANDLE hStdOutput;
77 HANDLE hStdError;
79
80#ifdef UNICODE
83#else
86#endif
87
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
101
102 /* Process */
103
104#define LOGON_WITH_PROFILE 0x00000001
105#define LOGON_NETCREDENTIALS_ONLY 0x00000002
106#define LOGON_ZERO_PASSWORD_BUFFER 0x80000000
107
108 WINPR_API BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine,
109 LPSECURITY_ATTRIBUTES lpProcessAttributes,
110 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
111 DWORD dwCreationFlags, LPVOID lpEnvironment,
112 LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo,
113 LPPROCESS_INFORMATION lpProcessInformation);
114
115 WINPR_API BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
116 LPSECURITY_ATTRIBUTES lpProcessAttributes,
117 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
118 DWORD dwCreationFlags, LPVOID lpEnvironment,
119 LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
120 LPPROCESS_INFORMATION lpProcessInformation);
121
122 WINPR_API BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName,
123 LPSTR lpCommandLine,
124 LPSECURITY_ATTRIBUTES lpProcessAttributes,
125 LPSECURITY_ATTRIBUTES lpThreadAttributes,
126 BOOL bInheritHandles, DWORD dwCreationFlags,
127 LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
128 LPSTARTUPINFOA lpStartupInfo,
129 LPPROCESS_INFORMATION lpProcessInformation);
130
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,
137 LPSTARTUPINFOW lpStartupInfo,
138 LPPROCESS_INFORMATION lpProcessInformation);
139
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,
144 LPSTARTUPINFOA lpStartupInfo,
145 LPPROCESS_INFORMATION lpProcessInformation);
146
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,
151 LPSTARTUPINFOW lpStartupInfo,
152 LPPROCESS_INFORMATION lpProcessInformation);
153
154 WINPR_API BOOL CreateProcessWithTokenA(HANDLE hToken, DWORD dwLogonFlags,
155 LPCSTR lpApplicationName, LPSTR lpCommandLine,
156 DWORD dwCreationFlags, LPVOID lpEnvironment,
157 LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo,
158 LPPROCESS_INFORMATION lpProcessInformation);
159
160 WINPR_API BOOL CreateProcessWithTokenW(HANDLE hToken, DWORD dwLogonFlags,
161 LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
162 DWORD dwCreationFlags, LPVOID lpEnvironment,
163 LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
164 LPPROCESS_INFORMATION lpProcessInformation);
165
166#ifdef UNICODE
167#define CreateProcess CreateProcessW
168#define CreateProcessAsUser CreateProcessAsUserW
169#define CreateProcessWithLogon CreateProcessWithLogonW
170#define CreateProcessWithToken CreateProcessWithTokenW
171#else
172#define CreateProcess CreateProcessA
173#define CreateProcessAsUser CreateProcessAsUserA
174#define CreateProcessWithLogon CreateProcessWithLogonA
175#define CreateProcessWithToken CreateProcessWithTokenA
176#endif
177
178 DECLSPEC_NORETURN WINPR_API VOID ExitProcess(UINT uExitCode);
179 WINPR_API BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode);
180
181 WINPR_PRAGMA_DIAG_PUSH
182 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
183
184 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
185 WINPR_API HANDLE _GetCurrentProcess(void);
186
187 WINPR_PRAGMA_DIAG_POP
188
189 WINPR_API DWORD GetCurrentProcessId(void);
190
191 WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode);
192
193 /* Process Argument Vector Parsing */
194
195 WINPR_API LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs);
196
197#ifdef UNICODE
198#define CommandLineToArgv CommandLineToArgvW
199#else
200#define CommandLineToArgv CommandLineToArgvA
201#endif
202
203 /* Thread */
204#define THREAD_MODE_BACKGROUND_BEGIN 0x00010000
205#define THREAD_MODE_BACKGROUND_END 0x00020000
212#define THREAD_PRIORITY_ABOVE_NORMAL 1
213#define THREAD_PRIORITY_BELOW_NORMAL -1
214#define THREAD_PRIORITY_HIGHEST 2
215#define THREAD_PRIORITY_IDLE -15
216#define THREAD_PRIORITY_LOWEST -2
217#define THREAD_PRIORITY_NORMAL 0
218#define THREAD_PRIORITY_TIME_CRITICAL 15
229 WINPR_API BOOL SetThreadPriority(HANDLE hThread, int nPriority);
230
231#define CREATE_SUSPENDED 0x00000004
232#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
233
234 WINPR_ATTR_MALLOC(CloseHandle, 1)
235 WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, size_t dwStackSize,
236 LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter,
237 DWORD dwCreationFlags, LPDWORD lpThreadId);
238
239 WINPR_ATTR_MALLOC(CloseHandle, 1)
240 WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes,
241 size_t dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
242 LPVOID lpParameter, DWORD dwCreationFlags,
243 LPDWORD lpThreadId);
244
245 WINPR_API VOID ExitThread(DWORD dwExitCode);
246 WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
247
248 WINPR_PRAGMA_DIAG_PUSH
249 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
250 // NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
251 WINPR_API HANDLE _GetCurrentThread(void);
252 WINPR_PRAGMA_DIAG_POP
253
254 WINPR_API DWORD GetCurrentThreadId(void);
255
256 typedef void (*PAPCFUNC)(ULONG_PTR Parameter);
257 WINPR_API DWORD QueueUserAPC(PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData);
258
259 WINPR_API DWORD ResumeThread(HANDLE hThread);
260 WINPR_API DWORD SuspendThread(HANDLE hThread);
261 WINPR_API BOOL SwitchToThread(void);
262
263 WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode);
264
265 /* Processor */
266
267 WINPR_API DWORD GetCurrentProcessorNumber(void);
268
269 /* Thread-Local Storage */
270
271#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
272
273 WINPR_API DWORD TlsAlloc(void);
274 WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex);
275 WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
276 WINPR_API BOOL TlsFree(DWORD dwTlsIndex);
277
278#else
279
280/*
281 * GetCurrentProcess / GetCurrentThread cause a conflict on Mac OS X
282 */
283WINPR_PRAGMA_DIAG_PUSH
284WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
285
286#define _GetCurrentProcess GetCurrentProcess
287#define _GetCurrentThread GetCurrentThread
288
289WINPR_PRAGMA_DIAG_POP
290
291#endif
292
293 /* CommandLineToArgvA is not present in the original Windows API, WinPR always exports it */
294
295 WINPR_API LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs);
296 WINPR_API VOID DumpThreadHandles(void);
297
298#ifdef __cplusplus
299}
300#endif
301
302#endif /* WINPR_THREAD_H */