pub fn find_in_directory<T>(
path: &Path,
visit: impl FnMut(&OsStr) -> Option<T>,
) -> Result<Option<T>>Expand description
Calls visit with each name in directory path, without . and ..,
in the kernel’s order, until it returns Some, and returns that value
(None when every name was visited).
Read with raw getdents64 into one fixed buffer from Rust’s allocator,
never with std::fs::read_dir: that calls glibc’s opendir, whose
directory buffer comes from the C library’s malloc. Under in-guest
LiteInst, Detcore runs inside the guest and that heap is the guest’s: the
freed buffer would keep the kernel’s bytes (raw /proc inode numbers, say)
where the guest’s next allocation finds them, so the guest could observe
host-chosen data, for example in the padding of its own getdents64
records. Rust’s allocator is private to the runtime there (inside a Tool
callback or an allocation scope). The names are streamed, not collected,
so a directory of any size costs the one buffer.