pthread and shadow cleanup
This commit is contained in:
+10
-10
@@ -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::<RlctAttr>()).detachstate as _) };
|
||||
unsafe { ptr::write(detachstate, (*attr.cast::<RlctAttr>()).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::<RlctAttr>()).guardsize) };
|
||||
unsafe { ptr::write(size, (*attr.cast::<RlctAttr>()).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::<RlctAttr>()).inheritsched as _) };
|
||||
unsafe { ptr::write(inheritsched, (*attr.cast::<RlctAttr>()).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::<RlctAttr>()).schedpolicy as _) };
|
||||
unsafe { ptr::write(policy, (*attr.cast::<RlctAttr>()).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::<RlctAttr>()).scope as _) };
|
||||
unsafe { ptr::write(scope, (*attr.cast::<RlctAttr>()).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::<RlctAttr>()).stack as _) };
|
||||
unsafe { core::ptr::write(stacksize, (*attr.cast::<RlctAttr>()).stacksize as _) };
|
||||
unsafe { ptr::write(stackaddr, (*attr.cast::<RlctAttr>()).stack as _) };
|
||||
unsafe { ptr::write(stacksize, (*attr.cast::<RlctAttr>()).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::<RlctAttr>()).stacksize as _) };
|
||||
unsafe { ptr::write(stacksize, (*attr.cast::<RlctAttr>()).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>(), RlctAttr::default()) };
|
||||
unsafe { ptr::write(attr.cast::<RlctAttr>(), RlctAttr::default()) };
|
||||
0
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ pub use self::rwlock::*;
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_self.html>.
|
||||
#[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 <https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_setcancelstate.html>.
|
||||
|
||||
+14
-16
@@ -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<DestBuffer>) -> Result<OwnedSpwd, Er
|
||||
MaybeAllocated::Borrowed(buf)
|
||||
}
|
||||
None => {
|
||||
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<DestBuffer>) -> Result<OwnedSpwd, Er
|
||||
pwd_slice[..sp_pwdp_str.len()].copy_from_slice(sp_pwdp_str.as_bytes());
|
||||
pwd_slice[sp_pwdp_str.len()] = 0;
|
||||
|
||||
let sp_namp = name_slice.as_mut_ptr() as *mut c_char;
|
||||
let sp_pwdp = pwd_slice.as_mut_ptr() as *mut c_char;
|
||||
let sp_namp = name_slice.as_mut_ptr().cast::<c_char>();
|
||||
let sp_pwdp = pwd_slice.as_mut_ptr().cast::<c_char>();
|
||||
|
||||
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::<u8>(),
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user