From 6e790042f09534dc51ebc074afceb9445ab9b7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Mon, 27 May 2019 00:00:03 +0000 Subject: [PATCH] x86 asm: align stack to 16-bits for abort() call Fixes the failing tests that called abort(). For coincidence, only native tests were failing. Asked at: https://stackoverflow.com/questions/56324948/why-does-calling-the-c-abort-function-from-an-x86-64-assembly-function-lead-to --- README.adoc | 4 +++- lkmc/x86_64.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 1ca5979..a66e5e2 100644 --- a/README.adoc +++ b/README.adoc @@ -11998,6 +11998,8 @@ Examples: * link:lkmc/x86_64.h[] `ENTRY` and `EXIT` +One important catch is that the stack must always be aligned to 16-bits before making calls: https://stackoverflow.com/questions/56324948/why-does-calling-the-c-abort-function-from-an-x86-64-assembly-function-lead-to + Bibliography: * https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI @@ -13434,7 +13436,7 @@ output: .... CPSR.M 0x3 -CPSR.M 0x3 +CPSR.M 0xA CPSR.M 0x3 CurrentEL.EL 0x1 CurrentEL.EL 0x2 diff --git a/lkmc/x86_64.h b/lkmc/x86_64.h index 5ad67fa..de4cce0 100644 --- a/lkmc/x86_64.h +++ b/lkmc/x86_64.h @@ -31,6 +31,7 @@ * https://github.com/cirosantilli/linux-kernel-module-cheat#x86_64-calling-convention */ #define LKMC_EPILOGUE \ + add $8, %rsp; \ pop %rbx; \ pop %r12; \ pop %r13; \ @@ -56,6 +57,7 @@ main: \ push %r13; \ push %r12; \ push %rbx; \ + sub $8, %rsp; \ main_after_prologue: \ ;