diff --git a/src/allocator.rs b/src/allocator.rs index 77c6a0a1..653ba85c 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,4 +1,5 @@ use core::alloc::{GlobalAlloc, Layout}; +use core::convert::TryInto; use core::ptr; use crate::bindings; @@ -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) { diff --git a/src/file_operations.rs b/src/file_operations.rs index 4376873e..d59e5269 100644 --- a/src/file_operations.rs +++ b/src/file_operations.rs @@ -46,10 +46,10 @@ unsafe extern "C" fn open_callback( unsafe extern "C" fn read_callback( 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(), }; @@ -62,7 +62,7 @@ unsafe extern "C" fn read_callback( }; 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() } @@ -73,10 +73,10 @@ unsafe extern "C" fn read_callback( unsafe extern "C" fn write_callback( 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(), }; @@ -89,7 +89,7 @@ unsafe extern "C" fn write_callback( }; 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() } diff --git a/src/sysctl.rs b/src/sysctl.rs index 71b054a1..a6c7fa20 100644 --- a/src/sysctl.rs +++ b/src/sysctl.rs @@ -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; @@ -83,7 +84,7 @@ unsafe extern "C" fn proc_handler( 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, @@ -93,7 +94,7 @@ unsafe extern "C" fn proc_handler( 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(), }; @@ -108,7 +109,7 @@ unsafe extern "C" fn proc_handler( 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,