Fix __pthread_clone and __bionic_clone error handling on x86.
Bug: 3461078
Change-Id: I93c151e27411211dd32717f206745c62c08c21ee
diff --git a/libc/arch-x86/bionic/clone.S b/libc/arch-x86/bionic/clone.S
index 6f84724..e7bc3ee 100644
--- a/libc/arch-x86/bionic/clone.S
+++ b/libc/arch-x86/bionic/clone.S
@@ -21,27 +21,33 @@
subl $16, %ecx
movl 20(%esp), %ebx
+
+ # make system call
movl $__NR_clone, %eax
int $0x80
- test %eax, %eax
- jns 1f
+
+ cmpl $0, %eax
+ je pc_child
+ jg pc_parent
# an error occurred, set errno and return -1
negl %eax
+ pushl %eax
call __set_errno
+ addl $4, %esp
orl $-1, %eax
- jmp 2f
+ jmp pc_return
-1:
- jnz 2f
-
+pc_child:
# we're in the child thread now, call __thread_entry
# with the appropriate arguments on the child stack
# we already placed most of them
call __thread_entry
hlt
-2:
+pc_parent:
+ # we're the parent; nothing to do.
+pc_return:
popl %ecx
popl %ebx
ret
@@ -75,27 +81,33 @@
movl 24(%esp), %edx
movl 32(%esp), %esi
movl 28(%esp), %edi
+
+ # make system call
movl $__NR_clone, %eax
int $0x80
- test %eax, %eax
- jns 1f
+
+ cmpl $0, %eax
+ je bc_child
+ jg bc_parent
# an error occurred, set errno and return -1
negl %eax
+ pushl %eax
call __set_errno
+ addl $4, %esp
orl $-1, %eax
- jmp 2f
+ jmp bc_return
-1:
- jnz 2f
-
+bc_child:
# we're in the child now, call __bionic_clone_entry
# with the appropriate arguments on the child stack
# we already placed most of them
call __bionic_clone_entry
hlt
-2:
+bc_parent:
+ # we're the parent; nothing to do.
+bc_return:
popl %edi
popl %esi
popl %ebx