use rusl::platform::{GidT, UidT};
use rusl::string::unix_str::UnixStr;
use tiny_start::elf::aux::AuxValues;
pub(crate) static mut AUX_VALUES: AuxValues = AuxValues::zeroed();
#[inline]
#[must_use]
#[expect(clippy::cast_possible_truncation)]
pub fn get_gid() -> GidT {
unsafe { AUX_VALUES.at_gid as GidT }
}
#[inline]
#[must_use]
#[expect(clippy::cast_possible_truncation)]
pub fn get_uid() -> UidT {
unsafe { AUX_VALUES.at_uid as UidT }
}
#[inline]
#[must_use]
pub fn get_random() -> Option<u128> {
unsafe {
let random_addr = AUX_VALUES.at_random;
if random_addr != 0 {
let random_bytes = random_addr as *const u8;
let unbounded_slice = core::slice::from_raw_parts(random_bytes, 16);
return Some(u128::from_ne_bytes(
unbounded_slice.try_into().unwrap_unchecked(),
));
}
None
}
}
#[inline]
#[must_use]
pub fn get_exec_fn() -> Option<&'static UnixStr> {
unsafe {
let fn_addr = AUX_VALUES.at_execfn;
if fn_addr != 0 {
return Some(UnixStr::from_ptr(fn_addr as *const u8));
}
None
}
}