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

Commit ea3b255

Browse files
committed
Some println debugging
1 parent a56acc7 commit ea3b255

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/chrdev.rs

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl DeviceNumberRegion {
4949
unsafe {
5050
(*cdev).owner = &mut bindings::__this_module;
5151
(*cdev).ops = &T::VTABLE.0 as *const bindings::file_operations;
52+
crate::println!("vtable={:?}", T::VTABLE.0);
5253
}
5354
let cdev = DeviceRegistration {
5455
cdev,
@@ -93,6 +94,7 @@ unsafe extern "C" fn open_callback<T: FileOperations>(
9394
_inode: *mut bindings::inode,
9495
file: *mut bindings::file,
9596
) -> c_types::c_int {
97+
crate::println!("open_callback reached");
9698
let f = match T::open() {
9799
Ok(f) => Box::new(f),
98100
Err(e) => return e.to_kernel_errno(),
@@ -107,6 +109,7 @@ unsafe extern "C" fn read_callback<T: FileOperations>(
107109
len: c_types::c_size_t,
108110
offset: *mut bindings::loff_t,
109111
) -> c_types::c_ssize_t {
112+
crate::println!("read_callback reached");
110113
let mut data = match UserSlicePtr::new(buf as *mut c_types::c_void, len) {
111114
Ok(ptr) => ptr.writer(),
112115
Err(e) => return e.to_kernel_errno() as c_types::c_ssize_t,
@@ -117,6 +120,7 @@ unsafe extern "C" fn read_callback<T: FileOperations>(
117120
Ok(()) => {
118121
let written = len - data.len();
119122
(*offset) += written as bindings::loff_t;
123+
crate::println!("read_callback: written={}", written);
120124
return written as c_types::c_ssize_t;
121125
}
122126
Err(e) => return e.to_kernel_errno() as c_types::c_ssize_t,
@@ -127,6 +131,7 @@ unsafe extern "C" fn release_callback<T: FileOperations>(
127131
_inode: *mut bindings::inode,
128132
file: *mut bindings::file,
129133
) -> c_types::c_int {
134+
crate::println!("release_callback reached");
130135
let ptr = (*file).private_data as *mut T;
131136
(*file).private_data = ptr::null_mut();
132137
Box::from_raw(ptr);

testlib/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ impl Drop for LoadedModule {
2929
}
3030

3131
pub fn with_kernel_module<F: Fn()>(f: F) {
32-
let status = Command::new("sudo")
33-
.arg("dmesg")
34-
.arg("-C")
35-
.status()
36-
.unwrap();
37-
assert!(status.success());
32+
// let status = Command::new("sudo")
33+
// .arg("dmesg")
34+
// .arg("-C")
35+
// .status()
36+
// .unwrap();
37+
// assert!(status.success());
3838
let _m = LoadedModule::load(env::var("KERNEL_MODULE").unwrap());
3939
f();
4040
}

tests/chrdev/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ impl linux_kernel_module::chrdev::FileOperations for CycleFile {
2121
&self,
2222
buf: &mut linux_kernel_module::user_ptr::UserSlicePtrWriter,
2323
) -> linux_kernel_module::KernelResult<()> {
24+
linux_kernel_module::println!("Called CycleFile::read with buf len: {}", buf.len());
2425
for c in b"123456789".iter().cycle().take(buf.len()) {
2526
buf.write(&[*c])?;
27+
linux_kernel_module::println!("CycleFile::read: buf.write()")
2628
}
2729
return Ok(());
2830
}
@@ -35,9 +37,11 @@ struct ChrdevTestModule {
3537

3638
impl linux_kernel_module::KernelModule for ChrdevTestModule {
3739
fn init() -> linux_kernel_module::KernelResult<Self> {
40+
linux_kernel_module::println!("Loaded chrdev module!");
3841
let dev_region =
3942
linux_kernel_module::chrdev::DeviceNumberRegion::allocate(0..1, "chrdev-tests\x00")?;
4043
let chrdev_registration = dev_region.register_device::<CycleFile>()?;
44+
linux_kernel_module::println!("Almost done!");
4145
Ok(ChrdevTestModule {
4246
_dev_region: dev_region,
4347
_chrdev_registration: chrdev_registration,

0 commit comments

Comments
 (0)