Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:42:38

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