File indexing completed on 2025-01-18 09:50:08
0001
0002
0003
0004
0005
0006 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_JOB_WORKAROUND_HPP_
0007 #define BOOST_PROCESS_DETAIL_WINDOWS_JOB_WORKAROUND_HPP_
0008
0009 #include <boost/winapi/config.hpp>
0010 #include <boost/winapi/basic_types.hpp>
0011 #include <boost/winapi/dll.hpp>
0012 #include <boost/winapi/overlapped.hpp>
0013
0014 #if defined( BOOST_USE_WINDOWS_H )
0015 #include <windows.h>
0016 #else
0017 extern "C"
0018 {
0019 BOOST_SYMBOL_IMPORT ::boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateIoCompletionPort(
0020 ::boost::winapi::HANDLE_ FileHandle,
0021 ::boost::winapi::HANDLE_ ExistingCompletionPort,
0022 ::boost::winapi::ULONG_PTR_ CompletionKey,
0023 ::boost::winapi::DWORD_ NumberOfConcurrentThreads
0024 );
0025
0026 BOOST_SYMBOL_IMPORT ::boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC GetQueuedCompletionStatus(
0027 ::boost::winapi::HANDLE_ CompletionPort,
0028 ::boost::winapi::LPDWORD_ lpNumberOfBytes,
0029 ::boost::winapi::ULONG_PTR_ *lpCompletionKey,
0030 _OVERLAPPED **lpOverlapped,
0031 ::boost::winapi::DWORD_ dwMilliseconds
0032 );
0033
0034 }
0035 #endif
0036 namespace boost { namespace process { namespace detail { namespace windows { namespace workaround {
0037
0038 extern "C"
0039 {
0040
0041 struct JOBOBJECT_ASSOCIATE_COMPLETION_PORT_
0042 {
0043 ::boost::winapi::PVOID_ CompletionKey;
0044 ::boost::winapi::HANDLE_ CompletionPort;
0045 };
0046
0047 constexpr static int JOB_OBJECT_MSG_END_OF_JOB_TIME_ = 1;
0048 constexpr static int JOB_OBJECT_MSG_END_OF_PROCESS_TIME_ = 2;
0049 constexpr static int JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT_ = 3;
0050 constexpr static int JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO_ = 4;
0051 constexpr static int JOB_OBJECT_MSG_NEW_PROCESS_ = 6;
0052 constexpr static int JOB_OBJECT_MSG_EXIT_PROCESS_ = 7;
0053 constexpr static int JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS_ = 8;
0054 constexpr static int JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT_ = 9;
0055 constexpr static int JOB_OBJECT_MSG_JOB_MEMORY_LIMIT_ = 10;
0056 constexpr static int JOB_OBJECT_MSG_NOTIFICATION_LIMIT_ = 11;
0057 constexpr static int JOB_OBJECT_MSG_JOB_CYCLE_TIME_LIMIT_ = 12;
0058 constexpr static int JOB_OBJECT_MSG_SILO_TERMINATED_ = 13;
0059
0060 }
0061
0062 BOOST_FORCEINLINE ::boost::winapi::BOOL_ get_queued_completion_status(
0063 ::boost::winapi::HANDLE_ CompletionPort,
0064 ::boost::winapi::LPDWORD_ lpNumberOfBytes,
0065 ::boost::winapi::ULONG_PTR_ *lpCompletionKey,
0066 ::boost::winapi::LPOVERLAPPED_ *lpOverlapped,
0067 ::boost::winapi::DWORD_ dwMilliseconds)
0068 {
0069 return ::GetQueuedCompletionStatus(
0070 CompletionPort,
0071 lpNumberOfBytes,
0072 lpCompletionKey,
0073 reinterpret_cast<::_OVERLAPPED**>(lpOverlapped),
0074 dwMilliseconds);
0075 }
0076
0077 #if defined( BOOST_USE_WINDOWS_H )
0078
0079 constexpr auto static JobObjectExtendedLimitInformation_ = ::JobObjectExtendedLimitInformation;
0080 constexpr auto static JobObjectAssociateCompletionPortInformation_ = ::JobObjectAssociateCompletionPortInformation;
0081 constexpr auto static JobObjectBasicAccountingInformation_ = ::JobObjectBasicAccountingInformation;
0082
0083 using JOBOBJECT_BASIC_LIMIT_INFORMATION_ = ::JOBOBJECT_BASIC_LIMIT_INFORMATION;
0084 using JOBOBJECTINFOCLASS_ = ::JOBOBJECTINFOCLASS;
0085 using IO_COUNTERS_ = ::IO_COUNTERS;
0086 using JOBOBJECT_EXTENDED_LIMIT_INFORMATION_ = ::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
0087 using JOBOBJECT_BASIC_ACCOUNTING_INFORMATION_ = ::JOBOBJECT_BASIC_ACCOUNTING_INFORMATION;
0088
0089 inline ::boost::winapi::BOOL_ query_information_job_object(
0090 ::boost::winapi::HANDLE_ hJob,
0091 JOBOBJECTINFOCLASS_ JobObjectInfoClass,
0092 void * lpJobObjectInfo,
0093 ::boost::winapi::DWORD_ cbJobObjectInfoLength,
0094 ::boost::winapi::DWORD_ *lpReturnLength)
0095 {
0096 return ::QueryInformationJobObject(hJob, JobObjectInfoClass, lpJobObjectInfo, cbJobObjectInfoLength, lpReturnLength);
0097 }
0098
0099 inline ::boost::winapi::BOOL_ set_information_job_object(
0100 ::boost::winapi::HANDLE_ hJob,
0101 JOBOBJECTINFOCLASS_ JobObjectInfoClass,
0102 void * lpJobObjectInfo,
0103 ::boost::winapi::DWORD_ cbJobObjectInfoLength)
0104 {
0105 return ::SetInformationJobObject(hJob, JobObjectInfoClass, lpJobObjectInfo, cbJobObjectInfoLength);
0106 }
0107
0108
0109 #else
0110
0111
0112
0113 extern "C"
0114 {
0115
0116 typedef enum _JOBOBJECTINFOCLASS_
0117 {
0118 JobObjectBasicAccountingInformation_ = 1,
0119 JobObjectBasicLimitInformation_,
0120 JobObjectBasicProcessIdList_,
0121 JobObjectBasicUIRestrictions_,
0122 JobObjectSecurityLimitInformation_,
0123 JobObjectEndOfJobTimeInformation_,
0124 JobObjectAssociateCompletionPortInformation_,
0125 JobObjectBasicAndIoAccountingInformation_,
0126 JobObjectExtendedLimitInformation_,
0127 JobObjectJobSetInformation_,
0128 JobObjectGroupInformation_,
0129 JobObjectNotificationLimitInformation_,
0130 JobObjectLimitViolationInformation_,
0131 JobObjectGroupInformationEx_,
0132 JobObjectCpuRateControlInformation_,
0133 JobObjectCompletionFilter_,
0134 JobObjectCompletionCounter_,
0135 JobObjectReserved1Information_ = 18,
0136 JobObjectReserved2Information_,
0137 JobObjectReserved3Information_,
0138 JobObjectReserved4Information_,
0139 JobObjectReserved5Information_,
0140 JobObjectReserved6Information_,
0141 JobObjectReserved7Information_,
0142 JobObjectReserved8Information_,
0143 MaxJobObjectInfoClass_
0144 } JOBOBJECTINFOCLASS_;
0145
0146 typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION_
0147 {
0148 ::boost::winapi::LARGE_INTEGER_ PerProcessUserTimeLimit;
0149 ::boost::winapi::LARGE_INTEGER_ PerJobUserTimeLimit;
0150 ::boost::winapi::DWORD_ LimitFlags;
0151 ::boost::winapi::SIZE_T_ MinimumWorkingSetSize;
0152 ::boost::winapi::SIZE_T_ MaximumWorkingSetSize;
0153 ::boost::winapi::DWORD_ ActiveProcessLimit;
0154 ::boost::winapi::ULONG_PTR_ Affinity;
0155 ::boost::winapi::DWORD_ PriorityClass;
0156 ::boost::winapi::DWORD_ SchedulingClass;
0157 } JOBOBJECT_BASIC_LIMIT_INFORMATION_;
0158
0159
0160 typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION_ {
0161 ::boost::winapi::LARGE_INTEGER_ TotalUserTime;
0162 ::boost::winapi::LARGE_INTEGER_ TotalKernelTime;
0163 ::boost::winapi::LARGE_INTEGER_ ThisPeriodTotalUserTime;
0164 ::boost::winapi::LARGE_INTEGER_ ThisPeriodTotalKernelTime;
0165 ::boost::winapi::DWORD_ TotalPageFaultCount;
0166 ::boost::winapi::DWORD_ TotalProcesses;
0167 ::boost::winapi::DWORD_ ActiveProcesses;
0168 ::boost::winapi::DWORD_ TotalTerminatedProcesses;
0169 } JOBOBJECT_BASIC_ACCOUNTING_INFORMATION_;
0170
0171 typedef struct _IO_COUNTERS_
0172 {
0173 ::boost::winapi::ULONGLONG_ ReadOperationCount;
0174 ::boost::winapi::ULONGLONG_ WriteOperationCount;
0175 ::boost::winapi::ULONGLONG_ OtherOperationCount;
0176 ::boost::winapi::ULONGLONG_ ReadTransferCount;
0177 ::boost::winapi::ULONGLONG_ WriteTransferCount;
0178 ::boost::winapi::ULONGLONG_ OtherTransferCount;
0179 } IO_COUNTERS_;
0180
0181
0182 typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION_
0183 {
0184 JOBOBJECT_BASIC_LIMIT_INFORMATION_ BasicLimitInformation;
0185 IO_COUNTERS_ IoInfo;
0186 ::boost::winapi::SIZE_T_ ProcessMemoryLimit;
0187 ::boost::winapi::SIZE_T_ JobMemoryLimit;
0188 ::boost::winapi::SIZE_T_ PeakProcessMemoryUsed;
0189 ::boost::winapi::SIZE_T_ PeakJobMemoryUsed;
0190 } JOBOBJECT_EXTENDED_LIMIT_INFORMATION_;
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 typedef ::boost::winapi::BOOL_ (BOOST_WINAPI_WINAPI_CC *query_information_job_object_p)(
0202 ::boost::winapi::HANDLE_,
0203 JOBOBJECTINFOCLASS_,
0204 void *,
0205 ::boost::winapi::DWORD_,
0206 ::boost::winapi::DWORD_ *);
0207
0208
0209 inline ::boost::winapi::BOOL_ query_information_job_object(
0210 ::boost::winapi::HANDLE_ hJob,
0211 JOBOBJECTINFOCLASS_ JobObjectInfoClass,
0212 void *lpJobObjectInfo,
0213 ::boost::winapi::DWORD_ cbJobObjectInfoLength,
0214 ::boost::winapi::DWORD_ *lpReturnLength)
0215 {
0216 static ::boost::winapi::HMODULE_ h = ::boost::winapi::get_module_handle(
0217 L"Kernel32.dll");
0218 static query_information_job_object_p f = reinterpret_cast<query_information_job_object_p>(::boost::winapi::get_proc_address(
0219 h, "QueryInformationJobObject"));
0220
0221 return (*f)(hJob, JobObjectInfoClass, lpJobObjectInfo,
0222 cbJobObjectInfoLength, lpReturnLength);
0223 }
0224
0225
0226
0227
0228
0229
0230
0231
0232 typedef ::boost::winapi::BOOL_ (BOOST_WINAPI_WINAPI_CC *set_information_job_object_p)(
0233 ::boost::winapi::HANDLE_,
0234 JOBOBJECTINFOCLASS_,
0235 void *,
0236 ::boost::winapi::DWORD_);
0237
0238 }
0239
0240 inline ::boost::winapi::BOOL_ set_information_job_object(
0241 ::boost::winapi::HANDLE_ hJob,
0242 JOBOBJECTINFOCLASS_ JobObjectInfoClass,
0243 void *lpJobObjectInfo,
0244 ::boost::winapi::DWORD_ cbJobObjectInfoLength)
0245 {
0246 static ::boost::winapi::HMODULE_ h = ::boost::winapi::get_module_handle(
0247 L"Kernel32.dll");
0248 static set_information_job_object_p f = reinterpret_cast<set_information_job_object_p>(::boost::winapi::get_proc_address(
0249 h, "SetInformationJobObject"));
0250
0251 return (*f)(hJob, JobObjectInfoClass, lpJobObjectInfo,
0252 cbJobObjectInfoLength);
0253 }
0254
0255 #endif
0256
0257 constexpr static ::boost::winapi::DWORD_ JOB_OBJECT_LIMIT_BREAKAWAY_OK_ = 0x00000800;
0258
0259 }}}}}
0260
0261 #endif