FreeRDP
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
30 extern "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
81  typedef STARTUPINFOW STARTUPINFO;
83 #else
84  typedef STARTUPINFOA STARTUPINFO;
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  WINPR_API HANDLE _GetCurrentProcess(void);
185 
186  WINPR_PRAGMA_DIAG_POP
187 
188  WINPR_API DWORD GetCurrentProcessId(void);
189 
190  WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode);
191 
192  /* Process Argument Vector Parsing */
193 
194  WINPR_API LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs);
195 
196 #ifdef UNICODE
197 #define CommandLineToArgv CommandLineToArgvW
198 #else
199 #define CommandLineToArgv CommandLineToArgvA
200 #endif
201 
202  /* Thread */
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);
229 
230 #define CREATE_SUSPENDED 0x00000004
231 #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
232 
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);
237 
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,
242  LPDWORD lpThreadId);
243 
244  WINPR_API VOID ExitThread(DWORD dwExitCode);
245  WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
246 
247  WINPR_PRAGMA_DIAG_PUSH
248  WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
249  WINPR_API HANDLE _GetCurrentThread(void);
250  WINPR_PRAGMA_DIAG_POP
251 
252  WINPR_API DWORD GetCurrentThreadId(void);
253 
254  typedef void (*PAPCFUNC)(ULONG_PTR Parameter);
255  WINPR_API DWORD QueueUserAPC(PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData);
256 
257  WINPR_API DWORD ResumeThread(HANDLE hThread);
258  WINPR_API DWORD SuspendThread(HANDLE hThread);
259  WINPR_API BOOL SwitchToThread(void);
260 
261  WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode);
262 
263  /* Processor */
264 
265  WINPR_API DWORD GetCurrentProcessorNumber(void);
266 
267  /* Thread-Local Storage */
268 
269 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
270 
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);
275 
276 #else
277 
278 /*
279  * GetCurrentProcess / GetCurrentThread cause a conflict on Mac OS X
280  */
281 WINPR_PRAGMA_DIAG_PUSH
282 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
283 
284 #define _GetCurrentProcess GetCurrentProcess
285 #define _GetCurrentThread GetCurrentThread
286 
287 WINPR_PRAGMA_DIAG_POP
288 
289 #endif
290 
291  /* CommandLineToArgvA is not present in the original Windows API, WinPR always exports it */
292 
293  WINPR_API LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs);
294  WINPR_API VOID DumpThreadHandles(void);
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 
300 #endif /* WINPR_THREAD_H */