Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions crates/fspy_client_unix/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn get_fd_path<A: Allocator>(allocator: A, fd: BorrowedFd<'_>) -> nix::Result<Op
let path = proc_fd_path(fd, &mut path);
match fspy_nostd_alloc::fs::readlinkat(allocator, CWD, path) {
Ok(path) => Ok(Some(path)),
Err(fspy_nostd::Errno::BADF | fspy_nostd::Errno::NOENT) => Ok(None),
Err(fspy_nostd::Error::BADF | fspy_nostd::Error::NOENT) => Ok(None),
Err(errno) => Err(nix::errno::Errno::from_raw(errno.raw_os_error())),
}
}
Expand Down Expand Up @@ -61,7 +61,7 @@ fn get_fd_path<A: Allocator>(allocator: A, fd: BorrowedFd<'_>) -> nix::Result<Op
// converting its allocation into the returned path.
Ok(Some(path.count().into_bytes()))
}
Err(fspy_nostd::Errno::BADF | fspy_nostd::Errno::NOENT) => Ok(None),
Err(fspy_nostd::Error::BADF | fspy_nostd::Error::NOENT) => Ok(None),
Err(errno) => Err(nix::errno::Errno::from_raw(errno.raw_os_error())),
}
}
Expand All @@ -72,9 +72,9 @@ pub trait ToAbsolutePath {
///
/// The result is a C string so that callers forwarding it to an exec —
/// which needs a terminator — cannot be handed unterminated bytes;
/// [`as_bytes`] gives the path without the NUL.
/// [`as_units`] gives the path without the NUL.
///
/// [`as_bytes`]: fspy_nostd::CStr::as_bytes
/// [`as_units`]: fspy_nostd::CStr::as_units
///
/// # Errors
///
Expand Down Expand Up @@ -103,7 +103,7 @@ impl ToAbsolutePath for BorrowedFd<'_> {
// SAFETY: a resolved descriptor path carries no interior NUL, and
// exactly one was appended above. The storage stays in `allocator`
// until it is dropped, which for a per-call arena ends the call.
Ok(Some(unsafe { fspy_nostd::CStr::from_bytes_with_nul_unchecked(path.leak()) }))
Ok(Some(unsafe { fspy_nostd::CStr::from_units_with_nul_unchecked(path.leak()) }))
}
}

Expand All @@ -119,7 +119,9 @@ impl PathAt<'_, '_> {
#[must_use]
pub const unsafe fn borrow_raw(fd: c_int, path: *const c_char) -> Self {
// SAFETY: both invariants are upheld by the caller.
Self(unsafe { BorrowedFd::borrow_raw(fd) }, unsafe { fspy_nostd::CStr::from_ptr(path) })
Self(unsafe { BorrowedFd::borrow_raw(fd) }, unsafe {
fspy_nostd::CStr::from_ptr(path.cast())
})
}
}

Expand All @@ -132,7 +134,7 @@ impl ToAbsolutePath for PathAt<'_, '_> {
Self: 'a,
{
let counted = self.1.count();
let pathname = counted.as_bytes();
let pathname = counted.as_units();

if pathname.starts_with(b"/") {
// Already absolute, and already NUL-terminated by the caller.
Expand All @@ -152,7 +154,7 @@ impl ToAbsolutePath for PathAt<'_, '_> {
// interior NUL — both come from C strings or the kernel — and
// exactly one was appended above. The storage stays in
// `allocator` until it is dropped.
Ok(Some(unsafe { fspy_nostd::CStr::from_bytes_with_nul_unchecked(base.leak()) }))
Ok(Some(unsafe { fspy_nostd::CStr::from_units_with_nul_unchecked(base.leak()) }))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fspy_client_unix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ impl Client {
let Some(abs_path) = path.to_absolute_path(&arena)? else {
return Ok(());
};
self.send(mode, Path::new(OsStr::from_bytes(abs_path.as_bytes())))
self.send(mode, Path::new(OsStr::from_bytes(abs_path.as_units())))
}
}
3 changes: 3 additions & 0 deletions crates/fspy_nostd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ atoi = { version = "3.1.0", default-features = false }
rustix = { workspace = true, features = ["runtime"] }
syscalls = { workspace = true }

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_System_LibraryLoader"] }

# Cross-validates the page-size probe against rustix's auxv-based answer.
[target.'cfg(target_os = "linux")'.dev-dependencies]
rustix = { workspace = true, features = ["param"] }
Expand Down
3 changes: 2 additions & 1 deletion crates/fspy_nostd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Low-level operations for fspy code that runs before a process runtime is ready or in a context where normal runtime code can deadlock.

The current implementation supports Linux and macOS. The crate has no Windows backend yet.
The current implementation supports Linux, macOS, and Windows.

## Execution contexts

Expand Down Expand Up @@ -58,3 +58,4 @@ Code that needs allocation uses an explicit allocator. [`fspy_nostd_alloc`](../f
- `env`: allocation-free process argument and environment iteration.
- `fs`: filesystem operations with caller-owned buffers.
- `param`: page-size access.
- `get_module_handle`: allocation-free lookup of an already-loaded Windows module.
Loading
Loading