diff --git a/README.adoc b/README.adoc index be68383..fd173df 100644 --- a/README.adoc +++ b/README.adoc @@ -11606,7 +11606,10 @@ and notice how the error message gives both: Other setup sanity checks that you might want to look into include: * link:userland/arch/empty.S[] -* link:userland/arch/fail.S[] +* `FAIL` tests +** link:userland/arch/fail.S[] +* `ASSERT_MEMCMP` tests +** link:userland/arch/x86_64/lkmc_assert_memcmp_fail.S[] === User vs system assembly diff --git a/path_properties.py b/path_properties.py index 5adcc66..49520b1 100644 --- a/path_properties.py +++ b/path_properties.py @@ -341,6 +341,8 @@ path_properties_tuples = ( } ), 'freestanding': freestanding_properties, + 'lkmc_assert_eq_fail.S': {'exit_status': 1}, + 'lkmc_assert_memcmp_fail.S': {'exit_status': 1}, } ), } diff --git a/userland/arch/fail.S b/userland/arch/fail.S index b9d8a01..7102e95 100644 --- a/userland/arch/fail.S +++ b/userland/arch/fail.S @@ -1,4 +1,4 @@ -/* See what happens on test failure. +/* See what happens on test failure with FAIL. * https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly */ diff --git a/userland/arch/x86_64/common_arch.h b/userland/arch/x86_64/common_arch.h index 26e37e4..8992631 100644 --- a/userland/arch/x86_64/common_arch.h +++ b/userland/arch/x86_64/common_arch.h @@ -3,19 +3,6 @@ #ifndef COMMON_ARCH_H #define COMMON_ARCH_H -#if 0 -#define ASSERT_EQ(reg, const) \ - push %rax; \ - push %rbx; \ - mov reg, %rax; \ - mov const, %rbx; \ - cmp %rax, %rbx; \ - pop %rbx; \ - pop %rax; \ - ASSERT(je); \ -; -#endif - #define ASSERT_EQ(reg, const) \ mov reg, %rdi; \ mov const, %rsi; \ @@ -28,11 +15,14 @@ ASSERT(je); \ ; -# TODO -##define ASSERT_MEMCMP(s1, s2, n) \ -# MEMCMP(s1, s2, n); \ -# ASSERT_EQ(x0, 0); \ -#; +#define ASSERT_MEMCMP(label1, label2, const_size) \ + lea label1(%rip), %rdi; \ + lea label2(%rip), %rsi; \ + mov const_size, %rdx; \ + call assert_memcmp; \ + cmp $0, %rax; \ + ASSERT(je); \ +; /* Program entry point. * @@ -90,12 +80,4 @@ pass: \ jmp fail; \ ; -# TODO -##define MEMCMP(s1, s2, n) \ -# adr x0, s1; \ -# adr x1, s2; \ -# ldr x2, =n; \ -# bl memcmp; \ -#; - #endif diff --git a/userland/arch/x86_64/lkmc_assert_eq_fail.S b/userland/arch/x86_64/lkmc_assert_eq_fail.S new file mode 100644 index 0000000..09d0c70 --- /dev/null +++ b/userland/arch/x86_64/lkmc_assert_eq_fail.S @@ -0,0 +1,9 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly */ + +#include "common.h" + +ENTRY + mov $1, %rax + ASSERT_EQ(%rax, $1) + ASSERT_EQ(%rax, $2) +EXIT diff --git a/userland/arch/x86_64/lkmc_assert_memcmp_fail.S b/userland/arch/x86_64/lkmc_assert_memcmp_fail.S new file mode 100644 index 0000000..1723379 --- /dev/null +++ b/userland/arch/x86_64/lkmc_assert_memcmp_fail.S @@ -0,0 +1,12 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly */ + +#include "common.h" + +.data + var0: .long 0x11111111, 0x22222222, 0x33333333, 0x44444444 + var1: .long 0x11111111, 0x22222222, 0x33333333, 0x44444444 + var2: .long 0x11111111, 0x22222223, 0x23333333, 0x44444444 +ENTRY + ASSERT_MEMCMP(var0, var1, $0x10) + ASSERT_MEMCMP(var0, var2, $0x10) +EXIT