From 79026f35510cdc7ad676194a3fe33859b604f9a7 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 18 Jun 2011 23:37:06 +0000 Subject: [PATCH] On x86, align stack to 16 bytes for all calls to C. Should fix random hangs on Mac OS X, whose ABI requires 16-byte stack alignment. Should be harmless on other operating systems. --- src/microcode/cmpauxmd/i386.m4 | 6 ++++++ src/microcode/cmpauxmd/x86-64.m4 | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/microcode/cmpauxmd/i386.m4 b/src/microcode/cmpauxmd/i386.m4 index 9d1273e4d..c77fd3a33 100644 --- a/src/microcode/cmpauxmd/i386.m4 +++ b/src/microcode/cmpauxmd/i386.m4 @@ -559,12 +559,17 @@ define_c_label(within_c_stack) OP(push,l) REG(ebp) # Save frame pointer OP(mov,l) TW(REG(esp),REG(ebp)) OP(mov,l) TW(REG(eax),REG(esp)) # Switch to C stack + OP(mov,l) TW(IMM(0),EVR(C_Stack_Pointer)) + OP(push,l) IMM(0) # Align sp to 16 bytes OP(push,l) REG(ebp) # Save stack pointer OP(push,l) LOF(HEX(c),REG(ebp)) # Push argument call IJMP(LOF(8,REG(ebp))) # Call function define_debugging_label(within_c_stack_restore) OP(pop,l) REG(eax) # Pop argument + OP(mov,l) TW(REG(esp),REG(eax)) # Restore C stack ptr + OP(add,l) TW(IMM(8),REG(eax)) + OP(mov,l) TW(REG(eax),EVR(C_Stack_Pointer)) OP(pop,l) REG(esp) # Restore stack pointer # and switch back to # Scheme stack @@ -574,6 +579,7 @@ define_debugging_label(within_c_stack_restore) define_debugging_label(within_c_stack_from_c) OP(push,l) REG(ebp) # Save a frame pointer, OP(mov,l) TW(REG(esp),REG(ebp)) # for debuggers. + OP(push,l) IMM(0) # Align sp to 16 bytes OP(push,l) LOF(HEX(c),REG(ebp)) # Push argument call IJMP(LOF(8,REG(ebp))) leave diff --git a/src/microcode/cmpauxmd/x86-64.m4 b/src/microcode/cmpauxmd/x86-64.m4 index 2ae38405c..8f4b3ec39 100644 --- a/src/microcode/cmpauxmd/x86-64.m4 +++ b/src/microcode/cmpauxmd/x86-64.m4 @@ -392,12 +392,17 @@ define_c_label(within_c_stack) OP(push,q) REG(rbp) # Save frame pointer OP(mov,q) TW(REG(rsp),REG(rbp)) OP(mov,q) TW(REG(rax),REG(rsp)) # Switch to C stack + OP(mov,q) TW(IMM(0),ABS(EVR(C_Stack_Pointer))) + OP(push,q) IMM(0) # Align sp to 16 bytes OP(push,q) REG(rbp) # Save stack pointer OP(mov,q) TW(REG(rdi),REG(rax)) # arg1 (fn) -> rax OP(mov,q) TW(REG(rsi),REG(rdi)) # arg2 (arg) -> arg1 call IJMP(REG(rax)) # call fn(arg) define_debugging_label(within_c_stack_restore) + OP(mov,q) TW(REG(rsp),REG(rax)) # Restore C stack ptr + OP(add,q) TW(IMM(16),REG(rax)) + OP(mov,q) TW(REG(rax),ABS(EVR(C_Stack_Pointer))) OP(pop,q) REG(rsp) # Restore stack pointer # and switch back to # Scheme stack -- 2.25.1