diff --git a/libc/arch-x86/bionic/clone.S b/libc/arch-x86/bionic/clone.S index 6f84724c3..e7bc3eec0 100644 --- a/libc/arch-x86/bionic/clone.S +++ b/libc/arch-x86/bionic/clone.S @@ -21,27 +21,33 @@ ENTRY(__pthread_clone) 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 - -1: - jnz 2f + jmp pc_return +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 @@ ENTRY(__bionic_clone) 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 - -1: - jnz 2f + jmp bc_return +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