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

Commit

Permalink
WIP: Add byte_strings dependency
Browse files Browse the repository at this point in the history
See also #80 and #16.
  • Loading branch information
geofft committed May 6, 2019
1 parent d8c6e90 commit 4aceb46
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ cache:
- directories:
- tests/target/

branches:
only:
- master

install:
- sudo apt-get install -y "linux-headers-$(uname -r)" realpath
- type -p cargo-install-update || cargo install --force cargo-update
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["Alex Gaynor <alex.gaynor@gmail.com>"]

[dependencies]
bitflags = "1"
byte-strings = { git = "https://github.com/geofft/byte-strings-rs", branch = "no-std", default-features = false }

[build-dependencies]
bindgen = "*"
Expand Down
1 change: 1 addition & 0 deletions hello-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ crate-type = ["staticlib"]

[dependencies]
linux-kernel-module = { path = ".." }
byte-strings = { git = "https://github.com/geofft/byte-strings-rs", branch = "no-std", default-features = false }
4 changes: 3 additions & 1 deletion hello-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![no_std]
#![feature(alloc, const_str_as_bytes)]
#![feature(alloc, const_slice_len)]
#[macro_use]
extern crate byte_strings;

extern crate alloc;
use alloc::borrow::ToOwned;
Expand Down
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern crate alloc;
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate byte_strings;

use core::panic::PanicInfo;

Expand Down Expand Up @@ -58,12 +60,16 @@ macro_rules! kernel_module {
};

(@attribute $name:ident, $value:expr) => {
kernel_module!(@modinfo $name, concat_bytes!(as_bytes!(stringify!($name), b"=", as_bytes!($value))));
};

(@modinfo $name:ident, $bytes:expr) => {
#[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();
// TODO: Use of .len() here requires `#![feature(const_slice_len)]`.
// We'd prefer [u8; ]. See https://github.com/rust-lang/rfcs/pull/2545
pub static $name: [u8; ($bytes).len()] = *($bytes);
};
}

Expand Down

0 comments on commit 4aceb46

Please sign in to comment.