Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 2438094

Browse files
committed
Fixes #18 -- call the kerne's BUG macro when we panic
1 parent 9486f3c commit 2438094

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const INCLUDED_FUNCTIONS: &[&str] = &[
1313
"kfree",
1414
"mount_nodev",
1515
"kill_litter_super",
16+
"BINDINGS_BUG",
1617
];
1718
const INCLUDED_VARS: &[&str] = &[
1819
"EINVAL",

hello-world/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-m := helloworld.o
2-
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a ../src/printk_helper.o
2+
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a ../src/helpers.o
33
EXTRA_LDFLAGS += --gc-sections --entry=init_module --undefined=cleanup_module
44

55
all:

src/helpers.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <linux/printk.h>
2+
3+
int printk_helper(const unsigned char *s, int len)
4+
{
5+
return printk(KERN_INFO "%.*s", len, (const char *)s);
6+
}
7+
8+
void bug_helper()
9+
{
10+
BUG();
11+
}

src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ pub trait KernelModule: Sized {
6464
fn init() -> KernelResult<Self>;
6565
}
6666

67+
extern "C" {
68+
fn bug_helper() -> !;
69+
}
70+
6771
#[lang = "eh_personality"]
6872
extern "C" fn eh_personality() {}
6973

7074
#[lang = "panic_fmt"]
7175
extern "C" fn panic_fmt() -> ! {
72-
loop {}
76+
unsafe {
77+
bug_helper();
78+
}
7379
}
7480

7581
#[global_allocator]

src/printk_helper.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

static-filesystem/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
obj-m := staticfilesystem.o
2-
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a ../src/printk_helper.o
2+
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a ../src/helpers.o
33
EXTRA_LDFLAGS += --gc-sections --entry=init_module --undefined=cleanup_module
44

55
all:

0 commit comments

Comments
 (0)