From e286649f08a6312ba3d88aa3eafa179ec3eab163 Mon Sep 17 00:00:00 2001 From: Niels Dossche Date: Wed, 25 Jan 2023 22:07:30 +0100 Subject: [PATCH] Make sure the i386 sysv stack is aligned SysV ABI requires a stack alignment of 16 bytes. Currently, for i386 with SysV ABI, the trampoline function is entered with an unaligned stack. This causes problems for the context-function that is jumped to as its stack is also unaligned. This causes a crash for our use-case because the context function contains an SSE instruction which reads from the stack. The SSE instruction requires the correct alignment. Fix it by changing the 0x2c offset to 0x30, such that the stack remains aligned. --- src/asm/make_i386_sysv_elf_gas.S | 4 ++-- src/asm/make_i386_sysv_macho_gas.S | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/asm/make_i386_sysv_elf_gas.S b/src/asm/make_i386_sysv_elf_gas.S index 0b7ab811..d945c0b2 100644 --- a/src/asm/make_i386_sysv_elf_gas.S +++ b/src/asm/make_i386_sysv_elf_gas.S @@ -40,8 +40,8 @@ make_fcontext: /* shift address in EAX to lower 16 byte boundary */ andl $-16, %eax - /* reserve space for context-data on context-stack */ - leal -0x2c(%eax), %eax + /* reserve space for context-data on context-stack, and align the stack */ + leal -0x30(%eax), %eax /* third arg of make_fcontext() == address of context-function */ /* stored in EBX */ diff --git a/src/asm/make_i386_sysv_macho_gas.S b/src/asm/make_i386_sysv_macho_gas.S index fdcdb7c8..98e23a6e 100644 --- a/src/asm/make_i386_sysv_macho_gas.S +++ b/src/asm/make_i386_sysv_macho_gas.S @@ -38,8 +38,8 @@ _make_fcontext: /* shift address in EAX to lower 16 byte boundary */ andl $-16, %eax - /* reserve space for context-data on context-stack */ - leal -0x2c(%eax), %eax + /* reserve space for context-data on context-stack, and align the stack */ + leal -0x30(%eax), %eax /* third arg of make_fcontext() == address of context-function */ /* stored in EBX */