Add unsafe_op_in_unsafe_fn lint

This commit is contained in:
Mathieu Strypsteen 2024-07-12 14:31:15 +02:00
parent 0512033ddd
commit 72726e00d5
4 changed files with 15 additions and 8 deletions

View file

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![deny(unsafe_op_in_unsafe_fn)]
extern crate alloc;

View file

@ -10,14 +10,18 @@ struct AllocInfo {
pub unsafe fn wrapped_alloc(layout: Layout) -> *mut u8 {
let header_layout = Layout::new::<AllocInfo>();
let (to_request, offset) = header_layout.extend(layout).unwrap();
let orig_ptr = underlying_alloc(to_request);
let result_ptr = orig_ptr.add(offset);
let info_ptr = result_ptr.sub(size_of::<AllocInfo>()) as *mut AllocInfo;
info_ptr.write_unaligned(AllocInfo { layout: to_request, ptr: orig_ptr });
result_ptr
unsafe {
let orig_ptr = underlying_alloc(to_request);
let result_ptr = orig_ptr.add(offset);
let info_ptr = result_ptr.sub(size_of::<AllocInfo>()) as *mut AllocInfo;
info_ptr.write_unaligned(AllocInfo { layout: to_request, ptr: orig_ptr });
result_ptr
}
}
pub unsafe fn wrapped_dealloc(ptr: *mut u8) {
let info_ptr = ptr.sub(size_of::<AllocInfo>()) as *const AllocInfo;
let info = info_ptr.read_unaligned();
underlying_dealloc(info.ptr, info.layout);
unsafe {
let info_ptr = ptr.sub(size_of::<AllocInfo>()) as *const AllocInfo;
let info = info_ptr.read_unaligned();
underlying_dealloc(info.ptr, info.layout);
}
}

View file

@ -1,2 +1,3 @@
#![allow(warnings)]
#![allow(unsafe_op_in_unsafe_fn)]
include!("acpica-bindings.rs");

View file

@ -1,5 +1,6 @@
#![no_main]
#![no_std]
#![forbid(unsafe_op_in_unsafe_fn)]
extern crate alloc;