From 9aba3a5b9b4e4aa758be9a907748ca44539cb57d Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Thu, 31 Jan 2019 11:05:36 -0800 Subject: [PATCH 01/29] Updated to work with recent nightly --- hello-world/src/lib.rs | 2 +- src/allocator.rs | 2 +- src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hello-world/src/lib.rs b/hello-world/src/lib.rs index 2413fe0a..caedd039 100644 --- a/hello-world/src/lib.rs +++ b/hello-world/src/lib.rs @@ -3,7 +3,7 @@ extern crate alloc; use alloc::borrow::ToOwned; -use alloc::String; +use alloc::string::String; #[macro_use] extern crate linux_kernel_module; diff --git a/src/allocator.rs b/src/allocator.rs index ee17f353..45efb943 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -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!"); } diff --git a/src/lib.rs b/src/lib.rs index c06448c6..0e774309 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] #[macro_use] extern crate alloc; From 77405f0b5f8e7ec873794e048e2e31993d746156 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Thu, 31 Jan 2019 11:30:26 -0800 Subject: [PATCH 02/29] Fix kernel_module todo --- hello-world/src/lib.rs | 3 ++- src/lib.rs | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hello-world/src/lib.rs b/hello-world/src/lib.rs index caedd039..1799c1ff 100644 --- a/hello-world/src/lib.rs +++ b/hello-world/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(alloc)] +#![feature(alloc, const_str_as_bytes)] extern crate alloc; use alloc::borrow::ToOwned; @@ -27,6 +27,7 @@ impl Drop for HelloWorldModule { println!("Goodbye kernel module!"); } } + kernel_module!( HelloWorldModule, author: "Alex Gaynor and Geoffrey Thomas", diff --git a/src/lib.rs b/src/lib.rs index 0e774309..f7d9c6ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 - // `const char []`. - pub static $name: &'static str = concat!(stringify!($name), "=", $value); + pub static $name: &'static [u8] = concat!(stringify!($name), "=", $value, '\0').as_bytes(); }; } From c017df50566bf6756f468c2f91bc0aee1da5de60 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 14:25:02 -0800 Subject: [PATCH 03/29] Manually pass the correct target to bindgen/clang in the top-level build script --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 82491ffb..91f80f5e 100644 --- a/build.rs +++ b/build.rs @@ -59,6 +59,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 +89,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() { From 1a37aa009907eb24d8a4a96d9d272c2f79670869 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 15:41:42 -0800 Subject: [PATCH 04/29] Use an older toolchain to build the module (nightly-2018-06-20), which also requires an older cargo xbuild: 0.4.7 --- Cargo.toml | 2 +- hello-world/src/lib.rs | 2 +- src/allocator.rs | 4 ++-- src/lib.rs | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 69777640..e8625f2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,6 @@ authors = ["Alex Gaynor "] bitflags = "1" [build-dependencies] -bindgen = "*" +bindgen = "0.37.4" cc = "1.0" shlex = "0.1" diff --git a/hello-world/src/lib.rs b/hello-world/src/lib.rs index 1799c1ff..e56de246 100644 --- a/hello-world/src/lib.rs +++ b/hello-world/src/lib.rs @@ -3,7 +3,7 @@ extern crate alloc; use alloc::borrow::ToOwned; -use alloc::string::String; +use alloc::String; #[macro_use] extern crate linux_kernel_module; diff --git a/src/allocator.rs b/src/allocator.rs index 45efb943..e4d3a2c7 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -21,7 +21,7 @@ unsafe impl GlobalAlloc for KernelAllocator { } } -#[alloc_error_handler] -fn oom(_layout: Layout) -> ! { +#[lang = "oom"] +extern "C" fn oom(_err: AllocErr) -> ! { panic!("Out of memory!"); } diff --git a/src/lib.rs b/src/lib.rs index f7d9c6ec..357a7e5c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(alloc, allocator_api, const_fn, lang_items, alloc_error_handler)] +#![feature(alloc, allocator_api, const_fn, lang_items, panic_implementation)] #[macro_use] extern crate alloc; @@ -72,7 +72,7 @@ extern "C" { fn bug_helper() -> !; } -#[panic_handler] +#[panic_implementation] fn panic(_info: &PanicInfo) -> ! { unsafe { bug_helper(); From 9928052d514779aa9de730d073301763f296fa85 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 15:54:32 -0800 Subject: [PATCH 05/29] Link libhello_world.a into an object file before linking it into the module (required by newer kernel build systems, it seems) --- hello-world/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello-world/Makefile b/hello-world/Makefile index fccc18c3..945e848a 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -1,5 +1,5 @@ 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 KDIR ?= /lib/modules/$(shell uname -r)/build From 7ea79fe3736bf804c1b9065e0077f08e09f53cdb Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 16:00:41 -0800 Subject: [PATCH 06/29] Updated hello-world makefile to check if inside the kernel build system or not --- hello-world/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hello-world/Makefile b/hello-world/Makefile index 945e848a..36ac27e4 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -1,10 +1,15 @@ +ifneq ($(KERNELRELEASE),) obj-m := helloworld.o helloworld-objs := libhello_world.o EXTRA_LDFLAGS += --entry=init_module KDIR ?= /lib/modules/$(shell uname -r)/build +$(M)/libhello_world.o: target/x86_64-linux-kernel-module/debug/libhello_world.a + $(LD) -r -o $@ --whole-archive $^ +else all: $(MAKE) -C $(KDIR) M=$(CURDIR) clean: - $(MAKE) -C $(KDIR) M=$(CURDIR) clean + $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean +endif From feddc8591b4dc6e77de1acc2f1f2be84223b9e00 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 16:42:25 -0800 Subject: [PATCH 07/29] Fixed rust-toolchain file --- rust-toolchain | 1 + 1 file changed, 1 insertion(+) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 00000000..84dd0794 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly-2018-06-20 From 1e08b632991ba4060bd8f0fd757e14de98654c8b Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 17:08:01 -0800 Subject: [PATCH 08/29] Bumped nightly up to 2018-10-11 (last known good nightly), bumped bindgen to 0.42.3 and restored the reverted fixes from d9ca6d3b92 --- Cargo.toml | 2 +- hello-world/src/lib.rs | 2 +- rust-toolchain | 2 +- src/allocator.rs | 4 ++-- src/lib.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e8625f2c..696aefa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,6 @@ authors = ["Alex Gaynor "] bitflags = "1" [build-dependencies] -bindgen = "0.37.4" +bindgen = "0.42.3" cc = "1.0" shlex = "0.1" diff --git a/hello-world/src/lib.rs b/hello-world/src/lib.rs index e56de246..1799c1ff 100644 --- a/hello-world/src/lib.rs +++ b/hello-world/src/lib.rs @@ -3,7 +3,7 @@ extern crate alloc; use alloc::borrow::ToOwned; -use alloc::String; +use alloc::string::String; #[macro_use] extern crate linux_kernel_module; diff --git a/rust-toolchain b/rust-toolchain index 84dd0794..721790eb 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2018-06-20 +nightly-2018-10-11 diff --git a/src/allocator.rs b/src/allocator.rs index e4d3a2c7..ee17f353 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -21,7 +21,7 @@ unsafe impl GlobalAlloc for KernelAllocator { } } -#[lang = "oom"] -extern "C" fn oom(_err: AllocErr) -> ! { +#[alloc_error_handler] +extern "C" fn oom(_layout: Layout) -> ! { panic!("Out of memory!"); } diff --git a/src/lib.rs b/src/lib.rs index 357a7e5c..f7d9c6ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(alloc, allocator_api, const_fn, lang_items, panic_implementation)] +#![feature(alloc, allocator_api, const_fn, lang_items, alloc_error_handler)] #[macro_use] extern crate alloc; @@ -72,7 +72,7 @@ extern "C" { fn bug_helper() -> !; } -#[panic_implementation] +#[panic_handler] fn panic(_info: &PanicInfo) -> ! { unsafe { bug_helper(); From 24fedec459f653215aab3f98ab9072121b1197fe Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 17:11:33 -0800 Subject: [PATCH 09/29] Removed extern C from oom function (omitted from previous commit) --- src/allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index ee17f353..45efb943 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -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!"); } From ffbe33a5d8912974e64bc5b199abd446a97a8df9 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 17:23:18 -0800 Subject: [PATCH 10/29] Add needs-plt option to target spec to prevent the compiler from using the GOT instead of the PLT --- x86_64-linux-kernel-module.json | 1 + 1 file changed, 1 insertion(+) diff --git a/x86_64-linux-kernel-module.json b/x86_64-linux-kernel-module.json index 93159324..fd5353af 100644 --- a/x86_64-linux-kernel-module.json +++ b/x86_64-linux-kernel-module.json @@ -24,6 +24,7 @@ }, "relocation-model": "static", "relro-level": "full", + "needs-plt": true, "target-c-int-width": "32", "target-endian": "little", "target-family": "unix", From e5e83e1d8f41c2596e76c8381a0ac46b0beb3810 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 17:26:45 -0800 Subject: [PATCH 11/29] Remove rust-toolchain file, now that the build works with any nightly --- rust-toolchain | 1 - 1 file changed, 1 deletion(-) delete mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 721790eb..00000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2018-10-11 From 2f2183defbecd3c74d8257e0ae49bcf772476192 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Thu, 31 Jan 2019 17:27:50 -0800 Subject: [PATCH 12/29] Use the latest version of bindgen again --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 696aefa2..69777640 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,6 @@ authors = ["Alex Gaynor "] bitflags = "1" [build-dependencies] -bindgen = "0.42.3" +bindgen = "*" cc = "1.0" shlex = "0.1" From 0525b4b6e501235d0cd020e02d144a9bea9400c9 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 1 Feb 2019 07:46:43 -0800 Subject: [PATCH 13/29] Fixed dead code for travis --- src/sysctl.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sysctl.rs b/src/sysctl.rs index 151be43e..2174f7ce 100644 --- a/src/sysctl.rs +++ b/src/sysctl.rs @@ -56,7 +56,6 @@ impl SysctlStorage for atomic::AtomicBool { pub struct Sysctl { inner: Box, - // Responsible for keeping the ctl_table alive. _table: Box<[bindings::ctl_table]>, header: *mut bindings::ctl_table_header, } From 742b83345a3e5efd2eb0791c08bf492baeb2be14 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 1 Feb 2019 08:00:00 -0800 Subject: [PATCH 14/29] Added const_str_as_bytes feature to sysctl-tests --- tests/sysctl/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sysctl/src/lib.rs b/tests/sysctl/src/lib.rs index 45fbc871..84e9a052 100644 --- a/tests/sysctl/src/lib.rs +++ b/tests/sysctl/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![feature(const_str_as_bytes)] use core::sync::atomic::AtomicBool; From 745c74fc7c6867dd43eade52d8968c2047c0e6ab Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 27 Mar 2019 12:52:55 -0400 Subject: [PATCH 15/29] Attempt to fix tests --- tests/Makefile | 7 ++++++- tests/run_tests.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index acfd9592..106c1a91 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,10 +1,15 @@ +ifneq ($(KERNELRELEASE),) obj-m := testmodule.o testmodule-objs := $(TEST_LIBRARY) EXTRA_LDFLAGS += --entry=init_module KDIR ?= /lib/modules/$(shell uname -r)/build +$(M)/$(TEST_LIBRARY): $(TEST_LIBRARY_ARCHIVE) + $(LD) -r -o $@ --whole-archive $^ +else all: $(MAKE) -C $(KDIR) M=$(CURDIR) clean: - $(MAKE) -C $(KDIR) M=$(CURDIR) clean + $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean +endif diff --git a/tests/run_tests.py b/tests/run_tests.py index f8fae900..aa337174 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -46,6 +46,8 @@ def main(): path ) ) + library_archive, _ = os.path.splitext(os.path.basename(module)) + library_archive = os.path.join(library_archive, ".a") run( "make", "-C", BASE_DIR, "TEST_LIBRARY={}".format( @@ -54,6 +56,7 @@ def main(): os.path.basename(module) ) ), + "TEST_LIBRARY_ARCHIVE={}".format(library_archive), ) run( "rustc", From 5253b5852a8e88db9d1ffcff1ec076b2ba451c1e Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 27 Mar 2019 12:58:34 -0400 Subject: [PATCH 16/29] Fix .a path generation --- tests/run_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run_tests.py b/tests/run_tests.py index aa337174..b49ec25f 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -47,7 +47,7 @@ def main(): ) ) library_archive, _ = os.path.splitext(os.path.basename(module)) - library_archive = os.path.join(library_archive, ".a") + library_archive = library_archive + ".a" run( "make", "-C", BASE_DIR, "TEST_LIBRARY={}".format( From f9f23677c0caf5af03a74528658a64afe040a0d0 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 27 Mar 2019 16:04:52 -0400 Subject: [PATCH 17/29] Fixed tests Makefile. Removed no_copy. Fixed run_test script --- tests/Makefile | 4 ++-- tests/printk/src/lib.rs | 1 + tests/run_tests.py | 12 ++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 106c1a91..410db15e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,10 +1,10 @@ ifneq ($(KERNELRELEASE),) obj-m := testmodule.o -testmodule-objs := $(TEST_LIBRARY) +testmodule-objs := $(TEST_LIBRARY_OBJECT) EXTRA_LDFLAGS += --entry=init_module KDIR ?= /lib/modules/$(shell uname -r)/build -$(M)/$(TEST_LIBRARY): $(TEST_LIBRARY_ARCHIVE) +$(M)/$(TEST_LIBRARY_OBJECT): target/x86_64-linux-kernel-module/debug/$(TEST_LIBRARY_ARCHIVE) $(LD) -r -o $@ --whole-archive $^ else all: diff --git a/tests/printk/src/lib.rs b/tests/printk/src/lib.rs index 3db1517a..dc0d8f4d 100644 --- a/tests/printk/src/lib.rs +++ b/tests/printk/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![feature(const_str_as_bytes)] #[macro_use] extern crate linux_kernel_module; diff --git a/tests/run_tests.py b/tests/run_tests.py index b49ec25f..681f6388 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -46,16 +46,12 @@ def main(): path ) ) - library_archive, _ = os.path.splitext(os.path.basename(module)) - library_archive = library_archive + ".a" + 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( From 4cb0789111b6ce50dcebb31a800b8718d375e1b5 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Thu, 28 Mar 2019 09:34:36 -0400 Subject: [PATCH 18/29] Added rustfmt to travis install --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8deb01c5..33942f24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,3 +34,4 @@ after_failure: notifications: email: false + From bf4487f1077896a02a1fe943e46bdd1c9c3d7528 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 28 Mar 2019 23:11:15 -0400 Subject: [PATCH 19/29] See what happens if we disable PLT --- x86_64-linux-kernel-module.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86_64-linux-kernel-module.json b/x86_64-linux-kernel-module.json index fd5353af..bae6b9c0 100644 --- a/x86_64-linux-kernel-module.json +++ b/x86_64-linux-kernel-module.json @@ -24,7 +24,7 @@ }, "relocation-model": "static", "relro-level": "full", - "needs-plt": true, + "needs-plt": false, "target-c-int-width": "32", "target-endian": "little", "target-family": "unix", From 40cabf0ec47cee66850a26c576ed2e5301066935 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 28 Apr 2019 20:19:36 -0400 Subject: [PATCH 20/29] Fix merge --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f7d9c6ec..4bb1a66a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(alloc, allocator_api, const_fn, lang_items, alloc_error_handler)] +#![feature(allocator_api, const_fn, lang_items, alloc_error_handler)] #[macro_use] extern crate alloc; From cb356910f5f10784249a5e4266582eff35fda2bb Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Mon, 29 Apr 2019 15:02:39 -0400 Subject: [PATCH 21/29] Re-enable needs-plt --- x86_64-linux-kernel-module.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86_64-linux-kernel-module.json b/x86_64-linux-kernel-module.json index bae6b9c0..fd5353af 100644 --- a/x86_64-linux-kernel-module.json +++ b/x86_64-linux-kernel-module.json @@ -24,7 +24,7 @@ }, "relocation-model": "static", "relro-level": "full", - "needs-plt": false, + "needs-plt": true, "target-c-int-width": "32", "target-endian": "little", "target-family": "unix", From d279b774d07d9688c769363d8cf5fdacbe901bc2 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Mon, 29 Apr 2019 15:04:08 -0400 Subject: [PATCH 22/29] Add accidentally removed comment --- src/sysctl.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sysctl.rs b/src/sysctl.rs index 2174f7ce..151be43e 100644 --- a/src/sysctl.rs +++ b/src/sysctl.rs @@ -56,6 +56,7 @@ impl SysctlStorage for atomic::AtomicBool { pub struct Sysctl { inner: Box, + // Responsible for keeping the ctl_table alive. _table: Box<[bindings::ctl_table]>, header: *mut bindings::ctl_table_header, } From 3cfcb0b63bab07d052c8b230204cbb291849dc27 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Mon, 29 Apr 2019 19:31:19 -0400 Subject: [PATCH 23/29] Addded desc_struct to opaque list due to it being packed and aligned --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index 91f80f5e..f5c45d5d 100644 --- a/build.rs +++ b/build.rs @@ -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", ]; From 5aaf0ec38af77eda6bd1042118a71c4fd054009e Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Fri, 3 May 2019 16:28:31 -0400 Subject: [PATCH 24/29] Revert Makefile path change to what's on master --- hello-world/Makefile | 2 +- src/lib.rs | 2 +- tests/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hello-world/Makefile b/hello-world/Makefile index 36ac27e4..9b2b120a 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -11,5 +11,5 @@ all: $(MAKE) -C $(KDIR) M=$(CURDIR) clean: - $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean + $(MAKE) -C $(KDIR) M=$(CURDIR) clean endif diff --git a/src/lib.rs b/src/lib.rs index 4bb1a66a..f7d9c6ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] #[macro_use] extern crate alloc; diff --git a/tests/Makefile b/tests/Makefile index 410db15e..ae5208b9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -11,5 +11,5 @@ all: $(MAKE) -C $(KDIR) M=$(CURDIR) clean: - $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean + $(MAKE) -C $(KDIR) M=$(CURDIR) clean endif From b0ca675eba01dfb4484ee206aa08fba444df1b4a Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Fri, 3 May 2019 18:06:45 -0400 Subject: [PATCH 25/29] Fixed KDIR location in makefiles --- hello-world/Makefile | 3 ++- tests/Makefile | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hello-world/Makefile b/hello-world/Makefile index 9b2b120a..21e4fbde 100644 --- a/hello-world/Makefile +++ b/hello-world/Makefile @@ -2,11 +2,12 @@ ifneq ($(KERNELRELEASE),) obj-m := helloworld.o helloworld-objs := libhello_world.o EXTRA_LDFLAGS += --entry=init_module -KDIR ?= /lib/modules/$(shell uname -r)/build $(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) diff --git a/tests/Makefile b/tests/Makefile index ae5208b9..8a2f876b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,11 +2,12 @@ ifneq ($(KERNELRELEASE),) obj-m := testmodule.o testmodule-objs := $(TEST_LIBRARY_OBJECT) EXTRA_LDFLAGS += --entry=init_module -KDIR ?= /lib/modules/$(shell uname -r)/build $(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) From ef7ec8894e1d52d0fb19c245b8678b7a7b1d9765 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 3 May 2019 17:46:52 -0700 Subject: [PATCH 26/29] Remove alloc feature as it is stable Co-Authored-By: TheDan64 --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f7d9c6ec..4bb1a66a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(alloc, allocator_api, const_fn, lang_items, alloc_error_handler)] +#![feature(allocator_api, const_fn, lang_items, alloc_error_handler)] #[macro_use] extern crate alloc; From b43e795790554af98144c5e28bab72fd1da23f73 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Fri, 3 May 2019 22:02:23 -0400 Subject: [PATCH 27/29] Disable trusty build in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 33942f24..8894aa22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ matrix: include: - - dist: trusty + # - dist: trusty - dist: xenial language: rust From 40dc3bf17a3e08ca1b6826fbefde259f78863225 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Sat, 4 May 2019 14:57:39 -0400 Subject: [PATCH 28/29] Remove trusty from travis build matrix --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8894aa22..a66a2c12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ matrix: include: - # - dist: trusty - dist: xenial language: rust From 26d6d697441680d2721af46336ebe09384278471 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Sat, 4 May 2019 15:03:42 -0400 Subject: [PATCH 29/29] Add TODO to kernel module macro --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4bb1a66a..a46ae77f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,8 @@ 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 `[u8; _]`, since the kernel defines this as a `const char []`. + // See https://github.com/rust-lang/rfcs/pull/2545 pub static $name: &'static [u8] = concat!(stringify!($name), "=", $value, '\0').as_bytes(); }; }