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

Commit 3a38379

Browse files
TheDan64alex
authored andcommitted
Switch modinfo from &str to &[u8] using const fn .as_bytes()
1 parent f65b31f commit 3a38379

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

hello-world/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![no_std]
2-
#![feature(alloc)]
2+
#![feature(alloc, const_str_as_bytes)]
33

44
extern crate alloc;
55
use alloc::borrow::ToOwned;
@@ -27,6 +27,7 @@ impl Drop for HelloWorldModule {
2727
println!("Goodbye kernel module!");
2828
}
2929
}
30+
3031
kernel_module!(
3132
HelloWorldModule,
3233
author: "Alex Gaynor and Geoffrey Thomas",

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ macro_rules! kernel_module {
6060
#[link_section = ".modinfo"]
6161
#[allow(non_upper_case_globals)]
6262
// TODO: Generate a name the same way the kernel's `__MODULE_INFO` does.
63-
// TODO: This needs to be a `&'static [u8]`, since the kernel defines this as a
64-
// `const char []`.
65-
pub static $name: &'static str = concat!(stringify!($name), "=", $value);
63+
// TODO: This needs to be a `[u8; _]`, since the kernel defines this as a `const char []`.
64+
// See https://github.com/rust-lang/rfcs/pull/2545
65+
pub static $name: &'static [u8] = concat!(stringify!($name), "=", $value, '\0').as_bytes();
6666
};
6767
}
6868

tests/printk/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![feature(const_str_as_bytes)]
23

34
#[macro_use]
45
extern crate linux_kernel_module;

tests/sysctl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![feature(const_str_as_bytes)]
23

34
use core::sync::atomic::AtomicBool;
45

0 commit comments

Comments
 (0)