Skip to content

Commit

Permalink
c18n: Remove assembly wrappers for _rtld_{setjmp,longjmp,unw_*}
Browse files Browse the repository at this point in the history
Instead, use the get_trusted_frame macro to obtain the trusted frame in
C.
  • Loading branch information
dpgao authored and dstolfa committed Mar 26, 2024
1 parent 716966f commit 8d29f2c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 203 deletions.
5 changes: 2 additions & 3 deletions lib/libc/aarch64/gen/_setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ENTRY(_longjmp)
/* Restore the stack pointer */
ldr REG(8), [REG(0)], #(REG_WIDTH)
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
mov c3, c8
mov c2, c8
#else
mov REGN(sp), REG(8)
#endif
Expand All @@ -105,12 +105,11 @@ ENTRY(_longjmp)

/* Load the return value */
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
mov c4, c0
mov c3, c0
#endif
cmp x1, #0
csinc x0, x1, xzr, ne
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
mov c1, c4
/*
* Tail-call to restore Executive mode state
*/
Expand Down
5 changes: 2 additions & 3 deletions lib/libc/aarch64/gen/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ENTRY(longjmp)
/* Restore the stack pointer */
ldr REG(8), [REG(0)], #(REG_WIDTH)
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
mov c3, c8
mov c2, c8
#else
mov REGN(sp), REG(8)
#endif
Expand All @@ -132,12 +132,11 @@ ENTRY(longjmp)

/* Load the return value */
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
mov c4, c0
mov c3, c0
#endif
cmp x1, #0
csinc x0, x1, xzr, ne
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
mov c1, c4
/*
* Tail-call to restore Executive mode state
*/
Expand Down
74 changes: 0 additions & 74 deletions libexec/rtld-elf/aarch64/rtld_c18n_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,6 @@
#include "rtld_c18n_machdep.h"
#undef IN_ASM

ENTRY(_rtld_setjmp)
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
mrs c2, rcsp_el0
#else
mov c2, csp
#endif
/*
* This function MUST preserve the value of c0 and clear unused return
* value registers.
*/
b _rtld_setjmp_impl
END(_rtld_setjmp)

ENTRY(_rtld_longjmp)
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
mrs c2, rcsp_el0
#else
mov c2, csp
#endif
/*
* This function MUST preserve the value of c0 and clear unused return
* value registers.
*/
b _rtld_longjmp_impl
END(_rtld_longjmp)

ENTRY(_rtld_thread_start)
mov c1, csp
sub csp, csp, #(CAP_WIDTH * 2)
Expand Down Expand Up @@ -304,54 +278,6 @@ ENTRY(tramp_hook)
#endif
END(tramp_hook)

ENTRY(_rtld_unw_getcontext)
/*
* This function MUST preserve the value of c0.
*/
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
mrs c2, rcsp_el0
#else
mov c2, csp
#endif
b _rtld_unw_getcontext_impl
END(_rtld_unw_getcontext)

ENTRY(_rtld_unw_setcontext)
/*
* This function MUST preserve the value of c0, c1.
*/
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
mrs c2, rcsp_el0
#else
mov c2, csp
#endif
b _rtld_unw_resume
END(_rtld_unw_setcontext)

ENTRY(_rtld_unw_getcontext_unsealed)
/*
* This function MUST preserve the value of c0.
*/
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
mrs c2, rcsp_el0
#else
mov c2, csp
#endif
b _rtld_unw_getcontext_impl_unsealed
END(_rtld_unw_getcontext)

ENTRY(_rtld_unw_setcontext_unsealed)
/*
* This function MUST preserve the value of c0, c1.
*/
#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
mrs c2, rcsp_el0
#else
mov c2, csp
#endif
b _rtld_unw_resume_unsealed
END(_rtld_unw_setcontext)

/*
* Trampoline templates are code but reside in rodata. Hence a new macro is
* defined to describe them.
Expand Down
Loading

0 comments on commit 8d29f2c

Please sign in to comment.