@@ -1087,6 +1087,33 @@ void ReleaseReservedMemory(BYTE* value)
1087
1087
1088
1088
using ReservedMemoryHolder = SpecializedWrapper<BYTE, ReleaseReservedMemory>;
1089
1089
1090
+ BOOL UnlockedLoaderHeap::CommitPages (void * pData, size_t dwSizeToCommitPart)
1091
+ {
1092
+ // Commit first set of pages, since it will contain the LoaderHeapBlock
1093
+ void *pTemp = ExecutableAllocator::Instance ()->Commit (pData, dwSizeToCommitPart, IsExecutable ());
1094
+ if (pTemp == NULL )
1095
+ {
1096
+ return FALSE ;
1097
+ }
1098
+
1099
+ if (IsInterleaved ())
1100
+ {
1101
+ _ASSERTE (dwSizeToCommitPart == GetOsPageSize ());
1102
+
1103
+ void *pTemp = ExecutableAllocator::Instance ()->Commit ((BYTE*)pData + dwSizeToCommitPart, dwSizeToCommitPart, FALSE );
1104
+ if (pTemp == NULL )
1105
+ {
1106
+ return FALSE ;
1107
+ }
1108
+
1109
+ ExecutableWriterHolder<BYTE> codePageWriterHolder ((BYTE*)pData, GetOsPageSize ());
1110
+ m_codePageGenerator (codePageWriterHolder.GetRW (), (BYTE*)pData);
1111
+ FlushInstructionCache (GetCurrentProcess (), pData, GetOsPageSize ());
1112
+ }
1113
+
1114
+ return TRUE ;
1115
+ }
1116
+
1090
1117
BOOL UnlockedLoaderHeap::UnlockedReservePages (size_t dwSizeToCommit)
1091
1118
{
1092
1119
CONTRACTL
@@ -1166,32 +1193,11 @@ BOOL UnlockedLoaderHeap::UnlockedReservePages(size_t dwSizeToCommit)
1166
1193
dwSizeToCommitPart /= 2 ;
1167
1194
}
1168
1195
1169
- // Commit first set of pages, since it will contain the LoaderHeapBlock
1170
- void *pTemp = ExecutableAllocator::Instance ()->Commit (pData, dwSizeToCommitPart, IsExecutable ());
1171
- if (pTemp == NULL )
1196
+ if (!CommitPages (pData, dwSizeToCommitPart))
1172
1197
{
1173
- _ASSERTE (!" Unable to commit a loaderheap code page" );
1174
-
1175
1198
return FALSE ;
1176
1199
}
1177
1200
1178
- if (IsInterleaved ())
1179
- {
1180
- _ASSERTE (dwSizeToCommitPart == GetOsPageSize ());
1181
-
1182
- void *pTemp = ExecutableAllocator::Instance ()->Commit ((BYTE*)pData + dwSizeToCommitPart, dwSizeToCommitPart, FALSE );
1183
- if (pTemp == NULL )
1184
- {
1185
- _ASSERTE (!" Unable to commit a loaderheap data page" );
1186
-
1187
- return FALSE ;
1188
- }
1189
-
1190
- ExecutableWriterHolder<BYTE> codePageWriterHolder (pData, GetOsPageSize ());
1191
- m_codePageGenerator (codePageWriterHolder.GetRW (), pData);
1192
- FlushInstructionCache (GetCurrentProcess (), pData, GetOsPageSize ());
1193
- }
1194
-
1195
1201
// Record reserved range in range list, if one is specified
1196
1202
// Do this AFTER the commit - otherwise we'll have bogus ranges included.
1197
1203
if (m_pRangeList != NULL )
@@ -1301,26 +1307,13 @@ BOOL UnlockedLoaderHeap::GetMoreCommittedPages(size_t dwMinSize)
1301
1307
dwSizeToCommitPart /= 2 ;
1302
1308
}
1303
1309
1304
- // Yes, so commit the desired number of reserved pages
1305
- void *pData = ExecutableAllocator::Instance ()->Commit (m_pPtrToEndOfCommittedRegion, dwSizeToCommitPart, IsExecutable ());
1306
- if (pData == NULL )
1310
+ if (!CommitPages (m_pPtrToEndOfCommittedRegion, dwSizeToCommitPart))
1307
1311
{
1308
1312
return FALSE ;
1309
1313
}
1310
1314
1311
1315
if (IsInterleaved ())
1312
1316
{
1313
- // Commit a data page after the code page
1314
- void * pDataRW = ExecutableAllocator::Instance ()->Commit (m_pPtrToEndOfCommittedRegion + dwSizeToCommitPart, dwSizeToCommitPart, FALSE );
1315
- if (pDataRW == NULL )
1316
- {
1317
- return FALSE ;
1318
- }
1319
-
1320
- ExecutableWriterHolder<BYTE> codePageWriterHolder ((BYTE*)pData, GetOsPageSize ());
1321
- m_codePageGenerator (codePageWriterHolder.GetRW (), (BYTE*)pData);
1322
- FlushInstructionCache (GetCurrentProcess (), pData, GetOsPageSize ());
1323
-
1324
1317
// If the remaining bytes are large enough to allocate data of the allocation granularity, add them to the free
1325
1318
// block list.
1326
1319
// Otherwise the remaining bytes that are available will be wasted.
@@ -1335,7 +1328,7 @@ BOOL UnlockedLoaderHeap::GetMoreCommittedPages(size_t dwMinSize)
1335
1328
1336
1329
// For interleaved heaps, further allocations will start from the newly committed page as they cannot
1337
1330
// cross page boundary.
1338
- m_pAllocPtr = (BYTE*)pData ;
1331
+ m_pAllocPtr = (BYTE*)m_pPtrToEndOfCommittedRegion ;
1339
1332
}
1340
1333
1341
1334
m_pPtrToEndOfCommittedRegion += dwSizeToCommitPart;
0 commit comments