diff --git a/libexec/rtld-elf/aarch64/rtld_c18n_asm.S b/libexec/rtld-elf/aarch64/rtld_c18n_asm.S index 4c9d29b97e93..23cdfc9fc41f 100644 --- a/libexec/rtld-elf/aarch64/rtld_c18n_asm.S +++ b/libexec/rtld-elf/aarch64/rtld_c18n_asm.S @@ -30,6 +30,15 @@ #include "rtld_c18n_machdep.h" #undef IN_ASM +ENTRY(_rtld_unw_getcontext_epilogue) + /* + * FIXME: llvm-libunwind specific ABI. This should be better specified. + */ + mov c2, csp + str c2, [c1] + RETURN +END(_rtld_unw_getcontext_epilogue) + ENTRY(_rtld_unw_setcontext_epilogue) /* * FIXME: llvm-libunwind specific ABI. This should be better specified. diff --git a/libexec/rtld-elf/rtld_c18n.c b/libexec/rtld-elf/rtld_c18n.c index 244bda37599e..c584f0e24235 100644 --- a/libexec/rtld-elf/rtld_c18n.c +++ b/libexec/rtld-elf/rtld_c18n.c @@ -827,6 +827,13 @@ resolve_untrusted_stk_impl(stk_table_index index) /* * Stack unwinding */ +/* + * Assembly functions that are tail-called when compartmentalisation is + * disabled. + */ +uintptr_t _rtld_unw_getcontext_epilogue(uintptr_t, void **); +struct jmp_args _rtld_unw_setcontext_epilogue(struct jmp_args, void *, void **); + static void * unwind_cursor() { @@ -859,6 +866,10 @@ _rtld_setjmp(uintptr_t ret, void **buf) uintptr_t _rtld_unw_getcontext(uintptr_t ret, void **buf) { + if (!C18N_ENABLED) { + __attribute__((musttail)) + return (_rtld_unw_getcontext_epilogue(ret, buf)); + } *buf = cheri_seal(unwind_cursor(), sealer_unwbuf); return (ret); } @@ -866,6 +877,10 @@ _rtld_unw_getcontext(uintptr_t ret, void **buf) uintptr_t _rtld_unw_getcontext_unsealed(uintptr_t ret, void **buf) { + if (!C18N_ENABLED) { + __attribute__((musttail)) + return (_rtld_unw_getcontext_epilogue(ret, buf)); + } *buf = unwind_cursor(); return (ret); } @@ -973,13 +988,6 @@ _rtld_longjmp(struct jmp_args ret, void *rcsp, void **buf) return (unwind_stack(ret, rcsp, cheri_unseal(*buf, sealer_jmpbuf))); } -/* - * An assembly function that is called to complete the unwind when - * compartmentalisation is disabled. The call must be a tail-call so that - * registers are not clobbered. - */ -struct jmp_args _rtld_unw_setcontext_epilogue(struct jmp_args, void *, void **); - struct jmp_args _rtld_unw_setcontext(struct jmp_args ret, void *rcsp, void **buf) {