size_of and align_of are part of the prelude nowadays

This commit is contained in:
bjorn3
2026-04-06 15:19:52 +02:00
committed by Jeremy Soller
parent 2e784dfe46
commit 654ee6ca3e
42 changed files with 137 additions and 166 deletions
+8 -8
View File
@@ -4,7 +4,7 @@ use crate::{
percpu::PercpuBlock,
syscall::FloatRegisters,
};
use core::{mem, mem::offset_of, ptr, sync::atomic::AtomicBool};
use core::{mem::offset_of, ptr, sync::atomic::AtomicBool};
use spin::Once;
use syscall::{EnvRegisters, Result};
@@ -92,7 +92,7 @@ impl Context {
) {
let mut stack_top = stack.initial_top();
const INT_REGS_SIZE: usize = core::mem::size_of::<InterruptStack>();
const INT_REGS_SIZE: usize = size_of::<InterruptStack>();
if userspace_allowed {
unsafe {
@@ -230,9 +230,9 @@ unsafe extern "C" fn fp_save(float_regs: &mut FloatRegisters) {
"str x9, [{3}]",
"mrs x9, fpsr",
"str x9, [{3}, {2} - {1}]",
const mem::offset_of!(FloatRegisters, fp_simd_regs),
const mem::offset_of!(FloatRegisters, fpcr),
const mem::offset_of!(FloatRegisters, fpsr),
const offset_of!(FloatRegisters, fp_simd_regs),
const offset_of!(FloatRegisters, fpcr),
const offset_of!(FloatRegisters, fpsr),
inout(reg) float_regs => _,
);
}
@@ -263,9 +263,9 @@ unsafe extern "C" fn fp_load(float_regs: &mut FloatRegisters) {
"msr fpcr, x9",
"ldr x9, [{3}, {2} - {1}]",
"msr fpsr, x9",
const mem::offset_of!(FloatRegisters, fp_simd_regs),
const mem::offset_of!(FloatRegisters, fpcr),
const mem::offset_of!(FloatRegisters, fpsr),
const offset_of!(FloatRegisters, fp_simd_regs),
const offset_of!(FloatRegisters, fpcr),
const offset_of!(FloatRegisters, fpsr),
inout(reg) float_regs => _,
);
}
+1 -1
View File
@@ -55,7 +55,7 @@ impl Context {
) {
let mut stack_top = stack.initial_top();
const INT_REGS_SIZE: usize = core::mem::size_of::<InterruptStack>();
const INT_REGS_SIZE: usize = size_of::<InterruptStack>();
if userspace_allowed {
unsafe {
+3 -3
View File
@@ -77,7 +77,7 @@ impl Context {
) {
let mut stack_top = stack.initial_top();
const INT_REGS_SIZE: usize = core::mem::size_of::<InterruptStack>();
const INT_REGS_SIZE: usize = size_of::<InterruptStack>();
unsafe {
if userspace_allowed {
@@ -86,13 +86,13 @@ impl Context {
stack_top.write_bytes(0_u8, INT_REGS_SIZE);
(&mut *stack_top.cast::<InterruptStack>()).init();
stack_top = stack_top.sub(core::mem::size_of::<usize>());
stack_top = stack_top.sub(size_of::<usize>());
stack_top
.cast::<usize>()
.write(crate::interrupt::syscall::enter_usermode as usize);
}
stack_top = stack_top.sub(core::mem::size_of::<usize>());
stack_top = stack_top.sub(size_of::<usize>());
stack_top.cast::<usize>().write(func as usize);
}
+3 -3
View File
@@ -89,7 +89,7 @@ impl Context {
) {
let mut stack_top = stack.initial_top();
const INT_REGS_SIZE: usize = core::mem::size_of::<InterruptStack>();
const INT_REGS_SIZE: usize = size_of::<InterruptStack>();
// Kstack::initial_top() is always at least 8 byte aligned. assertion to be safe
debug_assert!(
@@ -104,13 +104,13 @@ impl Context {
stack_top.write_bytes(0_u8, INT_REGS_SIZE);
(*stack_top.cast::<InterruptStack>()).init();
stack_top = stack_top.sub(core::mem::size_of::<usize>());
stack_top = stack_top.sub(size_of::<usize>());
stack_top
.cast::<usize>()
.write(crate::interrupt::syscall::enter_usermode as usize);
}
stack_top = stack_top.sub(core::mem::size_of::<usize>());
stack_top = stack_top.sub(size_of::<usize>());
stack_top.cast::<usize>().write(func as usize);
}
+4 -4
View File
@@ -405,7 +405,7 @@ impl Context {
this_percpu.maybe_handle_tlb_shootdown();
}
let _old_addrsp = core::mem::replace(
let _old_addrsp = mem::replace(
&mut *this_percpu.current_addrsp.borrow_mut(),
addr_space.clone(),
);
@@ -454,8 +454,8 @@ impl Context {
sig: &mut SignalState,
) -> (&Sigcontrol, &SigProcControl, &mut SignalState) {
let check = |off| {
assert_eq!(usize::from(off) % mem::align_of::<usize>(), 0);
assert!(usize::from(off).saturating_add(mem::size_of::<Sigcontrol>()) < PAGE_SIZE);
assert_eq!(usize::from(off) % align_of::<usize>(), 0);
assert!(usize::from(off).saturating_add(size_of::<Sigcontrol>()) < PAGE_SIZE);
};
check(sig.procctl_off);
check(sig.threadctl_off);
@@ -547,7 +547,7 @@ impl BorrowedHtBuf {
core::str::from_utf8(slice).map_err(|_| Error::new(EINVAL))
}
pub unsafe fn use_for_struct<T>(&mut self) -> Result<&mut T> {
if mem::size_of::<T>() > PAGE_SIZE || mem::align_of::<T>() > PAGE_SIZE {
if size_of::<T>() > PAGE_SIZE || align_of::<T>() > PAGE_SIZE {
return Err(Error::new(EINVAL));
}
self.buf_mut().fill(0_u8);