Skip to content

Conversation

@newpavlov
Copy link
Member

@newpavlov newpavlov commented Dec 10, 2025

This PR refactors util_libc, sanitizer, and lazy modules. The modules are moved into the utils directory and "mounted" with #[path = ".."]. With this change all uses of #[path = ".."] point towards the utils directory.

@newpavlov newpavlov requested a review from josephlr December 10, 2025 13:15
res if res > 0 => {
let len = usize::try_from(res).map_err(|_| Error::UNEXPECTED)?;
let (l, r) = buf.split_at_mut_checked(len).ok_or(Error::UNEXPECTED)?;
unsafe { sanitizer::unpoison(l) };
Copy link
Member Author

@newpavlov newpavlov Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it applies unpoison to all users of sys_fill_exact. It's redundant in some cases (e.g. when we read from /dev/urandom), but AFAIK it has no negative consequences (outside of outlandish scenarios of misbehaving libc), while allowing to simplify the code a fair bit.

#[path = "../util_libc.rs"]
mod util_libc;
#[path = "../utils/get_errno.rs"]
mod utils;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move imports of errno_location for 4 targets which use this backends here, but I don't think it's worth the trouble since all 4 targets use different names.

Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, esp. the changes to get_errno.


pub(crate) use get_errno::get_errno;

pub(crate) fn sys_fill_exact(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fn lost its doc which should still be valid and has some (internal) use.

Comment on lines 150 to 167
loop {
let ret = unsafe { getrandom_syscall(dest.as_mut_ptr().cast(), dest.len(), 0) };
unsafe { sanitizer::unpoison_linux_getrandom_result(dest, ret) };
match usize::try_from(ret) {
Ok(0) => return Err(Error::UNEXPECTED),
Ok(len) => {
dest = dest.get_mut(len..).ok_or(Error::UNEXPECTED)?;
let (l, r) = dest.split_at_mut_checked(len).ok_or(Error::UNEXPECTED)?;
unsafe { utils::unpoison(l) };
dest = r;
if dest.is_empty() {
return Ok(());
}
}
Err(_) if ret == EINTR => continue,
Err(_) => {
let code = i32::try_from(ret).map_err(|_| Error::UNEXPECTED)?;
return Err(Error::from_neg_error_code(code));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this use sys_fill_exact?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants