9 internal static class Kernel32
11 internal struct SECURITY_ATTRIBUTES
95 [DllImport(
"kernel32.dll", ExactSpelling =
true,
SetLastError =
true)]
98 [DllImport(
"kernel32.dll")]
104 [DllImport(
"kernel32.dll", BestFitMapping =
true,
CharSet =
CharSet.Unicode, EntryPoint =
"FormatMessageW", ExactSpelling =
true,
SetLastError =
true)]
105 private unsafe
static extern int FormatMessage(
int dwFlags,
IntPtr lpSource, uint dwMessageId,
int dwLanguageId,
void* lpBuffer,
int nSize,
IntPtr arguments);
120 fixed (
char* lpBuffer = span)
144 return $
"Unknown error (0x{errorCode:x})";
150 while (num > 0 &&
buffer[num - 1] <=
' ')
154 return buffer.Slice(0, num).ToString();
160 [DllImport(
"kernel32.dll")]
166 [DllImport(
"kernel32.dll", ExactSpelling =
true,
SetLastError =
true)]
183 if (nativeSize >= ullTotalVirtual)
192 SplitLong(maximumSize, out var high, out var low);
198 SplitLong(maximumSize, out var high, out var low);
204 SplitLong(fileOffset, out var high, out var low);
219 private static void SplitLong(
long number, out
int high, out
int low)
221 high = (int)(number >> 32);
222 low = (int)(number & 0xFFFFFFFFu);
static UIntPtr VirtualQuery(SafeHandle lpAddress, ref MEMORY_BASIC_INFORMATION lpBuffer, UIntPtr dwLength)
static SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, ref SECURITY_ATTRIBUTES lpFileMappingAttributes, int flProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, string lpName)
static IntPtr VirtualAlloc(SafeHandle lpAddress, UIntPtr dwSize, int flAllocationType, int flProtect)
static unsafe string GetMessage(int errorCode, IntPtr moduleHandle)
static void SetLastError(int errorCode)
static bool UnmapViewOfFile(IntPtr lpBaseAddress)
static bool FlushViewOfFile(IntPtr lpBaseAddress, UIntPtr dwNumberOfBytesToFlush)
static void GetSystemInfo(out SYSTEM_INFO lpSystemInfo)
static unsafe BOOL GlobalMemoryStatusEx(MEMORYSTATUSEX *lpBuffer)
static bool CloseHandle(IntPtr handle)
static SafeMemoryMappedViewHandle MapViewOfFile(SafeMemoryMappedFileHandle hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, UIntPtr dwNumberOfBytesToMap)
static string GetMessage(int errorCode)
static SafeMemoryMappedFileHandle OpenFileMapping(int dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, string lpName)
static unsafe int FormatMessage(int dwFlags, IntPtr lpSource, uint dwMessageId, int dwLanguageId, void *lpBuffer, int nSize, IntPtr arguments)
static SafeMemoryMappedFileHandle CreateFileMapping(IntPtr hFile, ref SECURITY_ATTRIBUTES lpFileMappingAttributes, int flProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, string lpName)
static string GetAndTrimString(Span< char > buffer)
static SafeMemoryMappedFileHandle CreateFileMapping(IntPtr hFile, ref Kernel32.SECURITY_ATTRIBUTES securityAttributes, int pageProtection, long maximumSize, string name)
static SafeMemoryMappedViewHandle MapViewOfFile(SafeMemoryMappedFileHandle hFileMappingObject, int desiredAccess, long fileOffset, UIntPtr numberOfBytesToMap)
static void SplitLong(long number, out int high, out int low)
static SafeMemoryMappedFileHandle CreateFileMapping(SafeFileHandle hFile, ref Kernel32.SECURITY_ATTRIBUTES securityAttributes, int pageProtection, long maximumSize, string name)
static SafeMemoryMappedFileHandle OpenFileMapping(int desiredAccess, bool inheritHandle, string name)
static IntPtr VirtualAlloc(SafeHandle baseAddress, UIntPtr size, int allocationType, int protection)
static unsafe void CheckForAvailableVirtualMemory(ulong nativeSize)
static void FreeHGlobal(IntPtr hglobal)
static int GetLastWin32Error()
static string IO_NotEnoughMemory
ulong ullAvailExtendedVirtual
IntPtr lpSecurityDescriptor
IntPtr lpMinimumApplicationAddress
IntPtr dwActiveProcessorMask
int dwAllocationGranularity
ushort wProcessorArchitecture
IntPtr lpMaximumApplicationAddress
static readonly IntPtr Zero
Span< T > Slice(int start)