[x86/Linux] Fix IsIPInMarkedJitHelper to handle sigsegv (dotnet/coreclr#9605)
authorSaeHie Park <saehie.park@gmail.com>
Thu, 16 Feb 2017 08:50:08 +0000 (17:50 +0900)
committerJan Vorlicek <janvorli@microsoft.com>
Thu, 16 Feb 2017 08:50:08 +0000 (09:50 +0100)
Include JIT_WriteBarrier and JIT_CheckedWriteBarrier functions
so that we can handle NullReferenceException for sigsegv from WriteBarriers.

Commit migrated from https://github.com/dotnet/coreclr/commit/f8e6123ca24475cff7d78ff234c2cfd67e9e9772

src/coreclr/src/vm/excep.cpp
src/coreclr/src/vm/i386/jithelp.S
src/coreclr/src/vm/i386/jithelp.asm
src/coreclr/src/vm/i386/jitinterfacex86.cpp
src/coreclr/src/vm/jitinterface.h

index 7fca6f0..a9c38ee 100644 (file)
@@ -7072,6 +7072,11 @@ bool IsIPInMarkedJitHelper(UINT_PTR uControlPc)
 
     CHECK_RANGE(JIT_WriteBarrier)
     CHECK_RANGE(JIT_CheckedWriteBarrier)
+#else
+#ifdef FEATURE_PAL
+    CHECK_RANGE(JIT_WriteBarrierGroup)
+    CHECK_RANGE(JIT_PatchedWriteBarrierGroup)
+#endif // FEATURE_PAL
 #endif // _TARGET_X86_
 
 #if defined(_TARGET_AMD64_) && defined(_DEBUG)
@@ -7097,8 +7102,8 @@ AdjustContextForWriteBarrier(
 #if defined(_TARGET_X86_) && !defined(PLATFORM_UNIX)
     void* f_IP = (void *)GetIP(pContext);
 
-    if (((f_IP >= (void *) JIT_WriteBarrierStart) && (f_IP <= (void *) JIT_WriteBarrierLast)) ||
-        ((f_IP >= (void *) JIT_PatchedWriteBarrierStart) && (f_IP <= (void *) JIT_PatchedWriteBarrierLast)))
+    if (((f_IP >= (void *) JIT_WriteBarrierGroup) && (f_IP <= (void *) JIT_WriteBarrierGroup_End)) ||
+        ((f_IP >= (void *) JIT_PatchedWriteBarrierGroup) && (f_IP <= (void *) JIT_PatchedWriteBarrierGroup_End)))
     {
         // set the exception IP to be the instruction that called the write barrier
         void* callsite = (void *)GetAdjustedCallAddress(*dac_cast<PTR_PCODE>(GetSP(pContext)));
index 9a7e334..d7cbba0 100644 (file)
@@ -371,12 +371,12 @@ NESTED_END JIT_ByRefWriteBarrier, _TEXT
 
 .endm
 
-// WriteBarrierStart and WriteBarrierEnd are used to determine bounds of
-// WriteBarrier functions so can determine if got AV in them.
+// JIT_WriteBarrierGroup and JIT_WriteBarrierGroup_End are used
+// to determine bounds of WriteBarrier functions so can determine if got AV in them.
 //
-LEAF_ENTRY JIT_WriteBarrierStart, _TEXT
+LEAF_ENTRY JIT_WriteBarrierGroup, _TEXT
     ret
-LEAF_END JIT_WriteBarrierStart, _TEXT
+LEAF_END JIT_WriteBarrierGroup, _TEXT
 
 #ifdef FEATURE_USE_ASM_GC_WRITE_BARRIERS
 // *******************************************************************************
@@ -408,14 +408,10 @@ WriteBarrierHelper EBP
 
 ByRefWriteBarrierHelper
 
-LEAF_ENTRY JIT_WriteBarrierLast, _TEXT
-    ret
-LEAF_END JIT_WriteBarrierLast, _TEXT
-
 // This is the first function outside the "keep together range". Used by BBT scripts.
-LEAF_ENTRY JIT_WriteBarrierEnd, _TEXT
+LEAF_ENTRY JIT_WriteBarrierGroup_End, _TEXT
     ret
-LEAF_END JIT_WriteBarrierEnd, _TEXT
+LEAF_END JIT_WriteBarrierGroup_End, _TEXT
 
 // *********************************************************************/
 //  In cases where we support it we have an optimized GC Poll callback.
@@ -688,9 +684,9 @@ LEAF_END JIT_PatchedCodeStart, _TEXT
 // **********************************************************************
 // Write barriers generated at runtime
 
-LEAF_ENTRY JIT_PatchedWriteBarrierStart, _TEXT
+LEAF_ENTRY JIT_PatchedWriteBarrierGroup, _TEXT
     ret
-LEAF_END JIT_PatchedWriteBarrierStart, _TEXT
+LEAF_END JIT_PatchedWriteBarrierGroup, _TEXT
 
 .macro PatchedWriteBarrierHelper rg
 .align 8
@@ -708,15 +704,11 @@ PatchedWriteBarrierHelper ESI
 PatchedWriteBarrierHelper EDI
 PatchedWriteBarrierHelper EBP
 
-LEAF_ENTRY JIT_PatchedWriteBarrierLast, _TEXT
+// This is the first function outside the "keep together range". Used by BBT scripts.
+LEAF_ENTRY JIT_PatchedWriteBarrierGroup_End, _TEXT
     ret
-LEAF_END JIT_PatchedWriteBarrierLast, _TEXT
+LEAF_END JIT_PatchedWriteBarrierGroup_End, _TEXT
 
 LEAF_ENTRY JIT_PatchedCodeLast, _TEXT
     ret
 LEAF_END JIT_PatchedCodeLast, _TEXT
-
-// This is the first function outside the "keep together range". Used by BBT scripts.
-LEAF_ENTRY JIT_PatchedCodeEnd, _TEXT
-    ret
-LEAF_END JIT_PatchedCodeEnd, _TEXT
index 8285c42..e8d2f12 100644 (file)
@@ -434,10 +434,10 @@ ENDM
 ; WriteBarrierStart and WriteBarrierEnd are used to determine bounds of
 ; WriteBarrier functions so can determine if got AV in them. 
 ; 
-PUBLIC _JIT_WriteBarrierStart@0
-_JIT_WriteBarrierStart@0 PROC
+PUBLIC _JIT_WriteBarrierGroup@0
+_JIT_WriteBarrierGroup@0 PROC
 ret
-_JIT_WriteBarrierStart@0 ENDP
+_JIT_WriteBarrierGroup@0 ENDP
 
 ifdef FEATURE_USE_ASM_GC_WRITE_BARRIERS
 ; Only define these if we're using the ASM GC write barriers; if this flag is not defined,
@@ -455,16 +455,11 @@ WriteBarrierHelper <EBP>
 
 ByRefWriteBarrierHelper
 
-PUBLIC _JIT_WriteBarrierLast@0
-_JIT_WriteBarrierLast@0 PROC
-ret
-_JIT_WriteBarrierLast@0 ENDP
-
 ; This is the first function outside the "keep together range". Used by BBT scripts.
-PUBLIC _JIT_WriteBarrierEnd@0
-_JIT_WriteBarrierEnd@0 PROC
+PUBLIC _JIT_WriteBarrierGroup_End@0
+_JIT_WriteBarrierGroup_End@0 PROC
 ret
-_JIT_WriteBarrierEnd@0 ENDP
+_JIT_WriteBarrierGroup_End@0 ENDP
 
 ;*********************************************************************/
 ; In cases where we support it we have an optimized GC Poll callback.  Normall (when we're not trying to
@@ -2345,10 +2340,10 @@ endif
 ;**********************************************************************
 ; Write barriers generated at runtime
 
-PUBLIC _JIT_PatchedWriteBarrierStart@0
-_JIT_PatchedWriteBarrierStart@0 PROC
+PUBLIC _JIT_PatchedWriteBarrierGroup@0
+_JIT_PatchedWriteBarrierGroup@0 PROC
 ret
-_JIT_PatchedWriteBarrierStart@0 ENDP
+_JIT_PatchedWriteBarrierGroup@0 ENDP
 
 PatchedWriteBarrierHelper MACRO rg
         ALIGN 8
@@ -2367,10 +2362,10 @@ PatchedWriteBarrierHelper <ESI>
 PatchedWriteBarrierHelper <EDI>
 PatchedWriteBarrierHelper <EBP>
 
-PUBLIC _JIT_PatchedWriteBarrierLast@0
-_JIT_PatchedWriteBarrierLast@0 PROC
+PUBLIC _JIT_PatchedWriteBarrierGroup_End@0
+_JIT_PatchedWriteBarrierGroup_End@0 PROC
 ret
-_JIT_PatchedWriteBarrierLast@0 ENDP
+_JIT_PatchedWriteBarrierGroup_End@0 ENDP
 
 _JIT_PatchedCodeLast@0 proc public
 ret
index 9af3a3c..89b0cf7 100644 (file)
@@ -1509,8 +1509,8 @@ void InitJITHelpers1()
 
     // All write barrier helpers should fit into one page.
     // If you hit this assert on retail build, there is most likely problem with BBT script.
-    _ASSERTE_ALL_BUILDS("clr/src/VM/i386/JITinterfaceX86.cpp", (BYTE*)JIT_WriteBarrierLast - (BYTE*)JIT_WriteBarrierStart < PAGE_SIZE);
-    _ASSERTE_ALL_BUILDS("clr/src/VM/i386/JITinterfaceX86.cpp", (BYTE*)JIT_PatchedWriteBarrierLast - (BYTE*)JIT_PatchedWriteBarrierStart < PAGE_SIZE);
+    _ASSERTE_ALL_BUILDS("clr/src/VM/i386/JITinterfaceX86.cpp", (BYTE*)JIT_WriteBarrierGroup_End - (BYTE*)JIT_WriteBarrierGroup < PAGE_SIZE);
+    _ASSERTE_ALL_BUILDS("clr/src/VM/i386/JITinterfaceX86.cpp", (BYTE*)JIT_PatchedWriteBarrierGroup_End - (BYTE*)JIT_PatchedWriteBarrierGroup < PAGE_SIZE);
 
     // Copy the write barriers to their final resting place.
     for (int iBarrier = 0; iBarrier < NUM_WRITE_BARRIERS; iBarrier++)
@@ -1690,8 +1690,8 @@ void StompWriteBarrierEphemeral(bool /* isRuntimeSuspended */)
     }
 
     if (flushICache)
-        FlushInstructionCache(GetCurrentProcess(), (void *)JIT_PatchedWriteBarrierStart,
-            (BYTE*)JIT_PatchedWriteBarrierLast - (BYTE*)JIT_PatchedWriteBarrierStart);
+        FlushInstructionCache(GetCurrentProcess(), (void *)JIT_PatchedWriteBarrierGroup,
+            (BYTE*)JIT_PatchedWriteBarrierGroup_End - (BYTE*)JIT_PatchedWriteBarrierGroup);
 }
 
 /*********************************************************************/
@@ -1827,8 +1827,8 @@ void StompWriteBarrierResize(bool isRuntimeSuspended, bool bReqUpperBoundsCheck)
     }
     else
     {
-        FlushInstructionCache(GetCurrentProcess(), (void *)JIT_PatchedWriteBarrierStart,
-            (BYTE*)JIT_PatchedWriteBarrierLast - (BYTE*)JIT_PatchedWriteBarrierStart);
+        FlushInstructionCache(GetCurrentProcess(), (void *)JIT_PatchedWriteBarrierGroup,
+            (BYTE*)JIT_PatchedWriteBarrierGroup_End - (BYTE*)JIT_PatchedWriteBarrierGroup);
     }
 
     if(bEESuspendedHere)
index d6dd5d2..978be03 100644 (file)
@@ -378,11 +378,11 @@ extern "C"
     void STDCALL JIT_WriteBarrierEDI();        // JIThelp.asm/JIThelp.s
     void STDCALL JIT_WriteBarrierEBP();        // JIThelp.asm/JIThelp.s
 
-    void STDCALL JIT_WriteBarrierStart();
-    void STDCALL JIT_WriteBarrierLast();
+    void STDCALL JIT_WriteBarrierGroup();
+    void STDCALL JIT_WriteBarrierGroup_End();
 
-    void STDCALL JIT_PatchedWriteBarrierStart();
-    void STDCALL JIT_PatchedWriteBarrierLast();
+    void STDCALL JIT_PatchedWriteBarrierGroup();
+    void STDCALL JIT_PatchedWriteBarrierGroup_End();
 }
 
 void ValidateWriteBarrierHelpers();