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

Fix some compiled errors(mismatched types) #216

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::alloc::{GlobalAlloc, Layout};
use core::convert::TryInto;
use core::ptr;

use crate::bindings;
Expand All @@ -10,7 +11,11 @@ unsafe impl GlobalAlloc for KernelAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
// krealloc is used instead of kmalloc because kmalloc is an inline function and can't be
// bound to as a result
bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8
bindings::krealloc(
ptr::null(),
layout.size().try_into().unwrap(),
bindings::GFP_KERNEL,
) as *mut u8
}

unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
Expand Down
16 changes: 8 additions & 8 deletions src/file_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ unsafe extern "C" fn open_callback<T: FileOperations>(
unsafe extern "C" fn read_callback<T: Read>(
file: *mut bindings::file,
buf: *mut c_types::c_char,
len: c_types::c_size_t,
len: c_types::c_ulonglong,
offset: *mut bindings::loff_t,
) -> c_types::c_ssize_t {
let mut data = match UserSlicePtr::new(buf as *mut c_types::c_void, len) {
) -> c_types::c_longlong {
let mut data = match UserSlicePtr::new(buf as *mut c_types::c_void, len.try_into().unwrap()) {
Ok(ptr) => ptr.writer(),
Err(e) => return e.to_kernel_errno().try_into().unwrap(),
};
Expand All @@ -62,7 +62,7 @@ unsafe extern "C" fn read_callback<T: Read>(
};
match f.read(&mut data, positive_offset) {
Ok(()) => {
let written = len - data.len();
let written = len - (data.len() as u64);
(*offset) += bindings::loff_t::try_from(written).unwrap();
written.try_into().unwrap()
}
Expand All @@ -73,10 +73,10 @@ unsafe extern "C" fn read_callback<T: Read>(
unsafe extern "C" fn write_callback<T: Write>(
file: *mut bindings::file,
buf: *const c_types::c_char,
len: c_types::c_size_t,
len: c_types::c_ulonglong,
offset: *mut bindings::loff_t,
) -> c_types::c_ssize_t {
let mut data = match UserSlicePtr::new(buf as *mut c_types::c_void, len) {
) -> c_types::c_longlong {
let mut data = match UserSlicePtr::new(buf as *mut c_types::c_void, len.try_into().unwrap()) {
Ok(ptr) => ptr.reader(),
Err(e) => return e.to_kernel_errno().try_into().unwrap(),
};
Expand All @@ -89,7 +89,7 @@ unsafe extern "C" fn write_callback<T: Write>(
};
match f.write(&mut data, positive_offset) {
Ok(()) => {
let read = len - data.len();
let read = len - (data.len() as u64);
(*offset) += bindings::loff_t::try_from(read).unwrap();
read.try_into().unwrap()
}
Expand Down
7 changes: 4 additions & 3 deletions src/sysctl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::boxed::Box;
use alloc::vec;
use core::convert::TryInto;
use core::mem;
use core::ptr;
use core::sync::atomic;
Expand Down Expand Up @@ -83,7 +84,7 @@ unsafe extern "C" fn proc_handler<T: SysctlStorage>(
ctl: *mut bindings::ctl_table,
write: c_types::c_int,
buffer: *mut c_types::c_void,
len: *mut usize,
len: *mut c_types::c_ulonglong,
ppos: *mut bindings::loff_t,
) -> c_types::c_int {
// If we're reading from some offset other than the beginning of the file,
Expand All @@ -93,7 +94,7 @@ unsafe extern "C" fn proc_handler<T: SysctlStorage>(
return 0;
}

let data = match UserSlicePtr::new(buffer, *len) {
let data = match UserSlicePtr::new(buffer, (*len).try_into().unwrap()) {
Ok(ptr) => ptr,
Err(e) => return e.to_kernel_errno(),
};
Expand All @@ -108,7 +109,7 @@ unsafe extern "C" fn proc_handler<T: SysctlStorage>(
let mut writer = data.writer();
storage.read_value(&mut writer)
};
*len = bytes_processed;
*len = bytes_processed.try_into().unwrap();
*ppos += *len as bindings::loff_t;
match result {
Ok(()) => 0,
Expand Down