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

Commit f712e90

Browse files
committed
Restrict allocation of executable memory by DebuggerHeap
DebuggerHeap is a common class that is used for both executable and non-executable memory allocations by debugging infrustructure. On Windows, OS supports concept of executable heap and CLR doesn't need to do anything extra for each executable allocation. On Linux/OSX this is not true. That's why this changes preserves fExecutable flag for each heap and makes sure that we mark memory as executable only when it is necessary.
1 parent 4c3e266 commit f712e90

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/debug/ee/debugger.cpp

Lines changed: 13 additions & 8 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

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)