Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 73b9f63

Browse files
echesakovjkotas
authored andcommitted
Use aligned memory access in JIT_StackProbe (#27235)
1 parent fec0438 commit 73b9f63

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/vm/amd64/JitHelpers_Fast.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,15 @@ LEAF_ENTRY JIT_StackProbe, _TEXT
10111011
;
10121012
; NOTE: this helper will probe at least one page below the one pointed by rsp.
10131013

1014-
lea rax, [rsp - PAGE_SIZE] ; rax points to some byte on the first unprobed page
1015-
or rax, (PAGE_SIZE - 1) ; rax points to the **highest address** on the first unprobed page
1014+
mov rax, rsp ; rax points to some byte on the last probed page
1015+
and rax, -PAGE_SIZE ; rax points to the **lowest address** on the last probed page
10161016
; This is done to make the following loop end condition simpler.
10171017

10181018
ProbeLoop:
1019-
test dword ptr [rax], eax
1020-
sub rax, PAGE_SIZE ; rax points to the highest address of the **next page** to probe
1019+
sub rax, PAGE_SIZE ; rax points to the lowest address of the **next page** to probe
1020+
test dword ptr [rax], eax ; rax points to the lowest address on the **last probed** page
10211021
cmp rax, r11
1022-
jge ProbeLoop ; if (rax >= r11), then we need to probe the page pointed to by rax.
1022+
jg ProbeLoop ; If (rax > r11), then we need to probe at least one more page.
10231023

10241024
ret
10251025

src/vm/amd64/jithelpers_fast.S

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,15 +565,14 @@ NESTED_ENTRY JIT_StackProbe, _TEXT, NoHandler
565565

566566
END_PROLOGUE
567567

568-
sub rsp, PAGE_SIZE // rsp points to some byte on the first unprobed page
569-
or rsp, (PAGE_SIZE - 1) // rsp points to the **highest address** on the first unprobed page
568+
and rsp, -PAGE_SIZE // rsp points to the **lowest address** on the last probed page
570569
// This is done to make the following loop end condition simpler.
571570

572571
LOCAL_LABEL(ProbeLoop):
573-
test dword ptr [rsp], eax
574-
sub rsp, PAGE_SIZE // rsp points to the highest address of the **next page** to probe
572+
sub rsp, PAGE_SIZE // rsp points to the lowest address of the **next page** to probe
573+
test dword ptr [rsp], eax // rsp points to the lowest address on the **last probed** page
575574
cmp rsp, r11
576-
jge LOCAL_LABEL(ProbeLoop) // if (rsp >= r11), then we need to probe the page pointed to by rsp.
575+
jg LOCAL_LABEL(ProbeLoop) // if (rsp > r11), then we need to probe at least one more page.
577576

578577
RESET_FRAME_WITH_RBP
579578
ret

src/vm/i386/jithelp.S

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,14 @@ NESTED_ENTRY JIT_StackProbe, _TEXT, NoHandler
638638
PROLOG_BEG
639639
PROLOG_END
640640

641-
sub esp, PAGE_SIZE // esp points to some byte on the first unprobed page
642-
or esp, (PAGE_SIZE - 1) // esp points to the **highest address** on the first unprobed page
641+
and esp, -PAGE_SIZE // esp points to the **lowest address** on the last probed page
643642
// This is done to make the loop end condition simpler.
644643

645644
LOCAL_LABEL(ProbeLoop):
646-
test [esp], eax
647-
sub esp, PAGE_SIZE // esp points to the highest address of the **next page** to probe
645+
sub esp, PAGE_SIZE // esp points to the lowest address of the **next page** to probe
646+
test [esp], eax // esp points to the lowest address on the **last probed** page
648647
cmp esp, eax
649-
jge LOCAL_LABEL(ProbeLoop) // if esp >= eax, then we need to probe the page pointed to by esp.
648+
jg LOCAL_LABEL(ProbeLoop) // if esp > eax, then we need to probe at least one more page.
650649

651650
EPILOG_BEG
652651
mov esp, ebp

src/vm/i386/jithelp.asm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,14 +1480,13 @@ _JIT_StackProbe@0 PROC public
14801480
push ebp
14811481
mov ebp, esp
14821482

1483-
sub esp, PAGE_SIZE ; esp points to some byte on the first unprobed page
1484-
or esp, (PAGE_SIZE - 1) ; esp points to the **highest address** on the first unprobed page
1483+
and esp, -PAGE_SIZE ; esp points to the **lowest address** on the last probed page
14851484
; This is done to make the loop end condition simpler.
14861485
ProbeLoop:
1487-
test [esp], eax
1488-
sub esp, PAGE_SIZE ; esp points to the highest address of the **next page** to probe
1486+
sub esp, PAGE_SIZE ; esp points to the lowest address of the **next page** to probe
1487+
test [esp], eax ; esp points to the lowest address on the **last probed** page
14891488
cmp esp, eax
1490-
jge ProbeLoop ; if esp >= eax, then we need to probe the page pointed to by esp.
1489+
jg ProbeLoop ; if esp > eax, then we need to probe at least one more page.
14911490

14921491
mov esp, ebp
14931492
pop ebp

0 commit comments

Comments
 (0)