userland x86_64: implement ASSERT_MEMCMP

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-08 00:00:10 +00:00
parent 8e1fd9991b
commit 53ef7281a4
6 changed files with 36 additions and 28 deletions

View File

@@ -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

View File

@@ -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},
}
),
}

View File

@@ -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
*/

View File

@@ -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

View 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

View 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