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
+3 -3
View File
@@ -1,5 +1,5 @@
use alloc::{borrow::ToOwned, string::String, vec::Vec};
use core::{ascii, fmt::Debug, mem};
use core::{ascii, fmt::Debug};
use super::{
copy_path_to_buf,
@@ -38,7 +38,7 @@ fn debug_buf(ptr: usize, len: usize) -> Result<Vec<u8>> {
})
}
unsafe fn read_struct<T>(ptr: usize) -> Result<T> {
unsafe { UserSlice::ro(ptr, mem::size_of::<T>()).and_then(|slice| slice.read_exact::<T>()) }
unsafe { UserSlice::ro(ptr, size_of::<T>()).and_then(|slice| slice.read_exact::<T>()) }
}
//TODO: calling format_call with arguments from another process space will not work
@@ -144,7 +144,7 @@ pub fn format_call(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, g
let mut times = vec![unsafe { buf.read_exact::<TimeSpec>()? }];
// One or two timespecs
if let Some(second) = buf.advance(mem::size_of::<TimeSpec>()) {
if let Some(second) = buf.advance(size_of::<TimeSpec>()) {
times.push(unsafe { second.read_exact::<TimeSpec>()? });
}
Ok(times)
+1 -1
View File
@@ -1,6 +1,6 @@
//! Filesystem syscalls
use core::{mem::size_of, num::NonZeroUsize};
use core::num::NonZeroUsize;
use alloc::{string::String, sync::Arc, vec::Vec};
use redox_path::RedoxPath;
+2 -2
View File
@@ -54,7 +54,7 @@ static FUTEXES: Mutex<L1, FutexList> =
fn validate_and_translate_virt(space: &AddrSpace, addr: VirtualAddress) -> Option<PhysicalAddress> {
// TODO: Move this elsewhere!
if addr.data().saturating_add(core::mem::size_of::<usize>()) >= crate::USER_END_OFFSET {
if addr.data().saturating_add(size_of::<usize>()) >= crate::USER_END_OFFSET {
return None;
}
@@ -87,7 +87,7 @@ pub fn futex(
match op {
// TODO: FUTEX_WAIT_MULTIPLE?
FUTEX_WAIT | FUTEX_WAIT64 => {
let timeout_opt = UserSlice::ro(val2, core::mem::size_of::<TimeSpec>())?
let timeout_opt = UserSlice::ro(val2, size_of::<TimeSpec>())?
.none_if_null()
.map(|buf| unsafe { buf.read_exact::<TimeSpec>() })
.transpose()?;
+5 -10
View File
@@ -4,8 +4,6 @@
extern crate syscall;
use core::mem::size_of;
use syscall::{dirent::DirentHeader, CallFlags, RwFlags, EINVAL};
pub use self::syscall::{
@@ -223,17 +221,14 @@ pub fn syscall(
}
SYS_YIELD => sched_yield(token).map(|()| 0),
SYS_NANOSLEEP => nanosleep(
UserSlice::ro(b, core::mem::size_of::<TimeSpec>())?,
UserSlice::wo(c, core::mem::size_of::<TimeSpec>())?.none_if_null(),
token,
)
.map(|()| 0),
SYS_CLOCK_GETTIME => clock_gettime(
b,
UserSlice::wo(c, core::mem::size_of::<TimeSpec>())?,
UserSlice::ro(b, size_of::<TimeSpec>())?,
UserSlice::wo(c, size_of::<TimeSpec>())?.none_if_null(),
token,
)
.map(|()| 0),
SYS_CLOCK_GETTIME => {
clock_gettime(b, UserSlice::wo(c, size_of::<TimeSpec>())?, token).map(|()| 0)
}
SYS_FUTEX => futex(b, c, d, e, f, token),
SYS_MPROTECT => mprotect(b, c, MapFlags::from_bits_truncate(d), token).map(|()| 0),
+5 -5
View File
@@ -204,7 +204,7 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok
.expect("Failed to allocate kernel scheme info page");
let mut cursor = kernel_schemes_info_page.start_address().data();
const HEADER_SIZE: usize = mem::size_of::<usize>();
const HEADER_SIZE: usize = size_of::<usize>();
UserSliceWo::new(cursor, HEADER_SIZE)
.expect("failed to create kernel schemes header user slice")
.copy_common_bytes_from_slice(&KERNEL_SCHEMES_COUNT.to_ne_bytes())
@@ -213,18 +213,18 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok
let info_bytes = unsafe {
core::slice::from_raw_parts(
kernel_schemes_infos.as_ptr() as *const u8,
KERNEL_SCHEMES_COUNT * mem::size_of::<syscall::data::KernelSchemeInfo>(),
KERNEL_SCHEMES_COUNT * size_of::<syscall::data::KernelSchemeInfo>(),
)
};
UserSliceWo::new(
cursor,
KERNEL_SCHEMES_COUNT * mem::size_of::<syscall::data::KernelSchemeInfo>(),
KERNEL_SCHEMES_COUNT * size_of::<syscall::data::KernelSchemeInfo>(),
)
.expect("failed to create kernel schemes info user slice")
.copy_common_bytes_from_slice(info_bytes)
.expect("failed to copy kernel schemes info");
cursor += KERNEL_SCHEMES_COUNT * mem::size_of::<syscall::data::KernelSchemeInfo>();
UserSliceWo::new(cursor, mem::size_of::<usize>())
cursor += KERNEL_SCHEMES_COUNT * size_of::<syscall::data::KernelSchemeInfo>();
UserSliceWo::new(cursor, size_of::<usize>())
.expect("failed to create scheme creation cap user slice")
.copy_common_bytes_from_slice(&scheme_creation_cap.to_ne_bytes())
.expect("failed to copy scheme creation cap");
+6 -9
View File
@@ -109,13 +109,10 @@ impl<const WRITE: bool> UserSlice<true, WRITE> {
pub unsafe fn read_exact<T>(self) -> Result<T> {
let mut t: T = unsafe { core::mem::zeroed() };
let slice = unsafe {
core::slice::from_raw_parts_mut(
(&mut t as *mut T).cast::<u8>(),
core::mem::size_of::<T>(),
)
core::slice::from_raw_parts_mut((&mut t as *mut T).cast::<u8>(), size_of::<T>())
};
self.limit(core::mem::size_of::<T>())
self.limit(size_of::<T>())
.ok_or(Error::new(EINVAL))?
.copy_to_slice(slice)?;
@@ -131,7 +128,7 @@ impl<const WRITE: bool> UserSlice<true, WRITE> {
// TODO: Merge int IO functions?
pub fn read_usize(self) -> Result<usize> {
let mut ret = 0_usize.to_ne_bytes();
self.limit(core::mem::size_of::<usize>())
self.limit(size_of::<usize>())
.ok_or(Error::new(EINVAL))?
.copy_to_slice(&mut ret)?;
Ok(usize::from_ne_bytes(ret))
@@ -144,7 +141,7 @@ impl<const WRITE: bool> UserSlice<true, WRITE> {
Ok(u32::from_ne_bytes(ret))
}
pub fn usizes(self) -> impl Iterator<Item = Result<usize>> {
self.in_exact_chunks(core::mem::size_of::<usize>())
self.in_exact_chunks(size_of::<usize>())
.map(Self::read_usize)
}
}
@@ -177,13 +174,13 @@ impl<const READ: bool> UserSlice<READ, true> {
Ok(())
}
pub fn write_usize(self, word: usize) -> Result<()> {
self.limit(core::mem::size_of::<usize>())
self.limit(size_of::<usize>())
.ok_or(Error::new(EINVAL))?
.copy_from_slice(&word.to_ne_bytes())?;
Ok(())
}
pub fn write_u32(self, int: u32) -> Result<()> {
self.limit(core::mem::size_of::<u32>())
self.limit(size_of::<u32>())
.ok_or(Error::new(EINVAL))?
.copy_from_slice(&int.to_ne_bytes())?;
Ok(())