* Fix the tests to run on 1.48.
This puts the benchmarks behind a `criterion` cfg, so add
`--cfg=criterion` to RUSTFLAGS when running cargo bench.
An MSRV of 1.48 enables us to support users such as async-io, which also
has an MSRV of 1.48.
* Add a rust-version field.
This prints a warning under Rust 1.48, but only when rustix is the
top-level build; when rustix is a dependency, it doesn't warn, so this
seems ok.
Move `fcntl_getfd`, `fcntl_setfd`, and `fcntl_dupfd_cloexec` out of
the `fs` module and into the `io` module, since they're not specific
to files, directories or memfd. This allows them to be used with the
"fs" feature is not enabled.
Also, add public aliases for then in `fs`, for compatibility, and to
have a place where all `fcntl` function are present.
And add a CI check for --no-default-features with no API features.
Fixes#453.
Rustix no longer has anything in the tree that needs the `fs` module
when the public "fs" feature isn't enabled, so make the `fd` module
conditional on `cfg(feature = "fs")`.
* Enable the "close" feature for io-lifetimes.
This follows up on #422, but enables "close" on the regular dependency
too, and not just the dev-dependency.
* Temporarily disable the backends no-libc test.
* Fix compilation on sparc targets.
Adjust cfg's as needed to fix compilation errors on sparc.
Fixes#408.
* Rust's 32-bit sparc Linux target has a 32-bit time_t.
Add a tier-3 CI check for x86_64-unknown-dragonfly, and fix the
compilation errors needed to compile with --features=all-apis.
This builds on top of #409!
Remove rustix::io::OwnedFd, and just use the std and io_lifetimes'
OwnedFd definition. Now that rustix is using io_lifetimes 1.0, which has
switched to using the `OwnedFd` in std, this is no longer needed.
This simplifies rustix' API, as users no longer have to be aware of the
difference between rustix::io::OwnedFd and rustix::fd::OwnedFd.
The main change here is the removal of `FromFd` and `IntoFd` in favor of
`From<OwnedFd>` and `impl<T> or OwnedFd`.
This also adds impls for std types for rustix::io::OwnedFd to make it
less inconvenient to work with.
Rustix's statx code now depends on linux-raw-sys, in order to obtain
Linux's `STATX__RESERVED` value, which musl doesn't export. As such,
always enable the linux-raw-sys dependency on Linux targets.
Fixes#389.
* Switch from `.init_array` constructors to /proc/self/auxv.
In the linux_raw backend, switch from using a `.init_array` constructor
for obtaining the aux values to reading them from /proc/self/auxv. This avoids
problems in situation where other Rust code can run before the constructor,
potentially distrupting the `__environ` value.
Also, for the linux_raw backend, introduce a new "use-libc-auxv" feature,
which enables use of libc to read the aux values, instead of reading
them from /proc/self/auxv.
The "use-libc-auxv" option is enabled by default, because it's more
efficient and doesn't depend on /proc, so it's likely better for most
users.
Mustang, for its part, continues to be able to use the incoming auxv on
the stack because it controls program startup. Since it doesn't have to
worry about the hazards of /proc or QEMU, it can trust the incoming
values, and do less checking.
Fixes#382.
* Remove the param `init` function from the libc backend.
* Fix the no-std build.
* Fix the backends test to accept that the default options now depend on libc.
* Use `NonNull` in `check_raw_pointer`'s return type.
This allows it to pack the return value into a single pointer-sized
value.
* Update more code to the new `check_raw_pointer` API.
* Fix an unused-import warning.
* Fix copy+paste.
* Thread `check_elf_base` through `check_vdso_base` too.
* Add a `Result` to `getpgid`, and add `getpgrp`.
Add a `Result` return type to `getpgid`, as it can fail if there's no
process with the given pid.
And, add a a `getpgrp` function, which is similar to `getpgid`, but
doesn't take a pid argument and always operates on the current process,
which means it doesn't need a `Result` return type.
* Use `getpgid` on platforms which don't have a `getpgrp` syscall.
* Guard against future `statx` fields.
Future versions of Linux may recognize new `statx` mask flags, which
enable writing to new `struct statx` fields. If a rustix user constructs
a flags value with `from_bits_unchecked`, they could potentially create
a flags value that causes `statx` on such a future Linux version to write
fields outside the buffer, evoking undefined behavior.
This is very unlikely to be a practical problem today, because:
- Scanning all known public users of rustix, I don't see any constructing
`StatxFlags` values this way.
- It's unlikely that any rustix user would ever have a need to construct
`StatxFlags` values this way.
- No existing version of Linux increases the size of `struct statx`
beyond what rustix currently knows about.
- `struct statx` contains several spare fields, including a
`__u64 __spare3[12]` specifically for expansion, so even if a future
Linux version defines new fields, it has lots of space available before
it needs to start increasing the size of `struct statx`.
* Implement `statvfs` and `fstatvfs`.
On libc, just go with whatever the libc `statvfs` gives us. On
linux_raw, translate the fields from `statfs` in the manner of
libc implementations.
* Preserve as much of the `f_fsid` field as possible.
* Document the relationship between `statfs` and `statvfs`.
* Add a `StatVfsMountFlags` type for the `f_flag` field.
Wrap long lines that were hidden from rustfmt by macros, be consistent
about trailing commas in `cfg`s, alphabetize operands to `any`/`all`,
and add some comments.
* Avoid using `.init_array` and `__environ` on non-musl non-glibc platforms.
Don't assume that non-musl non-glibc platforms have `.init_array` and
`__environ`; use an explicit `init` function on such platforms, and add a
`debug_assert` to check that it's called.
* Add a safety comment.
* Move the auxv functions into a new top-level "param" module.
"param" is short for "process parameter".
* Use `CStr` instead of `ZStr`.
* Remove `ZStr` and `ZString`.
Use `CStr` and `CString` instead, now that nightly has then in core and
alloc, respectively.
Fixes#336.
* Enable "core_c_str" on nightly to use core::ffi::CStr.
* Don't test --no-default-features on stable.
--no-default-features disables "std", and building without "std" will
require nightly now.
* `CString` and `NulError` are in alloc.
* Add comments to the relevant Cargo.toml features.
* rustfmt
And similar for `dup3`.
The idea behind using `&OwnedFd` is that `dup2`'s second operand isn't like a
normal borrow. It effectively closes the old file descriptor, and creates a
new one with the same index. This could break assumptions of classes that have
an `AsFd` to allow users to do special I/O operations, but which don't expect
users can close and reopen their file descriptor as some completely unrelated
resource.
However, the existence of things like [`FilelikeView`], as well as the
`ManuallyDrop` pattern, mean that `&OwnedFd` doesn't actually prevent
users from using `dup2` on a `BorrowedFd`.
With sunfishcode/io-lifetimes#32 though, `&mut OwnedFd` would be
sufficient, because it removes the `DerefMut` implementation.
So change `rustix` stance to be that `dup2` requires `&mut OwnedFd`.
This means that it's no longer possible to pass the same file descriptor
to both operands of `dup2` or `dup3` with safe Rust, which means it's not
possible to observe the difference in behavior in that case, so remove
the `dup3.rs` test.
[`FilelikeView`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/views/struct.FilelikeView.html
* Add comments.
* Fix a redundant word.
* Fix more redundant words.
* Fix a heading level in README.md.
* Fix line-wrapping in README.md.
* Fix typos in comments.
* Replace tabs with spaces.
* Fix a broken doc link.
* Reformat some comments.
* Add more comments.
* Name the linux_raw backend consistently.
* Add some comments to the vDSO parsing code.