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

Commit

Permalink
Merge pull request #1979 from Djuffin/debug-heap
Browse files Browse the repository at this point in the history
Restrict allocation of executable memory by DebuggerHeap
  • Loading branch information
ellismg committed Nov 6, 2015
2 parents 22b6099 + 3e0b7de commit 8923762
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16566,6 +16566,7 @@ DebuggerHeap::DebuggerHeap()
#ifdef USE_INTEROPSAFE_HEAP
m_hHeap = NULL;
#endif
m_fExecutable = FALSE;
}


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

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

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

#ifdef FEATURE_PAL
// We don't have executable heap in PAL, but we still need to allocate
// executable memory, that's why have change protection level for
// each allocation.
// UNIXTODO: We need to look how JIT solves this problem.
DWORD unusedFlags;
if (!VirtualProtect(ret, size, PAGE_EXECUTE_READWRITE, &unusedFlags))
{
_ASSERTE(!"VirtualProtect failed to make this memory executable");
if (m_fExecutable)
{
// We don't have executable heap in PAL, but we still need to allocate
// executable memory, that's why have change protection level for
// each allocation.
// UNIXTODO: We need to look how JIT solves this problem.
DWORD unusedFlags;
if (!VirtualProtect(ret, size, PAGE_EXECUTE_READWRITE, &unusedFlags))
{
_ASSERTE(!"VirtualProtect failed to make this memory executable");
}
}
#endif // FEATURE_PAL

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


#ifdef FEATURE_PAL
// We don't have executable heap in PAL, but we still need to allocate
// executable memory, that's why have change protection level for
// each allocation.
// UNIXTODO: We need to look how JIT solves this problem.
DWORD unusedFlags;
if (!VirtualProtect(ret, newSize, PAGE_EXECUTE_READWRITE, &unusedFlags))
{
_ASSERTE(!"VirtualProtect failed to make this memory executable");
if (m_fExecutable)
{
// We don't have executable heap in PAL, but we still need to allocate
// executable memory, that's why have change protection level for
// each allocation.
// UNIXTODO: We need to look how JIT solves this problem.
DWORD unusedFlags;
if (!VirtualProtect(ret, newSize, PAGE_EXECUTE_READWRITE, &unusedFlags))
{
_ASSERTE(!"VirtualProtect failed to make this memory executable");
}
}
#endif // FEATURE_PAL

Expand Down
1 change: 1 addition & 0 deletions src/debug/ee/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ class DebuggerHeap
#ifdef USE_INTEROPSAFE_HEAP
HANDLE m_hHeap;
#endif
BOOL m_fExecutable;
};

class DebuggerJitInfo;
Expand Down

0 comments on commit 8923762

Please sign in to comment.