Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

fiber: reserve stack before saving registers on riscv64 (#13943)

Sebastien Tardif734c7f134063
diff --git a/crates/fiber/src/stackswitch/riscv64.rs b/crates/fiber/src/stackswitch/riscv64.rs
index 113a49ccbc..b55ac71cc7 100644
--- a/crates/fiber/src/stackswitch/riscv64.rs
+++ b/crates/fiber/src/stackswitch/riscv64.rs
@@ -25,32 +25,33 @@ unsafe extern "C" fn wasmtime_fiber_switch_(top_of_stack: *mut u8 /* a0 */) {
//
// Note that this order for saving is important since we use CFI directives
// below to point to where all the saved registers are.
- sd ra, -0x8(sp)
- sd fp, -0x10(sp)
- sd s1, -0x18(sp)
- sd s2, -0x20(sp)
- sd s3, -0x28(sp)
- sd s4, -0x30(sp)
- sd s5, -0x38(sp)
- sd s6, -0x40(sp)
- sd s7, -0x48(sp)
- sd s8, -0x50(sp)
- sd s9, -0x58(sp)
- sd s10, -0x60(sp)
- sd s11, -0x68(sp)
- fsd fs0, -0x70(sp)
- fsd fs1, -0x78(sp)
- fsd fs2, -0x80(sp)
- fsd fs3, -0x88(sp)
- fsd fs4, -0x90(sp)
- fsd fs5, -0x98(sp)
- fsd fs6, -0xa0(sp)
- fsd fs7, -0xa8(sp)
- fsd fs8, -0xb0(sp)
- fsd fs9, -0xb8(sp)
- fsd fs10, -0xc0(sp)
- fsd fs11, -0xc8(sp)
+ // Reserve space before writing.
addi sp, sp, -0xd0
+ sd ra, 0xc8(sp)
+ sd fp, 0xc0(sp)
+ sd s1, 0xb8(sp)
+ sd s2, 0xb0(sp)
+ sd s3, 0xa8(sp)
+ sd s4, 0xa0(sp)
+ sd s5, 0x98(sp)
+ sd s6, 0x90(sp)
+ sd s7, 0x88(sp)
+ sd s8, 0x80(sp)
+ sd s9, 0x78(sp)
+ sd s10, 0x70(sp)
+ sd s11, 0x68(sp)
+ fsd fs0, 0x60(sp)
+ fsd fs1, 0x58(sp)
+ fsd fs2, 0x50(sp)
+ fsd fs3, 0x48(sp)
+ fsd fs4, 0x40(sp)
+ fsd fs5, 0x38(sp)
+ fsd fs6, 0x30(sp)
+ fsd fs7, 0x28(sp)
+ fsd fs8, 0x20(sp)
+ fsd fs9, 0x18(sp)
+ fsd fs10, 0x10(sp)
+ fsd fs11, 0x8(sp)
ld t0, -0x10(a0)
sd sp, -0x10(a0)