Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/asm/jump_arm64_aapcs_macho_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ _jump_fcontext:
stp fp, lr, [sp, #0x90]

; save LR as PC
#if defined(__arm64e__)
; signed with the address of its slot
mov x16, lr
add x17, sp, #0xa0
pacia x16, x17
str x16, [sp, #0xa0]
#else
str lr, [sp, #0xa0]
#endif

; store RSP (pointing to context-data) in X0
mov x4, sp
Expand Down Expand Up @@ -103,8 +111,15 @@ _jump_fcontext:

; load pc
ldr x4, [sp, #0xa0]
#if defined(__arm64e__)
add x17, sp, #0xa0
#endif

; restore stack from GP + FPU
add sp, sp, #0xb0

#if defined(__arm64e__)
braa x4, x17
#else
ret x4
#endif
18 changes: 18 additions & 0 deletions src/asm/make_arm64_aapcs_macho_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,25 @@ _make_fcontext:

; third arg of make_fcontext() == address of context-function
; store address as a PC to jump in
#if defined(__arm64e__)
; authenticate the C function pointer (IA, zero discriminator) and sign it
; with the address of its slot, as jump_fcontext signs a saved PC
mov x16, x2
autiza x16
; trap if authentication failed rather than re-sign a forged pointer,
; as clang does for arm64e
mov x17, x16
xpaci x17
cmp x16, x17
b.eq 1f
brk #0xc470
1:
add x17, x0, #0xa0
pacia x16, x17
str x16, [x0, #0xa0]
#else
str x2, [x0, #0xa0]
#endif

adr x1, finish

Expand Down
13 changes: 13 additions & 0 deletions src/asm/ontop_arm64_aapcs_macho_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ _ontop_fcontext:
stp x29, x30, [sp, #0x90]

; save LR as PC
#if defined(__arm64e__)
; signed with the address of its slot, which jump_fcontext authenticates
mov x16, x30
add x17, sp, #0xa0
pacia x16, x17
str x16, [sp, #0xa0]
#else
str x30, [sp, #0xa0]
#endif

; store RSP (pointing to context-data) in X5
mov x4, sp
Expand Down Expand Up @@ -106,4 +114,9 @@ _ontop_fcontext:
add sp, sp, #0xb0

; jump to ontop-function
#if defined(__arm64e__)
; a C function pointer: IA, zero discriminator
braaz x2
#else
ret x2
#endif