jobs.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2016 Klemens D. Morgenstern
  3. *
  4. * Distributed under the Boost Software License, Version 1.0.
  5. * See http://www.boost.org/LICENSE_1_0.txt
  6. */
  7. #ifndef BOOST_WINAPI_JOBS_HPP_INCLUDED_
  8. #define BOOST_WINAPI_JOBS_HPP_INCLUDED_
  9. #include <boost/winapi/config.hpp>
  10. #ifdef BOOST_HAS_PRAGMA_ONCE
  11. #pragma once
  12. #endif
  13. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  14. #include <boost/winapi/basic_types.hpp>
  15. #include <boost/winapi/access_rights.hpp>
  16. #if !defined( BOOST_USE_WINDOWS_H )
  17. extern "C" {
  18. #if !defined( BOOST_NO_ANSI_APIS )
  19. #if BOOST_WINAPI_PARTITION_DESKTOP
  20. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateJobObjectA(
  21. ::_SECURITY_ATTRIBUTES* lpJobAttributes,
  22. boost::winapi::LPCSTR_ lpName);
  23. #endif
  24. #endif
  25. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  26. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateJobObjectW(
  27. ::_SECURITY_ATTRIBUTES* lpJobAttributes,
  28. boost::winapi::LPCWSTR_ lpName);
  29. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC AssignProcessToJobObject(
  30. boost::winapi::HANDLE_ hJob,
  31. boost::winapi::HANDLE_ hProcess);
  32. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WINXP
  33. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC IsProcessInJob(
  34. boost::winapi::HANDLE_ ProcessHandle,
  35. boost::winapi::HANDLE_ JobHandle,
  36. boost::winapi::PBOOL_ Result);
  37. #endif
  38. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC TerminateJobObject(
  39. boost::winapi::HANDLE_ hJob,
  40. boost::winapi::UINT_ uExitCode);
  41. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  42. } // extern "C"
  43. #endif // !defined( BOOST_USE_WINDOWS_H )
  44. // MinGW does not declare OpenJobObjectA/W in headers but exports them from libraries
  45. #if !defined( BOOST_USE_WINDOWS_H ) || defined( BOOST_WINAPI_IS_MINGW )
  46. extern "C" {
  47. #if !defined( BOOST_NO_ANSI_APIS )
  48. #if BOOST_WINAPI_PARTITION_DESKTOP
  49. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC OpenJobObjectA(
  50. boost::winapi::DWORD_ dwDesiredAccess,
  51. boost::winapi::BOOL_ bInheritHandles,
  52. boost::winapi::LPCSTR_ lpName);
  53. #endif
  54. #endif
  55. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  56. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC OpenJobObjectW(
  57. boost::winapi::DWORD_ dwDesiredAccess,
  58. boost::winapi::BOOL_ bInheritHandles,
  59. boost::winapi::LPCWSTR_ lpName);
  60. #endif
  61. } // extern "C"
  62. #endif // !defined( BOOST_USE_WINDOWS_H ) || defined( BOOST_WINAPI_IS_MINGW )
  63. namespace boost {
  64. namespace winapi {
  65. // MinGW does not define job constants
  66. #if defined( BOOST_USE_WINDOWS_H ) && !defined( BOOST_WINAPI_IS_MINGW )
  67. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ASSIGN_PROCESS_ = JOB_OBJECT_ASSIGN_PROCESS;
  68. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_ATTRIBUTES_ = JOB_OBJECT_SET_ATTRIBUTES;
  69. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_QUERY_ = JOB_OBJECT_QUERY;
  70. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_TERMINATE_ = JOB_OBJECT_TERMINATE;
  71. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_SECURITY_ATTRIBUTES_ = JOB_OBJECT_SET_SECURITY_ATTRIBUTES;
  72. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ALL_ACCESS_ = JOB_OBJECT_ALL_ACCESS;
  73. #else
  74. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ASSIGN_PROCESS_ = 0x0001;
  75. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_ATTRIBUTES_ = 0x0002;
  76. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_QUERY_ = 0x0004;
  77. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_TERMINATE_ = 0x0008;
  78. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_SECURITY_ATTRIBUTES_ = 0x0010;
  79. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ALL_ACCESS_ = (STANDARD_RIGHTS_REQUIRED_ | SYNCHRONIZE_ | 0x1F);
  80. #endif
  81. #if BOOST_WINAPI_PARTITION_DESKTOP
  82. #if !defined( BOOST_NO_ANSI_APIS )
  83. BOOST_FORCEINLINE HANDLE_ CreateJobObjectA(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCSTR_ lpName)
  84. {
  85. return ::CreateJobObjectA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  86. }
  87. BOOST_FORCEINLINE HANDLE_ create_job_object(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCSTR_ lpName)
  88. {
  89. return ::CreateJobObjectA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  90. }
  91. using ::OpenJobObjectA;
  92. BOOST_FORCEINLINE HANDLE_ open_job_object(DWORD_ dwDesiredAccess, BOOL_ bInheritHandles, LPCSTR_ lpName)
  93. {
  94. return ::OpenJobObjectA(dwDesiredAccess, bInheritHandles, lpName);
  95. }
  96. #endif // !defined( BOOST_NO_ANSI_APIS )
  97. #endif // BOOST_WINAPI_PARTITION_DESKTOP
  98. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  99. using ::AssignProcessToJobObject;
  100. BOOST_FORCEINLINE HANDLE_ CreateJobObjectW(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCWSTR_ lpName)
  101. {
  102. return ::CreateJobObjectW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  103. }
  104. BOOST_FORCEINLINE HANDLE_ create_job_object(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCWSTR_ lpName)
  105. {
  106. return ::CreateJobObjectW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  107. }
  108. BOOST_FORCEINLINE HANDLE_ open_job_object(DWORD_ dwDesiredAccess, BOOL_ bInheritHandles, LPCWSTR_ lpName)
  109. {
  110. return ::OpenJobObjectW(dwDesiredAccess, bInheritHandles, lpName);
  111. }
  112. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WINXP
  113. using ::IsProcessInJob;
  114. #endif
  115. using ::OpenJobObjectW;
  116. using ::TerminateJobObject;
  117. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  118. } // namespace winapi
  119. } // namespace boost
  120. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  121. #endif // BOOST_WINAPI_JOBS_HPP_INCLUDED_