未验证 提交 317f73cb 编写于 作者: J Jan Vorlicek 提交者: GitHub

Fix PAL_JitWriteProtect export on Linux (#54190)

* Fix PAL_JitWriteProtect export on Linux

I have not realized that we actually export that symbol on Linux too and
that mscordac then have the dummy function missing.

* Code review feedback

* Disable PAL_JitWriteEnable usage in DBI / DAC

* Fix typo in amd64 version
Co-authored-by: NMike McLaughlin <mikem@microsoft.com>
上级 ddae3756
add_definitions( add_definitions(
-DDBI_COMPILE
-DFEATURE_METADATA_CUSTOM_DATA_SOURCE -DFEATURE_METADATA_CUSTOM_DATA_SOURCE
-DFEATURE_METADATA_DEBUGGEE_DATA_SOURCE -DFEATURE_METADATA_DEBUGGEE_DATA_SOURCE
-DFEATURE_NO_HOST -DFEATURE_NO_HOST
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#ifndef PRIMITIVES_H_ #ifndef PRIMITIVES_H_
#define PRIMITIVES_H_ #define PRIMITIVES_H_
#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
#include "executableallocator.h" #include "executableallocator.h"
#endif
#ifndef CORDB_ADDRESS_TYPE #ifndef CORDB_ADDRESS_TYPE
typedef const BYTE CORDB_ADDRESS_TYPE; typedef const BYTE CORDB_ADDRESS_TYPE;
...@@ -189,9 +191,14 @@ inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address) ...@@ -189,9 +191,14 @@ inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address)
{ {
LIMITED_METHOD_CONTRACT; LIMITED_METHOD_CONTRACT;
ExecutableWriterHolder<void> breakpointWriterHolder((LPVOID)address, CORDbg_BREAK_INSTRUCTION_SIZE); #if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
ExecutableWriterHolder<CORDB_ADDRESS_TYPE> breakpointWriterHolder(address, CORDbg_BREAK_INSTRUCTION_SIZE);
UNALIGNED CORDB_ADDRESS_TYPE* addressRW = breakpointWriterHolder.GetRW();
#else // !DBI_COMPILE && !DACCESS_COMPILE
UNALIGNED CORDB_ADDRESS_TYPE* addressRW = address;
#endif // !DBI_COMPILE && !DACCESS_COMPILE
*((unsigned char*)breakpointWriterHolder.GetRW()) = 0xCC; // int 3 (single byte patch) *((unsigned char*)addressRW) = 0xCC; // int 3 (single byte patch)
FlushInstructionCache(GetCurrentProcess(), address, 1); FlushInstructionCache(GetCurrentProcess(), address, 1);
} }
...@@ -202,9 +209,14 @@ inline void CORDbgSetInstruction(UNALIGNED CORDB_ADDRESS_TYPE* address, ...@@ -202,9 +209,14 @@ inline void CORDbgSetInstruction(UNALIGNED CORDB_ADDRESS_TYPE* address,
// In a DAC build, this function assumes the input is an host address. // In a DAC build, this function assumes the input is an host address.
LIMITED_METHOD_DAC_CONTRACT; LIMITED_METHOD_DAC_CONTRACT;
ExecutableWriterHolder<void> instructionWriterHolder((LPVOID)address, sizeof(unsigned char)); #if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
ExecutableWriterHolder<CORDB_ADDRESS_TYPE> instructionWriterHolder(address, sizeof(unsigned char));
UNALIGNED CORDB_ADDRESS_TYPE* addressRW = instructionWriterHolder.GetRW();
#else // !DBI_COMPILE && !DACCESS_COMPILE
UNALIGNED CORDB_ADDRESS_TYPE* addressRW = address;
#endif // !DBI_COMPILE && !DACCESS_COMPILE
*((unsigned char*)instructionWriterHolder.GetRW()) = *((unsigned char*)addressRW) =
(unsigned char) instruction; // setting one byte is important (unsigned char) instruction; // setting one byte is important
FlushInstructionCache(GetCurrentProcess(), address, 1); FlushInstructionCache(GetCurrentProcess(), address, 1);
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#ifndef PRIMITIVES_H_ #ifndef PRIMITIVES_H_
#define PRIMITIVES_H_ #define PRIMITIVES_H_
#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
#include "executableallocator.h" #include "executableallocator.h"
#endif
#ifndef THUMB_CODE #ifndef THUMB_CODE
#define THUMB_CODE 1 #define THUMB_CODE 1
...@@ -161,9 +163,14 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, ...@@ -161,9 +163,14 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address,
// In a DAC build, this function assumes the input is an host address. // In a DAC build, this function assumes the input is an host address.
LIMITED_METHOD_DAC_CONTRACT; LIMITED_METHOD_DAC_CONTRACT;
ExecutableWriterHolder<void> instructionWriterHolder((LPVOID)address, sizeof(PRD_TYPE)); #if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
ExecutableWriterHolder<CORDB_ADDRESS_TYPE> instructionWriterHolder(address, sizeof(PRD_TYPE));
CORDB_ADDRESS_TYPE* addressRW = instructionWriterHolder.GetRW();
#else // !DBI_COMPILE && !DACCESS_COMPILE
CORDB_ADDRESS_TYPE* addressRW = address;
#endif // !DBI_COMPILE && !DACCESS_COMPILE
CORDB_ADDRESS ptraddr = (CORDB_ADDRESS)instructionWriterHolder.GetRW(); CORDB_ADDRESS ptraddr = (CORDB_ADDRESS)addressRW;
_ASSERTE(ptraddr & THUMB_CODE); _ASSERTE(ptraddr & THUMB_CODE);
ptraddr &= ~THUMB_CODE; ptraddr &= ~THUMB_CODE;
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#ifndef PRIMITIVES_H_ #ifndef PRIMITIVES_H_
#define PRIMITIVES_H_ #define PRIMITIVES_H_
#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
#include "executableallocator.h" #include "executableallocator.h"
#endif
typedef NEON128 FPRegister64; typedef NEON128 FPRegister64;
typedef const BYTE CORDB_ADDRESS_TYPE; typedef const BYTE CORDB_ADDRESS_TYPE;
...@@ -148,9 +150,13 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, ...@@ -148,9 +150,13 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address,
// In a DAC build, this function assumes the input is an host address. // In a DAC build, this function assumes the input is an host address.
LIMITED_METHOD_DAC_CONTRACT; LIMITED_METHOD_DAC_CONTRACT;
#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
ExecutableWriterHolder<void> instructionWriterHolder((LPVOID)address, sizeof(PRD_TYPE)); ExecutableWriterHolder<void> instructionWriterHolder((LPVOID)address, sizeof(PRD_TYPE));
ULONGLONG ptraddr = dac_cast<ULONGLONG>(instructionWriterHolder.GetRW()); ULONGLONG ptraddr = dac_cast<ULONGLONG>(instructionWriterHolder.GetRW());
#else // !DBI_COMPILE && !DACCESS_COMPILE
ULONGLONG ptraddr = dac_cast<ULONGLONG>(address);
#endif // !DBI_COMPILE && !DACCESS_COMPILE
*(PRD_TYPE *)ptraddr = instruction; *(PRD_TYPE *)ptraddr = instruction;
FlushInstructionCache(GetCurrentProcess(), FlushInstructionCache(GetCurrentProcess(),
address, address,
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#ifndef PRIMITIVES_H_ #ifndef PRIMITIVES_H_
#define PRIMITIVES_H_ #define PRIMITIVES_H_
#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
#include "executableallocator.h" #include "executableallocator.h"
#endif
typedef const BYTE CORDB_ADDRESS_TYPE; typedef const BYTE CORDB_ADDRESS_TYPE;
typedef DPTR(CORDB_ADDRESS_TYPE) PTR_CORDB_ADDRESS_TYPE; typedef DPTR(CORDB_ADDRESS_TYPE) PTR_CORDB_ADDRESS_TYPE;
...@@ -149,9 +151,14 @@ inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address) ...@@ -149,9 +151,14 @@ inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address)
{ {
LIMITED_METHOD_CONTRACT; LIMITED_METHOD_CONTRACT;
ExecutableWriterHolder<void> breakpointWriterHolder((LPVOID)address, CORDbg_BREAK_INSTRUCTION_SIZE); #if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE)
ExecutableWriterHolder<CORDB_ADDRESS_TYPE> breakpointWriterHolder(address, CORDbg_BREAK_INSTRUCTION_SIZE);
UNALIGNED CORDB_ADDRESS_TYPE* addressRW = breakpointWriterHolder.GetRW();
#else // !DBI_COMPILE && !DACCESS_COMPILE
UNALIGNED CORDB_ADDRESS_TYPE* addressRW = address;
#endif // !DBI_COMPILE && !DACCESS_COMPILE
*((unsigned char*)breakpointWriterHolder.GetRW()) = 0xCC; // int 3 (single byte patch) *((unsigned char*)addressRW) = 0xCC; // int 3 (single byte patch)
FlushInstructionCache(GetCurrentProcess(), address, 1); FlushInstructionCache(GetCurrentProcess(), address, 1);
} }
......
...@@ -70,7 +70,6 @@ nativeStringResourceTable_mscorrc ...@@ -70,7 +70,6 @@ nativeStringResourceTable_mscorrc
#PAL__open #PAL__open
#PAL__pread #PAL__pread
#PAL__close #PAL__close
#PAL_JitWriteProtect
#_wcsicmp #_wcsicmp
#_stricmp #_stricmp
......
...@@ -33,7 +33,7 @@ class ExecutableWriterHolder ...@@ -33,7 +33,7 @@ class ExecutableWriterHolder
if (m_addressRX != NULL) if (m_addressRX != NULL)
{ {
// TODO: mapping / unmapping for targets using double memory mapping will be added with the double mapped allocator addition // TODO: mapping / unmapping for targets using double memory mapping will be added with the double mapped allocator addition
#if defined(HOST_OSX) && defined(HOST_ARM64) #if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE)
PAL_JitWriteProtect(false); PAL_JitWriteProtect(false);
#endif #endif
} }
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
{ {
m_addressRX = addressRX; m_addressRX = addressRX;
m_addressRW = addressRX; m_addressRW = addressRX;
#if defined(HOST_OSX) && defined(HOST_ARM64) #if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE)
PAL_JitWriteProtect(true); PAL_JitWriteProtect(true);
#endif #endif
} }
......
...@@ -2760,14 +2760,16 @@ VirtualFree( ...@@ -2760,14 +2760,16 @@ VirtualFree(
IN SIZE_T dwSize, IN SIZE_T dwSize,
IN DWORD dwFreeType); IN DWORD dwFreeType);
#if defined(HOST_OSX)
#if defined(HOST_OSX) && defined(HOST_ARM64)
PALIMPORT PALIMPORT
VOID VOID
PALAPI PALAPI
PAL_JitWriteProtect(bool writeEnable); PAL_JitWriteProtect(bool writeEnable);
#endif // defined(HOST_OSX) #endif // defined(HOST_OSX) && defined(HOST_ARM64)
PALIMPORT PALIMPORT
BOOL BOOL
......
...@@ -1760,10 +1760,9 @@ ExitVirtualProtect: ...@@ -1760,10 +1760,9 @@ ExitVirtualProtect:
return bRetVal; return bRetVal;
} }
#if defined(HOST_OSX) #if defined(HOST_OSX) && defined(HOST_ARM64)
PALAPI VOID PAL_JitWriteProtect(bool writeEnable) PALAPI VOID PAL_JitWriteProtect(bool writeEnable)
{ {
#if defined(HOST_ARM64)
thread_local int enabledCount = 0; thread_local int enabledCount = 0;
if (writeEnable) if (writeEnable)
{ {
...@@ -1780,9 +1779,8 @@ PALAPI VOID PAL_JitWriteProtect(bool writeEnable) ...@@ -1780,9 +1779,8 @@ PALAPI VOID PAL_JitWriteProtect(bool writeEnable)
} }
_ASSERTE(enabledCount >= 0); _ASSERTE(enabledCount >= 0);
} }
#endif // HOST_ARM64
} }
#endif // HOST_OSX #endif // HOST_OSX && HOST_ARM64
#if HAVE_VM_ALLOCATE #if HAVE_VM_ALLOCATE
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册