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

Commit

Permalink
Fixes #18 -- call the kerne's BUG macro when we panic
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed May 26, 2018
1 parent 9486f3c commit 2438094
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const INCLUDED_FUNCTIONS: &[&str] = &[
"kfree",
"mount_nodev",
"kill_litter_super",
"BINDINGS_BUG",
];
const INCLUDED_VARS: &[&str] = &[
"EINVAL",
Expand Down
2 changes: 1 addition & 1 deletion hello-world/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-m := helloworld.o
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a ../src/printk_helper.o
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a ../src/helpers.o
EXTRA_LDFLAGS += --gc-sections --entry=init_module --undefined=cleanup_module

all:
Expand Down
11 changes: 11 additions & 0 deletions src/helpers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <linux/printk.h>

int printk_helper(const unsigned char *s, int len)
{
return printk(KERN_INFO "%.*s", len, (const char *)s);
}

void bug_helper()
{
BUG();
}
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ pub trait KernelModule: Sized {
fn init() -> KernelResult<Self>;
}

extern "C" {
fn bug_helper() -> !;
}

#[lang = "eh_personality"]
extern "C" fn eh_personality() {}

#[lang = "panic_fmt"]
extern "C" fn panic_fmt() -> ! {
loop {}
unsafe {
bug_helper();
}
}

#[global_allocator]
Expand Down
6 changes: 0 additions & 6 deletions src/printk_helper.c

This file was deleted.

2 changes: 1 addition & 1 deletion static-filesystem/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-m := staticfilesystem.o
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a ../src/printk_helper.o
staticfilesystem-objs := target/x86_64-linux-kernel-module/debug/libstatic_filesystem.a ../src/helpers.o
EXTRA_LDFLAGS += --gc-sections --entry=init_module --undefined=cleanup_module

all:
Expand Down

0 comments on commit 2438094

Please sign in to comment.