From 2f57b0b68876440cef3e3a9276561c55e0f05271 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Fri, 18 Dec 2015 14:43:52 +0000 Subject: [PATCH] Tweak the block trampolines to work with the win64 calling convention (untested!). --- block_trampolines.S | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/block_trampolines.S b/block_trampolines.S index e3ed411..f95d6a0 100644 --- a/block_trampolines.S +++ b/block_trampolines.S @@ -32,14 +32,23 @@ TYPE_DIRECTIVE(CDECL(__objc_block_trampoline), @function) .globl CDECL(__objc_block_trampoline_end) #endif #if __x86_64 +#ifdef _WIN64 +#define ARG0 %rcx +#define ARG1 %rdx +#define ARG2 %r8 +#else +#define ARG0 %rdi +#define ARG1 %rsi +#define ARG2 %rdx +#endif CDECL(__objc_block_trampoline): - mov -15(%rip), %rsi # Load the block pointer into the second argument - xchg %rdi, %rsi # Swap the first and second arguments + mov -15(%rip), ARG1 # Load the block pointer into the second argument + xchg ARG1, ARG0 # Swap the first and second arguments jmp *-32(%rip) # Call the block function CDECL(__objc_block_trampoline_end): CDECL(__objc_block_trampoline_sret): - mov -15(%rip), %rdx # Load the block pointer into the second argument - xchg %rdx, %rsi # Swap the first and second arguments + mov -15(%rip), ARG2 # Load the block pointer into the second argument + xchg ARG1, ARG2 # Swap the first and second arguments jmp *-32(%rip) # Call the block function CDECL(__objc_block_trampoline_end_sret): #elif __i386