1 // process.hpp --------------------------------------------------------------//
3 // Copyright 2016 Klemens D. Morgenstern
4 // Copyright 2016 Andrey Semashev
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
9 #ifndef BOOST_DETAIL_WINAPI_PROCESS_HPP_
10 #define BOOST_DETAIL_WINAPI_PROCESS_HPP_
12 #include <boost/detail/winapi/config.hpp>
13 #include <boost/detail/winapi/basic_types.hpp>
14 #include <boost/detail/winapi/access_rights.hpp>
15 #include <boost/detail/winapi/get_current_process.hpp>
16 #include <boost/detail/winapi/get_current_process_id.hpp>
17 #include <boost/predef/platform.h>
19 #ifdef BOOST_HAS_PRAGMA_ONCE
23 #if BOOST_PLAT_WINDOWS_DESKTOP
25 #if !defined( BOOST_USE_WINDOWS_H )
28 struct _PROCESS_INFORMATION;
29 #if !defined( BOOST_NO_ANSI_APIS )
34 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
35 struct _PROC_THREAD_ATTRIBUTE_LIST;
36 #if !defined( BOOST_NO_ANSI_APIS )
37 struct _STARTUPINFOEXA;
39 struct _STARTUPINFOEXW;
42 BOOST_SYMBOL_IMPORT BOOST_NORETURN boost::detail::winapi::VOID_ WINAPI
43 ExitProcess(boost::detail::winapi::UINT_ uExitCode);
45 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI TerminateProcess(
46 boost::detail::winapi::HANDLE_ hProcess,
47 boost::detail::winapi::UINT_ uExitCode);
49 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI GetExitCodeProcess(
50 boost::detail::winapi::HANDLE_ hProcess,
51 boost::detail::winapi::LPDWORD_ lpExitCode);
53 #if !defined( BOOST_NO_ANSI_APIS )
54 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI CreateProcessA(
55 boost::detail::winapi::LPCSTR_ lpApplicationName,
56 boost::detail::winapi::LPSTR_ lpCommandLine,
57 ::_SECURITY_ATTRIBUTES* lpProcessAttributes,
58 ::_SECURITY_ATTRIBUTES* lpThreadAttributes,
59 boost::detail::winapi::INT_ bInheritHandles,
60 boost::detail::winapi::DWORD_ dwCreationFlags,
61 boost::detail::winapi::LPVOID_ lpEnvironment,
62 boost::detail::winapi::LPCSTR_ lpCurrentDirectory,
63 ::_STARTUPINFOA* lpStartupInfo,
64 ::_PROCESS_INFORMATION* lpProcessInformation);
67 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI CreateProcessW(
68 boost::detail::winapi::LPCWSTR_ lpApplicationName,
69 boost::detail::winapi::LPWSTR_ lpCommandLine,
70 ::_SECURITY_ATTRIBUTES* lpProcessAttributes,
71 ::_SECURITY_ATTRIBUTES* lpThreadAttributes,
72 boost::detail::winapi::INT_ bInheritHandles,
73 boost::detail::winapi::DWORD_ dwCreationFlags,
74 boost::detail::winapi::LPVOID_ lpEnvironment,
75 boost::detail::winapi::LPCWSTR_ lpCurrentDirectory,
76 ::_STARTUPINFOW* lpStartupInfo,
77 ::_PROCESS_INFORMATION* lpProcessInformation);
79 BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI OpenProcess(
80 boost::detail::winapi::DWORD_ dwDesiredAccess,
81 boost::detail::winapi::BOOL_ bInheritHandle,
82 boost::detail::winapi::DWORD_ dwProcessId);
85 #endif //defined BOOST_WINDOWS_H
91 #if defined( BOOST_USE_WINDOWS_H )
93 const DWORD_ DEBUG_PROCESS_ = DEBUG_PROCESS;
94 const DWORD_ DEBUG_ONLY_THIS_PROCESS_ = DEBUG_ONLY_THIS_PROCESS;
95 const DWORD_ CREATE_SUSPENDED_ = CREATE_SUSPENDED;
96 const DWORD_ DETACHED_PROCESS_ = DETACHED_PROCESS;
97 const DWORD_ CREATE_NEW_CONSOLE_ = CREATE_NEW_CONSOLE;
98 const DWORD_ CREATE_NEW_PROCESS_GROUP_ = CREATE_NEW_PROCESS_GROUP;
99 const DWORD_ CREATE_UNICODE_ENVIRONMENT_ = CREATE_UNICODE_ENVIRONMENT;
100 const DWORD_ CREATE_SEPARATE_WOW_VDM_ = CREATE_SEPARATE_WOW_VDM;
101 const DWORD_ CREATE_SHARED_WOW_VDM_ = CREATE_SHARED_WOW_VDM;
102 const DWORD_ CREATE_FORCEDOS_ = CREATE_FORCEDOS;
103 const DWORD_ CREATE_BREAKAWAY_FROM_JOB_ = CREATE_BREAKAWAY_FROM_JOB;
104 const DWORD_ CREATE_DEFAULT_ERROR_MODE_ = CREATE_DEFAULT_ERROR_MODE;
105 const DWORD_ CREATE_NO_WINDOW_ = CREATE_NO_WINDOW;
108 const DWORD_ PROFILE_USER_ = PROFILE_USER;
109 const DWORD_ PROFILE_KERNEL_ = PROFILE_KERNEL;
110 const DWORD_ PROFILE_SERVER_ = PROFILE_SERVER;
112 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
113 const DWORD_ CREATE_PROTECTED_PROCESS_ = CREATE_PROTECTED_PROCESS;
114 const DWORD_ EXTENDED_STARTUPINFO_PRESENT_ = EXTENDED_STARTUPINFO_PRESENT;
117 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN7
118 const DWORD_ INHERIT_PARENT_AFFINITY_ = INHERIT_PARENT_AFFINITY;
121 // Only documented for Windows CE
122 #if defined(UNDER_CE)
123 const DWORD_ INHERIT_CALLER_PRIORITY_ = INHERIT_CALLER_PRIORITY;
126 const DWORD_ STARTF_USESHOWWINDOW_ = STARTF_USESHOWWINDOW;
127 const DWORD_ STARTF_USESIZE_ = STARTF_USESIZE;
128 const DWORD_ STARTF_USEPOSITION_ = STARTF_USEPOSITION;
129 const DWORD_ STARTF_USECOUNTCHARS_ = STARTF_USECOUNTCHARS;
130 const DWORD_ STARTF_USEFILLATTRIBUTE_ = STARTF_USEFILLATTRIBUTE;
131 const DWORD_ STARTF_RUNFULLSCREEN_ = STARTF_RUNFULLSCREEN;
132 const DWORD_ STARTF_FORCEONFEEDBACK_ = STARTF_FORCEONFEEDBACK;
133 const DWORD_ STARTF_FORCEOFFFEEDBACK_ = STARTF_FORCEOFFFEEDBACK;
134 const DWORD_ STARTF_USESTDHANDLES_ = STARTF_USESTDHANDLES;
135 const DWORD_ STARTF_USEHOTKEY_ = STARTF_USEHOTKEY;
137 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN7
138 const DWORD_ STARTF_TITLEISLINKNAME_ = STARTF_TITLEISLINKNAME;
139 const DWORD_ STARTF_TITLEISAPPID_ = STARTF_TITLEISAPPID;
140 const DWORD_ STARTF_PREVENTPINNING_ = STARTF_PREVENTPINNING;
143 const DWORD_ PROCESS_TERMINATE_ = PROCESS_TERMINATE;
144 const DWORD_ PROCESS_CREATE_THREAD_ = PROCESS_CREATE_THREAD;
145 const DWORD_ PROCESS_SET_SESSIONID_ = PROCESS_SET_SESSIONID;
146 const DWORD_ PROCESS_VM_OPERATION_ = PROCESS_VM_OPERATION;
147 const DWORD_ PROCESS_VM_READ_ = PROCESS_VM_READ;
148 const DWORD_ PROCESS_VM_WRITE_ = PROCESS_VM_WRITE;
149 const DWORD_ PROCESS_DUP_HANDLE_ = PROCESS_DUP_HANDLE;
150 const DWORD_ PROCESS_CREATE_PROCESS_ = PROCESS_CREATE_PROCESS;
151 const DWORD_ PROCESS_SET_QUOTA_ = PROCESS_SET_QUOTA;
152 const DWORD_ PROCESS_SET_INFORMATION_ = PROCESS_SET_INFORMATION;
153 const DWORD_ PROCESS_QUERY_INFORMATION_ = PROCESS_QUERY_INFORMATION;
154 const DWORD_ PROCESS_SUSPEND_RESUME_ = PROCESS_SUSPEND_RESUME;
155 const DWORD_ PROCESS_ALL_ACCESS_ = PROCESS_ALL_ACCESS;
157 #else // defined( BOOST_USE_WINDOWS_H )
159 const DWORD_ DEBUG_PROCESS_ = 0x1;
160 const DWORD_ DEBUG_ONLY_THIS_PROCESS_ = 0x2;
161 const DWORD_ CREATE_SUSPENDED_ = 0x4;
162 const DWORD_ DETACHED_PROCESS_ = 0x8;
163 const DWORD_ CREATE_NEW_CONSOLE_ = 0x10;
164 const DWORD_ CREATE_NEW_PROCESS_GROUP_ = 0x200;
165 const DWORD_ CREATE_UNICODE_ENVIRONMENT_ = 0x400;
166 const DWORD_ CREATE_SEPARATE_WOW_VDM_ = 0x800;
167 const DWORD_ CREATE_SHARED_WOW_VDM_ = 0x1000;
168 const DWORD_ CREATE_FORCEDOS_ = 0x2000;
169 const DWORD_ CREATE_BREAKAWAY_FROM_JOB_ = 0x1000000;
170 const DWORD_ CREATE_DEFAULT_ERROR_MODE_ = 0x4000000;
171 const DWORD_ CREATE_NO_WINDOW_ = 0x8000000;
174 const DWORD_ PROFILE_USER_ = 0x10000000;
175 const DWORD_ PROFILE_KERNEL_ = 0x20000000;
176 const DWORD_ PROFILE_SERVER_ = 0x40000000;
178 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
179 const DWORD_ CREATE_PROTECTED_PROCESS_ = 0x40000;
180 const DWORD_ EXTENDED_STARTUPINFO_PRESENT_ = 0x80000;
183 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN7
184 const DWORD_ INHERIT_PARENT_AFFINITY_ = 0x10000;
187 // Only documented for Windows CE
188 #if defined(UNDER_CE)
189 const DWORD_ INHERIT_CALLER_PRIORITY_ = 0x20000;
192 const DWORD_ STARTF_USESHOWWINDOW_ = 0x00000001;
193 const DWORD_ STARTF_USESIZE_ = 0x00000002;
194 const DWORD_ STARTF_USEPOSITION_ = 0x00000004;
195 const DWORD_ STARTF_USECOUNTCHARS_ = 0x00000008;
196 const DWORD_ STARTF_USEFILLATTRIBUTE_ = 0x00000010;
197 const DWORD_ STARTF_RUNFULLSCREEN_ = 0x00000020;
198 const DWORD_ STARTF_FORCEONFEEDBACK_ = 0x00000040;
199 const DWORD_ STARTF_FORCEOFFFEEDBACK_ = 0x00000080;
200 const DWORD_ STARTF_USESTDHANDLES_ = 0x00000100;
201 const DWORD_ STARTF_USEHOTKEY_ = 0x00000200;
203 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN7
204 const DWORD_ STARTF_TITLEISLINKNAME_ = 0x00000800;
205 const DWORD_ STARTF_TITLEISAPPID_ = 0x00001000;
206 const DWORD_ STARTF_PREVENTPINNING_ = 0x00002000;
209 const DWORD_ PROCESS_TERMINATE_ = 0x0001;
210 const DWORD_ PROCESS_CREATE_THREAD_ = 0x0002;
211 const DWORD_ PROCESS_SET_SESSIONID_ = 0x0004;
212 const DWORD_ PROCESS_VM_OPERATION_ = 0x0008;
213 const DWORD_ PROCESS_VM_READ_ = 0x0010;
214 const DWORD_ PROCESS_VM_WRITE_ = 0x0020;
215 const DWORD_ PROCESS_DUP_HANDLE_ = 0x0040;
216 const DWORD_ PROCESS_CREATE_PROCESS_ = 0x0080;
217 const DWORD_ PROCESS_SET_QUOTA_ = 0x0100;
218 const DWORD_ PROCESS_SET_INFORMATION_ = 0x0200;
219 const DWORD_ PROCESS_QUERY_INFORMATION_ = 0x0400;
220 const DWORD_ PROCESS_SUSPEND_RESUME_ = 0x0800;
221 const DWORD_ PROCESS_ALL_ACCESS_ = (STANDARD_RIGHTS_REQUIRED_ | SYNCHRONIZE_ | 0xFFF);
223 #endif // defined( BOOST_USE_WINDOWS_H )
225 #if defined( BOOST_USE_WINDOWS_H ) && !defined( BOOST_WINAPI_IS_MINGW )
227 const DWORD_ CREATE_PRESERVE_CODE_AUTHZ_LEVEL_ = CREATE_PRESERVE_CODE_AUTHZ_LEVEL;
230 const DWORD_ CREATE_IGNORE_SYSTEM_DEFAULT_ = CREATE_IGNORE_SYSTEM_DEFAULT;
232 #else // defined( BOOST_USE_WINDOWS_H ) && !defined( BOOST_WINAPI_IS_MINGW )
234 const DWORD_ CREATE_PRESERVE_CODE_AUTHZ_LEVEL_ = 0x2000000;
237 const DWORD_ CREATE_IGNORE_SYSTEM_DEFAULT_ = 0x80000000;
239 #endif // defined( BOOST_USE_WINDOWS_H ) && !defined( BOOST_WINAPI_IS_MINGW )
241 typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _PROCESS_INFORMATION {
246 } PROCESS_INFORMATION_, *PPROCESS_INFORMATION_, *LPPROCESS_INFORMATION_;
248 typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _STARTUPINFOA {
257 DWORD_ dwXCountChars;
258 DWORD_ dwYCountChars;
259 DWORD_ dwFillAttribute;
267 } STARTUPINFOA_, *LPSTARTUPINFOA_;
269 typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _STARTUPINFOW {
278 DWORD_ dwXCountChars;
279 DWORD_ dwYCountChars;
280 DWORD_ dwFillAttribute;
288 } STARTUPINFOW_, *LPSTARTUPINFOW_;
290 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
292 typedef struct _PROC_THREAD_ATTRIBUTE_LIST PROC_THREAD_ATTRIBUTE_LIST_, *PPROC_THREAD_ATTRIBUTE_LIST_;
294 #if !defined(BOOST_NO_ANSI_APIS)
295 typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _STARTUPINFOEXA {
296 STARTUPINFOA_ StartupInfo;
297 PPROC_THREAD_ATTRIBUTE_LIST_ lpAttributeList;
298 } STARTUPINFOEXA_, *LPSTARTUPINFOEXA_;
299 #endif //BOOST_NO_ANSI_APIS
301 typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS _STARTUPINFOEXW {
302 STARTUPINFOW_ StartupInfo;
303 PPROC_THREAD_ATTRIBUTE_LIST_ lpAttributeList;
304 } STARTUPINFOEXW_, *LPSTARTUPINFOEXW_;
306 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
308 using ::GetExitCodeProcess;
310 using ::TerminateProcess;
313 #if !defined( BOOST_NO_ANSI_APIS )
314 BOOST_FORCEINLINE BOOL_ CreateProcessA(
315 LPCSTR_ lpApplicationName,
316 LPSTR_ lpCommandLine,
317 LPSECURITY_ATTRIBUTES_ lpProcessAttributes,
318 LPSECURITY_ATTRIBUTES_ lpThreadAttributes,
319 INT_ bInheritHandles,
320 DWORD_ dwCreationFlags,
321 LPVOID_ lpEnvironment,
322 LPCSTR_ lpCurrentDirectory,
323 LPSTARTUPINFOA_ lpStartupInfo,
324 LPPROCESS_INFORMATION_ lpProcessInformation)
326 return ::CreateProcessA(
329 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpProcessAttributes),
330 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpThreadAttributes),
335 reinterpret_cast< ::_STARTUPINFOA* >(lpStartupInfo),
336 reinterpret_cast< ::_PROCESS_INFORMATION* >(lpProcessInformation));
339 BOOST_FORCEINLINE BOOL_ create_process(
340 LPCSTR_ lpApplicationName,
341 LPSTR_ lpCommandLine,
342 LPSECURITY_ATTRIBUTES_ lpProcessAttributes,
343 LPSECURITY_ATTRIBUTES_ lpThreadAttributes,
344 INT_ bInheritHandles,
345 DWORD_ dwCreationFlags,
346 LPVOID_ lpEnvironment,
347 LPCSTR_ lpCurrentDirectory,
348 LPSTARTUPINFOA_ lpStartupInfo,
349 LPPROCESS_INFORMATION_ lpProcessInformation)
351 return ::CreateProcessA(
354 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpProcessAttributes),
355 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpThreadAttributes),
360 reinterpret_cast< ::_STARTUPINFOA* >(lpStartupInfo),
361 reinterpret_cast< ::_PROCESS_INFORMATION* >(lpProcessInformation));
365 BOOST_FORCEINLINE BOOL_ CreateProcessW(
366 LPCWSTR_ lpApplicationName,
367 LPWSTR_ lpCommandLine,
368 LPSECURITY_ATTRIBUTES_ lpProcessAttributes,
369 LPSECURITY_ATTRIBUTES_ lpThreadAttributes,
370 INT_ bInheritHandles,
371 DWORD_ dwCreationFlags,
372 LPVOID_ lpEnvironment,
373 LPCWSTR_ lpCurrentDirectory,
374 LPSTARTUPINFOW_ lpStartupInfo,
375 LPPROCESS_INFORMATION_ lpProcessInformation)
377 return ::CreateProcessW(
380 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpProcessAttributes),
381 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpThreadAttributes),
386 reinterpret_cast< ::_STARTUPINFOW* >(lpStartupInfo),
387 reinterpret_cast< ::_PROCESS_INFORMATION* >(lpProcessInformation));
390 BOOST_FORCEINLINE BOOL_ create_process(
391 LPCWSTR_ lpApplicationName,
392 LPWSTR_ lpCommandLine,
393 LPSECURITY_ATTRIBUTES_ lpProcessAttributes,
394 LPSECURITY_ATTRIBUTES_ lpThreadAttributes,
395 INT_ bInheritHandles,
396 DWORD_ dwCreationFlags,
397 LPVOID_ lpEnvironment,
398 LPCWSTR_ lpCurrentDirectory,
399 LPSTARTUPINFOW_ lpStartupInfo,
400 LPPROCESS_INFORMATION_ lpProcessInformation)
402 return ::CreateProcessW(
405 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpProcessAttributes),
406 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpThreadAttributes),
411 reinterpret_cast< ::_STARTUPINFOW* >(lpStartupInfo),
412 reinterpret_cast< ::_PROCESS_INFORMATION* >(lpProcessInformation));
419 #endif // BOOST_PLAT_WINDOWS_DESKTOP
421 #endif // BOOST_DETAIL_WINAPI_PROCESS_HPP_