Get LIBC_RUNTIME and LIBC_CALLS building on aarch64

This commit is contained in:
Justine Tunney 2023-05-09 01:56:56 -07:00
parent 7e46645193
commit e5e3cdf447
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
1200 changed files with 5341 additions and 3677 deletions

View file

@ -21,37 +21,55 @@
// Invokes clone() system call on GNU/Systemd.
//
// @param rdi is flags
// @param rsi is top of stack
// @param rdx is ptid
// @param rcx is ctid
// @param r8 is tls
// @param r9 is func(void*,int)→int
// @param 8(rsp) is arg
// @param rdi x0 is flags
// @param rsi x1 is top of stack
// @param rdx x2 is ptid
// @param rcx x3 is ctid
// @param r8 x4 is tls
// @param r9 x5 is func(void*,int)→int
// @param 8(rsp) x6 is arg
// @return tid of child on success, or -errno on error
sys_clone_linux:
#ifdef __x86_64__
push %rbp
mov %rsp,%rbp
push %rbx
mov %rcx,%r10
mov 16(%rbp),%rbx
mov $56,%eax # __NR_clone
mov $56,%eax // __NR_clone
syscall
test %rax,%rax
jz 2f
0: pop %rbx
pop %rbp
ret
2: xor %ebp,%ebp # child thread
mov %rbx,%rdi # arg
mov %r10,%r15 # experiment
mov (%r10),%esi # tid
call *%r9 # func(arg,tid)
xchg %eax,%edi # func(arg,tid) exitcode
mov (%r15),%eax # experiment
test %eax,%eax # experiment
jz 1f # experiment
mov $60,%eax # __NR_exit(exitcode)
2: xor %ebp,%ebp // child thread
mov %rbx,%rdi // arg
mov %r10,%r15 // experiment
mov (%r10),%esi // tid
call *%r9 // func(arg,tid)
xchg %eax,%edi // func(arg,tid) exitcode
mov (%r15),%eax // experiment
test %eax,%eax // experiment
jz 1f // experiment
mov $60,%eax // __NR_exit(exitcode)
syscall
1: hlt # ctid was corrupted by program!
1: hlt // ctid was corrupted by program!
#elif defined(__aarch64__)
and x1,x1,#-16 // align stack
stp x5,x6,[x1,#-16]! // save func and arg
mov x8,x3 // swap x3 and x4
mov x3,x4 // swap x3 and x4
mov x4,x8 // swap x3 and x4
mov x8,#220 // __NR_clone
svc #0
cbz x0,2f
ret
2: ldp x1,x0,[sp],#16 // child thread
blr x1
mov x8,#93 // __NR_exit
svc #0
#else
#error "unsupported architecture"
#endif
.endfn sys_clone_linux,globl,hidden