From 51714c4cb98716f1161a610451f39eb13ee47976 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:16:04 -0400 Subject: [PATCH 01/15] treewide: format TOML with taplo --- .cargo/config.toml | 10 +++++----- hotpath/policy.toml | 12 ++++++------ microfetch/Cargo.toml | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 9ed6285..dc272f3 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,12 +5,12 @@ # so they only affect the final binary and don't break proc-macro or build-script linking. [target.'cfg(target_os = "linux")'] # Suppress .eh_frame emission from our own codegen. -rustflags = ["-C", "force-unwind-tables=no"] +rustflags = [ "-C", "force-unwind-tables=no" ] [target.x86_64-unknown-linux-gnu] -linker = "scripts/clang-wild" -rustflags = ["-C", "force-unwind-tables=no"] +linker = "scripts/clang-wild" +rustflags = [ "-C", "force-unwind-tables=no" ] [target.aarch64-unknown-linux-gnu] -linker = "scripts/clang-wild" -rustflags = ["-C", "force-unwind-tables=no"] +linker = "scripts/clang-wild" +rustflags = [ "-C", "force-unwind-tables=no" ] diff --git a/hotpath/policy.toml b/hotpath/policy.toml index d084a0a..745d638 100644 --- a/hotpath/policy.toml +++ b/hotpath/policy.toml @@ -6,13 +6,13 @@ min_percent_total = 2 [functions.alloc] -judged = true +judged = true +metrics = [ "avg", "total" ] +min_calls = 1 min_percent_change = 20 -metrics = ["avg", "total"] -min_calls = 1 [functions.timing] -judged = false +judged = false +metrics = [ "avg", "total" ] +min_calls = 1 min_percent_change = 50 -metrics = ["avg", "total"] -min_calls = 1 diff --git a/microfetch/Cargo.toml b/microfetch/Cargo.toml index 5d0bfee..329dfd2 100644 --- a/microfetch/Cargo.toml +++ b/microfetch/Cargo.toml @@ -10,12 +10,12 @@ repository = "https://github.com/notashelf/microfetch" publish = true [[bin]] -name = "microfetch" -test = false +name = "microfetch" +test = false [dependencies] -microfetch-asm.workspace = true -microfetch-lib.workspace = true +microfetch-asm.workspace = true +microfetch-lib.workspace = true [lints] workspace = true From 6e8dbd9aeef5ad41d20a958cb5f2c86b45167a4c Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:16:10 -0400 Subject: [PATCH 02/15] treewide: fix clippy lints --- crates/asm/src/aarch64.rs | 18 +++++++-------- crates/asm/src/arm.rs | 18 +++++++-------- crates/asm/src/darwin.rs | 43 +++++++++++++++++++---------------- crates/asm/src/loongarch64.rs | 18 +++++++-------- crates/asm/src/mips.rs | 18 +++++++-------- crates/asm/src/mips64.rs | 18 +++++++-------- crates/asm/src/powerpc.rs | 18 +++++++-------- crates/asm/src/powerpc64.rs | 18 +++++++-------- crates/asm/src/riscv32.rs | 18 +++++++-------- crates/asm/src/riscv64.rs | 18 +++++++-------- crates/asm/src/s390x.rs | 18 +++++++-------- crates/asm/src/sparc.rs | 18 +++++++-------- crates/asm/src/sparc64.rs | 18 +++++++-------- crates/asm/src/x86.rs | 18 +++++++-------- crates/lib/src/cpu.rs | 5 ++-- crates/lib/src/lib.rs | 15 ++++++------ crates/lib/src/release.rs | 10 ++++---- crates/lib/src/system.rs | 22 ++++++------------ crates/lib/src/uptime.rs | 5 ++-- microfetch/src/main.rs | 27 ++++++++++++++-------- 20 files changed, 180 insertions(+), 181 deletions(-) diff --git a/crates/asm/src/aarch64.rs b/crates/asm/src/aarch64.rs index 6997f62..9635a23 100644 --- a/crates/asm/src/aarch64.rs +++ b/crates/asm/src/aarch64.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let fd: i64; core::arch::asm!( @@ -22,7 +22,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -42,7 +42,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -62,7 +62,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -79,7 +79,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -96,7 +96,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -115,7 +115,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -129,7 +129,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -152,7 +152,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "svc #0", diff --git a/crates/asm/src/arm.rs b/crates/asm/src/arm.rs index 892b012..18f0229 100644 --- a/crates/asm/src/arm.rs +++ b/crates/asm/src/arm.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -18,7 +18,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -34,7 +34,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -50,7 +50,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -64,7 +64,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -78,7 +78,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -94,7 +94,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; core::arch::asm!( @@ -108,7 +108,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -128,7 +128,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "svc #0", diff --git a/crates/asm/src/darwin.rs b/crates/asm/src/darwin.rs index 4c15518..06d80da 100644 --- a/crates/asm/src/darwin.rs +++ b/crates/asm/src/darwin.rs @@ -59,40 +59,48 @@ unsafe extern "C" { ) -> c_int; } -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { open(path.cast::(), flags) } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { read(fd, buf.cast::(), count) } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { write(fd, buf.cast::(), count) } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { close(fd) } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { uname(buf) } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { statfs(path.cast::(), buf) } } /// macOS has no `sysinfo(2)`; uptime comes from [`macos_uptime_secs`] instead. /// This stub exists only so the generic wrapper in `lib.rs` keeps compiling. -pub(super) unsafe fn sys_sysinfo(_info: *mut SysInfo) -> i64 { +#[allow( + clippy::missing_const_for_fn, + reason = "keeps the signature of the syscall it stands in for" +)] +pub unsafe fn sys_sysinfo(_info: *mut SysInfo) -> i64 { -1 } /// macOS has no `sched_getaffinity(2)`; core counts come from `sysctl` /// (`hw.logicalcpu` / `hw.physicalcpu`). This stub keeps the generic wrapper /// compiling. -pub(super) unsafe fn sys_sched_getaffinity( +#[allow( + clippy::missing_const_for_fn, + reason = "keeps the signature of the syscall it stands in for" +)] +pub unsafe fn sys_sched_getaffinity( _pid: i32, _mask_size: usize, _mask: *mut u8, @@ -100,7 +108,7 @@ pub(super) unsafe fn sys_sched_getaffinity( -1 } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { _exit(code) } } @@ -115,7 +123,7 @@ pub fn macos_sysctl_str(name: &[u8], out: &mut [u8]) -> Option { sysctlbyname( name.as_ptr().cast::(), out.as_mut_ptr().cast::(), - &mut len, + &raw mut len, ptr::null(), 0, ) @@ -136,7 +144,7 @@ pub fn macos_sysctl_u32(name: &[u8]) -> Option { sysctlbyname( name.as_ptr().cast::(), ptr::from_mut(&mut val).cast::(), - &mut len, + &raw mut len, ptr::null(), 0, ) @@ -156,7 +164,7 @@ fn macos_sysctl_u64(name: &[u8]) -> Option { sysctlbyname( name.as_ptr().cast::(), ptr::from_mut(&mut val).cast::(), - &mut len, + &raw mut len, ptr::null(), 0, ) @@ -222,7 +230,7 @@ pub fn macos_meminfo() -> Option<(u64, u64)> { mach_host_self(), HOST_VM_INFO64, ptr::from_mut(&mut vm).cast::(), - &mut count, + &raw mut count, ) }; if kr != 0 { @@ -240,10 +248,7 @@ pub fn macos_meminfo() -> Option<(u64, u64)> { /// `struct timeval` (`time_t` is 64-bit, `suseconds_t` is 32-bit on macOS). #[repr(C)] #[derive(Default)] -#[allow( - dead_code, - reason = "tv_usec/_pad exist only to fix the struct layout" -)] +#[allow(dead_code, reason = "tv_usec/_pad exist only to fix the struct layout")] struct Timeval { tv_sec: i64, tv_usec: i32, @@ -264,7 +269,7 @@ pub fn macos_uptime_secs() -> Option { mib.as_ptr(), mib.len() as u32, ptr::from_mut(&mut boot).cast::(), - &mut len, + &raw mut len, ptr::null(), 0, ) @@ -274,7 +279,7 @@ pub fn macos_uptime_secs() -> Option { } let mut now = Timeval::default(); - if unsafe { gettimeofday(&mut now, ptr::null_mut()) } != 0 { + if unsafe { gettimeofday(&raw mut now, ptr::null_mut()) } != 0 { return None; } diff --git a/crates/asm/src/loongarch64.rs b/crates/asm/src/loongarch64.rs index d5ab5ac..08a6098 100644 --- a/crates/asm/src/loongarch64.rs +++ b/crates/asm/src/loongarch64.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let fd: i64; core::arch::asm!( @@ -22,7 +22,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -41,7 +41,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -60,7 +60,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -77,7 +77,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -94,7 +94,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -112,7 +112,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -126,7 +126,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -149,7 +149,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall 0", diff --git a/crates/asm/src/mips.rs b/crates/asm/src/mips.rs index c5adf17..0b749b3 100644 --- a/crates/asm/src/mips.rs +++ b/crates/asm/src/mips.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -25,7 +25,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -48,7 +48,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -71,7 +71,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -92,7 +92,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -113,7 +113,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -136,7 +136,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; core::arch::asm!( @@ -157,7 +157,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -184,7 +184,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall", diff --git a/crates/asm/src/mips64.rs b/crates/asm/src/mips64.rs index 9127a1e..709446c 100644 --- a/crates/asm/src/mips64.rs +++ b/crates/asm/src/mips64.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -28,7 +28,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -51,7 +51,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -74,7 +74,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -98,7 +98,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -122,7 +122,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -147,7 +147,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -168,7 +168,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -194,7 +194,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall", diff --git a/crates/asm/src/powerpc.rs b/crates/asm/src/powerpc.rs index e2e7829..efafcf7 100644 --- a/crates/asm/src/powerpc.rs +++ b/crates/asm/src/powerpc.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -23,7 +23,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -44,7 +44,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -65,7 +65,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -84,7 +84,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -103,7 +103,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -124,7 +124,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; core::arch::asm!( @@ -143,7 +143,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -168,7 +168,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "li 0, 1", // SYS_exit diff --git a/crates/asm/src/powerpc64.rs b/crates/asm/src/powerpc64.rs index 13e0b33..09a28ef 100644 --- a/crates/asm/src/powerpc64.rs +++ b/crates/asm/src/powerpc64.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -26,7 +26,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -50,7 +50,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -74,7 +74,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -96,7 +96,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -118,7 +118,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -141,7 +141,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -160,7 +160,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -188,7 +188,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "li 0, 1", // SYS_exit diff --git a/crates/asm/src/riscv32.rs b/crates/asm/src/riscv32.rs index 1e4b29a..811f47d 100644 --- a/crates/asm/src/riscv32.rs +++ b/crates/asm/src/riscv32.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -19,7 +19,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -35,7 +35,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -51,7 +51,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -65,7 +65,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -79,7 +79,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { // asm-generic __NR_statfs routes to sys_statfs64 on 32-bit: 3-arg form. let ret: i32; @@ -96,7 +96,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; core::arch::asm!( @@ -110,7 +110,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -130,7 +130,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "ecall", diff --git a/crates/asm/src/riscv64.rs b/crates/asm/src/riscv64.rs index 2a0c10b..fcfc804 100644 --- a/crates/asm/src/riscv64.rs +++ b/crates/asm/src/riscv64.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let fd: i64; core::arch::asm!( @@ -23,7 +23,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -43,7 +43,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -63,7 +63,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -80,7 +80,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -98,7 +98,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -117,7 +117,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -131,7 +131,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -154,7 +154,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "ecall", diff --git a/crates/asm/src/s390x.rs b/crates/asm/src/s390x.rs index 3112ed6..5c4377b 100644 --- a/crates/asm/src/s390x.rs +++ b/crates/asm/src/s390x.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let fd: i64; core::arch::asm!( @@ -21,7 +21,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -40,7 +40,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -59,7 +59,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -76,7 +76,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -93,7 +93,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -111,7 +111,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -125,7 +125,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -148,7 +148,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "svc 0", diff --git a/crates/asm/src/sparc.rs b/crates/asm/src/sparc.rs index a4cc3f7..b2dda90 100644 --- a/crates/asm/src/sparc.rs +++ b/crates/asm/src/sparc.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -21,7 +21,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -40,7 +40,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -59,7 +59,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -76,7 +76,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -93,7 +93,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -112,7 +112,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; core::arch::asm!( @@ -129,7 +129,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -152,7 +152,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "mov {nr}, %g1", diff --git a/crates/asm/src/sparc64.rs b/crates/asm/src/sparc64.rs index 020657e..c81d602 100644 --- a/crates/asm/src/sparc64.rs +++ b/crates/asm/src/sparc64.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -24,7 +24,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -43,7 +43,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i64; core::arch::asm!( @@ -62,7 +62,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -82,7 +82,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -102,7 +102,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i64; core::arch::asm!( @@ -123,7 +123,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; core::arch::asm!( @@ -140,7 +140,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -166,7 +166,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "mov {nr}, %g1", diff --git a/crates/asm/src/x86.rs b/crates/asm/src/x86.rs index f0e619e..e2bd1ad 100644 --- a/crates/asm/src/x86.rs +++ b/crates/asm/src/x86.rs @@ -2,7 +2,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; -pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -19,7 +19,7 @@ pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { } } -pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -36,7 +36,7 @@ pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: i32; core::arch::asm!( @@ -53,7 +53,7 @@ pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { } } -pub(super) unsafe fn sys_close(fd: i32) -> i32 { +pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -68,7 +68,7 @@ pub(super) unsafe fn sys_close(fd: i32) -> i32 { } } -pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -83,7 +83,7 @@ pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { } } -pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; core::arch::asm!( @@ -100,7 +100,7 @@ pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { } } -pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { +pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; core::arch::asm!( @@ -115,7 +115,7 @@ pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { } } -pub(super) unsafe fn sys_sched_getaffinity( +pub unsafe fn sys_sched_getaffinity( pid: i32, mask_size: usize, mask: *mut u8, @@ -136,7 +136,7 @@ pub(super) unsafe fn sys_sched_getaffinity( } } -pub(super) unsafe fn sys_exit(code: i32) -> ! { +pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "mov ebx, {code:e}", diff --git a/crates/lib/src/cpu.rs b/crates/lib/src/cpu.rs index 06c9981..8197058 100644 --- a/crates/lib/src/cpu.rs +++ b/crates/lib/src/cpu.rs @@ -17,10 +17,9 @@ pub fn write_cpu_name(w: &mut StackWriter) { let mut buf = [0u8; 128]; if let Some(n) = crate::syscall::macos_sysctl_str(b"machdep.cpu.brand_string\0", &mut buf) + && let Ok(name) = core::str::from_utf8(&buf[..n]) { - if let Ok(name) = core::str::from_utf8(&buf[..n]) { - w.push_str(name); - } + w.push_str(name); } } diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index d756692..35c1a15 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -215,7 +215,7 @@ impl<'a> StackWriter<'a> { #[inline] #[must_use] - pub fn written(&self) -> &[u8] { + pub const fn written(&self) -> &[u8] { unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast(), self.pos) } } @@ -238,7 +238,7 @@ impl<'a> StackWriter<'a> { } #[inline] - pub fn push_byte(&mut self, b: u8) { + pub const fn push_byte(&mut self, b: u8) { if self.pos < self.buf.len() { self.buf[self.pos].write(b); self.pos += 1; @@ -343,11 +343,10 @@ fn write_row( if let Some(custom_logo) = custom_logo { w.push_str(c.cyan); w.push_str(custom_logo); - w.push_str(c.reset); } else { write_styled_row(w, c, logo); - w.push_str(c.reset); } + w.push_str(c.reset); w.push_str(" "); if row != 0 { write_styled_row(w, c, labels); @@ -448,26 +447,26 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> { // Custom logo is 11 lines from MICROFETCH_LOGO env var, one per info row. // Lines beyond 11 are ignored; missing lines render as empty. - let custom_lines: [&str; 11]; + let custom_lines: [&str; ROW_COUNT]; let use_custom = !CUSTOM_LOGO.is_empty(); let logo_lines = if use_custom { let mut lines_iter = CUSTOM_LOGO.split('\n'); custom_lines = core::array::from_fn(|_| lines_iter.next().unwrap_or("")); &custom_lines } else { - &[""; 11] // unused, we use LOGO pairs below + &[""; ROW_COUNT] // unused, we use LOGO pairs below }; let mut logo = LOGO; let mut labels = ROW_LABELS; w.push_byte(b'\n'); - for row in 0..ROW_COUNT { + for (row, &line) in logo_lines.iter().enumerate() { write_row( &mut w, &c, row, - use_custom.then_some(logo_lines[row]), + use_custom.then_some(line), &mut logo, &mut labels, &utsname, diff --git a/crates/lib/src/release.rs b/crates/lib/src/release.rs index cdcef26..21be72d 100644 --- a/crates/lib/src/release.rs +++ b/crates/lib/src/release.rs @@ -24,13 +24,11 @@ pub fn write_os_pretty_name(w: &mut StackWriter) -> Result<(), Error> { let mut buf = [0u8; 64]; if let Some(n) = crate::syscall::macos_sysctl_str(b"kern.osproductversion\0", &mut buf) + && let Ok(version) = core::str::from_utf8(&buf[..n]) + && !version.is_empty() { - if let Ok(version) = core::str::from_utf8(&buf[..n]) { - if !version.is_empty() { - w.push_byte(b' '); - w.push_str(version); - } - } + w.push_byte(b' '); + w.push_str(version); } Ok(()) } diff --git a/crates/lib/src/system.rs b/crates/lib/src/system.rs index 6bf431d..8f56e49 100644 --- a/crates/lib/src/system.rs +++ b/crates/lib/src/system.rs @@ -70,11 +70,7 @@ pub fn write_root_disk_usage( write_gib(w, total_bytes); w.push_str(" GiB ("); w.push_str(colors.cyan); - let pct = if total_bytes > 0 { - used_bytes * 100 / total_bytes - } else { - 0 - }; + let pct = (used_bytes * 100).checked_div(total_bytes).unwrap_or(0); w.push_u64(pct); w.push_byte(b'%'); w.push_str(colors.reset); @@ -128,11 +124,9 @@ pub fn write_memory_usage( ) -> Result<(), Error> { let (used_bytes, total_bytes) = crate::syscall::macos_meminfo().ok_or(Error::OsError(0))?; - let percentage_used = if total_bytes > 0 { - (used_bytes * 100 + total_bytes / 2) / total_bytes - } else { - 0 - }; + let percentage_used = (used_bytes * 100 + total_bytes / 2) + .checked_div(total_bytes) + .unwrap_or(0); write_gib(w, used_bytes); w.push_str(" GiB / "); @@ -209,11 +203,9 @@ pub fn write_memory_usage( } let (used_kb, total_kb) = parse_memory_info()?; - let percentage_used = if total_kb > 0 { - (used_kb * 100 + total_kb / 2) / total_kb - } else { - 0 - }; + let percentage_used = (used_kb * 100 + total_kb / 2) + .checked_div(total_kb) + .unwrap_or(0); write_kb_as_gib(w, used_kb); w.push_str(" GiB / "); diff --git a/crates/lib/src/uptime.rs b/crates/lib/src/uptime.rs index 55ced5f..919302b 100644 --- a/crates/lib/src/uptime.rs +++ b/crates/lib/src/uptime.rs @@ -28,12 +28,11 @@ pub fn write_uptime(w: &mut StackWriter) -> Result<(), Error> { let days = uptime_seconds / 86400; let hours = (uptime_seconds / 3600) % 24; let minutes = (uptime_seconds / 60) % 60; - let mut any = false; + let mut any = days > 0; - if days > 0 { + if any { w.push_u64(days); w.push_str(if days == 1 { " day" } else { " days" }); - any = true; } if hours > 0 { if any { diff --git a/microfetch/src/main.rs b/microfetch/src/main.rs index f6f9ffa..40d28db 100644 --- a/microfetch/src/main.rs +++ b/microfetch/src/main.rs @@ -9,12 +9,20 @@ ), feature(asm_experimental_arch) )] -#![cfg_attr(nightly, feature(lang_items))] +#![cfg_attr( + nightly, + feature(lang_items), + expect( + internal_features, + reason = "only the lang item can name the personality routine" + ) +)] -#[cfg(not(target_os = "macos"))] use core::arch::naked_asm; +#[cfg(not(any(target_os = "macos", target_abi = "elfv1")))] +use core::arch::naked_asm; // The custom `_start` (and the `entry_rust` it calls) is Linux-only. -#[cfg(not(target_os = "macos"))] +#[cfg(not(any(target_os = "macos", target_abi = "elfv1")))] use microfetch_asm::entry_rust; use microfetch_asm::sys_write; // Re-export libc replacement functions from asm crate. On macOS these are @@ -319,13 +327,12 @@ pub unsafe extern "C" fn main(argc: i32, argv: *const *const u8) -> i32 { } // Run the main application logic - match unsafe { microfetch_lib::run(argc, argv) } { - Ok(()) => 0, - Err(_) => { - const ERR_MSG: &[u8] = b"Error\n"; - let _ = unsafe { sys_write(2, ERR_MSG.as_ptr(), ERR_MSG.len()) }; - 1 - }, + if unsafe { microfetch_lib::run(argc, argv) }.is_ok() { + 0 + } else { + const ERR_MSG: &[u8] = b"Error\n"; + let _ = unsafe { sys_write(2, ERR_MSG.as_ptr(), ERR_MSG.len()) }; + 1 } } From c6b4feb3ecf3cd071d5d52f90a38780ba1b8582e Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 13:36:39 -0400 Subject: [PATCH 03/15] cargo: link dev builds with LTO --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3b703c0..49a800a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,12 +38,15 @@ too_many_lines = "allow" unused_trait_names = "allow" [profile.dev] +# nix's compiler_builtins carries compiler-rt objects that need libc, and only +# LTO keeps a debug link from pulling them in sadly +lto = "fat" opt-level = 1 panic = "abort" [profile.release] codegen-units = 1 -lto = true +lto = "fat" opt-level = "s" panic = "abort" strip = true From 77c2ac0ee689765f466bbe2752c7b4f0e3825e92 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 14:36:09 -0400 Subject: [PATCH 04/15] mips: link as a non-PIE executable entered at __start --- .cargo/config.toml | 5 +++++ microfetch/src/main.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index dc272f3..079ec3d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -14,3 +14,8 @@ rustflags = [ "-C", "force-unwind-tables=no" ] [target.aarch64-unknown-linux-gnu] linker = "scripts/clang-wild" rustflags = [ "-C", "force-unwind-tables=no" ] + +# rustc links these as PIE by default, but `__start` applies no relocations +# and never sets up $gp, so PIC code would read a GOT that does not exist. +[target.'cfg(any(target_arch = "mips", target_arch = "mips64"))'] +rustflags = [ "-C", "relocation-model=static" ] diff --git a/microfetch/src/main.rs b/microfetch/src/main.rs index 40d28db..adad1f7 100644 --- a/microfetch/src/main.rs +++ b/microfetch/src/main.rs @@ -247,7 +247,7 @@ unsafe extern "C" fn _start() { #[cfg(target_arch = "mips64")] #[unsafe(no_mangle)] #[unsafe(naked)] -unsafe extern "C" fn _start() { +unsafe extern "C" fn __start() { naked_asm!( "move $a0, $sp", // first arg = original sp (argc/argv) "daddiu $sp, $sp, -16",// reserve + keep 16-byte alignment (N64 ABI) @@ -295,7 +295,7 @@ extern "C" fn __atomic_store_1(ptr: *mut u8, val: u8, _order: i32) { #[cfg(target_arch = "mips")] #[unsafe(no_mangle)] #[unsafe(naked)] -unsafe extern "C" fn _start() { +unsafe extern "C" fn __start() { naked_asm!( "move $a0, $sp", // first arg = original sp (argc/argv) "addiu $sp, $sp, -24", // reserve 16-byte O32 shadow space + align From a799d2b6e87f015379e51c3b7db65c0530349788 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 16:09:43 -0400 Subject: [PATCH 05/15] bench: drop the unused criterion-cycles-per-byte dependency --- Cargo.lock | 80 ------------------------------------ Cargo.toml | 3 +- crates/benchmarks/Cargo.toml | 7 ++-- 3 files changed, 4 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5efb0e..edce76d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,8 +208,6 @@ dependencies = [ "num-traits", "oorandom", "page_size", - "plotters", - "rayon", "regex", "serde", "serde_json", @@ -217,16 +215,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "criterion-cycles-per-byte" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5396de42a52e9e5d8f67ef0702dae30451f310a9ba1c3094dcf228f0be0e54bc" -dependencies = [ - "cfg-if", - "criterion", -] - [[package]] name = "criterion-plot" version = "0.8.2" @@ -246,25 +234,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -626,7 +595,6 @@ name = "microfetch-bench" version = "1.2.0" dependencies = [ "criterion", - "criterion-cycles-per-byte", "hotpath", "microfetch-lib", ] @@ -688,34 +656,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" -[[package]] -name = "plotters" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" - -[[package]] -name = "plotters-svg" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" -dependencies = [ - "plotters-backend", -] - [[package]] name = "potential_utf" version = "0.1.6" @@ -773,26 +713,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "rayon" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "regex" version = "1.12.3" diff --git a/Cargo.toml b/Cargo.toml index 49a800a..63a2184 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,7 @@ version = "1.2.0" microfetch-asm = { path = "./crates/asm", version = "1.2.0" } microfetch-lib = { path = "./crates/lib", version = "1.2.0" } -criterion = { default-features = false, features = [ "cargo_bench_support" ], version = "0.8.2" } -criterion-cycles-per-byte = "0.8.0" +criterion = { default-features = false, features = [ "cargo_bench_support" ], version = "0.8.2" } [workspace.lints.clippy] complexity = { level = "warn", priority = -1 } diff --git a/crates/benchmarks/Cargo.toml b/crates/benchmarks/Cargo.toml index 89fd67c..0c31c4b 100644 --- a/crates/benchmarks/Cargo.toml +++ b/crates/benchmarks/Cargo.toml @@ -8,10 +8,9 @@ license.workspace = true publish = false [dependencies] -criterion.workspace = true -criterion-cycles-per-byte.workspace = true -hotpath = { optional = true, version = "0.28.3" } -microfetch-lib.workspace = true +criterion.workspace = true +hotpath = { optional = true, version = "0.28.3" } +microfetch-lib.workspace = true [features] hotpath = [ "dep:hotpath", "hotpath/hotpath", "microfetch-lib/hotpath" ] From 48909f6616b1cf2b870e2b9f4b4ea362e047ca59 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:18:23 -0400 Subject: [PATCH 06/15] ci: adopt the manic-systems reusable workflows --- .github/dependabot.yml | 26 +++-- .github/workflows/ci.yml | 132 ++++++++++++++++++++++++ .github/workflows/hotpath-benchmark.yml | 11 +- .github/workflows/hotpath-relay.yml | 4 +- .github/workflows/rust.yml | 114 -------------------- 5 files changed, 159 insertions(+), 128 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a1067c4..1ba4475 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,14 +1,28 @@ version: 2 updates: - # Update Cargo deps - package-ecosystem: cargo - directory: "/" + directory: / schedule: - interval: "weekly" + interval: weekly + cooldown: + default-days: 7 - # Update used workflows - package-ecosystem: github-actions - directory: "/" + directory: / schedule: - interval: daily + interval: weekly + cooldown: + default-days: 7 + exclude: [manic-systems/*] + groups: + actions: + patterns: ["*"] + - package-ecosystem: nix + directory: / + schedule: + interval: weekly + cooldown: + default-days: 7 + commit-message: + prefix: flake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5f7a55f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,132 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + merge_group: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name != 'push' }} + +jobs: + checks: + name: Checks (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, ubuntu-26.04-arm, macos-latest] + uses: manic-systems/workflows/.github/workflows/rust-checks.yml@4d2d4a73ac933d23f00fb7a17dd39569f8e1c1dc # v2.3.2 + with: + os: ${{ matrix.os }} + flake-check: false + fmt: ${{ matrix.os == 'ubuntu-latest' }} + fmt-command: cargo fmt --all --check && taplo fmt --check + clippy: true + clippy-command: cargo clippy --locked --workspace --all-targets -- -D warnings + test: true + test-command: >- + cargo build --locked && + cargo test --locked --workspace --exclude microfetch + + cross: + name: Cross (${{ matrix.target }}) + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-unknown-linux-gnu + toolchain: stable + - target: aarch64-unknown-linux-gnu + toolchain: stable + - target: riscv64gc-unknown-linux-gnu + toolchain: stable + - target: loongarch64-unknown-linux-gnu + toolchain: stable + - target: s390x-unknown-linux-gnu + toolchain: stable + # powerpc64 uses experimental asm features + - target: powerpc64le-unknown-linux-gnu + toolchain: nightly + - target: powerpc64-unknown-linux-gnu + toolchain: nightly + - target: armv7-unknown-linux-gnueabihf + toolchain: stable + # riscv32 is tier-3 + - target: riscv32gc-unknown-linux-gnu + toolchain: nightly + build-std: true + # sparc64 uses experimental asm features + - target: sparc64-unknown-linux-gnu + toolchain: nightly + # mips64 is tier-3 and uses experimental asm features + - target: mips64-unknown-linux-gnuabi64 + toolchain: nightly + build-std: true + - target: i686-unknown-linux-gnu + toolchain: stable + # powerpc uses experimental asm features + - target: powerpc-unknown-linux-gnu + toolchain: nightly + # mips is tier-3 and uses experimental asm features + - target: mips-unknown-linux-gnu + toolchain: nightly + build-std: true + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 + with: + toolchain: ${{ matrix.toolchain }} + target: ${{ !matrix.build-std && matrix.target || '' }} + components: ${{ matrix.build-std && 'rust-src' || '' }} + + - name: Install wild + uses: wild-linker/action@dc926c45399e1842cf81e604f52bdf0ad86a0c09 # v0.10.0 + + - name: Put wild on PATH + run: echo "$RUNNER_TEMP/wild-install" >> "$GITHUB_PATH" + + - name: Set up cross toolchain + uses: taiki-e/setup-cross-toolchain-action@12b7ad4acfa95a1476779d6c06699b96ec1691f8 # v1.42.0 + with: + target: ${{ matrix.target }} + + - name: Build + env: + TARGET: ${{ matrix.target }} + BUILD_STD: ${{ matrix.build-std && 'core,alloc,panic_abort' || '' }} + run: cargo build --locked --target "$TARGET" ${BUILD_STD:+-Zbuild-std="$BUILD_STD"} + + # tier-3 targets have no prebuilt std and tests are arch-agnostic, so + # run them against the host toolchain instead of the cross target. + - name: Test + env: + HOST_TARGET: ${{ matrix.build-std && 'x86_64-unknown-linux-gnu' || '' }} + run: cargo test --locked --workspace --exclude microfetch ${HOST_TARGET:+--target "$HOST_TARGET"} + + actions: + name: Actions Lint + uses: manic-systems/workflows/.github/workflows/actions-lint.yml@4d2d4a73ac933d23f00fb7a17dd39569f8e1c1dc # v2.3.2 + + required: + name: Required Checks + if: always() + needs: + - checks + - cross + - actions + runs-on: ubuntu-latest + steps: + - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') + run: exit 1 diff --git a/.github/workflows/hotpath-benchmark.yml b/.github/workflows/hotpath-benchmark.yml index 3cc4217..60e3f85 100644 --- a/.github/workflows/hotpath-benchmark.yml +++ b/.github/workflows/hotpath-benchmark.yml @@ -18,16 +18,15 @@ jobs: env: HOTPATH_BENCHMARK: microfetch steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + persist-credentials: false ref: ${{ github.event.pull_request.head.sha || github.sha }} - - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - rustflags: "" + - uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2.0.0 - name: Install the wild linker - uses: wild-linker/action@v0.10.0 + uses: wild-linker/action@dc926c45399e1842cf81e604f52bdf0ad86a0c09 # v0.10.0 - name: Put wild on PATH run: echo "$RUNNER_TEMP/wild-install" >> "$GITHUB_PATH" @@ -53,7 +52,7 @@ jobs: cargo run -q --release -p microfetch-bench --example hotpath \ --features hotpath,hotpath-alloc,hotpath-cloud - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: github.event_name == 'pull_request' with: name: hotpath-report diff --git a/.github/workflows/hotpath-relay.yml b/.github/workflows/hotpath-relay.yml index 818cf09..4ffbe43 100644 --- a/.github/workflows/hotpath-relay.yml +++ b/.github/workflows/hotpath-relay.yml @@ -1,14 +1,14 @@ name: hotpath-relay on: - workflow_run: + workflow_run: # zizmor: ignore[dangerous-triggers] hotpath relays the PR report artifact workflows: ["hotpath-benchmark"] types: - completed jobs: relay: - uses: pawurb/hotpath-rs/.github/workflows/hotpath-relay.yml@v0.28.5 + uses: pawurb/hotpath-rs/.github/workflows/hotpath-relay.yml@3c6a2b5dd994da3db5a3d23e1cc6b91c542bec2a # v0.28.5 permissions: actions: read id-token: write diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index c699a69..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,114 +0,0 @@ -name: Rust - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - test: - name: Test on ${{ matrix.target }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - target: x86_64-unknown-linux-gnu - toolchain: stable - - target: aarch64-unknown-linux-gnu - toolchain: stable - - target: riscv64gc-unknown-linux-gnu - toolchain: stable - - target: loongarch64-unknown-linux-gnu - toolchain: stable - - target: s390x-unknown-linux-gnu - toolchain: stable - # powerpc64 uses experimental asm features - - target: powerpc64le-unknown-linux-gnu - toolchain: nightly - - target: powerpc64-unknown-linux-gnu - toolchain: nightly - - target: armv7-unknown-linux-gnueabihf - toolchain: stable - # riscv32 is tier-3 - - target: riscv32gc-unknown-linux-gnu - toolchain: nightly - components: rust-src - build_std: true - # sparc64 uses experimental asm features - - target: sparc64-unknown-linux-gnu - toolchain: nightly - # mips64 is tier-3 and uses experimental asm features - - target: mips64-unknown-linux-gnuabi64 - toolchain: nightly - components: rust-src - build_std: true - - target: i686-unknown-linux-gnu - toolchain: stable - # powerpc uses experimental asm features - - target: powerpc-unknown-linux-gnu - toolchain: nightly - # mips is tier-3 and uses experimental asm features - - target: mips-unknown-linux-gnu - toolchain: nightly - components: rust-src - build_std: true - - steps: - - name: "Checkout" - uses: actions/checkout@v7 - - - name: "Setup Rust toolchain" - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: ${{ matrix.toolchain }} - components: ${{ matrix.components || '' }} - rustflags: "" - - - name: "Add Rust target" - if: ${{ !matrix.build_std }} - run: rustup target add ${{ matrix.target }} - - - name: "Install the wild linker" - uses: wild-linker/action@v0.10.0 - - name: "Put wild on PATH" - run: echo "$RUNNER_TEMP/wild-install" >> "$GITHUB_PATH" - - - name: "Setup cross-compilation toolchain" - uses: taiki-e/setup-cross-toolchain-action@v1 - with: - target: ${{ matrix.target }} - - - name: "Build" - run: cargo build --verbose --target ${{ matrix.target }} ${{ matrix.build_std && '-Z build-std=core,alloc,panic_abort' || '' }} ${{ matrix.extra_args || '' }} - - # tier-3 targets have no prebuilt std and tests are arch-agnostic, so - # run them against the host toolchain instead of the cross target. - - name: "Run tests" - run: cargo test --workspace --exclude microfetch --verbose ${{ matrix.build_std && '--target x86_64-unknown-linux-gnu' || '' }} - - # macOS is libSystem-backed (no raw syscalls, no static linking), so it - # builds natively on an Apple Silicon runner rather than cross-compiling. - build-macos: - name: Test on aarch64-apple-darwin - runs-on: macos-14 - steps: - - name: "Checkout" - uses: actions/checkout@v7 - - - name: "Setup Rust toolchain" - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - target: aarch64-apple-darwin - rustflags: "" - - - name: "Build" - run: cargo build --verbose --target aarch64-apple-darwin - - - name: "Run tests" - run: cargo test --workspace --exclude microfetch --verbose From b08cecf2931c421a074cbdfd10063b37286dd827 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:22:38 -0400 Subject: [PATCH 07/15] lib: make the fallible row writers infallible --- crates/benchmarks/benches/microfetch.rs | 10 ++--- crates/lib/src/cpu.rs | 37 +++++++--------- crates/lib/src/lib.rs | 27 +++--------- crates/lib/src/release.rs | 27 +++++------- crates/lib/src/system.rs | 57 ++++++++----------------- crates/lib/src/uptime.rs | 19 +++------ 6 files changed, 60 insertions(+), 117 deletions(-) diff --git a/crates/benchmarks/benches/microfetch.rs b/crates/benchmarks/benches/microfetch.rs index a44bf68..d6835ef 100644 --- a/crates/benchmarks/benches/microfetch.rs +++ b/crates/benchmarks/benches/microfetch.rs @@ -28,7 +28,7 @@ fn main_benchmark(c: &mut Criterion) { b.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; let mut w = StackWriter::new(&mut buf); - let _ = release::write_os_pretty_name(&mut w); + release::write_os_pretty_name(&mut w); black_box(w.written()); }); }); @@ -52,7 +52,7 @@ fn main_benchmark(c: &mut Criterion) { b.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; let mut w = StackWriter::new(&mut buf); - let _ = cpu::write_cpu_cores(&mut w); + cpu::write_cpu_cores(&mut w); black_box(w.written()); }); }); @@ -76,7 +76,7 @@ fn main_benchmark(c: &mut Criterion) { b.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; let mut w = StackWriter::new(&mut buf); - let _ = uptime::write_uptime(&mut w); + uptime::write_uptime(&mut w); black_box(w.written()); }); }); @@ -84,7 +84,7 @@ fn main_benchmark(c: &mut Criterion) { b.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; let mut w = StackWriter::new(&mut buf); - let _ = system::write_memory_usage(&mut w, &colors); + system::write_memory_usage(&mut w, &colors); black_box(w.written()); }); }); @@ -92,7 +92,7 @@ fn main_benchmark(c: &mut Criterion) { b.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; let mut w = StackWriter::new(&mut buf); - let _ = system::write_root_disk_usage(&mut w, &colors); + system::write_root_disk_usage(&mut w, &colors); black_box(w.written()); }); }); diff --git a/crates/lib/src/cpu.rs b/crates/lib/src/cpu.rs index 8197058..cd6ad87 100644 --- a/crates/lib/src/cpu.rs +++ b/crates/lib/src/cpu.rs @@ -1,6 +1,6 @@ +use crate::StackWriter; #[cfg(target_os = "linux")] use crate::syscall::read_file_fast; -use crate::{Error, StackWriter}; /// Writes CPU model name (trimmed) to the writer. #[cfg(target_os = "linux")] @@ -26,35 +26,31 @@ pub fn write_cpu_name(w: &mut StackWriter) { /// Writes CPU core/thread info string. /// /// Format: `{cores} cores ({p}p/{e}e), {threads} threads` on hybrid Intel, -/// `{cores} cores, {threads} threads` otherwise. -/// -/// # Errors -/// -/// Returns an error if the thread count cannot be determined. +/// `{cores} cores, {threads} threads` otherwise. Writes nothing if the thread +/// count cannot be determined. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_cpu_cores(w: &mut StackWriter) -> Result<(), Error> { - let threads = get_thread_count()?; +pub fn write_cpu_cores(w: &mut StackWriter) { + let Some(threads) = get_thread_count() else { + return; + }; let cores = get_core_count(threads); write_cores(w, cores, get_pe_cores(), threads); - Ok(()) } /// Writes CPU core/thread info via `sysctl` (macOS). /// /// On Apple Silicon `hw.perflevel0`/`hw.perflevel1` expose the performance -/// (P) and efficiency (E) core counts respectively. -/// -/// # Errors -/// -/// Returns an error if the logical CPU count cannot be determined. +/// (P) and efficiency (E) core counts respectively. Writes nothing if the +/// logical CPU count cannot be determined. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_cpu_cores(w: &mut StackWriter) -> Result<(), Error> { +pub fn write_cpu_cores(w: &mut StackWriter) { use crate::syscall::macos_sysctl_u32; - let threads = - macos_sysctl_u32(b"hw.logicalcpu\0").ok_or(Error::OsError(0))?; + let Some(threads) = macos_sysctl_u32(b"hw.logicalcpu\0") else { + return; + }; let cores = macos_sysctl_u32(b"hw.physicalcpu\0").unwrap_or(threads); // Performance/efficiency split (Apple Silicon). Only reported when both @@ -68,7 +64,6 @@ pub fn write_cpu_cores(w: &mut StackWriter) -> Result<(), Error> { }; write_cores(w, cores, pe, threads); - Ok(()) } /// Writes core/thread counts identically across platforms: @@ -100,13 +95,13 @@ fn write_cores( /// Count online threads via `sched_getaffinity(2)`. #[cfg(target_os = "linux")] -fn get_thread_count() -> Result { +fn get_thread_count() -> Option { let mut mask = [0u8; 128]; let ret = unsafe { crate::syscall::sys_sched_getaffinity(0, mask.len(), mask.as_mut_ptr()) }; if ret < 0 { - return Err(Error::from_raw_os_error(-ret)); + return None; } #[allow(clippy::cast_sign_loss)] @@ -115,7 +110,7 @@ fn get_thread_count() -> Result { for &byte in &mask[..bytes] { count += byte.count_ones(); } - Ok(count) + Some(count) } /// Derive physical core count from thread count and topology. diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index 35c1a15..8881e5d 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -54,13 +54,6 @@ impl Error { // we'd need to get the actual errno from the syscall return Self::OsError(0) } - - /// Creates an error from a raw OS error code (negative errno from syscall). - #[inline] - #[must_use] - pub const fn from_raw_os_error(errno: i32) -> Self { - Self::OsError(-errno) - } } // Store the environment pointer internally,initialized from `main()`. This @@ -357,25 +350,15 @@ fn write_row( w.push_str(" ~"); w.push_str(c.reset); }, - 1 => { - let _ = release::write_os_pretty_name(w); - }, + 1 => release::write_os_pretty_name(w), 2 => release::write_system_info(w, utsname), 3 => cpu::write_cpu_name(w), - 4 => { - let _ = cpu::write_cpu_cores(w); - }, + 4 => cpu::write_cpu_cores(w), 5 => system::write_shell(w), - 6 => { - let _ = uptime::write_uptime(w); - }, + 6 => uptime::write_uptime(w), 7 => desktop::write_desktop_info(w), - 8 => { - let _ = system::write_memory_usage(w, c); - }, - 9 => { - let _ = system::write_root_disk_usage(w, c); - }, + 8 => system::write_memory_usage(w, c), + 9 => system::write_root_disk_usage(w, c), _ => colors::write_dots(w, c), } w.push_byte(b'\n'); diff --git a/crates/lib/src/release.rs b/crates/lib/src/release.rs index 21be72d..fb9be95 100644 --- a/crates/lib/src/release.rs +++ b/crates/lib/src/release.rs @@ -1,6 +1,6 @@ #[cfg(target_os = "linux")] use crate::syscall::read_file_fast; -use crate::{Error, StackWriter, UtsName}; +use crate::{StackWriter, UtsName}; #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_system_info(w: &mut StackWriter, utsname: &UtsName) { @@ -13,13 +13,10 @@ pub fn write_system_info(w: &mut StackWriter, utsname: &UtsName) { } /// Writes the OS name from `kern.osproductversion` (macOS), e.g. `macOS 14.5`. -/// -/// # Errors -/// -/// Never errors; falls back to `macOS` if the version sysctl is unavailable. +/// Falls back to `macOS` if the version sysctl is unavailable. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_os_pretty_name(w: &mut StackWriter) -> Result<(), Error> { +pub fn write_os_pretty_name(w: &mut StackWriter) { w.push_str("macOS"); let mut buf = [0u8; 64]; if let Some(n) = @@ -30,25 +27,22 @@ pub fn write_os_pretty_name(w: &mut StackWriter) -> Result<(), Error> { w.push_byte(b' '); w.push_str(version); } - Ok(()) } -/// Writes the pretty name of the OS from `/etc/os-release`. -/// -/// # Errors -/// -/// Returns an error if `/etc/os-release` cannot be read. +/// Writes the pretty name of the OS from `/etc/os-release`, or nothing if it +/// cannot be read. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_os_pretty_name(w: &mut StackWriter) -> Result<(), Error> { +pub fn write_os_pretty_name(w: &mut StackWriter) { // Fast byte-level scanning for PRETTY_NAME= const PREFIX: &[u8] = b"PRETTY_NAME="; let mut buffer = [0u8; 1024]; // Use fast syscall-based file reading - let bytes_read = read_file_fast("/etc/os-release", &mut buffer) - .map_err(Error::from_raw_os_error)?; + let Ok(bytes_read) = read_file_fast("/etc/os-release", &mut buffer) else { + return; + }; let content = &buffer[..bytes_read]; let mut offset = 0; @@ -79,12 +73,11 @@ pub fn write_os_pretty_name(w: &mut StackWriter) -> Result<(), Error> { // valid UTF-8 (ASCII names, version numbers). No lossy conversion // needed. w.push_bytes(trimmed); - return Ok(()); + return; } offset += line_end + 1; } w.push_str("Unknown"); - Ok(()) } diff --git a/crates/lib/src/system.rs b/crates/lib/src/system.rs index 8f56e49..b6e6309 100644 --- a/crates/lib/src/system.rs +++ b/crates/lib/src/system.rs @@ -3,7 +3,6 @@ use core::mem::MaybeUninit; #[cfg(target_os = "linux")] use crate::syscall::read_file_fast; use crate::{ - Error, StackWriter, UtsName, colors::Colors, @@ -39,21 +38,15 @@ pub fn write_shell(w: &mut StackWriter) { } } -/// Gets the root disk usage information. -/// -/// # Errors -/// -/// Returns an error if the filesystem information cannot be retrieved. +/// Writes the root disk usage, or nothing if the filesystem information cannot +/// be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_root_disk_usage( - w: &mut StackWriter, - colors: &Colors, -) -> Result<(), Error> { +pub fn write_root_disk_usage(w: &mut StackWriter, colors: &Colors) { let mut vfs = MaybeUninit::::uninit(); let path = b"/\0"; if unsafe { sys_statfs(path.as_ptr(), vfs.as_mut_ptr()) } != 0 { - return Err(Error::last_os_error()); + return; } let vfs = unsafe { vfs.assume_init() }; @@ -75,8 +68,6 @@ pub fn write_root_disk_usage( w.push_byte(b'%'); w.push_str(colors.reset); w.push_byte(b')'); - - Ok(()) } fn write_centi_gib(w: &mut StackWriter, centi_gib: u64) { @@ -112,18 +103,13 @@ fn parse_u64_fast(s: &[u8]) -> u64 { } /// Writes the system memory usage information via `sysctl`/Mach (macOS). -/// -/// # Errors -/// -/// Returns an error if the memory statistics cannot be retrieved. +/// Writes nothing if the memory statistics cannot be retrieved. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_memory_usage( - w: &mut StackWriter, - colors: &Colors, -) -> Result<(), Error> { - let (used_bytes, total_bytes) = - crate::syscall::macos_meminfo().ok_or(Error::OsError(0))?; +pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { + let Some((used_bytes, total_bytes)) = crate::syscall::macos_meminfo() else { + return; + }; let percentage_used = (used_bytes * 100 + total_bytes / 2) .checked_div(total_bytes) .unwrap_or(0); @@ -137,30 +123,21 @@ pub fn write_memory_usage( w.push_byte(b'%'); w.push_str(colors.reset); w.push_byte(b')'); - - Ok(()) } /// Gets the system memory usage information. -/// -/// # Errors -/// -/// Returns an error if `/proc/meminfo` cannot be read. +/// Writes nothing if `/proc/meminfo` cannot be read. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_memory_usage( - w: &mut StackWriter, - colors: &Colors, -) -> Result<(), Error> { +pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { #[cfg_attr(feature = "hotpath", hotpath::measure)] - fn parse_memory_info() -> Result<(u64, u64), Error> { + fn parse_memory_info() -> Option<(u64, u64)> { let mut total_memory_kb = 0u64; let mut available_memory_kb = 0u64; let mut buffer = [0u8; 1024]; // Use fast syscall-based file reading - let bytes_read = read_file_fast("/proc/meminfo", &mut buffer) - .map_err(Error::from_raw_os_error)?; + let bytes_read = read_file_fast("/proc/meminfo", &mut buffer).ok()?; let meminfo = &buffer[..bytes_read]; // Fast scanning for MemTotal and MemAvailable @@ -199,10 +176,12 @@ pub fn write_memory_usage( offset += line_end + 1; } - Ok((total_memory_kb - available_memory_kb, total_memory_kb)) + Some((total_memory_kb - available_memory_kb, total_memory_kb)) } - let (used_kb, total_kb) = parse_memory_info()?; + let Some((used_kb, total_kb)) = parse_memory_info() else { + return; + }; let percentage_used = (used_kb * 100 + total_kb / 2) .checked_div(total_kb) .unwrap_or(0); @@ -216,6 +195,4 @@ pub fn write_memory_usage( w.push_byte(b'%'); w.push_str(colors.reset); w.push_byte(b')'); - - Ok(()) } diff --git a/crates/lib/src/uptime.rs b/crates/lib/src/uptime.rs index 919302b..acf4fe7 100644 --- a/crates/lib/src/uptime.rs +++ b/crates/lib/src/uptime.rs @@ -1,20 +1,16 @@ #[cfg(target_os = "linux")] use core::mem::MaybeUninit; +use crate::StackWriter; #[cfg(target_os = "linux")] use crate::syscall::sys_sysinfo; -use crate::{Error, StackWriter}; -/// Gets the current system uptime. -/// -/// # Errors -/// -/// Returns an error if the system uptime cannot be retrieved. +/// Writes the current system uptime, or nothing if it cannot be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_uptime(w: &mut StackWriter) -> Result<(), Error> { +pub fn write_uptime(w: &mut StackWriter) { #[cfg(target_os = "linux")] let uptime_seconds = { let mut info = MaybeUninit::uninit(); if unsafe { sys_sysinfo(info.as_mut_ptr()) } != 0 { - return Err(Error::last_os_error()); + return; } #[allow(clippy::cast_sign_loss)] unsafe { @@ -22,8 +18,9 @@ pub fn write_uptime(w: &mut StackWriter) -> Result<(), Error> { } }; #[cfg(target_os = "macos")] - let uptime_seconds = - crate::syscall::macos_uptime_secs().ok_or(Error::OsError(0))?; + let Some(uptime_seconds) = crate::syscall::macos_uptime_secs() else { + return; + }; let days = uptime_seconds / 86400; let hours = (uptime_seconds / 3600) % 24; @@ -53,6 +50,4 @@ pub fn write_uptime(w: &mut StackWriter) -> Result<(), Error> { if !any { w.push_str("less than a minute"); } - - Ok(()) } From f32ce3045e760f99ba95f50f980cbe9ef688cf73 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:22:38 -0400 Subject: [PATCH 08/15] treewide: replace integer casts with typed conversions --- crates/asm/src/aarch64.rs | 49 +++++++---------------- crates/asm/src/arm.rs | 8 ++-- crates/asm/src/darwin.rs | 5 ++- crates/asm/src/lib.rs | 17 +++----- crates/asm/src/loongarch64.rs | 49 +++++++---------------- crates/asm/src/mips.rs | 8 ++-- crates/asm/src/mips64.rs | 67 ++++++++++++++------------------ crates/asm/src/powerpc.rs | 8 ++-- crates/asm/src/powerpc64.rs | 73 ++++++++++++++--------------------- crates/asm/src/riscv32.rs | 8 ++-- crates/asm/src/riscv64.rs | 49 +++++++---------------- crates/asm/src/s390x.rs | 49 +++++++---------------- crates/asm/src/sparc.rs | 8 ++-- crates/asm/src/sparc64.rs | 67 ++++++++++++++------------------ crates/asm/src/x86.rs | 8 ++-- crates/asm/src/x86_64.rs | 49 +++++++---------------- crates/lib/src/cpu.rs | 10 +---- crates/lib/src/lib.rs | 14 +++---- crates/lib/src/system.rs | 10 ++++- crates/lib/src/uptime.rs | 9 +++-- 20 files changed, 214 insertions(+), 351 deletions(-) diff --git a/crates/asm/src/aarch64.rs b/crates/asm/src/aarch64.rs index 9635a23..334d543 100644 --- a/crates/asm/src/aarch64.rs +++ b/crates/asm/src/aarch64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i64; + let fd: i32; core::arch::asm!( "svc #0", in("x8") 56i64, // SYS_openat @@ -15,16 +15,13 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { lateout("x0") fd, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - fd as i32 - } + fd } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "svc #0", in("x8") 63i64, // SYS_read @@ -35,16 +32,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "svc #0", in("x8") 64i64, // SYS_write @@ -55,16 +49,13 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc #0", in("x8") 57i64, // SYS_close @@ -72,16 +63,13 @@ pub unsafe fn sys_close(fd: i32) -> i32 { lateout("x0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc #0", in("x8") 160i64, // SYS_uname @@ -89,16 +77,13 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { lateout("x0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc #0", in("x8") 43i64, // SYS_statfs @@ -108,10 +93,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -135,7 +117,7 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc #0", in("x8") 123i64, // __NR_sched_getaffinity @@ -145,10 +127,7 @@ pub unsafe fn sys_sched_getaffinity( lateout("x0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/arm.rs b/crates/asm/src/arm.rs index 18f0229..b3fd4ba 100644 --- a/crates/asm/src/arm.rs +++ b/crates/asm/src/arm.rs @@ -20,7 +20,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "svc #0", in("r7") 3i32, // SYS_read @@ -30,13 +30,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { lateout("r0") ret, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "svc #0", in("r7") 4i32, // SYS_write @@ -46,7 +46,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { lateout("r0") ret, options(nostack) ); - ret as isize + ret } } diff --git a/crates/asm/src/darwin.rs b/crates/asm/src/darwin.rs index 06d80da..be3b246 100644 --- a/crates/asm/src/darwin.rs +++ b/crates/asm/src/darwin.rs @@ -224,7 +224,8 @@ pub fn macos_meminfo() -> Option<(u64, u64)> { let page = u64::from(macos_sysctl_u32(b"hw.pagesize\0").unwrap_or(16384)); let mut vm = VmStatistics64::default(); - let mut count = (size_of::() / size_of::()) as u32; + let mut count = + u32::try_from(size_of::() / size_of::()).ok()?; let kr = unsafe { host_statistics64( mach_host_self(), @@ -267,7 +268,7 @@ pub fn macos_uptime_secs() -> Option { let ret = unsafe { sysctl( mib.as_ptr(), - mib.len() as u32, + u32::try_from(mib.len()).ok()?, ptr::from_mut(&mut boot).cast::(), &raw mut len, ptr::null(), diff --git a/crates/asm/src/lib.rs b/crates/asm/src/lib.rs index 3b27962..afa477b 100644 --- a/crates/asm/src/lib.rs +++ b/crates/asm/src/lib.rs @@ -97,8 +97,8 @@ pub unsafe extern "C" fn memcpy( dest_bytes.add(i).cast::().write_unaligned(word); i += WORD; } - } else if dest_bytes as usize % WORD == src_bytes as usize % WORD { - while i < n && !(dest_bytes.add(i) as usize).is_multiple_of(WORD) { + } else if dest_bytes.addr() % WORD == src_bytes.addr() % WORD { + while i < n && !dest_bytes.add(i).addr().is_multiple_of(WORD) { *dest_bytes.add(i) = *src_bytes.add(i); i += 1; } @@ -140,7 +140,7 @@ pub unsafe extern "C" fn memset( i += WORD; } } else { - while i < n && !(bytes.add(i) as usize).is_multiple_of(WORD) { + while i < n && !bytes.add(i).addr().is_multiple_of(WORD) { *bytes.add(i) = value; i += 1; } @@ -574,15 +574,8 @@ pub fn read_file_fast(path: &str, buffer: &mut [u8]) -> Result { let bytes_read = sys_read(fd, buffer.as_mut_ptr(), buffer.len()); let _ = sys_close(fd); - if bytes_read < 0 { - #[allow(clippy::cast_possible_truncation)] - return Err(bytes_read as i32); - } - - #[allow(clippy::cast_sign_loss)] - { - Ok(bytes_read as usize) - } + usize::try_from(bytes_read) + .map_err(|_| i32::try_from(bytes_read).unwrap_or(i32::MIN)) } } diff --git a/crates/asm/src/loongarch64.rs b/crates/asm/src/loongarch64.rs index 08a6098..5b0c5ef 100644 --- a/crates/asm/src/loongarch64.rs +++ b/crates/asm/src/loongarch64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i64; + let fd: i32; core::arch::asm!( "syscall 0", in("$a7") 56i64, // SYS_openat @@ -15,16 +15,13 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { lateout("$a0") fd, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - fd as i32 - } + fd } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "syscall 0", in("$a7") 63i64, // SYS_read @@ -34,16 +31,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { lateout("$a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "syscall 0", in("$a7") 64i64, // SYS_write @@ -53,16 +47,13 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { lateout("$a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall 0", in("$a7") 57i64, // SYS_close @@ -70,16 +61,13 @@ pub unsafe fn sys_close(fd: i32) -> i32 { lateout("$a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall 0", in("$a7") 160i64, // SYS_uname @@ -87,16 +75,13 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { lateout("$a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall 0", in("$a7") 43i64, // SYS_statfs @@ -105,10 +90,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { lateout("$a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -132,7 +114,7 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall 0", in("$a7") 123i64, // __NR_sched_getaffinity @@ -142,10 +124,7 @@ pub unsafe fn sys_sched_getaffinity( lateout("$a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/mips.rs b/crates/asm/src/mips.rs index 0b749b3..d83c9c2 100644 --- a/crates/asm/src/mips.rs +++ b/crates/asm/src/mips.rs @@ -27,7 +27,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "syscall", "beqz $7, 1f", @@ -44,13 +44,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { lateout("$24") _, lateout("$25") _, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "syscall", "beqz $7, 1f", @@ -67,7 +67,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { lateout("$24") _, lateout("$25") _, options(nostack) ); - ret as isize + ret } } diff --git a/crates/asm/src/mips64.rs b/crates/asm/src/mips64.rs index 709446c..82eb5b1 100644 --- a/crates/asm/src/mips64.rs +++ b/crates/asm/src/mips64.rs @@ -4,14 +4,15 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", "beqz $7, 1f", "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000i64 + 2 => ret, // SYS_open + in("$2") 5000i64 + 2, // SYS_open + lateout("$2") ret, in("$4") path, in("$5") flags, in("$6") 0i32, // mode @@ -21,23 +22,21 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { lateout("$24") _, lateout("$25") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "syscall", "beqz $7, 1f", "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000i64 + 0 => ret, // SYS_read + in("$2") 5000i64 + 0, // SYS_read + lateout("$2") ret, in("$4") fd, in("$5") buf, in("$6") count, @@ -47,20 +46,21 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { lateout("$24") _, lateout("$25") _, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "syscall", "beqz $7, 1f", "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000i64 + 1 => ret, // SYS_write + in("$2") 5000i64 + 1, // SYS_write + lateout("$2") ret, in("$4") fd, in("$5") buf, in("$6") count, @@ -70,20 +70,21 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { lateout("$24") _, lateout("$25") _, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", "beqz $7, 1f", "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000i64 + 3 => ret, // SYS_close + in("$2") 5000i64 + 3, // SYS_close + lateout("$2") ret, in("$4") fd, lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, @@ -91,23 +92,21 @@ pub unsafe fn sys_close(fd: i32) -> i32 { lateout("$24") _, lateout("$25") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", "beqz $7, 1f", "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000i64 + 61 => ret, // SYS_newuname + in("$2") 5000i64 + 61, // SYS_newuname + lateout("$2") ret, in("$4") buf, lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, @@ -115,23 +114,21 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { lateout("$24") _, lateout("$25") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", "beqz $7, 1f", "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000i64 + 134 => ret, // SYS_statfs + in("$2") 5000i64 + 134, // SYS_statfs + lateout("$2") ret, in("$4") path, in("$5") buf, lateout("$7") _, @@ -140,10 +137,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { lateout("$24") _, lateout("$25") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -156,7 +150,8 @@ pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { "nop", "dsubu $2, $0, $2", "1:", - inlateout("$2") 5000_i64 + 97 => ret, // SYS_sysinfo + in("$2") 5000_i64 + 97, // SYS_sysinfo + lateout("$2") ret, in("$4") info, lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, @@ -174,10 +169,11 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", - inlateout("$2") 5000i64 + 196 => ret, // __NR_sched_getaffinity + in("$2") 5000i64 + 196, // __NR_sched_getaffinity + lateout("$2") ret, in("$4") pid, in("$5") mask_size, in("$6") mask, @@ -187,10 +183,7 @@ pub unsafe fn sys_sched_getaffinity( lateout("$24") _, lateout("$25") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/powerpc.rs b/crates/asm/src/powerpc.rs index efafcf7..ae354e1 100644 --- a/crates/asm/src/powerpc.rs +++ b/crates/asm/src/powerpc.rs @@ -25,7 +25,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "sc", "bns+ 2f", @@ -40,13 +40,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { out("cr0") _, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "sc", "bns+ 2f", @@ -61,7 +61,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { out("cr0") _, options(nostack) ); - ret as isize + ret } } diff --git a/crates/asm/src/powerpc64.rs b/crates/asm/src/powerpc64.rs index 09a28ef..4a48ba0 100644 --- a/crates/asm/src/powerpc64.rs +++ b/crates/asm/src/powerpc64.rs @@ -4,14 +4,15 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 5i64 => _, // SYS_open - inlateout("r3") path => ret, + in("r3") path, + lateout("r3") ret, inlateout("r4") flags => _, inlateout("r5") 0i32 => _, // mode out("r6") _, out("r7") _, out("r8") _, @@ -19,23 +20,21 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 3i64 => _, // SYS_read - inlateout("r3") fd as i64 => ret, + in("r3") i64::from(fd), + lateout("r3") ret, inlateout("r4") buf => _, inlateout("r5") count => _, out("r6") _, out("r7") _, out("r8") _, @@ -43,23 +42,21 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 4i64 => _, // SYS_write - inlateout("r3") fd as i64 => ret, + in("r3") i64::from(fd), + lateout("r3") ret, inlateout("r4") buf => _, inlateout("r5") count => _, out("r6") _, out("r7") _, out("r8") _, @@ -67,77 +64,68 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 6i64 => _, // SYS_close - inlateout("r3") fd as i64 => ret, + in("r3") i64::from(fd), + lateout("r3") ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 122i64 => _, // SYS_uname - inlateout("r3") buf => ret, + in("r3") buf, + lateout("r3") ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 99i64 => _, // SYS_statfs - inlateout("r3") path => ret, + in("r3") path, + lateout("r3") ret, inlateout("r4") buf => _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -150,7 +138,8 @@ pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { "neg 3, 3", "2:", inlateout("r0") 116_i64 => _, // __NR_sysinfo - inlateout("r3") info => ret, + in("r3") info, + lateout("r3") ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, out("cr0") _, @@ -166,14 +155,15 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 223i64 => _, // __NR_sched_getaffinity - inlateout("r3") pid as i64 => ret, + in("r3") i64::from(pid), + lateout("r3") ret, inlateout("r4") mask_size => _, inlateout("r5") mask => _, out("r6") _, out("r7") _, out("r8") _, @@ -181,10 +171,7 @@ pub unsafe fn sys_sched_getaffinity( out("cr0") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/riscv32.rs b/crates/asm/src/riscv32.rs index 811f47d..a9daa4a 100644 --- a/crates/asm/src/riscv32.rs +++ b/crates/asm/src/riscv32.rs @@ -21,7 +21,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "ecall", in("a7") 63i32, // SYS_read @@ -31,13 +31,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { lateout("a0") ret, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "ecall", in("a7") 64i32, // SYS_write @@ -47,7 +47,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { lateout("a0") ret, options(nostack) ); - ret as isize + ret } } diff --git a/crates/asm/src/riscv64.rs b/crates/asm/src/riscv64.rs index fcfc804..030e2e1 100644 --- a/crates/asm/src/riscv64.rs +++ b/crates/asm/src/riscv64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i64; + let fd: i32; core::arch::asm!( "ecall", in("a7") 56i64, // SYS_openat @@ -16,16 +16,13 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - fd as i32 - } + fd } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "ecall", in("a7") 63i64, // SYS_read @@ -36,16 +33,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "ecall", in("a7") 64i64, // SYS_write @@ -56,16 +50,13 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "ecall", in("a7") 57i64, // SYS_close @@ -73,16 +64,13 @@ pub unsafe fn sys_close(fd: i32) -> i32 { lateout("a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "ecall", in("a7") 160i64, // SYS_uname @@ -91,16 +79,13 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "ecall", in("a7") 43i64, // SYS_statfs @@ -110,10 +95,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -137,7 +119,7 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "ecall", in("a7") 123i64, // __NR_sched_getaffinity @@ -147,10 +129,7 @@ pub unsafe fn sys_sched_getaffinity( lateout("a0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/s390x.rs b/crates/asm/src/s390x.rs index 5c4377b..c57e87e 100644 --- a/crates/asm/src/s390x.rs +++ b/crates/asm/src/s390x.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i64; + let fd: i32; core::arch::asm!( "svc 0", in("r1") 5i64, // SYS_open @@ -14,16 +14,13 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { lateout("r2") fd, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - fd as i32 - } + fd } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "svc 0", in("r1") 3i64, // SYS_read @@ -33,16 +30,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { lateout("r2") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "svc 0", in("r1") 4i64, // SYS_write @@ -52,16 +46,13 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { lateout("r2") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc 0", in("r1") 6i64, // SYS_close @@ -69,16 +60,13 @@ pub unsafe fn sys_close(fd: i32) -> i32 { lateout("r2") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc 0", in("r1") 122i64, // SYS_uname @@ -86,16 +74,13 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { lateout("r2") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc 0", in("r1") 99i64, // SYS_statfs @@ -104,10 +89,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { lateout("r2") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -131,7 +113,7 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "svc 0", in("r1") 240i64, // __NR_sched_getaffinity @@ -141,10 +123,7 @@ pub unsafe fn sys_sched_getaffinity( lateout("r2") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/sparc.rs b/crates/asm/src/sparc.rs index b2dda90..59f075d 100644 --- a/crates/asm/src/sparc.rs +++ b/crates/asm/src/sparc.rs @@ -23,7 +23,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "mov {nr}, %g1", "ta 0x10", @@ -36,13 +36,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { in("o2") count, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "mov {nr}, %g1", "ta 0x10", @@ -55,7 +55,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { in("o2") count, options(nostack) ); - ret as isize + ret } } diff --git a/crates/asm/src/sparc64.rs b/crates/asm/src/sparc64.rs index c81d602..fa33041 100644 --- a/crates/asm/src/sparc64.rs +++ b/crates/asm/src/sparc64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -12,21 +12,19 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "sub %g0, %o0, %o0", "1:", nr = in(reg) 5i64, // SYS_open - inlateout("o0") path => ret, + in("o0") path, + lateout("o0") ret, in("o1") flags, in("o2") 0i32, // mode options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -34,18 +32,19 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "sub %g0, %o0, %o0", "1:", nr = in(reg) 3i64, // SYS_read - inlateout("o0") fd as i64 => ret, + in("o0") i64::from(fd), + lateout("o0") ret, in("o1") buf, in("o2") count, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -53,18 +52,19 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "sub %g0, %o0, %o0", "1:", nr = in(reg) 4i64, // SYS_write - inlateout("o0") fd as i64 => ret, + in("o0") i64::from(fd), + lateout("o0") ret, in("o1") buf, in("o2") count, options(nostack) ); - ret as isize + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -72,19 +72,17 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "sub %g0, %o0, %o0", "1:", nr = in(reg) 6i64, // SYS_close - inlateout("o0") fd as i64 => ret, + in("o0") i64::from(fd), + lateout("o0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -92,19 +90,17 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "sub %g0, %o0, %o0", "1:", nr = in(reg) 189i64, // SYS_newuname - inlateout("o0") buf => ret, + in("o0") buf, + lateout("o0") ret, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -112,14 +108,12 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "sub %g0, %o0, %o0", "1:", nr = in(reg) 157i64, // SYS_statfs - inlateout("o0") path => ret, + in("o0") path, + lateout("o0") ret, in("o1") buf, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -133,7 +127,8 @@ pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { "sub %g0, %o0, %o0", "1:", nr = in(reg) 214_i64, // __NR_sysinfo - inlateout("o0") info => ret, + in("o0") info, + lateout("o0") ret, options(nostack) ); ret @@ -146,7 +141,7 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "mov {nr}, %g1", "t 0x6d", @@ -154,15 +149,13 @@ pub unsafe fn sys_sched_getaffinity( "sub %g0, %o0, %o0", "1:", nr = in(reg) 260i64, // __NR_sched_getaffinity - inlateout("o0") pid as i64 => ret, + in("o0") i64::from(pid), + lateout("o0") ret, in("o1") mask_size, in("o2") mask, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/asm/src/x86.rs b/crates/asm/src/x86.rs index e2bd1ad..cb0aede 100644 --- a/crates/asm/src/x86.rs +++ b/crates/asm/src/x86.rs @@ -21,7 +21,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "push ebx", "mov ebx, {arg1:e}", @@ -32,13 +32,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { in("ecx") buf, in("edx") count, ); - ret as isize + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i32; + let ret: isize; core::arch::asm!( "push ebx", "mov ebx, {arg1:e}", @@ -49,7 +49,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { in("ecx") buf, in("edx") count, ); - ret as isize + ret } } diff --git a/crates/asm/src/x86_64.rs b/crates/asm/src/x86_64.rs index e6e0cdd..58210c2 100644 --- a/crates/asm/src/x86_64.rs +++ b/crates/asm/src/x86_64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i64; + let fd: i32; core::arch::asm!( "syscall", in("rax") 2i64, // SYS_open @@ -16,16 +16,13 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { lateout("r11") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - fd as i32 - } + fd } } pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "syscall", in("rax") 0i64, // SYS_read @@ -38,16 +35,13 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { - let ret: i64; + let ret: isize; core::arch::asm!( "syscall", in("rax") 1i64, // SYS_write @@ -60,16 +54,13 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as isize - } + ret } } pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", in("rax") 3i64, // SYS_close @@ -79,16 +70,13 @@ pub unsafe fn sys_close(fd: i32) -> i32 { lateout("r11") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", in("rax") 63i64, // SYS_uname @@ -99,16 +87,13 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", in("rax") 137i64, // SYS_statfs @@ -120,10 +105,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } @@ -149,7 +131,7 @@ pub unsafe fn sys_sched_getaffinity( mask: *mut u8, ) -> i32 { unsafe { - let ret: i64; + let ret: i32; core::arch::asm!( "syscall", in("rax") 204i64, // __NR_sched_getaffinity @@ -161,10 +143,7 @@ pub unsafe fn sys_sched_getaffinity( lateout("r11") _, options(nostack) ); - #[allow(clippy::cast_possible_truncation)] - { - ret as i32 - } + ret } } diff --git a/crates/lib/src/cpu.rs b/crates/lib/src/cpu.rs index cd6ad87..9d944fb 100644 --- a/crates/lib/src/cpu.rs +++ b/crates/lib/src/cpu.rs @@ -100,12 +100,7 @@ fn get_thread_count() -> Option { let ret = unsafe { crate::syscall::sys_sched_getaffinity(0, mask.len(), mask.as_mut_ptr()) }; - if ret < 0 { - return None; - } - - #[allow(clippy::cast_sign_loss)] - let bytes = ret as usize; + let bytes = usize::try_from(ret).ok()?; let mut count = 0u32; for &byte in &mask[..bytes] { count += byte.count_ones(); @@ -328,8 +323,7 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { } } if hz > 0 { - #[allow(clippy::cast_possible_truncation)] - return Some((hz / 1_000_000) as u32); + return u32::try_from(hz / 1_000_000).ok(); } } None diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index 8881e5d..1639c6a 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -293,7 +293,7 @@ fn write_styled_row( let mut i = 0; while i < row_data.len() { if let marker @ 1..=3 = row_data[i] { - w.push_str(colors[(marker - 1) as usize]); + w.push_str(colors[usize::from(marker - 1)]); i += 1; } else { let chunk_start = i; @@ -461,13 +461,13 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> { // Single syscall for the entire output. let out = w.written(); let written = unsafe { sys_write(1, out.as_ptr(), out.len()) }; - if written < 0 { - #[allow(clippy::cast_possible_truncation)] - return Err(Error::OsError(written as i32)); - } + let Ok(count) = usize::try_from(written) else { + return Err( + i32::try_from(written).map_or(Error::WriteError, Error::OsError), + ); + }; - #[allow(clippy::cast_sign_loss)] - if written as usize != out.len() { + if count != out.len() { return Err(Error::WriteError); } diff --git a/crates/lib/src/system.rs b/crates/lib/src/system.rs index b6e6309..86e5ae3 100644 --- a/crates/lib/src/system.rs +++ b/crates/lib/src/system.rs @@ -50,8 +50,14 @@ pub fn write_root_disk_usage(w: &mut StackWriter, colors: &Colors) { } let vfs = unsafe { vfs.assume_init() }; - #[allow(clippy::cast_sign_loss)] - let block_size = vfs.f_bsize as u64; + #[allow( + clippy::unnecessary_fallible_conversions, + reason = "f_bsize is a signed long on most targets but u32 on macOS, \ + s390x, and 32-bit" + )] + let Some(block_size) = u64::try_from(vfs.f_bsize).ok() else { + return; + }; let total_blocks = vfs.f_blocks; let available_blocks = vfs.f_bavail; diff --git a/crates/lib/src/uptime.rs b/crates/lib/src/uptime.rs index acf4fe7..a3299fd 100644 --- a/crates/lib/src/uptime.rs +++ b/crates/lib/src/uptime.rs @@ -12,10 +12,11 @@ pub fn write_uptime(w: &mut StackWriter) { if unsafe { sys_sysinfo(info.as_mut_ptr()) } != 0 { return; } - #[allow(clippy::cast_sign_loss)] - unsafe { - info.assume_init().uptime as u64 - } + let Ok(seconds) = u64::try_from(unsafe { info.assume_init() }.uptime) + else { + return; + }; + seconds }; #[cfg(target_os = "macos")] let Some(uptime_seconds) = crate::syscall::macos_uptime_secs() else { From 49ce45423a7b59137a577e8b51454fb6db149997 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:22:38 -0400 Subject: [PATCH 09/15] treewide: give short identifiers descriptive names --- crates/asm/src/aarch64.rs | 6 +- crates/asm/src/darwin.rs | 16 +- crates/asm/src/lib.rs | 116 +++++----- crates/asm/src/loongarch64.rs | 6 +- crates/asm/src/riscv64.rs | 6 +- crates/asm/src/s390x.rs | 6 +- crates/asm/src/x86_64.rs | 6 +- crates/benchmarks/benches/microfetch.rs | 112 +++++----- crates/lib/build.rs | 4 +- crates/lib/src/colors.rs | 10 +- crates/lib/src/cpu.rs | 279 +++++++++++++----------- crates/lib/src/desktop.rs | 14 +- crates/lib/src/lib.rs | 157 ++++++------- crates/lib/src/release.rs | 34 +-- crates/lib/src/system.rs | 108 ++++----- crates/lib/src/uptime.rs | 20 +- 16 files changed, 459 insertions(+), 441 deletions(-) diff --git a/crates/asm/src/aarch64.rs b/crates/asm/src/aarch64.rs index 334d543..efc79a1 100644 --- a/crates/asm/src/aarch64.rs +++ b/crates/asm/src/aarch64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i32; + let ret: i32; core::arch::asm!( "svc #0", in("x8") 56i64, // SYS_openat @@ -12,10 +12,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { in("x1") path, in("x2") flags, in("x3") 0i32, // mode - lateout("x0") fd, + lateout("x0") ret, options(nostack) ); - fd + ret } } diff --git a/crates/asm/src/darwin.rs b/crates/asm/src/darwin.rs index be3b246..3c0c97d 100644 --- a/crates/asm/src/darwin.rs +++ b/crates/asm/src/darwin.rs @@ -47,7 +47,7 @@ unsafe extern "C" { newp: *const c_void, newlen: usize, ) -> c_int; - fn gettimeofday(tp: *mut Timeval, tzp: *mut c_void) -> c_int; + fn gettimeofday(timeval: *mut Timeval, tzp: *mut c_void) -> c_int; // Mach host interfaces (live in libsystem_kernel, part of libSystem). fn mach_host_self() -> u32; // mach_port_t @@ -223,25 +223,25 @@ pub fn macos_meminfo() -> Option<(u64, u64)> { // Apple Silicon uses 16 KiB pages; fall back to that if the sysctl is absent. let page = u64::from(macos_sysctl_u32(b"hw.pagesize\0").unwrap_or(16384)); - let mut vm = VmStatistics64::default(); + let mut vm_stats = VmStatistics64::default(); let mut count = u32::try_from(size_of::() / size_of::()).ok()?; - let kr = unsafe { + let ret = unsafe { host_statistics64( mach_host_self(), HOST_VM_INFO64, - ptr::from_mut(&mut vm).cast::(), + ptr::from_mut(&mut vm_stats).cast::(), &raw mut count, ) }; - if kr != 0 { + if ret != 0 { // Mach call failed; report total with unknown usage rather than erroring. return Some((0, total)); } - let used = (u64::from(vm.active_count) - + u64::from(vm.wire_count) - + u64::from(vm.compressor_page_count)) + let used = (u64::from(vm_stats.active_count) + + u64::from(vm_stats.wire_count) + + u64::from(vm_stats.compressor_page_count)) * page; Some((used.min(total), total)) } diff --git a/crates/asm/src/lib.rs b/crates/asm/src/lib.rs index afa477b..1c65543 100644 --- a/crates/asm/src/lib.rs +++ b/crates/asm/src/lib.rs @@ -71,12 +71,12 @@ const UNALIGNED_WORDS: bool = cfg!(any( target_arch = "loongarch64", )); -/// Copies `n` bytes from `src` to `dest`. +/// Copies `len` bytes from `src` to `dest`. /// /// # Safety /// /// `dest` and `src` must be valid pointers to non-overlapping regions of -/// memory of at least `n` bytes. +/// memory of at least `len` bytes. // On macOS these symbols are supplied by libSystem; defining our own would // clash at link time, so the freestanding implementations are Linux-only. #[cfg(not(target_os = "macos"))] @@ -85,31 +85,33 @@ const UNALIGNED_WORDS: bool = cfg!(any( pub unsafe extern "C" fn memcpy( dest: *mut c_void, src: *const c_void, - n: usize, + len: usize, ) -> *mut c_void { let dest_bytes = dest.cast::(); let src_bytes = src.cast::(); - let mut i = 0; + let mut offset = 0; unsafe { if UNALIGNED_WORDS { - while n - i >= WORD { - let word = src_bytes.add(i).cast::().read_unaligned(); - dest_bytes.add(i).cast::().write_unaligned(word); - i += WORD; + while len - offset >= WORD { + let word = src_bytes.add(offset).cast::().read_unaligned(); + dest_bytes.add(offset).cast::().write_unaligned(word); + offset += WORD; } } else if dest_bytes.addr() % WORD == src_bytes.addr() % WORD { - while i < n && !dest_bytes.add(i).addr().is_multiple_of(WORD) { - *dest_bytes.add(i) = *src_bytes.add(i); - i += 1; + while offset < len && !dest_bytes.add(offset).addr().is_multiple_of(WORD) + { + *dest_bytes.add(offset) = *src_bytes.add(offset); + offset += 1; } - while n - i >= WORD { - *dest_bytes.add(i).cast::() = *src_bytes.add(i).cast::(); - i += WORD; + while len - offset >= WORD { + *dest_bytes.add(offset).cast::() = + *src_bytes.add(offset).cast::(); + offset += WORD; } } - while i < n { - *dest_bytes.add(i) = *src_bytes.add(i); - i += 1; + while offset < len { + *dest_bytes.add(offset) = *src_bytes.add(offset); + offset += 1; } } dest @@ -119,64 +121,64 @@ pub unsafe extern "C" fn memcpy( /// /// # Safety /// -/// `s` must be a valid pointer to memory of at least `n` bytes. -/// The value in `c` is treated as unsigned (lower 8 bits used). +/// `dest` must be a valid pointer to memory of at least `len` bytes. +/// The value in `fill` is treated as unsigned (lower 8 bits used). #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] #[allow(clippy::cast_ptr_alignment)] pub unsafe extern "C" fn memset( - s: *mut c_void, - c: i32, - n: usize, + dest: *mut c_void, + fill: i32, + len: usize, ) -> *mut c_void { - let bytes = s.cast::(); - let value = c.to_le_bytes()[0]; - let mut i = 0; + let bytes = dest.cast::(); + let value = fill.to_le_bytes()[0]; + let mut offset = 0; unsafe { if UNALIGNED_WORDS { let word = usize::from_ne_bytes([value; WORD]); - while n - i >= WORD { - bytes.add(i).cast::().write_unaligned(word); - i += WORD; + while len - offset >= WORD { + bytes.add(offset).cast::().write_unaligned(word); + offset += WORD; } } else { - while i < n && !bytes.add(i).addr().is_multiple_of(WORD) { - *bytes.add(i) = value; - i += 1; + while offset < len && !bytes.add(offset).addr().is_multiple_of(WORD) { + *bytes.add(offset) = value; + offset += 1; } let word = usize::from_ne_bytes([value; WORD]); - while n - i >= WORD { - *bytes.add(i).cast::() = word; - i += WORD; + while len - offset >= WORD { + *bytes.add(offset).cast::() = word; + offset += WORD; } } - while i < n { - *bytes.add(i) = value; - i += 1; + while offset < len { + *bytes.add(offset) = value; + offset += 1; } } - s + dest } /// Compares two byte sequences. /// /// # Safety /// -/// `s1` and `s2` must be valid pointers to memory of at least `n` bytes. +/// `left` and `right` must be valid pointers to memory of at least `len` bytes. #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] pub unsafe extern "C" fn bcmp( - s1: *const c_void, - s2: *const c_void, - n: usize, + left: *const c_void, + right: *const c_void, + len: usize, ) -> i32 { - let bytes1 = s1.cast::(); - let bytes2 = s2.cast::(); - for i in 0..n { - let a = unsafe { *bytes1.add(i) }; - let b = unsafe { *bytes2.add(i) }; - if a != b { - return i32::from(a) - i32::from(b); + let bytes1 = left.cast::(); + let bytes2 = right.cast::(); + for offset in 0..len { + let left_byte = unsafe { *bytes1.add(offset) }; + let right_byte = unsafe { *bytes2.add(offset) }; + if left_byte != right_byte { + return i32::from(left_byte) - i32::from(right_byte); } } 0 @@ -186,27 +188,27 @@ pub unsafe extern "C" fn bcmp( /// /// # Safety /// -/// `s1` and `s2` must be valid pointers to memory of at least `n` bytes. +/// `left` and `right` must be valid pointers to memory of at least `len` bytes. #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] pub unsafe extern "C" fn memcmp( - s1: *const c_void, - s2: *const c_void, - n: usize, + left: *const c_void, + right: *const c_void, + len: usize, ) -> i32 { - unsafe { bcmp(s1, s2, n) } + unsafe { bcmp(left, right, len) } } /// Calculates the length of a null-terminated string. /// /// # Safety /// -/// `s` must be a valid pointer to a null-terminated string. +/// `cstr` must be a valid pointer to a null-terminated string. #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] -pub const unsafe extern "C" fn strlen(s: *const i8) -> usize { +pub const unsafe extern "C" fn strlen(cstr: *const i8) -> usize { let mut len = 0; - while unsafe { *s.add(len) } != 0 { + while unsafe { *cstr.add(len) } != 0 { len += 1; } len diff --git a/crates/asm/src/loongarch64.rs b/crates/asm/src/loongarch64.rs index 5b0c5ef..df092c0 100644 --- a/crates/asm/src/loongarch64.rs +++ b/crates/asm/src/loongarch64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i32; + let ret: i32; core::arch::asm!( "syscall 0", in("$a7") 56i64, // SYS_openat @@ -12,10 +12,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { in("$a1") path, in("$a2") flags, in("$a3") 0i32, // mode - lateout("$a0") fd, + lateout("$a0") ret, options(nostack) ); - fd + ret } } diff --git a/crates/asm/src/riscv64.rs b/crates/asm/src/riscv64.rs index 030e2e1..7653190 100644 --- a/crates/asm/src/riscv64.rs +++ b/crates/asm/src/riscv64.rs @@ -4,7 +4,7 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i32; + let ret: i32; core::arch::asm!( "ecall", in("a7") 56i64, // SYS_openat @@ -12,11 +12,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { in("a1") path, in("a2") flags, in("a3") 0i32, // mode - lateout("a0") fd, + lateout("a0") ret, options(nostack) ); - fd + ret } } diff --git a/crates/asm/src/s390x.rs b/crates/asm/src/s390x.rs index c57e87e..992f1d3 100644 --- a/crates/asm/src/s390x.rs +++ b/crates/asm/src/s390x.rs @@ -4,17 +4,17 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i32; + let ret: i32; core::arch::asm!( "svc 0", in("r1") 5i64, // SYS_open in("r2") path, in("r3") flags, in("r4") 0i32, // mode - lateout("r2") fd, + lateout("r2") ret, options(nostack) ); - fd + ret } } diff --git a/crates/asm/src/x86_64.rs b/crates/asm/src/x86_64.rs index 58210c2..5dd932e 100644 --- a/crates/asm/src/x86_64.rs +++ b/crates/asm/src/x86_64.rs @@ -4,19 +4,19 @@ use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { - let fd: i32; + let ret: i32; core::arch::asm!( "syscall", in("rax") 2i64, // SYS_open in("rdi") path, in("rsi") flags, in("rdx") 0i32, // mode (not used for reading) - lateout("rax") fd, + lateout("rax") ret, lateout("rcx") _, lateout("r11") _, options(nostack) ); - fd + ret } } diff --git a/crates/benchmarks/benches/microfetch.rs b/crates/benchmarks/benches/microfetch.rs index d6835ef..5085bb5 100644 --- a/crates/benchmarks/benches/microfetch.rs +++ b/crates/benchmarks/benches/microfetch.rs @@ -12,96 +12,96 @@ use microfetch_lib::{ uptime, }; -fn main_benchmark(c: &mut Criterion) { +fn main_benchmark(criterion: &mut Criterion) { let utsname = UtsName::uname().expect("Failed to get uname"); let colors = Colors::new(false); - c.bench_function("user_info", |b| { - b.iter(|| { + criterion.bench_function("user_info", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - system::write_username_and_hostname(&mut w, &colors, &utsname); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + system::write_username_and_hostname(&mut writer, &colors, &utsname); + black_box(writer.written()); }); }); - c.bench_function("os_name", |b| { - b.iter(|| { + criterion.bench_function("os_name", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - release::write_os_pretty_name(&mut w); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + release::write_os_pretty_name(&mut writer); + black_box(writer.written()); }); }); - c.bench_function("kernel_version", |b| { - b.iter(|| { + criterion.bench_function("kernel_version", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - release::write_system_info(&mut w, &utsname); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + release::write_system_info(&mut writer, &utsname); + black_box(writer.written()); }); }); - c.bench_function("cpu_name", |b| { - b.iter(|| { + criterion.bench_function("cpu_name", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - cpu::write_cpu_name(&mut w); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + cpu::write_cpu_name(&mut writer); + black_box(writer.written()); }); }); - c.bench_function("cpu_cores", |b| { - b.iter(|| { + criterion.bench_function("cpu_cores", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - cpu::write_cpu_cores(&mut w); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + cpu::write_cpu_cores(&mut writer); + black_box(writer.written()); }); }); - c.bench_function("shell", |b| { - b.iter(|| { + criterion.bench_function("shell", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - system::write_shell(&mut w); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + system::write_shell(&mut writer); + black_box(writer.written()); }); }); - c.bench_function("desktop", |b| { - b.iter(|| { + criterion.bench_function("desktop", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - desktop::write_desktop_info(&mut w); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + desktop::write_desktop_info(&mut writer); + black_box(writer.written()); }); }); - c.bench_function("uptime", |b| { - b.iter(|| { + criterion.bench_function("uptime", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - uptime::write_uptime(&mut w); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + uptime::write_uptime(&mut writer); + black_box(writer.written()); }); }); - c.bench_function("memory_usage", |b| { - b.iter(|| { + criterion.bench_function("memory_usage", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - system::write_memory_usage(&mut w, &colors); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + system::write_memory_usage(&mut writer, &colors); + black_box(writer.written()); }); }); - c.bench_function("storage", |b| { - b.iter(|| { + criterion.bench_function("storage", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - system::write_root_disk_usage(&mut w, &colors); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + system::write_root_disk_usage(&mut writer, &colors); + black_box(writer.written()); }); }); - c.bench_function("colors", |b| { - b.iter(|| { + criterion.bench_function("colors", |bencher| { + bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; - let mut w = StackWriter::new(&mut buf); - colors::write_dots(&mut w, &colors); - black_box(w.written()); + let mut writer = StackWriter::new(&mut buf); + colors::write_dots(&mut writer, &colors); + black_box(writer.written()); }); }); } diff --git a/crates/lib/build.rs b/crates/lib/build.rs index f6bdf9e..3d5f548 100644 --- a/crates/lib/build.rs +++ b/crates/lib/build.rs @@ -28,12 +28,12 @@ fn main() { ]; let mut out = Vec::new(); - for (i, row) in rows.iter().enumerate() { + for (row_index, row) in rows.iter().enumerate() { for &(color, text) in *row { out.push(color + 1); out.extend_from_slice(text.as_bytes()); } - if i < rows.len() - 1 { + if row_index < rows.len() - 1 { out.push(0); } } diff --git a/crates/lib/src/colors.rs b/crates/lib/src/colors.rs index ead3acd..65a7707 100644 --- a/crates/lib/src/colors.rs +++ b/crates/lib/src/colors.rs @@ -44,8 +44,8 @@ pub(crate) fn is_no_color() -> bool { } #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_dots(w: &mut StackWriter, colors: &Colors) { - for c in [ +pub fn write_dots(writer: &mut StackWriter, colors: &Colors) { + for color in [ colors.blue, colors.cyan, colors.green, @@ -53,8 +53,8 @@ pub fn write_dots(w: &mut StackWriter, colors: &Colors) { colors.red, colors.magenta, ] { - w.push_str(c); - w.push_str("● "); + writer.push_str(color); + writer.push_str("● "); } - w.push_str(colors.reset); + writer.push_str(colors.reset); } diff --git a/crates/lib/src/cpu.rs b/crates/lib/src/cpu.rs index 9d944fb..79ed5d7 100644 --- a/crates/lib/src/cpu.rs +++ b/crates/lib/src/cpu.rs @@ -5,21 +5,21 @@ use crate::syscall::read_file_fast; /// Writes CPU model name (trimmed) to the writer. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_cpu_name(w: &mut StackWriter) { - write_model_name(w); +pub fn write_cpu_name(writer: &mut StackWriter) { + write_model_name(writer); } /// Writes CPU model name from `machdep.cpu.brand_string` (macOS), /// e.g. `Apple M2 Pro`. Returns an empty string if unavailable. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_cpu_name(w: &mut StackWriter) { +pub fn write_cpu_name(writer: &mut StackWriter) { let mut buf = [0u8; 128]; - if let Some(n) = + if let Some(len) = crate::syscall::macos_sysctl_str(b"machdep.cpu.brand_string\0", &mut buf) - && let Ok(name) = core::str::from_utf8(&buf[..n]) + && let Ok(name) = core::str::from_utf8(&buf[..len]) { - w.push_str(name); + writer.push_str(name); } } @@ -30,12 +30,12 @@ pub fn write_cpu_name(w: &mut StackWriter) { /// count cannot be determined. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_cpu_cores(w: &mut StackWriter) { +pub fn write_cpu_cores(writer: &mut StackWriter) { let Some(threads) = get_thread_count() else { return; }; let cores = get_core_count(threads); - write_cores(w, cores, get_pe_cores(), threads); + write_cores(writer, cores, get_pe_cores(), threads); } /// Writes CPU core/thread info via `sysctl` (macOS). @@ -45,7 +45,7 @@ pub fn write_cpu_cores(w: &mut StackWriter) { /// logical CPU count cannot be determined. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_cpu_cores(w: &mut StackWriter) { +pub fn write_cpu_cores(writer: &mut StackWriter) { use crate::syscall::macos_sysctl_u32; let Some(threads) = macos_sysctl_u32(b"hw.logicalcpu\0") else { @@ -55,41 +55,41 @@ pub fn write_cpu_cores(w: &mut StackWriter) { // Performance/efficiency split (Apple Silicon). Only reported when both // perf levels are present. - let pe = match ( + let hybrid = match ( macos_sysctl_u32(b"hw.perflevel0.physicalcpu\0"), macos_sysctl_u32(b"hw.perflevel1.physicalcpu\0"), ) { - (Some(p), Some(e)) => Some((p, e)), + (Some(perf), Some(eff)) => Some((perf, eff)), _ => None, }; - write_cores(w, cores, pe, threads); + write_cores(writer, cores, hybrid, threads); } /// Writes core/thread counts identically across platforms: /// `{cores} cores ({p}p/{e}e), {threads} threads`, omitting the P/E group and /// the thread suffix when not applicable. fn write_cores( - w: &mut StackWriter, + writer: &mut StackWriter, cores: u32, - pe: Option<(u32, u32)>, + hybrid: Option<(u32, u32)>, threads: u32, ) { - w.push_u64(u64::from(cores)); - w.push_str(" cores"); - - if let Some((p, e)) = pe { - w.push_str(" ("); - w.push_u64(u64::from(p)); - w.push_str("p/"); - w.push_u64(u64::from(e)); - w.push_str("e)"); + writer.push_u64(u64::from(cores)); + writer.push_str(" cores"); + + if let Some((perf, eff)) = hybrid { + writer.push_str(" ("); + writer.push_u64(u64::from(perf)); + writer.push_str("p/"); + writer.push_u64(u64::from(eff)); + writer.push_str("e)"); } if threads != cores { - w.push_str(", "); - w.push_u64(u64::from(threads)); - w.push_str(" threads"); + writer.push_str(", "); + writer.push_u64(u64::from(threads)); + writer.push_str(" threads"); } } @@ -126,26 +126,30 @@ fn get_core_count(threads: u32) -> u32 { /// by reading `/sys/devices/cpu_core/cpus` and `/sys/devices/cpu_atom/cpus`. #[cfg(target_os = "linux")] fn get_pe_cores() -> Option<(u32, u32)> { - let p = count_cpulist("/sys/devices/cpu_core/cpus")?; - let e = count_cpulist("/sys/devices/cpu_atom/cpus").unwrap_or(0); - if p > 0 || e > 0 { Some((p, e)) } else { None } + let perf = count_cpulist("/sys/devices/cpu_core/cpus")?; + let eff = count_cpulist("/sys/devices/cpu_atom/cpus").unwrap_or(0); + if perf > 0 || eff > 0 { + Some((perf, eff)) + } else { + None + } } /// Parse a cpulist file and count listed CPUs. #[cfg(target_os = "linux")] fn count_cpulist(path: &str) -> Option { let mut buf = [0u8; 64]; - let n = read_file_fast(path, &mut buf).ok()?; - let data = &buf[..n]; + let len = read_file_fast(path, &mut buf).ok()?; + let data = &buf[..len]; let mut count = 0u32; - let mut i = 0; - while i < data.len() { + let mut pos = 0; + while pos < data.len() { // Parse start number - let start = parse_num(data, &mut i); - if i < data.len() && data[i] == b'-' { - i += 1; - let end = parse_num(data, &mut i); + let start = parse_num(data, &mut pos); + if pos < data.len() && data[pos] == b'-' { + pos += 1; + let end = parse_num(data, &mut pos); // The Kernel always emits ascending ranges, so end is always >= start // https://github.com/torvalds/linux/blob/v6.19/lib/vsprintf.c#L1276-L1303 count += end - start + 1; @@ -153,8 +157,8 @@ fn count_cpulist(path: &str) -> Option { count += 1; } // Skip comma or newline - if i < data.len() && (data[i] == b',' || data[i] == b'\n') { - i += 1; + if pos < data.len() && (data[pos] == b',' || data[pos] == b'\n') { + pos += 1; } } Some(count) @@ -162,13 +166,13 @@ fn count_cpulist(path: &str) -> Option { /// Parse a decimal number from a byte slice, advancing the index. #[cfg(target_os = "linux")] -fn parse_num(data: &[u8], i: &mut usize) -> u32 { - let mut n = 0u32; - while *i < data.len() && data[*i].is_ascii_digit() { - n = n * 10 + u32::from(data[*i] - b'0'); - *i += 1; +fn parse_num(data: &[u8], pos: &mut usize) -> u32 { + let mut value = 0u32; + while *pos < data.len() && data[*pos].is_ascii_digit() { + value = value * 10 + u32::from(data[*pos] - b'0'); + *pos += 1; } - n + value } /// Build `/sys/devices/system/cpu/cpu{n}/cpufreq/cpuinfo_max_freq` into buf, @@ -178,41 +182,41 @@ fn format_cpufreq_path(buf: &mut [u8; 64], cpu: u32) -> usize { const PREFIX: &[u8] = b"/sys/devices/system/cpu/cpu"; const SUFFIX: &[u8] = b"/cpufreq/cpuinfo_max_freq"; buf[..PREFIX.len()].copy_from_slice(PREFIX); - let mut i = PREFIX.len(); + let mut pos = PREFIX.len(); let mut tmp = [0u8; 3]; - let mut n = cpu; + let mut value = cpu; let mut digits = 0; loop { - tmp[digits] = b'0' + (n % 10) as u8; + tmp[digits] = b'0' + (value % 10) as u8; digits += 1; - n /= 10; - if n == 0 { + value /= 10; + if value == 0 { break; } } while digits > 0 { digits -= 1; - buf[i] = tmp[digits]; - i += 1; + buf[pos] = tmp[digits]; + pos += 1; } - buf[i..i + SUFFIX.len()].copy_from_slice(SUFFIX); - i + SUFFIX.len() + buf[pos..pos + SUFFIX.len()].copy_from_slice(SUFFIX); + pos + SUFFIX.len() } /// Read one CPU's `cpuinfo_max_freq`, in kHz. #[cfg(target_os = "linux")] fn read_cpu_max_khz(cpu: u32) -> Option { let mut path = [0u8; 64]; - let n = format_cpufreq_path(&mut path, cpu); + let path_len = format_cpufreq_path(&mut path, cpu); // SAFETY: the path is a constant prefix, decimal digits, and a constant // suffix, so it is ASCII by construction. - let p = unsafe { core::str::from_utf8_unchecked(&path[..n]) }; + let path_str = unsafe { core::str::from_utf8_unchecked(&path[..path_len]) }; let mut buf = [0u8; 32]; - let m = read_file_fast(p, &mut buf).ok()?; + let len = read_file_fast(path_str, &mut buf).ok()?; let mut khz = 0u32; - for &b in &buf[..m] { - if b.is_ascii_digit() { - khz = khz * 10 + u32::from(b - b'0'); + for &byte in &buf[..len] { + if byte.is_ascii_digit() { + khz = khz * 10 + u32::from(byte - b'0'); } } (khz > 0).then_some(khz) @@ -224,16 +228,16 @@ fn read_cpu_max_khz(cpu: u32) -> Option { #[cfg(target_os = "linux")] fn highest_present_cpu() -> Option { let mut buf = [0u8; 64]; - let n = read_file_fast("/sys/devices/system/cpu/present", &mut buf).ok()?; - let data = &buf[..n]; + let len = read_file_fast("/sys/devices/system/cpu/present", &mut buf).ok()?; + let data = &buf[..len]; let end = data.iter().rposition(u8::is_ascii_digit)? + 1; let start = data[..end] .iter() - .rposition(|b| !b.is_ascii_digit()) - .map_or(0, |i| i + 1); + .rposition(|byte| !byte.is_ascii_digit()) + .map_or(0, |pos| pos + 1); let mut cpu = 0u32; - for &b in &data[start..end] { - cpu = cpu * 10 + u32::from(b - b'0'); + for &byte in &data[start..end] { + cpu = cpu * 10 + u32::from(byte - b'0'); } Some(cpu) } @@ -280,19 +284,21 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { if let Some(val) = extract_field(cpuinfo, key) { // Parse integer part of the MHz value (e.g. "5200.00" -> 5200) let mut mhz = 0u32; - for &b in val.as_bytes() { - if b == b'.' { + for &byte in val.as_bytes() { + if byte == b'.' { break; } - if b.is_ascii_digit() { - mhz = mhz * 10 + u32::from(b - b'0'); + if byte.is_ascii_digit() { + mhz = mhz * 10 + u32::from(byte - b'0'); } } // Octeon presets loops_per_jiffy to clock_rate/HZ, so its BogoMIPS is // exactly 2x the core clock, unlike the 1:1 of other MIPS. // https://github.com/torvalds/linux/blob/v6.19/arch/mips/cavium-octeon/csrc-octeon.c#L40 - if *key == b"BogoMIPS" && cpuinfo.windows(6).any(|w| w == b"Octeon") { + if *key == b"BogoMIPS" + && cpuinfo.windows(6).any(|window| window == b"Octeon") + { mhz /= 2; } @@ -306,16 +312,16 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { if let Some(val) = extract_field(cpuinfo, b"Cpu0ClkTck") { let mut hz = 0u64; let mut seen = false; - for &b in val.as_bytes() { - let d = match b { - b'0'..=b'9' => Some(u64::from(b - b'0')), - b'a'..=b'f' => Some(u64::from(b - b'a' + 10)), - b'A'..=b'F' => Some(u64::from(b - b'A' + 10)), + for &byte in val.as_bytes() { + let hex_digit = match byte { + b'0'..=b'9' => Some(u64::from(byte - b'0')), + b'a'..=b'f' => Some(u64::from(byte - b'a' + 10)), + b'A'..=b'F' => Some(u64::from(byte - b'A' + 10)), _ => None, }; - match d { - Some(d) => { - hz = hz * 16 + d; + match hex_digit { + Some(digit) => { + hz = hz * 16 + digit; seen = true; }, None if seen => break, @@ -332,12 +338,12 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { /// Parse CPU model name from `/proc/cpuinfo` and write it directly. /// Appends CPU frequency if available. #[cfg(target_os = "linux")] -fn write_model_name(w: &mut StackWriter) { +fn write_model_name(writer: &mut StackWriter) { let mut buf = [0u8; 1024]; - let Ok(n) = read_file_fast("/proc/cpuinfo", &mut buf) else { + let Ok(len) = read_file_fast("/proc/cpuinfo", &mut buf) else { return; }; - let data = &buf[..n]; + let data = &buf[..len]; let mhz = get_cpu_freq_mhz(data); let named = match extract_name(data) { @@ -345,15 +351,15 @@ fn write_model_name(w: &mut StackWriter) { // x86 `model name` already ends in `@ GHz`, which hides the // ` CPU` that trim() would otherwise strip, so re-trim after cutting. let name = match (mhz, name.find(" @ ")) { - (Some(_), Some(at)) => trim(&name[..at]), + (Some(_), Some(at_pos)) => trim(&name[..at_pos]), _ => name, }; - w.push_str(name); + writer.push_str(name); true }, None => { - write_dt_compatible(w) - || (cfg!(target_arch = "aarch64") && write_arm_part(w, data)) + write_dt_compatible(writer) + || (cfg!(target_arch = "aarch64") && write_arm_part(writer, data)) }, }; @@ -362,7 +368,7 @@ fn write_model_name(w: &mut StackWriter) { }; if named { - w.push_str(" @ "); + writer.push_str(" @ "); } // Round to nearest 0.01 GHz, then split so carries (e.g. 1999 MHz) @@ -370,13 +376,13 @@ fn write_model_name(w: &mut StackWriter) { let rounded_centesimal = (mhz + 5) / 10; let ghz_int = rounded_centesimal / 100; let ghz_frac = rounded_centesimal % 100; - w.push_u64(u64::from(ghz_int)); - w.push_byte(b'.'); + writer.push_u64(u64::from(ghz_int)); + writer.push_byte(b'.'); if ghz_frac < 10 { - w.push_byte(b'0'); + writer.push_byte(b'0'); } - w.push_u64(u64::from(ghz_frac)); - w.push_str(" GHz"); + writer.push_u64(u64::from(ghz_frac)); + writer.push_str(" GHz"); } #[cfg(target_os = "linux")] @@ -485,7 +491,7 @@ static ARM_PARTS: [ArmPart; 45] = { /// Name the core from `CPU implementer` and `CPU part` on ACPI aarch64. #[cfg(target_os = "linux")] -fn write_arm_part(w: &mut StackWriter, data: &[u8]) -> bool { +fn write_arm_part(writer: &mut StackWriter, data: &[u8]) -> bool { let hex = |key| { let digits = extract_field(data, key)?.strip_prefix("0x")?; let mut value = 0u32; @@ -510,9 +516,9 @@ fn write_arm_part(w: &mut StackWriter, data: &[u8]) -> bool { return false; }; - let len = entry.model.iter().position(|&b| b == 0).unwrap_or(7); - w.push_str(entry.family.prefix()); - w.push_bytes(&entry.model[..len]); + let len = entry.model.iter().position(|&byte| byte == 0).unwrap_or(7); + writer.push_str(entry.family.prefix()); + writer.push_bytes(&entry.model[..len]); true } @@ -544,20 +550,27 @@ fn extract_name(data: &[u8]) -> Option<&str> { /// (board) to most-generic (`SoC`); we take the last entry and write just /// the model portion after the comma. #[cfg(target_os = "linux")] -fn write_dt_compatible(w: &mut StackWriter) -> bool { +fn write_dt_compatible(writer: &mut StackWriter) -> bool { let mut buf = [0u8; 256]; - let Ok(n) = + let Ok(len) = read_file_fast("/sys/firmware/devicetree/base/compatible", &mut buf) else { return false; }; // Drop the terminating NUL so the rposition below locates the entry // separator rather than the end-of-string marker. - let end = if n > 0 && buf[n - 1] == 0 { n - 1 } else { n }; + let end = if len > 0 && buf[len - 1] == 0 { + len - 1 + } else { + len + }; let data = &buf[..end]; - let start = data.iter().rposition(|&b| b == 0).map_or(0, |p| p + 1); + let start = data + .iter() + .rposition(|&byte| byte == 0) + .map_or(0, |pos| pos + 1); let entry = &data[start..]; - let Some(comma) = entry.iter().position(|&b| b == b',') else { + let Some(comma) = entry.iter().position(|&byte| byte == b',') else { return false; }; let Ok(model) = core::str::from_utf8(&entry[comma + 1..]) else { @@ -566,38 +579,38 @@ fn write_dt_compatible(w: &mut StackWriter) -> bool { if model.is_empty() { return false; } - w.push_str(model); + writer.push_str(model); true } /// Extract value of first occurrence of `key` in cpuinfo. #[cfg(target_os = "linux")] -fn extract_field<'a>(data: &'a [u8], key: &[u8]) -> Option<&'a str> { - let mut i = 0; - while i < data.len() { - let remaining = &data[i..]; +fn extract_field<'data>(data: &'data [u8], key: &[u8]) -> Option<&'data str> { + let mut index = 0; + while index < data.len() { + let remaining = &data[index..]; let eol = remaining .iter() - .position(|&b| b == b'\n') + .position(|&byte| byte == b'\n') .unwrap_or(remaining.len()); let line = &remaining[..eol]; if line.starts_with(key) { - let mut p = key.len(); - while p < line.len() && (line[p] == b'\t' || line[p] == b' ') { - p += 1; + let mut pos = key.len(); + while pos < line.len() && (line[pos] == b'\t' || line[pos] == b' ') { + pos += 1; } - if p < line.len() && line[p] == b':' { - p += 1; - while p < line.len() && line[p] == b' ' { - p += 1; + if pos < line.len() && line[pos] == b':' { + pos += 1; + while pos < line.len() && line[pos] == b' ' { + pos += 1; } // SAFETY: cpuinfo fields are ASCII - return Some(unsafe { core::str::from_utf8_unchecked(&line[p..]) }); + return Some(unsafe { core::str::from_utf8_unchecked(&line[pos..]) }); } } - i += eol + 1; + index += eol + 1; } None } @@ -605,48 +618,48 @@ fn extract_field<'a>(data: &'a [u8], key: &[u8]) -> Option<&'a str> { /// Strip noise from model names. #[cfg(target_os = "linux")] fn trim(name: &str) -> &str { - let b = name.as_bytes(); - let mut end = b.len(); + let bytes = name.as_bytes(); + let mut end = bytes.len(); - while end > 0 && b[end - 1].is_ascii_whitespace() { + while end > 0 && bytes[end - 1].is_ascii_whitespace() { end -= 1; } - if end >= 10 && &b[end - 10..end] == b" Processor" { + if end >= 10 && &bytes[end - 10..end] == b" Processor" { end -= 10; - } else if end >= 4 && &b[end - 4..end] == b" CPU" { + } else if end >= 4 && &bytes[end - 4..end] == b" CPU" { end -= 4; } - while end > 0 && b[end - 1].is_ascii_whitespace() { + while end > 0 && bytes[end - 1].is_ascii_whitespace() { end -= 1; } - if end >= 3 && &b[end - 3..end] == b"(R)" { + if end >= 3 && &bytes[end - 3..end] == b"(R)" { end -= 3; } else if end >= 4 - && (&b[end - 4..end] == b"(TM)" || &b[end - 4..end] == b"(tm)") + && (&bytes[end - 4..end] == b"(TM)" || &bytes[end - 4..end] == b"(tm)") { end -= 4; } - while end > 0 && b[end - 1].is_ascii_whitespace() { + while end > 0 && bytes[end - 1].is_ascii_whitespace() { end -= 1; } - if end > 7 && &b[end - 5..end] == b"-Core" { - let mut p = end - 5; - while p > 0 && b[p - 1].is_ascii_digit() { - p -= 1; + if end > 7 && &bytes[end - 5..end] == b"-Core" { + let mut pos = end - 5; + while pos > 0 && bytes[pos - 1].is_ascii_digit() { + pos -= 1; } - if p > 0 && b[p - 1] == b' ' { - end = p - 1; + if pos > 0 && bytes[pos - 1] == b' ' { + end = pos - 1; } } - while end > 0 && b[end - 1].is_ascii_whitespace() { + while end > 0 && bytes[end - 1].is_ascii_whitespace() { end -= 1; } let mut start = 0; - while start < end && b[start].is_ascii_whitespace() { + while start < end && bytes[start].is_ascii_whitespace() { start += 1; } diff --git a/crates/lib/src/desktop.rs b/crates/lib/src/desktop.rs index 3b5871a..100bb2e 100644 --- a/crates/lib/src/desktop.rs +++ b/crates/lib/src/desktop.rs @@ -1,7 +1,7 @@ use crate::{StackWriter, getenv_str}; #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_desktop_info(w: &mut StackWriter) { +pub fn write_desktop_info(writer: &mut StackWriter) { let desktop_raw = getenv_str("XDG_CURRENT_DESKTOP"); let session_raw = getenv_str("XDG_SESSION_TYPE"); @@ -13,7 +13,7 @@ pub fn write_desktop_info(w: &mut StackWriter) { "Unknown" } }, - |s| s.strip_prefix("none+").unwrap_or(s), + |desktop| desktop.strip_prefix("none+").unwrap_or(desktop), ); let backend_str = session_raw.unwrap_or({ @@ -24,8 +24,8 @@ pub fn write_desktop_info(w: &mut StackWriter) { } }); - w.push_str(desktop_str); - w.push_str(" ("); + writer.push_str(desktop_str); + writer.push_str(" ("); // Capitalize first character of backend if let Some(&first_byte) = backend_str.as_bytes().first() { @@ -35,9 +35,9 @@ pub fn write_desktop_info(w: &mut StackWriter) { } else { first_byte }; - w.push_byte(upper); - w.push_str(&backend_str[1..]); + writer.push_byte(upper); + writer.push_str(&backend_str[1..]); } - w.push_byte(b')'); + writer.push_byte(b')'); } diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index 1639c6a..f8a5cf0 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -91,20 +91,20 @@ pub fn getenv(name: &str) -> Option<&'static [u8]> { let name_bytes = name.as_bytes(); // Walk through environment variables - let mut i = 0; + let mut env_index = 0; loop { // SAFETY: environ is null-terminated array of pointers - let entry = unsafe { *envp.add(i) }; + let entry = unsafe { *envp.add(env_index) }; if entry.is_null() { break; } // Check if this entry starts with our variable name followed by '=' let mut matches = true; - for (j, &b) in name_bytes.iter().enumerate() { + for (name_index, &name_byte) in name_bytes.iter().enumerate() { // SAFETY: entry is a valid C string - let entry_byte = unsafe { *entry.add(j) }; - if entry_byte != b { + let entry_byte = unsafe { *entry.add(name_index) }; + if entry_byte != name_byte { matches = false; break; } @@ -120,8 +120,8 @@ pub fn getenv(name: &str) -> Option<&'static [u8]> { let mut len = 0; loop { // SAFETY: entry is a valid C string - let b = unsafe { *value_start.add(len) }; - if b == 0 { + let value_byte = unsafe { *value_start.add(len) }; + if value_byte == 0 { break; } len += 1; @@ -131,7 +131,7 @@ pub fn getenv(name: &str) -> Option<&'static [u8]> { } } - i += 1; + env_index += 1; } None @@ -195,14 +195,14 @@ impl UtsName { } /// Minimal, stack-allocated writer. -pub struct StackWriter<'a> { - buf: &'a mut [MaybeUninit], +pub struct StackWriter<'buf> { + buf: &'buf mut [MaybeUninit], pos: usize, } -impl<'a> StackWriter<'a> { +impl<'buf> StackWriter<'buf> { #[inline] - pub const fn new(buf: &'a mut [MaybeUninit]) -> Self { + pub const fn new(buf: &'buf mut [MaybeUninit]) -> Self { Self { buf, pos: 0 } } @@ -213,51 +213,51 @@ impl<'a> StackWriter<'a> { } #[inline] - pub fn push_str(&mut self, s: &str) { - self.push_bytes(s.as_bytes()); + pub fn push_str(&mut self, text: &str) { + self.push_bytes(text.as_bytes()); } #[inline(never)] pub fn push_bytes(&mut self, bytes: &[u8]) { - let n = bytes.len().min(self.buf.len() - self.pos); + let len = bytes.len().min(self.buf.len() - self.pos); unsafe { core::ptr::copy_nonoverlapping( bytes.as_ptr(), self.buf.as_mut_ptr().add(self.pos).cast(), - n, + len, ); } - self.pos += n; + self.pos += len; } #[inline] - pub const fn push_byte(&mut self, b: u8) { + pub const fn push_byte(&mut self, byte: u8) { if self.pos < self.buf.len() { - self.buf[self.pos].write(b); + self.buf[self.pos].write(byte); self.pos += 1; } } /// Write a [`CStr`]'s bytes (excluding the null terminator). #[inline] - pub fn push_cstr(&mut self, s: &CStr) { - self.push_bytes(s.to_bytes()); + pub fn push_cstr(&mut self, cstr: &CStr) { + self.push_bytes(cstr.to_bytes()); } /// Write a u64 as decimal ASCII. - pub fn push_u64(&mut self, mut n: u64) { - if n == 0 { + pub fn push_u64(&mut self, mut value: u64) { + if value == 0 { self.push_byte(b'0'); return; } - let mut tmp = [0u8; 20]; - let mut i = 20; - while n > 0 { - i -= 1; - tmp[i] = b'0' + (n % 10) as u8; - n /= 10; + let mut digits = [0u8; 20]; + let mut start = 20; + while value > 0 { + start -= 1; + digits[start] = b'0' + (value % 10) as u8; + value /= 10; } - self.push_bytes(&tmp[i..]); + self.push_bytes(&digits[start..]); } } @@ -270,7 +270,7 @@ impl<'a> StackWriter<'a> { /// Each line maps to one info row. When unset, the built-in two-tone NixOS /// logo is used. const CUSTOM_LOGO: &str = match option_env!("MICROFETCH_LOGO") { - Some(s) => s, + Some(logo) => logo, None => "", }; @@ -280,27 +280,30 @@ const LOGO: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/logo.bin")); /// Write one row from a packed color-marked byte stream. #[inline(never)] fn write_styled_row( - w: &mut StackWriter, - c: &colors::Colors, + writer: &mut StackWriter, + colors: &colors::Colors, stream: &mut &[u8], ) { - let colors = [c.blue, c.cyan, c.reset]; + let palette = [colors.blue, colors.cyan, colors.reset]; let data = *stream; - let row_end = data.iter().position(|&b| b == 0).unwrap_or(data.len()); + let row_end = data + .iter() + .position(|&byte| byte == 0) + .unwrap_or(data.len()); let row_data = &data[..row_end]; *stream = data.get(row_end + 1..).unwrap_or(&[]); - let mut i = 0; - while i < row_data.len() { - if let marker @ 1..=3 = row_data[i] { - w.push_str(colors[usize::from(marker - 1)]); - i += 1; + let mut pos = 0; + while pos < row_data.len() { + if let marker @ 1..=3 = row_data[pos] { + writer.push_str(palette[usize::from(marker - 1)]); + pos += 1; } else { - let chunk_start = i; - while i < row_data.len() && row_data[i] > 3 { - i += 1; + let chunk_start = pos; + while pos < row_data.len() && row_data[pos] > 3 { + pos += 1; } - w.push_bytes(&row_data[chunk_start..i]); + writer.push_bytes(&row_data[chunk_start..pos]); } } } @@ -324,44 +327,44 @@ const ROW_LABELS: &[u8] = concat!( #[inline(never)] #[allow(clippy::ref_option)] fn write_row( - w: &mut StackWriter, - c: &colors::Colors, + writer: &mut StackWriter, + colors: &colors::Colors, row: usize, custom_logo: Option<&str>, logo: &mut &[u8], labels: &mut &[u8], utsname: &UtsName, ) { - w.push_str(" "); + writer.push_str(" "); if let Some(custom_logo) = custom_logo { - w.push_str(c.cyan); - w.push_str(custom_logo); + writer.push_str(colors.cyan); + writer.push_str(custom_logo); } else { - write_styled_row(w, c, logo); + write_styled_row(writer, colors, logo); } - w.push_str(c.reset); - w.push_str(" "); + writer.push_str(colors.reset); + writer.push_str(" "); if row != 0 { - write_styled_row(w, c, labels); + write_styled_row(writer, colors, labels); } match row { 0 => { - system::write_username_and_hostname(w, c, utsname); - w.push_str(" ~"); - w.push_str(c.reset); + system::write_username_and_hostname(writer, colors, utsname); + writer.push_str(" ~"); + writer.push_str(colors.reset); }, - 1 => release::write_os_pretty_name(w), - 2 => release::write_system_info(w, utsname), - 3 => cpu::write_cpu_name(w), - 4 => cpu::write_cpu_cores(w), - 5 => system::write_shell(w), - 6 => uptime::write_uptime(w), - 7 => desktop::write_desktop_info(w), - 8 => system::write_memory_usage(w, c), - 9 => system::write_root_disk_usage(w, c), - _ => colors::write_dots(w, c), + 1 => release::write_os_pretty_name(writer), + 2 => release::write_system_info(writer, utsname), + 3 => cpu::write_cpu_name(writer), + 4 => cpu::write_cpu_cores(writer), + 5 => system::write_shell(writer), + 6 => uptime::write_uptime(writer), + 7 => desktop::write_desktop_info(writer), + 8 => system::write_memory_usage(writer, colors), + 9 => system::write_root_disk_usage(writer, colors), + _ => colors::write_dots(writer, colors), } - w.push_byte(b'\n'); + writer.push_byte(b'\n'); } /// Print version information using direct syscall. @@ -389,10 +392,10 @@ unsafe fn check_version_flag(argc: i32, argv: *const *const u8) -> bool { } // Check if arg1 is "--version" let version_flag = b"--version\0"; - for (i, &b) in version_flag.iter().enumerate() { + for (flag_index, &flag_byte) in version_flag.iter().enumerate() { // SAFETY: arg1 is a valid C string - let arg_byte = unsafe { *arg1.add(i) }; - if arg_byte != b { + let arg_byte = unsafe { *arg1.add(flag_index) }; + if arg_byte != flag_byte { return false; } } @@ -423,10 +426,10 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> { let utsname = UtsName::uname()?; let no_color = colors::is_no_color(); - let c = colors::Colors::new(no_color); + let colors = colors::Colors::new(no_color); let mut buf = [MaybeUninit::uninit(); 2560]; - let mut w = StackWriter::new(&mut buf); + let mut writer = StackWriter::new(&mut buf); // Custom logo is 11 lines from MICROFETCH_LOGO env var, one per info row. // Lines beyond 11 are ignored; missing lines render as empty. @@ -442,12 +445,12 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> { let mut logo = LOGO; let mut labels = ROW_LABELS; - w.push_byte(b'\n'); + writer.push_byte(b'\n'); for (row, &line) in logo_lines.iter().enumerate() { write_row( - &mut w, - &c, + &mut writer, + &colors, row, use_custom.then_some(line), &mut logo, @@ -456,10 +459,10 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> { ); } - w.push_byte(b'\n'); + writer.push_byte(b'\n'); // Single syscall for the entire output. - let out = w.written(); + let out = writer.written(); let written = unsafe { sys_write(1, out.as_ptr(), out.len()) }; let Ok(count) = usize::try_from(written) else { return Err( diff --git a/crates/lib/src/release.rs b/crates/lib/src/release.rs index fb9be95..2b215ae 100644 --- a/crates/lib/src/release.rs +++ b/crates/lib/src/release.rs @@ -3,29 +3,29 @@ use crate::syscall::read_file_fast; use crate::{StackWriter, UtsName}; #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_system_info(w: &mut StackWriter, utsname: &UtsName) { - w.push_cstr(utsname.sysname()); - w.push_byte(b' '); - w.push_cstr(utsname.release()); - w.push_str(" ("); - w.push_cstr(utsname.machine()); - w.push_byte(b')'); +pub fn write_system_info(writer: &mut StackWriter, utsname: &UtsName) { + writer.push_cstr(utsname.sysname()); + writer.push_byte(b' '); + writer.push_cstr(utsname.release()); + writer.push_str(" ("); + writer.push_cstr(utsname.machine()); + writer.push_byte(b')'); } /// Writes the OS name from `kern.osproductversion` (macOS), e.g. `macOS 14.5`. /// Falls back to `macOS` if the version sysctl is unavailable. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_os_pretty_name(w: &mut StackWriter) { - w.push_str("macOS"); +pub fn write_os_pretty_name(writer: &mut StackWriter) { + writer.push_str("macOS"); let mut buf = [0u8; 64]; - if let Some(n) = + if let Some(len) = crate::syscall::macos_sysctl_str(b"kern.osproductversion\0", &mut buf) - && let Ok(version) = core::str::from_utf8(&buf[..n]) + && let Ok(version) = core::str::from_utf8(&buf[..len]) && !version.is_empty() { - w.push_byte(b' '); - w.push_str(version); + writer.push_byte(b' '); + writer.push_str(version); } } @@ -33,7 +33,7 @@ pub fn write_os_pretty_name(w: &mut StackWriter) { /// cannot be read. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_os_pretty_name(w: &mut StackWriter) { +pub fn write_os_pretty_name(writer: &mut StackWriter) { // Fast byte-level scanning for PRETTY_NAME= const PREFIX: &[u8] = b"PRETTY_NAME="; @@ -52,7 +52,7 @@ pub fn write_os_pretty_name(w: &mut StackWriter) { // Find newline or end let line_end = remaining .iter() - .position(|&b| b == b'\n') + .position(|&byte| byte == b'\n') .unwrap_or(remaining.len()); let line = &remaining[..line_end]; @@ -72,12 +72,12 @@ pub fn write_os_pretty_name(w: &mut StackWriter) { // Write bytes directly — os-release values are effectively always // valid UTF-8 (ASCII names, version numbers). No lossy conversion // needed. - w.push_bytes(trimmed); + writer.push_bytes(trimmed); return; } offset += line_end + 1; } - w.push_str("Unknown"); + writer.push_str("Unknown"); } diff --git a/crates/lib/src/system.rs b/crates/lib/src/system.rs index 86e5ae3..191a3a5 100644 --- a/crates/lib/src/system.rs +++ b/crates/lib/src/system.rs @@ -11,37 +11,37 @@ use crate::{ #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_username_and_hostname( - w: &mut StackWriter, + writer: &mut StackWriter, colors: &Colors, utsname: &UtsName, ) { let username = crate::getenv_str("USER").unwrap_or("unknown_user"); let hostname = utsname.nodename(); - w.push_str(colors.yellow); - w.push_str(username); - w.push_str(colors.red); - w.push_byte(b'@'); - w.push_str(colors.green); - w.push_cstr(hostname); - w.push_str(colors.reset); + writer.push_str(colors.yellow); + writer.push_str(username); + writer.push_str(colors.red); + writer.push_byte(b'@'); + writer.push_str(colors.green); + writer.push_cstr(hostname); + writer.push_str(colors.reset); } #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_shell(w: &mut StackWriter) { +pub fn write_shell(writer: &mut StackWriter) { let shell = crate::getenv_str("SHELL").unwrap_or(""); if shell.is_empty() { - w.push_str("unknown_shell"); + writer.push_str("unknown_shell"); } else { - let start = shell.rfind('/').map_or(0, |i| i + 1); - w.push_str(&shell[start..]); + let start = shell.rfind('/').map_or(0, |pos| pos + 1); + writer.push_str(&shell[start..]); } } /// Writes the root disk usage, or nothing if the filesystem information cannot /// be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_root_disk_usage(w: &mut StackWriter, colors: &Colors) { +pub fn write_root_disk_usage(writer: &mut StackWriter, colors: &Colors) { let mut vfs = MaybeUninit::::uninit(); let path = b"/\0"; @@ -64,41 +64,41 @@ pub fn write_root_disk_usage(w: &mut StackWriter, colors: &Colors) { let total_bytes = block_size * total_blocks; let used_bytes = total_bytes - (block_size * available_blocks); - write_gib(w, used_bytes); - w.push_str(" GiB / "); - write_gib(w, total_bytes); - w.push_str(" GiB ("); - w.push_str(colors.cyan); + write_gib(writer, used_bytes); + writer.push_str(" GiB / "); + write_gib(writer, total_bytes); + writer.push_str(" GiB ("); + writer.push_str(colors.cyan); let pct = (used_bytes * 100).checked_div(total_bytes).unwrap_or(0); - w.push_u64(pct); - w.push_byte(b'%'); - w.push_str(colors.reset); - w.push_byte(b')'); + writer.push_u64(pct); + writer.push_byte(b'%'); + writer.push_str(colors.reset); + writer.push_byte(b')'); } -fn write_centi_gib(w: &mut StackWriter, centi_gib: u64) { - w.push_u64(centi_gib / 100); - w.push_byte(b'.'); +fn write_centi_gib(writer: &mut StackWriter, centi_gib: u64) { + writer.push_u64(centi_gib / 100); + writer.push_byte(b'.'); let frac = (centi_gib % 100) as u8; - w.push_byte(b'0' + frac / 10); - w.push_byte(b'0' + frac % 10); + writer.push_byte(b'0' + frac / 10); + writer.push_byte(b'0' + frac % 10); } -fn write_gib(w: &mut StackWriter, bytes: u64) { - write_centi_gib(w, (bytes * 100 + (1 << 29)) >> 30); +fn write_gib(writer: &mut StackWriter, bytes: u64) { + write_centi_gib(writer, (bytes * 100 + (1 << 29)) >> 30); } #[cfg(target_os = "linux")] -fn write_kb_as_gib(w: &mut StackWriter, kb: u64) { - write_centi_gib(w, (kb * 100 + (1 << 19)) >> 20); +fn write_kb_as_gib(writer: &mut StackWriter, kb: u64) { + write_centi_gib(writer, (kb * 100 + (1 << 19)) >> 20); } /// Fast integer parsing without stdlib overhead #[cfg(target_os = "linux")] #[inline] -fn parse_u64_fast(s: &[u8]) -> u64 { +fn parse_u64_fast(bytes: &[u8]) -> u64 { let mut result = 0u64; - for &byte in s { + for &byte in bytes { if byte.is_ascii_digit() { result = result * 10 + u64::from(byte - b'0'); } else { @@ -112,7 +112,7 @@ fn parse_u64_fast(s: &[u8]) -> u64 { /// Writes nothing if the memory statistics cannot be retrieved. #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { +pub fn write_memory_usage(writer: &mut StackWriter, colors: &Colors) { let Some((used_bytes, total_bytes)) = crate::syscall::macos_meminfo() else { return; }; @@ -120,22 +120,22 @@ pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { .checked_div(total_bytes) .unwrap_or(0); - write_gib(w, used_bytes); - w.push_str(" GiB / "); - write_gib(w, total_bytes); - w.push_str(" GiB ("); - w.push_str(colors.cyan); - w.push_u64(percentage_used); - w.push_byte(b'%'); - w.push_str(colors.reset); - w.push_byte(b')'); + write_gib(writer, used_bytes); + writer.push_str(" GiB / "); + write_gib(writer, total_bytes); + writer.push_str(" GiB ("); + writer.push_str(colors.cyan); + writer.push_u64(percentage_used); + writer.push_byte(b'%'); + writer.push_str(colors.reset); + writer.push_byte(b')'); } /// Gets the system memory usage information. /// Writes nothing if `/proc/meminfo` cannot be read. #[cfg(target_os = "linux")] #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { +pub fn write_memory_usage(writer: &mut StackWriter, colors: &Colors) { #[cfg_attr(feature = "hotpath", hotpath::measure)] fn parse_memory_info() -> Option<(u64, u64)> { let mut total_memory_kb = 0u64; @@ -157,7 +157,7 @@ pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { // Find newline or end let line_end = remaining .iter() - .position(|&b| b == b'\n') + .position(|&byte| byte == b'\n') .unwrap_or(remaining.len()); let line = &remaining[..line_end]; @@ -192,13 +192,13 @@ pub fn write_memory_usage(w: &mut StackWriter, colors: &Colors) { .checked_div(total_kb) .unwrap_or(0); - write_kb_as_gib(w, used_kb); - w.push_str(" GiB / "); - write_kb_as_gib(w, total_kb); - w.push_str(" GiB ("); - w.push_str(colors.cyan); - w.push_u64(percentage_used); - w.push_byte(b'%'); - w.push_str(colors.reset); - w.push_byte(b')'); + write_kb_as_gib(writer, used_kb); + writer.push_str(" GiB / "); + write_kb_as_gib(writer, total_kb); + writer.push_str(" GiB ("); + writer.push_str(colors.cyan); + writer.push_u64(percentage_used); + writer.push_byte(b'%'); + writer.push_str(colors.reset); + writer.push_byte(b')'); } diff --git a/crates/lib/src/uptime.rs b/crates/lib/src/uptime.rs index a3299fd..4ad18d7 100644 --- a/crates/lib/src/uptime.rs +++ b/crates/lib/src/uptime.rs @@ -5,7 +5,7 @@ use crate::StackWriter; /// Writes the current system uptime, or nothing if it cannot be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_uptime(w: &mut StackWriter) { +pub fn write_uptime(writer: &mut StackWriter) { #[cfg(target_os = "linux")] let uptime_seconds = { let mut info = MaybeUninit::uninit(); @@ -29,26 +29,26 @@ pub fn write_uptime(w: &mut StackWriter) { let mut any = days > 0; if any { - w.push_u64(days); - w.push_str(if days == 1 { " day" } else { " days" }); + writer.push_u64(days); + writer.push_str(if days == 1 { " day" } else { " days" }); } if hours > 0 { if any { - w.push_str(", "); + writer.push_str(", "); } - w.push_u64(hours); - w.push_str(if hours == 1 { " hour" } else { " hours" }); + writer.push_u64(hours); + writer.push_str(if hours == 1 { " hour" } else { " hours" }); any = true; } if minutes > 0 { if any { - w.push_str(", "); + writer.push_str(", "); } - w.push_u64(minutes); - w.push_str(if minutes == 1 { " minute" } else { " minutes" }); + writer.push_u64(minutes); + writer.push_str(if minutes == 1 { " minute" } else { " minutes" }); any = true; } if !any { - w.push_str("less than a minute"); + writer.push_str("less than a minute"); } } From ad5d810a593465b534a3f8ac2c44ad9fb43879aa Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 02:22:38 -0400 Subject: [PATCH 10/15] treewide: enable the clippy restriction group --- Cargo.toml | 59 ++++++---- crates/asm/src/aarch64.rs | 20 ++-- crates/asm/src/arm.rs | 18 +-- crates/asm/src/darwin.rs | 48 ++++---- crates/asm/src/lib.rs | 119 ++++++++++---------- crates/asm/src/loongarch64.rs | 20 ++-- crates/asm/src/mips.rs | 18 +-- crates/asm/src/mips64.rs | 18 +-- crates/asm/src/powerpc.rs | 16 +-- crates/asm/src/powerpc64.rs | 16 +-- crates/asm/src/riscv32.rs | 20 ++-- crates/asm/src/riscv64.rs | 20 ++-- crates/asm/src/s390x.rs | 18 +-- crates/asm/src/sparc.rs | 18 +-- crates/asm/src/sparc64.rs | 18 +-- crates/asm/src/x86.rs | 18 +-- crates/asm/src/x86_64.rs | 18 +-- crates/benchmarks/benches/microfetch.rs | 6 +- crates/lib/build.rs | 7 +- crates/lib/src/colors.rs | 4 +- crates/lib/src/cpu.rs | 143 ++++++++++-------------- crates/lib/src/desktop.rs | 12 +- crates/lib/src/lib.rs | 67 +++++------ crates/lib/src/release.rs | 12 +- crates/lib/src/system.rs | 55 ++++----- crates/lib/src/uptime.rs | 9 +- microfetch/build.rs | 13 +-- microfetch/src/main.rs | 14 +-- 28 files changed, 391 insertions(+), 433 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 63a2184..a9f824e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,26 +15,45 @@ microfetch-lib = { path = "./crates/lib", version = "1.2.0" } criterion = { default-features = false, features = [ "cargo_bench_support" ], version = "0.8.2" } [workspace.lints.clippy] -complexity = { level = "warn", priority = -1 } -nursery = { level = "warn", priority = -1 } -pedantic = { level = "warn", priority = -1 } -perf = { level = "warn", priority = -1 } -style = { level = "warn", priority = -1 } - -absolute_paths = "allow" -arbitrary_source_item_ordering = "allow" -implicit_return = "allow" -missing_docs_in_private_items = "allow" -non_ascii_literal = "allow" -pattern_type_mismatch = "allow" -print_stdout = "allow" -question_mark_used = "allow" -similar_names = "allow" -single_call_fn = "allow" -std_instead_of_core = "allow" -too_long_first_doc_paragraph = "allow" -too_many_lines = "allow" -unused_trait_names = "allow" +complexity = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +pedantic = { level = "warn", priority = -1 } +perf = { level = "warn", priority = -1 } +restriction = { level = "warn", priority = -1 } +style = { level = "warn", priority = -1 } + +absolute_paths = "allow" +allow_attributes = "allow" +arbitrary_source_item_ordering = "allow" +arithmetic_side_effects = "allow" +blanket_clippy_restriction_lints = "allow" +cfg_not_test = "allow" +exhaustive_enums = "allow" +exhaustive_structs = "allow" +implicit_return = "allow" +indexing_slicing = "allow" +inline_asm_x86_intel_syntax = "allow" +inline_modules = "allow" +integer_division = "allow" +integer_division_remainder_used = "allow" +missing_docs_in_private_items = "allow" +missing_inline_in_public_items = "allow" +multiple_unsafe_ops_per_block = "allow" +non_ascii_literal = "allow" +pattern_type_mismatch = "allow" +print_stdout = "allow" +pub_with_shorthand = "allow" +question_mark_used = "allow" +semicolon_inside_block = "allow" +separated_literal_suffix = "allow" +similar_names = "allow" +single_call_fn = "allow" +std_instead_of_core = "allow" +tests_outside_test_module = "allow" +too_long_first_doc_paragraph = "allow" +too_many_lines = "allow" +undocumented_unsafe_blocks = "allow" +unused_trait_names = "allow" [profile.dev] # nix's compiler_builtins carries compiler-rt objects that need libc, and only diff --git a/crates/asm/src/aarch64.rs b/crates/asm/src/aarch64.rs index efc79a1..222db47 100644 --- a/crates/asm/src/aarch64.rs +++ b/crates/asm/src/aarch64.rs @@ -7,11 +7,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("x8") 56i64, // SYS_openat - in("x0") -100i32, // AT_FDCWD + in("x8") 56_i64, // SYS_openat + in("x0") -100_i32, // AT_FDCWD in("x1") path, in("x2") flags, - in("x3") 0i32, // mode + in("x3") 0_i32, // mode lateout("x0") ret, options(nostack) ); @@ -24,7 +24,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "svc #0", - in("x8") 63i64, // SYS_read + in("x8") 63_i64, // SYS_read in("x0") fd, in("x1") buf, in("x2") count, @@ -41,7 +41,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "svc #0", - in("x8") 64i64, // SYS_write + in("x8") 64_i64, // SYS_write in("x0") fd, in("x1") buf, in("x2") count, @@ -58,7 +58,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("x8") 57i64, // SYS_close + in("x8") 57_i64, // SYS_close in("x0") fd, lateout("x0") ret, options(nostack) @@ -72,7 +72,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("x8") 160i64, // SYS_uname + in("x8") 160_i64, // SYS_uname in("x0") buf, lateout("x0") ret, options(nostack) @@ -86,7 +86,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("x8") 43i64, // SYS_statfs + in("x8") 43_i64, // SYS_statfs in("x0") path, in("x1") buf, lateout("x0") ret, @@ -120,7 +120,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "svc #0", - in("x8") 123i64, // __NR_sched_getaffinity + in("x8") 123_i64, // __NR_sched_getaffinity in("x0") pid, in("x1") mask_size, in("x2") mask, @@ -135,7 +135,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "svc #0", - in("x8") 93i64, // SYS_exit + in("x8") 93_i64, // SYS_exit in("x0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/arm.rs b/crates/asm/src/arm.rs index b3fd4ba..7ee48f6 100644 --- a/crates/asm/src/arm.rs +++ b/crates/asm/src/arm.rs @@ -7,10 +7,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("r7") 5i32, // SYS_open + in("r7") 5_i32, // SYS_open in("r0") path, in("r1") flags, - in("r2") 0i32, // mode + in("r2") 0_i32, // mode lateout("r0") ret, options(nostack) ); @@ -23,7 +23,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "svc #0", - in("r7") 3i32, // SYS_read + in("r7") 3_i32, // SYS_read in("r0") fd, in("r1") buf, in("r2") count, @@ -39,7 +39,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "svc #0", - in("r7") 4i32, // SYS_write + in("r7") 4_i32, // SYS_write in("r0") fd, in("r1") buf, in("r2") count, @@ -55,7 +55,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("r7") 6i32, // SYS_close + in("r7") 6_i32, // SYS_close in("r0") fd, lateout("r0") ret, options(nostack) @@ -69,7 +69,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("r7") 122i32, // SYS_newuname + in("r7") 122_i32, // SYS_newuname in("r0") buf, lateout("r0") ret, options(nostack) @@ -83,7 +83,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "svc #0", - in("r7") 266i32, // SYS_statfs64 + in("r7") 266_i32, // SYS_statfs64 in("r0") path, in("r1") core::mem::size_of::(), in("r2") buf, @@ -117,7 +117,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "svc #0", - in("r7") 242i32, // __NR_sched_getaffinity + in("r7") 242_i32, // __NR_sched_getaffinity in("r0") pid, in("r1") mask_size, in("r2") mask, @@ -132,7 +132,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "svc #0", - in("r7") 1i32, // SYS_exit + in("r7") 1_i32, // SYS_exit in("r0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/darwin.rs b/crates/asm/src/darwin.rs index 3c0c97d..03c70b5 100644 --- a/crates/asm/src/darwin.rs +++ b/crates/asm/src/darwin.rs @@ -59,27 +59,27 @@ unsafe extern "C" { ) -> c_int; } -pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { +pub(crate) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { open(path.cast::(), flags) } } -pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { +pub(crate) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { read(fd, buf.cast::(), count) } } -pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { +pub(crate) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { write(fd, buf.cast::(), count) } } -pub unsafe fn sys_close(fd: i32) -> i32 { +pub(crate) unsafe fn sys_close(fd: i32) -> i32 { unsafe { close(fd) } } -pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { +pub(crate) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { uname(buf) } } -pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { +pub(crate) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { statfs(path.cast::(), buf) } } @@ -89,7 +89,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { clippy::missing_const_for_fn, reason = "keeps the signature of the syscall it stands in for" )] -pub unsafe fn sys_sysinfo(_info: *mut SysInfo) -> i64 { +pub(crate) unsafe fn sys_sysinfo(_info: *mut SysInfo) -> i64 { -1 } @@ -100,7 +100,7 @@ pub unsafe fn sys_sysinfo(_info: *mut SysInfo) -> i64 { clippy::missing_const_for_fn, reason = "keeps the signature of the syscall it stands in for" )] -pub unsafe fn sys_sched_getaffinity( +pub(crate) unsafe fn sys_sched_getaffinity( _pid: i32, _mask_size: usize, _mask: *mut u8, @@ -108,7 +108,7 @@ pub unsafe fn sys_sched_getaffinity( -1 } -pub unsafe fn sys_exit(code: i32) -> ! { +pub(crate) unsafe fn sys_exit(code: i32) -> ! { unsafe { _exit(code) } } @@ -116,7 +116,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { /// NUL-terminated byte string (e.g. `b"machdep.cpu.brand_string\0"`). /// /// Returns the number of bytes written, excluding the trailing NUL. -#[must_use] +#[must_use = "the length says how much of `out` was filled"] pub fn macos_sysctl_str(name: &[u8], out: &mut [u8]) -> Option { let mut len = out.len(); let ret = unsafe { @@ -128,7 +128,7 @@ pub fn macos_sysctl_str(name: &[u8], out: &mut [u8]) -> Option { 0, ) }; - if ret != 0 { + if ret != 0_i32 { return None; } // `len` includes the terminating NUL on success. @@ -136,7 +136,7 @@ pub fn macos_sysctl_str(name: &[u8], out: &mut [u8]) -> Option { } /// Read a 32-bit integer sysctl by name (e.g. `b"hw.logicalcpu\0"`). -#[must_use] +#[must_use = "this only queries the kernel"] pub fn macos_sysctl_u32(name: &[u8]) -> Option { let mut val: u32 = 0; let mut len = size_of::(); @@ -149,11 +149,7 @@ pub fn macos_sysctl_u32(name: &[u8]) -> Option { 0, ) }; - if ret == 0 && len == size_of::() { - Some(val) - } else { - None - } + (ret == 0_i32 && len == size_of::()).then_some(val) } /// Read a 64-bit integer sysctl by name (e.g. `b"hw.memsize\0"`). @@ -169,11 +165,7 @@ fn macos_sysctl_u64(name: &[u8]) -> Option { 0, ) }; - if ret == 0 && len == size_of::() { - Some(val) - } else { - None - } + (ret == 0_i32 && len == size_of::()).then_some(val) } const HOST_VM_INFO64: c_int = 4; @@ -217,11 +209,11 @@ struct VmStatistics64 { /// Used" as `(active + wired + compressed) * page_size`; inactive and free /// pages are treated as available. This is an approximation and the exact /// formula can be tuned against real hardware. -#[must_use] +#[must_use = "this only queries the kernel"] pub fn macos_meminfo() -> Option<(u64, u64)> { let total = macos_sysctl_u64(b"hw.memsize\0")?; // Apple Silicon uses 16 KiB pages; fall back to that if the sysctl is absent. - let page = u64::from(macos_sysctl_u32(b"hw.pagesize\0").unwrap_or(16384)); + let page = u64::from(macos_sysctl_u32(b"hw.pagesize\0").unwrap_or(0x4000)); let mut vm_stats = VmStatistics64::default(); let mut count = @@ -234,7 +226,7 @@ pub fn macos_meminfo() -> Option<(u64, u64)> { &raw mut count, ) }; - if ret != 0 { + if ret != 0_i32 { // Mach call failed; report total with unknown usage rather than erroring. return Some((0, total)); } @@ -260,7 +252,7 @@ const CTL_KERN: c_int = 1; const KERN_BOOTTIME: c_int = 21; /// Returns the system uptime in seconds (`now - kern.boottime`). -#[must_use] +#[must_use = "this only queries the kernel"] pub fn macos_uptime_secs() -> Option { let mib = [CTL_KERN, KERN_BOOTTIME]; let mut boot = Timeval::default(); @@ -275,12 +267,12 @@ pub fn macos_uptime_secs() -> Option { 0, ) }; - if ret != 0 { + if ret != 0_i32 { return None; } let mut now = Timeval::default(); - if unsafe { gettimeofday(&raw mut now, ptr::null_mut()) } != 0 { + if unsafe { gettimeofday(&raw mut now, ptr::null_mut()) } != 0_i32 { return None; } diff --git a/crates/asm/src/lib.rs b/crates/asm/src/lib.rs index 1c65543..8009cc3 100644 --- a/crates/asm/src/lib.rs +++ b/crates/asm/src/lib.rs @@ -20,13 +20,14 @@ feature(asm_experimental_arch) )] -#[cfg(not(target_os = "macos"))] use core::ffi::c_void; +#[cfg(not(target_os = "macos"))] +use core::ffi::{c_char, c_void}; // Per-arch syscall implementations live in their own module files. // macOS is matched first; there `target_arch` is `aarch64`, but the // implementation is libSystem-backed rather than raw `svc` traps. core::cfg_select! { - all(target_os = "macos", target_arch = "aarch64") => { #[path = "darwin.rs" ] mod arch; } + all(target_os = "macos", target_arch = "aarch64") => { pub mod darwin; use darwin as arch; } target_os = "macos" => { compile_error!("microfetch on macOS supports aarch64 (Apple Silicon) only"); } target_arch = "x86_64" => { #[path = "x86_64.rs" ] mod arch; } target_arch = "aarch64" => { #[path = "aarch64.rs" ] mod arch; } @@ -45,15 +46,6 @@ core::cfg_select! { _ => { compile_error!("Unsupported architecture"); } } -/// macOS-only helpers backed by `sysctl`/Mach (see `darwin.rs`). -#[cfg(target_os = "macos")] -pub use arch::{ - macos_meminfo, - macos_sysctl_str, - macos_sysctl_u32, - macos_uptime_secs, -}; - #[cfg(not(target_os = "macos"))] const WORD: usize = size_of::(); @@ -81,7 +73,10 @@ const UNALIGNED_WORDS: bool = cfg!(any( // clash at link time, so the freestanding implementations are Linux-only. #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] -#[allow(clippy::cast_ptr_alignment)] +#[expect( + clippy::cast_ptr_alignment, + reason = "word accesses are either unaligned or follow an alignment prologue" +)] pub unsafe extern "C" fn memcpy( dest: *mut c_void, src: *const c_void, @@ -97,7 +92,8 @@ pub unsafe extern "C" fn memcpy( dest_bytes.add(offset).cast::().write_unaligned(word); offset += WORD; } - } else if dest_bytes.addr() % WORD == src_bytes.addr() % WORD { + } + if !UNALIGNED_WORDS && dest_bytes.addr() % WORD == src_bytes.addr() % WORD { while offset < len && !dest_bytes.add(offset).addr().is_multiple_of(WORD) { *dest_bytes.add(offset) = *src_bytes.add(offset); @@ -125,18 +121,21 @@ pub unsafe extern "C" fn memcpy( /// The value in `fill` is treated as unsigned (lower 8 bits used). #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] -#[allow(clippy::cast_ptr_alignment)] +#[expect( + clippy::cast_ptr_alignment, + reason = "word accesses are either unaligned or follow an alignment prologue" +)] pub unsafe extern "C" fn memset( dest: *mut c_void, fill: i32, len: usize, ) -> *mut c_void { let bytes = dest.cast::(); - let value = fill.to_le_bytes()[0]; + let value = u8::try_from(fill & 0xFF_i32).unwrap_or(0); let mut offset = 0; unsafe { if UNALIGNED_WORDS { - let word = usize::from_ne_bytes([value; WORD]); + let word = usize::MAX / 0xFF * usize::from(value); while len - offset >= WORD { bytes.add(offset).cast::().write_unaligned(word); offset += WORD; @@ -146,7 +145,7 @@ pub unsafe extern "C" fn memset( *bytes.add(offset) = value; offset += 1; } - let word = usize::from_ne_bytes([value; WORD]); + let word = usize::MAX / 0xFF * usize::from(value); while len - offset >= WORD { *bytes.add(offset).cast::() = word; offset += WORD; @@ -206,7 +205,7 @@ pub unsafe extern "C" fn memcmp( /// `cstr` must be a valid pointer to a null-terminated string. #[cfg(not(target_os = "macos"))] #[unsafe(no_mangle)] -pub const unsafe extern "C" fn strlen(cstr: *const i8) -> usize { +pub const unsafe extern "C" fn strlen(cstr: *const c_char) -> usize { let mut len = 0; while unsafe { *cstr.add(len) } != 0 { len += 1; @@ -255,7 +254,7 @@ pub unsafe extern "C" fn entry_rust(stack: *const usize) -> i32 { let argc = unsafe { *stack }; let argv = unsafe { stack.add(1).cast::<*const u8>() }; - // SAFETY: argc is unlikely to exceed i32::MAX on real systems + // argc is unlikely to exceed i32::MAX on real systems let argc_i32 = i32::try_from(argc).unwrap_or(i32::MAX); // Call the main function (defined by the binary crate) @@ -270,11 +269,11 @@ unsafe extern "C" { fn main(argc: i32, argv: *const *const u8) -> i32; } -/// Direct syscall to open a file +/// Direct syscall to open a file. /// /// # Returns /// -/// File descriptor or -1 on error +/// File descriptor or -1 on error. /// /// # Safety /// @@ -283,16 +282,16 @@ unsafe extern "C" { /// - `path` points to a valid null-terminated C string /// - The pointer remains valid for the duration of the syscall #[inline] -#[must_use] +#[must_use = "the descriptor must be checked and closed"] pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { arch::sys_open(path, flags) } } -/// Direct syscall to read from a file descriptor +/// Direct syscall to read from a file descriptor. /// /// # Returns /// -/// Number of bytes read or -1 on error +/// Number of bytes read or -1 on error. /// /// # Safety /// @@ -305,11 +304,11 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { arch::sys_read(fd, buf, count) } } -/// Direct syscall to write to a file descriptor +/// Direct syscall to write to a file descriptor. /// /// # Returns /// -/// Number of bytes written or -1 on error +/// Number of bytes written or -1 on error. /// /// # Safety /// @@ -318,18 +317,18 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { /// - `buf` points to a valid readable buffer of at least `count` bytes /// - `fd` is a valid open file descriptor #[inline] -#[must_use] +#[must_use = "a short or failed write goes unnoticed otherwise"] pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { arch::sys_write(fd, buf, count) } } -/// Direct syscall to close a file descriptor +/// Direct syscall to close a file descriptor. /// /// # Safety /// -/// The caller must ensure that `fd` is a valid open file descriptor +/// The caller must ensure that `fd` is a valid open file descriptor. #[inline] -#[must_use] +#[must_use = "close can report a deferred I/O error"] pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { arch::sys_close(fd) } } @@ -340,7 +339,6 @@ pub unsafe fn sys_close(fd: i32) -> i32 { /// machine. The `domainname` field (GNU extension, `[i8; 65]`) follows but is /// not used, nor any useful to us here. #[repr(C)] -#[allow(dead_code)] #[cfg(not(target_os = "macos"))] pub struct UtsNameBuf { pub sysname: [i8; 65], @@ -364,17 +362,16 @@ pub struct UtsNameBuf { pub machine: [i8; 256], } -/// Direct `uname(2)` syscall +/// Direct `uname(2)` syscall. /// /// # Returns /// -/// 0 on success, negative on error +/// 0 on success, negative on error. /// /// # Safety /// /// The caller must ensure that `buf` points to a valid `UtsNameBuf`. #[inline] -#[allow(dead_code)] pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { arch::sys_uname(buf) } } @@ -459,7 +456,7 @@ pub struct StatfsBuf { } /// on armv7 `statfs64(2)` has 32-bit word fields; see -/// https://github.com/torvalds/linux/blob/v6.19/include/uapi/asm-generic/statfs.h +/// . #[repr(C)] #[cfg(any( target_arch = "arm", @@ -486,14 +483,14 @@ pub struct StatfsBuf { } /// mips (O32) uses `compat_statfs64`, same reordering with 32-bit words; see -/// https://github.com/torvalds/linux/blob/v6.19/arch/mips/include/uapi/asm/statfs.h +/// . #[repr(C)] #[cfg(target_arch = "mips")] pub struct StatfsBuf { pub f_type: u32, pub f_bsize: u32, pub f_frsize: u32, - _pad: u32, + pub pad: u32, pub f_blocks: u64, pub f_bfree: u64, pub f_files: u64, @@ -508,7 +505,7 @@ pub struct StatfsBuf { } /// mips reorders fields; see -/// https://github.com/torvalds/linux/blob/v6.19/arch/mips/include/uapi/asm/statfs.h +/// . #[repr(C)] #[cfg(target_arch = "mips64")] pub struct StatfsBuf { @@ -528,11 +525,11 @@ pub struct StatfsBuf { pub _pad: [i64; 5], } -/// Direct `statfs(2)` syscall +/// Direct `statfs(2)` syscall. /// /// # Returns /// -/// 0 on success, negative errno on error +/// 0 on success, negative errno on error. /// /// # Safety /// @@ -563,7 +560,7 @@ pub fn read_file_fast(path: &str, buffer: &mut [u8]) -> Result { return Err(-22); // EINVAL } - let mut path_buf = [0u8; 256]; + let mut path_buf = [0_u8; 256]; path_buf[..path_bytes.len()].copy_from_slice(path_bytes); // XXX: Already zero-terminated since array is initialized to zeros @@ -574,10 +571,12 @@ pub fn read_file_fast(path: &str, buffer: &mut [u8]) -> Result { } let bytes_read = sys_read(fd, buffer.as_mut_ptr(), buffer.len()); - let _ = sys_close(fd); + _ = sys_close(fd); - usize::try_from(bytes_read) - .map_err(|_| i32::try_from(bytes_read).unwrap_or(i32::MIN)) + let Ok(len) = usize::try_from(bytes_read) else { + return Err(i32::try_from(bytes_read).unwrap_or(i32::MIN)); + }; + Ok(len) } } @@ -608,8 +607,8 @@ pub struct SysInfo { pub totalswap: u64, pub freeswap: u64, pub procs: u16, - _pad: u16, - _pad2: u32, /* alignment padding to reach 8-byte boundary for + pub pad: u16, + pub pad2: u32, /* alignment padding to reach 8-byte boundary for * totalhigh */ pub totalhigh: u64, pub freehigh: u64, @@ -619,7 +618,7 @@ pub struct SysInfo { } /// on armv7 `__kernel_long_t` is 4 bytes; see -/// https://github.com/torvalds/linux/blob/v6.19/include/uapi/linux/sysinfo.h +/// . #[repr(C)] #[cfg(any( target_arch = "arm", @@ -639,7 +638,7 @@ pub struct SysInfo { pub totalswap: u32, pub freeswap: u32, pub procs: u16, - _pad: u16, + pub pad: u16, pub totalhigh: u32, pub freehigh: u32, pub mem_unit: u32, @@ -647,11 +646,11 @@ pub struct SysInfo { pub _f: [u8; 8], } -/// Direct `sysinfo(2)` syscall +/// Direct `sysinfo(2)` syscall. /// /// # Returns /// -/// 0 on success, negative errno on error +/// 0 on success, negative errno on error. /// /// # Safety /// @@ -661,7 +660,7 @@ pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { arch::sys_sysinfo(info) } } -/// Direct `sched_getaffinity(2)` syscall +/// Direct `sched_getaffinity(2)` syscall. /// /// # Returns /// @@ -681,7 +680,7 @@ pub unsafe fn sys_sched_getaffinity( unsafe { arch::sys_sched_getaffinity(pid, mask_size, mask) } } -/// Direct syscall to exit the process +/// Direct syscall to exit the process. /// /// # Safety /// @@ -699,25 +698,21 @@ mod tests { #[test] fn runtime_memory_symbols_match_c_semantics() { - let src = [1u8, 2, 3, 4]; - let mut dest = [0u8; 4]; + let src = [1_u8, 2, 3, 4]; + let mut dest = [0_u8; 4]; - unsafe { - memcpy(dest.as_mut_ptr().cast(), src.as_ptr().cast(), src.len()); - } + unsafe { memcpy(dest.as_mut_ptr().cast(), src.as_ptr().cast(), src.len()) }; assert_eq!(dest, src); assert_eq!( unsafe { memcmp(dest.as_ptr().cast(), src.as_ptr().cast(), 4) }, - 0 + 0_i32 ); - unsafe { - memset(dest.as_mut_ptr().cast(), -1, dest.len()); - } + unsafe { memset(dest.as_mut_ptr().cast(), -1, dest.len()) }; assert_eq!(dest, [u8::MAX; 4]); assert_ne!( unsafe { bcmp(dest.as_ptr().cast(), src.as_ptr().cast(), 4) }, - 0 + 0_i32 ); } diff --git a/crates/asm/src/loongarch64.rs b/crates/asm/src/loongarch64.rs index df092c0..ef7e66d 100644 --- a/crates/asm/src/loongarch64.rs +++ b/crates/asm/src/loongarch64.rs @@ -7,11 +7,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "syscall 0", - in("$a7") 56i64, // SYS_openat - in("$a0") -100i32, // AT_FDCWD + in("$a7") 56_i64, // SYS_openat + in("$a0") -100_i32, // AT_FDCWD in("$a1") path, in("$a2") flags, - in("$a3") 0i32, // mode + in("$a3") 0_i32, // mode lateout("$a0") ret, options(nostack) ); @@ -24,7 +24,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "syscall 0", - in("$a7") 63i64, // SYS_read + in("$a7") 63_i64, // SYS_read in("$a0") fd, in("$a1") buf, in("$a2") count, @@ -40,7 +40,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "syscall 0", - in("$a7") 64i64, // SYS_write + in("$a7") 64_i64, // SYS_write in("$a0") fd, in("$a1") buf, in("$a2") count, @@ -56,7 +56,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "syscall 0", - in("$a7") 57i64, // SYS_close + in("$a7") 57_i64, // SYS_close in("$a0") fd, lateout("$a0") ret, options(nostack) @@ -70,7 +70,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "syscall 0", - in("$a7") 160i64, // SYS_uname + in("$a7") 160_i64, // SYS_uname in("$a0") buf, lateout("$a0") ret, options(nostack) @@ -84,7 +84,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "syscall 0", - in("$a7") 43i64, // SYS_statfs + in("$a7") 43_i64, // SYS_statfs in("$a0") path, in("$a1") buf, lateout("$a0") ret, @@ -117,7 +117,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "syscall 0", - in("$a7") 123i64, // __NR_sched_getaffinity + in("$a7") 123_i64, // __NR_sched_getaffinity in("$a0") pid, in("$a1") mask_size, in("$a2") mask, @@ -132,7 +132,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall 0", - in("$a7") 93i64, // SYS_exit + in("$a7") 93_i64, // SYS_exit in("$a0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/mips.rs b/crates/asm/src/mips.rs index d83c9c2..a7f1188 100644 --- a/crates/asm/src/mips.rs +++ b/crates/asm/src/mips.rs @@ -11,10 +11,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 5 => ret, // SYS_open + inlateout("$2") 4000_i32 + 5 => ret, // SYS_open in("$4") path, in("$5") flags, - in("$6") 0i32, // mode + in("$6") 0_i32, // mode lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, @@ -34,7 +34,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 3 => ret, // SYS_read + inlateout("$2") 4000_i32 + 3 => ret, // SYS_read in("$4") fd, in("$5") buf, in("$6") count, @@ -57,7 +57,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 4 => ret, // SYS_write + inlateout("$2") 4000_i32 + 4 => ret, // SYS_write in("$4") fd, in("$5") buf, in("$6") count, @@ -80,7 +80,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 6 => ret, // SYS_close + inlateout("$2") 4000_i32 + 6 => ret, // SYS_close in("$4") fd, lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, @@ -101,7 +101,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 122 => ret, // SYS_newuname + inlateout("$2") 4000_i32 + 122 => ret, // SYS_newuname in("$4") buf, lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, @@ -122,7 +122,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 255 => ret, // SYS_statfs64 + inlateout("$2") 4000_i32 + 255 => ret, // SYS_statfs64 in("$4") path, in("$5") core::mem::size_of::(), in("$6") buf, @@ -170,7 +170,7 @@ pub unsafe fn sys_sched_getaffinity( "nop", "subu $2, $0, $2", "1:", - inlateout("$2") 4000i32 + 240 => ret, // __NR_sched_getaffinity + inlateout("$2") 4000_i32 + 240 => ret, // __NR_sched_getaffinity in("$4") pid, in("$5") mask_size, in("$6") mask, @@ -188,7 +188,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall", - in("$2") 4000i32 + 1, // SYS_exit + in("$2") 4000_i32 + 1, // SYS_exit in("$4") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/mips64.rs b/crates/asm/src/mips64.rs index 82eb5b1..cfc3d52 100644 --- a/crates/asm/src/mips64.rs +++ b/crates/asm/src/mips64.rs @@ -11,11 +11,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "nop", "dsubu $2, $0, $2", "1:", - in("$2") 5000i64 + 2, // SYS_open + in("$2") 5000_i64 + 2, // SYS_open lateout("$2") ret, in("$4") path, in("$5") flags, - in("$6") 0i32, // mode + in("$6") 0_i32, // mode lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _, @@ -35,7 +35,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "nop", "dsubu $2, $0, $2", "1:", - in("$2") 5000i64 + 0, // SYS_read + in("$2") 5000_i64 + 0, // SYS_read lateout("$2") ret, in("$4") fd, in("$5") buf, @@ -59,7 +59,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "nop", "dsubu $2, $0, $2", "1:", - in("$2") 5000i64 + 1, // SYS_write + in("$2") 5000_i64 + 1, // SYS_write lateout("$2") ret, in("$4") fd, in("$5") buf, @@ -83,7 +83,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "nop", "dsubu $2, $0, $2", "1:", - in("$2") 5000i64 + 3, // SYS_close + in("$2") 5000_i64 + 3, // SYS_close lateout("$2") ret, in("$4") fd, lateout("$7") _, @@ -105,7 +105,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "nop", "dsubu $2, $0, $2", "1:", - in("$2") 5000i64 + 61, // SYS_newuname + in("$2") 5000_i64 + 61, // SYS_newuname lateout("$2") ret, in("$4") buf, lateout("$7") _, @@ -127,7 +127,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "nop", "dsubu $2, $0, $2", "1:", - in("$2") 5000i64 + 134, // SYS_statfs + in("$2") 5000_i64 + 134, // SYS_statfs lateout("$2") ret, in("$4") path, in("$5") buf, @@ -172,7 +172,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "syscall", - in("$2") 5000i64 + 196, // __NR_sched_getaffinity + in("$2") 5000_i64 + 196, // __NR_sched_getaffinity lateout("$2") ret, in("$4") pid, in("$5") mask_size, @@ -191,7 +191,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall", - in("$2") 5000i64 + 58, // SYS_exit + in("$2") 5000_i64 + 58, // SYS_exit in("$4") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/powerpc.rs b/crates/asm/src/powerpc.rs index ae354e1..91eb81f 100644 --- a/crates/asm/src/powerpc.rs +++ b/crates/asm/src/powerpc.rs @@ -10,10 +10,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 5i32 => _, // SYS_open + inlateout("r0") 5_i32 => _, // SYS_open inlateout("r3") path => ret, inlateout("r4") flags => _, - inlateout("r5") 0i32 => _, + inlateout("r5") 0_i32 => _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, out("cr0") _, @@ -31,7 +31,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 3i32 => _, // SYS_read + inlateout("r0") 3_i32 => _, // SYS_read inlateout("r3") fd => ret, inlateout("r4") buf => _, inlateout("r5") count => _, @@ -52,7 +52,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 4i32 => _, // SYS_write + inlateout("r0") 4_i32 => _, // SYS_write inlateout("r3") fd => ret, inlateout("r4") buf => _, inlateout("r5") count => _, @@ -73,7 +73,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 6i32 => _, // SYS_close + inlateout("r0") 6_i32 => _, // SYS_close inlateout("r3") fd => ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, @@ -92,7 +92,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 122i32 => _, // SYS_newuname + inlateout("r0") 122_i32 => _, // SYS_newuname inlateout("r3") buf => ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, @@ -111,7 +111,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 252i32 => _, // SYS_statfs64 + inlateout("r0") 252_i32 => _, // SYS_statfs64 inlateout("r3") path => ret, inlateout("r4") core::mem::size_of::() => _, inlateout("r5") buf => _, @@ -155,7 +155,7 @@ pub unsafe fn sys_sched_getaffinity( "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 223i32 => _, // __NR_sched_getaffinity + inlateout("r0") 223_i32 => _, // __NR_sched_getaffinity inlateout("r3") pid => ret, inlateout("r4") mask_size => _, inlateout("r5") mask => _, diff --git a/crates/asm/src/powerpc64.rs b/crates/asm/src/powerpc64.rs index 4a48ba0..ba82759 100644 --- a/crates/asm/src/powerpc64.rs +++ b/crates/asm/src/powerpc64.rs @@ -10,11 +10,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 5i64 => _, // SYS_open + inlateout("r0") 5_i64 => _, // SYS_open in("r3") path, lateout("r3") ret, inlateout("r4") flags => _, - inlateout("r5") 0i32 => _, // mode + inlateout("r5") 0_i32 => _, // mode out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, out("cr0") _, @@ -32,7 +32,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 3i64 => _, // SYS_read + inlateout("r0") 3_i64 => _, // SYS_read in("r3") i64::from(fd), lateout("r3") ret, inlateout("r4") buf => _, @@ -54,7 +54,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 4i64 => _, // SYS_write + inlateout("r0") 4_i64 => _, // SYS_write in("r3") i64::from(fd), lateout("r3") ret, inlateout("r4") buf => _, @@ -76,7 +76,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 6i64 => _, // SYS_close + inlateout("r0") 6_i64 => _, // SYS_close in("r3") i64::from(fd), lateout("r3") ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, @@ -96,7 +96,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 122i64 => _, // SYS_uname + inlateout("r0") 122_i64 => _, // SYS_uname in("r3") buf, lateout("r3") ret, out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _, @@ -116,7 +116,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 99i64 => _, // SYS_statfs + inlateout("r0") 99_i64 => _, // SYS_statfs in("r3") path, lateout("r3") ret, inlateout("r4") buf => _, @@ -161,7 +161,7 @@ pub unsafe fn sys_sched_getaffinity( "bns+ 2f", "neg 3, 3", "2:", - inlateout("r0") 223i64 => _, // __NR_sched_getaffinity + inlateout("r0") 223_i64 => _, // __NR_sched_getaffinity in("r3") i64::from(pid), lateout("r3") ret, inlateout("r4") mask_size => _, diff --git a/crates/asm/src/riscv32.rs b/crates/asm/src/riscv32.rs index a9daa4a..2756ba6 100644 --- a/crates/asm/src/riscv32.rs +++ b/crates/asm/src/riscv32.rs @@ -7,11 +7,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 56i32, // SYS_openat - in("a0") -100i32, // AT_FDCWD + in("a7") 56_i32, // SYS_openat + in("a0") -100_i32, // AT_FDCWD in("a1") path, in("a2") flags, - in("a3") 0i32, // mode + in("a3") 0_i32, // mode lateout("a0") ret, options(nostack) ); @@ -24,7 +24,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "ecall", - in("a7") 63i32, // SYS_read + in("a7") 63_i32, // SYS_read in("a0") fd, in("a1") buf, in("a2") count, @@ -40,7 +40,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "ecall", - in("a7") 64i32, // SYS_write + in("a7") 64_i32, // SYS_write in("a0") fd, in("a1") buf, in("a2") count, @@ -56,7 +56,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 57i32, // SYS_close + in("a7") 57_i32, // SYS_close in("a0") fd, lateout("a0") ret, options(nostack) @@ -70,7 +70,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 160i32, // SYS_uname + in("a7") 160_i32, // SYS_uname in("a0") buf, lateout("a0") ret, options(nostack) @@ -85,7 +85,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 43i32, // __NR_statfs + in("a7") 43_i32, // __NR_statfs in("a0") path, in("a1") core::mem::size_of::(), in("a2") buf, @@ -119,7 +119,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "ecall", - in("a7") 123i32, // __NR_sched_getaffinity + in("a7") 123_i32, // __NR_sched_getaffinity in("a0") pid, in("a1") mask_size, in("a2") mask, @@ -134,7 +134,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "ecall", - in("a7") 93i32, // SYS_exit + in("a7") 93_i32, // SYS_exit in("a0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/riscv64.rs b/crates/asm/src/riscv64.rs index 7653190..65ec607 100644 --- a/crates/asm/src/riscv64.rs +++ b/crates/asm/src/riscv64.rs @@ -7,11 +7,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 56i64, // SYS_openat - in("a0") -100i32, // AT_FDCWD + in("a7") 56_i64, // SYS_openat + in("a0") -100_i32, // AT_FDCWD in("a1") path, in("a2") flags, - in("a3") 0i32, // mode + in("a3") 0_i32, // mode lateout("a0") ret, options(nostack) ); @@ -25,7 +25,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "ecall", - in("a7") 63i64, // SYS_read + in("a7") 63_i64, // SYS_read in("a0") fd, in("a1") buf, in("a2") count, @@ -42,7 +42,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "ecall", - in("a7") 64i64, // SYS_write + in("a7") 64_i64, // SYS_write in("a0") fd, in("a1") buf, in("a2") count, @@ -59,7 +59,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 57i64, // SYS_close + in("a7") 57_i64, // SYS_close in("a0") fd, lateout("a0") ret, options(nostack) @@ -73,7 +73,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 160i64, // SYS_uname + in("a7") 160_i64, // SYS_uname in("a0") buf, lateout("a0") ret, options(nostack) @@ -88,7 +88,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "ecall", - in("a7") 43i64, // SYS_statfs + in("a7") 43_i64, // SYS_statfs in("a0") path, in("a1") buf, lateout("a0") ret, @@ -122,7 +122,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "ecall", - in("a7") 123i64, // __NR_sched_getaffinity + in("a7") 123_i64, // __NR_sched_getaffinity in("a0") pid, in("a1") mask_size, in("a2") mask, @@ -137,7 +137,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "ecall", - in("a7") 93i64, // SYS_exit + in("a7") 93_i64, // SYS_exit in("a0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/s390x.rs b/crates/asm/src/s390x.rs index 992f1d3..13b0ab2 100644 --- a/crates/asm/src/s390x.rs +++ b/crates/asm/src/s390x.rs @@ -7,10 +7,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "svc 0", - in("r1") 5i64, // SYS_open + in("r1") 5_i64, // SYS_open in("r2") path, in("r3") flags, - in("r4") 0i32, // mode + in("r4") 0_i32, // mode lateout("r2") ret, options(nostack) ); @@ -23,7 +23,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "svc 0", - in("r1") 3i64, // SYS_read + in("r1") 3_i64, // SYS_read in("r2") fd, in("r3") buf, in("r4") count, @@ -39,7 +39,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "svc 0", - in("r1") 4i64, // SYS_write + in("r1") 4_i64, // SYS_write in("r2") fd, in("r3") buf, in("r4") count, @@ -55,7 +55,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "svc 0", - in("r1") 6i64, // SYS_close + in("r1") 6_i64, // SYS_close in("r2") fd, lateout("r2") ret, options(nostack) @@ -69,7 +69,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "svc 0", - in("r1") 122i64, // SYS_uname + in("r1") 122_i64, // SYS_uname in("r2") buf, lateout("r2") ret, options(nostack) @@ -83,7 +83,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "svc 0", - in("r1") 99i64, // SYS_statfs + in("r1") 99_i64, // SYS_statfs in("r2") path, in("r3") buf, lateout("r2") ret, @@ -116,7 +116,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "svc 0", - in("r1") 240i64, // __NR_sched_getaffinity + in("r1") 240_i64, // __NR_sched_getaffinity in("r2") pid, in("r3") mask_size, in("r4") mask, @@ -131,7 +131,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "svc 0", - in("r1") 1i64, // SYS_exit + in("r1") 1_i64, // SYS_exit in("r2") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/sparc.rs b/crates/asm/src/sparc.rs index 59f075d..e4f6353 100644 --- a/crates/asm/src/sparc.rs +++ b/crates/asm/src/sparc.rs @@ -11,10 +11,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 5i32, // SYS_open + nr = in(reg) 5_i32, // SYS_open inlateout("o0") path => ret, in("o1") flags, - in("o2") 0i32, // mode + in("o2") 0_i32, // mode options(nostack) ); ret @@ -30,7 +30,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 3i32, // SYS_read + nr = in(reg) 3_i32, // SYS_read inlateout("o0") fd => ret, in("o1") buf, in("o2") count, @@ -49,7 +49,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 4i32, // SYS_write + nr = in(reg) 4_i32, // SYS_write inlateout("o0") fd => ret, in("o1") buf, in("o2") count, @@ -68,7 +68,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 6i32, // SYS_close + nr = in(reg) 6_i32, // SYS_close inlateout("o0") fd => ret, options(nostack) ); @@ -85,7 +85,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 189i32, // SYS_newuname + nr = in(reg) 189_i32, // SYS_newuname inlateout("o0") buf => ret, options(nostack) ); @@ -102,7 +102,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 234i32, // SYS_statfs64 + nr = in(reg) 234_i32, // SYS_statfs64 inlateout("o0") path => ret, in("o1") core::mem::size_of::(), in("o2") buf, @@ -142,7 +142,7 @@ pub unsafe fn sys_sched_getaffinity( "bcs,a 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 260i32, // __NR_sched_getaffinity + nr = in(reg) 260_i32, // __NR_sched_getaffinity inlateout("o0") pid => ret, in("o1") mask_size, in("o2") mask, @@ -157,7 +157,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { core::arch::asm!( "mov {nr}, %g1", "ta 0x10", - nr = in(reg) 1i32, // SYS_exit + nr = in(reg) 1_i32, // SYS_exit in("o0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/sparc64.rs b/crates/asm/src/sparc64.rs index fa33041..077680e 100644 --- a/crates/asm/src/sparc64.rs +++ b/crates/asm/src/sparc64.rs @@ -11,11 +11,11 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 5i64, // SYS_open + nr = in(reg) 5_i64, // SYS_open in("o0") path, lateout("o0") ret, in("o1") flags, - in("o2") 0i32, // mode + in("o2") 0_i32, // mode options(nostack) ); ret @@ -31,7 +31,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 3i64, // SYS_read + nr = in(reg) 3_i64, // SYS_read in("o0") i64::from(fd), lateout("o0") ret, in("o1") buf, @@ -51,7 +51,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 4i64, // SYS_write + nr = in(reg) 4_i64, // SYS_write in("o0") i64::from(fd), lateout("o0") ret, in("o1") buf, @@ -71,7 +71,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 6i64, // SYS_close + nr = in(reg) 6_i64, // SYS_close in("o0") i64::from(fd), lateout("o0") ret, options(nostack) @@ -89,7 +89,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 189i64, // SYS_newuname + nr = in(reg) 189_i64, // SYS_newuname in("o0") buf, lateout("o0") ret, options(nostack) @@ -107,7 +107,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 157i64, // SYS_statfs + nr = in(reg) 157_i64, // SYS_statfs in("o0") path, lateout("o0") ret, in("o1") buf, @@ -148,7 +148,7 @@ pub unsafe fn sys_sched_getaffinity( "bcs,a %xcc, 1f", "sub %g0, %o0, %o0", "1:", - nr = in(reg) 260i64, // __NR_sched_getaffinity + nr = in(reg) 260_i64, // __NR_sched_getaffinity in("o0") i64::from(pid), lateout("o0") ret, in("o1") mask_size, @@ -164,7 +164,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { core::arch::asm!( "mov {nr}, %g1", "t 0x6d", - nr = in(reg) 1i64, // SYS_exit + nr = in(reg) 1_i64, // SYS_exit in("o0") code, options(noreturn, nostack) ); diff --git a/crates/asm/src/x86.rs b/crates/asm/src/x86.rs index cb0aede..5f8e775 100644 --- a/crates/asm/src/x86.rs +++ b/crates/asm/src/x86.rs @@ -11,9 +11,9 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { "int 0x80", "pop ebx", arg1 = in(reg) path, - inlateout("eax") 5i32 => ret, // SYS_open + inlateout("eax") 5_i32 => ret, // SYS_open in("ecx") flags, - in("edx") 0i32, // mode + in("edx") 0_i32, // mode ); ret } @@ -28,7 +28,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { "int 0x80", "pop ebx", arg1 = in(reg) fd, - inlateout("eax") 3i32 => ret, // SYS_read + inlateout("eax") 3_i32 => ret, // SYS_read in("ecx") buf, in("edx") count, ); @@ -45,7 +45,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { "int 0x80", "pop ebx", arg1 = in(reg) fd, - inlateout("eax") 4i32 => ret, // SYS_write + inlateout("eax") 4_i32 => ret, // SYS_write in("ecx") buf, in("edx") count, ); @@ -62,7 +62,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { "int 0x80", "pop ebx", arg1 = in(reg) fd, - inlateout("eax") 6i32 => ret, // SYS_close + inlateout("eax") 6_i32 => ret, // SYS_close ); ret } @@ -77,7 +77,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { "int 0x80", "pop ebx", arg1 = in(reg) buf, - inlateout("eax") 122i32 => ret, // SYS_newuname + inlateout("eax") 122_i32 => ret, // SYS_newuname ); ret } @@ -92,7 +92,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "int 0x80", "pop ebx", arg1 = in(reg) path, - inlateout("eax") 268i32 => ret, // SYS_statfs64 + inlateout("eax") 268_i32 => ret, // SYS_statfs64 in("ecx") core::mem::size_of::(), in("edx") buf, ); @@ -128,7 +128,7 @@ pub unsafe fn sys_sched_getaffinity( "int 0x80", "pop ebx", arg1 = in(reg) pid, - inlateout("eax") 242i32 => ret, // __NR_sched_getaffinity + inlateout("eax") 242_i32 => ret, // __NR_sched_getaffinity in("ecx") mask_size, in("edx") mask, ); @@ -142,7 +142,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { "mov ebx, {code:e}", "int 0x80", code = in(reg) code, - in("eax") 1i32, // SYS_exit + in("eax") 1_i32, // SYS_exit options(noreturn) ); } diff --git a/crates/asm/src/x86_64.rs b/crates/asm/src/x86_64.rs index 5dd932e..5afb593 100644 --- a/crates/asm/src/x86_64.rs +++ b/crates/asm/src/x86_64.rs @@ -7,10 +7,10 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { let ret: i32; core::arch::asm!( "syscall", - in("rax") 2i64, // SYS_open + in("rax") 2_i64, // SYS_open in("rdi") path, in("rsi") flags, - in("rdx") 0i32, // mode (not used for reading) + in("rdx") 0_i32, // mode (not used for reading) lateout("rax") ret, lateout("rcx") _, lateout("r11") _, @@ -25,7 +25,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "syscall", - in("rax") 0i64, // SYS_read + in("rax") 0_i64, // SYS_read in("rdi") fd, in("rsi") buf, in("rdx") count, @@ -44,7 +44,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { let ret: isize; core::arch::asm!( "syscall", - in("rax") 1i64, // SYS_write + in("rax") 1_i64, // SYS_write in("rdi") fd, in("rsi") buf, in("rdx") count, @@ -63,7 +63,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { let ret: i32; core::arch::asm!( "syscall", - in("rax") 3i64, // SYS_close + in("rax") 3_i64, // SYS_close in("rdi") fd, lateout("rax") ret, lateout("rcx") _, @@ -79,7 +79,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { let ret: i32; core::arch::asm!( "syscall", - in("rax") 63i64, // SYS_uname + in("rax") 63_i64, // SYS_uname in("rdi") buf, lateout("rax") ret, lateout("rcx") _, @@ -96,7 +96,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { let ret: i32; core::arch::asm!( "syscall", - in("rax") 137i64, // SYS_statfs + in("rax") 137_i64, // SYS_statfs in("rdi") path, in("rsi") buf, lateout("rax") ret, @@ -134,7 +134,7 @@ pub unsafe fn sys_sched_getaffinity( let ret: i32; core::arch::asm!( "syscall", - in("rax") 204i64, // __NR_sched_getaffinity + in("rax") 204_i64, // __NR_sched_getaffinity in("rdi") pid, in("rsi") mask_size, in("rdx") mask, @@ -151,7 +151,7 @@ pub unsafe fn sys_exit(code: i32) -> ! { unsafe { core::arch::asm!( "syscall", - in("rax") 60i64, // SYS_exit + in("rax") 60_i64, // SYS_exit in("rdi") code, options(noreturn, nostack) ); diff --git a/crates/benchmarks/benches/microfetch.rs b/crates/benchmarks/benches/microfetch.rs index 5085bb5..afba5bb 100644 --- a/crates/benchmarks/benches/microfetch.rs +++ b/crates/benchmarks/benches/microfetch.rs @@ -12,6 +12,10 @@ use microfetch_lib::{ uptime, }; +#[expect( + clippy::expect_used, + reason = "the benchmarks cannot run without uname" +)] fn main_benchmark(criterion: &mut Criterion) { let utsname = UtsName::uname().expect("Failed to get uname"); let colors = Colors::new(false); @@ -76,7 +80,7 @@ fn main_benchmark(criterion: &mut Criterion) { bencher.iter(|| { let mut buf = [MaybeUninit::uninit(); 256]; let mut writer = StackWriter::new(&mut buf); - uptime::write_uptime(&mut writer); + uptime::write(&mut writer); black_box(writer.written()); }); }); diff --git a/crates/lib/build.rs b/crates/lib/build.rs index 3d5f548..13eb291 100644 --- a/crates/lib/build.rs +++ b/crates/lib/build.rs @@ -1,6 +1,6 @@ // Pack logo rows into a marker-delimited stream: // 1 = blue, 2 = cyan, 0 = row separator. -fn main() { +fn main() -> Result<(), Box> { let rows: &[&[(u8, &str)]] = &[ &[(0, "⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀"), (1, "⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀")], &[(0, "⠀⠀⠀⠀⠀⠀⠈⢿⣿⣆⠀⠀⠀"), (1, "⠘⣿⣿⣴⣿⡿⠁⠀⠀⠀⠀⠀⠀")], @@ -38,6 +38,7 @@ fn main() { } } - let out_dir = std::env::var("OUT_DIR").unwrap(); - std::fs::write(format!("{out_dir}/logo.bin"), &out).unwrap(); + let out_dir = std::env::var("OUT_DIR")?; + std::fs::write(format!("{out_dir}/logo.bin"), &out)?; + Ok(()) } diff --git a/crates/lib/src/colors.rs b/crates/lib/src/colors.rs index 65a7707..e16c8d1 100644 --- a/crates/lib/src/colors.rs +++ b/crates/lib/src/colors.rs @@ -1,6 +1,6 @@ use crate::StackWriter; -/// Color codes for terminal output +/// Color codes for terminal output. pub struct Colors { pub reset: &'static str, pub blue: &'static str, @@ -12,7 +12,7 @@ pub struct Colors { } impl Colors { - #[must_use] + #[must_use = "this builds a palette without side effects"] pub const fn new(is_no_color: bool) -> Self { if is_no_color { Self { diff --git a/crates/lib/src/cpu.rs b/crates/lib/src/cpu.rs index 79ed5d7..b544447 100644 --- a/crates/lib/src/cpu.rs +++ b/crates/lib/src/cpu.rs @@ -1,6 +1,7 @@ -use crate::StackWriter; #[cfg(target_os = "linux")] -use crate::syscall::read_file_fast; +use microfetch_asm::read_file_fast; + +use crate::StackWriter; /// Writes CPU model name (trimmed) to the writer. #[cfg(target_os = "linux")] @@ -14,9 +15,10 @@ pub fn write_cpu_name(writer: &mut StackWriter) { #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_cpu_name(writer: &mut StackWriter) { - let mut buf = [0u8; 128]; - if let Some(len) = - crate::syscall::macos_sysctl_str(b"machdep.cpu.brand_string\0", &mut buf) + use microfetch_asm::darwin::macos_sysctl_str; + + let mut buf = [0_u8; 128]; + if let Some(len) = macos_sysctl_str(b"machdep.cpu.brand_string\0", &mut buf) && let Ok(name) = core::str::from_utf8(&buf[..len]) { writer.push_str(name); @@ -46,7 +48,7 @@ pub fn write_cpu_cores(writer: &mut StackWriter) { #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_cpu_cores(writer: &mut StackWriter) { - use crate::syscall::macos_sysctl_u32; + use microfetch_asm::darwin::macos_sysctl_u32; let Some(threads) = macos_sysctl_u32(b"hw.logicalcpu\0") else { return; @@ -96,12 +98,12 @@ fn write_cores( /// Count online threads via `sched_getaffinity(2)`. #[cfg(target_os = "linux")] fn get_thread_count() -> Option { - let mut mask = [0u8; 128]; + let mut mask = [0_u8; 128]; let ret = unsafe { - crate::syscall::sys_sched_getaffinity(0, mask.len(), mask.as_mut_ptr()) + microfetch_asm::sys_sched_getaffinity(0, mask.len(), mask.as_mut_ptr()) }; let bytes = usize::try_from(ret).ok()?; - let mut count = 0u32; + let mut count = 0_u32; for &byte in &mask[..bytes] { count += byte.count_ones(); } @@ -128,21 +130,17 @@ fn get_core_count(threads: u32) -> u32 { fn get_pe_cores() -> Option<(u32, u32)> { let perf = count_cpulist("/sys/devices/cpu_core/cpus")?; let eff = count_cpulist("/sys/devices/cpu_atom/cpus").unwrap_or(0); - if perf > 0 || eff > 0 { - Some((perf, eff)) - } else { - None - } + (perf > 0 || eff > 0).then_some((perf, eff)) } /// Parse a cpulist file and count listed CPUs. #[cfg(target_os = "linux")] fn count_cpulist(path: &str) -> Option { - let mut buf = [0u8; 64]; + let mut buf = [0_u8; 64]; let len = read_file_fast(path, &mut buf).ok()?; let data = &buf[..len]; - let mut count = 0u32; + let mut count = 0_u32; let mut pos = 0; while pos < data.len() { // Parse start number @@ -167,7 +165,7 @@ fn count_cpulist(path: &str) -> Option { /// Parse a decimal number from a byte slice, advancing the index. #[cfg(target_os = "linux")] fn parse_num(data: &[u8], pos: &mut usize) -> u32 { - let mut value = 0u32; + let mut value = 0_u32; while *pos < data.len() && data[*pos].is_ascii_digit() { value = value * 10 + u32::from(data[*pos] - b'0'); *pos += 1; @@ -183,11 +181,11 @@ fn format_cpufreq_path(buf: &mut [u8; 64], cpu: u32) -> usize { const SUFFIX: &[u8] = b"/cpufreq/cpuinfo_max_freq"; buf[..PREFIX.len()].copy_from_slice(PREFIX); let mut pos = PREFIX.len(); - let mut tmp = [0u8; 3]; + let mut tmp = [0_u8; 3]; let mut value = cpu; let mut digits = 0; loop { - tmp[digits] = b'0' + (value % 10) as u8; + tmp[digits] = b'0' + u8::try_from(value % 10).unwrap_or(0); digits += 1; value /= 10; if value == 0 { @@ -206,14 +204,14 @@ fn format_cpufreq_path(buf: &mut [u8; 64], cpu: u32) -> usize { /// Read one CPU's `cpuinfo_max_freq`, in kHz. #[cfg(target_os = "linux")] fn read_cpu_max_khz(cpu: u32) -> Option { - let mut path = [0u8; 64]; + let mut path = [0_u8; 64]; let path_len = format_cpufreq_path(&mut path, cpu); // SAFETY: the path is a constant prefix, decimal digits, and a constant // suffix, so it is ASCII by construction. let path_str = unsafe { core::str::from_utf8_unchecked(&path[..path_len]) }; - let mut buf = [0u8; 32]; + let mut buf = [0_u8; 32]; let len = read_file_fast(path_str, &mut buf).ok()?; - let mut khz = 0u32; + let mut khz = 0_u32; for &byte in &buf[..len] { if byte.is_ascii_digit() { khz = khz * 10 + u32::from(byte - b'0'); @@ -227,7 +225,7 @@ fn read_cpu_max_khz(cpu: u32) -> Option { // https://github.com/torvalds/linux/blob/v6.19/drivers/base/cpu.c#L273-L286 #[cfg(target_os = "linux")] fn highest_present_cpu() -> Option { - let mut buf = [0u8; 64]; + let mut buf = [0_u8; 64]; let len = read_file_fast("/sys/devices/system/cpu/present", &mut buf).ok()?; let data = &buf[..len]; let end = data.iter().rposition(u8::is_ascii_digit)? + 1; @@ -235,7 +233,7 @@ fn highest_present_cpu() -> Option { .iter() .rposition(|byte| !byte.is_ascii_digit()) .map_or(0, |pos| pos + 1); - let mut cpu = 0u32; + let mut cpu = 0_u32; for &byte in &data[start..end] { cpu = cpu * 10 + u32::from(byte - b'0'); } @@ -273,7 +271,7 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { } // Fall back to cpuinfo fields for key in &[ - b"cpu MHz" as &[u8], + b"cpu MHz".as_slice(), b"cpu MHz dynamic", b"cpu MHz static", b"CPU MHz", @@ -283,7 +281,7 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { ] { if let Some(val) = extract_field(cpuinfo, key) { // Parse integer part of the MHz value (e.g. "5200.00" -> 5200) - let mut mhz = 0u32; + let mut mhz = 0_u32; for &byte in val.as_bytes() { if byte == b'.' { break; @@ -310,7 +308,7 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { // SPARC exposes its clock as `Cpu0ClkTck : `, // which signifies ticks per second in hex. if let Some(val) = extract_field(cpuinfo, b"Cpu0ClkTck") { - let mut hz = 0u64; + let mut hz = 0_u64; let mut seen = false; for &byte in val.as_bytes() { let hex_digit = match byte { @@ -339,22 +337,22 @@ fn get_cpu_freq_mhz(cpuinfo: &[u8]) -> Option { /// Appends CPU frequency if available. #[cfg(target_os = "linux")] fn write_model_name(writer: &mut StackWriter) { - let mut buf = [0u8; 1024]; + let mut buf = [0_u8; 1024]; let Ok(len) = read_file_fast("/proc/cpuinfo", &mut buf) else { return; }; let data = &buf[..len]; - let mhz = get_cpu_freq_mhz(data); + let freq_mhz = get_cpu_freq_mhz(data); let named = match extract_name(data) { Some(name) => { // x86 `model name` already ends in `@ GHz`, which hides the // ` CPU` that trim() would otherwise strip, so re-trim after cutting. - let name = match (mhz, name.find(" @ ")) { - (Some(_), Some(at_pos)) => trim(&name[..at_pos]), - _ => name, - }; - writer.push_str(name); + let clock_free = name.split_once(" @ ").map(|(head, _)| head); + match (freq_mhz, clock_free) { + (Some(_), Some(head)) => writer.push_str(trim(head)), + _ => writer.push_str(name), + } true }, None => { @@ -363,7 +361,7 @@ fn write_model_name(writer: &mut StackWriter) { }, }; - let Some(mhz) = mhz else { + let Some(mhz) = freq_mhz else { return; }; @@ -423,7 +421,7 @@ struct ArmPart { #[cfg(target_os = "linux")] const fn arm_part(part: u16, family: ArmFamily, model: &str) -> ArmPart { let bytes = model.as_bytes(); - let mut padded = [0u8; 7]; + let mut padded = [0_u8; 7]; let mut index = 0; while index < bytes.len() { padded[index] = bytes[index]; @@ -494,12 +492,12 @@ static ARM_PARTS: [ArmPart; 45] = { fn write_arm_part(writer: &mut StackWriter, data: &[u8]) -> bool { let hex = |key| { let digits = extract_field(data, key)?.strip_prefix("0x")?; - let mut value = 0u32; + let mut value = 0_u32; for digit in digits .bytes() .map_while(|byte| char::from(byte).to_digit(16)) { - value = value << 4 | digit; + value = (value << 4_u32) | digit; } Some(value) }; @@ -526,7 +524,7 @@ fn write_arm_part(writer: &mut StackWriter, data: &[u8]) -> bool { #[cfg(target_os = "linux")] fn extract_name(data: &[u8]) -> Option<&str> { for key in &[ - b"model name" as &[u8], + b"model name".as_slice(), b"Model Name", b"uarch", b"cpu model", @@ -551,7 +549,7 @@ fn extract_name(data: &[u8]) -> Option<&str> { /// the model portion after the comma. #[cfg(target_os = "linux")] fn write_dt_compatible(writer: &mut StackWriter) -> bool { - let mut buf = [0u8; 256]; + let mut buf = [0_u8; 256]; let Ok(len) = read_file_fast("/sys/firmware/devicetree/base/compatible", &mut buf) else { @@ -618,50 +616,29 @@ fn extract_field<'data>(data: &'data [u8], key: &[u8]) -> Option<&'data str> { /// Strip noise from model names. #[cfg(target_os = "linux")] fn trim(name: &str) -> &str { - let bytes = name.as_bytes(); - let mut end = bytes.len(); - - while end > 0 && bytes[end - 1].is_ascii_whitespace() { - end -= 1; - } - - if end >= 10 && &bytes[end - 10..end] == b" Processor" { - end -= 10; - } else if end >= 4 && &bytes[end - 4..end] == b" CPU" { - end -= 4; - } - while end > 0 && bytes[end - 1].is_ascii_whitespace() { - end -= 1; - } - - if end >= 3 && &bytes[end - 3..end] == b"(R)" { - end -= 3; - } else if end >= 4 - && (&bytes[end - 4..end] == b"(TM)" || &bytes[end - 4..end] == b"(tm)") + let mut rest = name.trim_ascii_end(); + + rest = rest + .strip_suffix(" Processor") + .or_else(|| rest.strip_suffix(" CPU")) + .unwrap_or(rest) + .trim_ascii_end(); + + rest = rest + .strip_suffix("(R)") + .or_else(|| rest.strip_suffix("(TM)")) + .or_else(|| rest.strip_suffix("(tm)")) + .unwrap_or(rest) + .trim_ascii_end(); + + if rest.len() > 7 + && let Some(head) = rest.strip_suffix("-Core") + && let Some(kept) = head + .trim_end_matches(|ch: char| ch.is_ascii_digit()) + .strip_suffix(' ') { - end -= 4; - } - while end > 0 && bytes[end - 1].is_ascii_whitespace() { - end -= 1; - } - - if end > 7 && &bytes[end - 5..end] == b"-Core" { - let mut pos = end - 5; - while pos > 0 && bytes[pos - 1].is_ascii_digit() { - pos -= 1; - } - if pos > 0 && bytes[pos - 1] == b' ' { - end = pos - 1; - } - } - while end > 0 && bytes[end - 1].is_ascii_whitespace() { - end -= 1; - } - - let mut start = 0; - while start < end && bytes[start].is_ascii_whitespace() { - start += 1; + rest = kept.trim_ascii_end(); } - &name[start..end] + rest.trim_ascii_start() } diff --git a/crates/lib/src/desktop.rs b/crates/lib/src/desktop.rs index 100bb2e..d89ddc9 100644 --- a/crates/lib/src/desktop.rs +++ b/crates/lib/src/desktop.rs @@ -28,15 +28,9 @@ pub fn write_desktop_info(writer: &mut StackWriter) { writer.push_str(" ("); // Capitalize first character of backend - if let Some(&first_byte) = backend_str.as_bytes().first() { - // Convert first byte to uppercase if it's ASCII lowercase - let upper = if first_byte.is_ascii_lowercase() { - first_byte - b'a' + b'A' - } else { - first_byte - }; - writer.push_byte(upper); - writer.push_str(&backend_str[1..]); + if let Some((&first_byte, rest)) = backend_str.as_bytes().split_first() { + writer.push_byte(first_byte.to_ascii_uppercase()); + writer.push_bytes(rest); } writer.push_byte(b')'); diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index f8a5cf0..1b5d448 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -16,21 +16,7 @@ use core::{ sync::atomic::{AtomicPtr, Ordering}, }; -pub use microfetch_asm as syscall; -pub use microfetch_asm::{ - StatfsBuf, - SysInfo, - UtsNameBuf, - read_file_fast, - sys_close, - sys_open, - sys_read, - sys_sched_getaffinity, - sys_statfs, - sys_sysinfo, - sys_uname, - sys_write, -}; +use microfetch_asm::{UtsNameBuf, sys_uname, sys_write}; /// A simple error type for microfetch operations. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -48,7 +34,7 @@ pub enum Error { impl Error { /// Creates an error from the last OS error (reads errno). #[inline] - #[must_use] + #[must_use = "this only reads errno"] pub const fn last_os_error() -> Self { // This is a simplified version - in a real implementation, // we'd need to get the actual errno from the syscall return @@ -74,14 +60,14 @@ pub unsafe fn init_env(envp: *const *const u8) { /// Gets the current environment pointer. #[inline] -#[must_use] +#[must_use = "this only reads the stored pointer"] fn get_envp() -> *const *const u8 { ENVP.load(Ordering::Acquire) } /// Gets an environment variable by name without using std or libc by reading /// from the environment pointer set by [`init_env`]. -#[must_use] +#[must_use = "this only reads the environment"] pub fn getenv(name: &str) -> Option<&'static [u8]> { let envp = get_envp(); if envp.is_null() { @@ -144,51 +130,51 @@ pub fn getenv(name: &str) -> Option<&'static [u8]> { /// Environment variables set by the shell / login process are always valid /// UTF-8 on any real Linux system. We skip the `from_utf8` validation and use /// `from_utf8_unchecked`. -#[must_use] +#[must_use = "this only reads the environment"] pub fn getenv_str(name: &str) -> Option<&'static str> { getenv(name).map(|bytes| unsafe { core::str::from_utf8_unchecked(bytes) }) } /// Checks if an environment variable exists (regardless of its value). -#[must_use] +#[must_use = "this only reads the environment"] pub fn env_exists(name: &str) -> bool { getenv(name).is_some() } -/// Wrapper for `utsname` with safe accessor methods +/// Wrapper for `utsname` with safe accessor methods. pub struct UtsName(UtsNameBuf); impl UtsName { - /// Calls `uname(2)` syscall and returns a `UtsName` wrapper + /// Calls `uname(2)` syscall and returns a `UtsName` wrapper. /// /// # Errors /// - /// Returns an error if the `uname` syscall fails + /// Returns an error if the `uname` syscall fails. pub fn uname() -> Result { let mut uts = MaybeUninit::uninit(); - if unsafe { sys_uname(uts.as_mut_ptr()) } != 0 { + if unsafe { sys_uname(uts.as_mut_ptr()) } != 0_i32 { return Err(Error::last_os_error()); } Ok(Self(unsafe { uts.assume_init() })) } - #[must_use] + #[must_use = "this only borrows a field"] pub const fn nodename(&self) -> &CStr { unsafe { CStr::from_ptr(self.0.nodename.as_ptr().cast()) } } - #[must_use] + #[must_use = "this only borrows a field"] pub const fn sysname(&self) -> &CStr { unsafe { CStr::from_ptr(self.0.sysname.as_ptr().cast()) } } - #[must_use] + #[must_use = "this only borrows a field"] pub const fn release(&self) -> &CStr { unsafe { CStr::from_ptr(self.0.release.as_ptr().cast()) } } - #[must_use] + #[must_use = "this only borrows a field"] pub const fn machine(&self) -> &CStr { unsafe { CStr::from_ptr(self.0.machine.as_ptr().cast()) } } @@ -207,7 +193,7 @@ impl<'buf> StackWriter<'buf> { } #[inline] - #[must_use] + #[must_use = "this only borrows the written bytes"] pub const fn written(&self) -> &[u8] { unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast(), self.pos) } } @@ -226,7 +212,7 @@ impl<'buf> StackWriter<'buf> { self.buf.as_mut_ptr().add(self.pos).cast(), len, ); - } + }; self.pos += len; } @@ -250,11 +236,11 @@ impl<'buf> StackWriter<'buf> { self.push_byte(b'0'); return; } - let mut digits = [0u8; 20]; + let mut digits = [0_u8; 20]; let mut start = 20; while value > 0 { start -= 1; - digits[start] = b'0' + (value % 10) as u8; + digits[start] = b'0' + u8::try_from(value % 10).unwrap_or(0); value /= 10; } self.push_bytes(&digits[start..]); @@ -265,7 +251,9 @@ impl<'buf> StackWriter<'buf> { /// environment variable. Set it to 11 newline-separated lines of ASCII/Unicode /// art when building to replace the default NixOS logo: /// -/// `MICROFETCH_LOGO="$(cat my_logo.txt)"` cargo build --release +/// ```sh +/// MICROFETCH_LOGO="$(cat my_logo.txt)" cargo build --release +/// ``` /// /// Each line maps to one info row. When unset, the built-in two-tone NixOS /// logo is used. @@ -325,7 +313,6 @@ const ROW_LABELS: &[u8] = concat!( /// Write one row: logo + label + value. #[inline(never)] -#[allow(clippy::ref_option)] fn write_row( writer: &mut StackWriter, colors: &colors::Colors, @@ -336,9 +323,9 @@ fn write_row( utsname: &UtsName, ) { writer.push_str(" "); - if let Some(custom_logo) = custom_logo { + if let Some(logo_text) = custom_logo { writer.push_str(colors.cyan); - writer.push_str(custom_logo); + writer.push_str(logo_text); } else { write_styled_row(writer, colors, logo); } @@ -358,7 +345,7 @@ fn write_row( 3 => cpu::write_cpu_name(writer), 4 => cpu::write_cpu_cores(writer), 5 => system::write_shell(writer), - 6 => uptime::write_uptime(writer), + 6 => uptime::write(writer), 7 => desktop::write_desktop_info(writer), 8 => system::write_memory_usage(writer, colors), 9 => system::write_root_disk_usage(writer, colors), @@ -371,7 +358,7 @@ fn write_row( fn print_version() { const VERSION: &str = concat!("Microfetch ", env!("CARGO_PKG_VERSION"), "\n"); unsafe { - let _ = sys_write(1, VERSION.as_ptr(), VERSION.len()); + _ = sys_write(1, VERSION.as_ptr(), VERSION.len()); } } @@ -382,7 +369,7 @@ fn print_version() { /// This function must be called with valid argc and argv from the program entry /// point. unsafe fn check_version_flag(argc: i32, argv: *const *const u8) -> bool { - if argc < 2 { + if argc < 2_i32 { return false; } // SAFETY: argv is a valid array of argc pointers @@ -412,7 +399,7 @@ unsafe fn check_version_flag(argc: i32, argv: *const *const u8) -> bool { /// /// # Errors /// -/// Returns an error if any system call fails +/// Returns an error if any system call fails. /// /// # Safety /// diff --git a/crates/lib/src/release.rs b/crates/lib/src/release.rs index 2b215ae..b721be4 100644 --- a/crates/lib/src/release.rs +++ b/crates/lib/src/release.rs @@ -1,5 +1,6 @@ #[cfg(target_os = "linux")] -use crate::syscall::read_file_fast; +use microfetch_asm::read_file_fast; + use crate::{StackWriter, UtsName}; #[cfg_attr(feature = "hotpath", hotpath::measure)] @@ -17,10 +18,11 @@ pub fn write_system_info(writer: &mut StackWriter, utsname: &UtsName) { #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_os_pretty_name(writer: &mut StackWriter) { + use microfetch_asm::darwin::macos_sysctl_str; + writer.push_str("macOS"); - let mut buf = [0u8; 64]; - if let Some(len) = - crate::syscall::macos_sysctl_str(b"kern.osproductversion\0", &mut buf) + let mut buf = [0_u8; 64]; + if let Some(len) = macos_sysctl_str(b"kern.osproductversion\0", &mut buf) && let Ok(version) = core::str::from_utf8(&buf[..len]) && !version.is_empty() { @@ -37,7 +39,7 @@ pub fn write_os_pretty_name(writer: &mut StackWriter) { // Fast byte-level scanning for PRETTY_NAME= const PREFIX: &[u8] = b"PRETTY_NAME="; - let mut buffer = [0u8; 1024]; + let mut buffer = [0_u8; 1024]; // Use fast syscall-based file reading let Ok(bytes_read) = read_file_fast("/etc/os-release", &mut buffer) else { diff --git a/crates/lib/src/system.rs b/crates/lib/src/system.rs index 191a3a5..264db8f 100644 --- a/crates/lib/src/system.rs +++ b/crates/lib/src/system.rs @@ -1,13 +1,10 @@ use core::mem::MaybeUninit; #[cfg(target_os = "linux")] -use crate::syscall::read_file_fast; -use crate::{ - StackWriter, - UtsName, - colors::Colors, - syscall::{StatfsBuf, sys_statfs}, -}; +use microfetch_asm::read_file_fast; +use microfetch_asm::{StatfsBuf, sys_statfs}; + +use crate::{StackWriter, UtsName, colors::Colors}; #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_username_and_hostname( @@ -33,8 +30,7 @@ pub fn write_shell(writer: &mut StackWriter) { if shell.is_empty() { writer.push_str("unknown_shell"); } else { - let start = shell.rfind('/').map_or(0, |pos| pos + 1); - writer.push_str(&shell[start..]); + writer.push_str(shell.rsplit_once('/').map_or(shell, |(_, name)| name)); } } @@ -42,14 +38,14 @@ pub fn write_shell(writer: &mut StackWriter) { /// be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_root_disk_usage(writer: &mut StackWriter, colors: &Colors) { - let mut vfs = MaybeUninit::::uninit(); + let mut vfs_buf = MaybeUninit::::uninit(); let path = b"/\0"; - if unsafe { sys_statfs(path.as_ptr(), vfs.as_mut_ptr()) } != 0 { + if unsafe { sys_statfs(path.as_ptr(), vfs_buf.as_mut_ptr()) } != 0_i32 { return; } - let vfs = unsafe { vfs.assume_init() }; + let vfs = unsafe { vfs_buf.assume_init() }; #[allow( clippy::unnecessary_fallible_conversions, reason = "f_bsize is a signed long on most targets but u32 on macOS, \ @@ -79,7 +75,7 @@ pub fn write_root_disk_usage(writer: &mut StackWriter, colors: &Colors) { fn write_centi_gib(writer: &mut StackWriter, centi_gib: u64) { writer.push_u64(centi_gib / 100); writer.push_byte(b'.'); - let frac = (centi_gib % 100) as u8; + let frac = u8::try_from(centi_gib % 100).unwrap_or(0); writer.push_byte(b'0' + frac / 10); writer.push_byte(b'0' + frac % 10); } @@ -93,11 +89,11 @@ fn write_kb_as_gib(writer: &mut StackWriter, kb: u64) { write_centi_gib(writer, (kb * 100 + (1 << 19)) >> 20); } -/// Fast integer parsing without stdlib overhead +/// Fast integer parsing without stdlib overhead. #[cfg(target_os = "linux")] #[inline] fn parse_u64_fast(bytes: &[u8]) -> u64 { - let mut result = 0u64; + let mut result = 0_u64; for &byte in bytes { if byte.is_ascii_digit() { result = result * 10 + u64::from(byte - b'0'); @@ -113,7 +109,9 @@ fn parse_u64_fast(bytes: &[u8]) -> u64 { #[cfg(target_os = "macos")] #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn write_memory_usage(writer: &mut StackWriter, colors: &Colors) { - let Some((used_bytes, total_bytes)) = crate::syscall::macos_meminfo() else { + use microfetch_asm::darwin::macos_meminfo; + + let Some((used_bytes, total_bytes)) = macos_meminfo() else { return; }; let percentage_used = (used_bytes * 100 + total_bytes / 2) @@ -138,9 +136,9 @@ pub fn write_memory_usage(writer: &mut StackWriter, colors: &Colors) { pub fn write_memory_usage(writer: &mut StackWriter, colors: &Colors) { #[cfg_attr(feature = "hotpath", hotpath::measure)] fn parse_memory_info() -> Option<(u64, u64)> { - let mut total_memory_kb = 0u64; - let mut available_memory_kb = 0u64; - let mut buffer = [0u8; 1024]; + let mut total_memory_kb = 0_u64; + let mut available_memory_kb = 0_u64; + let mut buffer = [0_u8; 1024]; // Use fast syscall-based file reading let bytes_read = read_file_fast("/proc/meminfo", &mut buffer).ok()?; @@ -161,21 +159,12 @@ pub fn write_memory_usage(writer: &mut StackWriter, colors: &Colors) { .unwrap_or(remaining.len()); let line = &remaining[..line_end]; - if line.starts_with(b"MemTotal:") { - // Skip "MemTotal:" and whitespace - let mut pos = 9; - while pos < line.len() && line[pos].is_ascii_whitespace() { - pos += 1; - } - total_memory_kb = parse_u64_fast(&line[pos..]); + if let Some(value) = line.strip_prefix(b"MemTotal:") { + total_memory_kb = parse_u64_fast(value.trim_ascii_start()); found_total = true; - } else if line.starts_with(b"MemAvailable:") { - // Skip "MemAvailable:" and whitespace - let mut pos = 13; - while pos < line.len() && line[pos].is_ascii_whitespace() { - pos += 1; - } - available_memory_kb = parse_u64_fast(&line[pos..]); + } + if let Some(value) = line.strip_prefix(b"MemAvailable:") { + available_memory_kb = parse_u64_fast(value.trim_ascii_start()); found_available = true; } diff --git a/crates/lib/src/uptime.rs b/crates/lib/src/uptime.rs index 4ad18d7..3f3fce0 100644 --- a/crates/lib/src/uptime.rs +++ b/crates/lib/src/uptime.rs @@ -1,11 +1,14 @@ #[cfg(target_os = "linux")] use core::mem::MaybeUninit; +#[cfg(target_os = "macos")] +use microfetch_asm::darwin::macos_uptime_secs; +#[cfg(target_os = "linux")] use microfetch_asm::sys_sysinfo; + use crate::StackWriter; -#[cfg(target_os = "linux")] use crate::syscall::sys_sysinfo; /// Writes the current system uptime, or nothing if it cannot be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] -pub fn write_uptime(writer: &mut StackWriter) { +pub fn write(writer: &mut StackWriter) { #[cfg(target_os = "linux")] let uptime_seconds = { let mut info = MaybeUninit::uninit(); @@ -19,7 +22,7 @@ pub fn write_uptime(writer: &mut StackWriter) { seconds }; #[cfg(target_os = "macos")] - let Some(uptime_seconds) = crate::syscall::macos_uptime_secs() else { + let Some(uptime_seconds) = macos_uptime_secs() else { return; }; diff --git a/microfetch/build.rs b/microfetch/build.rs index fb2811e..ecc1d2f 100644 --- a/microfetch/build.rs +++ b/microfetch/build.rs @@ -1,11 +1,8 @@ -use std::{env, process::Command}; +use std::{env, io, process::Command}; -fn main() { +fn main() -> io::Result<()> { let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); - let version = Command::new(rustc) - .arg("-vV") - .output() - .expect("failed to run `rustc -vV`"); + let version = Command::new(rustc).arg("-vV").output()?; let nightly = String::from_utf8_lossy(&version.stdout) .lines() .any(|line| { @@ -26,7 +23,7 @@ fn main() { // linker driver produces a correct (and ad-hoc code-signed) binary there. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); if target_os == "macos" { - return; + return Ok(()); } // No C runtime, we provide _start ourselves @@ -47,4 +44,6 @@ fn main() { println!("cargo:rustc-link-arg-bin=microfetch=-Wl,--build-id=none"); // Disable RELRO (removes relro_padding) println!("cargo:rustc-link-arg-bin=microfetch=-Wl,-z,norelro"); + + Ok(()) } diff --git a/microfetch/src/main.rs b/microfetch/src/main.rs index adad1f7..cd18d0b 100644 --- a/microfetch/src/main.rs +++ b/microfetch/src/main.rs @@ -25,10 +25,6 @@ use core::arch::naked_asm; #[cfg(not(any(target_os = "macos", target_abi = "elfv1")))] use microfetch_asm::entry_rust; use microfetch_asm::sys_write; -// Re-export libc replacement functions from asm crate. On macOS these are -// provided by libSystem, so we don't define (or re-export) our own. -#[cfg(not(target_os = "macos"))] -pub use microfetch_asm::{memcpy, memset, strlen}; #[cfg(target_arch = "x86_64")] #[unsafe(no_mangle)] @@ -324,14 +320,14 @@ pub unsafe extern "C" fn main(argc: i32, argv: *const *const u8) -> i32 { // Initialize the environment pointer unsafe { microfetch_lib::init_env(envp); - } + }; // Run the main application logic if unsafe { microfetch_lib::run(argc, argv) }.is_ok() { 0 } else { const ERR_MSG: &[u8] = b"Error\n"; - let _ = unsafe { sys_write(2, ERR_MSG.as_ptr(), ERR_MSG.len()) }; + _ = unsafe { sys_write(2, ERR_MSG.as_ptr(), ERR_MSG.len()) }; 1 } } @@ -341,15 +337,15 @@ pub unsafe extern "C" fn main(argc: i32, argv: *const *const u8) -> i32 { fn panic(_info: &core::panic::PanicInfo) -> ! { const PANIC_MSG: &[u8] = b"panic\n"; unsafe { - let _ = sys_write(2, PANIC_MSG.as_ptr(), PANIC_MSG.len()); + _ = sys_write(2, PANIC_MSG.as_ptr(), PANIC_MSG.len()); microfetch_asm::sys_exit(1) } } -/// Stubs for Rust exception handling +/// Stubs for Rust exception handling. /// /// Nightly mangles this symbol with a per-compiler hash since -/// https://github.com/rust-lang/rust/pull/148413, so only the lang item can name +/// , so only the lang item can name /// it there. #[cfg(all(not(test), nightly))] #[lang = "eh_personality"] From 363dec161a97375450a47021334eefcc4500bc15 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 13:32:31 -0400 Subject: [PATCH 11/15] treewide: import paths instead of spelling them out --- Cargo.toml | 1 - crates/asm/src/aarch64.rs | 20 +++++++++++--------- crates/asm/src/arm.rs | 22 ++++++++++++---------- crates/asm/src/loongarch64.rs | 20 +++++++++++--------- crates/asm/src/mips.rs | 22 ++++++++++++---------- crates/asm/src/mips64.rs | 20 +++++++++++--------- crates/asm/src/powerpc.rs | 22 ++++++++++++---------- crates/asm/src/powerpc64.rs | 20 +++++++++++--------- crates/asm/src/riscv32.rs | 22 ++++++++++++---------- crates/asm/src/riscv64.rs | 20 +++++++++++--------- crates/asm/src/s390x.rs | 20 +++++++++++--------- crates/asm/src/sparc.rs | 22 ++++++++++++---------- crates/asm/src/sparc64.rs | 20 +++++++++++--------- crates/asm/src/x86.rs | 22 ++++++++++++---------- crates/asm/src/x86_64.rs | 20 +++++++++++--------- crates/benchmarks/examples/hotpath.rs | 4 ++-- crates/lib/build.rs | 8 +++++--- crates/lib/src/cpu.rs | 10 ++++++---- crates/lib/src/lib.rs | 16 ++++++++++------ crates/lib/src/release.rs | 4 +++- microfetch/build.rs | 4 ++-- microfetch/src/main.rs | 12 ++++++++---- 22 files changed, 196 insertions(+), 155 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a9f824e..7e9f6c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ perf = { level = "warn", priority = -1 } restriction = { level = "warn", priority = -1 } style = { level = "warn", priority = -1 } -absolute_paths = "allow" allow_attributes = "allow" arbitrary_source_item_ordering = "allow" arithmetic_side_effects = "allow" diff --git a/crates/asm/src/aarch64.rs b/crates/asm/src/aarch64.rs index 222db47..fce16cc 100644 --- a/crates/asm/src/aarch64.rs +++ b/crates/asm/src/aarch64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `aarch64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("x8") 56_i64, // SYS_openat in("x0") -100_i32, // AT_FDCWD @@ -22,7 +24,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "svc #0", in("x8") 63_i64, // SYS_read in("x0") fd, @@ -39,7 +41,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "svc #0", in("x8") 64_i64, // SYS_write in("x0") fd, @@ -56,7 +58,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("x8") 57_i64, // SYS_close in("x0") fd, @@ -70,7 +72,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("x8") 160_i64, // SYS_uname in("x0") buf, @@ -84,7 +86,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("x8") 43_i64, // SYS_statfs in("x0") path, @@ -100,7 +102,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "svc #0", in("x8") 179_i64, // __NR_sysinfo in("x0") info, @@ -118,7 +120,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("x8") 123_i64, // __NR_sched_getaffinity in("x0") pid, @@ -133,7 +135,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "svc #0", in("x8") 93_i64, // SYS_exit in("x0") code, diff --git a/crates/asm/src/arm.rs b/crates/asm/src/arm.rs index 7ee48f6..4493f4a 100644 --- a/crates/asm/src/arm.rs +++ b/crates/asm/src/arm.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `arm`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("r7") 5_i32, // SYS_open in("r0") path, @@ -21,7 +23,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "svc #0", in("r7") 3_i32, // SYS_read in("r0") fd, @@ -37,7 +39,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "svc #0", in("r7") 4_i32, // SYS_write in("r0") fd, @@ -53,7 +55,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("r7") 6_i32, // SYS_close in("r0") fd, @@ -67,7 +69,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("r7") 122_i32, // SYS_newuname in("r0") buf, @@ -81,11 +83,11 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("r7") 266_i32, // SYS_statfs64 in("r0") path, - in("r1") core::mem::size_of::(), + in("r1") size_of::(), in("r2") buf, lateout("r0") ret, options(nostack) @@ -97,7 +99,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("r7") 116_i32, // __NR_sysinfo in("r0") info, @@ -115,7 +117,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc #0", in("r7") 242_i32, // __NR_sched_getaffinity in("r0") pid, @@ -130,7 +132,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "svc #0", in("r7") 1_i32, // SYS_exit in("r0") code, diff --git a/crates/asm/src/loongarch64.rs b/crates/asm/src/loongarch64.rs index ef7e66d..2475afa 100644 --- a/crates/asm/src/loongarch64.rs +++ b/crates/asm/src/loongarch64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `loongarch64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 56_i64, // SYS_openat in("$a0") -100_i32, // AT_FDCWD @@ -22,7 +24,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 63_i64, // SYS_read in("$a0") fd, @@ -38,7 +40,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 64_i64, // SYS_write in("$a0") fd, @@ -54,7 +56,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 57_i64, // SYS_close in("$a0") fd, @@ -68,7 +70,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 160_i64, // SYS_uname in("$a0") buf, @@ -82,7 +84,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 43_i64, // SYS_statfs in("$a0") path, @@ -97,7 +99,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 179_i64, // __NR_sysinfo in("$a0") info, @@ -115,7 +117,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall 0", in("$a7") 123_i64, // __NR_sched_getaffinity in("$a0") pid, @@ -130,7 +132,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "syscall 0", in("$a7") 93_i64, // SYS_exit in("$a0") code, diff --git a/crates/asm/src/mips.rs b/crates/asm/src/mips.rs index a7f1188..f1fda08 100644 --- a/crates/asm/src/mips.rs +++ b/crates/asm/src/mips.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `mips`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -28,7 +30,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -51,7 +53,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -74,7 +76,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -95,7 +97,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -116,7 +118,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -124,7 +126,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "1:", inlateout("$2") 4000_i32 + 255 => ret, // SYS_statfs64 in("$4") path, - in("$5") core::mem::size_of::(), + in("$5") size_of::(), in("$6") buf, lateout("$7") _, lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _, @@ -139,7 +141,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -164,7 +166,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -186,7 +188,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "syscall", in("$2") 4000_i32 + 1, // SYS_exit in("$4") code, diff --git a/crates/asm/src/mips64.rs b/crates/asm/src/mips64.rs index cfc3d52..12bd511 100644 --- a/crates/asm/src/mips64.rs +++ b/crates/asm/src/mips64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `mips64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -29,7 +31,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -53,7 +55,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -77,7 +79,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -99,7 +101,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -121,7 +123,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -144,7 +146,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "syscall", "beqz $7, 1f", "nop", @@ -170,7 +172,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", in("$2") 5000_i64 + 196, // __NR_sched_getaffinity lateout("$2") ret, @@ -189,7 +191,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "syscall", in("$2") 5000_i64 + 58, // SYS_exit in("$4") code, diff --git a/crates/asm/src/powerpc.rs b/crates/asm/src/powerpc.rs index 91eb81f..b1f9c5a 100644 --- a/crates/asm/src/powerpc.rs +++ b/crates/asm/src/powerpc.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `powerpc`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -26,7 +28,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -47,7 +49,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -68,7 +70,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -87,7 +89,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -106,14 +108,14 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", "2:", inlateout("r0") 252_i32 => _, // SYS_statfs64 inlateout("r3") path => ret, - inlateout("r4") core::mem::size_of::() => _, + inlateout("r4") size_of::() => _, inlateout("r5") buf => _, out("r6") _, out("r7") _, out("r8") _, out("r9") _, out("r10") _, out("r11") _, out("r12") _, @@ -127,7 +129,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -150,7 +152,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -170,7 +172,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "li 0, 1", // SYS_exit "sc", in("r3") code, diff --git a/crates/asm/src/powerpc64.rs b/crates/asm/src/powerpc64.rs index ba82759..597bdf3 100644 --- a/crates/asm/src/powerpc64.rs +++ b/crates/asm/src/powerpc64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `powerpc64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -27,7 +29,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -49,7 +51,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -71,7 +73,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -91,7 +93,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -111,7 +113,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -132,7 +134,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -156,7 +158,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "sc", "bns+ 2f", "neg 3, 3", @@ -177,7 +179,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "li 0, 1", // SYS_exit "sc", in("r3") code, diff --git a/crates/asm/src/riscv32.rs b/crates/asm/src/riscv32.rs index 2756ba6..b30e8ce 100644 --- a/crates/asm/src/riscv32.rs +++ b/crates/asm/src/riscv32.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `riscv32`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 56_i32, // SYS_openat in("a0") -100_i32, // AT_FDCWD @@ -22,7 +24,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "ecall", in("a7") 63_i32, // SYS_read in("a0") fd, @@ -38,7 +40,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "ecall", in("a7") 64_i32, // SYS_write in("a0") fd, @@ -54,7 +56,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 57_i32, // SYS_close in("a0") fd, @@ -68,7 +70,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 160_i32, // SYS_uname in("a0") buf, @@ -83,11 +85,11 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { // asm-generic __NR_statfs routes to sys_statfs64 on 32-bit: 3-arg form. let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 43_i32, // __NR_statfs in("a0") path, - in("a1") core::mem::size_of::(), + in("a1") size_of::(), in("a2") buf, lateout("a0") ret, options(nostack) @@ -99,7 +101,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 179_i32, // __NR_sysinfo in("a0") info, @@ -117,7 +119,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 123_i32, // __NR_sched_getaffinity in("a0") pid, @@ -132,7 +134,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "ecall", in("a7") 93_i32, // SYS_exit in("a0") code, diff --git a/crates/asm/src/riscv64.rs b/crates/asm/src/riscv64.rs index 65ec607..2433afe 100644 --- a/crates/asm/src/riscv64.rs +++ b/crates/asm/src/riscv64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `riscv64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 56_i64, // SYS_openat in("a0") -100_i32, // AT_FDCWD @@ -23,7 +25,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "ecall", in("a7") 63_i64, // SYS_read in("a0") fd, @@ -40,7 +42,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "ecall", in("a7") 64_i64, // SYS_write in("a0") fd, @@ -57,7 +59,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 57_i64, // SYS_close in("a0") fd, @@ -71,7 +73,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 160_i64, // SYS_uname in("a0") buf, @@ -86,7 +88,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 43_i64, // SYS_statfs in("a0") path, @@ -102,7 +104,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "ecall", in("a7") 179_i64, // __NR_sysinfo in("a0") info, @@ -120,7 +122,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "ecall", in("a7") 123_i64, // __NR_sched_getaffinity in("a0") pid, @@ -135,7 +137,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "ecall", in("a7") 93_i64, // SYS_exit in("a0") code, diff --git a/crates/asm/src/s390x.rs b/crates/asm/src/s390x.rs index 13b0ab2..243b227 100644 --- a/crates/asm/src/s390x.rs +++ b/crates/asm/src/s390x.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `s390x`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc 0", in("r1") 5_i64, // SYS_open in("r2") path, @@ -21,7 +23,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "svc 0", in("r1") 3_i64, // SYS_read in("r2") fd, @@ -37,7 +39,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "svc 0", in("r1") 4_i64, // SYS_write in("r2") fd, @@ -53,7 +55,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc 0", in("r1") 6_i64, // SYS_close in("r2") fd, @@ -67,7 +69,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc 0", in("r1") 122_i64, // SYS_uname in("r2") buf, @@ -81,7 +83,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc 0", in("r1") 99_i64, // SYS_statfs in("r2") path, @@ -96,7 +98,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "svc 0", in("r1") 116_i64, // __NR_sysinfo in("r2") info, @@ -114,7 +116,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "svc 0", in("r1") 240_i64, // __NR_sched_getaffinity in("r2") pid, @@ -129,7 +131,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "svc 0", in("r1") 1_i64, // SYS_exit in("r2") code, diff --git a/crates/asm/src/sparc.rs b/crates/asm/src/sparc.rs index e4f6353..72131bb 100644 --- a/crates/asm/src/sparc.rs +++ b/crates/asm/src/sparc.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `sparc`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -24,7 +26,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -43,7 +45,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -62,7 +64,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -79,7 +81,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -96,7 +98,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -104,7 +106,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { "1:", nr = in(reg) 234_i32, // SYS_statfs64 inlateout("o0") path => ret, - in("o1") core::mem::size_of::(), + in("o1") size_of::(), in("o2") buf, options(nostack) ); @@ -115,7 +117,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -136,7 +138,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", "bcs,a 1f", @@ -154,7 +156,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "mov {nr}, %g1", "ta 0x10", nr = in(reg) 1_i32, // SYS_exit diff --git a/crates/asm/src/sparc64.rs b/crates/asm/src/sparc64.rs index 077680e..358a7c8 100644 --- a/crates/asm/src/sparc64.rs +++ b/crates/asm/src/sparc64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `sparc64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -25,7 +27,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -45,7 +47,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -65,7 +67,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -83,7 +85,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -101,7 +103,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -120,7 +122,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -142,7 +144,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", "bcs,a %xcc, 1f", @@ -161,7 +163,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "mov {nr}, %g1", "t 0x6d", nr = in(reg) 1_i64, // SYS_exit diff --git a/crates/asm/src/x86.rs b/crates/asm/src/x86.rs index 5f8e775..cc454ac 100644 --- a/crates/asm/src/x86.rs +++ b/crates/asm/src/x86.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `x86`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -22,7 +24,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -39,7 +41,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -56,7 +58,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -71,7 +73,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -86,14 +88,14 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", "pop ebx", arg1 = in(reg) path, inlateout("eax") 268_i32 => ret, // SYS_statfs64 - in("ecx") core::mem::size_of::(), + in("ecx") size_of::(), in("edx") buf, ); ret @@ -103,7 +105,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -122,7 +124,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "push ebx", "mov ebx, {arg1:e}", "int 0x80", @@ -138,7 +140,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "mov ebx, {code:e}", "int 0x80", code = in(reg) code, diff --git a/crates/asm/src/x86_64.rs b/crates/asm/src/x86_64.rs index 5afb593..3aa4dab 100644 --- a/crates/asm/src/x86_64.rs +++ b/crates/asm/src/x86_64.rs @@ -1,11 +1,13 @@ //! Syscall implementations for `x86_64`. +use core::arch::asm; + use super::{StatfsBuf, SysInfo, UtsNameBuf}; pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", in("rax") 2_i64, // SYS_open in("rdi") path, @@ -23,7 +25,7 @@ pub unsafe fn sys_open(path: *const u8, flags: i32) -> i32 { pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall", in("rax") 0_i64, // SYS_read in("rdi") fd, @@ -42,7 +44,7 @@ pub unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize { pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { let ret: isize; - core::arch::asm!( + asm!( "syscall", in("rax") 1_i64, // SYS_write in("rdi") fd, @@ -61,7 +63,7 @@ pub unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize { pub unsafe fn sys_close(fd: i32) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", in("rax") 3_i64, // SYS_close in("rdi") fd, @@ -77,7 +79,7 @@ pub unsafe fn sys_close(fd: i32) -> i32 { pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", in("rax") 63_i64, // SYS_uname in("rdi") buf, @@ -94,7 +96,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", in("rax") 137_i64, // SYS_statfs in("rdi") path, @@ -112,7 +114,7 @@ pub unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { let ret: i64; - core::arch::asm!( + asm!( "syscall", in("rax") 99_i64, // __NR_sysinfo in("rdi") info, @@ -132,7 +134,7 @@ pub unsafe fn sys_sched_getaffinity( ) -> i32 { unsafe { let ret: i32; - core::arch::asm!( + asm!( "syscall", in("rax") 204_i64, // __NR_sched_getaffinity in("rdi") pid, @@ -149,7 +151,7 @@ pub unsafe fn sys_sched_getaffinity( pub unsafe fn sys_exit(code: i32) -> ! { unsafe { - core::arch::asm!( + asm!( "syscall", in("rax") 60_i64, // SYS_exit in("rdi") code, diff --git a/crates/benchmarks/examples/hotpath.rs b/crates/benchmarks/examples/hotpath.rs index d80b43d..2b4a780 100644 --- a/crates/benchmarks/examples/hotpath.rs +++ b/crates/benchmarks/examples/hotpath.rs @@ -2,10 +2,10 @@ //! `no_std` with its own `_start`, so it cannot host hotpath; this runs the //! same `microfetch_lib::run` from a regular std binary instead. -use std::{ffi::CString, os::unix::ffi::OsStringExt, ptr}; +use std::{env, ffi::CString, os::unix::ffi::OsStringExt, ptr}; fn main() { - let env: Vec = std::env::vars_os() + let env: Vec = env::vars_os() .map(|(key, value)| { let mut entry = key.into_vec(); entry.push(b'='); diff --git a/crates/lib/build.rs b/crates/lib/build.rs index 13eb291..9deaf1e 100644 --- a/crates/lib/build.rs +++ b/crates/lib/build.rs @@ -1,6 +1,8 @@ // Pack logo rows into a marker-delimited stream: // 1 = blue, 2 = cyan, 0 = row separator. -fn main() -> Result<(), Box> { +use std::{env, error::Error, fs}; + +fn main() -> Result<(), Box> { let rows: &[&[(u8, &str)]] = &[ &[(0, "⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀"), (1, "⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀")], &[(0, "⠀⠀⠀⠀⠀⠀⠈⢿⣿⣆⠀⠀⠀"), (1, "⠘⣿⣿⣴⣿⡿⠁⠀⠀⠀⠀⠀⠀")], @@ -38,7 +40,7 @@ fn main() -> Result<(), Box> { } } - let out_dir = std::env::var("OUT_DIR")?; - std::fs::write(format!("{out_dir}/logo.bin"), &out)?; + let out_dir = env::var("OUT_DIR")?; + fs::write(format!("{out_dir}/logo.bin"), &out)?; Ok(()) } diff --git a/crates/lib/src/cpu.rs b/crates/lib/src/cpu.rs index b544447..b73a9d1 100644 --- a/crates/lib/src/cpu.rs +++ b/crates/lib/src/cpu.rs @@ -1,3 +1,5 @@ +use core::str; + #[cfg(target_os = "linux")] use microfetch_asm::read_file_fast; @@ -19,7 +21,7 @@ pub fn write_cpu_name(writer: &mut StackWriter) { let mut buf = [0_u8; 128]; if let Some(len) = macos_sysctl_str(b"machdep.cpu.brand_string\0", &mut buf) - && let Ok(name) = core::str::from_utf8(&buf[..len]) + && let Ok(name) = str::from_utf8(&buf[..len]) { writer.push_str(name); } @@ -208,7 +210,7 @@ fn read_cpu_max_khz(cpu: u32) -> Option { let path_len = format_cpufreq_path(&mut path, cpu); // SAFETY: the path is a constant prefix, decimal digits, and a constant // suffix, so it is ASCII by construction. - let path_str = unsafe { core::str::from_utf8_unchecked(&path[..path_len]) }; + let path_str = unsafe { str::from_utf8_unchecked(&path[..path_len]) }; let mut buf = [0_u8; 32]; let len = read_file_fast(path_str, &mut buf).ok()?; let mut khz = 0_u32; @@ -571,7 +573,7 @@ fn write_dt_compatible(writer: &mut StackWriter) -> bool { let Some(comma) = entry.iter().position(|&byte| byte == b',') else { return false; }; - let Ok(model) = core::str::from_utf8(&entry[comma + 1..]) else { + let Ok(model) = str::from_utf8(&entry[comma + 1..]) else { return false; }; if model.is_empty() { @@ -604,7 +606,7 @@ fn extract_field<'data>(data: &'data [u8], key: &[u8]) -> Option<&'data str> { pos += 1; } // SAFETY: cpuinfo fields are ASCII - return Some(unsafe { core::str::from_utf8_unchecked(&line[pos..]) }); + return Some(unsafe { str::from_utf8_unchecked(&line[pos..]) }); } } diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index 1b5d448..07e4bc8 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -11,8 +11,12 @@ pub mod system; pub mod uptime; use core::{ + array, ffi::CStr, mem::MaybeUninit, + ptr, + slice, + str, sync::atomic::{AtomicPtr, Ordering}, }; @@ -44,7 +48,7 @@ impl Error { // Store the environment pointer internally,initialized from `main()`. This // helps avoid the libc dependency *completely*. -static ENVP: AtomicPtr<*const u8> = AtomicPtr::new(core::ptr::null_mut()); +static ENVP: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut()); /// Initialize the environment pointer. Must be called before any `getenv()` /// calls. This is called from `main()` with the calculated `envp`. @@ -113,7 +117,7 @@ pub fn getenv(name: &str) -> Option<&'static [u8]> { len += 1; } // SAFETY: We calculated the exact length - return Some(unsafe { core::slice::from_raw_parts(value_start, len) }); + return Some(unsafe { slice::from_raw_parts(value_start, len) }); } } @@ -132,7 +136,7 @@ pub fn getenv(name: &str) -> Option<&'static [u8]> { /// `from_utf8_unchecked`. #[must_use = "this only reads the environment"] pub fn getenv_str(name: &str) -> Option<&'static str> { - getenv(name).map(|bytes| unsafe { core::str::from_utf8_unchecked(bytes) }) + getenv(name).map(|bytes| unsafe { str::from_utf8_unchecked(bytes) }) } /// Checks if an environment variable exists (regardless of its value). @@ -195,7 +199,7 @@ impl<'buf> StackWriter<'buf> { #[inline] #[must_use = "this only borrows the written bytes"] pub const fn written(&self) -> &[u8] { - unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast(), self.pos) } + unsafe { slice::from_raw_parts(self.buf.as_ptr().cast(), self.pos) } } #[inline] @@ -207,7 +211,7 @@ impl<'buf> StackWriter<'buf> { pub fn push_bytes(&mut self, bytes: &[u8]) { let len = bytes.len().min(self.buf.len() - self.pos); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( bytes.as_ptr(), self.buf.as_mut_ptr().add(self.pos).cast(), len, @@ -424,7 +428,7 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> { let use_custom = !CUSTOM_LOGO.is_empty(); let logo_lines = if use_custom { let mut lines_iter = CUSTOM_LOGO.split('\n'); - custom_lines = core::array::from_fn(|_| lines_iter.next().unwrap_or("")); + custom_lines = array::from_fn(|_| lines_iter.next().unwrap_or("")); &custom_lines } else { &[""; ROW_COUNT] // unused, we use LOGO pairs below diff --git a/crates/lib/src/release.rs b/crates/lib/src/release.rs index b721be4..eb87b65 100644 --- a/crates/lib/src/release.rs +++ b/crates/lib/src/release.rs @@ -1,3 +1,5 @@ +#[cfg(target_os = "macos")] use core::str; + #[cfg(target_os = "linux")] use microfetch_asm::read_file_fast; @@ -23,7 +25,7 @@ pub fn write_os_pretty_name(writer: &mut StackWriter) { writer.push_str("macOS"); let mut buf = [0_u8; 64]; if let Some(len) = macos_sysctl_str(b"kern.osproductversion\0", &mut buf) - && let Ok(version) = core::str::from_utf8(&buf[..len]) + && let Ok(version) = str::from_utf8(&buf[..len]) && !version.is_empty() { writer.push_byte(b' '); diff --git a/microfetch/build.rs b/microfetch/build.rs index ecc1d2f..16f5620 100644 --- a/microfetch/build.rs +++ b/microfetch/build.rs @@ -21,7 +21,7 @@ fn main() -> io::Result<()> { // macOS cannot link statically, requires the standard C runtime startup, and // uses Mach-O (not ELF), so none of the flags below apply. The default // linker driver produces a correct (and ad-hoc code-signed) binary there. - let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); if target_os == "macos" { return Ok(()); } @@ -37,7 +37,7 @@ fn main() -> io::Result<()> { // Remove unreferenced input sections println!("cargo:rustc-link-arg-bin=microfetch=-Wl,--gc-sections"); // Strip all symbol table entries - if std::env::var("DEBUG").as_deref() != Ok("true") { + if env::var("DEBUG").as_deref() != Ok("true") { println!("cargo:rustc-link-arg-bin=microfetch=-Wl,--strip-all"); } // Omit the .note.gnu.build-id section diff --git a/microfetch/src/main.rs b/microfetch/src/main.rs index cd18d0b..84d6cdf 100644 --- a/microfetch/src/main.rs +++ b/microfetch/src/main.rs @@ -18,8 +18,12 @@ ) )] +#[cfg(all(target_arch = "powerpc64", target_abi = "elfv1"))] +use core::arch::global_asm; #[cfg(not(any(target_os = "macos", target_abi = "elfv1")))] use core::arch::naked_asm; +#[cfg(not(test))] use core::panic::PanicInfo; +#[cfg(all(not(test), target_arch = "sparc"))] use core::ptr; // The custom `_start` (and the `entry_rust` it calls) is Linux-only. #[cfg(not(any(target_os = "macos", target_abi = "elfv1")))] @@ -167,7 +171,7 @@ unsafe extern "C" fn _start() { // in .opd whose first word is the real code address. We emit both manually via // `global_asm` so the kernel reads the descriptor and jumps into `_start_impl`. #[cfg(all(target_arch = "powerpc64", target_abi = "elfv1"))] -core::arch::global_asm!( +global_asm!( ".section .opd, \"aw\"", ".balign 8", ".globl _start", @@ -279,13 +283,13 @@ unsafe extern "C" fn _start() { #[cfg(all(not(test), target_arch = "sparc"))] #[unsafe(no_mangle)] extern "C" fn __atomic_load_1(ptr: *const u8, _order: i32) -> u8 { - unsafe { core::ptr::read_volatile(ptr) } + unsafe { ptr::read_volatile(ptr) } } #[cfg(all(not(test), target_arch = "sparc"))] #[unsafe(no_mangle)] extern "C" fn __atomic_store_1(ptr: *mut u8, val: u8, _order: i32) { - unsafe { core::ptr::write_volatile(ptr, val) } + unsafe { ptr::write_volatile(ptr, val) } } #[cfg(target_arch = "mips")] @@ -334,7 +338,7 @@ pub unsafe extern "C" fn main(argc: i32, argv: *const *const u8) -> i32 { #[cfg(not(test))] #[panic_handler] -fn panic(_info: &core::panic::PanicInfo) -> ! { +fn panic(_info: &PanicInfo) -> ! { const PANIC_MSG: &[u8] = b"panic\n"; unsafe { _ = sys_write(2, PANIC_MSG.as_ptr(), PANIC_MSG.len()); From d9eb3fdb737df21b6b7a671ab955c12b8c076a42 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 13:57:23 -0400 Subject: [PATCH 12/15] lib: inline the default logo instead of generating it --- crates/lib/build.rs | 46 ------------------------------------------- crates/lib/src/lib.rs | 15 +++++++++++++- 2 files changed, 14 insertions(+), 47 deletions(-) delete mode 100644 crates/lib/build.rs diff --git a/crates/lib/build.rs b/crates/lib/build.rs deleted file mode 100644 index 9deaf1e..0000000 --- a/crates/lib/build.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Pack logo rows into a marker-delimited stream: -// 1 = blue, 2 = cyan, 0 = row separator. -use std::{env, error::Error, fs}; - -fn main() -> Result<(), Box> { - let rows: &[&[(u8, &str)]] = &[ - &[(0, "⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀"), (1, "⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀")], - &[(0, "⠀⠀⠀⠀⠀⠀⠈⢿⣿⣆⠀⠀⠀"), (1, "⠘⣿⣿⣴⣿⡿⠁⠀⠀⠀⠀⠀⠀")], - &[(0, "⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡜"), (1, "⢿⣿⣟⠀⠀⠀"), (0, "⢀⡄⠀⠀⠀")], - &[ - (0, "⠀⠀⠀⠉⠉⠉⠉"), - (1, "⣩⣭⡭"), - (0, "⠉⠉⠉⠉⠉"), - (1, "⠈⢿⣿⣆⠀"), - (0, "⢠⣿⣿⠂⠀⠀"), - ], - &[(1, "⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⢻⡟"), (0, "⣡⣿⣿⠃⠀⠀⠀")], - &[(1, "⢸⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀"), (0, "⣰⣿⣿⣿⣿⣿⣿⡇")], - &[(1, "⠀⠀⠀⢠⣿⣿⢋"), (0, "⣼⣧⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀")], - &[ - (1, "⠀⠀⠠⣿⣿⠃⠀"), - (0, "⠹⣿⣷⡀"), - (1, "⣀⣀⣀⣀⣀"), - (0, "⣚⣛⣋"), - (1, "⣀⣀⣀⣀⠀⠀⠀"), - ], - &[(1, "⠀⠀⠀⠘⠁⠀⠀⠀"), (0, "⣽⣿⣷⡜"), (1, "⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀")], - &[(0, "⠀⠀⠀⠀⠀⠀⢀⣾⣿⠟⣿⣿⡄⠀⠀⠀"), (1, "⠹⣿⣷⡀⠀⠀⠀⠀⠀⠀")], - &[(0, "⠀⠀⠀⠀⠀⠀⢺⣿⠋⠀⠈⢿⣿⣆⠀⠀⠀"), (1, "⠙⣿⡗⠀⠀⠀⠀⠀⠀")], - ]; - - let mut out = Vec::new(); - for (row_index, row) in rows.iter().enumerate() { - for &(color, text) in *row { - out.push(color + 1); - out.extend_from_slice(text.as_bytes()); - } - if row_index < rows.len() - 1 { - out.push(0); - } - } - - let out_dir = env::var("OUT_DIR")?; - fs::write(format!("{out_dir}/logo.bin"), &out)?; - Ok(()) -} diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index 07e4bc8..1e0efc8 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -267,7 +267,20 @@ const CUSTOM_LOGO: &str = match option_env!("MICROFETCH_LOGO") { }; /// Packed logo rows. `0` separates rows; `1` and `2` select colors. -const LOGO: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/logo.bin")); +const LOGO: &[u8] = concat!( + "\x01⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀\x02⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀\0", + "\x01⠀⠀⠀⠀⠀⠀⠈⢿⣿⣆⠀⠀⠀\x02⠘⣿⣿⣴⣿⡿⠁⠀⠀⠀⠀⠀⠀\0", + "\x01⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡜\x02⢿⣿⣟⠀⠀⠀\x01⢀⡄⠀⠀⠀\0", + "\x01⠀⠀⠀⠉⠉⠉⠉\x02⣩⣭⡭\x01⠉⠉⠉⠉⠉\x02⠈⢿⣿⣆⠀\x01⢠⣿⣿⠂⠀⠀\0", + "\x02⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⢻⡟\x01⣡⣿⣿⠃⠀⠀⠀\0", + "\x02⢸⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\x01⣰⣿⣿⣿⣿⣿⣿⡇\0", + "\x02⠀⠀⠀⢠⣿⣿⢋\x01⣼⣧⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀\0", + "\x02⠀⠀⠠⣿⣿⠃⠀\x01⠹⣿⣷⡀\x02⣀⣀⣀⣀⣀\x01⣚⣛⣋\x02⣀⣀⣀⣀⠀⠀⠀\0", + "\x02⠀⠀⠀⠘⠁⠀⠀⠀\x01⣽⣿⣷⡜\x02⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀\0", + "\x01⠀⠀⠀⠀⠀⠀⢀⣾⣿⠟⣿⣿⡄⠀⠀⠀\x02⠹⣿⣷⡀⠀⠀⠀⠀⠀⠀\0", + "\x01⠀⠀⠀⠀⠀⠀⢺⣿⠋⠀⠈⢿⣿⣆⠀⠀⠀\x02⠙⣿⡗⠀⠀⠀⠀⠀⠀", +) +.as_bytes(); /// Write one row from a packed color-marked byte stream. #[inline(never)] From 63defcd6ff447535d2301f8c84494820d679077f Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 13:57:23 -0400 Subject: [PATCH 13/15] treewide: drop five clippy allows --- Cargo.toml | 5 ----- crates/asm/src/lib.rs | 3 ++- crates/benchmarks/benches/microfetch.rs | 2 +- crates/benchmarks/examples/hotpath.rs | 10 +++++++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7e9f6c1..f3bb373 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,12 +47,7 @@ semicolon_inside_block = "allow" separated_literal_suffix = "allow" similar_names = "allow" single_call_fn = "allow" -std_instead_of_core = "allow" -tests_outside_test_module = "allow" -too_long_first_doc_paragraph = "allow" -too_many_lines = "allow" undocumented_unsafe_blocks = "allow" -unused_trait_names = "allow" [profile.dev] # nix's compiler_builtins carries compiler-rt objects that need libc, and only diff --git a/crates/asm/src/lib.rs b/crates/asm/src/lib.rs index 8009cc3..7a5e4d2 100644 --- a/crates/asm/src/lib.rs +++ b/crates/asm/src/lib.rs @@ -692,7 +692,8 @@ pub unsafe fn sys_exit(code: i32) -> ! { // The freestanding memory symbols exist everywhere but macOS, where // libSystem supplies them instead. -#[cfg(all(test, not(target_os = "macos")))] +#[cfg(test)] +#[cfg(not(target_os = "macos"))] mod tests { use super::*; diff --git a/crates/benchmarks/benches/microfetch.rs b/crates/benchmarks/benches/microfetch.rs index afba5bb..df863b2 100644 --- a/crates/benchmarks/benches/microfetch.rs +++ b/crates/benchmarks/benches/microfetch.rs @@ -1,4 +1,4 @@ -use std::{hint::black_box, mem::MaybeUninit}; +use core::{hint::black_box, mem::MaybeUninit}; use criterion::{Criterion, criterion_group, criterion_main}; use microfetch_lib::{ diff --git a/crates/benchmarks/examples/hotpath.rs b/crates/benchmarks/examples/hotpath.rs index 2b4a780..1914b0e 100644 --- a/crates/benchmarks/examples/hotpath.rs +++ b/crates/benchmarks/examples/hotpath.rs @@ -2,8 +2,16 @@ //! `no_std` with its own `_start`, so it cannot host hotpath; this runs the //! same `microfetch_lib::run` from a regular std binary instead. -use std::{env, ffi::CString, os::unix::ffi::OsStringExt, ptr}; +extern crate alloc; +use alloc::ffi::CString; +use core::ptr; +use std::{env, os::unix::ffi::OsStringExt as _}; + +#[expect( + clippy::expect_used, + reason = "a profiling example has nowhere to report errors" +)] fn main() { let env: Vec = env::vars_os() .map(|(key, value)| { From 83541e5520326ba588d9a691662108794a338a8c Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 14:01:58 -0400 Subject: [PATCH 14/15] treewide: annotate literals and turbofish instead of bindings --- crates/asm/src/darwin.rs | 4 ++-- crates/benchmarks/examples/hotpath.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/asm/src/darwin.rs b/crates/asm/src/darwin.rs index 03c70b5..8fcbe57 100644 --- a/crates/asm/src/darwin.rs +++ b/crates/asm/src/darwin.rs @@ -138,7 +138,7 @@ pub fn macos_sysctl_str(name: &[u8], out: &mut [u8]) -> Option { /// Read a 32-bit integer sysctl by name (e.g. `b"hw.logicalcpu\0"`). #[must_use = "this only queries the kernel"] pub fn macos_sysctl_u32(name: &[u8]) -> Option { - let mut val: u32 = 0; + let mut val = 0_u32; let mut len = size_of::(); let ret = unsafe { sysctlbyname( @@ -154,7 +154,7 @@ pub fn macos_sysctl_u32(name: &[u8]) -> Option { /// Read a 64-bit integer sysctl by name (e.g. `b"hw.memsize\0"`). fn macos_sysctl_u64(name: &[u8]) -> Option { - let mut val: u64 = 0; + let mut val = 0_u64; let mut len = size_of::(); let ret = unsafe { sysctlbyname( diff --git a/crates/benchmarks/examples/hotpath.rs b/crates/benchmarks/examples/hotpath.rs index 1914b0e..1e87a90 100644 --- a/crates/benchmarks/examples/hotpath.rs +++ b/crates/benchmarks/examples/hotpath.rs @@ -13,16 +13,18 @@ use std::{env, os::unix::ffi::OsStringExt as _}; reason = "a profiling example has nowhere to report errors" )] fn main() { - let env: Vec = env::vars_os() + let env = env::vars_os() .map(|(key, value)| { let mut entry = key.into_vec(); entry.push(b'='); entry.extend(value.into_vec()); CString::new(entry).expect("environment entries contain no NUL bytes") }) - .collect(); - let mut envp: Vec<*const u8> = - env.iter().map(|entry| entry.as_ptr().cast()).collect(); + .collect::>(); + let mut envp = env + .iter() + .map(|entry| entry.as_ptr().cast::()) + .collect::>(); envp.push(ptr::null()); let argv = [c"microfetch".as_ptr().cast::(), ptr::null()]; From 143a43a779866eaa5055cc55765a9940b644bf05 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 18 Oct 2026 14:02:31 -0400 Subject: [PATCH 15/15] treewide: drop the remaining clippy allow attributes --- Cargo.toml | 48 ++++++++++----------- crates/asm/src/darwin.rs | 36 +++------------- crates/asm/src/lib.rs | 93 +++++++++++++++++++++++++++++++++------- crates/lib/src/colors.rs | 2 +- crates/lib/src/system.rs | 10 +---- 5 files changed, 109 insertions(+), 80 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3bb373..ba00fb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,32 +22,30 @@ perf = { level = "warn", priority = -1 } restriction = { level = "warn", priority = -1 } style = { level = "warn", priority = -1 } -allow_attributes = "allow" -arbitrary_source_item_ordering = "allow" -arithmetic_side_effects = "allow" blanket_clippy_restriction_lints = "allow" -cfg_not_test = "allow" -exhaustive_enums = "allow" -exhaustive_structs = "allow" -implicit_return = "allow" -indexing_slicing = "allow" -inline_asm_x86_intel_syntax = "allow" -inline_modules = "allow" -integer_division = "allow" -integer_division_remainder_used = "allow" -missing_docs_in_private_items = "allow" -missing_inline_in_public_items = "allow" -multiple_unsafe_ops_per_block = "allow" -non_ascii_literal = "allow" -pattern_type_mismatch = "allow" -print_stdout = "allow" -pub_with_shorthand = "allow" -question_mark_used = "allow" -semicolon_inside_block = "allow" -separated_literal_suffix = "allow" -similar_names = "allow" -single_call_fn = "allow" -undocumented_unsafe_blocks = "allow" + +arbitrary_source_item_ordering = "allow" +arithmetic_side_effects = "allow" +cfg_not_test = "allow" +exhaustive_enums = "allow" +exhaustive_structs = "allow" +implicit_return = "allow" +indexing_slicing = "allow" +inline_asm_x86_intel_syntax = "allow" +inline_modules = "allow" +integer_division = "allow" +integer_division_remainder_used = "allow" +missing_docs_in_private_items = "allow" +missing_inline_in_public_items = "allow" +multiple_unsafe_ops_per_block = "allow" +pattern_type_mismatch = "allow" +pub_with_shorthand = "allow" +question_mark_used = "allow" +semicolon_inside_block = "allow" +separated_literal_suffix = "allow" +similar_names = "allow" +single_call_fn = "allow" +undocumented_unsafe_blocks = "allow" [profile.dev] # nix's compiler_builtins carries compiler-rt objects that need libc, and only diff --git a/crates/asm/src/darwin.rs b/crates/asm/src/darwin.rs index 8fcbe57..be4c6ca 100644 --- a/crates/asm/src/darwin.rs +++ b/crates/asm/src/darwin.rs @@ -1,8 +1,9 @@ //! macOS does not support a stable raw-syscall ABI the way Linux does, cannot //! be linked statically, and exposes none of the `/proc`, `/sys`, or -//! `/etc/os-release` interfaces the Linux path relies on. So instead of -//! handwritten `svc #0` traps, this module calls into `libSystem` (which is -//! always linked on macOS) via plain FFI: +//! `/etc/os-release` interfaces the Linux path relies on. +//! +//! So instead of handwritten `svc #0` traps, this module calls into `libSystem` +//! (which is always linked on macOS) via plain FFI: //! //! * file/IO + exit -> `open`/`read`/`write`/`close`/`_exit` //! * `uname(3)` -> kernel name/release/machine @@ -19,7 +20,7 @@ use core::{ ptr, }; -use super::{StatfsBuf, SysInfo, UtsNameBuf}; +use super::{StatfsBuf, UtsNameBuf}; #[link(name = "System", kind = "dylib")] unsafe extern "C" { @@ -83,31 +84,6 @@ pub(crate) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 { unsafe { statfs(path.cast::(), buf) } } -/// macOS has no `sysinfo(2)`; uptime comes from [`macos_uptime_secs`] instead. -/// This stub exists only so the generic wrapper in `lib.rs` keeps compiling. -#[allow( - clippy::missing_const_for_fn, - reason = "keeps the signature of the syscall it stands in for" -)] -pub(crate) unsafe fn sys_sysinfo(_info: *mut SysInfo) -> i64 { - -1 -} - -/// macOS has no `sched_getaffinity(2)`; core counts come from `sysctl` -/// (`hw.logicalcpu` / `hw.physicalcpu`). This stub keeps the generic wrapper -/// compiling. -#[allow( - clippy::missing_const_for_fn, - reason = "keeps the signature of the syscall it stands in for" -)] -pub(crate) unsafe fn sys_sched_getaffinity( - _pid: i32, - _mask_size: usize, - _mask: *mut u8, -) -> i32 { - -1 -} - pub(crate) unsafe fn sys_exit(code: i32) -> ! { unsafe { _exit(code) } } @@ -175,7 +151,6 @@ const HOST_VM_INFO64: c_int = 4; /// `host_statistics64` matches the kernel's expectation exactly (38 ints). #[repr(C)] #[derive(Default)] -#[allow(dead_code, reason = "most fields exist only to fix the struct layout")] struct VmStatistics64 { free_count: u32, active_count: u32, @@ -241,7 +216,6 @@ pub fn macos_meminfo() -> Option<(u64, u64)> { /// `struct timeval` (`time_t` is 64-bit, `suseconds_t` is 32-bit on macOS). #[repr(C)] #[derive(Default)] -#[allow(dead_code, reason = "tv_usec/_pad exist only to fix the struct layout")] struct Timeval { tv_sec: i64, tv_usec: i32, diff --git a/crates/asm/src/lib.rs b/crates/asm/src/lib.rs index 7a5e4d2..9ab1868 100644 --- a/crates/asm/src/lib.rs +++ b/crates/asm/src/lib.rs @@ -380,7 +380,7 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 { /// /// Linux ABI (`x86_64` and `aarch64`): the fields we use are at the same /// offsets on both architectures. Only the fields needed for disk usage are -/// declared; the remainder of the 120-byte struct is covered by `_pad`. +/// declared; the remainder of the 120-byte struct is covered by `spare`. #[repr(C)] #[cfg(not(any( target_os = "macos", @@ -406,13 +406,32 @@ pub struct StatfsBuf { pub f_frsize: i64, pub f_flags: i64, - #[allow(clippy::pub_underscore_fields, reason = "This is not a public API")] - pub _pad: [i64; 4], + pub spare: [i64; 4], +} + +#[cfg(not(any( + target_os = "macos", + target_arch = "s390x", + target_arch = "arm", + target_arch = "riscv32", + target_arch = "x86", + target_arch = "powerpc", + target_arch = "sparc", + target_arch = "mips64", + target_arch = "mips" +)))] +impl StatfsBuf { + #[must_use = "this only reads a field"] + pub const fn block_size(&self) -> u64 { + self.f_bsize.unsigned_abs() + } } /// macOS `struct statfs` (the 64-bit/`INODE64` ABI, which is the only one on -/// arm64). Only `f_bsize`, `f_blocks`, and `f_bavail` are read; the rest is -/// declared to give the struct its correct size and field offsets. +/// arm64). +/// +/// Only `f_bsize`, `f_blocks`, and `f_bavail` are read; the rest is declared +/// to give the struct its correct size and field offsets. #[repr(C)] #[cfg(target_os = "macos")] pub struct StatfsBuf { @@ -435,6 +454,14 @@ pub struct StatfsBuf { pub f_reserved: [u32; 7], } +#[cfg(target_os = "macos")] +impl StatfsBuf { + #[must_use = "this only reads a field"] + pub fn block_size(&self) -> u64 { + u64::from(self.f_bsize) + } +} + /// on s390x `f_type` and `f_bsize` are 32-bit. #[repr(C)] #[cfg(target_arch = "s390x")] @@ -451,8 +478,15 @@ pub struct StatfsBuf { pub f_frsize: u32, pub f_flags: u32, - #[allow(clippy::pub_underscore_fields, reason = "This is not a public API")] - pub _pad: [u32; 5], + pub spare: [u32; 5], +} + +#[cfg(target_arch = "s390x")] +impl StatfsBuf { + #[must_use = "this only reads a field"] + pub fn block_size(&self) -> u64 { + u64::from(self.f_bsize) + } } /// on armv7 `statfs64(2)` has 32-bit word fields; see @@ -478,8 +512,21 @@ pub struct StatfsBuf { pub f_frsize: u32, pub f_flags: u32, - #[allow(clippy::pub_underscore_fields, reason = "This is not a public API")] - pub _pad: [u32; 4], + pub spare: [u32; 4], +} + +#[cfg(any( + target_arch = "arm", + target_arch = "riscv32", + target_arch = "x86", + target_arch = "powerpc", + target_arch = "sparc" +))] +impl StatfsBuf { + #[must_use = "this only reads a field"] + pub fn block_size(&self) -> u64 { + u64::from(self.f_bsize) + } } /// mips (O32) uses `compat_statfs64`, same reordering with 32-bit words; see @@ -500,8 +547,15 @@ pub struct StatfsBuf { pub f_namelen: u32, pub f_flags: u32, - #[allow(clippy::pub_underscore_fields, reason = "This is not a public API")] - pub _pad2: [u32; 5], + pub spare: [u32; 5], +} + +#[cfg(target_arch = "mips")] +impl StatfsBuf { + #[must_use = "this only reads a field"] + pub fn block_size(&self) -> u64 { + u64::from(self.f_bsize) + } } /// mips reorders fields; see @@ -521,8 +575,15 @@ pub struct StatfsBuf { pub f_namelen: i64, pub f_flags: i64, - #[allow(clippy::pub_underscore_fields, reason = "This is not a public API")] - pub _pad: [i64; 5], + pub spare: [i64; 5], +} + +#[cfg(target_arch = "mips64")] +impl StatfsBuf { + #[must_use = "this only reads a field"] + pub const fn block_size(&self) -> u64 { + self.f_bsize.unsigned_abs() + } } /// Direct `statfs(2)` syscall. @@ -590,6 +651,7 @@ pub fn read_file_fast(path: &str, buffer: &mut [u8]) -> Result { /// `mem_unit` ends at offset 108, then 4 bytes of implicit padding to 112. #[repr(C)] #[cfg(not(any( + target_os = "macos", target_arch = "arm", target_arch = "riscv32", target_arch = "x86", @@ -642,8 +704,7 @@ pub struct SysInfo { pub totalhigh: u32, pub freehigh: u32, pub mem_unit: u32, - #[allow(clippy::pub_underscore_fields, reason = "This is not a public API")] - pub _f: [u8; 8], + pub spare: [u8; 8], } /// Direct `sysinfo(2)` syscall. @@ -655,6 +716,7 @@ pub struct SysInfo { /// # Safety /// /// The caller must ensure that `info` points to a valid `SysInfo` buffer. +#[cfg(not(target_os = "macos"))] #[inline] pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { unsafe { arch::sys_sysinfo(info) } @@ -671,6 +733,7 @@ pub unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 { /// /// The caller must ensure that `mask` points to a buffer of at least /// `mask_size` bytes. +#[cfg(not(target_os = "macos"))] #[inline] pub unsafe fn sys_sched_getaffinity( pid: i32, diff --git a/crates/lib/src/colors.rs b/crates/lib/src/colors.rs index e16c8d1..8373b3d 100644 --- a/crates/lib/src/colors.rs +++ b/crates/lib/src/colors.rs @@ -54,7 +54,7 @@ pub fn write_dots(writer: &mut StackWriter, colors: &Colors) { colors.magenta, ] { writer.push_str(color); - writer.push_str("● "); + writer.push_str("\u{25cf} "); } writer.push_str(colors.reset); } diff --git a/crates/lib/src/system.rs b/crates/lib/src/system.rs index 264db8f..19c2e13 100644 --- a/crates/lib/src/system.rs +++ b/crates/lib/src/system.rs @@ -46,14 +46,8 @@ pub fn write_root_disk_usage(writer: &mut StackWriter, colors: &Colors) { } let vfs = unsafe { vfs_buf.assume_init() }; - #[allow( - clippy::unnecessary_fallible_conversions, - reason = "f_bsize is a signed long on most targets but u32 on macOS, \ - s390x, and 32-bit" - )] - let Some(block_size) = u64::try_from(vfs.f_bsize).ok() else { - return; - }; + let block_size = vfs.block_size(); + let total_blocks = vfs.f_blocks; let available_blocks = vfs.f_bavail;