From 8185b203bef643773d1ce9cf5fdab21ff0868b1d Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Wed, 28 Oct 2015 05:33:47 -0700 Subject: [PATCH] Preserve xmm registers on x86_64 Summary: public `%xmm` registers weren't being preserved what would cause eventual weird issues for methods using floats / doubles / etc. Reviewed By: jspahrsummers Differential Revision: D2581358 fb-gh-sync-id: 701498def0f05716c665f4749e5154b828bf41ec --- React/Profiler/RCTProfileTrampoline-x86_64.S | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/React/Profiler/RCTProfileTrampoline-x86_64.S b/React/Profiler/RCTProfileTrampoline-x86_64.S index 5ac3b52c7..2f9d17786 100644 --- a/React/Profiler/RCTProfileTrampoline-x86_64.S +++ b/React/Profiler/RCTProfileTrampoline-x86_64.S @@ -22,6 +22,15 @@ SYMBOL_NAME(RCTProfileTrampoline): * We have to save %r12 since its value should be preserved across function * calls and we'll use it to keep the stack pointer */ + subq $0x80+8, %rsp // 8 x 16-bytes xmm registers + 8-bytes alignment + movdqa %xmm0, 0x70(%rsp) + movdqa %xmm1, 0x60(%rsp) + movdqa %xmm2, 0x50(%rsp) + movdqa %xmm3, 0x40(%rsp) + movdqa %xmm4, 0x30(%rsp) + movdqa %xmm5, 0x20(%rsp) + movdqa %xmm6, 0x10(%rsp) + movdqa %xmm7, 0x00(%rsp) pushq %rdi pushq %rsi pushq %rdx @@ -82,7 +91,7 @@ SYMBOL_NAME(RCTProfileTrampoline): movq %r14, 0x8(%rax) // mov the pointers we need to the callee saved registers - movq 0x48(%rsp), %r13 // caller of RCTProfileTrampoline + movq 0xd8(%rsp), %r13 // caller of RCTProfileTrampoline (0xd8 is stack top) movq %rax, %r14 // allocated memory's address /** @@ -108,6 +117,15 @@ SYMBOL_NAME(RCTProfileTrampoline): popq %rdx popq %rsi popq %rdi + movdqa 0x00(%rsp), %xmm7 + movdqa 0x10(%rsp), %xmm6 + movdqa 0x20(%rsp), %xmm5 + movdqa 0x30(%rsp), %xmm4 + movdqa 0x40(%rsp), %xmm3 + movdqa 0x50(%rsp), %xmm2 + movdqa 0x60(%rsp), %xmm1 + movdqa 0x70(%rsp), %xmm0 + addq $0x80+8, %rsp /** * delete parent caller (saved in %r13) `call` will add the new address so @@ -118,6 +136,8 @@ SYMBOL_NAME(RCTProfileTrampoline): // call the actual function and save the return value callq *%r11 pushq %rax + subq $0x10+8, %rsp //16-bytes xmm register + 8-bytes for alignment + movdqa %xmm0, (%rsp) // align stack pushq %r12 @@ -131,15 +151,12 @@ SYMBOL_NAME(RCTProfileTrampoline): movq %r12, %rsp popq %r12 - // save the return of the actual function call - popq %rax - /** * Restore the initial value of the callee saved registers, saved in the * memory allocated. */ movq %r13, %rcx - movq %r14, %rdx + movq %r14, %rdi movq 0x0(%r14), %r13 movq 0x8(%r14), %r14 @@ -148,13 +165,11 @@ SYMBOL_NAME(RCTProfileTrampoline): * memory) and align the stack */ pushq %rcx - pushq %rax pushq %r12 movq %rsp, %r12 andq $-0x10, %rsp // Free the memory allocated to stash callee saved registers - movq %rdx, %rdi callq SYMBOL_NAME(free) // unalign stack and restore %r12 @@ -165,8 +180,10 @@ SYMBOL_NAME(RCTProfileTrampoline): * pop the caller address to %rcx and the actual function return value to * %rax, so it's the return value of RCTProfileTrampoline */ - popq %rax popq %rcx + movdqa (%rsp), %xmm0 + addq $0x10+8, %rsp + popq %rax // jump to caller jmpq *%rcx