Clean up forking and cloning.
The kernel now maintains the pthread_internal_t::tid field for us,
and __clone was only used in one place so let's inline it so we don't
have to leave such a dangerous function lying around. Also rename
files to match their content and remove some useless #includes.
Change-Id: I24299fb4a940e394de75f864ee36fdabbd9438f9
diff --git a/libc/arch-x86_64/bionic/clone.S b/libc/arch-x86_64/bionic/__bionic_clone.S
similarity index 91%
rename from libc/arch-x86_64/bionic/clone.S
rename to libc/arch-x86_64/bionic/__bionic_clone.S
index b37416b..309c365 100644
--- a/libc/arch-x86_64/bionic/clone.S
+++ b/libc/arch-x86_64/bionic/__bionic_clone.S
@@ -40,8 +40,13 @@
movq %rax, -8(%rsi) # Write 'arg'.
subq $16, %rsi
+
+ # Translate to the kernel calling convention and swap the 'tls' and 'child_tid' arguments.
+ # They're flipped for x86-64 compared to all our other architectures and __bionic_clone.
movq %r8, %r10
movq %rcx, %r8
+
+ # Make the system call.
movl $__NR_clone, %eax
syscall
testl %eax, %eax
diff --git a/libc/arch-x86_64/syscalls.mk b/libc/arch-x86_64/syscalls.mk
index 50d9ab3..9e2bfcc 100644
--- a/libc/arch-x86_64/syscalls.mk
+++ b/libc/arch-x86_64/syscalls.mk
@@ -2,7 +2,6 @@
syscall_src :=
syscall_src += arch-x86_64/syscalls/__arch_prctl.S
syscall_src += arch-x86_64/syscalls/__brk.S
-syscall_src += arch-x86_64/syscalls/__clone.S
syscall_src += arch-x86_64/syscalls/__epoll_pwait.S
syscall_src += arch-x86_64/syscalls/__exit.S
syscall_src += arch-x86_64/syscalls/__getcpu.S
diff --git a/libc/arch-x86_64/syscalls/__clone.S b/libc/arch-x86_64/syscalls/__clone.S
deleted file mode 100644
index 4999762..0000000
--- a/libc/arch-x86_64/syscalls/__clone.S
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__clone)
- movq %rcx, %r10
- movl $__NR_clone, %eax
- syscall
- cmpq $-MAX_ERRNO, %rax
- jb 1f
- negl %eax
- movl %eax, %edi
- call __set_errno
- orq $-1, %rax
-1:
- ret
-END(__clone)
-.hidden _C_LABEL(__clone)
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
index 4f833c1..2614537 100644
--- a/libc/arch-x86_64/x86_64.mk
+++ b/libc/arch-x86_64/x86_64.mk
@@ -1,5 +1,5 @@
_LIBC_ARCH_COMMON_SRC_FILES := \
- arch-x86_64/bionic/clone.S \
+ arch-x86_64/bionic/__bionic_clone.S \
arch-x86_64/bionic/_exit_with_stack_teardown.S \
arch-x86_64/bionic/futex_x86_64.S \
arch-x86_64/bionic/__get_sp.S \