Skip to content

Commit

Permalink
switcher: shave trusted_stack_exhausted
Browse files Browse the repository at this point in the history
While we can't easily reuse the spill frame restore in
switcher_after_compartment_call, due to its interplay with the SHWM and
zeroing invariants, we can reuse .Lswitch_callee_dead_zeros.  This saves
a few bytes at the cost of a jump on an error path.
  • Loading branch information
nwf committed Nov 26, 2024
1 parent c9ac3fa commit 29bed5e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions sdk/core/switcher/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,18 @@ switcher_after_compartment_call:
#endif

// Zero all registers not holding state intended for caller; see atlas below
//.Lswitch_callee_dead_zeros:
.Lswitch_callee_dead_zeros:
/*
* FROM: above
* FROM: .Lswitch_trusted_stack_exhausted
* LIVE IN: mtdc, ra, sp, gp, s0, s1, a0, a1
*
* Atlas:
* mtdc: pointer to this thread's TrustedStack
* a0, a1: return value(s)
* ra, sp, gp, s0, s1: caller state
* tp, t0, t1, t2, a2, a3, a4, a5: dead (to be zeroed here)
*/
zeroAllRegistersExcept ra, sp, gp, s0, s1, a0, a1
.Lswitch_just_return:
/*
Expand Down Expand Up @@ -857,11 +868,10 @@ switcher_after_compartment_call:
clc cra, SPILL_SLOT_pcc(csp)
clc cgp, SPILL_SLOT_cgp(csp)
cincoffset csp, csp, SPILL_SLOT_SIZE
// Set the first return register (a0) and zero the other (a1) below
// Set the first return register (a0) and zero the other (a1)
li a0, -ENOTENOUGHTRUSTEDSTACK
// Zero everything else
zeroAllRegistersExcept ra, sp, gp, s0, s1, a0
cret
zeroOne a1
j .Lswitch_callee_dead_zeros

.size compartment_switcher_entry, . - compartment_switcher_entry

Expand Down

0 comments on commit 29bed5e

Please sign in to comment.