Add a stack_check instruction.
This instruction loads a stack limit from a global variable and compares it to the stack pointer, trapping if the stack has grown beyond the limit. Also add a expand_flags transform group containing legalization patterns for ISAs with CPU flags. Fixes #234.
This commit is contained in:
@@ -511,6 +511,11 @@ instructions before instruction selection::
|
||||
v9 = stack_addr ss3, 16
|
||||
v1 = load.f64 v9
|
||||
|
||||
When Cretonne code is running in a sandbox, it can also be necessary to include
|
||||
stack overflow checks in the prologue.
|
||||
|
||||
.. autoinst:: stack_check
|
||||
|
||||
Global variables
|
||||
----------------
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@ ebb0(v1: i32):
|
||||
trapz v1, user67
|
||||
return
|
||||
; check: $ebb0($v1: i32
|
||||
; nextln: brnz $v1, $(new=$EBB)
|
||||
; nextln: trap user67
|
||||
; check: $new:
|
||||
; nextln: $(f=$V) = ifcmp_imm $v1, 0
|
||||
; nextln: trapif eq $f, user67
|
||||
; nextln: return
|
||||
}
|
||||
|
||||
@@ -23,9 +22,8 @@ ebb0(v1: i32):
|
||||
trapnz v1, int_ovf
|
||||
return
|
||||
; check: $ebb0($v1: i32
|
||||
; nextln: brz $v1, $(new=$EBB)
|
||||
; nextln: trap int_ovf
|
||||
; check: $new:
|
||||
; nextln: $(f=$V) = ifcmp_imm $v1, 0
|
||||
; nextln: trapif ne $f, int_ovf
|
||||
; nextln: return
|
||||
}
|
||||
|
||||
|
||||
@@ -109,3 +109,17 @@ ebb0(v0: i32, v999: i64):
|
||||
; nextln: $v2 = load.f32 $v1+0x7fff_ffff
|
||||
return v2
|
||||
}
|
||||
|
||||
; Stack overflow check.
|
||||
; The stack limit is stored in a pointer-sized global variable.
|
||||
function %stkchk(i64 vmctx) spiderwasm {
|
||||
gv0 = vmctx+64
|
||||
|
||||
ebb0(v0: i64):
|
||||
; check: $ebb0(
|
||||
stack_check gv0
|
||||
; check: $(limit=$V) = load.i64 notrap aligned
|
||||
; check: $(flags=$V) = ifcmp_sp $limit
|
||||
; check: trapif uge $flags, stk_ovf
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user