Commit Graph

865 Commits

Author SHA1 Message Date
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
Koutheir Attouchi e328c738bc Add support for prctl(). 2022-09-16 07:14:37 -07:00
Dan Gohman 6ca8fefad8 Remove a few unnecessary allow(unsafe_code) annotations. 2022-09-14 16:34:15 -07:00
gco ccaebe7c3a Fix compilation errors on solaris. 2022-09-07 14:05:12 -07:00
Dan Gohman 325d679ee4 Remove rustix::io::OwnedFd.
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.
2022-08-20 08:30:47 -07:00
Dan Gohman 47584dde80 Add more From<T> for OwnedFd impls for rustix::io::OwnedFd. 2022-08-19 06:48:09 -07:00
Dan Gohman 9dfc94bcba Update to io-lifetimes 1.0.
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.
2022-08-17 16:20:04 -07:00
Dan Gohman 4eed038018 Switch from .init_array constructors to /proc/self/auxv. (#385)
* 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.
2022-08-08 11:06:28 -07:00
Dan Gohman 26baf41126 Add a Result to getpgid, and add getpgrp. (#386)
* 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.
2022-07-26 05:49:50 -07:00
Dan Gohman baa4cbf1b9 Misc code cleanups.
Simple cleanups factored out of an upcoming more complex PR.
2022-07-19 20:14:25 -07:00
Dan Gohman 1bbd4246d5 Remove the madvise from the vDSO checking code.
The `madvise` was there to test whether the `AT_SYSINFO_EHDR` pointer
was a valid pointer before dereferencing it. However, in situation where
the `madvise` would fail, plain dereferences should reliably segfault,
which is sufficient for this code.
2022-07-19 19:39:39 -07:00
carbotaniuman ad5b66e657 Add getpgid (#380)
* Add getpgid
2022-07-12 20:41:40 -07:00
Dan Gohman 4aae063274 Guard against future statx fields. (#379)
* 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`.
2022-07-12 20:39:31 -07:00
Dan Gohman 845546bc28 Minor code cleanup: avoid map(|()| ...).
Instead of `ret(a).map(|()| b)`, use `ret(a)?; Ok(b)`, which is a little
easier to read and debug.
2022-07-07 12:42:45 -07:00
Dan Gohman ec92ea492e Fix miscellaneous clippy lints. 2022-07-07 07:38:07 -07:00
Dan Gohman e82a2c1ea5 Implement statvfs and fstatvfs. (#375)
* 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.
2022-07-03 22:23:37 -07:00
Dan Gohman ea4ac8d07b Update src/io/stdio.rs for the imp->backend rename. 2022-07-02 15:21:03 -07:00
Dan Gohman 2ee0ada67b Add APIs to return raw stdio descriptors.
These are useful when one needs a raw descriptor and doesn't want the
overhead of doing `std::io::stdout().as_raw_fd()` or the unsafe block of
doing `rustix::io::stdout().as_raw_fd()`.
2022-07-02 15:18:57 -07:00
Dan Gohman 8362b8937a Update the debug-mode prebuilt libraries. 2022-07-02 15:18:43 -07:00