Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arch): unused_unsafe #385

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
17 changes: 8 additions & 9 deletions src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const PT_MEM_CD: u64 = 0x70F;
const PT_SELF: u64 = 1 << 55;

pub unsafe fn get_memory(_memory_size: u64) -> u64 {
(unsafe { ptr::addr_of!(loader_end) }.addr() as u64).align_up(LargePageSize::SIZE as u64)
(ptr::addr_of!(loader_end).addr() as u64).align_up(LargePageSize::SIZE as u64)
}

pub fn find_kernel() -> &'static [u8] {
Expand Down Expand Up @@ -124,21 +124,21 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
for i in pgt_slice.iter_mut() {
*i = 0;
}
pgt_slice[0] = unsafe { ptr::addr_of!(l1_pgtable) }.addr() as u64 + PT_PT;
pgt_slice[511] = unsafe { ptr::addr_of!(l0_pgtable) }.addr() as u64 + PT_PT + PT_SELF;
pgt_slice[0] = ptr::addr_of!(l1_pgtable).addr() as u64 + PT_PT;
pgt_slice[511] = ptr::addr_of!(l0_pgtable).addr() as u64 + PT_PT + PT_SELF;

let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l1_pgtable), 512) };
for i in pgt_slice.iter_mut() {
*i = 0;
}
pgt_slice[0] = unsafe { ptr::addr_of!(l2_pgtable) }.addr() as u64 + PT_PT;
pgt_slice[1] = unsafe { ptr::addr_of!(l2k_pgtable) }.addr() as u64 + PT_PT;
pgt_slice[0] = ptr::addr_of!(l2_pgtable).addr() as u64 + PT_PT;
pgt_slice[1] = ptr::addr_of!(l2k_pgtable).addr() as u64 + PT_PT;

let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l2_pgtable), 512) };
for i in pgt_slice.iter_mut() {
*i = 0;
}
pgt_slice[0] = unsafe { ptr::addr_of!(l3_pgtable) }.addr() as u64 + PT_PT;
pgt_slice[0] = ptr::addr_of!(l3_pgtable).addr() as u64 + PT_PT;

let pgt_slice = unsafe { core::slice::from_raw_parts_mut(ptr::addr_of_mut!(l3_pgtable), 512) };
for i in pgt_slice.iter_mut() {
Expand All @@ -152,9 +152,8 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
*i = 0;
}
for (i, pgt_slice) in pgt_slice.iter_mut().enumerate().take(10) {
*pgt_slice = unsafe { ptr::addr_of!(L0mib_pgtable) }.addr() as u64
+ (i * BasePageSize::SIZE) as u64
+ PT_PT;
*pgt_slice =
ptr::addr_of!(L0mib_pgtable).addr() as u64 + (i * BasePageSize::SIZE) as u64 + PT_PT;
}

let pgt_slice =
Expand Down
2 changes: 1 addition & 1 deletion src/arch/riscv64/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn get_fdt() -> Fdt<'static> {

pub fn get_stack_ptr() -> *mut u8 {
// SAFETY: We only create a pointer here
let stack_top = unsafe { ptr::addr_of_mut!(STACK) };
let stack_top = ptr::addr_of_mut!(STACK);
// SAFETY: Pointing directly past the object is allowed
let stack_bottom = unsafe { stack_top.add(1) };
stack_bottom.cast::<u8>()
Expand Down
5 changes: 2 additions & 3 deletions src/arch/x86_64/firecracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn find_kernel() -> &'static [u8] {
let elf_start = ramdisk_address as usize;
let elf_len = ramdisk_size as usize;

let free_memory_address = unsafe { ptr::addr_of!(loader_end) }
let free_memory_address = ptr::addr_of!(loader_end)
.addr()
.align_up(Size2MiB::SIZE as usize);
// TODO: Workaround for https://github.com/hermitcore/loader/issues/96
Expand Down Expand Up @@ -122,8 +122,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
} = kernel_info;

// determine boot stack address
let new_stack =
(unsafe { ptr::addr_of!(loader_end) }.addr() + 0x1000).align_up(Size4KiB::SIZE as usize);
let new_stack = (ptr::addr_of!(loader_end).addr() + 0x1000).align_up(Size4KiB::SIZE as usize);

let cmdline_ptr = unsafe {
*(sptr::from_exposed_addr(boot_params + LINUX_SETUP_HEADER_OFFSET + CMD_LINE_PTR_OFFSET))
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/multiboot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut mem).unwrap() };

// determine boot stack address
let mut new_stack = unsafe { ptr::addr_of!(loader_end) }
let mut new_stack = ptr::addr_of!(loader_end)
.addr()
.align_up(Size4KiB::SIZE as usize);

Expand Down