mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-27 12:04:27 +01:00
userland x86_64: implement ASSERT_MEMCMP
This commit is contained in:
@@ -11606,7 +11606,10 @@ and notice how the error message gives both:
|
|||||||
Other setup sanity checks that you might want to look into include:
|
Other setup sanity checks that you might want to look into include:
|
||||||
|
|
||||||
* link:userland/arch/empty.S[]
|
* 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
|
=== User vs system assembly
|
||||||
|
|
||||||
|
|||||||
@@ -341,6 +341,8 @@ path_properties_tuples = (
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
'freestanding': freestanding_properties,
|
'freestanding': freestanding_properties,
|
||||||
|
'lkmc_assert_eq_fail.S': {'exit_status': 1},
|
||||||
|
'lkmc_assert_memcmp_fail.S': {'exit_status': 1},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
* https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -3,19 +3,6 @@
|
|||||||
#ifndef COMMON_ARCH_H
|
#ifndef COMMON_ARCH_H
|
||||||
#define 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) \
|
#define ASSERT_EQ(reg, const) \
|
||||||
mov reg, %rdi; \
|
mov reg, %rdi; \
|
||||||
mov const, %rsi; \
|
mov const, %rsi; \
|
||||||
@@ -28,11 +15,14 @@
|
|||||||
ASSERT(je); \
|
ASSERT(je); \
|
||||||
;
|
;
|
||||||
|
|
||||||
# TODO
|
#define ASSERT_MEMCMP(label1, label2, const_size) \
|
||||||
##define ASSERT_MEMCMP(s1, s2, n) \
|
lea label1(%rip), %rdi; \
|
||||||
# MEMCMP(s1, s2, n); \
|
lea label2(%rip), %rsi; \
|
||||||
# ASSERT_EQ(x0, 0); \
|
mov const_size, %rdx; \
|
||||||
#;
|
call assert_memcmp; \
|
||||||
|
cmp $0, %rax; \
|
||||||
|
ASSERT(je); \
|
||||||
|
;
|
||||||
|
|
||||||
/* Program entry point.
|
/* Program entry point.
|
||||||
*
|
*
|
||||||
@@ -90,12 +80,4 @@ pass: \
|
|||||||
jmp fail; \
|
jmp fail; \
|
||||||
;
|
;
|
||||||
|
|
||||||
# TODO
|
|
||||||
##define MEMCMP(s1, s2, n) \
|
|
||||||
# adr x0, s1; \
|
|
||||||
# adr x1, s2; \
|
|
||||||
# ldr x2, =n; \
|
|
||||||
# bl memcmp; \
|
|
||||||
#;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
9
userland/arch/x86_64/lkmc_assert_eq_fail.S
Normal file
9
userland/arch/x86_64/lkmc_assert_eq_fail.S
Normal file
@@ -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
|
||||||
12
userland/arch/x86_64/lkmc_assert_memcmp_fail.S
Normal file
12
userland/arch/x86_64/lkmc_assert_memcmp_fail.S
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user