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

Commit 8923762

Browse files
committed
Merge pull request #1979 from Djuffin/debug-heap
Restrict allocation of executable memory by DebuggerHeap
2 parents 22b6099 + 3e0b7de commit 8923762

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/debug/ee/debugger.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16566,6 +16566,7 @@ DebuggerHeap::DebuggerHeap()
1656616566
#ifdef USE_INTEROPSAFE_HEAP
1656716567
m_hHeap = NULL;
1656816568
#endif
16569+
m_fExecutable = FALSE;
1656916570
}
1657016571

1657116572

@@ -16615,6 +16616,7 @@ HRESULT DebuggerHeap::Init(BOOL fExecutable)
1661516616

1661616617
// Have knob catch if we don't want to lazy init the debugger.
1661716618
_ASSERTE(!g_DbgShouldntUseDebugger);
16619+
m_fExecutable = fExecutable;
1661816620

1661916621
#ifdef USE_INTEROPSAFE_HEAP
1662016622
// If already inited, then we're done.
@@ -16742,14 +16744,17 @@ void *DebuggerHeap::Alloc(DWORD size)
1674216744
#endif
1674316745

1674416746
#ifdef FEATURE_PAL
16745-
// We don't have executable heap in PAL, but we still need to allocate
16746-
// executable memory, that's why have change protection level for
16747-
// each allocation.
16748-
// UNIXTODO: We need to look how JIT solves this problem.
16749-
DWORD unusedFlags;
16750-
if (!VirtualProtect(ret, size, PAGE_EXECUTE_READWRITE, &unusedFlags))
16751-
{
16752-
_ASSERTE(!"VirtualProtect failed to make this memory executable");
16747+
if (m_fExecutable)
16748+
{
16749+
// We don't have executable heap in PAL, but we still need to allocate
16750+
// executable memory, that's why have change protection level for
16751+
// each allocation.
16752+
// UNIXTODO: We need to look how JIT solves this problem.
16753+
DWORD unusedFlags;
16754+
if (!VirtualProtect(ret, size, PAGE_EXECUTE_READWRITE, &unusedFlags))
16755+
{
16756+
_ASSERTE(!"VirtualProtect failed to make this memory executable");
16757+
}
1675316758
}
1675416759
#endif // FEATURE_PAL
1675516760

@@ -16797,14 +16802,17 @@ void *DebuggerHeap::Realloc(void *pMem, DWORD newSize, DWORD oldSize)
1679716802

1679816803

1679916804
#ifdef FEATURE_PAL
16800-
// We don't have executable heap in PAL, but we still need to allocate
16801-
// executable memory, that's why have change protection level for
16802-
// each allocation.
16803-
// UNIXTODO: We need to look how JIT solves this problem.
16804-
DWORD unusedFlags;
16805-
if (!VirtualProtect(ret, newSize, PAGE_EXECUTE_READWRITE, &unusedFlags))
16806-
{
16807-
_ASSERTE(!"VirtualProtect failed to make this memory executable");
16805+
if (m_fExecutable)
16806+
{
16807+
// We don't have executable heap in PAL, but we still need to allocate
16808+
// executable memory, that's why have change protection level for
16809+
// each allocation.
16810+
// UNIXTODO: We need to look how JIT solves this problem.
16811+
DWORD unusedFlags;
16812+
if (!VirtualProtect(ret, newSize, PAGE_EXECUTE_READWRITE, &unusedFlags))
16813+
{
16814+
_ASSERTE(!"VirtualProtect failed to make this memory executable");
16815+
}
1680816816
}
1680916817
#endif // FEATURE_PAL
1681016818

src/debug/ee/debugger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ class DebuggerHeap
11031103
#ifdef USE_INTEROPSAFE_HEAP
11041104
HANDLE m_hHeap;
11051105
#endif
1106+
BOOL m_fExecutable;
11061107
};
11071108

11081109
class DebuggerJitInfo;

0 commit comments

Comments
 (0)