Commit Graph

883 Commits

Author SHA1 Message Date
Jordan aa1196b00f add O_DIRECT flag (#527) 2023-02-03 14:40:21 -08:00
Alex Saveau dfbdf3c300 Add method to know when buffer will be refilled (#524)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-02-03 14:40:21 -08:00
Dan Gohman cfad01449f Fix compilation on armv7-unknown-freebsd (#518)
* Fix compilation on armv7-unknown-freebsd

Use `time_t::MAX` to avoid depending on the relationship between
`time_t` and `c_long`.

* Silence the deprecation warning about `time_t`.
2023-01-17 12:40:15 -08:00
Alex Saveau 2bc2229509 Simplify RawDir iteration (#515)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-01-17 12:40:15 -08:00
Alex Saveau c9fb537048 Add mount syscall (#494)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2023-01-17 12:40:15 -08:00
Alex Saveau 8ba48ca279 Fix docs typo (#498) 2023-01-17 12:40:15 -08:00
Dan Gohman 54d04c9bc8 Support preadv2 and pwritev2 on all non-glibc Linux ABIs. (#489)
Use `libc::syscall` on ABIs where libc doesn't have bindings for
`preadv2` and `pwritev2`.
2022-12-26 20:56:54 -08:00
Alex Saveau 0b844fc778 Fix another UB in raw dir (#474)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-13 10:40:42 -08:00
Dan Gohman 5225e27a1f Add From impls for SocketAddrAny. (#482)
This allows more convenient construction of `SocketAddrAny` values.
2022-12-13 10:27:53 -08:00
Dan Gohman 1f2532f93d Add doc aliases for seek, tell, and chownat. (#481)
* Add doc aliases for `seek`, `tell`, and `chownat`.

* Add a mention of `socket_with` in `socket`'s documentation.

* Fix a broken doc comment link.
2022-12-13 10:27:34 -08:00
Dan Gohman 3502eb064b Fix the custom definition of Timespec to implement Copy. (#484) 2022-12-13 10:25:25 -08:00
Alan Somers 282dffc589 Future-proof for FreeBSD 12 (#469)
FreeBSD 12 changes the dirent structure, among other things.  libc
currently binds a FreeBSD 11 ABI, but that will change some day.  Tweak
rustix's dirent initialization code to work with either FreeBSD 11 or
12.
2022-12-03 09:36:21 -08:00
Dan Gohman 4e2599b729 Run the tests on Rust 1.48, and check compilation of tests and examples on more targets (#465)
* 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.
2022-12-01 11:42:09 -08:00
Dan Gohman 815104341c Don't check the errno value from isatty. (#468)
We don't actually do anything different for different errno values,
other than panic on unknown ones, and that isn't that isn't adding
much value compared to the cost of being an extra surprise when
porting to new OS's.

Fixes #467.
2022-12-01 11:03:27 -08:00
John Nunley 849d1832e5 Deduplicate the "context" set of structures (#466)
* Deduplicate the "context" set of structures
2022-11-30 08:10:50 -08:00
Alex Saveau 2aff00c77e Fix UB due to misaligned RawDir pointer (#464)
* Fix UB due to misaligned RawDir pointer

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Add alignment and stack tests to RawDir

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-29 17:05:39 -08:00
Dan Gohman 60b84026d7 Make the "param" module depend on the "fs" module.
In some configurations, the param module needs to open /proc/self/auxv,
and it needs the fs API to do that, so make the param module depend on
the fs module.

Also, disable the init_from_proc_self_auxv code on mustang, which
doesn't need it.
2022-11-28 12:36:15 -08:00
Dan Gohman d85c50603b Enable rustix::termios::isatty on wasm32-wasi. 2022-11-28 08:58:36 -08:00
Dan Gohman ef9a77313a Tidy up uses. 2022-11-28 08:58:36 -08:00
Dan Gohman 8fca74091c Tidy up cfgs. 2022-11-28 08:58:36 -08:00
Dan Gohman f6f44b7b05 Implement unshare. (#461)
Fixes #452.
2022-11-28 08:52:24 -08:00
Alex Saveau b5c2ea7127 Add zero-compromise directory iteration (#457)
* Add zero-compromise directory iteration

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Address review feedback

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Vastly simplify file_name calculation and remove pointer manipulation BS, yielding a 2x instruction count reduction

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Implement docs changes I mentioned

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Fix debug impl

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Support libc backend

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Clarify portability of fixed-sized buffers

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Turns out from_ptr is faster, oh well

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Make cookie a u64

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Fix cfgs

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-23 15:42:07 -08:00
Dan Gohman 28d40939ca Minor formatting cleanups. (#459) 2022-11-21 11:18:59 -08:00
Dan Gohman c7146a721e Fix compilation with --no-default-features. (#454)
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.
2022-11-21 10:56:46 -08:00
Dan Gohman d6164939a7 Fix a few clippy lints. (#458)
Fix a few minor clippy lints, and add clippy overrides for warnings that
we can't easily fix due to our MSRV, or due to our support of multiple targets.
2022-11-21 08:30:40 -08:00
Alex Saveau 74c56f3e70 Fix clippy lint (#455)
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-21 06:51:33 -08:00
Dan Gohman 2fc4f1be16 Disable the internal fs module when the "fs" feature isn't enabled. (#449)
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")`.
2022-11-16 12:19:50 -08:00
Alex Saveau 663a74364a Use stdlib with_c_str implementation (#448) 2022-11-16 12:19:21 -08:00
Dan Gohman 2a2ef7e1c8 Remove the uid/gid checks from the procfs code entirely. (#450)
As a followup to #444, remove the uid/gid checks from the procfs code
entirely. Procfs files can have their owner changed to root:root under
`PR_SET_DUMPABLE`, and root can be remapped to nobody by user
namespaces.

This check wasn't guarding against a known problem, and it's complex
to make sure it doesn't spuriously fail under any vald configuration,
so just remove it.
2022-11-15 16:21:16 -08:00
Dan Gohman 962ec8ab9a Change the procfs code to be tolerate of files being owned by root:root. (#444)
When a process is marked as non-dumpable, Linux changes the permissions
of the files under /proc/<pid> as owned by root:root. Relax the procfs
code, including removing use of `O_NOATIME`, so that it works on files
owned by `root:root`.

Fixes #441.
2022-11-15 10:32:38 -08:00
niluxv 701cd6392c Fix compilation on macos without std (#442) 2022-11-14 06:28:37 -08:00
niluxv 70b6814802 Use platform independent IpAddr and SocketAddr (#433)
Update `src/net/ip.rs` and `src/net/addr.rs` to use the new std code,
making these structures platform independent.

Doesn't include the new Debug/Display formatting code for these
structures, although that could have been added now that it doesn't
depend on std anymore.
2022-11-07 08:25:20 -08:00
niluxv 760c0b517c Add part of the FreeBSD procctl API (#429) 2022-11-07 07:39:44 -08:00
niluxv 65a9bcfd7f Add missing FreeBSD specific MapFlags constants (#436) 2022-11-02 13:17:23 -07:00
niluxv 058514e544 Fix compilation of libc backend without std (#430) 2022-10-23 15:38:41 -07:00
messense 6f603e0f33 Update windows-sys to 0.42.0 (#431)
* Update windows-sys to 0.42.0

* Update io-lifetimes to 1.0.0-rc2
2022-10-22 16:21:30 -07:00
nivkner e3dd07d50b add splice syscall (#421)
* add splice function

* add documentation to splice function

* add libc backend for splice

* update linux-raw-sys

* add linux_raw backend

* export splice items

* add tests for splice

* add cfgs

* remove unsafe vmsplice flag

* add IoSliceRaw to linux backend

* add IoSliceRaw to libc backend

* export IoSliceRaw

* add vmsplice function

* implement linux backend vmsplice

* implement libc backend vmsplice

* export vmsplice

* change description of splice

* add documentation of vmsplice

* add vmsplice tests

* Revert "remove unsafe vmsplice flag"

This reverts commit 9a2781e1d91d091e3f069c3c48d7e4a9bb51a45c.

* add vmsplice gift safety docs

* add lifetime parameter to IoSliceRaw

* change splice offsets to in-out args
2022-10-20 14:30:00 -07:00
Aleksandr Trukhin 36d79738cc Fix dir iterator in case of an error.
Do not resize internal buffer on error, otherwise iterator gets stuck in
infinite loop with zeroed `dirent`s after the first error. Correct
behavior is to return error indefinitely if it persists.
Error can be ENOENT if the directory is unlinked while iterating, for
example.

Signed-off-by: Aleksandr Trukhin <alxtry@gmail.com>
2022-10-12 13:37:26 -07:00
Dan Gohman b72d4291d2 Add a proc_self_status function for reading /proc/self/status on Linux.
Fixes #423.
2022-10-12 13:27:49 -07:00
Dan Gohman 378ac49422 Add logic to build.rs to autodetect whether we need to use thumb-mode.
`#[cfg(target_feature = "thumb-mode")]` isn't available on stable, so
use a build.rs script to detect whether we can use `r7` in inline asm
on ARM targets.
2022-10-10 13:29:21 -07:00
Dan Gohman 35e62e6467 Fix linux-raw inline asm for thumb-mode. (#416)
* Fix linux-raw inline asm for thumb-mode.

In thumb-mode, r7 is reserved as the frame pointer and isn't permitted
as an inline asm operand. It's still the syscall-number operand in
syscalls though, so pass the syscall-number operand in in a separate
register, copy it into r7 inside the inline asm, and then restore the
value of r7 when we're done.

* Add a thumbv7neon-unknown-linux-gnueabihf line to CI.
2022-09-27 15:11:40 -07:00
Qiu Chaofan 467b770383 Support AIX operating system (#406)
* Support AIX operating system

* Fix unused imports

* Rustfmt and fix ordering.

Co-authored-by: Dan Gohman <dev@sunfishcode.online>
2022-09-27 13:29:58 -07:00
Dan Gohman 350877a391 Fix compilation on sparc targets. (#417)
* 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.
2022-09-27 10:05:29 -07:00
ETKNeil 8925af59e8 Add ipv6 multicast hops support 2022-09-27 10:05:01 -07:00
Dan Gohman a4434a6c12 Fix various compilation errors on haiku. (#411)
This builds on top of #407!
2022-09-25 18:20:34 -07:00
Dan Gohman e5d9aa159f More fixes for compilation on x86_64-unknown-dragonfly. (#410)
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!
2022-09-25 13:15:28 -07:00
Al Hoang 175c20e182 haiku support (#407)
* haiku support

* cargo format

Co-authored-by: Al Hoang <3811822-hoanga@users.noreply.gitlab.com>
2022-09-25 12:25:02 -07:00
David Carlier 4302598df7 dragonflybsd build fix proposal. 2022-09-25 12:23:47 -07:00
Koutheir Attouchi 974f83d24b Add support for setns(). (#398) 2022-09-20 10:15:24 -07:00
ETKNeil 7ebfc094da Fix libc removing unsafe on makedev 2022-09-20 10:14:13 -07:00