Skip to content

Commit 8defab2

Browse files
committed
runtime: implement stackcheck for riscv64
1 parent 8da6405 commit 8defab2

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/runtime/asm_riscv64.s

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ nocgo:
6464
ADD $16, X2
6565

6666
// start this M
67+
CALL runtime·stackcheck(SB) // fault if stack check is wrong
6768
CALL runtime·mstart(SB)
6869

6970
WORD $0 // crash if reached
@@ -253,6 +254,17 @@ TEXT runtime·return0(SB), NOSPLIT, $0
253254
MOV $0, A0
254255
RET
255256

257+
// check that SP is in range [g->stack.lo, g->stack.hi)
258+
TEXT runtime·stackcheck(SB), NOSPLIT|NOFRAME, $0-0
259+
MOV (g_stack+stack_hi)(g), A0
260+
BGT A0, X2, 2(PC)
261+
CALL runtime·abort(SB)
262+
263+
MOV (g_stack+stack_lo)(g), A0
264+
BGT X2, A0, 2(PC)
265+
CALL runtime·abort(SB)
266+
RET
267+
256268
// restore state from Gobuf; longjmp
257269

258270
// func gogo(buf *gobuf)

src/runtime/sys_freebsd_riscv64.s

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TEXT runtime·thr_start(SB),NOSPLIT,$0
7979
// set up g
8080
MOV m_g0(A0), g
8181
MOV A0, g_m(g)
82-
CALL emptyfunc<>(SB) // fault if stack check is wrong
82+
CALL runtime·stackcheck(SB) // fault if stack check is wrong
8383
CALL runtime·mstart(SB)
8484

8585
WORD $0 // crash

src/runtime/sys_linux_riscv64.s

+1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ good:
536536
// In child, set up new stack
537537
MOV T0, g_m(T1)
538538
MOV T1, g
539+
CALL runtime·stackcheck(SB) // fault if stack check is wrong
539540

540541
nog:
541542
// Call fn

src/runtime/sys_openbsd_riscv64.s

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$200
5050
MOV m_g0(X10), g
5151
CALL runtime·save_g(SB)
5252

53+
CALL runtime·stackcheck(SB) // fault if stack check is wrong
5354
CALL runtime·mstart(SB)
5455

5556
// Restore callee-save registers.

0 commit comments

Comments
 (0)