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

Start moving to 2018-style macros #94

Merged
merged 19 commits into from
Jun 16, 2019
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate bindgen;
extern crate cc;
extern crate shlex;
use bindgen;
use cc;
use shlex;

use std::env;
use std::path::PathBuf;
Expand Down
7 changes: 3 additions & 4 deletions hello-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![no_std]
#![feature(alloc, const_str_as_bytes)]

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

#[macro_use]
extern crate linux_kernel_module;
use linux_kernel_module;
use linux_kernel_module::println;

struct HelloWorldModule {
message: String,
Expand All @@ -28,7 +27,7 @@ impl Drop for HelloWorldModule {
}
}

kernel_module!(
linux_kernel_module::kernel_module!(
HelloWorldModule,
author: "Alex Gaynor and Geoffrey Thomas",
description: "An extremely simple kernel module",
Expand Down
10 changes: 3 additions & 7 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use core::default::Default;
use core::marker;
use core::mem;

use bitflags;

use crate::bindings;
use crate::c_types;
use crate::error;
Expand All @@ -24,7 +26,7 @@ pub trait FileSystem {
const FLAGS: FileSystemFlags;
}

bitflags! {
bitflags::bitflags! {
pub struct FileSystemFlags: c_types::c_int {
const FS_REQUIRES_DEV = bindings::FS_REQUIRES_DEV as c_types::c_int;
const FS_BINARY_MOUNTDATA = bindings::FS_BINARY_MOUNTDATA as c_types::c_int;
Expand All @@ -34,12 +36,6 @@ bitflags! {
}
}

impl FileSystemFlags {
pub const fn const_empty() -> FileSystemFlags {
FileSystemFlags { bits: 0 }
}
}

extern "C" fn fill_super_callback<T: FileSystem>(
_sb: *mut bindings::super_block,
_data: *mut c_types::c_void,
Expand Down
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#![no_std]
#![feature(allocator_api, const_fn, alloc_error_handler)]
#![feature(allocator_api, alloc_error_handler)]

#[macro_use]
extern crate alloc;
#[macro_use]
extern crate bitflags;

use core::panic::PanicInfo;

Expand All @@ -14,7 +11,6 @@ mod c_types;
pub mod chrdev;
mod error;
pub mod filesystem;
#[macro_use]
pub mod printk;
pub mod sysctl;
mod types;
Expand Down Expand Up @@ -53,7 +49,7 @@ macro_rules! kernel_module {
}

$(
kernel_module!(@attribute $name, $value);
$crate::kernel_module!(@attribute $name, $value);
)*
};

Expand Down
1 change: 1 addition & 0 deletions src/sysctl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::boxed::Box;
use alloc::vec;
use core::mem;
use core::ptr;
use core::sync::atomic;
Expand Down
1 change: 1 addition & 0 deletions src/user_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec;
use alloc::vec::Vec;
use core::u32;

Expand Down
5 changes: 2 additions & 3 deletions tests/chrdev/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![no_std]
#![feature(const_str_as_bytes)]

#[macro_use]
extern crate linux_kernel_module;
use linux_kernel_module;

struct ChrdevTestModule {
_dev: linux_kernel_module::chrdev::DeviceNumberRegion,
Expand All @@ -19,7 +18,7 @@ impl linux_kernel_module::KernelModule for ChrdevTestModule {
}
}

kernel_module!(
linux_kernel_module::kernel_module!(
ChrdevTestModule,
author: "Alex Gaynor and Geoffrey Thomas",
description: "A module for testing character devices",
Expand Down
2 changes: 0 additions & 2 deletions tests/chrdev/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate kernel_module_tests;

use kernel_module_tests::with_kernel_module;
use std::fs;

Expand Down
5 changes: 2 additions & 3 deletions tests/printk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![no_std]
#![feature(const_str_as_bytes)]

#[macro_use]
extern crate linux_kernel_module;
use linux_kernel_module::{self, println};

struct PrintkTestModule;

Expand All @@ -16,7 +15,7 @@ impl linux_kernel_module::KernelModule for PrintkTestModule {
}
}

kernel_module!(
linux_kernel_module::kernel_module!(
PrintkTestModule,
author: "Alex Gaynor and Geoffrey Thomas",
description: "A module for testing println!()",
Expand Down
2 changes: 0 additions & 2 deletions tests/printk/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate kernel_module_tests;

use std::process::Command;

use kernel_module_tests::with_kernel_module;
Expand Down
2 changes: 1 addition & 1 deletion tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def main():
"rustc",
"--test",
"-Dwarnings",
"--edition", "2018",
"--out-dir", os.path.join(BASE_DIR, path),
os.path.join(BASE_DIR, path, "tests.rs"),
"--extern", "kernel_module_tests=libtestlib.rlib",
Expand All @@ -76,4 +77,3 @@ def main():

if __name__ == "__main__":
main()

5 changes: 2 additions & 3 deletions tests/sysctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

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

#[macro_use]
extern crate linux_kernel_module;
use linux_kernel_module;

use linux_kernel_module::sysctl::Sysctl;
use linux_kernel_module::Mode;
Expand Down Expand Up @@ -33,7 +32,7 @@ impl linux_kernel_module::KernelModule for SysctlTestModule {
}
}

kernel_module!(
linux_kernel_module::kernel_module!(
SysctlTestModule,
author: "Alex Gaynor and Geoffrey Thomas",
description: "A module for testing sysctls",
Expand Down
2 changes: 0 additions & 2 deletions tests/sysctl/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate kernel_module_tests;

use std::fs;
use std::path::Path;

Expand Down