private unsafe static ulong MemFreeAfterAddress(void *address, ulong size) { if (size >= MemoryFailPoint.TopOfMemory) { return(0UL); } ulong num = 0UL; Win32Native.MEMORY_BASIC_INFORMATION memory_BASIC_INFORMATION = default(Win32Native.MEMORY_BASIC_INFORMATION); UIntPtr sizeOfBuffer = (UIntPtr)((ulong)((long)Marshal.SizeOf <Win32Native.MEMORY_BASIC_INFORMATION>(memory_BASIC_INFORMATION))); while ((byte *)address + size < MemoryFailPoint.TopOfMemory) { UIntPtr value = Win32Native.VirtualQuery(address, ref memory_BASIC_INFORMATION, sizeOfBuffer); if (value == UIntPtr.Zero) { __Error.WinIOError(); } ulong num2 = memory_BASIC_INFORMATION.RegionSize.ToUInt64(); if (memory_BASIC_INFORMATION.State == 65536U) { if (num2 >= size) { return(num2); } num = Math.Max(num, num2); } address = (void *)((byte *)address + num2); } return(num); }
private static unsafe ulong MemFreeAfterAddress(void *address, ulong size) { if (size >= MemoryFailPoint.TopOfMemory) { return(0); } ulong val1 = 0; Win32Native.MEMORY_BASIC_INFORMATION buffer = new Win32Native.MEMORY_BASIC_INFORMATION(); UIntPtr sizeOfBuffer = (UIntPtr)((ulong)Marshal.SizeOf <Win32Native.MEMORY_BASIC_INFORMATION>(buffer)); ulong uint64; for (; (ulong)address + size < MemoryFailPoint.TopOfMemory; address = (void *)((ulong)address + uint64)) { if (Win32Native.VirtualQuery(address, ref buffer, sizeOfBuffer) == UIntPtr.Zero) { __Error.WinIOError(); } uint64 = buffer.RegionSize.ToUInt64(); if ((int)buffer.State == 65536) { if (uint64 >= size) { return(uint64); } val1 = Math.Max(val1, uint64); } } return(val1); }
private static unsafe ulong MemFreeAfterAddress(void *address, ulong size) { if (size >= TopOfMemory) { return(0L); } ulong num = 0L; Win32Native.MEMORY_BASIC_INFORMATION structure = new Win32Native.MEMORY_BASIC_INFORMATION(); IntPtr sizeOfBuffer = (IntPtr)Marshal.SizeOf(structure); while ((((ulong)address) + size) < TopOfMemory) { if (Win32Native.VirtualQuery(address, ref structure, sizeOfBuffer) == IntPtr.Zero) { __Error.WinIOError(); } ulong num2 = structure.RegionSize.ToUInt64(); if (structure.State == 0x10000) { if (num2 >= size) { return(num2); } num = Math.Max(num, num2); } address = (void *)(((ulong)address) + num2); } return(num); }
private unsafe bool CheckForSufficientStack() { if (s_pageSize == 0) { Win32Native.SYSTEM_INFO lpSystemInfo = new Win32Native.SYSTEM_INFO(); Win32Native.GetSystemInfo(ref lpSystemInfo); s_pageSize = lpSystemInfo.dwPageSize; } Win32Native.MEMORY_BASIC_INFORMATION buffer = new Win32Native.MEMORY_BASIC_INFORMATION(); UIntPtr ptr = new UIntPtr((void *)(&buffer - s_pageSize)); ulong num = ptr.ToUInt64(); if ((this.m_lastKnownWatermark != 0L) && (num > this.m_lastKnownWatermark)) { return(true); } Win32Native.VirtualQuery(ptr.ToPointer(), ref buffer, new IntPtr(sizeof(Win32Native.MEMORY_BASIC_INFORMATION))); UIntPtr allocationBase = (UIntPtr)buffer.AllocationBase; if ((num - allocationBase.ToUInt64()) > 0x10000L) { this.m_lastKnownWatermark = num; return(true); } return(false); }
private unsafe bool CheckForSufficientStack() { int num1 = StackGuard.s_pageSize; if (num1 == 0) { Win32Native.SYSTEM_INFO lpSystemInfo = new Win32Native.SYSTEM_INFO(); Win32Native.GetSystemInfo(ref lpSystemInfo); StackGuard.s_pageSize = num1 = lpSystemInfo.dwPageSize; } Win32Native.MEMORY_BASIC_INFORMATION buffer = new Win32Native.MEMORY_BASIC_INFORMATION(); UIntPtr num2 = new UIntPtr((void *)(&buffer - num1)); ulong uint64 = num2.ToUInt64(); if ((long)this.m_lastKnownWatermark != 0L && uint64 > this.m_lastKnownWatermark) { return(true); } IntPtr num3 = (IntPtr)Win32Native.VirtualQuery(num2.ToPointer(), ref buffer, (UIntPtr)((ulong)sizeof(Win32Native.MEMORY_BASIC_INFORMATION))); if (uint64 - (UIntPtr)buffer.AllocationBase.ToUInt64() <= 65536UL) { return(false); } this.m_lastKnownWatermark = uint64; return(true); }
private unsafe bool CheckForSufficientStack() { int num = StackGuard.s_pageSize; if (num == 0) { Win32Native.SYSTEM_INFO system_INFO = default(Win32Native.SYSTEM_INFO); Win32Native.GetSystemInfo(ref system_INFO); num = (StackGuard.s_pageSize = system_INFO.dwPageSize); } Win32Native.MEMORY_BASIC_INFORMATION memory_BASIC_INFORMATION = default(Win32Native.MEMORY_BASIC_INFORMATION); UIntPtr uintPtr = new UIntPtr((void *)((byte *)(&memory_BASIC_INFORMATION) - (IntPtr)num * (IntPtr)sizeof(Win32Native.MEMORY_BASIC_INFORMATION))); ulong num2 = uintPtr.ToUInt64(); if (this.m_lastKnownWatermark != 0UL && num2 > this.m_lastKnownWatermark) { return(true); } Win32Native.VirtualQuery(uintPtr.ToPointer(), ref memory_BASIC_INFORMATION, (UIntPtr)((ulong)((long)sizeof(Win32Native.MEMORY_BASIC_INFORMATION)))); if (num2 - ((UIntPtr)memory_BASIC_INFORMATION.AllocationBase).ToUInt64() > 65536UL) { this.m_lastKnownWatermark = num2; return(true); } return(false); }
[System.Security.SecurityCritical] // auto-generated private static unsafe ulong MemFreeAfterAddress(void *address, ulong size) { if (size >= TopOfMemory) { return(0); } ulong largestFreeRegion = 0; Win32Native.MEMORY_BASIC_INFORMATION memInfo = new Win32Native.MEMORY_BASIC_INFORMATION(); UIntPtr sizeOfMemInfo = (UIntPtr)Marshal.SizeOf(memInfo); while (((ulong)address) + size < TopOfMemory) { UIntPtr r = Win32Native.VirtualQuery(address, ref memInfo, sizeOfMemInfo); if (r == UIntPtr.Zero) { __Error.WinIOError(); } ulong regionSize = memInfo.RegionSize.ToUInt64(); if (memInfo.State == Win32Native.MEM_FREE) { if (regionSize >= size) { return(regionSize); } else { largestFreeRegion = Math.Max(largestFreeRegion, regionSize); } } address = (void *)((ulong)address + regionSize); } return(largestFreeRegion); }