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

Fixed invalid module format & recent nightly support #67

Closed
wants to merge 29 commits into from
Closed
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9aba3a5
Updated to work with recent nightly
TheDan64 Jan 31, 2019
77405f0
Fix kernel_module todo
TheDan64 Jan 31, 2019
c017df5
Manually pass the correct target to bindgen/clang in the top-level bu…
ahomescu Jan 31, 2019
1a37aa0
Use an older toolchain to build the module (nightly-2018-06-20), whic…
ahomescu Jan 31, 2019
9928052
Link libhello_world.a into an object file before linking it into the …
ahomescu Jan 31, 2019
7ea79fe
Updated hello-world makefile to check if inside the kernel build syst…
ahomescu Feb 1, 2019
feddc85
Fixed rust-toolchain file
ahomescu Feb 1, 2019
1e08b63
Bumped nightly up to 2018-10-11 (last known good nightly), bumped bin…
ahomescu Feb 1, 2019
24fedec
Removed extern C from oom function (omitted from previous commit)
ahomescu Feb 1, 2019
ffbe33a
Add needs-plt option to target spec to prevent the compiler from usin…
ahomescu Feb 1, 2019
e5e83e1
Remove rust-toolchain file, now that the build works with any nightly
ahomescu Feb 1, 2019
2f2183d
Use the latest version of bindgen again
ahomescu Feb 1, 2019
0525b4b
Fixed dead code for travis
TheDan64 Feb 1, 2019
742b833
Added const_str_as_bytes feature to sysctl-tests
TheDan64 Feb 1, 2019
745c74f
Attempt to fix tests
TheDan64 Mar 27, 2019
5253b58
Fix .a path generation
TheDan64 Mar 27, 2019
f9f2367
Fixed tests Makefile. Removed no_copy. Fixed run_test script
TheDan64 Mar 27, 2019
4cb0789
Added rustfmt to travis install
TheDan64 Mar 28, 2019
bf4487f
See what happens if we disable PLT
alex Mar 29, 2019
40cabf0
Fix merge
alex Apr 29, 2019
cb35691
Re-enable needs-plt
TheDan64 Apr 29, 2019
d279b77
Add accidentally removed comment
TheDan64 Apr 29, 2019
3cfcb0b
Addded desc_struct to opaque list due to it being packed and aligned
TheDan64 Apr 29, 2019
5aaf0ec
Revert Makefile path change to what's on master
TheDan64 May 3, 2019
b0ca675
Fixed KDIR location in makefiles
TheDan64 May 3, 2019
ef7ec88
Remove alloc feature as it is stable
alex May 4, 2019
b43e795
Disable trusty build in travis
TheDan64 May 4, 2019
40dc3bf
Remove trusty from travis build matrix
TheDan64 May 4, 2019
26d6d69
Add TODO to kernel module macro
TheDan64 May 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -34,3 +34,4 @@ after_failure:

notifications:
email: false

3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ const OPAQUE_TYPES: &[&str] = &[
// This needs to be opaque because it's both packed and aligned, which rustc
// doesn't support yet. See https://github.com/rust-lang/rust/issues/59154
// and https://github.com/rust-lang/rust-bindgen/issues/1538
"desc_struct",
"xregs_state",
];

@@ -59,6 +60,7 @@ fn main() {
)
.unwrap();

builder = builder.clang_arg("--target=x86_64-linux-kernel-module");
for arg in shlex::split(&output).unwrap() {
builder = builder.clang_arg(arg.to_string());
}
@@ -88,6 +90,7 @@ fn main() {
let mut builder = cc::Build::new();
println!("cargo:rerun-if-env-changed=CLANG");
builder.compiler(env::var("CLANG").unwrap_or("clang".to_string()));
builder.target("x86_64-linux-kernel-module");
builder.warnings(false);
builder.file("src/helpers.c");
for arg in shlex::split(&output).unwrap() {
8 changes: 7 additions & 1 deletion hello-world/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
ifneq ($(KERNELRELEASE),)
obj-m := helloworld.o
helloworld-objs := target/x86_64-linux-kernel-module/debug/libhello_world.a
helloworld-objs := libhello_world.o
EXTRA_LDFLAGS += --entry=init_module

$(M)/libhello_world.o: target/x86_64-linux-kernel-module/debug/libhello_world.a
$(LD) -r -o $@ --whole-archive $^
else
KDIR ?= /lib/modules/$(shell uname -r)/build

all:
$(MAKE) -C $(KDIR) M=$(CURDIR)

clean:
$(MAKE) -C $(KDIR) M=$(CURDIR) clean
endif
5 changes: 3 additions & 2 deletions hello-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![no_std]
#![feature(alloc)]
#![feature(alloc, const_str_as_bytes)]

extern crate alloc;
use alloc::borrow::ToOwned;
use alloc::String;
use alloc::string::String;

#[macro_use]
extern crate linux_kernel_module;
@@ -27,6 +27,7 @@ impl Drop for HelloWorldModule {
println!("Goodbye kernel module!");
}
}

kernel_module!(
HelloWorldModule,
author: "Alex Gaynor and Geoffrey Thomas",
2 changes: 1 addition & 1 deletion src/allocator.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,6 @@ unsafe impl GlobalAlloc for KernelAllocator {
}

#[alloc_error_handler]
extern "C" fn oom(_layout: Layout) -> ! {
fn oom(_layout: Layout) -> ! {
panic!("Out of memory!");
}
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![feature(allocator_api, const_fn, lang_items, alloc_error_handler)]
#![feature(alloc, allocator_api, const_fn, lang_items, alloc_error_handler)]
TheDan64 marked this conversation as resolved.
Show resolved Hide resolved

#[macro_use]
extern crate alloc;
@@ -60,9 +60,7 @@ macro_rules! kernel_module {
#[link_section = ".modinfo"]
#[allow(non_upper_case_globals)]
// TODO: Generate a name the same way the kernel's `__MODULE_INFO` does.
// TODO: This needs to be a `&'static [u8]`, since the kernel defines this as a
TheDan64 marked this conversation as resolved.
Show resolved Hide resolved
// `const char []`.
pub static $name: &'static str = concat!(stringify!($name), "=", $value);
pub static $name: &'static [u8] = concat!(stringify!($name), "=", $value, '\0').as_bytes();
};
}

8 changes: 7 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
ifneq ($(KERNELRELEASE),)
obj-m := testmodule.o
testmodule-objs := $(TEST_LIBRARY)
testmodule-objs := $(TEST_LIBRARY_OBJECT)
EXTRA_LDFLAGS += --entry=init_module

$(M)/$(TEST_LIBRARY_OBJECT): target/x86_64-linux-kernel-module/debug/$(TEST_LIBRARY_ARCHIVE)
$(LD) -r -o $@ --whole-archive $^
else
KDIR ?= /lib/modules/$(shell uname -r)/build

all:
$(MAKE) -C $(KDIR) M=$(CURDIR)

clean:
$(MAKE) -C $(KDIR) M=$(CURDIR) clean
endif
1 change: 1 addition & 0 deletions tests/printk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![feature(const_str_as_bytes)]

#[macro_use]
extern crate linux_kernel_module;
11 changes: 5 additions & 6 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -46,14 +46,13 @@ def main():
path
)
)
library_path, _ = os.path.splitext(os.path.basename(module))
library_object = library_path + ".o"
library_archive = library_path + ".a"
run(
"make", "-C", BASE_DIR,
"TEST_LIBRARY={}".format(
os.path.join(
"target/x86_64-linux-kernel-module/debug/",
os.path.basename(module)
)
),
"TEST_LIBRARY_OBJECT={}".format(library_object),
"TEST_LIBRARY_ARCHIVE={}".format(library_archive),
)
run(
"rustc",
1 change: 1 addition & 0 deletions tests/sysctl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![no_std]
#![feature(const_str_as_bytes)]

use core::sync::atomic::AtomicBool;

1 change: 1 addition & 0 deletions x86_64-linux-kernel-module.json
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
},
"relocation-model": "static",
"relro-level": "full",
"needs-plt": true,
"target-c-int-width": "32",
"target-endian": "little",
"target-family": "unix",