mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Get rid of lkmc_assert_fail in favor of abort + assert
What was missing previously was implementing abort in baremetal. I had done that previously and forgotten to do this conversion!
This commit is contained in:
25
README.adoc
25
README.adoc
@@ -15155,7 +15155,6 @@ So setup this `on_exit` automatically from all our <<baremetal-bootloaders>>, so
|
|||||||
The following examples end up testing that our setup is working:
|
The following examples end up testing that our setup is working:
|
||||||
+
|
+
|
||||||
* link:baremetal/assert_fail.c[]
|
* link:baremetal/assert_fail.c[]
|
||||||
* link:baremetal/lkmc_assert_fail.c[]
|
|
||||||
* link:baremetal/return1.c[]
|
* link:baremetal/return1.c[]
|
||||||
* link:baremetal/return2.c[]
|
* link:baremetal/return2.c[]
|
||||||
* link:baremetal/exit0.c[]
|
* link:baremetal/exit0.c[]
|
||||||
@@ -15165,30 +15164,6 @@ The following examples end up testing that our setup is working:
|
|||||||
|
|
||||||
Beware that on Linux kernel simulations, you cannot even echo that string from userland, since userland stdout shows up on the serial.
|
Beware that on Linux kernel simulations, you cannot even echo that string from userland, since userland stdout shows up on the serial.
|
||||||
|
|
||||||
====== baremetal assert
|
|
||||||
|
|
||||||
TODO: implement enough syscalls for it, so we can get the error line:
|
|
||||||
|
|
||||||
....
|
|
||||||
cd baremetal
|
|
||||||
ln -s ../lkmc/assert_fail.c
|
|
||||||
cd ..
|
|
||||||
./build --arch aarch64
|
|
||||||
....
|
|
||||||
|
|
||||||
fails with:
|
|
||||||
|
|
||||||
....
|
|
||||||
/path/to/linux-kernel-module-cheat/out/crosstool-ng/build/default/install/aarch64/lib/gcc/aarch64-unknown-elf/8.1.0/../../../../aarch64-unknown-elf/lib/libg.a(lib_a-signalr.o): In function `_kill_r':
|
|
||||||
/path/to/linux-kernel-module-cheat/out/crosstool-ng/build/default/build/aarch64-unknown-elf/src/newlib/newlib/libc/reent/signalr.c:53: undefined reference to `_kill'
|
|
||||||
/path/to/linux-kernel-module-cheat/out/crosstool-ng/build/default/build/aarch64-unknown-elf/src/newlib/newlib/libc/reent/signalr.c:53:(.text+0x20): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `_kill'
|
|
||||||
/path/to/linux-kernel-module-cheat/out/crosstool-ng/build/default/install/aarch64/lib/gcc/aarch64-unknown-elf/8.1.0/../../../../aarch64-unknown-elf/lib/libg.a(lib_a-signalr.o): In function `_getpid_r':
|
|
||||||
/path/to/linux-kernel-module-cheat/out/crosstool-ng/build/default/build/aarch64-unknown-elf/src/newlib/newlib/libc/reent/signalr.c:83: undefined reference to `_getpid'
|
|
||||||
/path/to/linux-kernel-module-cheat/out/crosstool-ng/build/default/build/aarch64-unknown-elf/src/newlib/newlib/libc/reent/signalr.c:83:(.text+0x44): relocation truncated to fit: R_AARCH64_JUMP26 against undefined symbol `_getpid'
|
|
||||||
....
|
|
||||||
|
|
||||||
at 406ee82cf33a6e3df0067b219b0414c59d7018b3 + 1.
|
|
||||||
|
|
||||||
==== Non-automated tests
|
==== Non-automated tests
|
||||||
|
|
||||||
===== Test GDB Linux kernel
|
===== Test GDB Linux kernel
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ main:
|
|||||||
/* test-gdb-result */
|
/* test-gdb-result */
|
||||||
cmp x1, 3
|
cmp x1, 3
|
||||||
beq 1f
|
beq 1f
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
1:
|
1:
|
||||||
mov x0, 0
|
mov x0, 0
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ main:
|
|||||||
fmov d3, 4.0
|
fmov d3, 4.0
|
||||||
fcmp d2, d3
|
fcmp d2, d3
|
||||||
beq 1f
|
beq 1f
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
1:
|
1:
|
||||||
|
|
||||||
/* Now in 32-bit. */
|
/* Now in 32-bit. */
|
||||||
@@ -26,7 +26,7 @@ main:
|
|||||||
fmov s3, 4.0
|
fmov s3, 4.0
|
||||||
fcmp s2, s3
|
fcmp s2, s3
|
||||||
beq 1f
|
beq 1f
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
1:
|
1:
|
||||||
|
|
||||||
/* Higher registers. */
|
/* Higher registers. */
|
||||||
@@ -40,7 +40,7 @@ main:
|
|||||||
/* test-gdb-d31 */
|
/* test-gdb-d31 */
|
||||||
fcmp d30, d31
|
fcmp d30, d31
|
||||||
beq 1f
|
beq 1f
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
1:
|
1:
|
||||||
|
|
||||||
mov x0, 0
|
mov x0, 0
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ main:
|
|||||||
ldr x1, mynewvar
|
ldr x1, mynewvar
|
||||||
cmp x0, x1
|
cmp x0, x1
|
||||||
beq 1f
|
beq 1f
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
1:
|
1:
|
||||||
|
|
||||||
/* Go home. */
|
/* Go home. */
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ main:
|
|||||||
/* test-gdb-result */
|
/* test-gdb-result */
|
||||||
cmp r1, #3
|
cmp r1, #3
|
||||||
beq 1f
|
beq 1f
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
1:
|
1:
|
||||||
mov r0, #0
|
mov r0, #0
|
||||||
bx lr
|
bx lr
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ LKMC_VECTOR_TABLE
|
|||||||
LKMC_WEAK(lkmc_vector_trap_handler)
|
LKMC_WEAK(lkmc_vector_trap_handler)
|
||||||
ldr x0, =lkmc_vector_trap_handler_error
|
ldr x0, =lkmc_vector_trap_handler_error
|
||||||
bl puts
|
bl puts
|
||||||
bl lkmc_assert_fail
|
bl abort
|
||||||
lkmc_vector_trap_handler_error:
|
lkmc_vector_trap_handler_error:
|
||||||
.asciz "error: unexpected interrupt"
|
.asciz "error: unexpected interrupt"
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../lkmc/lkmc_assert_fail.c
|
|
||||||
4
lkmc.c
4
lkmc.c
@@ -6,10 +6,6 @@
|
|||||||
|
|
||||||
#include <lkmc.h>
|
#include <lkmc.h>
|
||||||
|
|
||||||
void lkmc_assert_fail(void) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void lkmc_baremetal_on_exit_callback(int status, void *arg) {
|
void lkmc_baremetal_on_exit_callback(int status, void *arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
|
|||||||
1
lkmc.h
1
lkmc.h
@@ -11,7 +11,6 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void lkmc_assert_fail();
|
|
||||||
void lkmc_baremetal_on_exit_callback(int status, void *arg);
|
void lkmc_baremetal_on_exit_callback(int status, void *arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <lkmc.h>
|
#include <assert.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
@@ -9,5 +9,5 @@ int main(void) {
|
|||||||
k = i + j;
|
k = i + j;
|
||||||
/* test-gdb-result */
|
/* test-gdb-result */
|
||||||
if (k != 3)
|
if (k != 3)
|
||||||
lkmc_assert_fail();
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
#include <lkmc.h>
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
lkmc_assert_fail();
|
|
||||||
}
|
|
||||||
@@ -261,7 +261,6 @@ path_properties_tuples = (
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
'assert_fail.c': {'exit_status': 134},
|
'assert_fail.c': {'exit_status': 134},
|
||||||
'lkmc_assert_fail.c': {'exit_status': 1},
|
|
||||||
'exit1.c': {'exit_status': 1},
|
'exit1.c': {'exit_status': 1},
|
||||||
'infinite_loop.c': {'more_than_1s': True},
|
'infinite_loop.c': {'more_than_1s': True},
|
||||||
'lib': {'no_executable': True},
|
'lib': {'no_executable': True},
|
||||||
@@ -376,7 +375,6 @@ path_properties_tuples = (
|
|||||||
'lkmc': (
|
'lkmc': (
|
||||||
{'extra_objs_lkmc_common': True},
|
{'extra_objs_lkmc_common': True},
|
||||||
{
|
{
|
||||||
'assert_fail.c': {'exit_status': 1},
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
'libs': (
|
'libs': (
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../lkmc/lkmc_assert_fail.c
|
|
||||||
Reference in New Issue
Block a user