From 8176a2bda4e1caac846407d9ccee2cb62ed4d143 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 10 Feb 2021 14:44:36 -0800 Subject: [PATCH] Reorganize protection flipping (#48118) Get rid of explicit protection change to RW --- src/coreclr/vm/dllimportcallback.cpp | 9 +++++---- src/coreclr/vm/exceptionhandling.cpp | 8 -------- src/coreclr/vm/prestub.cpp | 12 +++++++----- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/coreclr/vm/dllimportcallback.cpp b/src/coreclr/vm/dllimportcallback.cpp index 25bb2d4..4736bd4 100644 --- a/src/coreclr/vm/dllimportcallback.cpp +++ b/src/coreclr/vm/dllimportcallback.cpp @@ -249,10 +249,6 @@ PCODE TheUMEntryPrestubWorker(UMEntryThunk * pUMEntryThunk) if (pThread->IsAbortRequested()) pThread->HandleThreadAbort(); -#if defined(HOST_OSX) && defined(HOST_ARM64) - auto jitWriteEnableHolder = PAL_JITWriteEnable(true); -#endif // defined(HOST_OSX) && defined(HOST_ARM64) - UMEntryThunk::DoRunTimeInit(pUMEntryThunk); return (PCODE)pUMEntryThunk->GetCode(); @@ -288,6 +284,11 @@ void STDCALL UMEntryThunk::DoRunTimeInit(UMEntryThunk* pUMEntryThunk) { GCX_PREEMP(); + +#if defined(HOST_OSX) && defined(HOST_ARM64) + auto jitWriteEnableHolder = PAL_JITWriteEnable(true); +#endif // defined(HOST_OSX) && defined(HOST_ARM64) + pUMEntryThunk->RunTimeInit(); } diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index e1f0b7f..7c3f935 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -3312,10 +3312,6 @@ DWORD_PTR ExceptionTracker::CallHandler( break; } -#if defined(HOST_OSX) && defined(HOST_ARM64) - auto jitWriteEnableHolder = PAL_JITWriteEnable(false); -#endif // defined(HOST_OSX) && defined(HOST_ARM64) - #ifdef USE_FUNCLET_CALL_HELPER // Invoke the funclet. We pass throwable only when invoking the catch block. // Since the actual caller of the funclet is the assembly helper, pass the reference @@ -3952,10 +3948,6 @@ void ExceptionTracker::ResumeExecution( EH_LOG((LL_INFO100, "resuming execution at 0x%p\n", GetIP(pContextRecord))); EH_LOG((LL_INFO100, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n")); -#if defined(HOST_OSX) && defined(HOST_ARM64) - auto jitWriteEnableHolder = PAL_JITWriteEnable(false); -#endif // defined(HOST_OSX) && defined(HOST_ARM64) - RtlRestoreContext(pContextRecord, pExceptionRecord); UNREACHABLE(); diff --git a/src/coreclr/vm/prestub.cpp b/src/coreclr/vm/prestub.cpp index 6722618..87bc136 100644 --- a/src/coreclr/vm/prestub.cpp +++ b/src/coreclr/vm/prestub.cpp @@ -1921,10 +1921,6 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method ETWOnStartup(PrestubWorker_V1, PrestubWorkerEnd_V1); -#if defined(HOST_OSX) && defined(HOST_ARM64) - auto jitWriteEnableHolder = PAL_JITWriteEnable(true); -#endif // defined(HOST_OSX) && defined(HOST_ARM64) - MAKE_CURRENT_THREAD_AVAILABLE(); // Attempt to check what GC mode we are running under. @@ -1994,7 +1990,13 @@ extern "C" PCODE STDCALL PreStubWorker(TransitionBlock* pTransitionBlock, Method } GCX_PREEMP_THREAD_EXISTS(CURRENT_THREAD); - pbRetVal = pMD->DoPrestub(pDispatchingMT, CallerGCMode::Coop); + { +#if defined(HOST_OSX) && defined(HOST_ARM64) + auto jitWriteEnableHolder = PAL_JITWriteEnable(true); +#endif // defined(HOST_OSX) && defined(HOST_ARM64) + + pbRetVal = pMD->DoPrestub(pDispatchingMT, CallerGCMode::Coop); + } UNINSTALL_UNWIND_AND_CONTINUE_HANDLER; UNINSTALL_MANAGED_EXCEPTION_DISPATCHER; -- 2.7.4