Alex Rønne Petersen c666ebb1f8
musl: Add unwinding protection in clone() implementations.
Whatever was in the frame pointer register prior to clone() will no longer be
valid in the child process, so zero it to protect FP-based unwinders. This is
just an extension of what was already done for i386 and x86_64. Only applied
to architectures where the _start() code also zeroes the frame pointer.
2024-12-11 00:10:17 +01:00

36 lines
762 B
ArmAsm
Vendored

.set noreorder
.global __clone
.hidden __clone
.type __clone,@function
__clone:
# Save function pointer and argument pointer on new thread stack
and $5, $5, -16 # aligning stack to double word
subu $5, $5, 16
sw $4, 0($5) # save function pointer
sw $7, 4($5) # save argument pointer
# Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
# sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls)
move $4, $6
move $6, $8
move $7, $9
move $8, $10
li $2, 6055
syscall
beq $7, $0, 1f
nop
jr $ra
subu $2, $0, $2
1: beq $2, $0, 1f
nop
jr $ra
nop
1: move $fp, $0
lw $25, 0($sp) # function pointer
lw $4, 4($sp) # argument pointer
jalr $25 # call the user's function
nop
move $4, $2
li $2, 6058
syscall