From 938f38daee0549748974ca00960241fec1506299 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 17 Oct 2013 22:22:31 -0700 Subject: [PATCH] Fix clone.S for x86_64. We need to pull the arguments off the child stack and put them into the registers they're expected to be in. Change-Id: I064b3258cdd89d513c632857cabb46e52492af2b --- libc/arch-x86_64/bionic/clone.S | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/libc/arch-x86_64/bionic/clone.S b/libc/arch-x86_64/bionic/clone.S index df2929eba..a9adeaacc 100644 --- a/libc/arch-x86_64/bionic/clone.S +++ b/libc/arch-x86_64/bionic/clone.S @@ -31,24 +31,24 @@ // int __pthread_clone(void* (*fn)(void*), void* tls, int flags, void* arg); ENTRY(__pthread_clone) - # save tls + # Save tls. movq %rsi, %r11 - # 16-byte alignment on child stack + # 16-byte alignment for child stack. andq $~15, %rsi - # insert arguments onto the child stack - movq %rdi, -32(%rsi) - movq %rcx, -24(%rsi) - movq %r11, -16(%rsi) - + # Copy arguments onto the child stack. + movq %rdi, -32(%rsi) # fn + movq %rcx, -24(%rsi) # arg + movq %r11, -16(%rsi) # tls subq $32, %rsi + movq %rdx, %rdi movl $__NR_clone, %eax syscall testl %eax, %eax jns 1f - # an error occurred, set errno and return -1 + # An error occurred, set errno and return -1. negl %eax movl %eax, %edi call __set_errno @@ -57,9 +57,12 @@ ENTRY(__pthread_clone) 1: jnz 2f - # we're in the child thread now, call __thread_entry - # with the appropriate arguments on the child stack - # we already placed most of them + # We're in the child thread now, call __thread_entry + # with the arguments from the child stack moved into + # the appropriate registers. + popq %rdi + popq %rsi + popq %rdx call __thread_entry hlt 2: @@ -103,6 +106,7 @@ ENTRY(__bionic_clone) # we're in the child now, call __bionic_clone_entry # with the appropriate arguments on the child stack # we already placed most of them + # TODO: write a test for __bionic_clone and then fix this too (see above). call __bionic_clone_entry hlt