summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)Author
2021-12-30Optimize UnixAddr for the BSDsAlan Somers
On BSD-derived operating systems, struct sockaddr has a sa_len field that holds the length of the structure. UnixAddr's path_len field is redundant. Remove path_len on BSD-derived OSes, retaining it only for Illumos and Linux-based OSes. Also, ensure that two UnixAddrs compare equal if they differ only by the presence of a trailing NUL. On Linux, syscalls like getsockname add a trailing NUL to the sockaddr they return, even if no NUL was present on the sockaddr originally passed to the kernel via a syscall like bind, and even though the docs explicitly say that any NUL passed to bind is not considered to be part of the address. Work around this bug by stripping it in UnixAddrKind::get(), so that at least two UnixAddrs will compare identical even if they differ in the presence of a trailing NUL.
2021-12-21UnixAddr: replace path_len with sun_lenAlan Somers
Within UnixAddr, replace the path_len variable (length of the sun_path field) with sun_len (length of the whole structure). This is more similar to how other sockaddr types work, and it's the same way that the BSDs use the sun_len field. Also, don't require that sun_path be nul-terminated. The OS doesn't require it.
2021-12-21Improve the sockaddr interface:Alan Somers
* All sockaddr newtypes should be repr(transparent) * All sockaddr newtypes should be opaque, so the user can't do something like change the sa_family field in a way that violates invariants. This is a prerequisite for #1544.
2021-12-21impl Send and Sync for IoVecAlan Somers
2021-12-22Merge #1613bors[bot]
1613: Fix clippy warning by adding #[must_use] r=asomers a=rtzoeller Clippy added a lint for non-constructor methods which return `self`, encouraging them to be marked as `#[must_use]`. Mark the methods which are failing with the latest nightly's clippy. ``` $ cargo clippy warning: missing `#[must_use]` attribute on a method returning `Self` --> src/sys/aio.rs:1068:5 | 1068 | / pub fn emplace_slice(mut self, fd: RawFd, offs: off_t, buf: &'a [u8], 1069 | | prio: libc::c_int, sigev_notify: SigevNotify, 1070 | | opcode: LioOpcode) -> Self 1071 | | { ... | 1074 | | self 1075 | | } | |_____^ | = note: `#[warn(clippy::return_self_not_must_use)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: missing `#[must_use]` attribute on a method returning `Self` --> src/sys/aio.rs:1084:5 | 1084 | / pub fn emplace_mut_slice(mut self, fd: RawFd, offs: off_t, 1085 | | buf: &'a mut [u8], prio: libc::c_int, 1086 | | sigev_notify: SigevNotify, opcode: LioOpcode) 1087 | | -> Self ... | 1091 | | self 1092 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use warning: `nix` (lib) generated 2 warnings Finished dev [unoptimized + debuginfo] target(s) in 0.01s ``` Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2021-12-22Enable sched_get/setaffinity on DragonFly BSDRyan Zoeller
2021-12-22Fix clippy warning on latest nightlyRyan Zoeller
2021-12-22Add fdatasync for missing platformsRyan Zoeller
2021-12-22Recent versions of Android support EPOLLEXCLUSIVERyan Zoeller
Enable epoll tests on Android, because they are passing.
2021-12-22Merge #1577bors[bot]
1577: DragonFly 6.0 added fexecve(2) r=rtzoeller a=rtzoeller Enable `fexecve()` on DragonFly, as it was added in the 6.0 release. Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2021-12-21Merge #1571bors[bot]
1571: Remove broken newlib support r=rtzoeller a=asomers Nix has never supported a newlib target, but there were a few cfg checks for it in our codebase. Some of them were misspelled (newlibc vs newlib), and some of the checks were wrong. Removing them makes the code much more readable. Co-authored-by: Alan Somers <asomers@gmail.com>
2021-12-21DragonFly 6.0 added fexecve(2)Ryan Zoeller
2021-12-21Merge #1583bors[bot]
1583: Remove unsafe in with_nix_path() for [u8] r=asomers a=rtzoeller Remove use of `unsafe` in the implementation of `with_nix_path()` for `[u8]`. This also comes with a nice determinism win across input sizes, and is fairly performance neutral (slightly slower for small strings, much faster for large strings). I suspect the performance degradation in the existing implementation is related to the following note in the `CStr::from_ptr()` documentation: > Note: This operation is intended to be a 0-cost cast but it is currently implemented with an up-front calculation of the length of the string. This is not guaranteed to always be the case. --- Tested with `cargo 1.57.0-nightly (7fbbf4e8f 2021-10-19)`, with variations of the following benchmarking code: ```rs #[bench] fn bench_with_nix_path_1024(b: &mut test::Bencher) { let bytes = std::hint::black_box([70u8; 1024]); b.iter(|| { bytes.with_nix_path(|cstr| { std::hint::black_box(&cstr); }).unwrap(); }) } ``` | Length | Before Change | After Change | |--------|-----------------------|-----------------------| | 16 | 37 ns/iter (+/- 0) | 44 ns/iter (+/- 0) | | 64 | 39 ns/iter (+/- 0) | 44 ns/iter (+/- 0) | | 256 | 84 ns/iter (+/- 0) | 48 ns/iter (+/- 0) | | 1024 | 232 ns/iter (+/- 1) | 50 ns/iter (+/- 1) | | 4095 | 796 ns/iter (+/- 8) | 62 ns/iter (+/- 2) | Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2021-12-20feature-gate most Nix functionsVincent Dagonneau
Using features reduces build time and size for consumer crates. By default all features are enabled.
2021-12-11clippy cleanup with the latest nightlyAlan Somers
2021-12-04Merge #1601bors[bot]
1601: Update `mman` related docs r=rtzoeller a=schctl Added docs for `memfd_create`, `shm_open`, and `shm_unlink`, and some man-page and intra doc links. Co-authored-by: Sachin Cherian <sachinctl@protonmail.com>
2021-12-03Update `mman` related docsSachin Cherian
- Add docs for `memfd_create`, `shm_open`, and `shm_unlink` - Add man-page links - Remove` #[allow(missing_docs)]`on the `memfd` module
2021-12-02Merge branch 'nix-rust:master' into freebsd-fixS.J.R. van Schaik
2021-11-26Update doc comment to match type `Option<Signal>`Johannes Schilling
This has previously been done for `killpg`, but not `kill` it seems.
2021-11-17Fix documentation formating for pipe2rusty-snake
2021-11-02MapFlags::MAP_ALIGNED_SUPER not exposed on FreeBSD due to typoS.J.R. van Schaik
2021-10-22Remove unsafe in with_nix_path() for [u8]Ryan Zoeller
2021-10-23Merge #1565 #1566bors[bot]
1565: Update features::socket_atomic_cloexec r=asomers a=asomers Several platforms have long supported SOCK_OCLOEXEC. Mark them as supporting this feature. 1566: Correct definition of MADV_SOFT_OFFLINE on ppc r=asomers a=asomers Rust has no "ppc" target_arch. It should be "powerpc" or "powerpc64". Co-authored-by: Alan Somers <asomers@gmail.com>
2021-10-21Fix unsoundness in `FdSet` methodstaylor.fish
Ensure file descriptors are nonnegative and less than `FD_SETSIZE`. (Fixes #1572.)
2021-10-16Remove broken newlib supportAlan Somers
Nix has never supported a newlib target, but there were a few cfg checks for it in our codebase. Some of them were misspelled (newlibc vs newlib), and some of the checks were wrong. Removing them makes the code much more readable.
2021-10-16Fix a Clippy warning on the latest nightlyAlan Somers
2021-10-16Correct definition of MADV_SOFT_OFFLINE on ppcAlan Somers
Rust has no "ppc" target_arch. It should be "powerpc" or "powerpc64".
2021-10-16Update features::socket_atomic_cloexecAlan Somers
Several platforms have long supported SOCK_OCLOEXEC. Mark them as supporting this feature.
2021-10-09sockopt's Set and Get traits are not unsafeAlan Somers
They were properly marked as unsafe as originally written. However, when the internal mem::zeroed() was replaced by mem::uninitialized(), these traits actually became safe. Only Get::assume_init() is actually unsafe. Fixes a warning with the latest Clippy.
2021-09-29Merge #1538 #1545 #1546bors[bot]
1538: posix_fadvise doesn't return -1 as sentinel value r=asomers a=ocadaruma ## Summary - `posix_fadvise(2)` does return error number directly (i.e. not through `errno`) * refs: https://man7.org/linux/man-pages/man2/posix_fadvise.2.html , https://man7.org/linux/man-pages/man2/posix_fadvise.2.html - However `posix_fadvise`-binding uses `Errno::result` to translate the error now, which is mis-use. 1545: Fix memory unsafety in unistd::getgrouplist r=asomers a=asomers Fixes #1541 1546: Revert "Expose SockAddr::from_raw_sockaddr" r=asomers a=asomers This reverts commit ed43d2c65e65dd68c9cf2dcf06f5ec45a44aaccd. As discussed in #1544 the API of this function needs to change. For now, revert the PR that made it public, because it has not yet been included in any release. Co-authored-by: Haruki Okada <ocadaruma@gmail.com> Co-authored-by: vitalyd <vitalyd@gmail.com> Co-authored-by: Alan Somers <asomers@gmail.com>
2021-09-28Fix return value of posix_fadviseHaruki Okada
libc::posix_fadvise returns errnos directly rather than in the errno variable.
2021-09-28Revert "Expose SockAddr::from_raw_sockaddr"Alan Somers
This reverts commit ed43d2c65e65dd68c9cf2dcf06f5ec45a44aaccd. As discussed in #1544 the API of this function needs to change. For now, revert the PR that made it public, because it has not yet been included in any release.
2021-09-28Fix memory unsafety in unistd::getgrouplistvitalyd
Fixes #1541
2021-09-28Merge #1536bors[bot]
1536: Lower limits in setrlimit example r=asomers a=rtzoeller The current values causes the doc test to fail on Fedora 34 for unprivileged users. The values can be lowered without meaningfully changing the example. Previously the example failed with EPERM. Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2021-09-20Lower limits in setrlimit exampleRyan Zoeller
The current value causes the doc test to fail on Fedora 34 for unprivileged users.
2021-09-19Fix #411 - Provide accessors for 'events' in PollFdConrad Meyer
Test: `cargo test --test test test_pollfd_events`
2021-09-19Actually connect the mman tests to the buildAlan Somers
This was an oversight from #1306. Reported-by: @ocadaruma
2021-09-19Merge #1531bors[bot]
1531: mman add MAP_CONCEAL mmap flag for openbsd r=asomers a=devnexen Co-authored-by: David Carlier <devnexen@gmail.com>
2021-09-19mman add MAP_CONCEAL mmap flag for openbsdDavid Carlier
2021-09-19Merge #1532bors[bot]
1532: mman MAP_JIT flag documentation. r=asomers a=devnexen Co-authored-by: David Carlier <devnexen@gmail.com>
2021-09-19Merge #1522bors[bot]
1522: mman mod adding MAP_ALIGNED_SUPER flag for freebsd. r=asomers a=devnexen Co-authored-by: David Carlier <devnexen@gmail.com>
2021-09-19Clippy cleanupAlan Somers
And this time, start running Clippy in CI
2021-09-19mman MAP_JIT flag documentation.David Carlier
2021-09-19mman mod adding MAP_ALIGNED_SUPER flag for freebsd.David Carlier
2021-09-19Merge #1496bors[bot]
1496: Rework UnixAddr to fix soundness issues r=asomers a=coolreader18 Fixes #1494 I went with making `sun_path` always nul-terminated since that just seems to make things easier, since (at least according to linux man pages) `sockaddr_un`s returned by the kernel will always be nul-terminated. Co-authored-by: Noa <33094578+coolreader18@users.noreply.github.com>
2021-09-18mman: add MAP_EXCL flag for freebsd.David Carlier
2021-09-13Merge #1524bors[bot]
1524: Add docs for most sockopts r=asomers a=asomers Co-authored-by: Alan Somers <asomers@gmail.com>
2021-09-12Add docs for all sockopts that are documented by their respective OSesAlan Somers
2021-09-12Add the ability to set doc strings in sockopts' definitionsAlan Somers
2021-09-12Switch the argument order of sockopt_impl!Alan Somers
This macro is not exported outside of the crate, so there's no danger.