summaryrefslogtreecommitdiff
path: root/src/vm/gcenv.os.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/gcenv.os.cpp')
-rw-r--r--src/vm/gcenv.os.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/vm/gcenv.os.cpp b/src/vm/gcenv.os.cpp
index 77be88c96d..abacc3c76d 100644
--- a/src/vm/gcenv.os.cpp
+++ b/src/vm/gcenv.os.cpp
@@ -171,13 +171,18 @@ void* GCToOSInterface::VirtualReserve(size_t size, size_t alignment, uint32_t fl
LIMITED_METHOD_CONTRACT;
DWORD memFlags = (flags & VirtualReserveFlags::WriteWatch) ? (MEM_RESERVE | MEM_WRITE_WATCH) : MEM_RESERVE;
+
+ // This is not strictly necessary for a correctness standpoint. Windows already guarantees
+ // allocation granularity alignment when using MEM_RESERVE, so aligning the size here has no effect.
+ // However, ClrVirtualAlloc does expect the size to be aligned to the allocation granularity.
+ size_t aligned_size = (size + g_SystemInfo.dwAllocationGranularity - 1) & ~static_cast<size_t>(g_SystemInfo.dwAllocationGranularity - 1);
if (alignment == 0)
{
- return ::ClrVirtualAlloc(0, size, memFlags, PAGE_READWRITE);
+ return ::ClrVirtualAlloc(0, aligned_size, memFlags, PAGE_READWRITE);
}
else
{
- return ::ClrVirtualAllocAligned(0, size, memFlags, PAGE_READWRITE, alignment);
+ return ::ClrVirtualAllocAligned(0, aligned_size, memFlags, PAGE_READWRITE, alignment);
}
}
@@ -669,6 +674,13 @@ bool GCToOSInterface::CreateThread(GCThreadFunction function, void* param, GCThr
return true;
}
+uint32_t GCToOSInterface::GetTotalProcessorCount()
+{
+ LIMITED_METHOD_CONTRACT;
+
+ return g_SystemInfo.dwNumberOfProcessors;
+}
+
// Initialize the critical section
void CLRCriticalSection::Initialize()
{