@@ -104,7 +104,7 @@ ENTRY(create_untrusted_stk)
104104 / *
105105 * NON - STANDARD CALLING CONVENTION
106106 *
107- * w19 : Callee's compartment ID
107+ * w13 : Callee's compartment ID
108108 * c26: Callee to be tail - called
109109 *
110110 * The function resolves the callee's stack , installs it , and tail - calls
@@ -123,7 +123,7 @@ ENTRY(create_untrusted_stk)
123123
124124 save_arguments
125125
126- mov w0 , w19
126+ mov w0 , w13
127127 bl resolve_untrusted_stk_impl
128128 mov c10 , c0
129129
@@ -166,16 +166,27 @@ ENTRY(tramp_hook)
166166 *
167167 * c10 - c11 hold the first two arguments of tramp_hook.
168168 *
169- * All argument registers and callee - saved registers must be preserved.
169+ * All argument registers , callee - saved registers , and arguments used
170+ * by the stack resolver must be preserved.
170171 * /
171172
172173 save_arguments
173174
175+ / *
176+ * Save arguments used by the stack resolver.
177+ * /
178+ mov w19 , w13
179+
174180 mov c0 , c10
175181 mov c1 , c11
176182 mrs c2 , TRUSTED_STACK
177183 bl tramp_hook_impl
178184
185+ / *
186+ * Restore arguments used by the stack resolver.
187+ * /
188+ mov w13 , w19
189+
179190 restore_arguments
180191
181192#ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
@@ -217,13 +228,54 @@ TRAMP(tramp_push_frame)
217228 * /
218229 ldp x10 , x11 , [ TRUSTED_STACK_C , #TRUSTED_FRAME_CALLER ]
219230 / *
220- * Get the stack lookup table .
231+ * Extract the caller's compartment ID .
221232 * /
222- mrs STACK_TABLE_C , STACK_TABLE
233+ ubfx x12 , x10 , # 32 , # 16
234+ / *
235+ * Get the callee's compartment ID.
236+ * /
237+ 1 : movz w13 , # 0 / * To be patched at runtime * /
238+
239+ / *
240+ * Tail - call the target if the caller 's and callee' s compartment IDs
241+ * match. Otherwise , go to the middle of the slow path.
242+ * /
243+ cmp w12 , w13
244+ b.ne 5f
245+ / *
246+ * Load the target capability and overwrite c18.
247+ * /
248+ 2 : ldr c18 , # 0 / * To be patched at runtime * /
249+ #ifdef __ARM_MORELLO_PURECAP_BENCHMARK_ABI
250+ br x18
251+ #else
252+ brr c18
253+ #endif
254+
255+ / *
256+ * Entry point of the slow path.
257+ * /
258+ 3 : mrs TRUSTED_STACK_C , TRUSTED_STACK
259+
260+ / *
261+ * Load the caller's compartment ID and the landing address from the
262+ * previous trusted frame.
263+ * /
264+ ldp x10 , x11 , [ TRUSTED_STACK_C , #TRUSTED_FRAME_CALLER ]
223265 / *
224266 * Extract the caller's compartment ID.
225267 * /
226268 ubfx x12 , x10 , # 32 , # 16
269+ / *
270+ * Get the callee's compartment ID.
271+ * /
272+ 4 : movz w13 , # 0 / * To be patched at runtime * /
273+
274+ 5 :
275+ / *
276+ * Get the stack lookup table.
277+ * /
278+ mrs STACK_TABLE_C , STACK_TABLE
227279 / *
228280 * Load the caller's old stack top from the stack lookup table.
229281 * /
@@ -239,21 +291,17 @@ TRAMP(tramp_push_frame)
239291 / *
240292 * Get the length of the stack lookup table.
241293 * /
242- gclen x13 , STACK_TABLE_C
294+ gclen x14 , STACK_TABLE_C
243295
244296 stp c19 , c20 , [ TRUSTED_STACK_C , #( - CAP_WIDTH * TRUSTED_FRAME_SIZE + CAP_WIDTH * 2 ) ]
245- / *
246- * Get the callee's compartment ID.
247- * /
248- 1 : movz w19 , # 0 / * To be patched at runtime * /
249297 / *
250298 * Use subs instead of cmp to clear a capability tag.
251299 * /
252- subs x14 , x13 , x19
300+ subs x19 , x14 , x13
253301 / *
254302 * If the stack lookup table index is out - of - bounds , set it to zero.
255303 * /
256- csel w20 , w19 , wzr , hi
304+ csel w20 , w13 , wzr , hi
257305 / *
258306 * Load the callee's stack if the stack lookup table index is within
259307 * bounds. Otherwise the resolver will be loaded.
@@ -288,18 +336,18 @@ TRAMP(tramp_push_frame)
288336 / *
289337 * Get the landing address.
290338 * /
291- 2 : adr c24 , # 0 / * To be patched at runtime * /
339+ 6 : adr c24 , # 0 / * To be patched at runtime * /
292340
293341 stp c25 , c26 , [ TRUSTED_STACK_C , #( - CAP_WIDTH * TRUSTED_FRAME_SIZE + CAP_WIDTH * 8 ) ]
294342 / *
295343 * Compute the number of return value registers. If the call is a tail -
296344 * call , it is the minimum of th at of the caller and the callee.
297345 * /
298- 3 : ubfm x25 , x23 , # 48 , # 0 / * To be patched at runtime * /
346+ 7 : ubfm x25 , x23 , # 48 , # 0 / * To be patched at runtime * /
299347 / *
300348 * Load the target capability.
301349 * /
302- 4 : ldr c26 , # 0 / * To be patched at runtime * /
350+ 8 : ldr c26 , # 0 / * To be patched at runtime * /
303351
304352 / *
305353 * Save the caller's current stack top and old stack top.
@@ -347,10 +395,10 @@ TRAMP(tramp_push_frame)
347395 * /
348396 str x24 , [ TRUSTED_STACK_C , #TRUSTED_FRAME_LANDING ]
349397 / *
350- * Combine the caller 's compartment ID and the number of return value
398+ * Combine the callee 's compartment ID and the number of return value
351399 * registers.
352400 * /
353- orr w24 , w19 , w25 , lsl # 16
401+ orr w24 , w13 , w25 , lsl # 16
354402 / *
355403 * Save the callee's compartment ID and the number of return value
356404 * registers.
@@ -369,10 +417,20 @@ TRAMP(tramp_push_frame)
369417 set_untrusted_stk c15
370418TRAMPEND(tramp_push_frame)
371419
372- PATCH_POINT(tramp_push_frame , cid , 1b )
373- PATCH_POINT(tramp_push_frame , landing , 2b)
374- PATCH_POINT(tramp_push_frame , n_rets , 3b)
375- PATCH_POINT(tramp_push_frame , target , 4b)
420+ PATCH_POINT(tramp_push_frame , cid_fast , 1b )
421+ PATCH_POINT(tramp_push_frame , target_fast , 2b)
422+ PATCH_POINT(tramp_push_frame , cid , 4b)
423+ PATCH_POINT(tramp_push_frame , landing , 6b)
424+ PATCH_POINT(tramp_push_frame , n_rets , 7b)
425+ PATCH_POINT(tramp_push_frame , target , 8b)
426+
427+ . section .rodata
428+ .globl c18n_tramp_entry_slow_offset
429+ .balign 8
430+ .type c18n_tramp_entry_slow_offset , %object
431+ c18n_tramp_entry_slow_offset:
432+ .quad 3b - tramp_push_frame
433+ .size c18n_tramp_entry_slow_offset , . - c18n_tramp_entry_slow_offset
376434
377435/ *
378436 * Save the address of the current frame to c29 so th at unwinders can locate it.
0 commit comments