summaryrefslogtreecommitdiff
path: root/src/sys
AgeCommit message (Collapse)Author
2022-12-31fix: clippy::size_of_refJonathan
2022-12-25fix: linux+mips+uclibc unreachable patternXiaobo Liu
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
2022-12-13Added CANbus socket family protocol constants.fpagliughi
2022-12-13Merge #1940bors[bot]
1940: feat: I/O safety for 'sys/select' r=asomers a=SteveLauC #### What this PR does: 1. Adds I/O safety for module `sys/select`. Co-authored-by: Steve Lau <stevelauc@outlook.com>
2022-12-12feat: I/O safety for 'sys/select'Steve Lau
2022-12-11Merge #1923bors[bot]
1923: feat: I/O safety for 'sys/wait' r=asomers a=SteveLauC #### What this PR does: 1. Adds I/O safety for `sys/wait` ---------- Actually, I am not sure about which type to use here: ```rust pub enum Id<'fd> { /// Wait for the child referred to by the given PID file descriptor #[cfg(any(target_os = "android", target_os = "linux"))] PIDFd(RawFd), PIDFd(BorrowedFd<'fd>), } ``` If we use `Fd: AsFd` ```rust pub enum Id<'fd, Fd: AsFd> { /// Wait for the child referred to by the given PID file descriptor #[cfg(any(target_os = "android", target_os = "linux"))] PIDFd(RawFd), PIDFd(&'fd Fd), } ``` then the user has to specify that generic type when using this interface, which is kinda user-unfriendly... ------ The typical usage of this interface will be something like: ```rust // Thought currently we don't have pidfd_open(2) in `Nix` let fd_referring_to_a_process: OwnedFd = pidfd_open().unwrap(); let status = waitid(Id::PIDFd(fd_referring_to_a_process), WaitPidFlag::XXXX).unwrap(); ``` UPDATE: `pidfd_open(2)` will be added in #1859 or #1868 . Co-authored-by: Steve Lau <stevelauc@outlook.com>
2022-12-11Merge #1928 #1938bors[bot]
1928: feat: I/O safety for 'sys/memfd' & 'sys/event' & 'sys/eventfd' r=asomers a=SteveLauC #### What this PR does: Adds I/O safety for moduels: 1. `sys/memfd` 2. `sys/event` 3. `sys/eventfd` ----- BYW, I called `rustfmt` on these 4 files, which introduces some noise, sorry about this. 1938: Deprecate the signalfd function. r=asomers a=asomers The SignalFd type is just as capable and easier to use. CC `@JonathanWoollett-Light` Co-authored-by: Steve Lau <stevelauc@outlook.com> Co-authored-by: Alan Somers <asomers@gmail.com>
2022-12-11feat: I/O safety for 'sys/wait'Steve Lau
2022-12-11feat: I/O safety for 'sys/memfd' & 'sys/event' & 'sys/eventfd'Steve Lau
2022-12-10Deprecate the signalfd function.Alan Somers
The SignalFd type is just as capable and easier to use.
2022-12-10Merge #1874bors[bot]
1874: signalfd optional file descriptor r=asomers a=JonathanWoollett-Light [`sys::signalfd::signalfd`](https://docs.rs/nix/latest/nix/sys/signalfd/fn.signalfd.html) currently takes a `RawFd` for its `fd` argument. Considering from [the documentation](https://man7.org/linux/man-pages/man2/signalfd.2.html): > If the fd argument is -1, then the call creates a new file descriptor and associates the signal set specified in mask with that file descriptor. If fd is not -1, then it must specify a valid existing signalfd file descriptor, and mask is used to replace the signal set associated with that file descriptor. We can better pass the argument as `Option<BorrowedFd>` which encodes the optional nature of this parameter in an option rather than the value being -1 (invalid) (`size_of::<Option<BorrowedFd>>() == size_of::<RawFd>() == 4`). This removes the error case where `fd < -1`. > EBADF The fd file descriptor is not a valid file descriptor. This does however require additional changes to produce a cohesive implementation, notably changing the type within `Signal` from `RawFd` to `ManuallyDrop<OwnedFd>`, this has no functional affect, but illustrates ownership and allows the type to more easily produce `BorrowedFd`s. To use [`BorrowedFd`](https://doc.rust-lang.org/stable/std/os/unix/io/struct.BorrowedFd.html) requires updating the MSRV to `>= 1.63.0` Co-authored-by: Jonathan <jonathanwoollettlight@gmail.com>
2022-12-10signalfd optional file descriptorJonathan
2022-12-09Formatting only changes for #1928 and #1863Alex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-09Merge #1913 #1926 #1927 #1931 #1933bors[bot]
1913: feat: I/O safety for 'sys/inotify' r=asomers a=SteveLauC #### What this PR does: 1. Changes the `fd` field of `struct Inotify` from `RawFd` to `OwnedFd` 2. Changes the interfaces of functions in the `impl Inotify {}` > The type of `self` changes from `Self` to `&mut Self`. From: ```rust pub fn add_watch<P: ?Sized + NixPath>( self, path: &P, mask: AddWatchFlags, ) -> Result<WatchDescriptor> pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()> pub fn read_events(self) -> Result<Vec<InotifyEvent>> ``` To: ```rust pub fn add_watch<P: ?Sized + NixPath>( &mut self, path: &P, mask: AddWatchFlags, ) -> Result<WatchDescriptor> pub fn rm_watch(&mut self, wd: WatchDescriptor) -> Result<()> pub fn read_events(&mut self) -> Result<Vec<InotifyEvent>> ``` In the previous implementation, these functions can take `self` by value as `struct Inotify` [was `Copy`](https://docs.rs/nix/latest/nix/sys/inotify/struct.Inotify.html#impl-Copy-for-Inotify). With the changes in `1` applied, `struct Inotify` is no longer `Copy`, so we have to take `self` by reference. ------- Blocks until the merge of #1863 as this PR needs `read(2)` to be I/O-safe. 1926: feat: I/O safety for 'sys/sendfile' r=asomers a=SteveLauC #### What this PR does: 1. Adds I/O safety for module `sys/sendfile`. 1927: feat: I/O safety for 'sys/statvfs' r=asomers a=SteveLauC #### What this PR does: 1. Adds I/O safety for module `sys/statvfs`. 1931: feat: I/O safety for 'sys/uid' & 'sched' r=asomers a=SteveLauC #### What this PR does: Adds I/O safety for modules: 1. `sys/uio` 2. `sched` 1933: feat: I/O safety for 'sys/timerfd' r=asomers a=SteveLauC #### What this PR does: 1. Adds I/O safety for module `sys/timerfd`. Co-authored-by: Steve Lau <stevelauc@outlook.com>
2022-12-09feat: I/O safety for 'sys/timerfd'Steve Lau
2022-12-09feat: I/O safety for 'sys/inotify'Steve Lau
2022-12-09feat: I/O safety for 'sys/sendfile'Steve Lau
2022-12-09feat: I/O safety for 'sys/uid' & 'sched'Steve Lau
2022-12-09feat: I/O safety for 'sys/statvfs'Steve Lau
2022-12-09refactor: take AsFd by valueSteve Lau
2022-12-08feat: I/O safety for 'sys/termios' & 'pty'Steve Lau
2022-12-06Merge #1916bors[bot]
1916: Use I/O safety in sys::mman r=rtzoeller a=asomers Co-authored-by: Alan Somers <asomers@gmail.com>
2022-12-06Merge #1882bors[bot]
1882: Epoll type r=asomers a=JonathanWoollett-Light Epoll can be most safely used as a type. This implement a type `Epoll` which supports this. Co-authored-by: Jonathan <jonathanwoollettlight@gmail.com>
2022-12-06feat: I/O safety for 'sys/statfs'Steve Lau
2022-12-05Use I/O safety in sys::mmanAlan Somers
2022-12-04Cleanup old Clippy directives.Alan Somers
2022-12-04EpollJonathan
2022-12-04Fix clippy lintsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04Merge #1909bors[bot]
1909: More annoying formatting changes r=asomers a=SUPERCILEX Extracted from https://github.com/nix-rust/nix/pull/1862 Co-authored-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04More annoying formatting changesAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04Move some pure formatting changes out of #1863Alex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-03Nuke deprecated net APIsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-02Nuke IoVecAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-29Add routing socket typeEmils
2022-11-28Fix UB in the SO_TYPE sockoptAlan Somers
When reading a value into an enum from getsockopt, we must validate it. Failing to do so can lead to UB for example with SOCK_PACKET on Linux. Perform the validation in GetSockOpt::get. Currently SockType is the only type that requires validation. Fixes #1819
2022-11-28Update use of libc::timespec to prepare for future libc versionWesley Wiser
In a future release of the `libc` crate, `libc::timespec` will contain private padding fields on `*-linux-musl` targets and so the struct will no longer be able to be created using the literal initialization syntax. Update places where `libc::timespec` is created to first zero initialize the value and then update the `tv_sec` and `tv_nsec` fields manually. Many of these places are in `const fn`s so a helper function `zero_init_timespec()` is introduced to help with this as `std::mem::MaybeUninit::zeroed()` is not a `const` function. Some matches on `libc::timespec` are also updated to include a trailing `..` pattern which works when `libc::timespec` has additional, private fields as well as when it does not (like for `x86_64-unknown-linux-gnu`).
2022-11-25Merge #1865bors[bot]
1865: Add IpMtu sockopt r=asomers a=ShadowJonathan Resolves https://github.com/nix-rust/nix/issues/1864 Co-authored-by: Jonathan de Jong <jonathandejong02@gmail.com>
2022-11-25Clippy cleanup with the latest nightly.Alan Somers
2022-11-23add IpMtu sockoptJonathan de Jong
2022-11-21Merge #1848bors[bot]
1848: SockProtocol::Raw = libc::IPPROTO_RAW for raw sockets r=asomers a=StackOverflowExcept1on Hey, I wanna to make call like `socket(af_type, SOCK_RAW, IPPROTO_RAW)` but currently there is no way to do it with rust https://github.com/rickettm/SendIP/blob/aad12a001157489ab9053c8665e09aec24a2ff6d/sendip.c#L143 Update: Feel free to add `#[cfg]` attribute if I made mistakes that might cause errors on some platforms Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com>
2022-11-21Use the new UnixAddr::new_unnamed in the unit testsAlan Somers
Use it in the from_sockaddr_un_abstract_unnamed test. That test and this method were introduced by PRs #1871 and #1857, which crossed each other.
2022-11-21Added `SockProtocol::Raw = libc::IPPROTO_RAW` for raw socketsStackOverflowExcept1on
2022-11-21Merge #1857bors[bot]
1857: Add better support for unnamed unix socket addrs r=asomers a=stevenengler This adds the following 2 functions/methods: `UnixAddr::new_unnamed` and `UnixAddr::is_unnamed`. Closes #1585 unix(7) on Linux: > unnamed: A stream socket that has not been bound to a pathname using bind(2) has no name. Likewise, the two sockets created by socketpair(2) are unnamed. When the address of an unnamed socket is returned, its length is `sizeof(sa_family_t)`, and `sun_path` should not be inspected. **Edit:** This currently isn't working on BSD, but I see why. Will fix it shortly. Co-authored-by: Steven Engler <opara@cs.georgetown.edu>
2022-11-21Merge #1871bors[bot]
1871: Fix using SockaddrStorage to store Unix domain addresses on Linux r=rtzoeller a=asomers Since it has variable length, the user of a sockaddr_un must keep track of its true length. On the BSDs, this is handled by the builtin sun_len field. But on Linux-like operating systems it isn't. Fix this bug by explicitly tracking it for SockaddrStorage just like we already do for UnixAddr. Fixes #1866 Co-authored-by: Alan Somers <asomers@gmail.com>
2022-11-21fixup! Added better support for unnamed unix socket addrsSteven Engler
Make Linux-only
2022-11-21Added better support for unnamed unix socket addrsSteven Engler
2022-11-20mmap non-zero lengthJonathan
2022-11-20Merge #1853bors[bot]
1853: Adds IP_TOS, IPV6_TCLASS and SO_PRIORITY sockopt wrappers for Linux r=asomers a=mzachar Added socket option wrappers for DiffServ related parameters on Linux Co-authored-by: mzachar <mzachar@users.noreply.github.com>
2022-11-20Merge #1870bors[bot]
1870: mmap addr r=asomers a=JonathanWoollett-Light Uses `Some<size_t>` instead of `*mut c_void` for the `addr` passed to [`sys::mman::mmap`](https://docs.rs/nix/latest/nix/sys/mman/fn.mmap.html). In this instance we are not usefully passing a pointer, it will never be dereferenced. We are passing a location which represents where to attach the shared memory to. In this case `size_t` better represents an address and not a pointer, and `Option<size_t>` better represents an optional argument than `NULLPTR`. In C since there is no optional type this is a pointer as this allows it be null which is an alias here for `None`. Co-authored-by: Jonathan <jonathanwoollettlight@gmail.com>
2022-11-20mmap addrJonathan