File indexing completed on 2025-01-18 09:50:08
0001
0002
0003
0004
0005
0006 #ifndef BOOST_PROCESS_DETAIL_WINDOWS_HANDLE_WORKAROUND_HPP_
0007 #define BOOST_PROCESS_DETAIL_WINDOWS_HANDLE_WORKAROUND_HPP_
0008
0009 #include <boost/winapi/basic_types.hpp>
0010 #include <boost/winapi/dll.hpp>
0011 #include <boost/winapi/access_rights.hpp>
0012
0013
0014 #if defined( BOOST_USE_WINDOWS_H )
0015 #include <winternl.h>
0016 #endif
0017
0018
0019 namespace boost { namespace process { namespace detail { namespace windows { namespace workaround
0020 {
0021
0022
0023 typedef struct _SYSTEM_HANDLE_ENTRY_
0024 {
0025 ::boost::winapi::ULONG_ OwnerPid;
0026 ::boost::winapi::BYTE_ ObjectType;
0027 ::boost::winapi::BYTE_ HandleFlags;
0028 ::boost::winapi::USHORT_ HandleValue;
0029 ::boost::winapi::PVOID_ ObjectPointer;
0030 ::boost::winapi::ULONG_ AccessMask;
0031 } SYSTEM_HANDLE_ENTRY_, *PSYSTEM_HANDLE_ENTRY_;
0032
0033 typedef struct _SYSTEM_HANDLE_INFORMATION_
0034 {
0035 ::boost::winapi::ULONG_ Count;
0036 SYSTEM_HANDLE_ENTRY_ Handle[1];
0037 } SYSTEM_HANDLE_INFORMATION_, *PSYSTEM_HANDLE_INFORMATION_;
0038
0039 #if defined( BOOST_USE_WINDOWS_H )
0040
0041 using UNICODE_STRING_ = ::UNICODE_STRING;
0042 using GENERIC_MAPPING_ = ::GENERIC_MAPPING;
0043 using OBJECT_INFORMATION_CLASS_ = ::OBJECT_INFORMATION_CLASS;
0044
0045 constexpr static OBJECT_INFORMATION_CLASS_ ObjectTypeInformation = ::OBJECT_INFORMATION_CLASS::ObjectTypeInformation;
0046
0047 typedef struct _OBJECT_TYPE_INFORMATION_ {
0048 UNICODE_STRING TypeName;
0049 ULONG TotalNumberOfObjects;
0050 ULONG TotalNumberOfHandles;
0051 ULONG TotalPagedPoolUsage;
0052 ULONG TotalNonPagedPoolUsage;
0053 ULONG TotalNamePoolUsage;
0054 ULONG TotalHandleTableUsage;
0055 ULONG HighWaterNumberOfObjects;
0056 ULONG HighWaterNumberOfHandles;
0057 ULONG HighWaterPagedPoolUsage;
0058 ULONG HighWaterNonPagedPoolUsage;
0059 ULONG HighWaterNamePoolUsage;
0060 ULONG HighWaterHandleTableUsage;
0061 ULONG InvalidAttributes;
0062 GENERIC_MAPPING GenericMapping;
0063 ULONG ValidAccessMask;
0064 BOOLEAN SecurityRequired;
0065 BOOLEAN MaintainHandleCount;
0066 UCHAR TypeIndex;
0067 CHAR ReservedByte;
0068 ULONG PoolType;
0069 ULONG DefaultPagedPoolCharge;
0070 ULONG DefaultNonPagedPoolCharge;
0071 } OBJECT_TYPE_INFORMATION_, *POBJECT_TYPE_INFORMATION_;
0072
0073 #else
0074
0075 typedef enum _OBJECT_INFORMATION_CLASS_
0076 {
0077 ObjectBasicInformation,
0078 ObjectNameInformation,
0079 ObjectTypeInformation,
0080 ObjectAllInformation,
0081 ObjectDataInformation
0082 } OBJECT_INFORMATION_CLASS_, *POBJECT_INFORMATION_CLASS_;
0083
0084 typedef struct _UNICODE_STRING_ {
0085 ::boost::winapi::USHORT_ Length;
0086 ::boost::winapi::USHORT_ MaximumLength;
0087 ::boost::winapi::LPWSTR_ Buffer;
0088 } UNICODE_STRING_, *PUNICODE_STRING_;
0089
0090 typedef struct _GENERIC_MAPPING_ {
0091 ::boost::winapi::ACCESS_MASK_ GenericRead;
0092 ::boost::winapi::ACCESS_MASK_ GenericWrite;
0093 ::boost::winapi::ACCESS_MASK_ GenericExecute;
0094 ::boost::winapi::ACCESS_MASK_ GenericAll;
0095 } GENERIC_MAPPING_;
0096
0097 #endif
0098
0099 typedef struct _OBJECT_BASIC_INFORMATION {
0100 ::boost::winapi::ULONG_ Attributes;
0101 ::boost::winapi::ACCESS_MASK_ GrantedAccess;
0102 ::boost::winapi::ULONG_ HandleCount;
0103 ::boost::winapi::ULONG_ PointerCount;
0104 ::boost::winapi::ULONG_ PagedPoolUsage;
0105 ::boost::winapi::ULONG_ NonPagedPoolUsage;
0106 ::boost::winapi::ULONG_ Reserved[3];
0107 ::boost::winapi::ULONG_ NameInformationLength;
0108 ::boost::winapi::ULONG_ TypeInformationLength;
0109 ::boost::winapi::ULONG_ SecurityDescriptorLength;
0110 ::boost::winapi::LARGE_INTEGER_ CreateTime;
0111 } OBJECT_BASIC_INFORMATION_, *POBJECT_BASIC_INFORMATION_;
0112
0113 typedef struct _OBJECT_NAME_INFORMATION {
0114 UNICODE_STRING_ Name;
0115 } OBJECT_NAME_INFORMATION_, *POBJECT_NAME_INFORMATION_;
0116
0117
0118 #if defined( BOOST_USE_WINDOWS_H )
0119
0120 extern "C"
0121 {
0122
0123 using SYSTEM_INFORMATION_CLASS_ = ::SYSTEM_INFORMATION_CLASS;
0124 constexpr static SYSTEM_INFORMATION_CLASS_ SystemHandleInformation_ = static_cast<SYSTEM_INFORMATION_CLASS_>(16);
0125
0126 inline ::boost::winapi::NTSTATUS_ nt_system_query_information(
0127 SYSTEM_INFORMATION_CLASS SystemInformationClass,
0128 void * SystemInformation,
0129 ::boost::winapi::ULONG_ SystemInformationLength,
0130 ::boost::winapi::PULONG_ ReturnLength)
0131 {
0132 return ::NtQuerySystemInformation(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength);
0133 }
0134
0135 inline ::boost::winapi::NTSTATUS_ nt_query_object(
0136 ::boost::winapi::HANDLE_ Handle,
0137 OBJECT_INFORMATION_CLASS_ ObjectInformationClass,
0138 ::boost::winapi::PVOID_ ObjectInformation,
0139 ::boost::winapi::ULONG_ ObjectInformationLength,
0140 ::boost::winapi::PULONG_ ReturnLength
0141 )
0142 {
0143 return ::NtQueryObject(Handle, ObjectInformationClass, ObjectInformation, ObjectInformationLength, ReturnLength);
0144 }
0145
0146 }
0147
0148 #else
0149
0150
0151
0152 extern "C"
0153 {
0154
0155 typedef enum _SYSTEM_INFORMATION_CLASS_
0156 {
0157 SystemBasicInformation_ = 0,
0158 SystemProcessorInformation_ = 1,
0159 SystemPerformanceInformation_ = 2,
0160 SystemTimeOfDayInformation_ = 3,
0161 SystemProcessInformation_ = 5,
0162 SystemProcessorPerformanceInformation_ = 8,
0163 SystemHandleInformation_ = 16,
0164 SystemPagefileInformation_ = 18,
0165 SystemInterruptInformation_ = 23,
0166 SystemExceptionInformation_ = 33,
0167 SystemRegistryQuotaInformation_ = 37,
0168 SystemLookasideInformation_ = 45
0169 } SYSTEM_INFORMATION_CLASS_;
0170
0171
0172 typedef struct _OBJECT_TYPE_INFORMATION_ {
0173 UNICODE_STRING_ TypeName;
0174 ::boost::winapi::ULONG_ TotalNumberOfObjects;
0175 ::boost::winapi::ULONG_ TotalNumberOfHandles;
0176 ::boost::winapi::ULONG_ TotalPagedPoolUsage;
0177 ::boost::winapi::ULONG_ TotalNonPagedPoolUsage;
0178 ::boost::winapi::ULONG_ TotalNamePoolUsage;
0179 ::boost::winapi::ULONG_ TotalHandleTableUsage;
0180 ::boost::winapi::ULONG_ HighWaterNumberOfObjects;
0181 ::boost::winapi::ULONG_ HighWaterNumberOfHandles;
0182 ::boost::winapi::ULONG_ HighWaterPagedPoolUsage;
0183 ::boost::winapi::ULONG_ HighWaterNonPagedPoolUsage;
0184 ::boost::winapi::ULONG_ HighWaterNamePoolUsage;
0185 ::boost::winapi::ULONG_ HighWaterHandleTableUsage;
0186 ::boost::winapi::ULONG_ InvalidAttributes;
0187 GENERIC_MAPPING_ GenericMapping;
0188 ::boost::winapi::ULONG_ ValidAccessMask;
0189 ::boost::winapi::BOOLEAN_ SecurityRequired;
0190 ::boost::winapi::BOOLEAN_ MaintainHandleCount;
0191 ::boost::winapi::UCHAR_ TypeIndex;
0192 ::boost::winapi::CHAR_ ReservedByte;
0193 ::boost::winapi::ULONG_ PoolType;
0194 ::boost::winapi::ULONG_ DefaultPagedPoolCharge;
0195 ::boost::winapi::ULONG_ DefaultNonPagedPoolCharge;
0196 } OBJECT_TYPE_INFORMATION_, *POBJECT_TYPE_INFORMATION_;
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 typedef ::boost::winapi::NTSTATUS_ (*nt_system_query_information_p )(
0209 SYSTEM_INFORMATION_CLASS_,
0210 void *,
0211 ::boost::winapi::ULONG_,
0212 ::boost::winapi::PULONG_);
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 typedef ::boost::winapi::NTSTATUS_ (*nt_query_object_p )(
0224 ::boost::winapi::HANDLE_,
0225 OBJECT_INFORMATION_CLASS_,
0226 void *,
0227 ::boost::winapi::ULONG_,
0228 ::boost::winapi::PULONG_);
0229
0230 }
0231
0232 inline ::boost::winapi::NTSTATUS_ nt_system_query_information(
0233 SYSTEM_INFORMATION_CLASS_ SystemInformationClass,
0234 void *SystemInformation,
0235 ::boost::winapi::ULONG_ SystemInformationLength,
0236 ::boost::winapi::PULONG_ ReturnLength)
0237 {
0238 static ::boost::winapi::HMODULE_ h = ::boost::winapi::get_module_handle(L"Ntdll.dll");
0239 static nt_system_query_information_p f = reinterpret_cast<nt_system_query_information_p>(::boost::winapi::get_proc_address(h, "NtQuerySystemInformation"));
0240
0241 return (*f)(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength);
0242 }
0243
0244
0245 inline ::boost::winapi::BOOL_ nt_query_object(
0246 ::boost::winapi::HANDLE_ Handle,
0247 OBJECT_INFORMATION_CLASS_ ObjectInformationClass,
0248 void *ObjectInformation,
0249 ::boost::winapi::ULONG_ ObjectInformationLength,
0250 ::boost::winapi::PULONG_ ReturnLength)
0251 {
0252 static ::boost::winapi::HMODULE_ h = ::boost::winapi::get_module_handle(L"Ntdll.dll");
0253 static nt_query_object_p f = reinterpret_cast<nt_query_object_p>(::boost::winapi::get_proc_address(h, "NtQueryObject"));
0254
0255 return (*f)(Handle, ObjectInformationClass, ObjectInformation, ObjectInformationLength, ReturnLength);
0256 }
0257
0258 #endif
0259
0260 }}}}}
0261
0262 #endif