From: Jan Vorlicek Date: Tue, 15 Jun 2021 18:37:30 +0000 (+0200) Subject: Fix PAL_JitWriteProtect export on Linux (#54190) X-Git-Tag: submit/tizen/20210909.063632~759 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=317f73cbf660a9155c89a496bc2623bf521e4364;p=platform%2Fupstream%2Fdotnet%2Fruntime.git 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: Mike McLaughlin --- diff --git a/src/coreclr/debug/di/CMakeLists.txt b/src/coreclr/debug/di/CMakeLists.txt index 55f34bd..b0272c4 100644 --- a/src/coreclr/debug/di/CMakeLists.txt +++ b/src/coreclr/debug/di/CMakeLists.txt @@ -1,4 +1,5 @@ add_definitions( + -DDBI_COMPILE -DFEATURE_METADATA_CUSTOM_DATA_SOURCE -DFEATURE_METADATA_DEBUGGEE_DATA_SOURCE -DFEATURE_NO_HOST diff --git a/src/coreclr/debug/inc/amd64/primitives.h b/src/coreclr/debug/inc/amd64/primitives.h index d42dc66..d8d14b2 100644 --- a/src/coreclr/debug/inc/amd64/primitives.h +++ b/src/coreclr/debug/inc/amd64/primitives.h @@ -12,7 +12,9 @@ #ifndef PRIMITIVES_H_ #define PRIMITIVES_H_ +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) #include "executableallocator.h" +#endif #ifndef CORDB_ADDRESS_TYPE typedef const BYTE CORDB_ADDRESS_TYPE; @@ -189,9 +191,14 @@ inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address) { LIMITED_METHOD_CONTRACT; - ExecutableWriterHolder breakpointWriterHolder((LPVOID)address, CORDbg_BREAK_INSTRUCTION_SIZE); +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) + ExecutableWriterHolder 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); } @@ -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. LIMITED_METHOD_DAC_CONTRACT; - ExecutableWriterHolder instructionWriterHolder((LPVOID)address, sizeof(unsigned char)); +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) + ExecutableWriterHolder 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 FlushInstructionCache(GetCurrentProcess(), address, 1); diff --git a/src/coreclr/debug/inc/arm/primitives.h b/src/coreclr/debug/inc/arm/primitives.h index eb29d83..c4e2d28 100644 --- a/src/coreclr/debug/inc/arm/primitives.h +++ b/src/coreclr/debug/inc/arm/primitives.h @@ -12,7 +12,9 @@ #ifndef PRIMITIVES_H_ #define PRIMITIVES_H_ +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) #include "executableallocator.h" +#endif #ifndef THUMB_CODE #define THUMB_CODE 1 @@ -161,9 +163,14 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, // In a DAC build, this function assumes the input is an host address. LIMITED_METHOD_DAC_CONTRACT; - ExecutableWriterHolder instructionWriterHolder((LPVOID)address, sizeof(PRD_TYPE)); +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) + ExecutableWriterHolder 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); ptraddr &= ~THUMB_CODE; diff --git a/src/coreclr/debug/inc/arm64/primitives.h b/src/coreclr/debug/inc/arm64/primitives.h index 1fb1b9c..4f4c3f7 100644 --- a/src/coreclr/debug/inc/arm64/primitives.h +++ b/src/coreclr/debug/inc/arm64/primitives.h @@ -12,7 +12,9 @@ #ifndef PRIMITIVES_H_ #define PRIMITIVES_H_ +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) #include "executableallocator.h" +#endif typedef NEON128 FPRegister64; typedef const BYTE CORDB_ADDRESS_TYPE; @@ -148,9 +150,13 @@ inline void CORDbgSetInstruction(CORDB_ADDRESS_TYPE* address, // In a DAC build, this function assumes the input is an host address. LIMITED_METHOD_DAC_CONTRACT; +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) ExecutableWriterHolder instructionWriterHolder((LPVOID)address, sizeof(PRD_TYPE)); ULONGLONG ptraddr = dac_cast(instructionWriterHolder.GetRW()); +#else // !DBI_COMPILE && !DACCESS_COMPILE + ULONGLONG ptraddr = dac_cast(address); +#endif // !DBI_COMPILE && !DACCESS_COMPILE *(PRD_TYPE *)ptraddr = instruction; FlushInstructionCache(GetCurrentProcess(), address, diff --git a/src/coreclr/debug/inc/i386/primitives.h b/src/coreclr/debug/inc/i386/primitives.h index 0c1d4bc..313b42c 100644 --- a/src/coreclr/debug/inc/i386/primitives.h +++ b/src/coreclr/debug/inc/i386/primitives.h @@ -12,7 +12,9 @@ #ifndef PRIMITIVES_H_ #define PRIMITIVES_H_ +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) #include "executableallocator.h" +#endif typedef const BYTE CORDB_ADDRESS_TYPE; typedef DPTR(CORDB_ADDRESS_TYPE) PTR_CORDB_ADDRESS_TYPE; @@ -149,9 +151,14 @@ inline void CORDbgInsertBreakpoint(UNALIGNED CORDB_ADDRESS_TYPE *address) { LIMITED_METHOD_CONTRACT; - ExecutableWriterHolder breakpointWriterHolder((LPVOID)address, CORDbg_BREAK_INSTRUCTION_SIZE); +#if !defined(DBI_COMPILE) && !defined(DACCESS_COMPILE) + ExecutableWriterHolder 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); } diff --git a/src/coreclr/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/dlls/mscordac/mscordac_unixexports.src index aa7352b..4fc0af3 100644 --- a/src/coreclr/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/dlls/mscordac/mscordac_unixexports.src @@ -70,7 +70,6 @@ nativeStringResourceTable_mscorrc #PAL__open #PAL__pread #PAL__close -#PAL_JitWriteProtect #_wcsicmp #_stricmp diff --git a/src/coreclr/inc/executableallocator.h b/src/coreclr/inc/executableallocator.h index c71f613..ce0c6c2 100644 --- a/src/coreclr/inc/executableallocator.h +++ b/src/coreclr/inc/executableallocator.h @@ -33,7 +33,7 @@ class ExecutableWriterHolder if (m_addressRX != NULL) { // 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); #endif } @@ -63,7 +63,7 @@ public: { m_addressRX = addressRX; m_addressRW = addressRX; -#if defined(HOST_OSX) && defined(HOST_ARM64) +#if defined(HOST_OSX) && defined(HOST_ARM64) && !defined(DACCESS_COMPILE) PAL_JitWriteProtect(true); #endif } diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 69d9052..8e0553e 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -2760,14 +2760,16 @@ VirtualFree( IN SIZE_T dwSize, IN DWORD dwFreeType); -#if defined(HOST_OSX) + +#if defined(HOST_OSX) && defined(HOST_ARM64) PALIMPORT VOID PALAPI PAL_JitWriteProtect(bool writeEnable); -#endif // defined(HOST_OSX) +#endif // defined(HOST_OSX) && defined(HOST_ARM64) + PALIMPORT BOOL diff --git a/src/coreclr/pal/src/map/virtual.cpp b/src/coreclr/pal/src/map/virtual.cpp index 9267f4f..645cf10 100644 --- a/src/coreclr/pal/src/map/virtual.cpp +++ b/src/coreclr/pal/src/map/virtual.cpp @@ -1760,10 +1760,9 @@ ExitVirtualProtect: return bRetVal; } -#if defined(HOST_OSX) +#if defined(HOST_OSX) && defined(HOST_ARM64) PALAPI VOID PAL_JitWriteProtect(bool writeEnable) { -#if defined(HOST_ARM64) thread_local int enabledCount = 0; if (writeEnable) { @@ -1780,9 +1779,8 @@ PALAPI VOID PAL_JitWriteProtect(bool writeEnable) } _ASSERTE(enabledCount >= 0); } -#endif // HOST_ARM64 } -#endif // HOST_OSX +#endif // HOST_OSX && HOST_ARM64 #if HAVE_VM_ALLOCATE //---------------------------------------------------------------------------------------