Use aligned memory access in JIT_StackProbe (dotnet/coreclr#27235)
authorEgor Chesakov <Egor.Chesakov@microsoft.com>
Thu, 17 Oct 2019 03:44:55 +0000 (20:44 -0700)
committerJan Kotas <jkotas@microsoft.com>
Thu, 17 Oct 2019 03:44:55 +0000 (20:44 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/73b9f63aecbc8157464c20adbf15ac9a3eb85ea3

src/coreclr/src/vm/amd64/JitHelpers_Fast.asm
src/coreclr/src/vm/amd64/jithelpers_fast.S
src/coreclr/src/vm/i386/jithelp.S
src/coreclr/src/vm/i386/jithelp.asm

index 57dc46f..6d84939 100644 (file)
@@ -1011,15 +1011,15 @@ LEAF_ENTRY JIT_StackProbe, _TEXT
         ;
         ; NOTE: this helper will probe at least one page below the one pointed by rsp.
 
-        lea     rax, [rsp - PAGE_SIZE] ; rax points to some byte on the first unprobed page
-        or      rax, (PAGE_SIZE - 1)   ; rax points to the **highest address** on the first unprobed page
+        mov     rax, rsp               ; rax points to some byte on the last probed page
+        and     rax, -PAGE_SIZE        ; rax points to the **lowest address** on the last probed page
                                        ; This is done to make the following loop end condition simpler.
 
 ProbeLoop:
-        test    dword ptr [rax], eax
-        sub     rax, PAGE_SIZE         ; rax points to the highest address of the **next page** to probe
+        sub     rax, PAGE_SIZE         ; rax points to the lowest address of the **next page** to probe
+        test    dword ptr [rax], eax   ; rax points to the lowest address on the **last probed** page
         cmp     rax, r11
-        jge     ProbeLoop              ; if (rax >= r11), then we need to probe the page pointed to by rax.
+        jg      ProbeLoop              ; If (rax > r11), then we need to probe at least one more page.
 
         ret
 
index d95b117..26dcad9 100644 (file)
@@ -565,15 +565,14 @@ NESTED_ENTRY JIT_StackProbe, _TEXT, NoHandler
 
     END_PROLOGUE
 
-        sub     rsp, PAGE_SIZE         // rsp points to some byte on the first unprobed page
-        or      rsp, (PAGE_SIZE - 1)   // rsp points to the **highest address** on the first unprobed page
+        and     rsp, -PAGE_SIZE        // rsp points to the **lowest address** on the last probed page
                                        // This is done to make the following loop end condition simpler.
 
 LOCAL_LABEL(ProbeLoop):
-        test    dword ptr [rsp], eax
-        sub     rsp, PAGE_SIZE         // rsp points to the highest address of the **next page** to probe
+        sub     rsp, PAGE_SIZE         // rsp points to the lowest address of the **next page** to probe
+        test    dword ptr [rsp], eax   // rsp points to the lowest address on the **last probed** page
         cmp     rsp, r11
-        jge     LOCAL_LABEL(ProbeLoop) // if (rsp >= r11), then we need to probe the page pointed to by rsp.
+        jg      LOCAL_LABEL(ProbeLoop) // if (rsp > r11), then we need to probe at least one more page.
 
         RESET_FRAME_WITH_RBP
         ret
index 71f11bd..56c98bb 100644 (file)
@@ -638,15 +638,14 @@ NESTED_ENTRY JIT_StackProbe, _TEXT, NoHandler
     PROLOG_BEG
     PROLOG_END
 
-    sub     esp, PAGE_SIZE         // esp points to some byte on the first unprobed page
-    or      esp, (PAGE_SIZE - 1)   // esp points to the **highest address** on the first unprobed page
+    and     esp, -PAGE_SIZE        // esp points to the **lowest address** on the last probed page
                                    // This is done to make the loop end condition simpler.
 
 LOCAL_LABEL(ProbeLoop):
-    test    [esp], eax
-    sub     esp, PAGE_SIZE         // esp points to the highest address of the **next page** to probe
+    sub     esp, PAGE_SIZE         // esp points to the lowest address of the **next page** to probe
+    test    [esp], eax             // esp points to the lowest address on the **last probed** page
     cmp     esp, eax
-    jge     LOCAL_LABEL(ProbeLoop) // if esp >= eax, then we need to probe the page pointed to by esp.
+    jg      LOCAL_LABEL(ProbeLoop) // if esp > eax, then we need to probe at least one more page.
 
     EPILOG_BEG
     mov     esp, ebp
index 5bad9ca..463d9b6 100644 (file)
@@ -1480,14 +1480,13 @@ _JIT_StackProbe@0 PROC public
     push    ebp
     mov     ebp, esp
 
-    sub     esp, PAGE_SIZE       ; esp points to some byte on the first unprobed page
-    or      esp, (PAGE_SIZE - 1) ; esp points to the **highest address** on the first unprobed page
+    and     esp, -PAGE_SIZE      ; esp points to the **lowest address** on the last probed page
                                  ; This is done to make the loop end condition simpler.
 ProbeLoop:
-    test    [esp], eax
-    sub     esp, PAGE_SIZE       ; esp points to the highest address of the **next page** to probe
+    sub     esp, PAGE_SIZE       ; esp points to the lowest address of the **next page** to probe
+    test    [esp], eax           ; esp points to the lowest address on the **last probed** page
     cmp     esp, eax
-    jge     ProbeLoop            ; if esp >= eax, then we need to probe the page pointed to by esp.
+    jg      ProbeLoop            ; if esp > eax, then we need to probe at least one more page.
 
     mov     esp, ebp
     pop     ebp