jobs.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include <boost/winapi/detail/header.hpp>
  17. #if !defined( BOOST_USE_WINDOWS_H )
  18. extern "C" {
  19. #if !defined( BOOST_NO_ANSI_APIS )
  20. #if BOOST_WINAPI_PARTITION_DESKTOP
  21. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateJobObjectA(
  22. ::_SECURITY_ATTRIBUTES* lpJobAttributes,
  23. boost::winapi::LPCSTR_ lpName);
  24. #endif
  25. #endif
  26. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  27. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateJobObjectW(
  28. ::_SECURITY_ATTRIBUTES* lpJobAttributes,
  29. boost::winapi::LPCWSTR_ lpName);
  30. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC AssignProcessToJobObject(
  31. boost::winapi::HANDLE_ hJob,
  32. boost::winapi::HANDLE_ hProcess);
  33. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WINXP
  34. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC IsProcessInJob(
  35. boost::winapi::HANDLE_ ProcessHandle,
  36. boost::winapi::HANDLE_ JobHandle,
  37. boost::winapi::PBOOL_ Result);
  38. #endif
  39. BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC TerminateJobObject(
  40. boost::winapi::HANDLE_ hJob,
  41. boost::winapi::UINT_ uExitCode);
  42. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  43. } // extern "C"
  44. #endif // !defined( BOOST_USE_WINDOWS_H )
  45. // MinGW does not declare OpenJobObjectA/W in headers but exports them from libraries
  46. #if !defined( BOOST_USE_WINDOWS_H ) || defined( BOOST_WINAPI_IS_MINGW )
  47. extern "C" {
  48. #if !defined( BOOST_NO_ANSI_APIS )
  49. #if BOOST_WINAPI_PARTITION_DESKTOP
  50. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC OpenJobObjectA(
  51. boost::winapi::DWORD_ dwDesiredAccess,
  52. boost::winapi::BOOL_ bInheritHandles,
  53. boost::winapi::LPCSTR_ lpName);
  54. #endif
  55. #endif
  56. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  57. BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC OpenJobObjectW(
  58. boost::winapi::DWORD_ dwDesiredAccess,
  59. boost::winapi::BOOL_ bInheritHandles,
  60. boost::winapi::LPCWSTR_ lpName);
  61. #endif
  62. } // extern "C"
  63. #endif // !defined( BOOST_USE_WINDOWS_H ) || defined( BOOST_WINAPI_IS_MINGW )
  64. namespace boost {
  65. namespace winapi {
  66. // MinGW does not define job constants
  67. #if defined( BOOST_USE_WINDOWS_H ) && !defined( BOOST_WINAPI_IS_MINGW )
  68. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ASSIGN_PROCESS_ = JOB_OBJECT_ASSIGN_PROCESS;
  69. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_ATTRIBUTES_ = JOB_OBJECT_SET_ATTRIBUTES;
  70. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_QUERY_ = JOB_OBJECT_QUERY;
  71. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_TERMINATE_ = JOB_OBJECT_TERMINATE;
  72. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_SECURITY_ATTRIBUTES_ = JOB_OBJECT_SET_SECURITY_ATTRIBUTES;
  73. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ALL_ACCESS_ = JOB_OBJECT_ALL_ACCESS;
  74. #else
  75. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ASSIGN_PROCESS_ = 0x0001;
  76. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_ATTRIBUTES_ = 0x0002;
  77. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_QUERY_ = 0x0004;
  78. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_TERMINATE_ = 0x0008;
  79. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_SET_SECURITY_ATTRIBUTES_ = 0x0010;
  80. BOOST_CONSTEXPR_OR_CONST DWORD_ JOB_OBJECT_ALL_ACCESS_ = (STANDARD_RIGHTS_REQUIRED_ | SYNCHRONIZE_ | 0x1F);
  81. #endif
  82. #if BOOST_WINAPI_PARTITION_DESKTOP
  83. #if !defined( BOOST_NO_ANSI_APIS )
  84. BOOST_FORCEINLINE HANDLE_ CreateJobObjectA(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCSTR_ lpName)
  85. {
  86. return ::CreateJobObjectA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  87. }
  88. BOOST_FORCEINLINE HANDLE_ create_job_object(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCSTR_ lpName)
  89. {
  90. return ::CreateJobObjectA(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  91. }
  92. using ::OpenJobObjectA;
  93. BOOST_FORCEINLINE HANDLE_ open_job_object(DWORD_ dwDesiredAccess, BOOL_ bInheritHandles, LPCSTR_ lpName)
  94. {
  95. return ::OpenJobObjectA(dwDesiredAccess, bInheritHandles, lpName);
  96. }
  97. #endif // !defined( BOOST_NO_ANSI_APIS )
  98. #endif // BOOST_WINAPI_PARTITION_DESKTOP
  99. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  100. using ::AssignProcessToJobObject;
  101. BOOST_FORCEINLINE HANDLE_ CreateJobObjectW(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCWSTR_ lpName)
  102. {
  103. return ::CreateJobObjectW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  104. }
  105. BOOST_FORCEINLINE HANDLE_ create_job_object(LPSECURITY_ATTRIBUTES_ lpJobAttributes, LPCWSTR_ lpName)
  106. {
  107. return ::CreateJobObjectW(reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpJobAttributes), lpName);
  108. }
  109. BOOST_FORCEINLINE HANDLE_ open_job_object(DWORD_ dwDesiredAccess, BOOL_ bInheritHandles, LPCWSTR_ lpName)
  110. {
  111. return ::OpenJobObjectW(dwDesiredAccess, bInheritHandles, lpName);
  112. }
  113. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WINXP
  114. using ::IsProcessInJob;
  115. #endif
  116. using ::OpenJobObjectW;
  117. using ::TerminateJobObject;
  118. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  119. } // namespace winapi
  120. } // namespace boost
  121. #include <boost/winapi/detail/footer.hpp>
  122. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN2K
  123. #endif // BOOST_WINAPI_JOBS_HPP_INCLUDED_