2 * WinPR: Windows Portable Runtime
3 * Process Thread Functions
5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
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>
36 typedef struct _STARTUPINFOA
48 DWORD dwFillAttribute;
56 } STARTUPINFOA, *LPSTARTUPINFOA;
58 typedef struct _STARTUPINFOW
70 DWORD dwFillAttribute;
78 } STARTUPINFOW, *LPSTARTUPINFOW;
81 typedef STARTUPINFOW STARTUPINFO;
82 typedef LPSTARTUPINFOW LPSTARTUPINFO;
84 typedef STARTUPINFOA STARTUPINFO;
85 typedef LPSTARTUPINFOA LPSTARTUPINFO;
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,
112 LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo,
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,
119 LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
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,
128 LPSTARTUPINFOA lpStartupInfo,
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,
137 LPSTARTUPINFOW lpStartupInfo,
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,
144 LPSTARTUPINFOA lpStartupInfo,
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,
151 LPSTARTUPINFOW lpStartupInfo,
152 LPPROCESS_INFORMATION lpProcessInformation);
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);
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);
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_API HANDLE _GetCurrentProcess(void);
182 WINPR_API DWORD GetCurrentProcessId(void);
184 WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode);
186 /* Process Argument Vector Parsing */
188 WINPR_API LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs);
191 #define CommandLineToArgv CommandLineToArgvW
193 #define CommandLineToArgv CommandLineToArgvA
198 #define CREATE_SUSPENDED 0x00000004
199 #define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
201 WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
202 LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter,
203 DWORD dwCreationFlags, LPDWORD lpThreadId);
205 WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes,
206 SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
207 LPVOID lpParameter, DWORD dwCreationFlags,
210 WINPR_API DECLSPEC_NORETURN VOID ExitThread(DWORD dwExitCode);
211 WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
213 WINPR_API HANDLE _GetCurrentThread(void);
214 WINPR_API DWORD GetCurrentThreadId(void);
216 typedef void (*PAPCFUNC)(ULONG_PTR Parameter);
217 WINPR_API DWORD QueueUserAPC(PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData);
219 WINPR_API DWORD ResumeThread(HANDLE hThread);
220 WINPR_API DWORD SuspendThread(HANDLE hThread);
221 WINPR_API BOOL SwitchToThread(void);
223 WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode);
227 WINPR_API DWORD GetCurrentProcessorNumber(void);
229 /* Thread-Local Storage */
231 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
233 WINPR_API DWORD TlsAlloc(void);
234 WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex);
235 WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
236 WINPR_API BOOL TlsFree(DWORD dwTlsIndex);
241 * GetCurrentProcess / GetCurrentThread cause a conflict on Mac OS X
243 #define _GetCurrentProcess GetCurrentProcess
244 #define _GetCurrentThread GetCurrentThread
248 /* CommandLineToArgvA is not present in the original Windows API, WinPR always exports it */
250 WINPR_API LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs);
252 #if defined(WITH_DEBUG_THREADS)
253 WINPR_API VOID DumpThreadHandles(void);
260 #endif /* WINPR_THREAD_H */