]> git.lizzy.rs Git - rust.git/commit - compiler/rustc_log/src/lib.rs
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
authorMatthias Krüger <matthias.krueger@famsik.de>
Sat, 14 Jan 2023 17:45:26 +0000 (18:45 +0100)
committerGitHub <noreply@github.com>
Sat, 14 Jan 2023 17:45:26 +0000 (18:45 +0100)
commit43134714f529d087aecb8c6327ca282c2fa261f1
tree95e1e490c4697b591a7570ab761ad250d2a27113
parentd7bc758638772dbc5718eb33347998cfce0bee5e
parentb49aa8d53e2e1424f5d9997734cfd71b2ae647b4
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum

Stop probing for statx unless necessary

As is the current toy program:
fn main() -> std::io::Result<()> {
    use std::fs;

    let metadata = fs::metadata("foo.txt")?;

    assert!(!metadata.is_dir());
    Ok(())
}

... observed under strace will issue:
[snip]
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address) statx(AT_FDCWD, "foo.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0

While statx is not necessarily always present, checking for it can be delayed to the first error condition. Said condition may very well never happen, in which case the check got avoided altogether.

Note this is still suboptimal as there still will be programs issuing it, but bulk of the problem is removed.

Tested by forbidding the syscall for the binary and observing it correctly falls back to newfstatat.

While here tidy up the commentary, in particular by denoting some problems with the current approach.