On x86, align stack to 16 bytes for all calls to C.
authorTaylor R Campbell <campbell@mumble.net>
Sat, 18 Jun 2011 23:37:06 +0000 (23:37 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Sat, 18 Jun 2011 23:37:59 +0000 (23:37 +0000)
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
src/microcode/cmpauxmd/x86-64.m4

index 9d1273e4dbe83aa36971eb1105c70f42ac9e4700..c77fd3a3348a22c9ef08c62e0d3798d65c6a2198 100644 (file)
@@ -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
index 2ae38405c15195d1ffa17ea92eab58ecedb3fb9d..8f4b3ec393a668b16f75282bd1f12e0415bfa5a8 100644 (file)
@@ -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