Skip to content

Commit e13bfc0

Browse files
coroutine/arm64: Skip saving/restoring x30 twice and use autiasp
We don't need to save/restore x30 twice, and we can just use `ret`, which uses x30 as return address register instead of explicit `ret <reg>` instruction. This also allows us to use `autiasp` instead of `autia1716` and we can skip setting SP/LR to x16/x17. Also the size of register save area is shrunk by 16 bytes due to the removal of extra x30 save/restore.
1 parent 0298eaf commit e13bfc0

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

coroutine/arm64/Context.S

+6-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer):
3636
hint #34
3737
#endif
3838
# Make space on the stack for caller registers
39-
sub sp, sp, 0xb0
39+
sub sp, sp, 0xa0
4040

4141
# Save caller registers
4242
stp d8, d9, [sp, 0x00]
@@ -50,9 +50,6 @@ PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer):
5050
stp x27, x28, [sp, 0x80]
5151
stp x29, x30, [sp, 0x90]
5252

53-
# Save return address
54-
str x30, [sp, 0xa0]
55-
5653
# Save stack pointer to x0 (first argument)
5754
mov x2, sp
5855
str x2, [x0, 0]
@@ -73,20 +70,16 @@ PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer):
7370
ldp x27, x28, [sp, 0x80]
7471
ldp x29, x30, [sp, 0x90]
7572

76-
# Load return address into x17
77-
ldr x17, [sp, 0xa0]
78-
7973
# Pop stack frame
80-
add sp, sp, 0xb0
74+
add sp, sp, 0xa0
8175

8276
#if defined(__ARM_FEATURE_PAC_DEFAULT) && (__ARM_FEATURE_PAC_DEFAULT != 0)
83-
mov x16, sp
84-
# autia1716
85-
hint #12
77+
# autiasp: Authenticate x30 (LR) with SP and key A
78+
hint #29
8679
#endif
8780

88-
# Jump to return address (in x17)
89-
ret x17
81+
# Jump to return address (in x30)
82+
ret
9083

9184
#if defined(__linux__) && defined(__ELF__)
9285
.section .note.GNU-stack,"",%progbits

coroutine/arm64/Context.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#define COROUTINE __attribute__((noreturn)) void
1919

20-
enum {COROUTINE_REGISTERS = 0xb0 / 8};
20+
enum {COROUTINE_REGISTERS = 0xa0 / 8};
2121

2222
#if defined(__SANITIZE_ADDRESS__)
2323
#define COROUTINE_SANITIZE_ADDRESS
@@ -89,7 +89,7 @@ static inline void coroutine_initialize(
8989
context->stack_pointer -= COROUTINE_REGISTERS;
9090
memset(context->stack_pointer, 0, sizeof(void*) * COROUTINE_REGISTERS);
9191

92-
context->stack_pointer[0xa0 / 8] = ptrauth_sign_instruction_addr((void*)start, (void*)top);
92+
context->stack_pointer[0x98 / 8] = ptrauth_sign_instruction_addr((void*)start, (void*)top);
9393
}
9494

9595
struct coroutine_context * coroutine_transfer(struct coroutine_context * current, struct coroutine_context * target);

0 commit comments

Comments
 (0)