Files
linux-kernel-module-cheat/lkmc/x86_64.h
Ciro Santilli 六四事件 法轮功 6e790042f0 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
2019-05-27 00:00:03 +00:00

65 lines
1.3 KiB
C

#ifndef LKMC_X86_64_H
#define LKMC_X86_64_H
/* This and other macros may make C function calls, and therefore can destroy
* non-callee saved registers. */
#define LKMC_ASSERT_EQ(general1, general2) \
mov general2, %rdi; \
push %rdi; \
mov general1, %rdi; \
pop %rsi; \
mov $__LINE__, %edx; \
call lkmc_assert_eq_64; \
;
#define LKMC_ASSERT_FAIL \
mov $__LINE__, %edi; \
call lkmc_assert_fail; \
;
/* Assert that two memory arrays are the same. */
#define LKMC_ASSERT_MEMCMP(label1, label2, const_size) \
lea label1(%rip), %rdi; \
lea label2(%rip), %rsi; \
mov const_size, %rdx; \
mov $__LINE__, %ecx; \
call lkmc_assert_memcmp; \
;
/* Function epilogue.
*
* https://github.com/cirosantilli/linux-kernel-module-cheat#x86_64-calling-convention
*/
#define LKMC_EPILOGUE \
add $8, %rsp; \
pop %rbx; \
pop %r12; \
pop %r13; \
pop %r14; \
pop %r15; \
pop %rbp; \
mov $0, %rax; \
ret; \
;
/* Function prologue.
*
* https://github.com/cirosantilli/linux-kernel-module-cheat#x86_64-calling-convention
*/
#define LKMC_PROLOGUE \
.text; \
.global main; \
main: \
push %rbp; \
mov %rsp, %rbp; \
push %r15; \
push %r14; \
push %r13; \
push %r12; \
push %rbx; \
sub $8, %rsp; \
main_after_prologue: \
;
#endif