From b6032515a058fb02c8c4152c9f055bb3bd462ae2 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 12 Feb 2013 23:02:33 -0800 Subject: [PATCH] Fix __pthread_clone and __bionic_clone error handling on x86. Bug: 3461078 Change-Id: I93c151e27411211dd32717f206745c62c08c21ee --- libc/arch-x86/bionic/clone.S | 40 +++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) 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