From c8790352886cd8f4a3b440991e5eff8ce72f8251 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 23 Feb 2026 16:28:26 +0000 Subject: [PATCH] pthread and shadow cleanup --- src/header/pthread/attr.rs | 20 ++++++++++---------- src/header/pthread/mod.rs | 2 +- src/header/shadow/mod.rs | 30 ++++++++++++++---------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/header/pthread/attr.rs b/src/header/pthread/attr.rs index 3061fba974..a975f9ea75 100644 --- a/src/header/pthread/attr.rs +++ b/src/header/pthread/attr.rs @@ -36,7 +36,7 @@ impl Default for RlctAttr { #[unsafe(no_mangle)] pub unsafe extern "C" fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> c_int { - unsafe { core::ptr::drop_in_place(attr) }; + unsafe { ptr::drop_in_place(attr) }; 0 } @@ -45,7 +45,7 @@ pub unsafe extern "C" fn pthread_attr_getdetachstate( attr: *const pthread_attr_t, detachstate: *mut c_int, ) -> c_int { - unsafe { core::ptr::write(detachstate, (*attr.cast::()).detachstate as _) }; + unsafe { ptr::write(detachstate, (*attr.cast::()).detachstate.into()) }; 0 } @@ -54,7 +54,7 @@ pub unsafe extern "C" fn pthread_attr_getguardsize( attr: *const pthread_attr_t, size: *mut size_t, ) -> c_int { - unsafe { core::ptr::write(size, (*attr.cast::()).guardsize) }; + unsafe { ptr::write(size, (*attr.cast::()).guardsize) }; 0 } @@ -63,7 +63,7 @@ pub unsafe extern "C" fn pthread_attr_getinheritsched( attr: *const pthread_attr_t, inheritsched: *mut c_int, ) -> c_int { - unsafe { core::ptr::write(inheritsched, (*attr.cast::()).inheritsched as _) }; + unsafe { ptr::write(inheritsched, (*attr.cast::()).inheritsched.into()) }; 0 } @@ -81,7 +81,7 @@ pub unsafe extern "C" fn pthread_attr_getschedpolicy( attr: *const pthread_attr_t, policy: *mut c_int, ) -> c_int { - unsafe { core::ptr::write(policy, (*attr.cast::()).schedpolicy as _) }; + unsafe { ptr::write(policy, (*attr.cast::()).schedpolicy.into()) }; 0 } @@ -90,7 +90,7 @@ pub unsafe extern "C" fn pthread_attr_getscope( attr: *const pthread_attr_t, scope: *mut c_int, ) -> c_int { - unsafe { core::ptr::write(scope, (*attr.cast::()).scope as _) }; + unsafe { ptr::write(scope, (*attr.cast::()).scope.into()) }; 0 } @@ -100,8 +100,8 @@ pub unsafe extern "C" fn pthread_attr_getstack( stackaddr: *mut *mut c_void, stacksize: *mut size_t, ) -> c_int { - unsafe { core::ptr::write(stackaddr, (*attr.cast::()).stack as _) }; - unsafe { core::ptr::write(stacksize, (*attr.cast::()).stacksize as _) }; + unsafe { ptr::write(stackaddr, (*attr.cast::()).stack as _) }; + unsafe { ptr::write(stacksize, (*attr.cast::()).stacksize as _) }; 0 } @@ -110,13 +110,13 @@ pub unsafe extern "C" fn pthread_attr_getstacksize( attr: *const pthread_attr_t, stacksize: *mut size_t, ) -> c_int { - unsafe { core::ptr::write(stacksize, (*attr.cast::()).stacksize as _) }; + unsafe { ptr::write(stacksize, (*attr.cast::()).stacksize as _) }; 0 } #[unsafe(no_mangle)] pub unsafe extern "C" fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int { - unsafe { core::ptr::write(attr.cast::(), RlctAttr::default()) }; + unsafe { ptr::write(attr.cast::(), RlctAttr::default()) }; 0 } diff --git a/src/header/pthread/mod.rs b/src/header/pthread/mod.rs index 62774a0b9d..f7315fa25f 100644 --- a/src/header/pthread/mod.rs +++ b/src/header/pthread/mod.rs @@ -232,7 +232,7 @@ pub use self::rwlock::*; /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn pthread_self() -> pthread_t { - (unsafe { pthread::current_thread().unwrap_unchecked() }) as *const _ as *mut _ + core::ptr::from_ref(unsafe { pthread::current_thread().unwrap_unchecked() }) as *mut _ } /// See . diff --git a/src/header/shadow/mod.rs b/src/header/shadow/mod.rs index a2537eae92..0f92b109b7 100644 --- a/src/header/shadow/mod.rs +++ b/src/header/shadow/mod.rs @@ -6,7 +6,7 @@ use core::{ str::FromStr, }; -use alloc::{boxed::Box, string::String, vec::Vec}; +use alloc::{boxed::Box, string::String}; use crate::{ c_str::CStr, @@ -145,8 +145,7 @@ fn parse_spwd(line: String, destbuf: Option) -> Result { - let mut vec = Vec::with_capacity(string_data_len); - vec.resize(string_data_len, 0); + let vec = vec![0; string_data_len]; MaybeAllocated::Owned(Box::into_pin(vec.into_boxed_slice())) } }; @@ -159,8 +158,8 @@ fn parse_spwd(line: String, destbuf: Option) -> Result(); + let sp_pwdp = pwd_slice.as_mut_ptr().cast::(); let reference = spwd { sp_namp, @@ -186,10 +185,10 @@ pub unsafe extern "C" fn getspnam(name: *const c_char) -> *mut spwd { for line in BufReader::new(db).lines() { let Ok(line) = line else { continue }; - if line.starts_with(c_name.to_str().unwrap_or("\0")) { - if let Ok(pwd) = parse_spwd(line, None) { - return pwd.into_global(); - } + if line.starts_with(c_name.to_str().unwrap_or("\0")) + && let Ok(pwd) = parse_spwd(line, None) + { + return pwd.into_global(); } } ptr::null_mut() @@ -214,7 +213,7 @@ pub unsafe extern "C" fn getspnam_r( let Ok(line) = line else { continue }; if line.starts_with(c_name) { let dest_buf = Some(DestBuffer { - ptr: buffer as *mut u8, + ptr: buffer.cast::(), len: buflen, }); return match parse_spwd(line, dest_buf) { @@ -256,12 +255,11 @@ pub unsafe extern "C" fn getspent() -> *mut spwd { setspent(); } } - if let Some(lines) = line_reader { - if let Some(Ok(line)) = lines.next() { - if let Ok(sp) = parse_spwd(line, None) { - return sp.into_global(); - } - } + if let Some(lines) = line_reader + && let Some(Ok(line)) = lines.next() + && let Ok(sp) = parse_spwd(line, None) + { + return sp.into_global(); } ptr::null_mut() }