Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 02f172c

Browse files
Konstantin Baladurinjkotas
Konstantin Baladurin
authored andcommitted
LoaderHeap: remove LHF_ZEROINIT option.
This option was used for UMEntryThunkCode::Poison. Now we use own free list to store freed thunks and don't return allocated memory to the LoaderHeap. So reused thunks are always uninitialized.
1 parent f2e5252 commit 02f172c

File tree

4 files changed

+10
-30
lines changed

4 files changed

+10
-30
lines changed

src/inc/loaderheap.h

+5-12
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ class UnlockedLoaderHeap
288288
SIZE_T dwReservedRegionSize,
289289
size_t *pPrivatePerfCounter_LoaderBytes = NULL,
290290
RangeList *pRangeList = NULL,
291-
BOOL fMakeExecutable = FALSE,
292-
BOOL fZeroInit = TRUE);
291+
BOOL fMakeExecutable = FALSE);
293292

294293
~UnlockedLoaderHeap();
295294
#endif
@@ -400,8 +399,6 @@ class UnlockedLoaderHeap
400399
}
401400

402401
BOOL IsExecutable();
403-
BOOL IsZeroInit();
404-
405402

406403
public:
407404
#ifdef _DEBUG
@@ -446,16 +443,14 @@ class LoaderHeap : public UnlockedLoaderHeap, public ILoaderHeapBackout
446443
DWORD dwCommitBlockSize,
447444
size_t *pPrivatePerfCounter_LoaderBytes = NULL,
448445
RangeList *pRangeList = NULL,
449-
BOOL fMakeExecutable = FALSE,
450-
BOOL fZeroInit = TRUE
446+
BOOL fMakeExecutable = FALSE
451447
)
452448
: UnlockedLoaderHeap(dwReserveBlockSize,
453449
dwCommitBlockSize,
454450
NULL, 0,
455451
pPrivatePerfCounter_LoaderBytes,
456452
pRangeList,
457-
fMakeExecutable,
458-
fZeroInit)
453+
fMakeExecutable)
459454
{
460455
WRAPPER_NO_CONTRACT;
461456
m_CriticalSection = NULL;
@@ -470,17 +465,15 @@ class LoaderHeap : public UnlockedLoaderHeap, public ILoaderHeapBackout
470465
SIZE_T dwReservedRegionSize,
471466
size_t *pPrivatePerfCounter_LoaderBytes = NULL,
472467
RangeList *pRangeList = NULL,
473-
BOOL fMakeExecutable = FALSE,
474-
BOOL fZeroInit = TRUE
468+
BOOL fMakeExecutable = FALSE
475469
)
476470
: UnlockedLoaderHeap(dwReserveBlockSize,
477471
dwCommitBlockSize,
478472
dwReservedRegionAddress,
479473
dwReservedRegionSize,
480474
pPrivatePerfCounter_LoaderBytes,
481475
pRangeList,
482-
fMakeExecutable,
483-
fZeroInit)
476+
fMakeExecutable)
484477
{
485478
WRAPPER_NO_CONTRACT;
486479
m_CriticalSection = NULL;

src/utilcode/loaderheap.cpp

+4-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "eventtracebase.h"
1212

1313
#define LHF_EXECUTABLE 0x1
14-
#define LHF_ZEROINIT 0x2
1514

1615
#ifndef DACCESS_COMPILE
1716

@@ -906,8 +905,7 @@ UnlockedLoaderHeap::UnlockedLoaderHeap(DWORD dwReserveBlockSize,
906905
SIZE_T dwReservedRegionSize,
907906
size_t *pPrivatePerfCounter_LoaderBytes,
908907
RangeList *pRangeList,
909-
BOOL fMakeExecutable,
910-
BOOL fZeroInit)
908+
BOOL fMakeExecutable)
911909
{
912910
CONTRACTL
913911
{
@@ -950,9 +948,6 @@ UnlockedLoaderHeap::UnlockedLoaderHeap(DWORD dwReserveBlockSize,
950948
m_Options |= LHF_EXECUTABLE;
951949
#endif // CROSSGEN_COMPILE
952950

953-
if (fZeroInit)
954-
m_Options |= LHF_ZEROINIT;
955-
956951
m_pFirstFreeBlock = NULL;
957952

958953
if (dwReservedRegionAddress != NULL && dwReservedRegionSize > 0)
@@ -1360,7 +1355,7 @@ void *UnlockedLoaderHeap::UnlockedAllocMem_NoThrow(size_t dwSize
13601355
// Don't fill the memory we allocated - it is assumed to be zeroed - fill the memory after it
13611356
memset(pAllocatedBytes + dwRequestedSize, 0xEE, LOADER_HEAP_DEBUG_BOUNDARY);
13621357
#endif
1363-
if ((dwRequestedSize > 0) && (m_Options & LHF_ZEROINIT))
1358+
if (dwRequestedSize > 0)
13641359
{
13651360
_ASSERTE_MSG(pAllocatedBytes[0] == 0 && memcmp(pAllocatedBytes, pAllocatedBytes + 1, dwRequestedSize - 1) == 0,
13661361
"LoaderHeap must return zero-initialized memory");
@@ -1538,8 +1533,7 @@ void UnlockedLoaderHeap::UnlockedBackoutMem(void *pMem,
15381533
{
15391534
// Cool. This was the last block allocated. We can just undo the allocation instead
15401535
// of going to the freelist.
1541-
if (m_Options & LHF_ZEROINIT)
1542-
memset(pMem, 0x00, dwSize); // Fill freed region with 0
1536+
memset(pMem, 0x00, dwSize); // Fill freed region with 0
15431537
m_pAllocPtr = (BYTE*)pMem;
15441538
}
15451539
else
@@ -1657,7 +1651,7 @@ void *UnlockedLoaderHeap::UnlockedAllocAlignedMem_NoThrow(size_t dwRequestedSiz
16571651
memset(pAllocatedBytes + dwRequestedSize, 0xee, LOADER_HEAP_DEBUG_BOUNDARY);
16581652
#endif
16591653

1660-
if ((dwRequestedSize != 0) && (m_Options & LHF_ZEROINIT))
1654+
if (dwRequestedSize != 0)
16611655
{
16621656
_ASSERTE_MSG(pAllocatedBytes[0] == 0 && memcmp(pAllocatedBytes, pAllocatedBytes + 1, dwRequestedSize - 1) == 0,
16631657
"LoaderHeap must return zero-initialized memory");
@@ -1782,11 +1776,6 @@ BOOL UnlockedLoaderHeap::IsExecutable()
17821776
return (m_Options & LHF_EXECUTABLE);
17831777
}
17841778

1785-
BOOL UnlockedLoaderHeap::IsZeroInit()
1786-
{
1787-
return (m_Options & LHF_ZEROINIT);
1788-
}
1789-
17901779
#ifdef DACCESS_COMPILE
17911780

17921781
void UnlockedLoaderHeap::EnumMemoryRegions(CLRDataEnumMemoryFlags flags)

src/vm/dllimportcallback.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,6 @@ void UMEntryThunk::Terminate()
11531153
}
11541154
CONTRACTL_END;
11551155

1156-
_ASSERTE(!SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->IsZeroInit());
11571156
m_code.Poison();
11581157

11591158
s_thunkFreeList.AddToList(this);

src/vm/loaderallocator.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,7 @@ void LoaderAllocator::Init(BaseDomain *pDomain, BYTE *pExecutableHeapMemory)
10051005
dwExecutableHeapReserveSize,
10061006
LOADERHEAP_PROFILE_COUNTER,
10071007
NULL,
1008-
TRUE /* Make heap executable */,
1009-
FALSE /* Disable zero-initialization (needed by UMEntryThunkCode::Poison) */
1008+
TRUE /* Make heap executable */
10101009
);
10111010
initReservedMem += dwExecutableHeapReserveSize;
10121011
}

0 commit comments

Comments
 (0)