diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index d019affc33b33..0314a2920f074 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -2376,6 +2376,16 @@ HeapList* LoaderCodeHeap::CreateCodeHeap(CodeHeapRequestInfo *pInfo, LoaderHeap } else { + // Include internal CodeHeap structures in the reserve + allocationSize = ALIGN_UP(allocationSize, VIRTUAL_ALLOC_RESERVE_GRANULARITY); + reserveSize = max(reserveSize, allocationSize); + + if (reserveSize != (DWORD) reserveSize) + { + _ASSERTE(!"reserveSize does not fit in a DWORD"); + EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); + } + if (loAddr != NULL || hiAddr != NULL) { #ifdef _DEBUG