66
77#if _WIN32
88#if ENABLE_OOP_NATIVE_CODEGEN
9- #include " ../Core/DelayLoadLibrary.h"
9+ #include " Core/DelayLoadLibrary.h"
10+
11+ #include " XDataAllocator.h"
12+ #include " CustomHeap.h"
1013
1114#ifdef NTDDI_WIN10_RS2
1215#if (NTDDI_VERSION >= NTDDI_WIN10_RS2)
@@ -603,6 +606,19 @@ SectionAllocWrapper::AllocPages(LPVOID requestAddress, size_t pageCount, DWORD a
603606 {
604607 return nullptr ;
605608 }
609+
610+ // pages could be filled with debugbreak
611+ // zero one page at a time to minimize working set impact while zeroing
612+ for (size_t i = 0 ; i < dwSize / AutoSystemInfo::PageSize; ++i)
613+ {
614+ LPVOID localAddr = AllocLocal ((char *)requestAddress + i * AutoSystemInfo::PageSize, AutoSystemInfo::PageSize);
615+ if (localAddr == nullptr )
616+ {
617+ return nullptr ;
618+ }
619+ ZeroMemory (localAddr, AutoSystemInfo::PageSize);
620+ FreeLocal (localAddr);
621+ }
606622 address = requestAddress;
607623 }
608624
@@ -677,10 +693,10 @@ BOOL SectionAllocWrapper::Free(LPVOID lpAddress, size_t dwSize, DWORD dwFreeType
677693 {
678694 return FALSE ;
679695 }
680- ZeroMemory (localAddr, AutoSystemInfo::PageSize);
696+
697+ CustomHeap::FillDebugBreak ((BYTE*)localAddr, AutoSystemInfo::PageSize);
681698 FreeLocal (localAddr);
682699 }
683- UnlockMemory (this ->process , lpAddress, dwSize);
684700 }
685701
686702 return TRUE ;
@@ -928,6 +944,19 @@ LPVOID PreReservedSectionAllocWrapper::AllocPages(LPVOID lpAddress, DECLSPEC_GUA
928944
929945 addressToReserve = (char *)lpAddress;
930946 freeSegmentsBVIndex = (uint)((addressToReserve - (char *)this ->preReservedStartAddress ) / AutoSystemInfo::Data.GetAllocationGranularityPageSize ());
947+
948+ // pages could be filled with debugbreak
949+ // zero one page at a time to minimize working set impact while zeroing
950+ for (size_t i = 0 ; i < dwSize / AutoSystemInfo::PageSize; ++i)
951+ {
952+ LPVOID localAddr = AllocLocal ((char *)lpAddress + i * AutoSystemInfo::PageSize, AutoSystemInfo::PageSize);
953+ if (localAddr == nullptr )
954+ {
955+ return nullptr ;
956+ }
957+ ZeroMemory (localAddr, AutoSystemInfo::PageSize);
958+ FreeLocal (localAddr);
959+ }
931960#if DBG
932961 uint numOfSegments = (uint)ceil ((double )dwSize / (double )AutoSystemInfo::Data.GetAllocationGranularityPageSize ());
933962 Assert (numOfSegments != 0 );
@@ -978,12 +1007,17 @@ PreReservedSectionAllocWrapper::Free(LPVOID lpAddress, size_t dwSize, DWORD dwFr
9781007 {
9791008 return FALSE ;
9801009 }
981- ZeroMemory (localAddr, AutoSystemInfo::PageSize);
1010+ if ((dwFreeType & MEM_RELEASE) == MEM_RELEASE)
1011+ {
1012+ ZeroMemory (localAddr, AutoSystemInfo::PageSize);
1013+ }
1014+ else
1015+ {
1016+ CustomHeap::FillDebugBreak ((BYTE*)localAddr, AutoSystemInfo::PageSize);
1017+ }
9821018 FreeLocal (localAddr);
9831019 }
9841020
985- UnlockMemory (this ->process , lpAddress, dwSize);
986-
9871021 size_t requestedNumOfSegments = dwSize / AutoSystemInfo::Data.GetAllocationGranularityPageSize ();
9881022 Assert (requestedNumOfSegments <= MAXUINT32);
9891023
@@ -1000,6 +1034,8 @@ PreReservedSectionAllocWrapper::Free(LPVOID lpAddress, size_t dwSize, DWORD dwFr
10001034 AssertMsg (freeSegmentsBVIndex < PreReservedAllocationSegmentCount, " Invalid Index ?" );
10011035 freeSegments.SetRange (freeSegmentsBVIndex, static_cast <uint>(requestedNumOfSegments));
10021036 PreReservedHeapTrace (_u (" MEM_RELEASE: Address: 0x%p of size: 0x%x * 0x%x bytes\n " ), lpAddress, requestedNumOfSegments, AutoSystemInfo::Data.GetAllocationGranularityPageSize ());
1037+
1038+ UnlockMemory (this ->process , lpAddress, dwSize);
10031039 }
10041040
10051041 return TRUE ;
0 commit comments