From 08541b68f7c6a8bb74d4318d59bc0940ef2d0ca4 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Tue, 29 Sep 2015 17:05:58 +0200 Subject: [PATCH] dde_linux: stack alignment on x86_64 in wifi/usb platform_execute() is used to initially switch the stack of a routine/task. While Thread_base::alloc_secondary_stack() properly aligns the returned stack pointer the x86_64 assembler implementation did not comply to stack frame management specified in the ABI. The used (and most simple) stack-alignment check may pass a float to a varargs function on x86, which requires the compiler to properly save some XMM registers on stack. --- .../usb/include/spec/x86_64/platform/platform.h | 14 +++++++++----- .../wifi/include/spec/x86_64/platform/platform.h | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/repos/dde_linux/src/lib/usb/include/spec/x86_64/platform/platform.h b/repos/dde_linux/src/lib/usb/include/spec/x86_64/platform/platform.h index e2f477a59..77fe1601f 100644 --- a/repos/dde_linux/src/lib/usb/include/spec/x86_64/platform/platform.h +++ b/repos/dde_linux/src/lib/usb/include/spec/x86_64/platform/platform.h @@ -20,11 +20,15 @@ static inline void platform_execute(void *sp, void *func, void *arg) { - asm volatile ("movq %2, %%rdi;" - "movq %1, 0(%0);" - "movq %0, %%rsp;" - "call *0(%%rsp);" - : "+r" (sp), "+r" (func), "+r" (arg) : : "memory"); + asm volatile ("movq %0, %%rsp;" /* load stack pointer */ + "movq %%rsp, %%rbp;" /* caller stack frame (for GDB debugging) */ + "movq %0, -8(%%rbp);" + "movq %1, -16(%%rbp);" + "movq %2, -24(%%rbp);" + "sub $24, %%rsp;" /* adjust to next stack frame */ + "movq %2, %%rdi;" /* 1st argument */ + "call *-16(%%rbp);" /* call func */ + : : "r" (sp), "r" (func), "r" (arg)); } #endif /* _X86_64__PLATFORM_H_ */ diff --git a/repos/dde_linux/src/lib/wifi/include/spec/x86_64/platform/platform.h b/repos/dde_linux/src/lib/wifi/include/spec/x86_64/platform/platform.h index 13a367d20..f31b72257 100644 --- a/repos/dde_linux/src/lib/wifi/include/spec/x86_64/platform/platform.h +++ b/repos/dde_linux/src/lib/wifi/include/spec/x86_64/platform/platform.h @@ -19,11 +19,15 @@ static inline void platform_execute(void *sp, void *func, void *arg) { - asm volatile ("movq %2, %%rdi;" - "movq %1, 0(%0);" - "movq %0, %%rsp;" - "call *0(%%rsp);" - : "+r" (sp), "+r" (func), "+r" (arg) : : "memory"); + asm volatile ("movq %0, %%rsp;" /* load stack pointer */ + "movq %%rsp, %%rbp;" /* caller stack frame (for GDB debugging) */ + "movq %0, -8(%%rbp);" + "movq %1, -16(%%rbp);" + "movq %2, -24(%%rbp);" + "sub $24, %%rsp;" /* adjust to next stack frame */ + "movq %2, %%rdi;" /* 1st argument */ + "call *-16(%%rbp);" /* call func */ + : : "r" (sp), "r" (func), "r" (arg)); } #endif /* _X86_64__PLATFORM_H_ */