Skip to content

Commit c26afdd

Browse files
authored
Merge pull request #2095 from hermit-os/fn-as-usize
fix: avoid casting functions to usize if possible
2 parents faf8d37 + b70840b commit c26afdd

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/arch/aarch64/kernel/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn boot_next_processor() {
137137
if cpu_online == 0 {
138138
use aarch64_cpu::registers::{Readable, TTBR0_EL1};
139139

140-
let virt_start = VirtAddr::from(smp_start as *const () as usize);
140+
let virt_start = VirtAddr::from_ptr(smp_start as *const ());
141141
let phys_start = virtual_to_physical(virt_start).unwrap();
142142
assert!(virt_start.as_u64() == phys_start.as_u64());
143143

src/arch/x86_64/kernel/apic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ pub fn init_next_processor_variables() {
750750
pub fn boot_application_processors() {
751751
use core::hint;
752752

753+
use hermit_entry::boot_info::RawBootInfo;
753754
use x86_64::structures::paging::Translate;
754755

755756
use super::start;
@@ -800,10 +801,9 @@ pub fn boot_application_processors() {
800801
"Set entry point for application processor to {:p}",
801802
start::_start as *const ()
802803
);
803-
ptr::write_unaligned(
804-
(SMP_BOOT_CODE_ADDRESS + SMP_BOOT_CODE_OFFSET_ENTRY).as_mut_ptr(),
805-
start::_start as *const () as usize,
806-
);
804+
(SMP_BOOT_CODE_ADDRESS + SMP_BOOT_CODE_OFFSET_ENTRY)
805+
.as_mut_ptr::<unsafe extern "C" fn(Option<&'static RawBootInfo>, cpu_id: u32) -> !>()
806+
.write_unaligned(start::_start);
807807
}
808808

809809
// Now wake up each application processor.

src/arch/x86_64/kernel/processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ pub fn configure() {
917917
let cs_syscall = SegmentSelector::new(1, PrivilegeLevel::Ring0);
918918
let ss_syscall = SegmentSelector::new(2, PrivilegeLevel::Ring0);
919919
Star::write(cs_sysret, ss_sysret, cs_syscall, ss_syscall).unwrap();
920-
let syscall_handler_addr = syscall::syscall_handler as *const () as usize;
921-
let syscall_handler_addr = VirtAddr::new(syscall_handler_addr.try_into().unwrap());
920+
let syscall_handler_addr = syscall::syscall_handler as *const ();
921+
let syscall_handler_addr = VirtAddr::from_ptr(syscall_handler_addr);
922922
LStar::write(syscall_handler_addr);
923923
SFMask::write(RFlags::INTERRUPT_FLAG); // clear IF flag during system call
924924
}

0 commit comments

Comments
 (0)