Skip to content

Commit 3b77d94

Browse files
committed
CFI improvements to the AArch64 fiber implementation
Now the fiber implementation on AArch64 authenticates function return addresses and includes the relevant BTI instructions. Copyright (c) 2022, Arm Limited.
1 parent 8e2209f commit 3b77d94

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

crates/fiber/src/arch/aarch64.S

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ GLOBL(wasmtime_fiber_switch)
1616
.p2align 2
1717
TYPE(wasmtime_fiber_switch)
1818
FUNCTION(wasmtime_fiber_switch):
19+
#if CFG_TARGET_OS_macos
20+
hint #27 // pacibsp
21+
#else
22+
hint #25 // paciasp
23+
#endif
1924
// Save all callee-saved registers on the stack since we're assuming
2025
// they're clobbered as a result of the stack switch.
2126
stp lr, fp, [sp, -16]!
@@ -48,6 +53,11 @@ FUNCTION(wasmtime_fiber_switch):
4853
ldp x22, x21, [sp], 16
4954
ldp x20, x19, [sp], 16
5055
ldp lr, fp, [sp], 16
56+
#if CFG_TARGET_OS_macos
57+
hint #31 // autibsp
58+
#else
59+
hint #29 // autiasp
60+
#endif
5161
ret
5262
SIZE(wasmtime_fiber_switch)
5363

@@ -61,8 +71,17 @@ GLOBL(wasmtime_fiber_init)
6171
.p2align 2
6272
TYPE(wasmtime_fiber_init)
6373
FUNCTION(wasmtime_fiber_init):
64-
adr x8, FUNCTION(wasmtime_fiber_start)
65-
stp x0, x8, [x0, -0x28] // x0 => x19, x8 => lr
74+
hint #34 // bti c
75+
sub x16, x0, #16
76+
// TODO: Use the PACGA instruction to authenticate the saved register state,
77+
// which avoids creating signed pointers to wasmtime_fiber_start().
78+
adr x17, FUNCTION(wasmtime_fiber_start)
79+
#if CFG_TARGET_OS_macos
80+
hint #10 // pacib1716
81+
#else
82+
hint #8 // pacia1716
83+
#endif
84+
stp x0, x17, [x16, -0x18] // x0 => x19, x17 => lr
6685
stp x2, x1, [x0, -0x38] // x1 => x20, x2 => x21
6786

6887
// `wasmtime_fiber_switch` has an 0xa0 byte stack, and we add 0x10 more for
@@ -87,6 +106,9 @@ FUNCTION(wasmtime_fiber_start):
87106
0x23, 0xa0, 0x1 /* DW_OP_plus_uconst 0xa0 */
88107

89108
.cfi_rel_offset x29, -0x08
109+
#ifndef CFG_TARGET_OS_macos
110+
.cfi_window_save
111+
#endif
90112
.cfi_rel_offset lr, -0x10
91113
.cfi_rel_offset x19, -0x18
92114
.cfi_rel_offset x20, -0x20

0 commit comments

Comments
 (0)