diff options
Diffstat (limited to 'vendor/rustix/src')
-rw-r--r-- | vendor/rustix/src/backend/libc/conv.rs (renamed from vendor/rustix/src/imp/libc/conv.rs) | 6 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/dir.rs (renamed from vendor/rustix/src/imp/libc/fs/dir.rs) | 121 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/makedev.rs (renamed from vendor/rustix/src/imp/libc/fs/makedev.rs) | 6 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/mod.rs (renamed from vendor/rustix/src/imp/libc/fs/mod.rs) | 3 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/syscalls.rs (renamed from vendor/rustix/src/imp/libc/fs/syscalls.rs) | 164 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/fs/types.rs (renamed from vendor/rustix/src/imp/libc/fs/types.rs) | 118 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/epoll.rs (renamed from vendor/rustix/src/imp/libc/io/epoll.rs) | 39 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/errno.rs (renamed from vendor/rustix/src/imp/libc/io/errno.rs) | 125 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/io_slice.rs (renamed from vendor/rustix/src/imp/libc/io/io_slice.rs) | 2 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/mod.rs (renamed from vendor/rustix/src/imp/libc/io/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/poll_fd.rs (renamed from vendor/rustix/src/imp/libc/io/poll_fd.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/syscalls.rs (renamed from vendor/rustix/src/imp/libc/io/syscalls.rs) | 105 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/types.rs (renamed from vendor/rustix/src/imp/libc/io/types.rs) | 81 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io/windows_syscalls.rs (renamed from vendor/rustix/src/imp/libc/io/windows_syscalls.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io_lifetimes.rs (renamed from vendor/rustix/src/imp/libc/io_lifetimes.rs) | 34 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io_uring/mod.rs (renamed from vendor/rustix/src/imp/libc/io_uring/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/io_uring/syscalls.rs (renamed from vendor/rustix/src/imp/libc/io_uring/syscalls.rs) | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/mm/mod.rs (renamed from vendor/rustix/src/imp/libc/mm/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/mm/syscalls.rs (renamed from vendor/rustix/src/imp/libc/mm/syscalls.rs) | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/mm/types.rs (renamed from vendor/rustix/src/imp/libc/mm/types.rs) | 51 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/mod.rs (renamed from vendor/rustix/src/imp/libc/mod.rs) | 6 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/addr.rs (renamed from vendor/rustix/src/imp/libc/net/addr.rs) | 10 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/ext.rs (renamed from vendor/rustix/src/imp/libc/net/ext.rs) | 19 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/mod.rs (renamed from vendor/rustix/src/imp/libc/net/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/read_sockaddr.rs (renamed from vendor/rustix/src/imp/libc/net/read_sockaddr.rs) | 6 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/send_recv.rs (renamed from vendor/rustix/src/imp/libc/net/send_recv.rs) | 8 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/syscalls.rs (renamed from vendor/rustix/src/imp/libc/net/syscalls.rs) | 28 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/types.rs (renamed from vendor/rustix/src/imp/libc/net/types.rs) | 108 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/net/write_sockaddr.rs (renamed from vendor/rustix/src/imp/libc/net/write_sockaddr.rs) | 6 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/offset.rs (renamed from vendor/rustix/src/imp/libc/offset.rs) | 63 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/param/auxv.rs (renamed from vendor/rustix/src/imp/libc/param/auxv.rs) | 12 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/param/mod.rs (renamed from vendor/rustix/src/imp/libc/param/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/process/cpu_set.rs (renamed from vendor/rustix/src/imp/libc/process/cpu_set.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/process/mod.rs (renamed from vendor/rustix/src/imp/libc/process/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/process/syscalls.rs (renamed from vendor/rustix/src/imp/libc/process/syscalls.rs) | 50 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/process/types.rs (renamed from vendor/rustix/src/imp/libc/process/types.rs) | 75 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/process/wait.rs (renamed from vendor/rustix/src/imp/libc/process/wait.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/rand/mod.rs (renamed from vendor/rustix/src/imp/libc/rand/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/rand/syscalls.rs (renamed from vendor/rustix/src/imp/libc/rand/syscalls.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/rand/types.rs (renamed from vendor/rustix/src/imp/libc/rand/types.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/termios/mod.rs (renamed from vendor/rustix/src/imp/libc/termios/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/termios/syscalls.rs (renamed from vendor/rustix/src/imp/libc/termios/syscalls.rs) | 7 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/termios/types.rs (renamed from vendor/rustix/src/imp/libc/termios/types.rs) | 103 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/thread/mod.rs (renamed from vendor/rustix/src/imp/libc/thread/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/thread/syscalls.rs (renamed from vendor/rustix/src/imp/libc/thread/syscalls.rs) | 17 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/time/mod.rs (renamed from vendor/rustix/src/imp/libc/time/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/time/syscalls.rs (renamed from vendor/rustix/src/imp/libc/time/syscalls.rs) | 18 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/time/types.rs (renamed from vendor/rustix/src/imp/libc/time/types.rs) | 2 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/weak.rs (renamed from vendor/rustix/src/imp/libc/weak.rs) | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/libc/winsock_c.rs (renamed from vendor/rustix/src/imp/libc/winsock_c.rs) | 2 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/aarch64.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/aarch64.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/arm.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/arm.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/mips.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/mips.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/mips64.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/mips64.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/mod.rs) | 5 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/powerpc64.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/powerpc64.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/riscv64.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/riscv64.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/thumb.rs | 322 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/x86.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/x86.rs) | 50 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/inline/x86_64.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/inline/x86_64.rs) | 32 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/mod.rs) | 76 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/aarch64.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/aarch64.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/arm.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/arm.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/mips.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/mips.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/mips64.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/mips64.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/mod.rs) | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/nr_last.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/nr_last.rs) | 26 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/powerpc64.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/powerpc64.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/riscv64.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/riscv64.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/x86.rs (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/x86.rs) | 38 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/x86.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/x86.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/arch/outline/x86_64.s (renamed from vendor/rustix/src/imp/linux_raw/arch/outline/x86_64.s) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/c.rs (renamed from vendor/rustix/src/imp/linux_raw/c.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/conv.rs (renamed from vendor/rustix/src/imp/linux_raw/conv.rs) | 76 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/elf.rs (renamed from vendor/rustix/src/imp/linux_raw/elf.rs) | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/fs/dir.rs (renamed from vendor/rustix/src/imp/linux_raw/fs/dir.rs) | 26 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/fs/makedev.rs (renamed from vendor/rustix/src/imp/linux_raw/fs/makedev.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/fs/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/fs/mod.rs) | 1 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/fs/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/fs/syscalls.rs) | 197 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/fs/types.rs (renamed from vendor/rustix/src/imp/linux_raw/fs/types.rs) | 69 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/epoll.rs (renamed from vendor/rustix/src/imp/linux_raw/io/epoll.rs) | 40 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/errno.rs (renamed from vendor/rustix/src/imp/linux_raw/io/errno.rs) | 28 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/io_slice.rs (renamed from vendor/rustix/src/imp/linux_raw/io/io_slice.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/io/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/poll_fd.rs (renamed from vendor/rustix/src/imp/linux_raw/io/poll_fd.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/io/syscalls.rs) | 146 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io/types.rs (renamed from vendor/rustix/src/imp/linux_raw/io/types.rs) | 61 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io_uring/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/io_uring/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/io_uring/syscalls.rs) | 5 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/mm/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/mm/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/mm/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/mm/syscalls.rs) | 8 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/mm/types.rs (renamed from vendor/rustix/src/imp/linux_raw/mm/types.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/mod.rs) | 18 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/addr.rs (renamed from vendor/rustix/src/imp/linux_raw/net/addr.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/net/mod.rs) | 2 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/read_sockaddr.rs (renamed from vendor/rustix/src/imp/linux_raw/net/read_sockaddr.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/send_recv.rs (renamed from vendor/rustix/src/imp/linux_raw/net/send_recv.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/net/syscalls.rs) | 40 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/types.rs (renamed from vendor/rustix/src/imp/linux_raw/net/types.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs (renamed from vendor/rustix/src/imp/linux_raw/net/write_sockaddr.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/param/auxv.rs | 370 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs | 74 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/param/mod.rs | 12 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs | 159 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/process/cpu_set.rs (renamed from vendor/rustix/src/imp/linux_raw/process/cpu_set.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/process/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/process/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/process/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/process/syscalls.rs) | 61 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/process/types.rs (renamed from vendor/rustix/src/imp/linux_raw/process/types.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/process/wait.rs (renamed from vendor/rustix/src/imp/linux_raw/process/wait.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/rand/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/rand/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/rand/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/rand/syscalls.rs) | 2 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/rand/types.rs (renamed from vendor/rustix/src/imp/linux_raw/rand/types.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/reg.rs (renamed from vendor/rustix/src/imp/linux_raw/reg.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/runtime/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/runtime/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/runtime/syscalls.rs) | 5 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/runtime/tls.rs (renamed from vendor/rustix/src/imp/linux_raw/runtime/tls.rs) | 11 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/termios/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/termios/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/termios/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/termios/syscalls.rs) | 33 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/termios/types.rs (renamed from vendor/rustix/src/imp/linux_raw/termios/types.rs) | 4 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/thread/futex.rs (renamed from vendor/rustix/src/imp/linux_raw/thread/futex.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/thread/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/thread/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/thread/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/thread/syscalls.rs) | 14 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/time/mod.rs (renamed from vendor/rustix/src/imp/linux_raw/time/mod.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/time/syscalls.rs (renamed from vendor/rustix/src/imp/linux_raw/time/syscalls.rs) | 38 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/time/types.rs (renamed from vendor/rustix/src/imp/linux_raw/time/types.rs) | 0 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/vdso.rs | 310 | ||||
-rw-r--r-- | vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs (renamed from vendor/rustix/src/imp/linux_raw/vdso_wrappers.rs) | 26 | ||||
-rw-r--r-- | vendor/rustix/src/const_assert.rs | 1 | ||||
-rw-r--r-- | vendor/rustix/src/fs/abs.rs | 42 | ||||
-rw-r--r-- | vendor/rustix/src/fs/at.rs | 55 | ||||
-rw-r--r-- | vendor/rustix/src/fs/constants.rs | 15 | ||||
-rw-r--r-- | vendor/rustix/src/fs/copy_file_range.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/fs/cwd.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/fs/dir.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fadvise.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcntl.rs | 72 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcntl_darwin.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fcopyfile.rs | 16 | ||||
-rw-r--r-- | vendor/rustix/src/fs/fd.rs | 97 | ||||
-rw-r--r-- | vendor/rustix/src/fs/file_type.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/fs/getpath.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/fs/makedev.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/fs/memfd_create.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/fs/mod.rs | 51 | ||||
-rw-r--r-- | vendor/rustix/src/fs/openat2.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/fs/sendfile.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/fs/statx.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/imp/linux_raw/net/ext.rs | 64 | ||||
-rw-r--r-- | vendor/rustix/src/imp/linux_raw/param/auxv.rs | 203 | ||||
-rw-r--r-- | vendor/rustix/src/imp/linux_raw/param/mod.rs | 1 | ||||
-rw-r--r-- | vendor/rustix/src/imp/linux_raw/vdso.rs | 435 | ||||
-rw-r--r-- | vendor/rustix/src/io/close.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/io/dup.rs | 20 | ||||
-rw-r--r-- | vendor/rustix/src/io/errno.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/io/eventfd.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/io/fcntl.rs | 86 | ||||
-rw-r--r-- | vendor/rustix/src/io/fd/owned.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/io/fd/raw.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/io/ioctl.rs | 22 | ||||
-rw-r--r-- | vendor/rustix/src/io/is_read_write.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/io/mod.rs | 45 | ||||
-rw-r--r-- | vendor/rustix/src/io/owned_fd.rs | 272 | ||||
-rw-r--r-- | vendor/rustix/src/io/pipe.rs | 91 | ||||
-rw-r--r-- | vendor/rustix/src/io/poll.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/io/procfs.rs | 106 | ||||
-rw-r--r-- | vendor/rustix/src/io/read_write.rs | 32 | ||||
-rw-r--r-- | vendor/rustix/src/io/stdio.rs | 96 | ||||
-rw-r--r-- | vendor/rustix/src/io_uring.rs | 19 | ||||
-rw-r--r-- | vendor/rustix/src/lib.rs | 30 | ||||
-rw-r--r-- | vendor/rustix/src/mm/madvise.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/mm/mmap.rs | 28 | ||||
-rw-r--r-- | vendor/rustix/src/mm/msync.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/mm/userfaultfd.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/net/addr.rs | 204 | ||||
-rw-r--r-- | vendor/rustix/src/net/ip.rs | 423 | ||||
-rw-r--r-- | vendor/rustix/src/net/send_recv.rs | 28 | ||||
-rw-r--r-- | vendor/rustix/src/net/socket.rs | 62 | ||||
-rw-r--r-- | vendor/rustix/src/net/socket_addr_any.rs | 20 | ||||
-rw-r--r-- | vendor/rustix/src/net/socketpair.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/net/sockopt.rs | 102 | ||||
-rw-r--r-- | vendor/rustix/src/net/wsa.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/param/auxv.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/param/init.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/param/mod.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/path/arg.rs | 28 | ||||
-rw-r--r-- | vendor/rustix/src/path/dec_int.rs | 2 | ||||
-rw-r--r-- | vendor/rustix/src/process/chdir.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/process/exit.rs | 8 | ||||
-rw-r--r-- | vendor/rustix/src/process/id.rs | 53 | ||||
-rw-r--r-- | vendor/rustix/src/process/kill.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/process/membarrier.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/process/mod.rs | 13 | ||||
-rw-r--r-- | vendor/rustix/src/process/prctl.rs | 1120 | ||||
-rw-r--r-- | vendor/rustix/src/process/priority.rs | 16 | ||||
-rw-r--r-- | vendor/rustix/src/process/procctl.rs | 180 | ||||
-rw-r--r-- | vendor/rustix/src/process/rlimit.rs | 10 | ||||
-rw-r--r-- | vendor/rustix/src/process/sched.rs | 22 | ||||
-rw-r--r-- | vendor/rustix/src/process/sched_yield.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/process/uname.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/process/wait.rs | 26 | ||||
-rw-r--r-- | vendor/rustix/src/rand/getrandom.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/runtime.rs | 38 | ||||
-rw-r--r-- | vendor/rustix/src/termios/cf.rs | 14 | ||||
-rw-r--r-- | vendor/rustix/src/termios/constants.rs | 401 | ||||
-rw-r--r-- | vendor/rustix/src/termios/mod.rs | 105 | ||||
-rw-r--r-- | vendor/rustix/src/termios/tc.rs | 26 | ||||
-rw-r--r-- | vendor/rustix/src/termios/tty.rs | 11 | ||||
-rw-r--r-- | vendor/rustix/src/thread/clock.rs | 14 | ||||
-rw-r--r-- | vendor/rustix/src/thread/futex.rs | 6 | ||||
-rw-r--r-- | vendor/rustix/src/thread/id.rs | 4 | ||||
-rw-r--r-- | vendor/rustix/src/thread/mod.rs | 9 | ||||
-rw-r--r-- | vendor/rustix/src/thread/prctl.rs | 989 | ||||
-rw-r--r-- | vendor/rustix/src/thread/setns.rs | 89 | ||||
-rw-r--r-- | vendor/rustix/src/time/clock.rs | 12 | ||||
-rw-r--r-- | vendor/rustix/src/time/timerfd.rs | 13 | ||||
-rw-r--r-- | vendor/rustix/src/utils.rs | 16 |
216 files changed, 7291 insertions, 2888 deletions
diff --git a/vendor/rustix/src/imp/libc/conv.rs b/vendor/rustix/src/backend/libc/conv.rs index fed15fbd1..1e74ea9ba 100644 --- a/vendor/rustix/src/imp/libc/conv.rs +++ b/vendor/rustix/src/backend/libc/conv.rs @@ -5,12 +5,13 @@ #![allow(dead_code)] use super::c; -use super::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, LibcFd, RawFd}; +use super::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, LibcFd, OwnedFd, RawFd}; #[cfg(not(windows))] +#[cfg(feature = "fs")] use super::offset::libc_off_t; #[cfg(not(windows))] use crate::ffi::CStr; -use crate::io::{self, OwnedFd}; +use crate::io; #[cfg(windows)] use core::convert::TryInto; @@ -120,6 +121,7 @@ pub(super) fn syscall_ret_u32(raw: c::c_long) -> io::Result<u32> { } #[cfg(not(windows))] +#[cfg(feature = "fs")] #[inline] pub(super) fn ret_off_t(raw: libc_off_t) -> io::Result<libc_off_t> { if raw == -1 { diff --git a/vendor/rustix/src/imp/libc/fs/dir.rs b/vendor/rustix/src/backend/libc/fs/dir.rs index 1e6b6066f..8e5477401 100644 --- a/vendor/rustix/src/imp/libc/fs/dir.rs +++ b/vendor/rustix/src/backend/libc/fs/dir.rs @@ -1,6 +1,6 @@ use super::super::c; use super::super::conv::owned_fd; -#[cfg(not(target_os = "illumos"))] +#[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] use super::types::FileType; use crate::fd::{AsFd, BorrowedFd}; use crate::ffi::CStr; @@ -8,12 +8,22 @@ use crate::ffi::CStr; use crate::ffi::CString; use crate::fs::{fcntl_getfl, fstat, openat, Mode, OFlags, Stat}; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", -)))] // not implemented in libc for netbsd yet +)))] use crate::fs::{fstatfs, StatFs}; +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +use crate::fs::{fstatvfs, StatVfs}; use crate::io; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] use crate::process::fchdir; @@ -65,8 +75,8 @@ impl Dir { // file description state, which would cause Undefined Behavior after // our call to `fdopendir`. To prevent this, we obtain an independent // `OwnedFd`. - let flags = fcntl_getfl(&fd)?; - let fd_for_dir = openat(&fd, cstr!("."), flags | OFlags::CLOEXEC, Mode::empty())?; + let flags = fcntl_getfl(fd)?; + let fd_for_dir = openat(fd, cstr!("."), flags | OFlags::CLOEXEC, Mode::empty())?; let raw = owned_fd(fd_for_dir); unsafe { @@ -75,9 +85,9 @@ impl Dir { if let Some(libc_dir) = NonNull::new(libc_dir) { Ok(Self(libc_dir)) } else { - let e = io::Errno::last_os_error(); + let err = io::Errno::last_os_error(); let _ = c::close(raw); - Err(e) + Err(err) } } } @@ -129,16 +139,31 @@ impl Dir { /// `fstatfs(self)` #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", - )))] // not implemented in libc for netbsd yet + )))] #[inline] pub fn statfs(&self) -> io::Result<StatFs> { fstatfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) }) } + /// `fstatvfs(self)` + #[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", + )))] + #[inline] + pub fn statvfs(&self) -> io::Result<StatVfs> { + fstatvfs(unsafe { BorrowedFd::borrow_raw(c::dirfd(self.0.as_ptr())) }) + } + /// `fchdir(self)` #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] #[inline] @@ -151,12 +176,19 @@ impl Dir { // struct, as the name is NUL-terminated and memory may not be allocated for // the full extent of the struct. Copy the fields one at a time. unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent { - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "illumos", + target_os = "solaris" + )))] let d_type = input.d_type; #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -164,6 +196,9 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent { )))] let d_off = input.d_off; + #[cfg(target_os = "aix")] + let d_offset = input.d_offset; + #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -172,13 +207,19 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent { )))] let d_ino = input.d_ino; - #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] + #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))] let d_fileno = input.d_fileno; - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "dragonfly", target_os = "wasi")))] let d_reclen = input.d_reclen; #[cfg(any( + target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd", @@ -190,34 +231,46 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent { #[cfg(any(target_os = "ios", target_os = "macos"))] let d_seekoff = input.d_seekoff; + #[cfg(target_os = "haiku")] + let d_dev = input.d_dev; + #[cfg(target_os = "haiku")] + let d_pdev = input.d_pdev; + #[cfg(target_os = "haiku")] + let d_pino = input.d_pino; + // Construct the input. Rust will give us an error if any OS has a input // with a field that we missed here. And we can avoid blindly copying the // whole `d_name` field, which may not be entirely allocated. #[cfg_attr(target_os = "wasi", allow(unused_mut))] + #[cfg(not(target_os = "dragonfly"))] let mut dirent = libc_dirent { - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "illumos", + target_os = "solaris" + )))] d_type, #[cfg(not(any( - target_os = "dragonfly", + target_os = "aix", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "wasi", )))] d_off, - #[cfg(not(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", - )))] + #[cfg(target_os = "aix")] + d_offset, + #[cfg(not(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))] d_ino, #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] d_fileno, #[cfg(not(target_os = "wasi"))] d_reclen, #[cfg(any( + target_os = "aix", target_os = "freebsd", target_os = "ios", target_os = "macos", @@ -239,6 +292,29 @@ unsafe fn read_dirent(input: &libc_dirent) -> libc_dirent { d_name: zeroed(), #[cfg(target_os = "openbsd")] __d_padding: zeroed(), + #[cfg(target_os = "haiku")] + d_dev, + #[cfg(target_os = "haiku")] + d_pdev, + #[cfg(target_os = "haiku")] + d_pino, + }; + /* + pub d_ino: ino_t, + pub d_pino: i64, + pub d_reclen: ::c_ushort, + pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX + // */ + + // On dragonfly, `dirent` has some non-public padding fields so we can't + // directly initialize it. + #[cfg(target_os = "dragonfly")] + let mut dirent = unsafe { + let mut dirent: libc_dirent = zeroed(); + dirent.d_fileno = d_fileno; + dirent.d_namlen = d_namlen; + dirent.d_type = d_type; + dirent }; // Copy from d_name, reading up to and including the first NUL. @@ -306,7 +382,12 @@ impl DirEntry { } /// Returns the type of this directory entry. - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "illumos", + target_os = "solaris" + )))] #[inline] pub fn file_type(&self) -> FileType { FileType::from_dirent_d_type(self.dirent.d_type) @@ -321,7 +402,7 @@ impl DirEntry { )))] #[inline] pub fn ino(&self) -> u64 { - self.dirent.d_ino + self.dirent.d_ino as u64 } /// Return the inode number of this directory entry. diff --git a/vendor/rustix/src/imp/libc/fs/makedev.rs b/vendor/rustix/src/backend/libc/fs/makedev.rs index d9089e7f4..08ecd872e 100644 --- a/vendor/rustix/src/imp/libc/fs/makedev.rs +++ b/vendor/rustix/src/backend/libc/fs/makedev.rs @@ -5,14 +5,14 @@ use crate::fs::Dev; #[cfg(not(any(target_os = "android", target_os = "emscripten")))] #[inline] pub(crate) fn makedev(maj: u32, min: u32) -> Dev { - unsafe { c::makedev(maj, min) } + c::makedev(maj, min) } #[cfg(all(target_os = "android", not(target_pointer_width = "32")))] #[inline] pub(crate) fn makedev(maj: u32, min: u32) -> Dev { // Android's `makedev` oddly has signed argument types. - unsafe { c::makedev(maj as i32, min as i32) } + c::makedev(maj, min) } #[cfg(all(target_os = "android", target_pointer_width = "32"))] @@ -30,7 +30,7 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev { #[inline] pub(crate) fn makedev(maj: u32, min: u32) -> Dev { // Emscripten's `makedev` has a 32-bit return value. - Dev::from(unsafe { c::makedev(maj, min) }) + Dev::from(c::makedev(maj, min)) } #[cfg(not(any(target_os = "android", target_os = "emscripten")))] diff --git a/vendor/rustix/src/imp/libc/fs/mod.rs b/vendor/rustix/src/backend/libc/fs/mod.rs index 02b7b2d6a..d0fc08765 100644 --- a/vendor/rustix/src/imp/libc/fs/mod.rs +++ b/vendor/rustix/src/backend/libc/fs/mod.rs @@ -1,8 +1,8 @@ #[cfg(not(target_os = "redox"))] -#[cfg(any(feature = "fs", feature = "procfs"))] pub(crate) mod dir; #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "freebsd", target_os = "illumos", target_os = "ios", @@ -10,6 +10,7 @@ pub(crate) mod dir; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] pub(crate) mod makedev; diff --git a/vendor/rustix/src/imp/libc/fs/syscalls.rs b/vendor/rustix/src/backend/libc/fs/syscalls.rs index 0317367ab..1d1891f0f 100644 --- a/vendor/rustix/src/imp/libc/fs/syscalls.rs +++ b/vendor/rustix/src/backend/libc/fs/syscalls.rs @@ -10,15 +10,18 @@ use super::super::conv::{syscall_ret, syscall_ret_owned_fd, syscall_ret_ssize_t} use super::super::offset::libc_fallocate; #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] use super::super::offset::libc_posix_fadvise; #[cfg(not(any( + target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "fuchsia", @@ -29,48 +32,61 @@ use super::super::offset::libc_posix_fadvise; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] use super::super::offset::libc_posix_fallocate; use super::super::offset::{libc_fstat, libc_fstatat, libc_ftruncate, libc_lseek, libc_off_t}; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] use super::super::offset::{libc_fstatfs, libc_statfs}; +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +use super::super::offset::{libc_fstatvfs, libc_statvfs}; #[cfg(all( any(target_arch = "arm", target_arch = "mips", target_arch = "x86"), target_env = "gnu", ))] use super::super::time::types::LibcTimespec; -use crate::fd::BorrowedFd; -#[cfg(not(target_os = "wasi"))] -use crate::fd::RawFd; +use crate::fd::{BorrowedFd, OwnedFd}; use crate::ffi::CStr; #[cfg(any(target_os = "ios", target_os = "macos"))] use crate::ffi::CString; -#[cfg(not(target_os = "illumos"))] +#[cfg(not(any(target_os = "illumos", target_os = "solaris")))] use crate::fs::Access; #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] use crate::fs::Advice; #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] use crate::fs::FallocateFlags; -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] use crate::fs::FlockOperation; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] use crate::fs::MemfdFlags; @@ -82,12 +98,13 @@ use crate::fs::MemfdFlags; ))] use crate::fs::SealFlags; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] -// not implemented in libc for netbsd yet use crate::fs::StatFs; #[cfg(any(target_os = "android", target_os = "linux"))] use crate::fs::{cwd, RenameFlags, ResolveFlags, Statx, StatxFlags}; @@ -98,8 +115,16 @@ use crate::fs::{cwd, RenameFlags, ResolveFlags, Statx, StatxFlags}; target_os = "wasi", )))] use crate::fs::{Dev, FileType}; -use crate::fs::{FdFlags, Mode, OFlags, Stat, Timestamps}; -use crate::io::{self, OwnedFd, SeekFrom}; +use crate::fs::{Mode, OFlags, Stat, Timestamps}; +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +use crate::fs::{StatVfs, StatVfsMountFlags}; +use crate::io::{self, SeekFrom}; #[cfg(not(target_os = "wasi"))] use crate::process::{Gid, Uid}; #[cfg(not(all( @@ -179,7 +204,7 @@ pub(crate) fn openat( // Work around <https://sourceware.org/bugzilla/show_bug.cgi?id=17523>. // Basically old glibc versions don't handle O_TMPFILE correctly. #[cfg(all(unix, target_env = "gnu"))] - if oflags.contains(OFlags::TMPFILE) && crate::imp::if_glibc_is_less_than_2_25() { + if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() { return openat_via_syscall(dirfd, path, oflags, mode); } unsafe { @@ -196,9 +221,11 @@ pub(crate) fn openat( } #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] #[inline] @@ -210,6 +237,22 @@ pub(crate) fn statfs(filename: &CStr) -> io::Result<StatFs> { } } +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +#[inline] +pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> { + unsafe { + let mut result = MaybeUninit::<libc_statvfs>::uninit(); + ret(libc_statvfs(c_str(filename), result.as_mut_ptr()))?; + Ok(libc_statvfs_to_statvfs(result.assume_init())) + } +} + #[cfg(not(target_os = "redox"))] #[inline] pub(crate) fn readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, buf: &mut [u8]) -> io::Result<usize> { @@ -349,9 +392,9 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io:: ))] { match statx(dirfd, path, flags, StatxFlags::BASIC_STATS) { - Ok(x) => return statx_to_stat(x), + Ok(x) => statx_to_stat(x), Err(io::Errno::NOSYS) => statat_old(dirfd, path, flags), - Err(e) => return Err(e), + Err(err) => Err(err), } } @@ -390,7 +433,12 @@ fn statat_old(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result< } } -#[cfg(not(any(target_os = "emscripten", target_os = "illumos", target_os = "redox")))] +#[cfg(not(any( + target_os = "emscripten", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", +)))] pub(crate) fn accessat( dirfd: BorrowedFd<'_>, path: &CStr, @@ -757,12 +805,14 @@ pub(crate) fn copy_file_range( #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub(crate) fn fadvise(fd: BorrowedFd<'_>, offset: u64, len: u64, advice: Advice) -> io::Result<()> { let offset = offset as i64; @@ -794,14 +844,6 @@ pub(crate) fn fadvise(fd: BorrowedFd<'_>, offset: u64, len: u64, advice: Advice) } } -pub(crate) fn fcntl_getfd(fd: BorrowedFd<'_>) -> io::Result<FdFlags> { - unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_GETFD)).map(FdFlags::from_bits_truncate) } -} - -pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> { - unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_SETFD, flags.bits())) } -} - pub(crate) fn fcntl_getfl(fd: BorrowedFd<'_>) -> io::Result<OFlags> { unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_GETFL)).map(OFlags::from_bits_truncate) } } @@ -833,11 +875,6 @@ pub(crate) fn fcntl_add_seals(fd: BorrowedFd<'_>, seals: SealFlags) -> io::Resul unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_ADD_SEALS, seals.bits())) } } -#[cfg(not(target_os = "wasi"))] -pub(crate) fn fcntl_dupfd_cloexec(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { - unsafe { ret_owned_fd(c::fcntl(borrowed_fd(fd), c::F_DUPFD_CLOEXEC, min)) } -} - pub(crate) fn seek(fd: BorrowedFd<'_>, pos: SeekFrom) -> io::Result<u64> { let (whence, offset): (c::c_int, libc_off_t) = match pos { SeekFrom::Start(pos) => { @@ -897,7 +934,7 @@ pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>) } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result<()> { unsafe { ret(c::flock(borrowed_fd(fd), operation as c::c_int)) } } @@ -911,9 +948,9 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> { ))] { match statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) { - Ok(x) => return statx_to_stat(x), + Ok(x) => statx_to_stat(x), Err(io::Errno::NOSYS) => fstat_old(fd), - Err(e) => return Err(e), + Err(err) => Err(err), } } @@ -943,11 +980,13 @@ fn fstat_old(fd: BorrowedFd<'_>) -> io::Result<Stat> { } #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", -)))] // not implemented in libc for netbsd yet +)))] pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> { let mut statfs = MaybeUninit::<StatFs>::uninit(); unsafe { @@ -956,6 +995,44 @@ pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> { } } +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> { + let mut statvfs = MaybeUninit::<libc_statvfs>::uninit(); + unsafe { + ret(libc_fstatvfs(borrowed_fd(fd), statvfs.as_mut_ptr()))?; + Ok(libc_statvfs_to_statvfs(statvfs.assume_init())) + } +} + +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi" +)))] +fn libc_statvfs_to_statvfs(from: libc_statvfs) -> StatVfs { + StatVfs { + f_bsize: from.f_bsize as u64, + f_frsize: from.f_frsize as u64, + f_blocks: from.f_blocks as u64, + f_bfree: from.f_bfree as u64, + f_bavail: from.f_bavail as u64, + f_files: from.f_files as u64, + f_ffree: from.f_ffree as u64, + f_favail: from.f_ffree as u64, + f_fsid: from.f_fsid as u64, + f_flag: unsafe { StatVfsMountFlags::from_bits_unchecked(from.f_flag as u64) }, + f_namemax: from.f_namemax as u64, + } +} + pub(crate) fn futimens(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> { // 32-bit gnu version: libc has `futimens` but it is not y2038 safe by default. #[cfg(all( @@ -1058,6 +1135,7 @@ unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> } #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "illumos", target_os = "ios", @@ -1065,6 +1143,7 @@ unsafe fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub(crate) fn fallocate( fd: BorrowedFd<'_>, @@ -1107,7 +1186,7 @@ pub(crate) fn fallocate( assert!(mode.is_empty()); - let new_len = offset.checked_add(len).ok_or_else(|| io::Errno::FBIG)?; + let new_len = offset.checked_add(len).ok_or(io::Errno::FBIG)?; let mut store = c::fstore_t { fst_flags: c::F_ALLOCATECONTIG, fst_posmode: c::F_PEOFPOSMODE, @@ -1130,6 +1209,7 @@ pub(crate) fn fsync(fd: BorrowedFd<'_>) -> io::Result<()> { #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", @@ -1417,6 +1497,28 @@ pub(crate) fn statx( flags: AtFlags, mask: StatxFlags, ) -> io::Result<Statx> { + // If a future Linux kernel adds more fields to `struct statx` and users + // passing flags unknown to rustix in `StatxFlags`, we could end up + // writing outside of the buffer. To prevent this possibility, we mask off + // any flags that we don't know about. + // + // This includes `STATX__RESERVED`, which has a value that we know, but + // which could take on arbitrary new meaning in the future. Linux currently + // rejects this flag with `EINVAL`, so we do the same. + // + // This doesn't rely on `STATX_ALL` because [it's deprecated] and already + // doesn't represent all the known flags. + // + // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/ + #[cfg(not(any(target_os = "android", target_env = "musl")))] + const STATX__RESERVED: u32 = libc::STATX__RESERVED as u32; + #[cfg(any(target_os = "android", target_env = "musl"))] + const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED; + if (mask.bits() & STATX__RESERVED) == STATX__RESERVED { + return Err(io::Errno::INVAL); + } + let mask = mask & StatxFlags::all(); + let mut statx_buf = MaybeUninit::<Statx>::uninit(); unsafe { ret(sys::statx( @@ -1520,7 +1622,7 @@ pub(crate) fn getpath(fd: BorrowedFd<'_>) -> io::Result<CString> { // `F_GETPATH` in terms of `MAXPATHLEN`, and there are no // alternatives. If a better method is invented, it should be used // instead. - let mut buf = vec![0; c::PATH_MAX as usize]; + let mut buf = alloc::vec![0; c::PATH_MAX as usize]; // From the [macOS `fcntl` man page]: // `F_GETPATH` - Get the path of the file descriptor `Fildes`. The argument diff --git a/vendor/rustix/src/imp/libc/fs/types.rs b/vendor/rustix/src/backend/libc/fs/types.rs index 9d892daf0..8d8ec08bf 100644 --- a/vendor/rustix/src/imp/libc/fs/types.rs +++ b/vendor/rustix/src/backend/libc/fs/types.rs @@ -2,17 +2,6 @@ use super::super::c; use bitflags::bitflags; bitflags! { - /// `FD_*` constants for use with [`fcntl_getfd`] and [`fcntl_setfd`]. - /// - /// [`fcntl_getfd`]: crate::fs::fcntl_getfd - /// [`fcntl_setfd`]: crate::fs::fcntl_setfd - pub struct FdFlags: c::c_int { - /// `FD_CLOEXEC` - const CLOEXEC = c::FD_CLOEXEC; - } -} - -bitflags! { /// `*_OK` constants for use with [`accessat`]. /// /// [`accessat`]: fn.accessat.html @@ -438,7 +427,12 @@ impl FileType { } /// Construct a `FileType` from the `d_type` field of a `c::dirent`. - #[cfg(not(any(target_os = "illumos", target_os = "redox")))] + #[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris" + )))] pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self { match d_type { c::DT_REG => Self::RegularFile, @@ -461,12 +455,14 @@ impl FileType { /// [`fadvise`]: crate::fs::fadvise #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[repr(u32)] @@ -681,10 +677,12 @@ bitflags! { } #[cfg(not(any( + target_os = "aix", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] bitflags! { /// `FALLOC_FL_*` constants for use with [`fallocate`]. @@ -693,8 +691,10 @@ bitflags! { pub struct FallocateFlags: i32 { /// `FALLOC_FL_KEEP_SIZE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -704,8 +704,10 @@ bitflags! { const KEEP_SIZE = c::FALLOC_FL_KEEP_SIZE; /// `FALLOC_FL_PUNCH_HOLE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -715,8 +717,10 @@ bitflags! { const PUNCH_HOLE = c::FALLOC_FL_PUNCH_HOLE; /// `FALLOC_FL_NO_HIDE_STALE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "linux", target_os = "macos", @@ -729,8 +733,10 @@ bitflags! { const NO_HIDE_STALE = c::FALLOC_FL_NO_HIDE_STALE; /// `FALLOC_FL_COLLAPSE_RANGE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -741,8 +747,10 @@ bitflags! { const COLLAPSE_RANGE = c::FALLOC_FL_COLLAPSE_RANGE; /// `FALLOC_FL_ZERO_RANGE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -753,8 +761,10 @@ bitflags! { const ZERO_RANGE = c::FALLOC_FL_ZERO_RANGE; /// `FALLOC_FL_INSERT_RANGE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -765,8 +775,10 @@ bitflags! { const INSERT_RANGE = c::FALLOC_FL_INSERT_RANGE; /// `FALLOC_FL_UNSHARE_RANGE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -778,10 +790,56 @@ bitflags! { } } +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +bitflags! { + /// `ST_*` constants for use with [`StatVfs`]. + pub struct StatVfsMountFlags: u64 { + /// `ST_MANDLOCK` + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] + const MANDLOCK = libc::ST_MANDLOCK as u64; + + /// `ST_NOATIME` + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] + const NOATIME = libc::ST_NOATIME as u64; + + /// `ST_NODEV` + #[cfg(any(target_os = "aix", target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] + const NODEV = libc::ST_NODEV as u64; + + /// `ST_NODIRATIME` + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] + const NODIRATIME = libc::ST_NODIRATIME as u64; + + /// `ST_NOEXEC` + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] + const NOEXEC = libc::ST_NOEXEC as u64; + + /// `ST_NOSUID` + const NOSUID = libc::ST_NOSUID as u64; + + /// `ST_RDONLY` + const RDONLY = libc::ST_RDONLY as u64; + + /// `ST_RELATIME` + #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] + const RELATIME = libc::ST_RELATIME as u64; + + /// `ST_SYNCHRONOUS` + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] + const SYNCHRONOUS = libc::ST_SYNCHRONOUS as u64; + } +} + /// `LOCK_*` constants for use with [`flock`] /// /// [`flock`]: crate::fs::flock -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[repr(i32)] pub enum FlockOperation { @@ -858,24 +916,28 @@ pub struct Stat { pub st_ino: u64, } -/// `struct statfs` for use with [`fstatfs`]. +/// `struct statfs` for use with [`statfs`] and [`fstatfs`]. /// +/// [`statfs`]: crate::fs::statfs /// [`fstatfs`]: crate::fs::fstatfs #[cfg(not(any( target_os = "android", target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "linux", target_os = "l4re", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] #[allow(clippy::module_name_repetitions)] pub type StatFs = c::statfs; -/// `struct statfs` for use with [`fstatfs`]. +/// `struct statfs` for use with [`statfs`] and [`fstatfs`]. /// +/// [`statfs`]: crate::fs::statfs /// [`fstatfs`]: crate::fs::fstatfs #[cfg(any( target_os = "android", @@ -885,6 +947,32 @@ pub type StatFs = c::statfs; ))] pub type StatFs = c::statfs64; +/// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`]. +/// +/// [`statvfs`]: crate::fs::statvfs +/// [`fstatvfs`]: crate::fs::fstatvfs +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +#[allow(missing_docs)] +pub struct StatVfs { + pub f_bsize: u64, + pub f_frsize: u64, + pub f_blocks: u64, + pub f_bfree: u64, + pub f_bavail: u64, + pub f_files: u64, + pub f_ffree: u64, + pub f_favail: u64, + pub f_fsid: u64, + pub f_flag: StatVfsMountFlags, + pub f_namemax: u64, +} + /// `struct statx` for use with [`statx`]. /// /// [`statx`]: crate::fs::statx diff --git a/vendor/rustix/src/imp/libc/io/epoll.rs b/vendor/rustix/src/backend/libc/io/epoll.rs index a95e6b5cd..3205a613f 100644 --- a/vendor/rustix/src/imp/libc/io/epoll.rs +++ b/vendor/rustix/src/backend/libc/io/epoll.rs @@ -59,10 +59,10 @@ use super::super::c; use super::super::conv::{ret, ret_owned_fd, ret_u32}; -use crate::fd::{AsFd, AsRawFd, BorrowedFd, RawFd}; +use crate::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; #[cfg(not(feature = "rustc-dep-of-std"))] -use crate::fd::{FromFd, FromRawFd, IntoFd, IntoRawFd}; -use crate::io::{self, OwnedFd}; +use crate::fd::{FromRawFd, IntoRawFd}; +use crate::io; use alloc::vec::Vec; use bitflags::bitflags; use core::convert::TryInto; @@ -207,17 +207,17 @@ impl<'a> Context for Borrowing<'a> { } /// A type implementing [`Context`] where the `Data` type is `T`, a type -/// implementing `IntoFd` and `FromFd`. +/// implementing `From<OwnedFd>` and `From<T> for OwnedFd`. /// /// This may be used with [`OwnedFd`], or higher-level types like /// [`std::fs::File`] or [`std::net::TcpStream`]. #[cfg(not(feature = "rustc-dep-of-std"))] -pub struct Owning<'context, T: IntoFd + FromFd> { +pub struct Owning<'context, T: Into<OwnedFd> + From<OwnedFd>> { _phantom: PhantomData<&'context T>, } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: IntoFd + FromFd> Owning<'context, T> { +impl<'context, T: Into<OwnedFd> + From<OwnedFd>> Owning<'context, T> { /// Creates a new empty `Owning`. #[allow(clippy::new_without_default)] // This is a specialized type that doesn't need to be generically constructible. #[inline] @@ -229,16 +229,17 @@ impl<'context, T: IntoFd + FromFd> Owning<'context, T> { } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> Context for Owning<'context, T> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> Context for Owning<'context, T> { type Data = T; type Target = BorrowedFd<'context>; #[inline] fn acquire<'call>(&self, data: Self::Data) -> Ref<'call, Self::Target> { - let raw_fd = data.into_fd().into_raw_fd(); + let fd: OwnedFd = data.into(); + let raw_fd = fd.into_raw_fd(); // Safety: `epoll` will assign ownership of the file descriptor to the - // kernel epoll object. We use `IntoFd`+`IntoRawFd` to consume the - // `Data` and extract the raw file descriptor and then "borrow" it + // kernel epoll object. We use `Into<OwnedFd>`+`IntoRawFd` to consume + // the `Data` and extract the raw file descriptor and then "borrow" it // with `borrow_raw` knowing that the borrow won't outlive the // kernel epoll object. unsafe { Ref::new(BorrowedFd::<'context>::borrow_raw(raw_fd)) } @@ -260,7 +261,7 @@ impl<'context, T: AsFd + IntoFd + FromFd> Context for Owning<'context, T> { // being released, so we can create a new `OwnedFd` that assumes // ownership. let raw_fd = target.consume().as_raw_fd(); - unsafe { T::from_fd(io_lifetimes::OwnedFd::from_raw_fd(raw_fd)) } + unsafe { T::from(OwnedFd::from_raw_fd(raw_fd).into()) } } } @@ -396,21 +397,21 @@ impl<Context: self::Context> Epoll<Context> { } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> AsRawFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsRawFd for Epoll<Owning<'context, T>> { fn as_raw_fd(&self) -> RawFd { self.epoll_fd.as_raw_fd() } } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> IntoRawFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> IntoRawFd for Epoll<Owning<'context, T>> { fn into_raw_fd(self) -> RawFd { self.epoll_fd.into_raw_fd() } } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> FromRawFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> FromRawFd for Epoll<Owning<'context, T>> { unsafe fn from_raw_fd(fd: RawFd) -> Self { Self { epoll_fd: OwnedFd::from_raw_fd(fd), @@ -420,21 +421,25 @@ impl<'context, T: AsFd + IntoFd + FromFd> FromRawFd for Epoll<Owning<'context, T } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> AsFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsFd for Epoll<Owning<'context, T>> { fn as_fd(&self) -> BorrowedFd<'_> { self.epoll_fd.as_fd() } } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> From<Epoll<Owning<'context, T>>> for OwnedFd { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> From<Epoll<Owning<'context, T>>> + for OwnedFd +{ fn from(epoll: Epoll<Owning<'context, T>>) -> Self { epoll.epoll_fd } } #[cfg(not(feature = "rustc-dep-of-std"))] -impl<'context, T: AsFd + IntoFd + FromFd> From<OwnedFd> for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> From<OwnedFd> + for Epoll<Owning<'context, T>> +{ fn from(fd: OwnedFd) -> Self { Self { epoll_fd: fd, diff --git a/vendor/rustix/src/imp/libc/io/errno.rs b/vendor/rustix/src/backend/libc/io/errno.rs index 470cf205c..131709e0c 100644 --- a/vendor/rustix/src/imp/libc/io/errno.rs +++ b/vendor/rustix/src/backend/libc/io/errno.rs @@ -26,8 +26,10 @@ impl Errno { /// `EADV` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -54,8 +56,10 @@ impl Errno { /// `EBADE` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -68,8 +72,10 @@ impl Errno { /// `EBADFD` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -83,8 +89,10 @@ impl Errno { /// `EBADR` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -105,8 +113,10 @@ impl Errno { /// `EBADRQC` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -117,8 +127,10 @@ impl Errno { /// `EBADSLT` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -129,8 +141,10 @@ impl Errno { /// `EBFONT` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -154,6 +168,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -164,8 +179,10 @@ impl Errno { /// `ECOMM` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -185,9 +202,11 @@ impl Errno { /// `EDEADLOCK` #[cfg(not(any( windows, + target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -209,13 +228,16 @@ impl Errno { /// `EDOTDOT` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const DOTDOT: Self = Self(c::EDOTDOT); @@ -248,15 +270,18 @@ impl Errno { /// `EHWPOISON` #[cfg(not(any( windows, + target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] pub const HWPOISON: Self = Self(c::EHWPOISON); @@ -294,52 +319,64 @@ impl Errno { /// `EISNAM` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const ISNAM: Self = Self(c::EISNAM); /// `EKEYEXPIRED` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const KEYEXPIRED: Self = Self(c::EKEYEXPIRED); /// `EKEYREJECTED` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const KEYREJECTED: Self = Self(c::EKEYREJECTED); /// `EKEYREVOKED` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const KEYREVOKED: Self = Self(c::EKEYREVOKED); @@ -348,6 +385,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -360,6 +398,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -372,6 +411,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -384,6 +424,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -394,8 +435,10 @@ impl Errno { /// `ELIBACC` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -406,8 +449,10 @@ impl Errno { /// `ELIBBAD` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -418,8 +463,10 @@ impl Errno { /// `ELIBEXEC` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -430,8 +477,10 @@ impl Errno { /// `ELIBMAX` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -442,8 +491,10 @@ impl Errno { /// `ELIBSCN` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -456,6 +507,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -468,13 +520,16 @@ impl Errno { /// `EMEDIUMTYPE` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const MEDIUMTYPE: Self = Self(c::EMEDIUMTYPE); @@ -493,13 +548,16 @@ impl Errno { /// `ENAVAIL` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const NAVAIL: Self = Self(c::ENAVAIL); @@ -525,8 +583,10 @@ impl Errno { /// `ENOANO` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -538,6 +598,7 @@ impl Errno { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -551,6 +612,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -563,6 +625,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "openbsd", target_os = "wasi", )))] @@ -579,13 +642,16 @@ impl Errno { /// `ENOKEY` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const NOKEY: Self = Self(c::ENOKEY); @@ -598,13 +664,16 @@ impl Errno { /// `ENOMEDIUM` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const NOMEDIUM: Self = Self(c::ENOMEDIUM); @@ -620,8 +689,10 @@ impl Errno { /// `ENONET` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -632,8 +703,10 @@ impl Errno { /// `ENOPKG` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -651,6 +724,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "openbsd", target_os = "wasi", )))] @@ -660,6 +734,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "openbsd", target_os = "wasi", )))] @@ -668,7 +743,7 @@ impl Errno { #[cfg(not(windows))] pub const NOSYS: Self = Self(c::ENOSYS); /// `ENOTBLK` - #[cfg(not(any(windows, target_os = "wasi")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "wasi")))] pub const NOTBLK: Self = Self(c::ENOTBLK); /// `ENOTCAPABLE` #[cfg(any(target_os = "freebsd", target_os = "wasi"))] @@ -683,23 +758,31 @@ impl Errno { /// `ENOTNAM` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const NOTNAM: Self = Self(c::ENOTNAM); /// `ENOTRECOVERABLE` - #[cfg(not(any(windows, target_os = "dragonfly", target_os = "netbsd")))] + #[cfg(not(any( + windows, + target_os = "dragonfly", + target_os = "haiku", + target_os = "netbsd" + )))] pub const NOTRECOVERABLE: Self = Self(c::ENOTRECOVERABLE); /// `ENOTSOCK` pub const NOTSOCK: Self = Self(c::ENOTSOCK); /// `ENOTSUP` - #[cfg(not(any(windows, target_os = "redox")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "redox")))] pub const NOTSUP: Self = Self(c::ENOTSUP); /// `ENOTTY` #[cfg(not(windows))] @@ -707,8 +790,10 @@ impl Errno { /// `ENOTUNIQ` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -725,7 +810,12 @@ impl Errno { #[cfg(not(windows))] pub const OVERFLOW: Self = Self(c::EOVERFLOW); /// `EOWNERDEAD` - #[cfg(not(any(windows, target_os = "dragonfly", target_os = "netbsd")))] + #[cfg(not(any( + windows, + target_os = "haiku", + target_os = "dragonfly", + target_os = "netbsd" + )))] pub const OWNERDEAD: Self = Self(c::EOWNERDEAD); /// `EPERM` #[cfg(not(windows))] @@ -795,8 +885,10 @@ impl Errno { /// `EREMCHG` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -805,18 +897,21 @@ impl Errno { )))] pub const REMCHG: Self = Self(c::EREMCHG); /// `EREMOTE` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] pub const REMOTE: Self = Self(c::EREMOTE); /// `EREMOTEIO` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const REMOTEIO: Self = Self(c::EREMOTEIO); @@ -825,6 +920,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -835,15 +931,18 @@ impl Errno { /// `ERFKILL` #[cfg(not(any( windows, + target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] pub const RFKILL: Self = Self(c::ERFKILL); @@ -864,7 +963,7 @@ impl Errno { #[cfg(not(target_os = "wasi"))] pub const SHUTDOWN: Self = Self(c::ESHUTDOWN); /// `ESOCKTNOSUPPORT` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] pub const SOCKTNOSUPPORT: Self = Self(c::ESOCKTNOSUPPORT); /// `ESPIPE` #[cfg(not(windows))] @@ -875,8 +974,10 @@ impl Errno { /// `ESRMNT` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -889,8 +990,10 @@ impl Errno { /// `ESTRPIPE` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -914,7 +1017,7 @@ impl Errno { #[doc(alias = "2BIG")] pub const TOOBIG: Self = Self(c::E2BIG); /// `ETOOMANYREFS` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] pub const TOOMANYREFS: Self = Self(c::ETOOMANYREFS); /// `ETXTBSY` #[cfg(not(windows))] @@ -922,13 +1025,16 @@ impl Errno { /// `EUCLEAN` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "wasi", )))] pub const UCLEAN: Self = Self(c::EUCLEAN); @@ -937,6 +1043,7 @@ impl Errno { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -945,7 +1052,7 @@ impl Errno { )))] pub const UNATCH: Self = Self(c::EUNATCH); /// `EUSERS` - #[cfg(not(target_os = "wasi"))] + #[cfg(not(any(target_os = "haiku", target_os = "wasi")))] pub const USERS: Self = Self(c::EUSERS); /// `EWOULDBLOCK` pub const WOULDBLOCK: Self = Self(c::EWOULDBLOCK); @@ -955,8 +1062,10 @@ impl Errno { /// `EXFULL` #[cfg(not(any( windows, + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", diff --git a/vendor/rustix/src/imp/libc/io/io_slice.rs b/vendor/rustix/src/backend/libc/io/io_slice.rs index 81c504d25..de1ef434c 100644 --- a/vendor/rustix/src/imp/libc/io/io_slice.rs +++ b/vendor/rustix/src/backend/libc/io/io_slice.rs @@ -2,6 +2,8 @@ //! library/std/src/sys/unix/io.rs //! dca3f1b786efd27be3b325ed1e01e247aa589c3b. +#![allow(missing_docs)] + use super::super::c; use core::marker::PhantomData; use core::slice; diff --git a/vendor/rustix/src/imp/libc/io/mod.rs b/vendor/rustix/src/backend/libc/io/mod.rs index 1378adf3d..1378adf3d 100644 --- a/vendor/rustix/src/imp/libc/io/mod.rs +++ b/vendor/rustix/src/backend/libc/io/mod.rs diff --git a/vendor/rustix/src/imp/libc/io/poll_fd.rs b/vendor/rustix/src/backend/libc/io/poll_fd.rs index c516a9309..c516a9309 100644 --- a/vendor/rustix/src/imp/libc/io/poll_fd.rs +++ b/vendor/rustix/src/backend/libc/io/poll_fd.rs diff --git a/vendor/rustix/src/imp/libc/io/syscalls.rs b/vendor/rustix/src/backend/libc/io/syscalls.rs index 4fafbfd66..3774e700a 100644 --- a/vendor/rustix/src/imp/libc/io/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/syscalls.rs @@ -7,22 +7,30 @@ use super::super::conv::{ borrowed_fd, ret, ret_c_int, ret_discarded_fd, ret_owned_fd, ret_ssize_t, }; use super::super::offset::{libc_pread, libc_pwrite}; -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] use super::super::offset::{libc_preadv, libc_pwritev}; #[cfg(all(target_os = "linux", target_env = "gnu"))] use super::super::offset::{libc_preadv2, libc_pwritev2}; -use crate::fd::{AsFd, BorrowedFd, RawFd}; -#[cfg(not(target_os = "wasi"))] +use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; +#[cfg(not(any(target_os = "aix", target_os = "wasi")))] use crate::io::DupFlags; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "wasi")))] +#[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "wasi" +)))] use crate::io::PipeFlags; -use crate::io::{self, IoSlice, IoSliceMut, OwnedFd, PollFd}; +use crate::io::{self, FdFlags, IoSlice, IoSliceMut, PollFd}; #[cfg(any(target_os = "android", target_os = "linux"))] -use crate::io::{EventfdFlags, ReadWriteFlags}; +use crate::io::{EventfdFlags, IoSliceRaw, ReadWriteFlags, SpliceFlags}; use core::cmp::min; use core::convert::TryInto; use core::mem::MaybeUninit; -#[cfg(feature = "net")] +#[cfg(any(target_os = "android", target_os = "linux"))] +use core::ptr; +#[cfg(all(feature = "fs", feature = "net"))] use libc_errno::errno; pub(crate) fn read(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> { @@ -103,7 +111,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> Ok(nwritten as usize) } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] pub(crate) fn preadv( fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut], @@ -122,7 +130,7 @@ pub(crate) fn preadv( Ok(nread as usize) } -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result<usize> { // Silently cast; we'll get `EINVAL` if the value is negative. let offset = offset as i64; @@ -314,7 +322,7 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> { } #[cfg(not(any(target_os = "redox", target_os = "wasi")))] -#[cfg(feature = "net")] +#[cfg(all(feature = "fs", feature = "net"))] pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { let (mut read, mut write) = crate::fs::fd::_is_file_read_write(fd)?; let mut not_socket = false; @@ -361,11 +369,24 @@ pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { } #[cfg(target_os = "wasi")] -#[cfg(feature = "net")] +#[cfg(all(feature = "fs", feature = "net"))] pub(crate) fn is_read_write(_fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { todo!("Implement is_read_write for WASI in terms of fd_fdstat_get"); } +pub(crate) fn fcntl_getfd(fd: BorrowedFd<'_>) -> io::Result<FdFlags> { + unsafe { ret_c_int(c::fcntl(borrowed_fd(fd), c::F_GETFD)).map(FdFlags::from_bits_truncate) } +} + +pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> { + unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_SETFD, flags.bits())) } +} + +#[cfg(not(target_os = "wasi"))] +pub(crate) fn fcntl_dupfd_cloexec(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { + unsafe { ret_owned_fd(c::fcntl(borrowed_fd(fd), c::F_DUPFD_CLOEXEC, min)) } +} + #[cfg(not(target_os = "wasi"))] pub(crate) fn dup(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> { unsafe { ret_owned_fd(c::dup(borrowed_fd(fd))) } @@ -377,8 +398,10 @@ pub(crate) fn dup2(fd: BorrowedFd<'_>, new: &mut OwnedFd) -> io::Result<()> { } #[cfg(not(any( + target_os = "aix", target_os = "android", target_os = "dragonfly", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", @@ -397,6 +420,7 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, flags: DupFlags) -> io #[cfg(any( target_os = "android", target_os = "dragonfly", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", @@ -414,12 +438,12 @@ pub(crate) fn ioctl_fioclex(fd: BorrowedFd<'_>) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::FIOCLEX)) } } -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub(crate) fn ioctl_tiocexcl(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCEXCL as _)) } } -#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> { unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) } } @@ -434,7 +458,13 @@ pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { } } -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "wasi")))] +#[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "wasi" +)))] pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { unsafe { let mut result = MaybeUninit::<[OwnedFd; 2]>::uninit(); @@ -454,3 +484,50 @@ pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usiz ret_c_int(unsafe { c::poll(fds.as_mut_ptr().cast(), nfds, timeout) }) .map(|nready| nready as usize) } + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub fn splice( + fd_in: BorrowedFd, + off_in: Option<&mut u64>, + fd_out: BorrowedFd, + off_out: Option<&mut u64>, + len: usize, + flags: SpliceFlags, +) -> io::Result<usize> { + let off_in = off_in + .map(|off| (off as *mut u64).cast()) + .unwrap_or(ptr::null_mut()); + + let off_out = off_out + .map(|off| (off as *mut u64).cast()) + .unwrap_or(ptr::null_mut()); + + ret_ssize_t(unsafe { + c::splice( + borrowed_fd(fd_in), + off_in, + borrowed_fd(fd_out), + off_out, + len, + flags.bits(), + ) + }) + .map(|spliced| spliced as usize) +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub unsafe fn vmsplice( + fd: BorrowedFd, + bufs: &[IoSliceRaw], + flags: SpliceFlags, +) -> io::Result<usize> { + ret_ssize_t(c::vmsplice( + borrowed_fd(fd), + bufs.as_ptr().cast::<c::iovec>(), + min(bufs.len(), max_iov()), + flags.bits(), + )) + .map(|spliced| spliced as usize) +} diff --git a/vendor/rustix/src/imp/libc/io/types.rs b/vendor/rustix/src/backend/libc/io/types.rs index 483f3a6af..46d5f6332 100644 --- a/vendor/rustix/src/imp/libc/io/types.rs +++ b/vendor/rustix/src/backend/libc/io/types.rs @@ -1,6 +1,18 @@ use super::super::c; -#[cfg(not(target_os = "wasi"))] use bitflags::bitflags; +#[cfg(any(target_os = "android", target_os = "linux"))] +use core::marker::PhantomData; + +bitflags! { + /// `FD_*` constants for use with [`fcntl_getfd`] and [`fcntl_setfd`]. + /// + /// [`fcntl_getfd`]: crate::io::fcntl_getfd + /// [`fcntl_setfd`]: crate::io::fcntl_setfd + pub struct FdFlags: c::c_int { + /// `FD_CLOEXEC` + const CLOEXEC = c::FD_CLOEXEC; + } +} #[cfg(any(target_os = "android", target_os = "linux"))] bitflags! { @@ -27,6 +39,21 @@ bitflags! { } } +#[cfg(any(target_os = "android", target_os = "linux"))] +bitflags! { + /// `SPLICE_F_*` constants for use with [`splice`] and [`vmsplice`]. + pub struct SpliceFlags: c::c_uint { + /// `SPLICE_F_MOVE` + const MOVE = c::SPLICE_F_MOVE; + /// `SPLICE_F_NONBLOCK` + const NONBLOCK = c::SPLICE_F_NONBLOCK; + /// `SPLICE_F_MORE` + const MORE = c::SPLICE_F_MORE; + /// `SPLICE_F_GIFT` + const GIFT = c::SPLICE_F_GIFT; + } +} + #[cfg(not(target_os = "wasi"))] bitflags! { /// `O_*` constants for use with [`dup2`]. @@ -53,7 +80,13 @@ bitflags! { /// `O_CLOEXEC` const CLOEXEC = c::O_CLOEXEC; /// `O_DIRECT` - #[cfg(not(any(target_os = "illumos", target_os = "openbsd", target_os = "redox")))] + #[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "openbsd", + target_os = "redox", + target_os = "solaris", + )))] const DIRECT = c::O_DIRECT; /// `O_NONBLOCK` const NONBLOCK = c::O_NONBLOCK; @@ -76,7 +109,13 @@ bitflags! { } /// `PIPE_BUF`—The maximum size of a write to a pipe guaranteed to be atomic. -#[cfg(not(any(target_os = "illumos", target_os = "redox", target_os = "wasi")))] +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] pub const PIPE_BUF: usize = c::PIPE_BUF; #[cfg(not(any(windows, target_os = "redox")))] @@ -87,3 +126,39 @@ pub(crate) const STDIN_FILENO: c::c_int = c::STDIN_FILENO; pub(crate) const STDOUT_FILENO: c::c_int = c::STDOUT_FILENO; #[cfg(not(windows))] pub(crate) const STDERR_FILENO: c::c_int = c::STDERR_FILENO; + +/// A buffer type used with `vmsplice`. +/// It is guaranteed to be ABI compatible with the iovec type on Unix platforms and WSABUF on Windows. +/// Unlike `IoSlice` and `IoSliceMut` it is semantically like a raw pointer, +/// and therefore can be shared or mutated as needed. +#[cfg(any(target_os = "android", target_os = "linux"))] +#[repr(transparent)] +pub struct IoSliceRaw<'a> { + _buf: c::iovec, + _lifetime: PhantomData<&'a ()>, +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +impl<'a> IoSliceRaw<'a> { + /// Creates a new IoSlice wrapping a byte slice. + pub fn from_slice(buf: &'a [u8]) -> Self { + IoSliceRaw { + _buf: c::iovec { + iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void, + iov_len: buf.len() as _, + }, + _lifetime: PhantomData, + } + } + + /// Creates a new IoSlice wrapping a mutable byte slice. + pub fn from_slice_mut(buf: &'a mut [u8]) -> Self { + IoSliceRaw { + _buf: c::iovec { + iov_base: buf.as_mut_ptr() as *mut c::c_void, + iov_len: buf.len() as _, + }, + _lifetime: PhantomData, + } + } +} diff --git a/vendor/rustix/src/imp/libc/io/windows_syscalls.rs b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs index 4c6e86f94..4c6e86f94 100644 --- a/vendor/rustix/src/imp/libc/io/windows_syscalls.rs +++ b/vendor/rustix/src/backend/libc/io/windows_syscalls.rs diff --git a/vendor/rustix/src/imp/libc/io_lifetimes.rs b/vendor/rustix/src/backend/libc/io_lifetimes.rs index b0b14b7c8..2dcd772e8 100644 --- a/vendor/rustix/src/imp/libc/io_lifetimes.rs +++ b/vendor/rustix/src/backend/libc/io_lifetimes.rs @@ -9,7 +9,7 @@ pub use std::os::windows::io::RawSocket as RawFd; pub(crate) use windows_sys::Win32::Networking::WinSock::SOCKET as LibcFd; // Re-export the `Socket` traits so that users can implement them. -pub use io_lifetimes::{AsSocket, FromSocket, IntoSocket}; +pub use io_lifetimes::AsSocket; /// A version of [`AsRawFd`] for use with Winsock2 API. /// @@ -75,35 +75,3 @@ impl<T: AsSocket> AsFd for T { self.as_socket() } } - -/// A version of [`IntoFd`] for use with Winsock2 API. -/// -/// [`IntoFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html -pub trait IntoFd { - /// A version of [`into_fd`] for use with Winsock2 API. - /// - /// [`into_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.IntoFd.html#tymethod.into_fd - fn into_fd(self) -> OwnedFd; -} -impl<T: IntoSocket> IntoFd for T { - #[inline] - fn into_fd(self) -> OwnedFd { - self.into_socket() - } -} - -/// A version of [`FromFd`] for use with Winsock2 API. -/// -/// [`FromFd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html -pub trait FromFd { - /// A version of [`from_fd`] for use with Winsock2 API. - /// - /// [`from_fd`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/trait.FromFd.html#tymethod.from_fd - fn from_fd(fd: OwnedFd) -> Self; -} -impl<T: FromSocket> FromFd for T { - #[inline] - fn from_fd(fd: OwnedFd) -> Self { - Self::from_socket(fd) - } -} diff --git a/vendor/rustix/src/imp/libc/io_uring/mod.rs b/vendor/rustix/src/backend/libc/io_uring/mod.rs index ef944f04d..ef944f04d 100644 --- a/vendor/rustix/src/imp/libc/io_uring/mod.rs +++ b/vendor/rustix/src/backend/libc/io_uring/mod.rs diff --git a/vendor/rustix/src/imp/libc/io_uring/syscalls.rs b/vendor/rustix/src/backend/libc/io_uring/syscalls.rs index d1e68363c..31fcec3db 100644 --- a/vendor/rustix/src/imp/libc/io_uring/syscalls.rs +++ b/vendor/rustix/src/backend/libc/io_uring/syscalls.rs @@ -2,8 +2,8 @@ use super::super::c; use super::super::conv::{borrowed_fd, syscall_ret, syscall_ret_owned_fd, syscall_ret_u32}; -use crate::fd::BorrowedFd; -use crate::io::{self, OwnedFd}; +use crate::fd::{BorrowedFd, OwnedFd}; +use crate::io; use crate::io_uring::{io_uring_params, IoringEnterFlags, IoringRegisterOp}; use linux_raw_sys::general::{__NR_io_uring_enter, __NR_io_uring_register, __NR_io_uring_setup}; diff --git a/vendor/rustix/src/imp/libc/mm/mod.rs b/vendor/rustix/src/backend/libc/mm/mod.rs index 1e0181a99..1e0181a99 100644 --- a/vendor/rustix/src/imp/libc/mm/mod.rs +++ b/vendor/rustix/src/backend/libc/mm/mod.rs diff --git a/vendor/rustix/src/imp/libc/mm/syscalls.rs b/vendor/rustix/src/backend/libc/mm/syscalls.rs index ee670b5bf..a1d2df1af 100644 --- a/vendor/rustix/src/imp/libc/mm/syscalls.rs +++ b/vendor/rustix/src/backend/libc/mm/syscalls.rs @@ -13,9 +13,9 @@ use super::types::{MapFlags, MprotectFlags, MsyncFlags, ProtFlags}; #[cfg(any(target_os = "android", target_os = "linux"))] use super::types::{MlockFlags, UserfaultfdFlags}; use crate::fd::BorrowedFd; -use crate::io; #[cfg(any(target_os = "android", target_os = "linux"))] -use crate::io::OwnedFd; +use crate::fd::OwnedFd; +use crate::io; #[cfg(not(target_os = "redox"))] pub(crate) fn madvise(addr: *mut c::c_void, len: usize, advice: Advice) -> io::Result<()> { diff --git a/vendor/rustix/src/imp/libc/mm/types.rs b/vendor/rustix/src/backend/libc/mm/types.rs index 385b6c0e6..11ab708cf 100644 --- a/vendor/rustix/src/imp/libc/mm/types.rs +++ b/vendor/rustix/src/backend/libc/mm/types.rs @@ -56,12 +56,14 @@ bitflags! { target_os = "emscripten", target_os = "freebsd", target_os = "fuchsia", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const SHARED_VALIDATE = c::MAP_SHARED_VALIDATE; /// `MAP_PRIVATE` @@ -70,12 +72,14 @@ bitflags! { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const DENYWRITE = c::MAP_DENYWRITE; /// `MAP_FIXED` @@ -87,36 +91,42 @@ bitflags! { target_os = "emscripten", target_os = "freebsd", target_os = "fuchsia", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const FIXED_NOREPLACE = c::MAP_FIXED_NOREPLACE; /// `MAP_GROWSDOWN` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const GROWSDOWN = c::MAP_GROWSDOWN; /// `MAP_HUGETLB` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const HUGETLB = c::MAP_HUGETLB; /// `MAP_HUGE_2MB` @@ -126,12 +136,14 @@ bitflags! { target_os = "emscripten", target_os = "freebsd", target_os = "fuchsia", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const HUGE_2MB = c::MAP_HUGE_2MB; /// `MAP_HUGE_1GB` @@ -141,51 +153,68 @@ bitflags! { target_os = "emscripten", target_os = "freebsd", target_os = "fuchsia", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const HUGE_1GB = c::MAP_HUGE_1GB; /// `MAP_LOCKED` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const LOCKED = c::MAP_LOCKED; + /// `MAP_NOCORE` + #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] + const NOCORE = c::MAP_NOCORE; /// `MAP_NORESERVE` #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "redox")))] const NORESERVE = c::MAP_NORESERVE; + /// `MAP_NOSYNC` + #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))] + const NOSYNC = c::MAP_NOSYNC; /// `MAP_POPULATE` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] const POPULATE = c::MAP_POPULATE; /// `MAP_STACK` #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", )))] const STACK = c::MAP_STACK; + /// `MAP_PREFAULT_READ` + #[cfg(target_os = "freebsd")] + const PREFAULT_READ = c::MAP_PREFAULT_READ; /// `MAP_SYNC` #[cfg(not(any( target_os = "android", @@ -193,12 +222,14 @@ bitflags! { target_os = "emscripten", target_os = "freebsd", target_os = "fuchsia", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", all( any(target_os = "android", target_os = "linux"), any(target_arch = "mips", target_arch = "mips64"), @@ -262,43 +293,43 @@ bitflags! { #[non_exhaustive] pub enum Advice { /// `POSIX_MADV_NORMAL` - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "haiku")))] Normal = c::POSIX_MADV_NORMAL, /// `POSIX_MADV_NORMAL` - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "haiku"))] Normal = c::MADV_NORMAL, /// `POSIX_MADV_SEQUENTIAL` - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "haiku")))] Sequential = c::POSIX_MADV_SEQUENTIAL, /// `POSIX_MADV_SEQUENTIAL` - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "haiku"))] Sequential = c::MADV_SEQUENTIAL, /// `POSIX_MADV_RANDOM` - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "haiku")))] Random = c::POSIX_MADV_RANDOM, /// `POSIX_MADV_RANDOM` - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "haiku"))] Random = c::MADV_RANDOM, /// `POSIX_MADV_WILLNEED` - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "haiku")))] WillNeed = c::POSIX_MADV_WILLNEED, /// `POSIX_MADV_WILLNEED` - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "haiku"))] WillNeed = c::MADV_WILLNEED, /// `POSIX_MADV_DONTNEED` - #[cfg(not(any(target_os = "android", target_os = "emscripten")))] + #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "haiku")))] DontNeed = c::POSIX_MADV_DONTNEED, /// `POSIX_MADV_DONTNEED` - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "haiku"))] DontNeed = i32::MAX - 1, /// `MADV_DONTNEED` diff --git a/vendor/rustix/src/imp/libc/mod.rs b/vendor/rustix/src/backend/libc/mod.rs index e99a323ce..16d21b657 100644 --- a/vendor/rustix/src/imp/libc/mod.rs +++ b/vendor/rustix/src/backend/libc/mod.rs @@ -56,7 +56,7 @@ pub(crate) mod c; pub(crate) use libc as c; #[cfg(not(windows))] -// #[cfg(feature = "fs")] // TODO: Enable this once `OwnedFd` moves out of the tree. +#[cfg(feature = "fs")] pub(crate) mod fs; pub(crate) mod io; #[cfg(any(target_os = "android", target_os = "linux"))] @@ -64,7 +64,7 @@ pub(crate) mod io; #[cfg_attr(doc_cfg, doc(cfg(feature = "io_uring")))] pub(crate) mod io_uring; #[cfg(not(any(windows, target_os = "wasi")))] -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` +#[cfg(feature = "mm")] pub(crate) mod mm; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] #[cfg(feature = "net")] @@ -101,7 +101,7 @@ pub(crate) mod time; #[cfg(all(unix, target_env = "gnu"))] pub(crate) fn if_glibc_is_less_than_2_25() -> bool { // This is also defined inside `weak_or_syscall!` in - // imp/libc/rand/syscalls.rs, but it's not convenient to re-export the weak + // backend/libc/rand/syscalls.rs, but it's not convenient to re-export the weak // symbol from that macro, so we duplicate it at a small cost here. weak! { fn getrandom(*mut c::c_void, c::size_t, c::c_uint) -> c::ssize_t } diff --git a/vendor/rustix/src/imp/libc/net/addr.rs b/vendor/rustix/src/backend/libc/net/addr.rs index 1aeda5e5d..ba64ed279 100644 --- a/vendor/rustix/src/imp/libc/net/addr.rs +++ b/vendor/rustix/src/backend/libc/net/addr.rs @@ -109,6 +109,7 @@ impl SocketAddrUnix { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -128,12 +129,15 @@ impl SocketAddrUnix { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", )))] sun_path: [0; 108], + #[cfg(target_os = "haiku")] + sun_path: [0; 126], } } @@ -273,6 +277,7 @@ pub(crate) fn offsetof_sun_path() -> usize { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -282,6 +287,7 @@ pub(crate) fn offsetof_sun_path() -> usize { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -291,6 +297,7 @@ pub(crate) fn offsetof_sun_path() -> usize { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -309,12 +316,15 @@ pub(crate) fn offsetof_sun_path() -> usize { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", )))] sun_path: [0; 108], + #[cfg(target_os = "haiku")] + sun_path: [0; 126], }; (crate::utils::as_ptr(&z.sun_path) as usize) - (crate::utils::as_ptr(&z) as usize) } diff --git a/vendor/rustix/src/imp/libc/net/ext.rs b/vendor/rustix/src/backend/libc/net/ext.rs index 7b5313c51..1c8f9f65c 100644 --- a/vendor/rustix/src/imp/libc/net/ext.rs +++ b/vendor/rustix/src/backend/libc/net/ext.rs @@ -127,27 +127,13 @@ pub(crate) fn sockaddr_in6_sin6_scope_id(addr: c::sockaddr_in6) -> u32 { addr.sin6_scope_id } -#[cfg(not(feature = "std"))] -#[cfg(not(windows))] -#[inline] -pub(crate) fn sockaddr_in6_sin6_scope_id_mut(addr: &mut c::sockaddr_in6) -> &mut u32 { - &mut addr.sin6_scope_id -} - -#[cfg(not(feature = "std"))] -#[cfg(windows)] -#[inline] -pub(crate) fn sockaddr_in6_sin6_scope_id_mut(addr: &mut c::sockaddr_in6) -> &mut u32 { - let addr: &mut sockaddr_in6 = unsafe { core::mem::transmute(addr) }; - &mut addr.sin6_scope_id -} - #[cfg(not(windows))] #[inline] pub(crate) const fn sockaddr_in6_new( #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -164,6 +150,7 @@ pub(crate) const fn sockaddr_in6_new( #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -175,7 +162,7 @@ pub(crate) const fn sockaddr_in6_new( sin6_flowinfo, sin6_addr, sin6_scope_id, - #[cfg(target_os = "illumos")] + #[cfg(any(target_os = "illumos", target_os = "solaris"))] __sin6_src_id: 0, } } diff --git a/vendor/rustix/src/imp/libc/net/mod.rs b/vendor/rustix/src/backend/libc/net/mod.rs index f7196ae4f..f7196ae4f 100644 --- a/vendor/rustix/src/imp/libc/net/mod.rs +++ b/vendor/rustix/src/backend/libc/net/mod.rs diff --git a/vendor/rustix/src/imp/libc/net/read_sockaddr.rs b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs index cb76b296c..5a946fbeb 100644 --- a/vendor/rustix/src/imp/libc/net/read_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/read_sockaddr.rs @@ -49,6 +49,7 @@ unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -58,6 +59,7 @@ unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -67,13 +69,17 @@ unsafe fn read_ss_family(storage: *const c::sockaddr_storage) -> u16 { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", )))] sa_family: 0_u16, + #[cfg(not(target_os = "haiku"))] sa_data: [0; 14], + #[cfg(target_os = "haiku")] + sa_data: [0; 30], }; (*storage.cast::<sockaddr_header>()).ss_family.into() diff --git a/vendor/rustix/src/imp/libc/net/send_recv.rs b/vendor/rustix/src/backend/libc/net/send_recv.rs index 9ab908d62..8d1cc8ab7 100644 --- a/vendor/rustix/src/imp/libc/net/send_recv.rs +++ b/vendor/rustix/src/backend/libc/net/send_recv.rs @@ -9,11 +9,13 @@ bitflags! { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] const CONFIRM = c::MSG_CONFIRM; /// `MSG_DONTROUTE` @@ -29,11 +31,13 @@ bitflags! { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] const MORE = c::MSG_MORE; #[cfg(not(any(windows, target_os = "ios", target_os = "macos")))] @@ -47,7 +51,7 @@ bitflags! { bitflags! { /// `MSG_*` pub struct RecvFlags: i32 { - #[cfg(not(any(windows, target_os = "illumos", target_os = "ios", target_os = "macos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "solaris")))] /// `MSG_CMSG_CLOEXEC` const CMSG_CLOEXEC = c::MSG_CMSG_CLOEXEC; /// `MSG_DONTWAIT` @@ -58,11 +62,13 @@ bitflags! { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] const ERRQUEUE = c::MSG_ERRQUEUE; /// `MSG_OOB` diff --git a/vendor/rustix/src/imp/libc/net/syscalls.rs b/vendor/rustix/src/backend/libc/net/syscalls.rs index b0bab2e31..3d8a849c7 100644 --- a/vendor/rustix/src/imp/libc/net/syscalls.rs +++ b/vendor/rustix/src/backend/libc/net/syscalls.rs @@ -15,8 +15,8 @@ use super::send_recv::{RecvFlags, SendFlags}; use super::types::{AcceptFlags, AddressFamily, Protocol, Shutdown, SocketFlags, SocketType}; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] use super::write_sockaddr::{encode_sockaddr_v4, encode_sockaddr_v6}; -use crate::fd::BorrowedFd; -use crate::io::{self, OwnedFd}; +use crate::fd::{BorrowedFd, OwnedFd}; +use crate::io; use crate::net::{SocketAddrAny, SocketAddrV4, SocketAddrV6}; use crate::utils::as_ptr; use core::convert::TryInto; @@ -252,6 +252,7 @@ pub(crate) fn accept(sockfd: BorrowedFd<'_>) -> io::Result<OwnedFd> { #[cfg(not(any( windows, + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", @@ -288,6 +289,7 @@ pub(crate) fn acceptfrom(sockfd: BorrowedFd<'_>) -> io::Result<(OwnedFd, Option< #[cfg(not(any( windows, + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", @@ -315,14 +317,14 @@ pub(crate) fn acceptfrom_with( /// Darwin lacks `accept4`, but does have `accept`. We define /// `AcceptFlags` to have no flags, so we can discard it here. -#[cfg(any(windows, target_os = "ios", target_os = "macos"))] +#[cfg(any(windows, target_os = "haiku", target_os = "ios", target_os = "macos"))] pub(crate) fn accept_with(sockfd: BorrowedFd<'_>, _flags: AcceptFlags) -> io::Result<OwnedFd> { accept(sockfd) } /// Darwin lacks `accept4`, but does have `accept`. We define /// `AcceptFlags` to have no flags, so we can discard it here. -#[cfg(any(windows, target_os = "ios", target_os = "macos"))] +#[cfg(any(windows, target_os = "haiku", target_os = "ios", target_os = "macos"))] pub(crate) fn acceptfrom_with( sockfd: BorrowedFd<'_>, _flags: AcceptFlags, @@ -700,6 +702,24 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn set_ipv6_multicast_hops( + fd: BorrowedFd<'_>, + multicast_hops: u32, + ) -> io::Result<()> { + setsockopt( + fd, + c::IPPROTO_IP as _, + c::IPV6_MULTICAST_LOOP, + multicast_hops, + ) + } + + #[inline] + pub(crate) fn get_ipv6_multicast_hops(fd: BorrowedFd<'_>) -> io::Result<u32> { + getsockopt(fd, c::IPPROTO_IP as _, c::IPV6_MULTICAST_LOOP) + } + + #[inline] pub(crate) fn set_ip_add_membership( fd: BorrowedFd<'_>, multiaddr: &Ipv4Addr, diff --git a/vendor/rustix/src/imp/libc/net/types.rs b/vendor/rustix/src/backend/libc/net/types.rs index 63e3a317e..19d97e7c7 100644 --- a/vendor/rustix/src/imp/libc/net/types.rs +++ b/vendor/rustix/src/backend/libc/net/types.rs @@ -27,6 +27,7 @@ impl SocketType { pub const RAW: Self = Self(c::SOCK_RAW as u32); /// `SOCK_RDM` + #[cfg(not(target_os = "haiku"))] pub const RDM: Self = Self(c::SOCK_RDM as u32); /// Constructs a `SocketType` from a raw integer. @@ -64,11 +65,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const NETLINK: Self = Self(c::AF_NETLINK as _); /// `AF_UNIX`, aka `AF_LOCAL` @@ -79,11 +82,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const AX25: Self = Self(c::AF_AX25 as _); /// `AF_IPX` @@ -95,11 +100,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const NETROM: Self = Self(c::AF_NETROM as _); /// `AF_BRIDGE` @@ -107,11 +114,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const BRIDGE: Self = Self(c::AF_BRIDGE as _); /// `AF_ATMPVC` @@ -119,11 +128,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const ATMPVC: Self = Self(c::AF_ATMPVC as _); /// `AF_X25` @@ -131,6 +142,7 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -142,26 +154,31 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const ROSE: Self = Self(c::AF_ROSE as _); /// `AF_DECnet` #[allow(non_upper_case_globals)] + #[cfg(not(target_os = "haiku"))] pub const DECnet: Self = Self(c::AF_DECnet as _); /// `AF_NETBEUI` #[cfg(not(any( windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const NETBEUI: Self = Self(c::AF_NETBEUI as _); /// `AF_SECURITY` @@ -169,11 +186,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const SECURITY: Self = Self(c::AF_SECURITY as _); /// `AF_KEY` @@ -181,6 +200,7 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -192,6 +212,7 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -203,11 +224,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const ASH: Self = Self(c::AF_ASH as _); /// `AF_ECONET` @@ -215,11 +238,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const ECONET: Self = Self(c::AF_ECONET as _); /// `AF_ATMSVC` @@ -227,11 +252,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const ATMSVC: Self = Self(c::AF_ATMSVC as _); /// `AF_RDS` @@ -239,24 +266,29 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const RDS: Self = Self(c::AF_RDS as _); /// `AF_SNA` + #[cfg(not(target_os = "haiku"))] pub const SNA: Self = Self(c::AF_SNA as _); /// `AF_IRDA` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const IRDA: Self = Self(c::AF_IRDA as _); /// `AF_PPPOX` @@ -264,11 +296,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const PPPOX: Self = Self(c::AF_PPPOX as _); /// `AF_WANPIPE` @@ -276,11 +310,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const WANPIPE: Self = Self(c::AF_WANPIPE as _); /// `AF_LLC` @@ -288,11 +324,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const LLC: Self = Self(c::AF_LLC as _); /// `AF_CAN` @@ -300,11 +338,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const CAN: Self = Self(c::AF_CAN as _); /// `AF_TIPC` @@ -312,26 +352,30 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const TIPC: Self = Self(c::AF_TIPC as _); /// `AF_BLUETOOTH` - #[cfg(not(any(windows, target_os = "illumos", target_os = "ios", target_os = "macos")))] + #[cfg(not(any(windows, target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "solaris")))] pub const BLUETOOTH: Self = Self(c::AF_BLUETOOTH as _); /// `AF_IUCV` #[cfg(not(any( windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const IUCV: Self = Self(c::AF_IUCV as _); /// `AF_RXRPC` @@ -339,26 +383,30 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const RXRPC: Self = Self(c::AF_RXRPC as _); /// `AF_ISDN` - #[cfg(not(any(windows, target_os = "illumos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const ISDN: Self = Self(c::AF_ISDN as _); /// `AF_PHONET` #[cfg(not(any( windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const PHONET: Self = Self(c::AF_PHONET as _); /// `AF_IEEE802154` @@ -366,11 +414,13 @@ impl AddressFamily { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const IEEE802154: Self = Self(c::AF_IEEE802154 as _); @@ -403,57 +453,61 @@ impl Protocol { /// `IPPROTO_ICMP` pub const ICMP: Self = Self(c::IPPROTO_ICMP as _); /// `IPPROTO_IGMP` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const IGMP: Self = Self(c::IPPROTO_IGMP as _); /// `IPPROTO_IPIP` - #[cfg(not(any(windows, target_os = "illumos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const IPIP: Self = Self(c::IPPROTO_IPIP as _); /// `IPPROTO_TCP` pub const TCP: Self = Self(c::IPPROTO_TCP as _); /// `IPPROTO_EGP` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const EGP: Self = Self(c::IPPROTO_EGP as _); /// `IPPROTO_PUP` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const PUP: Self = Self(c::IPPROTO_PUP as _); /// `IPPROTO_UDP` pub const UDP: Self = Self(c::IPPROTO_UDP as _); /// `IPPROTO_IDP` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const IDP: Self = Self(c::IPPROTO_IDP as _); /// `IPPROTO_TP` - #[cfg(not(any(windows, target_os = "illumos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const TP: Self = Self(c::IPPROTO_TP as _); /// `IPPROTO_DCCP` #[cfg(not(any( windows, target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "openbsd", + target_os = "solaris", )))] pub const DCCP: Self = Self(c::IPPROTO_DCCP as _); /// `IPPROTO_IPV6` pub const IPV6: Self = Self(c::IPPROTO_IPV6 as _); /// `IPPROTO_RSVP` - #[cfg(not(any(windows, target_os = "illumos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const RSVP: Self = Self(c::IPPROTO_RSVP as _); /// `IPPROTO_GRE` - #[cfg(not(any(windows, target_os = "illumos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const GRE: Self = Self(c::IPPROTO_GRE as _); /// `IPPROTO_ESP` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const ESP: Self = Self(c::IPPROTO_ESP as _); /// `IPPROTO_AH` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const AH: Self = Self(c::IPPROTO_AH as _); /// `IPPROTO_MTP` #[cfg(not(any( windows, + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const MTP: Self = Self(c::IPPROTO_MTP as _); /// `IPPROTO_BEETPH` @@ -461,53 +515,61 @@ impl Protocol { windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const BEETPH: Self = Self(c::IPPROTO_BEETPH as _); /// `IPPROTO_ENCAP` - #[cfg(not(any(windows, target_os = "illumos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const ENCAP: Self = Self(c::IPPROTO_ENCAP as _); /// `IPPROTO_PIM` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const PIM: Self = Self(c::IPPROTO_PIM as _); /// `IPPROTO_COMP` #[cfg(not(any( windows, target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const COMP: Self = Self(c::IPPROTO_COMP as _); /// `IPPROTO_SCTP` - #[cfg(not(any(target_os = "dragonfly", target_os = "illumos", target_os = "openbsd")))] + #[cfg(not(any(target_os = "dragonfly", target_os = "haiku", target_os = "illumos", target_os = "openbsd", target_os = "solaris")))] pub const SCTP: Self = Self(c::IPPROTO_SCTP as _); /// `IPPROTO_UDPLITE` #[cfg(not(any( windows, target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const UDPLITE: Self = Self(c::IPPROTO_UDPLITE as _); /// `IPPROTO_MPLS` #[cfg(not(any( windows, target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", + target_os = "solaris", )))] pub const MPLS: Self = Self(c::IPPROTO_MPLS as _); /// `IPPROTO_RAW` @@ -520,15 +582,17 @@ impl Protocol { target_os = "emscripten", target_os = "freebsd", target_os = "fuchsia", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const MPTCP: Self = Self(c::IPPROTO_MPTCP as _); /// `IPPROTO_FRAGMENT` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const FRAGMENT: Self = Self(c::IPPROTO_FRAGMENT as _); /// `IPPROTO_ICMPV6` pub const ICMPV6: Self = Self(c::IPPROTO_ICMPV6 as _); @@ -536,15 +600,17 @@ impl Protocol { #[cfg(not(any( windows, target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const MH: Self = Self(c::IPPROTO_MH as _); /// `IPPROTO_ROUTING` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] pub const ROUTING: Self = Self(c::IPPROTO_ROUTING as _); /// Constructs a `Protocol` from a raw integer. @@ -581,11 +647,11 @@ bitflags! { /// [`acceptfrom_with`]: crate::net::acceptfrom_with pub struct AcceptFlags: c::c_int { /// `SOCK_NONBLOCK` - #[cfg(not(any(windows, target_os = "ios", target_os = "macos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "ios", target_os = "macos")))] const NONBLOCK = c::SOCK_NONBLOCK; /// `SOCK_CLOEXEC` - #[cfg(not(any(windows, target_os = "ios", target_os = "macos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "ios", target_os = "macos")))] const CLOEXEC = c::SOCK_CLOEXEC; } } @@ -596,11 +662,11 @@ bitflags! { /// [`socket`]: crate::net::socket pub struct SocketFlags: c::c_int { /// `SOCK_NONBLOCK` - #[cfg(not(any(windows, target_os = "ios", target_os = "macos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "ios", target_os = "macos")))] const NONBLOCK = c::SOCK_NONBLOCK; /// `SOCK_CLOEXEC` - #[cfg(not(any(windows, target_os = "ios", target_os = "macos")))] + #[cfg(not(any(windows, target_os = "haiku", target_os = "ios", target_os = "macos")))] const CLOEXEC = c::SOCK_CLOEXEC; } } diff --git a/vendor/rustix/src/imp/libc/net/write_sockaddr.rs b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs index adbf7255d..f44284a0b 100644 --- a/vendor/rustix/src/imp/libc/net/write_sockaddr.rs +++ b/vendor/rustix/src/backend/libc/net/write_sockaddr.rs @@ -26,6 +26,7 @@ pub(crate) unsafe fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -35,7 +36,10 @@ pub(crate) unsafe fn encode_sockaddr_v4(v4: &SocketAddrV4) -> c::sockaddr_in { sin_family: c::AF_INET as _, sin_port: u16::to_be(v4.port()), sin_addr: in_addr_new(u32::from_ne_bytes(v4.ip().octets())), + #[cfg(not(target_os = "haiku"))] sin_zero: [0; 8_usize], + #[cfg(target_os = "haiku")] + sin_zero: [0; 24_usize], } } @@ -49,6 +53,7 @@ pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -67,6 +72,7 @@ pub(crate) unsafe fn encode_sockaddr_v6(v6: &SocketAddrV6) -> c::sockaddr_in6 { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", diff --git a/vendor/rustix/src/imp/libc/offset.rs b/vendor/rustix/src/backend/libc/offset.rs index 3002e8bdd..48729be0c 100644 --- a/vendor/rustix/src/imp/libc/offset.rs +++ b/vendor/rustix/src/backend/libc/offset.rs @@ -6,10 +6,11 @@ use super::c; #[cfg(not(any( windows, target_os = "android", - target_os = "linux", target_os = "emscripten", target_os = "l4re", + target_os = "linux", )))] +#[cfg(feature = "fs")] pub(super) use c::{ fstat as libc_fstat, fstatat as libc_fstatat, ftruncate as libc_ftruncate, lseek as libc_lseek, off_t as libc_off_t, @@ -17,33 +18,42 @@ pub(super) use c::{ #[cfg(any( target_os = "android", - target_os = "linux", target_os = "emscripten", target_os = "l4re", + target_os = "linux", ))] +#[cfg(feature = "fs")] pub(super) use c::{ fstat64 as libc_fstat, fstatat64 as libc_fstatat, ftruncate64 as libc_ftruncate, - lseek64 as libc_lseek, off64_t as libc_off_t, rlimit64 as libc_rlimit, + lseek64 as libc_lseek, off64_t as libc_off_t, }; +#[cfg(any( + target_os = "android", + target_os = "emscripten", + target_os = "l4re", + target_os = "linux", +))] +pub(super) use c::rlimit64 as libc_rlimit; + #[cfg(not(any( windows, target_os = "android", - target_os = "linux", target_os = "emscripten", target_os = "l4re", + target_os = "linux", target_os = "wasi", )))] -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` +#[cfg(feature = "mm")] pub(super) use c::mmap as libc_mmap; #[cfg(not(any( windows, target_os = "android", - target_os = "linux", target_os = "emscripten", target_os = "fuchsia", target_os = "l4re", + target_os = "linux", target_os = "redox", target_os = "wasi", )))] @@ -83,7 +93,7 @@ pub(super) use c::{getrlimit64 as libc_getrlimit, setrlimit64 as libc_setrlimit} target_os = "emscripten", target_os = "l4re", ))] -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` +#[cfg(feature = "mm")] pub(super) use c::mmap64 as libc_mmap; // `prlimit64` wasn't supported in glibc until 2.13. @@ -150,6 +160,7 @@ pub(super) unsafe fn libc_prlimit( target_os = "l4re", target_os = "redox", )))] +#[cfg(feature = "fs")] pub(super) use c::openat as libc_openat; #[cfg(any( target_os = "android", @@ -157,17 +168,21 @@ pub(super) use c::openat as libc_openat; target_os = "emscripten", target_os = "l4re", ))] +#[cfg(feature = "fs")] pub(super) use c::openat64 as libc_openat; #[cfg(target_os = "fuchsia")] +#[cfg(feature = "fs")] pub(super) use c::fallocate as libc_fallocate; #[cfg(any(target_os = "android", target_os = "linux"))] +#[cfg(feature = "fs")] pub(super) use c::fallocate64 as libc_fallocate; #[cfg(not(any( windows, target_os = "android", target_os = "dragonfly", target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "linux", @@ -176,7 +191,9 @@ pub(super) use c::fallocate64 as libc_fallocate; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] +#[cfg(feature = "fs")] pub(super) use c::posix_fadvise as libc_posix_fadvise; #[cfg(any( target_os = "android", @@ -184,6 +201,7 @@ pub(super) use c::posix_fadvise as libc_posix_fadvise; target_os = "linux", target_os = "l4re", ))] +#[cfg(feature = "fs")] pub(super) use c::posix_fadvise64 as libc_posix_fadvise; #[cfg(all(not(any( @@ -202,7 +220,7 @@ mod readwrite_pv64 { use super::c; // 64-bit offsets on 32-bit platforms are passed in endianness-specific - // lo/hi pairs. See src/imp/linux_raw/conv.rs for details. + // lo/hi pairs. See src/backend/linux_raw/conv.rs for details. #[cfg(all(target_endian = "little", target_pointer_width = "32"))] fn lo(x: u64) -> usize { (x >> 32) as usize @@ -288,10 +306,12 @@ mod readwrite_pv64 { windows, target_os = "android", target_os = "emscripten", + target_os = "haiku", target_os = "ios", target_os = "linux", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] pub(super) use c::{preadv as libc_preadv, pwritev as libc_pwritev}; #[cfg(target_os = "android")] @@ -324,6 +344,7 @@ pub(super) use readwrite_pv::{preadv as libc_preadv, pwritev as libc_pwritev}; #[cfg(not(any( windows, + target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "fuchsia", @@ -335,22 +356,42 @@ pub(super) use readwrite_pv::{preadv as libc_preadv, pwritev as libc_pwritev}; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] +#[cfg(feature = "fs")] pub(super) use c::posix_fallocate as libc_posix_fallocate; #[cfg(any(target_os = "l4re"))] +#[cfg(feature = "fs")] pub(super) use c::posix_fallocate64 as libc_posix_fallocate; #[cfg(not(any( windows, target_os = "android", target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "linux", target_os = "l4re", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] +#[cfg(feature = "fs")] pub(super) use {c::fstatfs as libc_fstatfs, c::statfs as libc_statfs}; +#[cfg(not(any( + windows, + target_os = "android", + target_os = "emscripten", + target_os = "haiku", + target_os = "illumos", + target_os = "linux", + target_os = "l4re", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +#[cfg(feature = "fs")] +pub(super) use {c::fstatvfs as libc_fstatvfs, c::statvfs as libc_statvfs}; #[cfg(any( target_os = "android", @@ -358,4 +399,8 @@ pub(super) use {c::fstatfs as libc_fstatfs, c::statfs as libc_statfs}; target_os = "emscripten", target_os = "l4re", ))] -pub(super) use {c::fstatfs64 as libc_fstatfs, c::statfs64 as libc_statfs}; +#[cfg(feature = "fs")] +pub(super) use { + c::fstatfs64 as libc_fstatfs, c::fstatvfs64 as libc_fstatvfs, c::statfs64 as libc_statfs, + c::statvfs64 as libc_statvfs, +}; diff --git a/vendor/rustix/src/imp/libc/param/auxv.rs b/vendor/rustix/src/backend/libc/param/auxv.rs index 584329da9..a770c60d8 100644 --- a/vendor/rustix/src/imp/libc/param/auxv.rs +++ b/vendor/rustix/src/backend/libc/param/auxv.rs @@ -52,15 +52,3 @@ pub(crate) fn linux_execfn() -> &'static CStr { cstr!("") } } - -/// Initialize process-wide state. -#[cfg(any( - target_vendor = "mustang", - not(any(target_env = "gnu", target_env = "musl")), -))] -#[inline] -#[doc(hidden)] -pub(crate) unsafe fn init(_envp: *mut *mut u8) { - // Nothing to do. This is the libc backend, and libc does the - // initialization for us. -} diff --git a/vendor/rustix/src/imp/libc/param/mod.rs b/vendor/rustix/src/backend/libc/param/mod.rs index 2cb2fe78a..2cb2fe78a 100644 --- a/vendor/rustix/src/imp/libc/param/mod.rs +++ b/vendor/rustix/src/backend/libc/param/mod.rs diff --git a/vendor/rustix/src/imp/libc/process/cpu_set.rs b/vendor/rustix/src/backend/libc/process/cpu_set.rs index 14ad8d208..14ad8d208 100644 --- a/vendor/rustix/src/imp/libc/process/cpu_set.rs +++ b/vendor/rustix/src/backend/libc/process/cpu_set.rs diff --git a/vendor/rustix/src/imp/libc/process/mod.rs b/vendor/rustix/src/backend/libc/process/mod.rs index 8675c1af9..8675c1af9 100644 --- a/vendor/rustix/src/imp/libc/process/mod.rs +++ b/vendor/rustix/src/backend/libc/process/mod.rs diff --git a/vendor/rustix/src/imp/libc/process/syscalls.rs b/vendor/rustix/src/backend/libc/process/syscalls.rs index 9874f617f..6f4e85916 100644 --- a/vendor/rustix/src/imp/libc/process/syscalls.rs +++ b/vendor/rustix/src/backend/libc/process/syscalls.rs @@ -3,6 +3,8 @@ use super::super::c; #[cfg(not(any(target_os = "wasi", target_os = "fuchsia")))] use super::super::conv::borrowed_fd; +#[cfg(not(target_os = "wasi"))] +use super::super::conv::ret_pid_t; use super::super::conv::{c_str, ret, ret_c_int, ret_discarded_char_ptr}; #[cfg(any(target_os = "android", target_os = "linux"))] use super::super::conv::{syscall_ret, syscall_ret_u32}; @@ -145,6 +147,27 @@ pub(crate) fn getppid() -> Option<Pid> { } } +#[cfg(not(target_os = "wasi"))] +#[inline] +pub(crate) fn getpgid(pid: Option<Pid>) -> io::Result<Pid> { + unsafe { + let pgid = ret_pid_t(c::getpgid(Pid::as_raw(pid) as _))?; + debug_assert_ne!(pgid, 0); + Ok(Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pgid))) + } +} + +#[cfg(not(target_os = "wasi"))] +#[inline] +#[must_use] +pub(crate) fn getpgrp() -> Pid { + unsafe { + let pgid = c::getpgrp(); + debug_assert_ne!(pgid, 0); + Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pgid)) + } +} + #[cfg(any( target_os = "android", target_os = "dragonfly", @@ -302,8 +325,8 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res limit as _, &lim, result.as_mut_ptr(), - )) - .map(|()| rlimit_from_libc(result.assume_init())) + ))?; + Ok(rlimit_from_libc(result.assume_init())) } } @@ -417,3 +440,26 @@ pub(crate) fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> { pub(crate) fn kill_current_process_group(sig: Signal) -> io::Result<()> { unsafe { ret(c::kill(0, sig as i32)) } } + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub(crate) unsafe fn prctl( + option: c::c_int, + arg2: *mut c::c_void, + arg3: *mut c::c_void, + arg4: *mut c::c_void, + arg5: *mut c::c_void, +) -> io::Result<c::c_int> { + ret_c_int(c::prctl(option, arg2, arg3, arg4, arg5)) +} + +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +#[inline] +pub(crate) unsafe fn procctl( + idtype: c::idtype_t, + id: c::id_t, + option: c::c_int, + data: *mut c::c_void, +) -> io::Result<()> { + ret(c::procctl(idtype, id, option, data)) +} diff --git a/vendor/rustix/src/imp/libc/process/types.rs b/vendor/rustix/src/backend/libc/process/types.rs index 60d629d81..f8e3b8bf4 100644 --- a/vendor/rustix/src/imp/libc/process/types.rs +++ b/vendor/rustix/src/backend/libc/process/types.rs @@ -54,87 +54,117 @@ pub enum Resource { /// `RLIMIT_STACK` Stack = c::RLIMIT_STACK as c::c_int, /// `RLIMIT_CORE` + #[cfg(not(target_os = "haiku"))] Core = c::RLIMIT_CORE as c::c_int, /// `RLIMIT_RSS` - #[cfg(not(any(target_os = "illumos", target_os = "ios", target_os = "macos")))] + #[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "solaris", + )))] Rss = c::RLIMIT_RSS as c::c_int, /// `RLIMIT_NPROC` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any(target_os = "haiku", target_os = "illumos", target_os = "solaris")))] Nproc = c::RLIMIT_NPROC as c::c_int, /// `RLIMIT_NOFILE` Nofile = c::RLIMIT_NOFILE as c::c_int, /// `RLIMIT_MEMLOCK` - #[cfg(not(target_os = "illumos"))] + #[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "illumos", + target_os = "solaris" + )))] Memlock = c::RLIMIT_MEMLOCK as c::c_int, /// `RLIMIT_AS` #[cfg(not(target_os = "openbsd"))] As = c::RLIMIT_AS as c::c_int, /// `RLIMIT_LOCKS` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] Locks = c::RLIMIT_LOCKS as c::c_int, /// `RLIMIT_SIGPENDING` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] Sigpending = c::RLIMIT_SIGPENDING as c::c_int, /// `RLIMIT_MSGQUEUE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] Msgqueue = c::RLIMIT_MSGQUEUE as c::c_int, /// `RLIMIT_NICE` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] Nice = c::RLIMIT_NICE as c::c_int, /// `RLIMIT_RTPRIO` #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] Rtprio = c::RLIMIT_RTPRIO as c::c_int, /// `RLIMIT_RTTIME` #[cfg(not(any( + target_os = "aix", target_os = "android", target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] Rttime = c::RLIMIT_RTTIME as c::c_int, } @@ -191,15 +221,24 @@ pub enum Signal { Term = c::SIGTERM, /// `SIGSTKFLT` #[cfg(not(any( + target_os = "aix", + target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", all( any(target_os = "android", target_os = "linux"), - any(target_arch = "mips", target_arch = "mips64"), + any( + target_arch = "mips", + target_arch = "mips64", + target_arch = "sparc", + target_arch = "sparc64" + ), ) )))] Stkflt = c::SIGSTKFLT, @@ -231,10 +270,13 @@ pub enum Signal { Winch = c::SIGWINCH, /// `SIGIO`, aka `SIGPOLL` #[doc(alias = "Poll")] + #[cfg(not(target_os = "haiku"))] Io = c::SIGIO, /// `SIGPWR` #[cfg(not(any( + target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -268,15 +310,24 @@ impl Signal { c::SIGALRM => Some(Self::Alarm), c::SIGTERM => Some(Self::Term), #[cfg(not(any( + target_os = "aix", + target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", all( any(target_os = "android", target_os = "linux"), - any(target_arch = "mips", target_arch = "mips64"), + any( + target_arch = "mips", + target_arch = "mips64", + target_arch = "sparc", + target_arch = "sparc64" + ), ) )))] c::SIGSTKFLT => Some(Self::Stkflt), @@ -292,9 +343,12 @@ impl Signal { c::SIGVTALRM => Some(Self::Vtalarm), c::SIGPROF => Some(Self::Prof), c::SIGWINCH => Some(Self::Winch), + #[cfg(not(target_os = "haiku"))] c::SIGIO => Some(Self::Io), #[cfg(not(any( + target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -327,6 +381,8 @@ pub type RawUid = c::uid_t; /// A CPU identifier as a raw integer. #[cfg(any(target_os = "android", target_os = "linux"))] pub type RawCpuid = u32; +#[cfg(target_os = "freebsd")] +pub type RawId = c::id_t; #[cfg(not(target_os = "wasi"))] pub(crate) type RawUname = c::utsname; @@ -352,10 +408,7 @@ pub(crate) fn raw_cpu_set_new() -> RawCpuSet { set } -#[cfg(any( - target_os = "android", - target_os = "dragonfly", - target_os = "fuchsia", - target_os = "linux", -))] +#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] pub(crate) const CPU_SETSIZE: usize = c::CPU_SETSIZE as usize; +#[cfg(target_os = "dragonfly")] +pub(crate) const CPU_SETSIZE: usize = 256; diff --git a/vendor/rustix/src/imp/libc/process/wait.rs b/vendor/rustix/src/backend/libc/process/wait.rs index 6de79955d..6de79955d 100644 --- a/vendor/rustix/src/imp/libc/process/wait.rs +++ b/vendor/rustix/src/backend/libc/process/wait.rs diff --git a/vendor/rustix/src/imp/libc/rand/mod.rs b/vendor/rustix/src/backend/libc/rand/mod.rs index 1e0181a99..1e0181a99 100644 --- a/vendor/rustix/src/imp/libc/rand/mod.rs +++ b/vendor/rustix/src/backend/libc/rand/mod.rs diff --git a/vendor/rustix/src/imp/libc/rand/syscalls.rs b/vendor/rustix/src/backend/libc/rand/syscalls.rs index 1c4286235..1c4286235 100644 --- a/vendor/rustix/src/imp/libc/rand/syscalls.rs +++ b/vendor/rustix/src/backend/libc/rand/syscalls.rs diff --git a/vendor/rustix/src/imp/libc/rand/types.rs b/vendor/rustix/src/backend/libc/rand/types.rs index 2ba3f1119..2ba3f1119 100644 --- a/vendor/rustix/src/imp/libc/rand/types.rs +++ b/vendor/rustix/src/backend/libc/rand/types.rs diff --git a/vendor/rustix/src/imp/libc/termios/mod.rs b/vendor/rustix/src/backend/libc/termios/mod.rs index 1e0181a99..1e0181a99 100644 --- a/vendor/rustix/src/imp/libc/termios/mod.rs +++ b/vendor/rustix/src/backend/libc/termios/mod.rs diff --git a/vendor/rustix/src/imp/libc/termios/syscalls.rs b/vendor/rustix/src/backend/libc/termios/syscalls.rs index 91b01b4a1..e0ab7a016 100644 --- a/vendor/rustix/src/imp/libc/termios/syscalls.rs +++ b/vendor/rustix/src/backend/libc/termios/syscalls.rs @@ -2,9 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp::syscalls` module documentation for details. - -#![allow(unsafe_code)] +//! See the `rustix::backend::syscalls` module documentation for details. use super::super::c; use super::super::conv::{borrowed_fd, ret, ret_pid_t}; @@ -21,7 +19,8 @@ use libc_errno::errno; pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { let mut result = MaybeUninit::<Termios>::uninit(); unsafe { - ret(c::tcgetattr(borrowed_fd(fd), result.as_mut_ptr())).map(|()| result.assume_init()) + ret(c::tcgetattr(borrowed_fd(fd), result.as_mut_ptr()))?; + Ok(result.assume_init()) } } diff --git a/vendor/rustix/src/imp/libc/termios/types.rs b/vendor/rustix/src/backend/libc/termios/types.rs index 7e6728755..6dda70064 100644 --- a/vendor/rustix/src/imp/libc/termios/types.rs +++ b/vendor/rustix/src/backend/libc/termios/types.rs @@ -95,11 +95,13 @@ pub const VMIN: usize = c::VMIN as usize; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const VSWTC: usize = c::VSWTC as usize; @@ -116,15 +118,19 @@ pub const VSUSP: usize = c::VSUSP as usize; pub const VEOL: usize = c::VEOL as usize; /// `VREPRINT` +#[cfg(not(target_os = "haiku"))] pub const VREPRINT: usize = c::VREPRINT as usize; /// `VDISCARD` +#[cfg(not(target_os = "haiku"))] pub const VDISCARD: usize = c::VDISCARD as usize; /// `VWERASE` +#[cfg(not(target_os = "haiku"))] pub const VWERASE: usize = c::VWERASE as usize; /// `VLNEXT` +#[cfg(not(target_os = "haiku"))] pub const VLNEXT: usize = c::VLNEXT as usize; /// `VEOL2` @@ -183,7 +189,12 @@ pub const IXANY: c::c_uint = c::IXANY; pub const IXOFF: c::c_uint = c::IXOFF; /// `IMAXBEL` -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +#[cfg(not(any( + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "redox" +)))] pub const IMAXBEL: c::c_uint = c::IMAXBEL; /// `IUTF8` @@ -191,12 +202,14 @@ pub const IMAXBEL: c::c_uint = c::IMAXBEL; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const IUTF8: c::c_uint = c::IUTF8; @@ -263,6 +276,7 @@ pub const OFDEL: c::c_uint = c::OFDEL; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const NLDLY: c::c_uint = c::NLDLY; @@ -277,6 +291,7 @@ pub const NLDLY: c::c_uint = c::NLDLY; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const NL0: c::c_uint = c::NL0; @@ -291,6 +306,7 @@ pub const NL0: c::c_uint = c::NL0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const NL1: c::c_uint = c::NL1; @@ -304,6 +320,7 @@ pub const NL1: c::c_uint = c::NL1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CRDLY: c::c_uint = c::CRDLY; @@ -318,6 +335,7 @@ pub const CRDLY: c::c_uint = c::CRDLY; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CR0: c::c_uint = c::CR0; @@ -334,6 +352,7 @@ pub const CR0: c::c_uint = c::CR0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CR1: c::c_uint = c::CR1; @@ -350,6 +369,7 @@ pub const CR1: c::c_uint = c::CR1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CR2: c::c_uint = c::CR2; @@ -366,22 +386,26 @@ pub const CR2: c::c_uint = c::CR2; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CR3: c::c_uint = c::CR3; /// `TABDLY` #[cfg(not(any( + target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "illumos", target_os = "redox", + target_os = "solaris", )))] pub const TABDLY: c::c_uint = c::TABDLY; /// `TAB0` #[cfg(not(any( + target_os = "dragonfly", target_os = "fuchsia", target_os = "illumos", target_os = "ios", @@ -389,6 +413,7 @@ pub const TABDLY: c::c_uint = c::TABDLY; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const TAB0: c::c_uint = c::TAB0; @@ -405,6 +430,7 @@ pub const TAB0: c::c_uint = c::TAB0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const TAB1: c::c_uint = c::TAB1; @@ -421,12 +447,14 @@ pub const TAB1: c::c_uint = c::TAB1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const TAB2: c::c_uint = c::TAB2; /// `TAB3` #[cfg(not(any( target_env = "musl", + target_os = "dragonfly", target_os = "emscripten", target_os = "fuchsia", target_os = "illumos", @@ -435,6 +463,7 @@ pub const TAB2: c::c_uint = c::TAB2; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const TAB3: c::c_uint = c::TAB3; @@ -448,6 +477,7 @@ pub const TAB3: c::c_uint = c::TAB3; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const BSDLY: c::c_uint = c::BSDLY; @@ -462,6 +492,7 @@ pub const BSDLY: c::c_uint = c::BSDLY; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const BS0: c::c_uint = c::BS0; @@ -478,6 +509,7 @@ pub const BS0: c::c_uint = c::BS0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const BS1: c::c_uint = c::BS1; @@ -492,6 +524,7 @@ pub const BS1: c::c_uint = c::BS1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const FFDLY: c::c_uint = c::FFDLY; @@ -506,6 +539,7 @@ pub const FFDLY: c::c_uint = c::FFDLY; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const FF0: c::c_uint = c::FF0; @@ -522,6 +556,7 @@ pub const FF0: c::c_uint = c::FF0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const FF1: c::c_uint = c::FF1; @@ -536,6 +571,7 @@ pub const FF1: c::c_uint = c::FF1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const VTDLY: c::c_uint = c::VTDLY; @@ -550,6 +586,7 @@ pub const VTDLY: c::c_uint = c::VTDLY; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const VT0: c::c_uint = c::VT0; @@ -566,6 +603,7 @@ pub const VT0: c::c_uint = c::VT0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const VT1: c::c_uint = c::VT1; @@ -627,18 +665,26 @@ pub const B115200: Speed = c::B115200; pub const B230400: Speed = c::B230400; /// `B460800` -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +)))] pub const B460800: Speed = c::B460800; /// `B500000` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B500000: Speed = c::B500000; @@ -646,26 +692,36 @@ pub const B500000: Speed = c::B500000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B576000: Speed = c::B576000; /// `B921600` -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +)))] pub const B921600: Speed = c::B921600; /// `B1000000` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B1000000: Speed = c::B1000000; @@ -673,10 +729,12 @@ pub const B1000000: Speed = c::B1000000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B1152000: Speed = c::B1152000; @@ -684,10 +742,12 @@ pub const B1152000: Speed = c::B1152000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B1500000: Speed = c::B1500000; @@ -695,54 +755,72 @@ pub const B1500000: Speed = c::B1500000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B2000000: Speed = c::B2000000; /// `B2500000` #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B2500000: Speed = c::B2500000; /// `B3000000` #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B3000000: Speed = c::B3000000; /// `B3500000` #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B3500000: Speed = c::B3500000; /// `B4000000` #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub const B4000000: Speed = c::B4000000; @@ -829,20 +907,24 @@ pub const IEXTEN: c::c_uint = c::IEXTEN; /// `EXTA` #[cfg(not(any( target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] pub const EXTA: c::c_uint = c::EXTA; /// `EXTB` #[cfg(not(any( target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] pub const EXTB: c::c_uint = c::EXTB; @@ -850,6 +932,7 @@ pub const EXTB: c::c_uint = c::EXTB; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -862,12 +945,14 @@ pub const CBAUD: c::c_uint = c::CBAUD; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CBAUDEX: c::c_uint = c::CBAUDEX; @@ -876,6 +961,7 @@ pub const CBAUDEX: c::c_uint = c::CBAUDEX; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -896,12 +982,14 @@ pub const CIBAUD: c::tcflag_t = 0o77600000; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const CMSPAR: c::c_uint = c::CMSPAR; @@ -934,18 +1022,25 @@ pub const FLUSHO: c::c_uint = c::FLUSHO; pub const PENDIN: c::c_uint = c::PENDIN; /// `EXTPROC` -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +#[cfg(not(any( + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "redox" +)))] pub const EXTPROC: c::c_uint = c::EXTPROC; /// `XTABS` #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub const XTABS: c::c_uint = c::XTABS; diff --git a/vendor/rustix/src/imp/libc/thread/mod.rs b/vendor/rustix/src/backend/libc/thread/mod.rs index 40e0d1135..40e0d1135 100644 --- a/vendor/rustix/src/imp/libc/thread/mod.rs +++ b/vendor/rustix/src/backend/libc/thread/mod.rs diff --git a/vendor/rustix/src/imp/libc/thread/syscalls.rs b/vendor/rustix/src/backend/libc/thread/syscalls.rs index c885372dc..0709fbb19 100644 --- a/vendor/rustix/src/imp/libc/thread/syscalls.rs +++ b/vendor/rustix/src/backend/libc/thread/syscalls.rs @@ -2,7 +2,11 @@ use super::super::c; use super::super::conv::ret; +#[cfg(any(target_os = "android", target_os = "linux"))] +use super::super::conv::{borrowed_fd, ret_c_int}; use super::super::time::types::LibcTimespec; +#[cfg(any(target_os = "android", target_os = "linux"))] +use crate::fd::BorrowedFd; use crate::io; #[cfg(any(target_os = "android", target_os = "linux"))] use crate::process::{Pid, RawNonZeroPid}; @@ -11,8 +15,9 @@ use crate::thread::{NanosleepRelativeResult, Timespec}; use core::mem::MaybeUninit; #[cfg(not(any( target_os = "dragonfly", - target_os = "freebsd", target_os = "emscripten", + target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "openbsd", @@ -36,6 +41,7 @@ weak!(fn __nanosleep64(*const LibcTimespec, *mut LibcTimespec) -> c::c_int); target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "openbsd", @@ -127,8 +133,9 @@ unsafe fn clock_nanosleep_relative_old(id: ClockId, request: &Timespec) -> Nanos #[cfg(not(any( target_os = "dragonfly", - target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. target_os = "emscripten", + target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "openbsd", @@ -280,3 +287,9 @@ pub(crate) fn gettid() -> Pid { Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(tid)) } } + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub(crate) fn setns(fd: BorrowedFd, nstype: c::c_int) -> io::Result<c::c_int> { + unsafe { ret_c_int(c::setns(borrowed_fd(fd), nstype)) } +} diff --git a/vendor/rustix/src/imp/libc/time/mod.rs b/vendor/rustix/src/backend/libc/time/mod.rs index bff7fd564..bff7fd564 100644 --- a/vendor/rustix/src/imp/libc/time/mod.rs +++ b/vendor/rustix/src/backend/libc/time/mod.rs diff --git a/vendor/rustix/src/imp/libc/time/syscalls.rs b/vendor/rustix/src/backend/libc/time/syscalls.rs index 2bbaf8ff1..c9e075e53 100644 --- a/vendor/rustix/src/imp/libc/time/syscalls.rs +++ b/vendor/rustix/src/backend/libc/time/syscalls.rs @@ -15,8 +15,7 @@ use core::mem::MaybeUninit; #[cfg(feature = "time")] use { super::super::conv::{borrowed_fd, ret_owned_fd}, - crate::fd::BorrowedFd, - crate::io::OwnedFd, + crate::fd::{BorrowedFd, OwnedFd}, crate::time::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}, }; @@ -259,8 +258,8 @@ pub(crate) fn timerfd_settime( flags.bits(), &new_value.clone().into(), result.as_mut_ptr(), - )) - .map(|()| result.assume_init().into()) + ))?; + Ok(result.assume_init().into()) } else { timerfd_settime_old(fd, flags, new_value) } @@ -276,8 +275,8 @@ pub(crate) fn timerfd_settime( flags.bits(), new_value, result.as_mut_ptr(), - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } } @@ -363,8 +362,8 @@ pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> { ))] unsafe { if let Some(libc_timerfd_gettime) = __timerfd_gettime64.get() { - ret(libc_timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr())) - .map(|()| result.assume_init().into()) + ret(libc_timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr()))?; + Ok(result.assume_init().into()) } else { timerfd_gettime_old(fd) } @@ -375,7 +374,8 @@ pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> { target_env = "gnu", )))] unsafe { - ret(c::timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr())).map(|()| result.assume_init()) + ret(c::timerfd_gettime(borrowed_fd(fd), result.as_mut_ptr()))?; + Ok(result.assume_init()) } } diff --git a/vendor/rustix/src/imp/libc/time/types.rs b/vendor/rustix/src/backend/libc/time/types.rs index 4aa2b22e5..080f64431 100644 --- a/vendor/rustix/src/imp/libc/time/types.rs +++ b/vendor/rustix/src/backend/libc/time/types.rs @@ -132,6 +132,7 @@ pub enum ClockId { target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] ProcessCPUTime = c::CLOCK_PROCESS_CPUTIME_ID, @@ -141,6 +142,7 @@ pub enum ClockId { target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] ThreadCPUTime = c::CLOCK_THREAD_CPUTIME_ID, diff --git a/vendor/rustix/src/imp/libc/weak.rs b/vendor/rustix/src/backend/libc/weak.rs index 893403b1c..d578038cd 100644 --- a/vendor/rustix/src/imp/libc/weak.rs +++ b/vendor/rustix/src/backend/libc/weak.rs @@ -38,8 +38,8 @@ const INVALID: *mut c_void = 1 as *mut c_void; macro_rules! weak { ($vis:vis fn $name:ident($($t:ty),*) -> $ret:ty) => ( #[allow(non_upper_case_globals)] - $vis static $name: $crate::imp::weak::Weak<unsafe extern fn($($t),*) -> $ret> = - $crate::imp::weak::Weak::new(concat!(stringify!($name), '\0')); + $vis static $name: $crate::backend::weak::Weak<unsafe extern fn($($t),*) -> $ret> = + $crate::backend::weak::Weak::new(concat!(stringify!($name), '\0')); ) } diff --git a/vendor/rustix/src/imp/libc/winsock_c.rs b/vendor/rustix/src/backend/libc/winsock_c.rs index 1fbce416f..7d78aef65 100644 --- a/vendor/rustix/src/imp/libc/winsock_c.rs +++ b/vendor/rustix/src/backend/libc/winsock_c.rs @@ -59,7 +59,7 @@ pub(crate) const SHUT_WR: i32 = WinSock::SD_SEND as _; pub(crate) use WinSock::{ closesocket as close, ioctlsocket as ioctl, WSAPoll as poll, ADDRESS_FAMILY as sa_family_t, ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr, IPV6_MREQ as ipv6_mreq, - IP_MREQ as ip_mreq, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, + IP_MREQ as ip_mreq, LINGER as linger, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, WSAEACCES as EACCES, WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL, WSAEAFNOSUPPORT as EAFNOSUPPORT, WSAEALREADY as EALREADY, WSAEBADF as EBADF, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/aarch64.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/aarch64.rs index 7d33a4a52..0f4465d51 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/aarch64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/aarch64.rs @@ -1,13 +1,15 @@ //! aarch64 Linux system calls. -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; use core::arch::asm; #[cfg(target_pointer_width = "32")] compile_error!("arm64-ilp32 is not supported yet"); #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { let r0; asm!( "svc 0", @@ -19,7 +21,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg< } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let r0; asm!( "svc 0", @@ -31,7 +33,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -46,7 +48,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "svc 0", in("x8") nr.to_asm(), @@ -56,7 +58,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -73,7 +75,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -90,7 +92,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -109,7 +111,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -128,7 +130,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -149,7 +151,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -170,7 +172,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -193,7 +195,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -216,7 +218,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -241,7 +243,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/arm.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/arm.rs index 9acccd6dc..9695c6028 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/arm.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/arm.rs @@ -1,10 +1,12 @@ //! arm Linux system calls. -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; use core::arch::asm; #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { let r0; asm!( "svc 0", @@ -16,7 +18,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg< } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let r0; asm!( "svc 0", @@ -28,7 +30,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -43,7 +45,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "svc 0", in("r7") nr.to_asm(), @@ -53,7 +55,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -70,7 +72,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -87,7 +89,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -106,7 +108,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -125,7 +127,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -146,7 +148,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -167,7 +169,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -190,7 +192,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -213,7 +215,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -238,7 +240,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/mips.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/mips.rs index 0f2b9d9d2..b39a16847 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/mips.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/mips.rs @@ -6,13 +6,13 @@ //! Mips-family platforms have a special calling convention for `__NR_pipe`, //! however we use `__NR_pipe2` instead to avoid having to implement it. -use crate::imp::reg::{ +use crate::backend::reg::{ ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, A6, R0, }; use core::arch::asm; #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { let x0; let err: usize; asm!( @@ -39,7 +39,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let x0; let err: usize; asm!( @@ -67,7 +67,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -98,7 +98,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "syscall", in("$2" /*$v0*/) nr.to_asm(), @@ -108,7 +108,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -141,7 +141,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -174,7 +174,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -209,7 +209,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -244,7 +244,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -280,7 +280,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -316,7 +316,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -359,7 +359,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -402,7 +402,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -448,7 +448,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -494,7 +494,7 @@ pub(in crate::imp) unsafe fn syscall6_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall7_readonly( +pub(in crate::backend) unsafe fn syscall7_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/mips64.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/mips64.rs index 36dd79316..d3c7d341f 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/mips64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/mips64.rs @@ -6,11 +6,13 @@ //! Mips-family platforms have a special calling convention for `__NR_pipe`, //! however we use `__NR_pipe2` instead to avoid having to implement it. -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; use core::arch::asm; #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { let x0; let err: usize; asm!( @@ -37,7 +39,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let x0; let err: usize; asm!( @@ -65,7 +67,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -96,7 +98,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "syscall", in("$2" /*$v0*/) nr.to_asm(), @@ -106,7 +108,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -139,7 +141,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -172,7 +174,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -207,7 +209,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -242,7 +244,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -278,7 +280,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -314,7 +316,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -351,7 +353,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -388,7 +390,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -426,7 +428,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs index 3e25e2149..524c449d9 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/mod.rs @@ -5,7 +5,8 @@ //! conventions are otherwise the compiler's job. But for now, use inline asm. #[cfg_attr(target_arch = "aarch64", path = "aarch64.rs")] -#[cfg_attr(target_arch = "arm", path = "arm.rs")] +#[cfg_attr(all(target_arch = "arm", not(thumb_mode)), path = "arm.rs")] +#[cfg_attr(all(target_arch = "arm", thumb_mode), path = "thumb.rs")] #[cfg_attr(target_arch = "mips", path = "mips.rs")] #[cfg_attr(target_arch = "mips64", path = "mips64.rs")] #[cfg_attr(target_arch = "powerpc64", path = "powerpc64.rs")] @@ -14,4 +15,4 @@ #[cfg_attr(target_arch = "x86_64", path = "x86_64.rs")] mod target_arch; -pub(in crate::imp) use self::target_arch::*; +pub(in crate::backend) use self::target_arch::*; diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/powerpc64.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/powerpc64.rs index 520bd4d79..8cca7dca7 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/powerpc64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/powerpc64.rs @@ -9,11 +9,13 @@ //! check the flag and negate the error value to make PowerPC64 look like other //! architectures. -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; use core::arch::asm; #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> { let r0; asm!( "sc", @@ -38,7 +40,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let r0; asm!( "sc", @@ -63,7 +65,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -91,7 +93,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "sc", in("r0") nr.to_asm(), @@ -101,7 +103,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -130,7 +132,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -159,7 +161,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -189,7 +191,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -219,7 +221,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -250,7 +252,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -281,7 +283,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -313,7 +315,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -345,7 +347,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -378,7 +380,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/riscv64.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/riscv64.rs index 3ed36a16c..b1e306266 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/riscv64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/riscv64.rs @@ -1,10 +1,12 @@ //! riscv64 Linux system calls. -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; use core::arch::asm; #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { let r0; asm!( "ecall", @@ -16,7 +18,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg< } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let r0; asm!( "ecall", @@ -28,7 +30,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -43,7 +45,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "ecall", in("a7") nr.to_asm(), @@ -53,7 +55,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -70,7 +72,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -87,7 +89,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -106,7 +108,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -125,7 +127,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -146,7 +148,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -167,7 +169,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -190,7 +192,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -213,7 +215,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -238,7 +240,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/backend/linux_raw/arch/inline/thumb.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/thumb.rs new file mode 100644 index 000000000..398a73dfe --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/thumb.rs @@ -0,0 +1,322 @@ +//! arm Linux system calls, using thumb-mode. +//! +//! In thumb-mode, r7 is the frame pointer and is not permitted to be used in +//! an inline asm operand, so we have to use a different register and copy it +//! into r7 inside the inline asm. + +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; +use core::arch::asm; + +#[inline] +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + lateout("r0") r0, + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall1_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { + asm!( + "mov r7, {nr}", + "svc 0", + nr = in(reg) nr.to_asm(), + in("r0") a0.to_asm(), + options(noreturn) + ) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall2( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall2_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall3( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall3_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall4( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + in("r3") a3.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall4_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + in("r3") a3.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall5( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + in("r3") a3.to_asm(), + in("r4") a4.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall5_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + in("r3") a3.to_asm(), + in("r4") a4.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall6( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, + a5: ArgReg<'_, A5>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + in("r3") a3.to_asm(), + in("r4") a4.to_asm(), + in("r5") a5.to_asm(), + options(nostack, preserves_flags) + ); + FromAsm::from_asm(r0) +} + +#[inline] +pub(in crate::backend) unsafe fn syscall6_readonly( + nr: SyscallNumber<'_>, + a0: ArgReg<'_, A0>, + a1: ArgReg<'_, A1>, + a2: ArgReg<'_, A2>, + a3: ArgReg<'_, A3>, + a4: ArgReg<'_, A4>, + a5: ArgReg<'_, A5>, +) -> RetReg<R0> { + let r0; + asm!( + "mov {tmp}, r7", + "mov r7, {nr}", + "svc 0", + "mov r7, {tmp}", + nr = in(reg) nr.to_asm(), + tmp = out(reg) _, + inlateout("r0") a0.to_asm() => r0, + in("r1") a1.to_asm(), + in("r2") a2.to_asm(), + in("r3") a3.to_asm(), + in("r4") a4.to_asm(), + in("r5") a5.to_asm(), + options(nostack, preserves_flags, readonly) + ); + FromAsm::from_asm(r0) +} diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/x86.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/x86.rs index 8d1b4ed0a..8e115148d 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/x86.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/x86.rs @@ -9,12 +9,14 @@ #![allow(dead_code)] -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; -use crate::imp::vdso_wrappers::SyscallType; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; +use crate::backend::vdso_wrappers::SyscallType; use core::arch::asm; #[inline] -pub(in crate::imp) unsafe fn indirect_syscall0( +pub(in crate::backend) unsafe fn indirect_syscall0( callee: SyscallType, nr: SyscallNumber<'_>, ) -> RetReg<R0> { @@ -29,7 +31,7 @@ pub(in crate::imp) unsafe fn indirect_syscall0( } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall1( +pub(in crate::backend) unsafe fn indirect_syscall1( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -46,7 +48,7 @@ pub(in crate::imp) unsafe fn indirect_syscall1( } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall1_noreturn( +pub(in crate::backend) unsafe fn indirect_syscall1_noreturn( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -61,7 +63,7 @@ pub(in crate::imp) unsafe fn indirect_syscall1_noreturn( } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall2( +pub(in crate::backend) unsafe fn indirect_syscall2( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -80,7 +82,7 @@ pub(in crate::imp) unsafe fn indirect_syscall2( } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall3( +pub(in crate::backend) unsafe fn indirect_syscall3( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -101,7 +103,7 @@ pub(in crate::imp) unsafe fn indirect_syscall3( } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall4( +pub(in crate::backend) unsafe fn indirect_syscall4( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -132,7 +134,7 @@ pub(in crate::imp) unsafe fn indirect_syscall4( } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall5( +pub(in crate::backend) unsafe fn indirect_syscall5( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -166,7 +168,7 @@ pub(in crate::imp) unsafe fn indirect_syscall5( #[allow(clippy::too_many_arguments)] #[inline] -pub(in crate::imp) unsafe fn indirect_syscall6( +pub(in crate::backend) unsafe fn indirect_syscall6( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -207,7 +209,7 @@ pub(in crate::imp) unsafe fn indirect_syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { let r0; asm!( "int $$0x80", @@ -218,7 +220,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg< } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let r0; asm!( "int $$0x80", @@ -230,7 +232,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -245,7 +247,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "int $$0x80", in("eax") nr.to_asm(), @@ -255,7 +257,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -272,7 +274,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -289,7 +291,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -308,7 +310,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -327,7 +329,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -352,7 +354,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -375,7 +377,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -404,7 +406,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -430,7 +432,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -461,7 +463,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/inline/x86_64.rs b/vendor/rustix/src/backend/linux_raw/arch/inline/x86_64.rs index 75d6124f7..084f5fee4 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/inline/x86_64.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/inline/x86_64.rs @@ -1,13 +1,15 @@ //! x86-64 Linux system calls. -use crate::imp::reg::{ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::{ + ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0, +}; use core::arch::asm; #[cfg(target_pointer_width = "32")] compile_error!("x32 is not yet supported"); #[inline] -pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> { let r0; asm!( "syscall", @@ -20,7 +22,7 @@ pub(in crate::imp) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg< } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { let r0; asm!( "syscall", @@ -34,7 +36,7 @@ pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) } #[inline] -pub(in crate::imp) unsafe fn syscall1_readonly( +pub(in crate::backend) unsafe fn syscall1_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, ) -> RetReg<R0> { @@ -51,7 +53,7 @@ pub(in crate::imp) unsafe fn syscall1_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { asm!( "syscall", in("rax") nr.to_asm(), @@ -61,7 +63,7 @@ pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -80,7 +82,7 @@ pub(in crate::imp) unsafe fn syscall2( } #[inline] -pub(in crate::imp) unsafe fn syscall2_readonly( +pub(in crate::backend) unsafe fn syscall2_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -99,7 +101,7 @@ pub(in crate::imp) unsafe fn syscall2_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -120,7 +122,7 @@ pub(in crate::imp) unsafe fn syscall3( } #[inline] -pub(in crate::imp) unsafe fn syscall3_readonly( +pub(in crate::backend) unsafe fn syscall3_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -141,7 +143,7 @@ pub(in crate::imp) unsafe fn syscall3_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -164,7 +166,7 @@ pub(in crate::imp) unsafe fn syscall4( } #[inline] -pub(in crate::imp) unsafe fn syscall4_readonly( +pub(in crate::backend) unsafe fn syscall4_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -187,7 +189,7 @@ pub(in crate::imp) unsafe fn syscall4_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -212,7 +214,7 @@ pub(in crate::imp) unsafe fn syscall5( } #[inline] -pub(in crate::imp) unsafe fn syscall5_readonly( +pub(in crate::backend) unsafe fn syscall5_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -237,7 +239,7 @@ pub(in crate::imp) unsafe fn syscall5_readonly( } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -264,7 +266,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[inline] -pub(in crate::imp) unsafe fn syscall6_readonly( +pub(in crate::backend) unsafe fn syscall6_readonly( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/mod.rs index 81f3a255e..e13f675fd 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/mod.rs @@ -15,13 +15,15 @@ #![allow(unsafe_code)] #![cfg_attr(not(feature = "all-apis"), allow(unused_imports))] +// We'll use as many arguments as syscalls need. +#![allow(clippy::too_many_arguments)] // When inline asm is available, use it. Otherwise, use out-of-line asm. These // functions always use the machine's syscall instruction, even when it isn't // the fastest option available. #[cfg_attr(asm, path = "inline/mod.rs")] #[cfg_attr(not(asm), path = "outline/mod.rs")] -pub(in crate::imp) mod asm; +pub(in crate::backend) mod asm; // On most architectures, the architecture syscall instruction is fast, so use // it directly. @@ -34,17 +36,17 @@ pub(in crate::imp) mod asm; target_arch = "riscv64", target_arch = "x86_64", ))] -pub(in crate::imp) use self::asm as choose; +pub(in crate::backend) use self::asm as choose; // On 32-bit x86, use vDSO wrappers for all syscalls. We could use the // architecture syscall instruction (`int 0x80`), but the vDSO kernel_vsyscall // mechanism is much faster. #[cfg(target_arch = "x86")] -pub(in crate::imp) use super::vdso_wrappers::x86_via_vdso as choose; +pub(in crate::backend) use super::vdso_wrappers::x86_via_vdso as choose; // This would be the code for always using `int 0x80` on 32-bit x86. //#[cfg(target_arch = "x86")] -//pub(in crate::imp) use self::asm as choose; +//pub(in crate::backend) use self::asm as choose; // Macros for invoking system calls. // @@ -55,27 +57,29 @@ pub(in crate::imp) use super::vdso_wrappers::x86_via_vdso as choose; // - Counting the number of arguments. macro_rules! syscall { ($nr:ident) => { - $crate::imp::arch::choose::syscall0($crate::imp::reg::nr(linux_raw_sys::general::$nr)) + $crate::backend::arch::choose::syscall0($crate::backend::reg::nr( + linux_raw_sys::general::$nr, + )) }; ($nr:ident, $a0:expr) => { - $crate::imp::arch::choose::syscall1( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall1( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), ) }; ($nr:ident, $a0:expr, $a1:expr) => { - $crate::imp::arch::choose::syscall2( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall2( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), ) }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr) => { - $crate::imp::arch::choose::syscall3( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall3( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -83,8 +87,8 @@ macro_rules! syscall { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr) => { - $crate::imp::arch::choose::syscall4( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall4( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -93,8 +97,8 @@ macro_rules! syscall { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => { - $crate::imp::arch::choose::syscall5( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall5( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -104,8 +108,8 @@ macro_rules! syscall { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => { - $crate::imp::arch::choose::syscall6( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall6( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -116,8 +120,8 @@ macro_rules! syscall { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => { - $crate::imp::arch::choose::syscall7( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall7( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -131,29 +135,29 @@ macro_rules! syscall { macro_rules! syscall_readonly { ($nr:ident) => { - $crate::imp::arch::choose::syscall0_readonly($crate::imp::reg::nr( + $crate::backend::arch::choose::syscall0_readonly($crate::backend::reg::nr( linux_raw_sys::general::$nr, )) }; ($nr:ident, $a0:expr) => { - $crate::imp::arch::choose::syscall1_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall1_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), ) }; ($nr:ident, $a0:expr, $a1:expr) => { - $crate::imp::arch::choose::syscall2_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall2_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), ) }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr) => { - $crate::imp::arch::choose::syscall3_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall3_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -161,8 +165,8 @@ macro_rules! syscall_readonly { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr) => { - $crate::imp::arch::choose::syscall4_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall4_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -171,8 +175,8 @@ macro_rules! syscall_readonly { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => { - $crate::imp::arch::choose::syscall5_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall5_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -182,8 +186,8 @@ macro_rules! syscall_readonly { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => { - $crate::imp::arch::choose::syscall6_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall6_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -194,8 +198,8 @@ macro_rules! syscall_readonly { }; ($nr:ident, $a0:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => { - $crate::imp::arch::choose::syscall7_readonly( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall7_readonly( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), $a1.into(), $a2.into(), @@ -210,8 +214,8 @@ macro_rules! syscall_readonly { #[cfg(feature = "runtime")] macro_rules! syscall_noreturn { ($nr:ident, $a0:expr) => { - $crate::imp::arch::choose::syscall1_noreturn( - $crate::imp::reg::nr(linux_raw_sys::general::$nr), + $crate::backend::arch::choose::syscall1_noreturn( + $crate::backend::reg::nr(linux_raw_sys::general::$nr), $a0.into(), ) }; diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/aarch64.s b/vendor/rustix/src/backend/linux_raw/arch/outline/aarch64.s index 1fad2fa6d..1fad2fa6d 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/aarch64.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/aarch64.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/arm.s b/vendor/rustix/src/backend/linux_raw/arch/outline/arm.s index 7001686f1..7001686f1 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/arm.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/arm.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/mips.s b/vendor/rustix/src/backend/linux_raw/arch/outline/mips.s index ab1bbfa2d..ab1bbfa2d 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/mips.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/mips.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/mips64.s b/vendor/rustix/src/backend/linux_raw/arch/outline/mips64.s index 3c5e76e36..3c5e76e36 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/mips64.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/mips64.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/mod.rs b/vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs index ce1352751..a6a5f270d 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/mod.rs @@ -28,6 +28,6 @@ mod nr_last; target_arch = "riscv64", target_arch = "x86_64", ))] -pub(in crate::imp) use nr_last::*; +pub(in crate::backend) use nr_last::*; #[cfg(target_arch = "x86")] -pub(in crate::imp) use x86::*; +pub(in crate::backend) use x86::*; diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/nr_last.rs b/vendor/rustix/src/backend/linux_raw/arch/outline/nr_last.rs index fdcd11021..4af64d6c4 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/nr_last.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/nr_last.rs @@ -13,8 +13,8 @@ //! other arguments mostly as they are. #[cfg(target_arch = "mips")] -use crate::imp::reg::A6; -use crate::imp::reg::{ArgReg, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::reg::A6; +use crate::backend::reg::{ArgReg, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; // First we declare the actual assembly routines with `*_nr_last` names and // reordered arguments. If the signatures or calling conventions are ever @@ -78,19 +78,19 @@ extern "C" { // Then we define inline wrapper functions that do the reordering. #[inline] -pub(in crate::imp) unsafe fn syscall0(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0(nr: SyscallNumber<'_>) -> RetReg<R0> { rustix_syscall0_nr_last(nr) } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { rustix_syscall1_nr_last(a0, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { rustix_syscall1_noreturn_nr_last(a0, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -98,7 +98,7 @@ pub(in crate::imp) unsafe fn syscall2( rustix_syscall2_nr_last(a0, a1, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -107,7 +107,7 @@ pub(in crate::imp) unsafe fn syscall3( rustix_syscall3_nr_last(a0, a1, a2, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -117,7 +117,7 @@ pub(in crate::imp) unsafe fn syscall4( rustix_syscall4_nr_last(a0, a1, a2, a3, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -128,7 +128,7 @@ pub(in crate::imp) unsafe fn syscall5( rustix_syscall5_nr_last(a0, a1, a2, a3, a4, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -141,7 +141,7 @@ pub(in crate::imp) unsafe fn syscall6( } #[cfg(target_arch = "mips")] #[inline] -pub(in crate::imp) unsafe fn syscall7( +pub(in crate::backend) unsafe fn syscall7( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -158,8 +158,8 @@ pub(in crate::imp) unsafe fn syscall7( // separate `_readonly` implementations, so these can just be aliases to // their non-`_readonly` counterparts. #[cfg(target_arch = "mips")] -pub(in crate::imp) use syscall7 as syscall7_readonly; -pub(in crate::imp) use { +pub(in crate::backend) use syscall7 as syscall7_readonly; +pub(in crate::backend) use { syscall0 as syscall0_readonly, syscall1 as syscall1_readonly, syscall2 as syscall2_readonly, syscall3 as syscall3_readonly, syscall4 as syscall4_readonly, syscall5 as syscall5_readonly, syscall6 as syscall6_readonly, diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/powerpc64.s b/vendor/rustix/src/backend/linux_raw/arch/outline/powerpc64.s index 29d4c0a95..29d4c0a95 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/powerpc64.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/powerpc64.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/riscv64.s b/vendor/rustix/src/backend/linux_raw/arch/outline/riscv64.s index 28d692f7c..28d692f7c 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/riscv64.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/riscv64.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/x86.rs b/vendor/rustix/src/backend/linux_raw/arch/outline/x86.rs index 938a4a09d..e74b8d2aa 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/x86.rs +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/x86.rs @@ -14,8 +14,8 @@ #![allow(dead_code, unused_imports)] -use crate::imp::reg::{ArgReg, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; -use crate::imp::vdso_wrappers::SyscallType; +use crate::backend::reg::{ArgReg, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; +use crate::backend::vdso_wrappers::SyscallType; // First we declare the actual assembly routines with `*_nr_last_fastcall` // names and reordered arguments. If the signatures or calling conventions are @@ -68,19 +68,19 @@ extern "fastcall" { // Then we define inline wrapper functions that do the reordering. #[inline] -pub(in crate::imp) unsafe fn syscall0(nr: SyscallNumber<'_>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall0(nr: SyscallNumber<'_>) -> RetReg<R0> { rustix_syscall0_nr_last_fastcall(nr) } #[inline] -pub(in crate::imp) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { +pub(in crate::backend) unsafe fn syscall1(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> RetReg<R0> { rustix_syscall1_nr_last_fastcall(a0, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { +pub(in crate::backend) unsafe fn syscall1_noreturn(nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>) -> ! { rustix_syscall1_noreturn_nr_last_fastcall(a0, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall2( +pub(in crate::backend) unsafe fn syscall2( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -88,7 +88,7 @@ pub(in crate::imp) unsafe fn syscall2( rustix_syscall2_nr_last_fastcall(a1, a0, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall3( +pub(in crate::backend) unsafe fn syscall3( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -97,7 +97,7 @@ pub(in crate::imp) unsafe fn syscall3( rustix_syscall3_nr_last_fastcall(a1, a2, a0, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall4( +pub(in crate::backend) unsafe fn syscall4( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -107,7 +107,7 @@ pub(in crate::imp) unsafe fn syscall4( rustix_syscall4_nr_last_fastcall(a1, a2, a0, a3, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall5( +pub(in crate::backend) unsafe fn syscall5( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -118,7 +118,7 @@ pub(in crate::imp) unsafe fn syscall5( rustix_syscall5_nr_last_fastcall(a1, a2, a0, a3, a4, nr) } #[inline] -pub(in crate::imp) unsafe fn syscall6( +pub(in crate::backend) unsafe fn syscall6( nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, a1: ArgReg<'_, A1>, @@ -133,7 +133,7 @@ pub(in crate::imp) unsafe fn syscall6( // Then we define the `_readonly` versions of the wrappers. We don't have // separate `_readonly` implementations, so these can just be aliases to // their non-`_readonly` counterparts. -pub(in crate::imp) use { +pub(in crate::backend) use { syscall0 as syscall0_readonly, syscall1 as syscall1_readonly, syscall2 as syscall2_readonly, syscall3 as syscall3_readonly, syscall4 as syscall4_readonly, syscall5 as syscall5_readonly, syscall6 as syscall6_readonly, @@ -206,14 +206,14 @@ extern "fastcall" { // Then we define inline wrapper functions that do the reordering. #[inline] -pub(in crate::imp) unsafe fn indirect_syscall0( +pub(in crate::backend) unsafe fn indirect_syscall0( callee: SyscallType, nr: SyscallNumber<'_>, ) -> RetReg<R0> { rustix_indirect_syscall0_nr_last_fastcall(nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall1( +pub(in crate::backend) unsafe fn indirect_syscall1( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -221,7 +221,7 @@ pub(in crate::imp) unsafe fn indirect_syscall1( rustix_indirect_syscall1_nr_last_fastcall(a0, nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall1_noreturn( +pub(in crate::backend) unsafe fn indirect_syscall1_noreturn( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -229,7 +229,7 @@ pub(in crate::imp) unsafe fn indirect_syscall1_noreturn( rustix_indirect_syscall1_noreturn_nr_last_fastcall(a0, nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall2( +pub(in crate::backend) unsafe fn indirect_syscall2( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -238,7 +238,7 @@ pub(in crate::imp) unsafe fn indirect_syscall2( rustix_indirect_syscall2_nr_last_fastcall(a1, a0, nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall3( +pub(in crate::backend) unsafe fn indirect_syscall3( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -248,7 +248,7 @@ pub(in crate::imp) unsafe fn indirect_syscall3( rustix_indirect_syscall3_nr_last_fastcall(a1, a2, a0, nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall4( +pub(in crate::backend) unsafe fn indirect_syscall4( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -259,7 +259,7 @@ pub(in crate::imp) unsafe fn indirect_syscall4( rustix_indirect_syscall4_nr_last_fastcall(a1, a2, a0, a3, nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall5( +pub(in crate::backend) unsafe fn indirect_syscall5( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, @@ -271,7 +271,7 @@ pub(in crate::imp) unsafe fn indirect_syscall5( rustix_indirect_syscall5_nr_last_fastcall(a1, a2, a0, a3, a4, nr, callee) } #[inline] -pub(in crate::imp) unsafe fn indirect_syscall6( +pub(in crate::backend) unsafe fn indirect_syscall6( callee: SyscallType, nr: SyscallNumber<'_>, a0: ArgReg<'_, A0>, diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/x86.s b/vendor/rustix/src/backend/linux_raw/arch/outline/x86.s index bda234e1a..bda234e1a 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/x86.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/x86.s diff --git a/vendor/rustix/src/imp/linux_raw/arch/outline/x86_64.s b/vendor/rustix/src/backend/linux_raw/arch/outline/x86_64.s index 2beda323b..2beda323b 100644 --- a/vendor/rustix/src/imp/linux_raw/arch/outline/x86_64.s +++ b/vendor/rustix/src/backend/linux_raw/arch/outline/x86_64.s diff --git a/vendor/rustix/src/imp/linux_raw/c.rs b/vendor/rustix/src/backend/linux_raw/c.rs index a6f0b8ff6..a6f0b8ff6 100644 --- a/vendor/rustix/src/imp/linux_raw/c.rs +++ b/vendor/rustix/src/backend/linux_raw/c.rs diff --git a/vendor/rustix/src/imp/linux_raw/conv.rs b/vendor/rustix/src/backend/linux_raw/conv.rs index c80ad58cc..7e09cdf80 100644 --- a/vendor/rustix/src/imp/linux_raw/conv.rs +++ b/vendor/rustix/src/backend/linux_raw/conv.rs @@ -30,9 +30,11 @@ use super::reg::{raw_arg, ArgNumber, ArgReg, RetReg, R0}; use super::time::types::ClockId; #[cfg(feature = "time")] use super::time::types::TimerfdClockId; +use crate::fd::OwnedFd; use crate::ffi::CStr; +#[cfg(feature = "fs")] use crate::fs::{FileType, Mode, OFlags}; -use crate::io::{self, OwnedFd}; +use crate::io; use crate::process::{Pid, Resource, Signal}; use crate::utils::{as_mut_ptr, as_ptr}; use core::mem::MaybeUninit; @@ -44,6 +46,7 @@ use linux_raw_sys::general::__kernel_loff_t; #[cfg(feature = "net")] use linux_raw_sys::general::socklen_t; #[cfg(target_pointer_width = "32")] +#[cfg(feature = "fs")] use linux_raw_sys::general::O_LARGEFILE; /// Convert `SYS_*` constants for socketcall. @@ -156,6 +159,7 @@ impl<'a, Num: ArgNumber> From<BorrowedFd<'a>> for ArgReg<'a, Num> { #[inline] pub(super) unsafe fn raw_fd<'a, Num: ArgNumber>(fd: RawFd) -> ArgReg<'a, Num> { // Use `no_fd` when passing `-1` is intended. + #[cfg(feature = "fs")] debug_assert!(fd == crate::fs::cwd().as_raw_fd() || fd >= 0); // Don't pass the `io_uring_register_files_skip` sentry value this way. @@ -226,7 +230,7 @@ pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<Num /// syscall. #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] #[inline] -pub(super) fn opt_ref<'a, T: Sized, Num: ArgNumber>(t: Option<&'a T>) -> ArgReg<'a, Num> { +pub(super) fn opt_ref<T: Sized, Num: ArgNumber>(t: Option<&T>) -> ArgReg<Num> { // This optimizes into the equivalent of `transmute(t)`, and has the // advantage of not requiring `unsafe`. match t { @@ -285,6 +289,7 @@ pub(super) fn socklen_t<'a, Num: ArgNumber>(i: socklen_t) -> ArgReg<'a, Num> { pass_usize(i as usize) } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<Mode> for ArgReg<'a, Num> { #[inline] fn from(mode: Mode) -> Self { @@ -292,6 +297,7 @@ impl<'a, Num: ArgNumber> From<Mode> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<(Mode, FileType)> for ArgReg<'a, Num> { #[inline] fn from(pair: (Mode, FileType)) -> Self { @@ -299,6 +305,7 @@ impl<'a, Num: ArgNumber> From<(Mode, FileType)> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::AtFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::AtFlags) -> Self { @@ -306,6 +313,7 @@ impl<'a, Num: ArgNumber> From<crate::fs::AtFlags> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::MemfdFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::MemfdFlags) -> Self { @@ -313,6 +321,7 @@ impl<'a, Num: ArgNumber> From<crate::fs::MemfdFlags> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::RenameFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::RenameFlags) -> Self { @@ -320,6 +329,7 @@ impl<'a, Num: ArgNumber> From<crate::fs::RenameFlags> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::StatxFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::StatxFlags) -> Self { @@ -327,9 +337,9 @@ impl<'a, Num: ArgNumber> From<crate::fs::StatxFlags> for ArgReg<'a, Num> { } } -impl<'a, Num: ArgNumber> From<crate::fs::FdFlags> for ArgReg<'a, Num> { +impl<'a, Num: ArgNumber> From<crate::io::FdFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::fs::FdFlags) -> Self { + fn from(flags: crate::io::FdFlags) -> Self { c_uint(flags.bits()) } } @@ -369,65 +379,67 @@ impl<'a, Num: ArgNumber> From<crate::io::epoll::CreateFlags> for ArgReg<'a, Num> } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::ProtFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::ProtFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::ProtFlags) -> Self { + fn from(flags: crate::backend::mm::types::ProtFlags) -> Self { c_uint(flags.bits()) } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::MsyncFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MsyncFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::MsyncFlags) -> Self { + fn from(flags: crate::backend::mm::types::MsyncFlags) -> Self { c_uint(flags.bits()) } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::MremapFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MremapFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::MremapFlags) -> Self { + fn from(flags: crate::backend::mm::types::MremapFlags) -> Self { c_uint(flags.bits()) } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::MlockFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MlockFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::MlockFlags) -> Self { + fn from(flags: crate::backend::mm::types::MlockFlags) -> Self { c_uint(flags.bits()) } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::MapFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MapFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::MapFlags) -> Self { + fn from(flags: crate::backend::mm::types::MapFlags) -> Self { c_uint(flags.bits()) } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::MprotectFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::MprotectFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::MprotectFlags) -> Self { + fn from(flags: crate::backend::mm::types::MprotectFlags) -> Self { c_uint(flags.bits()) } } -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` -impl<'a, Num: ArgNumber> From<crate::imp::mm::types::UserfaultfdFlags> for ArgReg<'a, Num> { +#[cfg(feature = "mm")] +impl<'a, Num: ArgNumber> From<crate::backend::mm::types::UserfaultfdFlags> for ArgReg<'a, Num> { #[inline] - fn from(flags: crate::imp::mm::types::UserfaultfdFlags) -> Self { + fn from(flags: crate::backend::mm::types::UserfaultfdFlags) -> Self { c_uint(flags.bits()) } } -impl<'a, Num: ArgNumber> From<crate::imp::process::types::MembarrierCommand> for ArgReg<'a, Num> { +impl<'a, Num: ArgNumber> From<crate::backend::process::types::MembarrierCommand> + for ArgReg<'a, Num> +{ #[inline] - fn from(cmd: crate::imp::process::types::MembarrierCommand) -> Self { + fn from(cmd: crate::backend::process::types::MembarrierCommand) -> Self { c_uint(cmd as u32) } } @@ -453,6 +465,7 @@ pub(super) fn dev_t<'a, Num: ArgNumber>(dev: u64) -> io::Result<ArgReg<'a, Num>> } #[cfg(target_pointer_width = "32")] +#[cfg(feature = "fs")] #[inline] fn oflags_bits(oflags: OFlags) -> c::c_uint { let mut bits = oflags.bits(); @@ -465,11 +478,13 @@ fn oflags_bits(oflags: OFlags) -> c::c_uint { } #[cfg(target_pointer_width = "64")] +#[cfg(feature = "fs")] #[inline] const fn oflags_bits(oflags: OFlags) -> c::c_uint { oflags.bits() } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<OFlags> for ArgReg<'a, Num> { #[inline] fn from(oflags: OFlags) -> Self { @@ -478,11 +493,13 @@ impl<'a, Num: ArgNumber> From<OFlags> for ArgReg<'a, Num> { } /// Convert an `OFlags` into a `u64` for use in the `open_how` struct. +#[cfg(feature = "fs")] #[inline] pub(super) fn oflags_for_open_how(oflags: OFlags) -> u64 { u64::from(oflags_bits(oflags)) } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::FallocateFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::FallocateFlags) -> Self { @@ -517,6 +534,7 @@ impl<'a, Num: ArgNumber> From<Signal> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::Advice> for ArgReg<'a, Num> { #[inline] fn from(advice: crate::fs::Advice) -> Self { @@ -524,6 +542,7 @@ impl<'a, Num: ArgNumber> From<crate::fs::Advice> for ArgReg<'a, Num> { } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::SealFlags> for ArgReg<'a, Num> { #[inline] fn from(flags: crate::fs::SealFlags) -> Self { @@ -615,6 +634,7 @@ impl<'a, Num: ArgNumber> From<(crate::thread::FutexOperation, crate::thread::Fut } } +#[cfg(feature = "fs")] impl<'a, Num: ArgNumber> From<crate::fs::Access> for ArgReg<'a, Num> { #[inline] fn from(access: crate::fs::Access) -> Self { @@ -744,7 +764,7 @@ pub(super) unsafe fn ret_usize_infallible(raw: RetReg<R0>) -> usize { #[inline] pub(super) unsafe fn ret_owned_fd(raw: RetReg<R0>) -> io::Result<OwnedFd> { let raw_fd = try_decode_raw_fd(raw)?; - Ok(OwnedFd::from(crate::imp::fd::OwnedFd::from_raw_fd(raw_fd))) + Ok(crate::backend::fd::OwnedFd::from_raw_fd(raw_fd)) } /// Convert the return value of `dup2` and `dup3`. diff --git a/vendor/rustix/src/imp/linux_raw/elf.rs b/vendor/rustix/src/backend/linux_raw/elf.rs index 7b9bb3245..87fb5fa0f 100644 --- a/vendor/rustix/src/imp/linux_raw/elf.rs +++ b/vendor/rustix/src/backend/linux_raw/elf.rs @@ -1,6 +1,10 @@ //! The ELF ABI. #![allow(non_snake_case)] +#![cfg_attr( + all(not(target_vendor = "mustang"), feature = "use-libc-auxv"), + allow(dead_code) +)] pub(super) const SELFMAG: usize = 4; pub(super) const ELFMAG: [u8; SELFMAG] = [0x7f, b'E', b'L', b'F']; diff --git a/vendor/rustix/src/imp/linux_raw/fs/dir.rs b/vendor/rustix/src/backend/linux_raw/fs/dir.rs index 64f5aa652..cfa347d03 100644 --- a/vendor/rustix/src/imp/linux_raw/fs/dir.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/dir.rs @@ -1,7 +1,9 @@ -use crate::fd::{AsFd, BorrowedFd}; +use crate::fd::{AsFd, BorrowedFd, OwnedFd}; use crate::ffi::{CStr, CString}; -use crate::fs::{fcntl_getfl, fstat, fstatfs, openat, FileType, Mode, OFlags, Stat, StatFs}; -use crate::io::{self, OwnedFd}; +use crate::fs::{ + fcntl_getfl, fstat, fstatfs, fstatvfs, openat, FileType, Mode, OFlags, Stat, StatFs, StatVfs, +}; +use crate::io; use crate::process::fchdir; use crate::utils::as_ptr; use alloc::borrow::ToOwned; @@ -51,7 +53,7 @@ impl Dir { /// `readdir(self)`, where `None` means the end of the directory. pub fn read(&mut self) -> Option<io::Result<DirEntry>> { if let Some(next) = self.next.take() { - match crate::imp::fs::syscalls::_seek(self.fd.as_fd(), next as i64, SEEK_SET) { + match crate::backend::fs::syscalls::_seek(self.fd.as_fd(), next as i64, SEEK_SET) { Ok(_) => (), Err(err) => return Some(Err(err)), } @@ -134,15 +136,19 @@ impl Dir { } fn read_more(&mut self) -> Option<io::Result<()>> { + let og_len = self.buf.len(); // Capacity increment currently chosen by wild guess. self.buf .resize(self.buf.capacity() + 32 * size_of::<linux_dirent64>(), 0); - self.pos = 0; - let nread = match crate::imp::fs::syscalls::getdents(self.fd.as_fd(), &mut self.buf) { + let nread = match crate::backend::fs::syscalls::getdents(self.fd.as_fd(), &mut self.buf) { Ok(nread) => nread, - Err(err) => return Some(Err(err)), + Err(err) => { + self.buf.resize(og_len, 0); + return Some(Err(err)); + } }; self.buf.resize(nread, 0); + self.pos = 0; if nread == 0 { None } else { @@ -162,6 +168,12 @@ impl Dir { fstatfs(&self.fd) } + /// `fstatvfs(self)` + #[inline] + pub fn statvfs(&self) -> io::Result<StatVfs> { + fstatvfs(&self.fd) + } + /// `fchdir(self)` #[inline] pub fn chdir(&self) -> io::Result<()> { diff --git a/vendor/rustix/src/imp/linux_raw/fs/makedev.rs b/vendor/rustix/src/backend/linux_raw/fs/makedev.rs index 284ba2f10..284ba2f10 100644 --- a/vendor/rustix/src/imp/linux_raw/fs/makedev.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/makedev.rs diff --git a/vendor/rustix/src/imp/linux_raw/fs/mod.rs b/vendor/rustix/src/backend/linux_raw/fs/mod.rs index 641e65744..015c6baec 100644 --- a/vendor/rustix/src/imp/linux_raw/fs/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/mod.rs @@ -1,4 +1,3 @@ -#[cfg(any(feature = "fs", feature = "procfs"))] pub(crate) mod dir; pub(crate) mod makedev; pub(crate) mod syscalls; diff --git a/vendor/rustix/src/imp/linux_raw/fs/syscalls.rs b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs index db1ecaaf6..ff58f0a7b 100644 --- a/vendor/rustix/src/imp/linux_raw/fs/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(dead_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -21,22 +21,23 @@ use super::super::conv::{loff_t, loff_t_from_u64, ret_u64}; target_pointer_width = "32", ))] use crate::fd::AsFd; -use crate::fd::{BorrowedFd, RawFd}; +use crate::fd::{BorrowedFd, OwnedFd}; use crate::ffi::CStr; use crate::fs::{ - Access, Advice, AtFlags, FallocateFlags, FdFlags, FileType, FlockOperation, MemfdFlags, Mode, - OFlags, RenameFlags, ResolveFlags, SealFlags, Stat, StatFs, StatxFlags, Timestamps, + Access, Advice, AtFlags, FallocateFlags, FileType, FlockOperation, MemfdFlags, Mode, OFlags, + RenameFlags, ResolveFlags, SealFlags, Stat, StatFs, StatVfs, StatVfsMountFlags, StatxFlags, + Timestamps, }; -use crate::io::{self, OwnedFd, SeekFrom}; +use crate::io::{self, SeekFrom}; use crate::process::{Gid, Uid}; use core::convert::TryInto; use core::mem::MaybeUninit; #[cfg(target_arch = "mips64")] use linux_raw_sys::general::stat as linux_stat64; use linux_raw_sys::general::{ - __kernel_timespec, open_how, statx, AT_EACCESS, AT_FDCWD, AT_REMOVEDIR, AT_SYMLINK_NOFOLLOW, - F_ADD_SEALS, F_DUPFD, F_DUPFD_CLOEXEC, F_GETFD, F_GETFL, F_GETLEASE, F_GETOWN, F_GETPIPE_SZ, - F_GETSIG, F_GET_SEALS, F_SETFD, F_SETFL, F_SETPIPE_SZ, SEEK_CUR, SEEK_END, SEEK_SET, + __kernel_fsid_t, __kernel_timespec, open_how, statx, AT_EACCESS, AT_FDCWD, AT_REMOVEDIR, + AT_SYMLINK_NOFOLLOW, F_ADD_SEALS, F_GETFL, F_GETLEASE, F_GETOWN, F_GETPIPE_SZ, F_GETSIG, + F_GET_SEALS, F_SETFL, F_SETPIPE_SZ, SEEK_CUR, SEEK_END, SEEK_SET, STATX__RESERVED, }; #[cfg(target_pointer_width = "32")] use { @@ -231,8 +232,8 @@ pub(crate) fn _seek(fd: BorrowedFd<'_>, offset: i64, whence: c::c_uint) -> io::R pass_usize(offset as usize), &mut result, c_uint(whence) - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } #[cfg(target_pointer_width = "64")] unsafe { @@ -413,14 +414,15 @@ pub(crate) fn fstat(fd: BorrowedFd<'_>) -> io::Result<Stat> { match statx(fd, cstr!(""), AtFlags::EMPTY_PATH, StatxFlags::BASIC_STATS) { Ok(x) => statx_to_stat(x), Err(io::Errno::NOSYS) => fstat_old(fd), - Err(e) => Err(e), + Err(err) => Err(err), } } #[cfg(all(target_pointer_width = "64", not(target_arch = "mips64")))] unsafe { let mut result = MaybeUninit::<Stat>::uninit(); - ret(syscall!(__NR_fstat, fd, &mut result)).map(|()| result.assume_init()) + ret(syscall!(__NR_fstat, fd, &mut result))?; + Ok(result.assume_init()) } } @@ -451,9 +453,9 @@ pub(crate) fn stat(filename: &CStr) -> io::Result<Stat> { AtFlags::empty(), StatxFlags::BASIC_STATS, ) { - Ok(x) => return statx_to_stat(x), + Ok(x) => statx_to_stat(x), Err(io::Errno::NOSYS) => stat_old(filename), - Err(e) => return Err(e), + Err(err) => Err(err), } } @@ -466,8 +468,8 @@ pub(crate) fn stat(filename: &CStr) -> io::Result<Stat> { filename, &mut result, c_uint(0) - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } } @@ -505,9 +507,9 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, filename: &CStr, flags: AtFlags) -> #[cfg(any(target_pointer_width = "32", target_arch = "mips64"))] { match statx(dirfd, filename, flags, StatxFlags::BASIC_STATS) { - Ok(x) => return statx_to_stat(x), + Ok(x) => statx_to_stat(x), Err(io::Errno::NOSYS) => statat_old(dirfd, filename, flags), - Err(e) => return Err(e), + Err(err) => Err(err), } } @@ -520,8 +522,8 @@ pub(crate) fn statat(dirfd: BorrowedFd<'_>, filename: &CStr, flags: AtFlags) -> filename, &mut result, flags - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } } @@ -564,9 +566,9 @@ pub(crate) fn lstat(filename: &CStr) -> io::Result<Stat> { AtFlags::SYMLINK_NOFOLLOW, StatxFlags::BASIC_STATS, ) { - Ok(x) => return statx_to_stat(x), + Ok(x) => statx_to_stat(x), Err(io::Errno::NOSYS) => lstat_old(filename), - Err(e) => return Err(e), + Err(err) => Err(err), } } @@ -579,8 +581,8 @@ pub(crate) fn lstat(filename: &CStr) -> io::Result<Stat> { filename, &mut result, c_uint(AT_SYMLINK_NOFOLLOW) - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } } @@ -719,6 +721,24 @@ pub(crate) fn statx( flags: AtFlags, mask: StatxFlags, ) -> io::Result<statx> { + // If a future Linux kernel adds more fields to `struct statx` and users + // passing flags unknown to rustix in `StatxFlags`, we could end up + // writing outside of the buffer. To prevent this possibility, we mask off + // any flags that we don't know about. + // + // This includes `STATX__RESERVED`, which has a value that we know, but + // which could take on arbitrary new meaning in the future. Linux currently + // rejects this flag with `EINVAL`, so we do the same. + // + // This doesn't rely on `STATX_ALL` because [it's deprecated] and already + // doesn't represent all the known flags. + // + // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/20200505095915.11275-7-mszeredi@redhat.com/ + if (mask.bits() & STATX__RESERVED) == STATX__RESERVED { + return Err(io::Errno::INVAL); + } + let mask = mask & StatxFlags::all(); + unsafe { let mut statx_buf = MaybeUninit::<statx>::uninit(); ret(syscall!( @@ -728,8 +748,8 @@ pub(crate) fn statx( flags, mask, &mut statx_buf - )) - .map(|()| statx_buf.assume_init()) + ))?; + Ok(statx_buf.assume_init()) } } @@ -762,18 +782,28 @@ pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> { fd, size_of::<StatFs, _>(), &mut result - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } #[cfg(target_pointer_width = "64")] unsafe { let mut result = MaybeUninit::<StatFs>::uninit(); - ret(syscall!(__NR_fstatfs, fd, &mut result)).map(|()| result.assume_init()) + ret(syscall!(__NR_fstatfs, fd, &mut result))?; + Ok(result.assume_init()) } } #[inline] +pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> { + // Linux doesn't have an `fstatvfs` syscall; we have to do `fstatfs` and + // translate the fields as best we can. + let statfs = fstatfs(fd)?; + + Ok(statfs_to_statvfs(statfs)) +} + +#[inline] pub(crate) fn statfs(filename: &CStr) -> io::Result<StatFs> { #[cfg(target_pointer_width = "32")] unsafe { @@ -783,13 +813,46 @@ pub(crate) fn statfs(filename: &CStr) -> io::Result<StatFs> { filename, size_of::<StatFs, _>(), &mut result - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } #[cfg(target_pointer_width = "64")] unsafe { let mut result = MaybeUninit::<StatFs>::uninit(); - ret(syscall!(__NR_statfs, filename, &mut result)).map(|()| result.assume_init()) + ret(syscall!(__NR_statfs, filename, &mut result))?; + Ok(result.assume_init()) + } +} + +#[inline] +pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> { + // Linux doesn't have a `statvfs` syscall; we have to do `statfs` and + // translate the fields as best we can. + let statfs = statfs(filename)?; + + Ok(statfs_to_statvfs(statfs)) +} + +fn statfs_to_statvfs(statfs: StatFs) -> StatVfs { + let __kernel_fsid_t { val } = statfs.f_fsid; + let [f_fsid_val0, f_fsid_val1]: [i32; 2] = val; + + StatVfs { + f_bsize: statfs.f_bsize as u64, + f_frsize: if statfs.f_frsize != 0 { + statfs.f_frsize + } else { + statfs.f_bsize + } as u64, + f_blocks: statfs.f_blocks as u64, + f_bfree: statfs.f_bfree as u64, + f_bavail: statfs.f_bavail as u64, + f_files: statfs.f_files as u64, + f_ffree: statfs.f_ffree as u64, + f_favail: statfs.f_ffree as u64, + f_fsid: f_fsid_val0 as u32 as u64 | ((f_fsid_val1 as u32 as u64) << 32), + f_flag: unsafe { StatVfsMountFlags::from_bits_unchecked(statfs.f_flags as u64) }, + f_namemax: statfs.f_namelen as u64, } } @@ -822,76 +885,6 @@ pub(crate) fn readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, buf: &mut [u8]) -> } #[inline] -pub(crate) fn fcntl_dupfd(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { - #[cfg(target_pointer_width = "32")] - unsafe { - ret_owned_fd(syscall_readonly!( - __NR_fcntl64, - fd, - c_uint(F_DUPFD), - raw_fd(min) - )) - } - #[cfg(target_pointer_width = "64")] - unsafe { - ret_owned_fd(syscall_readonly!( - __NR_fcntl, - fd, - c_uint(F_DUPFD), - raw_fd(min) - )) - } -} - -#[inline] -pub(crate) fn fcntl_dupfd_cloexec(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { - #[cfg(target_pointer_width = "32")] - unsafe { - ret_owned_fd(syscall_readonly!( - __NR_fcntl64, - fd, - c_uint(F_DUPFD_CLOEXEC), - raw_fd(min) - )) - } - #[cfg(target_pointer_width = "64")] - unsafe { - ret_owned_fd(syscall_readonly!( - __NR_fcntl, - fd, - c_uint(F_DUPFD_CLOEXEC), - raw_fd(min) - )) - } -} - -#[inline] -pub(crate) fn fcntl_getfd(fd: BorrowedFd<'_>) -> io::Result<FdFlags> { - #[cfg(target_pointer_width = "32")] - unsafe { - ret_c_uint(syscall_readonly!(__NR_fcntl64, fd, c_uint(F_GETFD))) - .map(FdFlags::from_bits_truncate) - } - #[cfg(target_pointer_width = "64")] - unsafe { - ret_c_uint(syscall_readonly!(__NR_fcntl, fd, c_uint(F_GETFD))) - .map(FdFlags::from_bits_truncate) - } -} - -#[inline] -pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> { - #[cfg(target_pointer_width = "32")] - unsafe { - ret(syscall_readonly!(__NR_fcntl64, fd, c_uint(F_SETFD), flags)) - } - #[cfg(target_pointer_width = "64")] - unsafe { - ret(syscall_readonly!(__NR_fcntl, fd, c_uint(F_SETFD), flags)) - } -} - -#[inline] pub(crate) fn fcntl_getfl(fd: BorrowedFd<'_>) -> io::Result<OFlags> { #[cfg(target_pointer_width = "32")] unsafe { diff --git a/vendor/rustix/src/imp/linux_raw/fs/types.rs b/vendor/rustix/src/backend/linux_raw/fs/types.rs index 959a5ee27..a8d225ede 100644 --- a/vendor/rustix/src/imp/linux_raw/fs/types.rs +++ b/vendor/rustix/src/backend/linux_raw/fs/types.rs @@ -2,17 +2,6 @@ use super::super::c; use bitflags::bitflags; bitflags! { - /// `FD_*` constants for use with [`fcntl_getfd`] and [`fcntl_setfd`]. - /// - /// [`fcntl_getfd`]: crate::fs::fcntl_getfd - /// [`fcntl_setfd`]: crate::fs::fcntl_setfd - pub struct FdFlags: c::c_uint { - /// `FD_CLOEXEC` - const CLOEXEC = linux_raw_sys::general::FD_CLOEXEC; - } -} - -bitflags! { /// `*_OK` constants for use with [`accessat`]. /// /// [`accessat`]: fn.accessat.html @@ -494,6 +483,38 @@ bitflags! { } } +bitflags! { + /// `ST_*` constants for use with [`StatVfs`]. + pub struct StatVfsMountFlags: u64 { + /// `ST_MANDLOCK` + const MANDLOCK = linux_raw_sys::general::MS_MANDLOCK as u64; + + /// `ST_NOATIME` + const NOATIME = linux_raw_sys::general::MS_NOATIME as u64; + + /// `ST_NODEV` + const NODEV = linux_raw_sys::general::MS_NODEV as u64; + + /// `ST_NODIRATIME` + const NODIRATIME = linux_raw_sys::general::MS_NODIRATIME as u64; + + /// `ST_NOEXEC` + const NOEXEC = linux_raw_sys::general::MS_NOEXEC as u64; + + /// `ST_NOSUID` + const NOSUID = linux_raw_sys::general::MS_NOSUID as u64; + + /// `ST_RDONLY` + const RDONLY = linux_raw_sys::general::MS_RDONLY as u64; + + /// `ST_RELATIME` + const RELATIME = linux_raw_sys::general::MS_RELATIME as u64; + + /// `ST_SYNCHRONOUS` + const SYNCHRONOUS = linux_raw_sys::general::MS_SYNCHRONOUS as u64; + } +} + /// `LOCK_*` constants for use with [`flock`] /// /// [`flock`]: crate::fs::flock @@ -551,19 +572,31 @@ pub struct Stat { #[cfg(all(target_pointer_width = "64", not(target_arch = "mips64")))] pub type Stat = linux_raw_sys::general::stat; -/// `struct statfs` for use with [`fstatfs`]. +/// `struct statfs` for use with [`statfs`] and [`fstatfs`]. /// +/// [`statfs`]: crate::fs::statfs /// [`fstatfs`]: crate::fs::fstatfs -#[cfg(target_pointer_width = "32")] #[allow(clippy::module_name_repetitions)] pub type StatFs = linux_raw_sys::general::statfs64; -/// `struct statfs` for use with [`fstatfs`]. +/// `struct statvfs` for use with [`statvfs`] and [`fstatvfs`]. /// -/// [`fstatfs`]: crate::fs::fstatfs -#[cfg(target_pointer_width = "64")] -#[allow(clippy::module_name_repetitions)] -pub type StatFs = linux_raw_sys::general::statfs64; +/// [`statvfs`]: crate::fs::statvfs +/// [`fstatvfs`]: crate::fs::fstatvfs +#[allow(missing_docs)] +pub struct StatVfs { + pub f_bsize: u64, + pub f_frsize: u64, + pub f_blocks: u64, + pub f_bfree: u64, + pub f_bavail: u64, + pub f_files: u64, + pub f_ffree: u64, + pub f_favail: u64, + pub f_fsid: u64, + pub f_flag: StatVfsMountFlags, + pub f_namemax: u64, +} /// `struct statx` for use with [`statx`]. /// diff --git a/vendor/rustix/src/imp/linux_raw/io/epoll.rs b/vendor/rustix/src/backend/linux_raw/io/epoll.rs index 4362e40fb..d55ad75b1 100644 --- a/vendor/rustix/src/imp/linux_raw/io/epoll.rs +++ b/vendor/rustix/src/backend/linux_raw/io/epoll.rs @@ -60,11 +60,11 @@ #![allow(unsafe_code)] use super::super::c; -use crate::fd::{AsFd, AsRawFd, BorrowedFd, RawFd}; +use crate::backend::io::syscalls::{epoll_add, epoll_create, epoll_del, epoll_mod, epoll_wait}; +use crate::fd::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd}; #[cfg(feature = "std")] -use crate::fd::{FromFd, FromRawFd, IntoFd, IntoRawFd}; -use crate::imp::io::syscalls::{epoll_add, epoll_create, epoll_del, epoll_mod, epoll_wait}; -use crate::io::{self, OwnedFd}; +use crate::fd::{FromRawFd, IntoRawFd}; +use crate::io; use alloc::vec::Vec; use bitflags::bitflags; use core::fmt; @@ -207,17 +207,17 @@ impl<'a> Context for Borrowing<'a> { } /// A type implementing [`Context`] where the `Data` type is `T`, a type -/// implementing `IntoFd` and `FromFd`. +/// implementing `From<OwnedFd>` and `From<T> of OwnedFd`. /// /// This may be used with [`OwnedFd`], or higher-level types like /// [`std::fs::File`] or [`std::net::TcpStream`]. #[cfg(feature = "std")] -pub struct Owning<'context, T: IntoFd + FromFd> { +pub struct Owning<'context, T: Into<OwnedFd> + From<OwnedFd>> { _phantom: PhantomData<&'context T>, } #[cfg(feature = "std")] -impl<'context, T: IntoFd + FromFd> Owning<'context, T> { +impl<'context, T: Into<OwnedFd> + From<OwnedFd>> Owning<'context, T> { /// Creates a new empty `Owning`. #[allow(clippy::new_without_default)] // This is a specialized type that doesn't need to be generically constructible. #[inline] @@ -229,16 +229,16 @@ impl<'context, T: IntoFd + FromFd> Owning<'context, T> { } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> Context for Owning<'context, T> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> Context for Owning<'context, T> { type Data = T; type Target = BorrowedFd<'context>; #[inline] fn acquire<'call>(&self, data: Self::Data) -> Ref<'call, Self::Target> { - let raw_fd = data.into_fd().into_raw_fd(); + let raw_fd = data.into().into_raw_fd(); // Safety: `epoll` will assign ownership of the file descriptor to the - // kernel epoll object. We use `IntoFd`+`IntoRawFd` to consume the - // `Data` and extract the raw file descriptor and then "borrow" it + // kernel epoll object. We use `Into<OwnedFd>`+`IntoRawFd` to consume + // the `Data` and extract the raw file descriptor and then "borrow" it // with `borrow_raw` knowing that the borrow won't outlive the // kernel epoll object. unsafe { Ref::new(BorrowedFd::<'context>::borrow_raw(raw_fd)) } @@ -261,7 +261,7 @@ impl<'context, T: AsFd + IntoFd + FromFd> Context for Owning<'context, T> { // Safety: The file descriptor was held by the kernel epoll object and // is now being released, so we can create a new `OwnedFd` that assumes // ownership. - unsafe { T::from_fd(io_lifetimes::OwnedFd::from_raw_fd(raw_fd)) } + unsafe { T::from(io_lifetimes::OwnedFd::from_raw_fd(raw_fd)) } } } @@ -388,21 +388,21 @@ impl<Context: self::Context> Epoll<Context> { } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> AsRawFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsRawFd for Epoll<Owning<'context, T>> { fn as_raw_fd(&self) -> RawFd { self.epoll_fd.as_raw_fd() } } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> IntoRawFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> IntoRawFd for Epoll<Owning<'context, T>> { fn into_raw_fd(self) -> RawFd { self.epoll_fd.into_raw_fd() } } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> FromRawFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> FromRawFd for Epoll<Owning<'context, T>> { unsafe fn from_raw_fd(fd: RawFd) -> Self { Self { epoll_fd: OwnedFd::from_raw_fd(fd), @@ -412,21 +412,25 @@ impl<'context, T: AsFd + IntoFd + FromFd> FromRawFd for Epoll<Owning<'context, T } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> AsFd for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> AsFd for Epoll<Owning<'context, T>> { fn as_fd(&self) -> BorrowedFd<'_> { self.epoll_fd.as_fd() } } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> From<Epoll<Owning<'context, T>>> for OwnedFd { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> From<Epoll<Owning<'context, T>>> + for OwnedFd +{ fn from(epoll: Epoll<Owning<'context, T>>) -> Self { epoll.epoll_fd } } #[cfg(feature = "std")] -impl<'context, T: AsFd + IntoFd + FromFd> From<OwnedFd> for Epoll<Owning<'context, T>> { +impl<'context, T: AsFd + Into<OwnedFd> + From<OwnedFd>> From<OwnedFd> + for Epoll<Owning<'context, T>> +{ fn from(fd: OwnedFd) -> Self { Self { epoll_fd: fd, diff --git a/vendor/rustix/src/imp/linux_raw/io/errno.rs b/vendor/rustix/src/backend/linux_raw/io/errno.rs index 2637ae02e..5c7b2fcd5 100644 --- a/vendor/rustix/src/imp/linux_raw/io/errno.rs +++ b/vendor/rustix/src/backend/linux_raw/io/errno.rs @@ -11,8 +11,8 @@ #![cfg_attr(not(rustc_attrs), allow(unused_unsafe))] use super::super::c; -use crate::imp::fd::RawFd; -use crate::imp::reg::{RetNumber, RetReg}; +use crate::backend::fd::RawFd; +use crate::backend::reg::{RetNumber, RetReg}; use crate::io; use linux_raw_sys::errno; @@ -78,7 +78,9 @@ impl Errno { /// Check for an error from the result of a syscall which encodes a /// `c::c_int` on success. #[inline] -pub(in crate::imp) fn try_decode_c_int<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<c::c_int> { +pub(in crate::backend) fn try_decode_c_int<Num: RetNumber>( + raw: RetReg<Num>, +) -> io::Result<c::c_int> { if raw.is_in_range(-4095..0) { // Safety: `raw` must be in `-4095..0`, and we just checked that raw is // in that range. @@ -91,7 +93,9 @@ pub(in crate::imp) fn try_decode_c_int<Num: RetNumber>(raw: RetReg<Num>) -> io:: /// Check for an error from the result of a syscall which encodes a /// `c::c_uint` on success. #[inline] -pub(in crate::imp) fn try_decode_c_uint<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<c::c_uint> { +pub(in crate::backend) fn try_decode_c_uint<Num: RetNumber>( + raw: RetReg<Num>, +) -> io::Result<c::c_uint> { if raw.is_in_range(-4095..0) { // Safety: `raw` must be in `-4095..0`, and we just checked that raw is // in that range. @@ -104,7 +108,7 @@ pub(in crate::imp) fn try_decode_c_uint<Num: RetNumber>(raw: RetReg<Num>) -> io: /// Check for an error from the result of a syscall which encodes a `usize` on /// success. #[inline] -pub(in crate::imp) fn try_decode_usize<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<usize> { +pub(in crate::backend) fn try_decode_usize<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<usize> { if raw.is_in_range(-4095..0) { // Safety: `raw` must be in `-4095..0`, and we just checked that raw is // in that range. @@ -117,7 +121,7 @@ pub(in crate::imp) fn try_decode_usize<Num: RetNumber>(raw: RetReg<Num>) -> io:: /// Check for an error from the result of a syscall which encodes a /// `*mut c_void` on success. #[inline] -pub(in crate::imp) fn try_decode_void_star<Num: RetNumber>( +pub(in crate::backend) fn try_decode_void_star<Num: RetNumber>( raw: RetReg<Num>, ) -> io::Result<*mut c::c_void> { if raw.is_in_range(-4095..0) { @@ -133,7 +137,7 @@ pub(in crate::imp) fn try_decode_void_star<Num: RetNumber>( /// `u64` on success. #[cfg(target_pointer_width = "64")] #[inline] -pub(in crate::imp) fn try_decode_u64<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<u64> { +pub(in crate::backend) fn try_decode_u64<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<u64> { if raw.is_in_range(-4095..0) { // Safety: `raw` must be in `-4095..0`, and we just checked that raw is // in that range. @@ -151,7 +155,7 @@ pub(in crate::imp) fn try_decode_u64<Num: RetNumber>(raw: RetReg<Num>) -> io::Re /// This must only be used with syscalls which return file descriptors on /// success. #[inline] -pub(in crate::imp) unsafe fn try_decode_raw_fd<Num: RetNumber>( +pub(in crate::backend) unsafe fn try_decode_raw_fd<Num: RetNumber>( raw: RetReg<Num>, ) -> io::Result<RawFd> { // Instead of using `check_result` here, we just check for negative, since @@ -180,7 +184,9 @@ pub(in crate::imp) unsafe fn try_decode_raw_fd<Num: RetNumber>( /// /// This must only be used with syscalls which return no value on success. #[inline] -pub(in crate::imp) unsafe fn try_decode_void<Num: RetNumber>(raw: RetReg<Num>) -> io::Result<()> { +pub(in crate::backend) unsafe fn try_decode_void<Num: RetNumber>( + raw: RetReg<Num>, +) -> io::Result<()> { // Instead of using `check_result` here, we just check for zero, since this // function is only used for system calls which have no other return value, // and this produces smaller code. @@ -210,7 +216,7 @@ pub(in crate::imp) unsafe fn try_decode_void<Num: RetNumber>(raw: RetReg<Num>) - /// This must only be used with syscalls which do not return on success. #[cfg(feature = "runtime")] #[inline] -pub(in crate::imp) unsafe fn try_decode_error<Num: RetNumber>(raw: RetReg<Num>) -> io::Errno { +pub(in crate::backend) unsafe fn try_decode_error<Num: RetNumber>(raw: RetReg<Num>) -> io::Errno { debug_assert!(raw.is_in_range(-4095..0)); // Tell the optimizer that we know the value is in the error range. @@ -226,7 +232,7 @@ pub(in crate::imp) unsafe fn try_decode_error<Num: RetNumber>(raw: RetReg<Num>) /// Return the contained `usize` value. #[cfg(not(debug_assertions))] #[inline] -pub(in crate::imp) fn decode_usize_infallible<Num: RetNumber>(raw: RetReg<Num>) -> usize { +pub(in crate::backend) fn decode_usize_infallible<Num: RetNumber>(raw: RetReg<Num>) -> usize { raw.decode_usize() } diff --git a/vendor/rustix/src/imp/linux_raw/io/io_slice.rs b/vendor/rustix/src/backend/linux_raw/io/io_slice.rs index fc8e64698..fc8e64698 100644 --- a/vendor/rustix/src/imp/linux_raw/io/io_slice.rs +++ b/vendor/rustix/src/backend/linux_raw/io/io_slice.rs diff --git a/vendor/rustix/src/imp/linux_raw/io/mod.rs b/vendor/rustix/src/backend/linux_raw/io/mod.rs index f5c2bf3c0..f5c2bf3c0 100644 --- a/vendor/rustix/src/imp/linux_raw/io/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/io/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/io/poll_fd.rs b/vendor/rustix/src/backend/linux_raw/io/poll_fd.rs index 252358331..252358331 100644 --- a/vendor/rustix/src/imp/linux_raw/io/poll_fd.rs +++ b/vendor/rustix/src/backend/linux_raw/io/poll_fd.rs diff --git a/vendor/rustix/src/imp/linux_raw/io/syscalls.rs b/vendor/rustix/src/backend/linux_raw/io/syscalls.rs index 7857859de..2cc7898af 100644 --- a/vendor/rustix/src/imp/linux_raw/io/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/io/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -10,22 +10,27 @@ use super::super::c; #[cfg(target_pointer_width = "64")] use super::super::conv::loff_t_from_u64; use super::super::conv::{ - by_ref, c_int, c_uint, pass_usize, raw_fd, ret, ret_discarded_fd, ret_owned_fd, ret_usize, - slice, slice_mut, zero, + by_ref, c_int, c_uint, opt_mut, pass_usize, raw_fd, ret, ret_c_uint, ret_discarded_fd, + ret_owned_fd, ret_usize, slice, slice_mut, zero, }; #[cfg(target_pointer_width = "32")] use super::super::conv::{hi, lo}; -use crate::fd::{AsFd, BorrowedFd, RawFd}; +use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; +#[cfg(any(target_os = "android", target_os = "linux"))] +use crate::io::SpliceFlags; use crate::io::{ - self, epoll, DupFlags, EventfdFlags, IoSlice, IoSliceMut, OwnedFd, PipeFlags, PollFd, - ReadWriteFlags, + self, epoll, DupFlags, EventfdFlags, FdFlags, IoSlice, IoSliceMut, IoSliceRaw, PipeFlags, + PollFd, ReadWriteFlags, }; -#[cfg(feature = "net")] +#[cfg(all(feature = "fs", feature = "net"))] use crate::net::{RecvFlags, SendFlags}; use core::cmp; use core::mem::MaybeUninit; +#[cfg(target_os = "espidf")] +use linux_raw_sys::general::F_DUPFD; use linux_raw_sys::general::{ - epoll_event, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD, UIO_MAXIOV, + epoll_event, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD, F_DUPFD_CLOEXEC, F_GETFD, F_SETFD, + UIO_MAXIOV, }; use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FIONBIO, FIONREAD, TIOCEXCL, TIOCNXCL}; #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] @@ -301,8 +306,8 @@ pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> pub(crate) fn ioctl_fionread(fd: BorrowedFd<'_>) -> io::Result<u64> { unsafe { let mut result = MaybeUninit::<c::c_int>::uninit(); - ret(syscall!(__NR_ioctl, fd, c_uint(FIONREAD), &mut result)) - .map(|()| result.assume_init() as u64) + ret(syscall!(__NR_ioctl, fd, c_uint(FIONREAD), &mut result))?; + Ok(result.assume_init() as u64) } } @@ -333,8 +338,8 @@ pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd<'_>) -> io::Result<()> { pub(crate) fn ioctl_blksszget(fd: BorrowedFd) -> io::Result<u32> { let mut result = MaybeUninit::<c::c_uint>::uninit(); unsafe { - ret(syscall!(__NR_ioctl, fd, c_uint(BLKSSZGET), &mut result)) - .map(|()| result.assume_init() as u32) + ret(syscall!(__NR_ioctl, fd, c_uint(BLKSSZGET), &mut result))?; + Ok(result.assume_init() as u32) } } @@ -342,12 +347,12 @@ pub(crate) fn ioctl_blksszget(fd: BorrowedFd) -> io::Result<u32> { pub(crate) fn ioctl_blkpbszget(fd: BorrowedFd) -> io::Result<u32> { let mut result = MaybeUninit::<c::c_uint>::uninit(); unsafe { - ret(syscall!(__NR_ioctl, fd, c_uint(BLKPBSZGET), &mut result)) - .map(|()| result.assume_init() as u32) + ret(syscall!(__NR_ioctl, fd, c_uint(BLKPBSZGET), &mut result))?; + Ok(result.assume_init() as u32) } } -#[cfg(feature = "net")] +#[cfg(all(feature = "fs", feature = "net"))] pub(crate) fn is_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { let (mut read, mut write) = crate::fs::fd::_is_file_read_write(fd)?; let mut not_socket = false; @@ -417,6 +422,77 @@ pub(crate) fn dup3(fd: BorrowedFd<'_>, new: &mut OwnedFd, flags: DupFlags) -> io } #[inline] +pub(crate) fn fcntl_getfd(fd: BorrowedFd<'_>) -> io::Result<FdFlags> { + #[cfg(target_pointer_width = "32")] + unsafe { + ret_c_uint(syscall_readonly!(__NR_fcntl64, fd, c_uint(F_GETFD))) + .map(FdFlags::from_bits_truncate) + } + #[cfg(target_pointer_width = "64")] + unsafe { + ret_c_uint(syscall_readonly!(__NR_fcntl, fd, c_uint(F_GETFD))) + .map(FdFlags::from_bits_truncate) + } +} + +#[inline] +pub(crate) fn fcntl_setfd(fd: BorrowedFd<'_>, flags: FdFlags) -> io::Result<()> { + #[cfg(target_pointer_width = "32")] + unsafe { + ret(syscall_readonly!(__NR_fcntl64, fd, c_uint(F_SETFD), flags)) + } + #[cfg(target_pointer_width = "64")] + unsafe { + ret(syscall_readonly!(__NR_fcntl, fd, c_uint(F_SETFD), flags)) + } +} + +#[cfg(target_os = "espidf")] +#[inline] +pub(crate) fn fcntl_dupfd(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { + #[cfg(target_pointer_width = "32")] + unsafe { + ret_owned_fd(syscall_readonly!( + __NR_fcntl64, + fd, + c_uint(F_DUPFD), + raw_fd(min) + )) + } + #[cfg(target_pointer_width = "64")] + unsafe { + ret_owned_fd(syscall_readonly!( + __NR_fcntl, + fd, + c_uint(F_DUPFD), + raw_fd(min) + )) + } +} + +#[inline] +pub(crate) fn fcntl_dupfd_cloexec(fd: BorrowedFd<'_>, min: RawFd) -> io::Result<OwnedFd> { + #[cfg(target_pointer_width = "32")] + unsafe { + ret_owned_fd(syscall_readonly!( + __NR_fcntl64, + fd, + c_uint(F_DUPFD_CLOEXEC), + raw_fd(min) + )) + } + #[cfg(target_pointer_width = "64")] + unsafe { + ret_owned_fd(syscall_readonly!( + __NR_fcntl, + fd, + c_uint(F_DUPFD_CLOEXEC), + raw_fd(min) + )) + } +} + +#[inline] pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { unsafe { let mut result = MaybeUninit::<[OwnedFd; 2]>::uninit(); @@ -558,3 +634,43 @@ pub(crate) fn epoll_wait( )) } } + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub fn splice( + fd_in: BorrowedFd, + off_in: Option<&mut u64>, + fd_out: BorrowedFd, + off_out: Option<&mut u64>, + len: usize, + flags: SpliceFlags, +) -> io::Result<usize> { + unsafe { + ret_usize(syscall!( + __NR_splice, + fd_in, + opt_mut(off_in), + fd_out, + opt_mut(off_out), + pass_usize(len), + c_uint(flags.bits()) + )) + } +} + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub unsafe fn vmsplice( + fd: BorrowedFd, + bufs: &[IoSliceRaw], + flags: SpliceFlags, +) -> io::Result<usize> { + let (bufs_addr, bufs_len) = slice(&bufs[..cmp::min(bufs.len(), max_iov())]); + ret_usize(syscall!( + __NR_vmsplice, + fd, + bufs_addr, + bufs_len, + c_uint(flags.bits()) + )) +} diff --git a/vendor/rustix/src/imp/linux_raw/io/types.rs b/vendor/rustix/src/backend/linux_raw/io/types.rs index 282a23aa1..51ab61d94 100644 --- a/vendor/rustix/src/imp/linux_raw/io/types.rs +++ b/vendor/rustix/src/backend/linux_raw/io/types.rs @@ -1,5 +1,17 @@ use super::super::c; use bitflags::bitflags; +use core::marker::PhantomData; + +bitflags! { + /// `FD_*` constants for use with [`fcntl_getfd`] and [`fcntl_setfd`]. + /// + /// [`fcntl_getfd`]: crate::io::fcntl_getfd + /// [`fcntl_setfd`]: crate::io::fcntl_setfd + pub struct FdFlags: c::c_uint { + /// `FD_CLOEXEC` + const CLOEXEC = linux_raw_sys::general::FD_CLOEXEC; + } +} bitflags! { /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`]. @@ -20,6 +32,21 @@ bitflags! { } } +#[cfg(any(target_os = "android", target_os = "linux"))] +bitflags! { + /// `SPLICE_F_*` constants for use with [`splice`] and [`vmsplice`]. + pub struct SpliceFlags: c::c_uint { + /// `SPLICE_F_MOVE` + const MOVE = linux_raw_sys::general::SPLICE_F_MOVE; + /// `SPLICE_F_NONBLOCK` + const NONBLOCK = linux_raw_sys::general::SPLICE_F_NONBLOCK; + /// `SPLICE_F_MORE` + const MORE = linux_raw_sys::general::SPLICE_F_MORE; + /// `SPLICE_F_GIFT` + const GIFT = linux_raw_sys::general::SPLICE_F_GIFT; + } +} + bitflags! { /// `O_*` constants for use with [`dup2`]. /// @@ -65,3 +92,37 @@ pub(crate) const AT_FDCWD: c::c_int = linux_raw_sys::general::AT_FDCWD; pub(crate) const STDIN_FILENO: c::c_uint = linux_raw_sys::general::STDIN_FILENO; pub(crate) const STDOUT_FILENO: c::c_uint = linux_raw_sys::general::STDOUT_FILENO; pub(crate) const STDERR_FILENO: c::c_uint = linux_raw_sys::general::STDERR_FILENO; + +/// A buffer type used with `vmsplice`. +/// It is guaranteed to be ABI compatible with the iovec type on Unix platforms and WSABUF on Windows. +/// Unlike `IoSlice` and `IoSliceMut` it is semantically like a raw pointer, +/// and therefore can be shared or mutated as needed. +#[repr(transparent)] +pub struct IoSliceRaw<'a> { + _buf: c::iovec, + _lifetime: PhantomData<&'a ()>, +} + +impl<'a> IoSliceRaw<'a> { + /// Creates a new IoSlice wrapping a byte slice. + pub fn from_slice(buf: &'a [u8]) -> Self { + IoSliceRaw { + _buf: c::iovec { + iov_base: buf.as_ptr() as *mut u8 as *mut c::c_void, + iov_len: buf.len() as _, + }, + _lifetime: PhantomData, + } + } + + /// Creates a new IoSlice wrapping a mutable byte slice. + pub fn from_slice_mut(buf: &'a mut [u8]) -> Self { + IoSliceRaw { + _buf: c::iovec { + iov_base: buf.as_mut_ptr() as *mut c::c_void, + iov_len: buf.len() as _, + }, + _lifetime: PhantomData, + } + } +} diff --git a/vendor/rustix/src/imp/linux_raw/io_uring/mod.rs b/vendor/rustix/src/backend/linux_raw/io_uring/mod.rs index ef944f04d..ef944f04d 100644 --- a/vendor/rustix/src/imp/linux_raw/io_uring/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/io_uring/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/io_uring/syscalls.rs b/vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs index 812568efc..196676985 100644 --- a/vendor/rustix/src/imp/linux_raw/io_uring/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/io_uring/syscalls.rs @@ -2,14 +2,13 @@ //! //! # Safety //! -//! See the `rustix::imp::syscalls` module documentation for details. +//! See the `rustix::backend::syscalls` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] use super::super::conv::{by_mut, c_uint, pass_usize, ret, ret_c_uint, ret_owned_fd}; -use crate::fd::BorrowedFd; +use crate::fd::{BorrowedFd, OwnedFd}; use crate::io; -use crate::io::OwnedFd; use crate::io_uring::{io_uring_params, IoringEnterFlags, IoringRegisterOp}; use core::ffi::c_void; diff --git a/vendor/rustix/src/imp/linux_raw/mm/mod.rs b/vendor/rustix/src/backend/linux_raw/mm/mod.rs index 1e0181a99..1e0181a99 100644 --- a/vendor/rustix/src/imp/linux_raw/mm/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/mm/syscalls.rs b/vendor/rustix/src/backend/linux_raw/mm/syscalls.rs index 8b230be3d..8fa6a3ec3 100644 --- a/vendor/rustix/src/imp/linux_raw/mm/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -14,8 +14,8 @@ use super::types::{ Advice, MapFlags, MlockFlags, MprotectFlags, MremapFlags, MsyncFlags, ProtFlags, UserfaultfdFlags, }; -use crate::fd::BorrowedFd; -use crate::io::{self, OwnedFd}; +use crate::fd::{BorrowedFd, OwnedFd}; +use crate::io; #[cfg(target_pointer_width = "32")] use core::convert::TryInto; use linux_raw_sys::general::MAP_ANONYMOUS; @@ -61,7 +61,7 @@ pub(crate) unsafe fn mmap( fd, (offset / 4096) .try_into() - .map(|scaled_offset| pass_usize(scaled_offset)) + .map(pass_usize) .map_err(|_| io::Errno::INVAL)? )) } diff --git a/vendor/rustix/src/imp/linux_raw/mm/types.rs b/vendor/rustix/src/backend/linux_raw/mm/types.rs index a58dd76be..a58dd76be 100644 --- a/vendor/rustix/src/imp/linux_raw/mm/types.rs +++ b/vendor/rustix/src/backend/linux_raw/mm/types.rs diff --git a/vendor/rustix/src/imp/linux_raw/mod.rs b/vendor/rustix/src/backend/linux_raw/mod.rs index ed46eaad1..231dc37b6 100644 --- a/vendor/rustix/src/imp/linux_raw/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/mod.rs @@ -24,23 +24,23 @@ mod vdso; #[cfg(any(feature = "time", target_arch = "x86"))] mod vdso_wrappers; -#[cfg(any( - feature = "param", - feature = "runtime", - feature = "time", - target_arch = "x86", -))] -pub(crate) mod param; -// #[cfg(feature = "fs")] // TODO: Enable once `OwnedFd` moves out of the tree. +#[cfg(feature = "fs")] pub(crate) mod fs; pub(crate) mod io; #[cfg(feature = "io_uring")] #[cfg_attr(doc_cfg, doc(cfg(feature = "io_uring")))] pub(crate) mod io_uring; -#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise` +#[cfg(feature = "mm")] pub(crate) mod mm; #[cfg(feature = "net")] pub(crate) mod net; +#[cfg(any( + feature = "param", + feature = "runtime", + feature = "time", + target_arch = "x86", +))] +pub(crate) mod param; pub(crate) mod process; #[cfg(feature = "rand")] pub(crate) mod rand; diff --git a/vendor/rustix/src/imp/linux_raw/net/addr.rs b/vendor/rustix/src/backend/linux_raw/net/addr.rs index d5683f34e..d5683f34e 100644 --- a/vendor/rustix/src/imp/linux_raw/net/addr.rs +++ b/vendor/rustix/src/backend/linux_raw/net/addr.rs diff --git a/vendor/rustix/src/imp/linux_raw/net/mod.rs b/vendor/rustix/src/backend/linux_raw/net/mod.rs index 5e67dfd21..f2273db1b 100644 --- a/vendor/rustix/src/imp/linux_raw/net/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/net/mod.rs @@ -1,6 +1,4 @@ pub(crate) mod addr; -#[cfg(not(feature = "std"))] -pub(crate) mod ext; pub(crate) mod read_sockaddr; pub(crate) mod send_recv; pub(crate) mod syscalls; diff --git a/vendor/rustix/src/imp/linux_raw/net/read_sockaddr.rs b/vendor/rustix/src/backend/linux_raw/net/read_sockaddr.rs index b9bc09b96..b9bc09b96 100644 --- a/vendor/rustix/src/imp/linux_raw/net/read_sockaddr.rs +++ b/vendor/rustix/src/backend/linux_raw/net/read_sockaddr.rs diff --git a/vendor/rustix/src/imp/linux_raw/net/send_recv.rs b/vendor/rustix/src/backend/linux_raw/net/send_recv.rs index 888e81e2b..888e81e2b 100644 --- a/vendor/rustix/src/imp/linux_raw/net/send_recv.rs +++ b/vendor/rustix/src/backend/linux_raw/net/send_recv.rs diff --git a/vendor/rustix/src/imp/linux_raw/net/syscalls.rs b/vendor/rustix/src/backend/linux_raw/net/syscalls.rs index 18a0f130d..7b9947a03 100644 --- a/vendor/rustix/src/imp/linux_raw/net/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/net/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -15,8 +15,8 @@ use super::read_sockaddr::{initialize_family_to_unspec, maybe_read_sockaddr_os, use super::send_recv::{RecvFlags, SendFlags}; use super::types::{AcceptFlags, AddressFamily, Protocol, Shutdown, SocketFlags, SocketType}; use super::write_sockaddr::{encode_sockaddr_v4, encode_sockaddr_v6}; -use crate::fd::BorrowedFd; -use crate::io::{self, OwnedFd}; +use crate::fd::{BorrowedFd, OwnedFd}; +use crate::io; use crate::net::{SocketAddrAny, SocketAddrUnix, SocketAddrV4, SocketAddrV6}; use c::{sockaddr, sockaddr_in, sockaddr_in6, socklen_t}; use core::convert::TryInto; @@ -102,11 +102,9 @@ pub(crate) fn socketpair( (type_, flags), protocol, &mut result - )) - .map(|()| { - let [fd0, fd1] = result.assume_init(); - (fd0, fd1) - }) + ))?; + let [fd0, fd1] = result.assume_init(); + Ok((fd0, fd1)) } #[cfg(target_arch = "x86")] unsafe { @@ -120,11 +118,9 @@ pub(crate) fn socketpair( protocol.into(), (&mut result).into(), ]) - )) - .map(|()| { - let [fd0, fd1] = result.assume_init(); - (fd0, fd1) - }) + ))?; + let [fd0, fd1] = result.assume_init(); + Ok((fd0, fd1)) } } @@ -1136,6 +1132,24 @@ pub(crate) mod sockopt { } #[inline] + pub(crate) fn set_ipv6_multicast_hops( + fd: BorrowedFd<'_>, + multicast_hops: u32, + ) -> io::Result<()> { + setsockopt( + fd, + c::IPPROTO_IP as _, + c::IPV6_MULTICAST_LOOP, + multicast_hops, + ) + } + + #[inline] + pub(crate) fn get_ipv6_multicast_hops(fd: BorrowedFd<'_>) -> io::Result<u32> { + getsockopt(fd, c::IPPROTO_IP as _, c::IPV6_MULTICAST_LOOP) + } + + #[inline] pub(crate) fn set_ip_add_membership( fd: BorrowedFd<'_>, multiaddr: &Ipv4Addr, diff --git a/vendor/rustix/src/imp/linux_raw/net/types.rs b/vendor/rustix/src/backend/linux_raw/net/types.rs index b8f786b3f..b8f786b3f 100644 --- a/vendor/rustix/src/imp/linux_raw/net/types.rs +++ b/vendor/rustix/src/backend/linux_raw/net/types.rs diff --git a/vendor/rustix/src/imp/linux_raw/net/write_sockaddr.rs b/vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs index 17abd96a0..17abd96a0 100644 --- a/vendor/rustix/src/imp/linux_raw/net/write_sockaddr.rs +++ b/vendor/rustix/src/backend/linux_raw/net/write_sockaddr.rs diff --git a/vendor/rustix/src/backend/linux_raw/param/auxv.rs b/vendor/rustix/src/backend/linux_raw/param/auxv.rs new file mode 100644 index 000000000..20a3d5da6 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/param/auxv.rs @@ -0,0 +1,370 @@ +//! Linux auxv support. +//! +//! # Safety +//! +//! This uses raw pointers to locate and read the kernel-provided auxv array. +#![allow(unsafe_code)] + +use super::super::c; +use super::super::elf::*; +use crate::fd::OwnedFd; +#[cfg(feature = "param")] +use crate::ffi::CStr; +use crate::fs::{Mode, OFlags}; +use crate::utils::{as_ptr, check_raw_pointer}; +use alloc::vec::Vec; +use core::ffi::c_void; +use core::mem::size_of; +use core::ptr::{null_mut, read_unaligned, NonNull}; +#[cfg(feature = "runtime")] +use core::slice; +use core::sync::atomic::Ordering::Relaxed; +use core::sync::atomic::{AtomicPtr, AtomicUsize}; +use linux_raw_sys::general::{ + AT_BASE, AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, + AT_PHNUM, AT_SYSINFO_EHDR, +}; + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn page_size() -> usize { + let mut page_size = PAGE_SIZE.load(Relaxed); + + if page_size == 0 { + init_from_proc_self_auxv(); + page_size = PAGE_SIZE.load(Relaxed); + } + + page_size +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn clock_ticks_per_second() -> u64 { + let mut ticks = CLOCK_TICKS_PER_SECOND.load(Relaxed); + + if ticks == 0 { + init_from_proc_self_auxv(); + ticks = CLOCK_TICKS_PER_SECOND.load(Relaxed); + } + + ticks as u64 +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_hwcap() -> (usize, usize) { + let mut hwcap = HWCAP.load(Relaxed); + let mut hwcap2 = HWCAP2.load(Relaxed); + + if hwcap == 0 || hwcap2 == 0 { + init_from_proc_self_auxv(); + hwcap = HWCAP.load(Relaxed); + hwcap2 = HWCAP2.load(Relaxed); + } + + (hwcap, hwcap2) +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_execfn() -> &'static CStr { + let mut execfn = EXECFN.load(Relaxed); + + if execfn.is_null() { + init_from_proc_self_auxv(); + execfn = EXECFN.load(Relaxed); + } + + // Safety: We assume the `AT_EXECFN` value provided by the kernel is a + // valid pointer to a valid NUL-terminated array of bytes. + unsafe { CStr::from_ptr(execfn.cast()) } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) { + let mut phdr = PHDR.load(Relaxed); + let mut phnum = PHNUM.load(Relaxed); + + if phdr.is_null() || phnum == 0 { + init_from_proc_self_auxv(); + phdr = PHDR.load(Relaxed); + phnum = PHNUM.load(Relaxed); + } + + (phdr.cast(), phnum) +} + +#[cfg(feature = "runtime")] +#[inline] +pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { + let (phdr, phnum) = exe_phdrs(); + + // Safety: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the + // kernel form a valid slice. + unsafe { slice::from_raw_parts(phdr.cast(), phnum) } +} + +/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, +/// so if we don't see it, this function returns a null pointer. +#[inline] +pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { + let mut ehdr = SYSINFO_EHDR.load(Relaxed); + + if ehdr.is_null() { + init_from_proc_self_auxv(); + ehdr = SYSINFO_EHDR.load(Relaxed); + } + + ehdr +} + +static PAGE_SIZE: AtomicUsize = AtomicUsize::new(0); +static CLOCK_TICKS_PER_SECOND: AtomicUsize = AtomicUsize::new(0); +static HWCAP: AtomicUsize = AtomicUsize::new(0); +static HWCAP2: AtomicUsize = AtomicUsize::new(0); +static SYSINFO_EHDR: AtomicPtr<Elf_Ehdr> = AtomicPtr::new(null_mut()); +static PHDR: AtomicPtr<Elf_Phdr> = AtomicPtr::new(null_mut()); +static PHNUM: AtomicUsize = AtomicUsize::new(0); +static EXECFN: AtomicPtr<c::c_char> = AtomicPtr::new(null_mut()); + +/// On non-Mustang platforms, we read the aux vector from /proc/self/auxv. +fn init_from_proc_self_auxv() { + // Open "/proc/self/auxv", either because we trust "/proc", or because + // we're running inside QEMU and `proc_self_auxv`'s extra checking foils + // QEMU's emulation so we need to do a plain open to get the right + // auxv records. + let file = crate::fs::openat( + crate::fs::cwd(), + "/proc/self/auxv", + OFlags::empty(), + Mode::empty(), + ) + .unwrap(); + + let _ = init_from_auxv_file(file); +} + +/// Process auxv entries from the open file `auxv`. +fn init_from_auxv_file(auxv: OwnedFd) -> Option<()> { + let mut buffer = Vec::<u8>::with_capacity(512); + loop { + let cur = buffer.len(); + + // Request one extra byte; `Vec` will often allocate more. + buffer.reserve(1); + + // Use all the space it allocated. + buffer.resize(buffer.capacity(), 0); + + // Read up to that many bytes. + let n = match crate::io::read(&auxv, &mut buffer[cur..]) { + Err(crate::io::Errno::INTR) => 0, + Err(_err) => panic!(), + Ok(0) => break, + Ok(n) => n, + }; + + // Account for the number of bytes actually read. + buffer.resize(cur + n, 0_u8); + } + + // Safety: We loaded from an auxv file into the buffer. + unsafe { init_from_auxp(buffer.as_ptr().cast()) } +} + +/// Process auxv entries from the auxv array pointed to by `auxp`. +/// +/// # Safety +/// +/// This must be passed a pointer to an auxv array. +/// +/// The buffer contains `Elf_aux_t` elements, though it need not be aligned; +/// function uses `read_unaligned` to read from it. +unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) -> Option<()> { + let mut pagesz = 0; + let mut clktck = 0; + let mut hwcap = 0; + let mut hwcap2 = 0; + let mut phdr = null_mut(); + let mut phnum = 0; + let mut execfn = null_mut(); + let mut sysinfo_ehdr = null_mut(); + let mut phent = 0; + + loop { + let Elf_auxv_t { a_type, a_val } = read_unaligned(auxp); + + match a_type as _ { + AT_PAGESZ => pagesz = a_val as usize, + AT_CLKTCK => clktck = a_val as usize, + AT_HWCAP => hwcap = a_val as usize, + AT_HWCAP2 => hwcap2 = a_val as usize, + AT_PHDR => phdr = check_raw_pointer::<Elf_Phdr>(a_val as *mut _)?.as_ptr(), + AT_PHNUM => phnum = a_val as usize, + AT_PHENT => phent = a_val as usize, + AT_EXECFN => execfn = check_raw_pointer::<c::c_char>(a_val as *mut _)?.as_ptr(), + AT_BASE => check_interpreter_base(a_val.cast())?, + AT_SYSINFO_EHDR => sysinfo_ehdr = check_vdso_base(a_val as *mut _)?.as_ptr(), + AT_NULL => break, + _ => (), + } + auxp = auxp.add(1); + } + + assert_eq!(phent, size_of::<Elf_Phdr>()); + + // The base and sysinfo_ehdr (if present) matches our platform. Accept + // the aux values. + PAGE_SIZE.store(pagesz, Relaxed); + CLOCK_TICKS_PER_SECOND.store(clktck, Relaxed); + HWCAP.store(hwcap, Relaxed); + HWCAP2.store(hwcap2, Relaxed); + PHDR.store(phdr, Relaxed); + PHNUM.store(phnum, Relaxed); + EXECFN.store(execfn, Relaxed); + SYSINFO_EHDR.store(sysinfo_ehdr, Relaxed); + + Some(()) +} + +/// Check that `base` is a valid pointer to the program interpreter. +/// +/// `base` is some value we got from a `AT_BASE` aux record somewhere, +/// which hopefully holds the value of the program interpreter in memory. Do a +/// series of checks to be as sure as we can that it's safe to use. +unsafe fn check_interpreter_base(base: *const Elf_Ehdr) -> Option<()> { + check_elf_base(base)?; + Some(()) +} + +/// Check that `base` is a valid pointer to the kernel-provided vDSO. +/// +/// `base` is some value we got from a `AT_SYSINFO_EHDR` aux record somewhere, +/// which hopefully holds the value of the kernel-provided vDSO in memory. Do a +/// series of checks to be as sure as we can that it's safe to use. +unsafe fn check_vdso_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> { + // In theory, we could check that we're not attempting to parse our own ELF + // image, as an additional check. However, older Linux toolchains don't + // support this, and Rust's `#[linkage = "extern_weak"]` isn't stable yet, + // so just disable this for now. + /* + { + extern "C" { + static __ehdr_start: c::c_void; + } + + let ehdr_start: *const c::c_void = &__ehdr_start; + if base == ehdr_start { + return None; + } + } + */ + + let hdr = check_elf_base(base)?; + + // Check that the ELF is not writable, since that would indicate that this + // isn't the ELF we think it is. Here we're just using `clock_getres` just + // as an arbitrary system call which writes to a buffer and fails with + // `EFAULT` if the buffer is not writable. + { + use super::super::conv::{c_uint, ret}; + if ret(syscall!( + __NR_clock_getres, + c_uint(linux_raw_sys::general::CLOCK_MONOTONIC), + base + )) != Err(crate::io::Errno::FAULT) + { + // We can't gracefully fail here because we would seem to have just + // mutated some unknown memory. + #[cfg(feature = "std")] + { + std::process::abort(); + } + #[cfg(all(not(feature = "std"), feature = "rustc-dep-of-std"))] + { + core::intrinsics::abort(); + } + } + } + + Some(hdr) +} + +/// Check that `base` is a valid pointer to an ELF image. +unsafe fn check_elf_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> { + // If we're reading a 64-bit auxv on a 32-bit platform, we'll see + // a zero `a_val` because `AT_*` values are never greater than + // `u32::MAX`. Zero is used by libc's `getauxval` to indicate + // errors, so it should never be a valid value. + if base.is_null() { + return None; + } + + let hdr = match check_raw_pointer::<Elf_Ehdr>(base as *mut _) { + Some(hdr) => hdr, + None => return None, + }; + + let hdr = hdr.as_ref(); + if hdr.e_ident[..SELFMAG] != ELFMAG { + return None; // Wrong ELF magic + } + if !matches!(hdr.e_ident[EI_OSABI], ELFOSABI_SYSV | ELFOSABI_LINUX) { + return None; // Unrecognized ELF OS ABI + } + if hdr.e_ident[EI_ABIVERSION] != ELFABIVERSION { + return None; // Unrecognized ELF ABI version + } + if hdr.e_type != ET_DYN { + return None; // Wrong ELF type + } + + // If ELF is extended, we'll need to adjust. + if hdr.e_ident[EI_VERSION] != EV_CURRENT + || hdr.e_ehsize as usize != size_of::<Elf_Ehdr>() + || hdr.e_phentsize as usize != size_of::<Elf_Phdr>() + { + return None; + } + // We don't currently support extra-large numbers of segments. + if hdr.e_phnum == PN_XNUM { + return None; + } + + // If `e_phoff` is zero, it's more likely that we're looking at memory that + // has been zeroed than that the kernel has somehow aliased the `Ehdr` and + // the `Phdr`. + if hdr.e_phoff < size_of::<Elf_Ehdr>() { + return None; + } + + // Verify that the `EI_CLASS`/`EI_DATA`/`e_machine` fields match the + // architecture we're running as. This helps catch cases where we're + // running under QEMU. + if hdr.e_ident[EI_CLASS] != ELFCLASS { + return None; // Wrong ELF class + } + if hdr.e_ident[EI_DATA] != ELFDATA { + return None; // Wrong ELF data + } + if hdr.e_machine != EM_CURRENT { + return None; // Wrong machine type + } + + Some(NonNull::new_unchecked(as_ptr(hdr) as *mut _)) +} + +// ELF ABI + +#[repr(C)] +#[derive(Copy, Clone)] +struct Elf_auxv_t { + a_type: usize, + + // Some of the values in the auxv array are pointers, so we make `a_val` a + // pointer, in order to preserve their provenance. For the values which are + // integers, we cast this to `usize`. + a_val: *const c_void, +} diff --git a/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs b/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs new file mode 100644 index 000000000..1597fd727 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/param/libc_auxv.rs @@ -0,0 +1,74 @@ +//! Linux auxv support, using libc. +//! +//! # Safety +//! +//! This uses raw pointers to locate and read the kernel-provided auxv array. +#![allow(unsafe_code)] + +#[cfg(any(feature = "param", feature = "runtime"))] +use super::super::c; +use super::super::elf::*; +#[cfg(feature = "param")] +use crate::ffi::CStr; +#[cfg(feature = "runtime")] +use core::slice; + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn page_size() -> usize { + unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn clock_ticks_per_second() -> u64 { + unsafe { libc::getauxval(libc::AT_CLKTCK) as u64 } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_hwcap() -> (usize, usize) { + unsafe { + ( + libc::getauxval(libc::AT_HWCAP) as usize, + libc::getauxval(libc::AT_HWCAP2) as usize, + ) + } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_execfn() -> &'static CStr { + unsafe { + let execfn = libc::getauxval(libc::AT_EXECFN) as *const c::c_char; + CStr::from_ptr(execfn.cast()) + } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) { + unsafe { + ( + libc::getauxval(libc::AT_PHDR) as *const c::c_void, + libc::getauxval(libc::AT_PHNUM) as usize, + ) + } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { + let (phdr, phnum) = exe_phdrs(); + + // Safety: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the + // kernel form a valid slice. + unsafe { slice::from_raw_parts(phdr.cast(), phnum) } +} + +/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, +/// so if we don't see it, this function returns a null pointer. +#[inline] +pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { + unsafe { libc::getauxval(linux_raw_sys::general::AT_SYSINFO_EHDR.into()) as *const Elf_Ehdr } +} diff --git a/vendor/rustix/src/backend/linux_raw/param/mod.rs b/vendor/rustix/src/backend/linux_raw/param/mod.rs new file mode 100644 index 000000000..956282074 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/param/mod.rs @@ -0,0 +1,12 @@ +// On Mustang, origin is in control of program startup and can access the +// incoming aux values on the stack. +// +// With "use-libc-auxv" enabled, use libc's `getauxval`. +// +// Otherwise, we read aux values from /proc/self/auxv. +#[cfg_attr(target_vendor = "mustang", path = "mustang_auxv.rs")] +#[cfg_attr( + all(not(target_vendor = "mustang"), feature = "use-libc-auxv"), + path = "libc_auxv.rs" +)] +pub(crate) mod auxv; diff --git a/vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs b/vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs new file mode 100644 index 000000000..e9b89b500 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/param/mustang_auxv.rs @@ -0,0 +1,159 @@ +//! Linux auxv support, for Mustang. +//! +//! # Safety +//! +//! This uses raw pointers to locate and read the kernel-provided auxv array. +#![allow(unsafe_code)] + +use super::super::c; +use super::super::elf::*; +#[cfg(feature = "param")] +use crate::ffi::CStr; +use core::ffi::c_void; +use core::mem::size_of; +use core::ptr::{null, read}; +#[cfg(feature = "runtime")] +use core::slice; +use linux_raw_sys::general::{ + AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, AT_PHNUM, + AT_SYSINFO_EHDR, +}; + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn page_size() -> usize { + // Safety: This is initialized during program startup. + unsafe { PAGE_SIZE } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn clock_ticks_per_second() -> u64 { + // Safety: This is initialized during program startup. + unsafe { CLOCK_TICKS_PER_SECOND as u64 } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_hwcap() -> (usize, usize) { + // Safety: This is initialized during program startup. + unsafe { (HWCAP, HWCAP2) } +} + +#[cfg(feature = "param")] +#[inline] +pub(crate) fn linux_execfn() -> &'static CStr { + // Safety: This is initialized during program startup. And we + // assume it's a valid pointer to a NUL-terminated string. + unsafe { CStr::from_ptr(EXECFN.0.cast()) } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(crate) fn exe_phdrs() -> (*const c_void, usize) { + // Safety: This is initialized during program startup. + unsafe { (PHDR.0.cast(), PHNUM) } +} + +#[cfg(feature = "runtime")] +#[inline] +pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { + let (phdr, phnum) = exe_phdrs(); + + // Safety: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the + // kernel form a valid slice. + unsafe { slice::from_raw_parts(phdr.cast(), phnum) } +} + +/// `AT_SYSINFO_EHDR` isn't present on all platforms in all configurations, +/// so if we don't see it, this function returns a null pointer. +#[inline] +pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { + // Safety: This is initialized during program startup. + unsafe { SYSINFO_EHDR.0 } +} + +/// A const pointer to `T` that implements [`Sync`]. +#[repr(transparent)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct SyncConstPtr<T>(*const T); +unsafe impl<T> Sync for SyncConstPtr<T> {} + +impl<T> SyncConstPtr<T> { + /// Creates a `SyncConstPointer` from a raw pointer. + /// + /// Behavior is undefined if `ptr` is actually not + /// safe to share across threads. + pub const unsafe fn new(ptr: *const T) -> Self { + Self(ptr) + } +} + +static mut PAGE_SIZE: usize = 0; +static mut CLOCK_TICKS_PER_SECOND: usize = 0; +static mut HWCAP: usize = 0; +static mut HWCAP2: usize = 0; +static mut SYSINFO_EHDR: SyncConstPtr<Elf_Ehdr> = unsafe { SyncConstPtr::new(null()) }; +static mut PHDR: SyncConstPtr<Elf_Phdr> = unsafe { SyncConstPtr::new(null()) }; +static mut PHNUM: usize = 0; +static mut EXECFN: SyncConstPtr<c::c_char> = unsafe { SyncConstPtr::new(null()) }; + +/// On mustang, we export a function to be called during initialization, and +/// passed a pointer to the original environment variable block set up by the +/// OS. +pub(crate) unsafe fn init(envp: *mut *mut u8) { + init_from_envp(envp); +} + +/// # Safety +/// +/// This must be passed a pointer to the environment variable buffer +/// provided by the kernel, which is followed in memory by the auxv array. +unsafe fn init_from_envp(mut envp: *mut *mut u8) { + while !(*envp).is_null() { + envp = envp.add(1); + } + init_from_auxp(envp.add(1).cast()) +} + +/// Process auxv entries from the auxv array pointed to by `auxp`. +/// +/// # Safety +/// +/// This must be passed a pointer to an auxv array. +/// +/// The buffer contains `Elf_aux_t` elements, though it need not be aligned; +/// function uses `read_unaligned` to read from it. +unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) { + loop { + let Elf_auxv_t { a_type, a_val } = read(auxp); + + match a_type as _ { + AT_PAGESZ => PAGE_SIZE = a_val as usize, + AT_CLKTCK => CLOCK_TICKS_PER_SECOND = a_val as usize, + AT_HWCAP => HWCAP = a_val as usize, + AT_HWCAP2 => HWCAP2 = a_val as usize, + AT_PHDR => PHDR = SyncConstPtr::new(a_val.cast::<Elf_Phdr>()), + AT_PHNUM => PHNUM = a_val as usize, + AT_PHENT => assert_eq!(a_val as usize, size_of::<Elf_Phdr>()), + AT_EXECFN => EXECFN = SyncConstPtr::new(a_val.cast::<c::c_char>()), + AT_SYSINFO_EHDR => SYSINFO_EHDR = SyncConstPtr::new(a_val.cast::<Elf_Ehdr>()), + AT_NULL => break, + _ => (), + } + auxp = auxp.add(1); + } +} + +// ELF ABI + +#[repr(C)] +#[derive(Copy, Clone)] +struct Elf_auxv_t { + a_type: usize, + + // Some of the values in the auxv array are pointers, so we make `a_val` a + // pointer, in order to preserve their provenance. For the values which are + // integers, we cast this to `usize`. + a_val: *const c_void, +} diff --git a/vendor/rustix/src/imp/linux_raw/process/cpu_set.rs b/vendor/rustix/src/backend/linux_raw/process/cpu_set.rs index 10c5f478e..10c5f478e 100644 --- a/vendor/rustix/src/imp/linux_raw/process/cpu_set.rs +++ b/vendor/rustix/src/backend/linux_raw/process/cpu_set.rs diff --git a/vendor/rustix/src/imp/linux_raw/process/mod.rs b/vendor/rustix/src/backend/linux_raw/process/mod.rs index 9b2c25f91..9b2c25f91 100644 --- a/vendor/rustix/src/imp/linux_raw/process/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/process/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/process/syscalls.rs b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs index 3c833ede7..ac62e6944 100644 --- a/vendor/rustix/src/imp/linux_raw/process/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/process/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -21,6 +21,7 @@ use crate::process::{ }; use core::convert::TryInto; use core::mem::MaybeUninit; +use core::num::NonZeroU32; use core::ptr::{null, null_mut}; use linux_raw_sys::general::{ __kernel_gid_t, __kernel_pid_t, __kernel_uid_t, membarrier_cmd, membarrier_cmd_flag, rlimit, @@ -100,6 +101,37 @@ pub(crate) fn getppid() -> Option<Pid> { } #[inline] +pub(crate) fn getpgid(pid: Option<Pid>) -> io::Result<Pid> { + unsafe { + let pgid: i32 = + ret_usize(syscall_readonly!(__NR_getpgid, c_uint(Pid::as_raw(pid))))? as __kernel_pid_t; + Ok(Pid::from_raw_nonzero(NonZeroU32::new_unchecked( + pgid as u32, + ))) + } +} + +#[inline] +pub(crate) fn getpgrp() -> Pid { + // Use the `getpgrp` syscall if available. + #[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] + unsafe { + let pgid: i32 = ret_usize_infallible(syscall_readonly!(__NR_getpgrp)) as __kernel_pid_t; + debug_assert!(pgid > 0); + Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pgid as u32)) + } + + // Otherwise use `getpgrp` and pass it zero. + #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] + unsafe { + let pgid: i32 = + ret_usize_infallible(syscall_readonly!(__NR_getpgid, c_uint(0))) as __kernel_pid_t; + debug_assert!(pgid > 0); + Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pgid as u32)) + } +} + +#[inline] pub(crate) fn getgid() -> Gid { #[cfg(any(target_arch = "x86", target_arch = "sparc", target_arch = "arm"))] unsafe { @@ -307,8 +339,8 @@ pub(crate) fn getrlimit(limit: Resource) -> Rlimit { &mut result )) { Ok(()) => rlimit_from_linux(result.assume_init()), - Err(e) => { - debug_assert_eq!(e, io::Errno::NOSYS); + Err(err) => { + debug_assert_eq!(err, io::Errno::NOSYS); getrlimit_old(limit) } } @@ -348,7 +380,7 @@ unsafe fn getrlimit_old(limit: Resource) -> Rlimit { #[inline] pub(crate) fn setrlimit(limit: Resource, new: Rlimit) -> io::Result<()> { unsafe { - let lim = rlimit_to_linux(new.clone())?; + let lim = rlimit_to_linux(new.clone()); match ret(syscall_readonly!( __NR_prlimit64, c_uint(0), @@ -358,7 +390,7 @@ pub(crate) fn setrlimit(limit: Resource, new: Rlimit) -> io::Result<()> { )) { Ok(()) => Ok(()), Err(io::Errno::NOSYS) => setrlimit_old(limit, new), - Err(e) => Err(e), + Err(err) => Err(err), } } } @@ -372,7 +404,7 @@ unsafe fn setrlimit_old(limit: Resource, new: Rlimit) -> io::Result<()> { #[inline] pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Result<Rlimit> { - let lim = rlimit_to_linux(new)?; + let lim = rlimit_to_linux(new); let mut result = MaybeUninit::<rlimit64>::uninit(); unsafe { match ret(syscall!( @@ -383,7 +415,7 @@ pub(crate) fn prlimit(pid: Option<Pid>, limit: Resource, new: Rlimit) -> io::Res &mut result )) { Ok(()) => Ok(rlimit_from_linux(result.assume_init())), - Err(e) => Err(e), + Err(err) => Err(err), } } } @@ -406,7 +438,7 @@ fn rlimit_from_linux(lim: rlimit64) -> Rlimit { /// Convert a C `rlimit64` to a Rust `Rlimit`. #[inline] -fn rlimit_to_linux(lim: Rlimit) -> io::Result<rlimit64> { +fn rlimit_to_linux(lim: Rlimit) -> rlimit64 { let rlim_cur = match lim.current { Some(r) => r, None => RLIM64_INFINITY as _, @@ -415,7 +447,7 @@ fn rlimit_to_linux(lim: Rlimit) -> io::Result<rlimit64> { Some(r) => r, None => RLIM64_INFINITY as _, }; - Ok(rlimit64 { rlim_cur, rlim_max }) + rlimit64 { rlim_cur, rlim_max } } /// Like `rlimit_from_linux` but uses Linux's old 32-bit `rlimit`. @@ -515,3 +547,14 @@ pub(crate) fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> { pub(crate) fn kill_current_process_group(sig: Signal) -> io::Result<()> { unsafe { ret(syscall_readonly!(__NR_kill, pass_usize(0), sig)) } } + +#[inline] +pub(crate) unsafe fn prctl( + option: c::c_int, + arg2: *mut c::c_void, + arg3: *mut c::c_void, + arg4: *mut c::c_void, + arg5: *mut c::c_void, +) -> io::Result<c::c_int> { + ret_c_int(syscall!(__NR_prctl, c_int(option), arg2, arg3, arg4, arg5)) +} diff --git a/vendor/rustix/src/imp/linux_raw/process/types.rs b/vendor/rustix/src/backend/linux_raw/process/types.rs index 53e2c7db1..53e2c7db1 100644 --- a/vendor/rustix/src/imp/linux_raw/process/types.rs +++ b/vendor/rustix/src/backend/linux_raw/process/types.rs diff --git a/vendor/rustix/src/imp/linux_raw/process/wait.rs b/vendor/rustix/src/backend/linux_raw/process/wait.rs index 701b4ac0c..701b4ac0c 100644 --- a/vendor/rustix/src/imp/linux_raw/process/wait.rs +++ b/vendor/rustix/src/backend/linux_raw/process/wait.rs diff --git a/vendor/rustix/src/imp/linux_raw/rand/mod.rs b/vendor/rustix/src/backend/linux_raw/rand/mod.rs index 1e0181a99..1e0181a99 100644 --- a/vendor/rustix/src/imp/linux_raw/rand/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/rand/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/rand/syscalls.rs b/vendor/rustix/src/backend/linux_raw/rand/syscalls.rs index 2b5ca28e5..5533f75e0 100644 --- a/vendor/rustix/src/imp/linux_raw/rand/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/rand/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] diff --git a/vendor/rustix/src/imp/linux_raw/rand/types.rs b/vendor/rustix/src/backend/linux_raw/rand/types.rs index 75f17443e..75f17443e 100644 --- a/vendor/rustix/src/imp/linux_raw/rand/types.rs +++ b/vendor/rustix/src/backend/linux_raw/rand/types.rs diff --git a/vendor/rustix/src/imp/linux_raw/reg.rs b/vendor/rustix/src/backend/linux_raw/reg.rs index afe99c5f4..afe99c5f4 100644 --- a/vendor/rustix/src/imp/linux_raw/reg.rs +++ b/vendor/rustix/src/backend/linux_raw/reg.rs diff --git a/vendor/rustix/src/imp/linux_raw/runtime/mod.rs b/vendor/rustix/src/backend/linux_raw/runtime/mod.rs index 0b48649ce..0b48649ce 100644 --- a/vendor/rustix/src/imp/linux_raw/runtime/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/runtime/syscalls.rs b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs index 49a29b2a2..a331786f9 100644 --- a/vendor/rustix/src/imp/linux_raw/runtime/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -10,8 +10,10 @@ use super::super::c; #[cfg(target_arch = "x86")] use super::super::conv::by_mut; use super::super::conv::{c_int, c_uint, ret, ret_c_uint, ret_error, ret_usize_infallible, zero}; +#[cfg(feature = "fs")] use crate::fd::BorrowedFd; use crate::ffi::CStr; +#[cfg(feature = "fs")] use crate::fs::AtFlags; use crate::io; use crate::process::{Pid, RawNonZeroPid}; @@ -32,6 +34,7 @@ pub(crate) unsafe fn fork() -> io::Result<Option<Pid>> { Ok(Pid::from_raw(pid)) } +#[cfg(feature = "fs")] pub(crate) unsafe fn execveat( dirfd: BorrowedFd<'_>, path: &CStr, diff --git a/vendor/rustix/src/imp/linux_raw/runtime/tls.rs b/vendor/rustix/src/backend/linux_raw/runtime/tls.rs index 63eed9bbd..43ed25d7d 100644 --- a/vendor/rustix/src/imp/linux_raw/runtime/tls.rs +++ b/vendor/rustix/src/backend/linux_raw/runtime/tls.rs @@ -22,15 +22,10 @@ pub(crate) fn startup_tls_info() -> StartupTlsInfo { // to the process describe a valid phdr array. unsafe { for phdr in phdrs { - match (*phdr).p_type { - PT_PHDR => { - base = phdrs - .as_ptr() - .cast::<u8>() - .offset(-((*phdr).p_vaddr as isize)) - } + match phdr.p_type { + PT_PHDR => base = phdrs.as_ptr().cast::<u8>().offset(-(phdr.p_vaddr as isize)), PT_TLS => tls_phdr = phdr, - PT_GNU_STACK => stack_size = (*phdr).p_memsz, + PT_GNU_STACK => stack_size = phdr.p_memsz, _ => {} } } diff --git a/vendor/rustix/src/imp/linux_raw/termios/mod.rs b/vendor/rustix/src/backend/linux_raw/termios/mod.rs index 1e0181a99..1e0181a99 100644 --- a/vendor/rustix/src/imp/linux_raw/termios/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/termios/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/termios/syscalls.rs b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs index b62a033e0..a8dda5f81 100644 --- a/vendor/rustix/src/imp/linux_raw/termios/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/termios/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -27,8 +27,8 @@ use linux_raw_sys::ioctl::{ pub(crate) fn tcgetwinsize(fd: BorrowedFd<'_>) -> io::Result<Winsize> { unsafe { let mut result = MaybeUninit::<Winsize>::uninit(); - ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGWINSZ), &mut result)) - .map(|()| result.assume_init()) + ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGWINSZ), &mut result))?; + Ok(result.assume_init()) } } @@ -36,7 +36,8 @@ pub(crate) fn tcgetwinsize(fd: BorrowedFd<'_>) -> io::Result<Winsize> { pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { unsafe { let mut result = MaybeUninit::<Termios>::uninit(); - ret(syscall!(__NR_ioctl, fd, c_uint(TCGETS), &mut result)).map(|()| result.assume_init()) + ret(syscall!(__NR_ioctl, fd, c_uint(TCGETS), &mut result))?; + Ok(result.assume_init()) } } @@ -44,11 +45,12 @@ pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> { pub(crate) fn tcgetpgrp(fd: BorrowedFd<'_>) -> io::Result<Pid> { unsafe { let mut result = MaybeUninit::<__kernel_pid_t>::uninit(); - ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGPGRP), &mut result)).map(|()| { - let pid = result.assume_init(); - debug_assert!(pid > 0); - Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pid as u32)) - }) + ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGPGRP), &mut result))?; + let pid = result.assume_init(); + debug_assert!(pid > 0); + Ok(Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked( + pid as u32, + ))) } } @@ -113,11 +115,12 @@ pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> { pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> { unsafe { let mut result = MaybeUninit::<__kernel_pid_t>::uninit(); - ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGSID), &mut result)).map(|()| { - let pid = result.assume_init(); - debug_assert!(pid > 0); - Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked(pid as u32)) - }) + ret(syscall!(__NR_ioctl, fd, c_uint(TIOCGSID), &mut result))?; + let pid = result.assume_init(); + debug_assert!(pid > 0); + Ok(Pid::from_raw_nonzero(RawNonZeroPid::new_unchecked( + pid as u32, + ))) } } @@ -227,7 +230,7 @@ pub(crate) fn ttyname(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> { // Gather the ttyname by reading the 'fd' file inside 'proc_self_fd'. let r = - super::super::fs::syscalls::readlinkat(proc_self_fd, DecInt::from_fd(&fd).as_c_str(), buf)?; + super::super::fs::syscalls::readlinkat(proc_self_fd, DecInt::from_fd(fd).as_c_str(), buf)?; // If the number of bytes is equal to the buffer length, truncation may // have occurred. This check also ensures that we have enough space for diff --git a/vendor/rustix/src/imp/linux_raw/termios/types.rs b/vendor/rustix/src/backend/linux_raw/termios/types.rs index ce8832455..88db4e1c9 100644 --- a/vendor/rustix/src/imp/linux_raw/termios/types.rs +++ b/vendor/rustix/src/backend/linux_raw/termios/types.rs @@ -338,15 +338,19 @@ pub const B1500000: Speed = linux_raw_sys::general::B1500000; pub const B2000000: Speed = linux_raw_sys::general::B2000000; /// `B2500000` +#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64",)))] pub const B2500000: Speed = linux_raw_sys::general::B2500000; /// `B3000000` +#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64",)))] pub const B3000000: Speed = linux_raw_sys::general::B3000000; /// `B3500000` +#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64",)))] pub const B3500000: Speed = linux_raw_sys::general::B3500000; /// `B4000000` +#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64",)))] pub const B4000000: Speed = linux_raw_sys::general::B4000000; /// `CSIZE` diff --git a/vendor/rustix/src/imp/linux_raw/thread/futex.rs b/vendor/rustix/src/backend/linux_raw/thread/futex.rs index 9e087f9f1..9e087f9f1 100644 --- a/vendor/rustix/src/imp/linux_raw/thread/futex.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/futex.rs diff --git a/vendor/rustix/src/imp/linux_raw/thread/mod.rs b/vendor/rustix/src/backend/linux_raw/thread/mod.rs index 8bb80c33a..8bb80c33a 100644 --- a/vendor/rustix/src/imp/linux_raw/thread/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/thread/syscalls.rs b/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs index 600b4649d..99c632e7e 100644 --- a/vendor/rustix/src/imp/linux_raw/thread/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/thread/syscalls.rs @@ -2,11 +2,15 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] -use super::super::conv::{by_ref, c_int, c_uint, ret, ret_usize, ret_usize_infallible, zero}; +use super::super::c; +use super::super::conv::{ + by_ref, c_int, c_uint, ret, ret_c_int, ret_usize, ret_usize_infallible, zero, +}; +use crate::fd::BorrowedFd; use crate::io; use crate::process::{Pid, RawNonZeroPid}; use crate::thread::{ClockId, FutexFlags, FutexOperation, NanosleepRelativeResult, Timespec}; @@ -278,3 +282,9 @@ unsafe fn futex_old( c_uint(val3) )) } + +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub(crate) fn setns(fd: BorrowedFd, nstype: c::c_int) -> io::Result<c::c_int> { + unsafe { ret_c_int(syscall_readonly!(__NR_setns, fd, c_int(nstype))) } +} diff --git a/vendor/rustix/src/imp/linux_raw/time/mod.rs b/vendor/rustix/src/backend/linux_raw/time/mod.rs index c42592c4f..c42592c4f 100644 --- a/vendor/rustix/src/imp/linux_raw/time/mod.rs +++ b/vendor/rustix/src/backend/linux_raw/time/mod.rs diff --git a/vendor/rustix/src/imp/linux_raw/time/syscalls.rs b/vendor/rustix/src/backend/linux_raw/time/syscalls.rs index 93651e499..6e73a921b 100644 --- a/vendor/rustix/src/imp/linux_raw/time/syscalls.rs +++ b/vendor/rustix/src/backend/linux_raw/time/syscalls.rs @@ -2,7 +2,7 @@ //! //! # Safety //! -//! See the `rustix::imp` module documentation for details. +//! See the `rustix::backend` module documentation for details. #![allow(unsafe_code)] #![allow(clippy::undocumented_unsafe_blocks)] @@ -12,9 +12,9 @@ use super::super::conv::{ret, ret_infallible}; use super::types::ClockId; #[cfg(feature = "time")] use crate::fd::BorrowedFd; -use crate::io; #[cfg(feature = "time")] -use crate::io::OwnedFd; +use crate::fd::OwnedFd; +use crate::io; #[cfg(feature = "time")] use crate::time::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}; use core::mem::MaybeUninit; @@ -88,8 +88,8 @@ pub(crate) fn timerfd_settime( flags, by_ref(new_value), &mut result - )) - .map(|()| result.assume_init()) + ))?; + Ok(result.assume_init()) } #[cfg(target_pointer_width = "32")] @@ -109,8 +109,8 @@ pub(crate) fn timerfd_settime( } else { Err(err) } - }) - .map(|()| result.assume_init()) + })?; + Ok(result.assume_init()) } } @@ -183,22 +183,22 @@ pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> { #[cfg(target_pointer_width = "64")] unsafe { - ret(syscall!(__NR_timerfd_gettime, fd, &mut result)).map(|()| result.assume_init()) + ret(syscall!(__NR_timerfd_gettime, fd, &mut result))?; + Ok(result.assume_init()) } #[cfg(target_pointer_width = "32")] unsafe { - ret(syscall!(__NR_timerfd_gettime64, fd, &mut result)) - .or_else(|err| { - // See the comments in `rustix_clock_gettime_via_syscall` about - // emulation. - if err == io::Errno::NOSYS { - timerfd_gettime_old(fd, &mut result) - } else { - Err(err) - } - }) - .map(|()| result.assume_init()) + ret(syscall!(__NR_timerfd_gettime64, fd, &mut result)).or_else(|err| { + // See the comments in `rustix_clock_gettime_via_syscall` about + // emulation. + if err == io::Errno::NOSYS { + timerfd_gettime_old(fd, &mut result) + } else { + Err(err) + } + })?; + Ok(result.assume_init()) } } diff --git a/vendor/rustix/src/imp/linux_raw/time/types.rs b/vendor/rustix/src/backend/linux_raw/time/types.rs index 5a0fcc6f5..5a0fcc6f5 100644 --- a/vendor/rustix/src/imp/linux_raw/time/types.rs +++ b/vendor/rustix/src/backend/linux_raw/time/types.rs diff --git a/vendor/rustix/src/backend/linux_raw/vdso.rs b/vendor/rustix/src/backend/linux_raw/vdso.rs new file mode 100644 index 000000000..da7910b88 --- /dev/null +++ b/vendor/rustix/src/backend/linux_raw/vdso.rs @@ -0,0 +1,310 @@ +//! Parse the Linux vDSO. +//! +//! The following code is transliterated from +//! tools/testing/selftests/vDSO/parse_vdso.c in Linux 5.11, which is licensed +//! with Creative Commons Zero License, version 1.0, +//! available at <https://creativecommons.org/publicdomain/zero/1.0/legalcode> +//! +//! # Safety +//! +//! Parsing the vDSO involves a lot of raw pointer manipulation. This +//! implementation follows Linux's reference implementation, and adds several +//! additional safety checks. +#![allow(unsafe_code)] + +use super::c; +use super::elf::*; +use crate::ffi::CStr; +use crate::utils::check_raw_pointer; +use core::ffi::c_void; +use core::mem::size_of; +use core::ptr::{null, null_mut}; + +pub(super) struct Vdso { + // Load information + load_addr: *const Elf_Ehdr, + load_end: *const c_void, // the end of the `PT_LOAD` segment + pv_offset: usize, // recorded paddr - recorded vaddr + + // Symbol table + symtab: *const Elf_Sym, + symstrings: *const u8, + bucket: *const u32, + chain: *const u32, + nbucket: u32, + //nchain: u32, + + // Version table + versym: *const u16, + verdef: *const Elf_Verdef, +} + +// Straight from the ELF specification. +fn elf_hash(name: &CStr) -> u32 { + let mut h: u32 = 0; + for b in name.to_bytes() { + h = (h << 4).wrapping_add(u32::from(*b)); + let g = h & 0xf000_0000; + if g != 0 { + h ^= g >> 24; + } + h &= !g; + } + h +} + +/// Create a `Vdso` value by parsing the vDSO at the `sysinfo_ehdr` address. +fn init_from_sysinfo_ehdr() -> Option<Vdso> { + // Safety: the auxv initialization code does extensive checks to ensure + // that the value we get really is an `AT_SYSINFO_EHDR` value from the + // kernel. + unsafe { + let hdr = super::param::auxv::sysinfo_ehdr(); + + // If the platform doesn't provide a `AT_SYSINFO_EHDR`, we can't locate + // the vDSO. + if hdr.is_null() { + return None; + } + + let mut vdso = Vdso { + load_addr: hdr, + load_end: hdr.cast(), + pv_offset: 0, + symtab: null(), + symstrings: null(), + bucket: null(), + chain: null(), + nbucket: 0, + //nchain: 0, + versym: null(), + verdef: null(), + }; + + let hdr = &*hdr; + let pt = check_raw_pointer::<Elf_Phdr>(vdso.base_plus(hdr.e_phoff)? as *mut _)?.as_ptr(); + let mut dyn_: *const Elf_Dyn = null(); + let mut num_dyn = 0; + + // We need two things from the segment table: the load offset + // and the dynamic table. + let mut found_vaddr = false; + for i in 0..hdr.e_phnum { + let phdr = &*pt.add(i as usize); + if phdr.p_flags & PF_W != 0 { + // Don't trust any vDSO that claims to be loading writable + // segments into memory. + return None; + } + if phdr.p_type == PT_LOAD && !found_vaddr { + // The segment should be readable and executable, because it + // contains the symbol table and the function bodies. + if phdr.p_flags & (PF_R | PF_X) != (PF_R | PF_X) { + return None; + } + found_vaddr = true; + vdso.load_end = vdso.base_plus(phdr.p_offset.checked_add(phdr.p_memsz)?)?; + vdso.pv_offset = phdr.p_offset.wrapping_sub(phdr.p_vaddr); + } else if phdr.p_type == PT_DYNAMIC { + // If `p_offset` is zero, it's more likely that we're looking at memory + // that has been zeroed than that the kernel has somehow aliased the + // `Ehdr` and the `Elf_Dyn` array. + if phdr.p_offset < size_of::<Elf_Ehdr>() { + return None; + } + + dyn_ = check_raw_pointer::<Elf_Dyn>(vdso.base_plus(phdr.p_offset)? as *mut _)? + .as_ptr(); + num_dyn = phdr.p_memsz / size_of::<Elf_Dyn>(); + } else if phdr.p_type == PT_INTERP || phdr.p_type == PT_GNU_RELRO { + // Don't trust any ELF image that has an "interpreter" or that uses + // RELRO, which is likely to be a user ELF image rather and not the + // kernel vDSO. + return None; + } + } + + if !found_vaddr || dyn_.is_null() { + return None; // Failed + } + + // Fish out the useful bits of the dynamic table. + let mut hash: *const u32 = null(); + vdso.symstrings = null(); + vdso.symtab = null(); + vdso.versym = null(); + vdso.verdef = null(); + let mut i = 0; + loop { + if i == num_dyn { + return None; + } + let d = &*dyn_.add(i); + match d.d_tag { + DT_STRTAB => { + vdso.symstrings = + check_raw_pointer::<u8>(vdso.addr_from_elf(d.d_val)? as *mut _)?.as_ptr(); + } + DT_SYMTAB => { + vdso.symtab = + check_raw_pointer::<Elf_Sym>(vdso.addr_from_elf(d.d_val)? as *mut _)? + .as_ptr(); + } + DT_HASH => { + hash = + check_raw_pointer::<u32>(vdso.addr_from_elf(d.d_val)? as *mut _)?.as_ptr(); + } + DT_VERSYM => { + vdso.versym = + check_raw_pointer::<u16>(vdso.addr_from_elf(d.d_val)? as *mut _)?.as_ptr(); + } + DT_VERDEF => { + vdso.verdef = + check_raw_pointer::<Elf_Verdef>(vdso.addr_from_elf(d.d_val)? as *mut _)? + .as_ptr(); + } + DT_SYMENT => { + if d.d_val != size_of::<Elf_Sym>() { + return None; // Failed + } + } + DT_NULL => break, + _ => {} + } + i = i.checked_add(1)?; + } + // The upstream code checks `symstrings`, `symtab`, and `hash` for null; + // here, `check_raw_pointer` has already done that. + + if vdso.verdef.is_null() { + vdso.versym = null(); + } + + // Parse the hash table header. + vdso.nbucket = *hash.add(0); + //vdso.nchain = *hash.add(1); + vdso.bucket = hash.add(2); + vdso.chain = hash.add(vdso.nbucket as usize + 2); + + // That's all we need. + Some(vdso) + } +} + +impl Vdso { + /// Parse the vDSO. + /// + /// Returns `None` if the vDSO can't be located or if it doesn't conform + /// to our expectations. + #[inline] + pub(super) fn new() -> Option<Self> { + init_from_sysinfo_ehdr() + } + + /// Check the version for a symbol. + /// + /// # Safety + /// + /// The raw pointers inside `self` must be valid. + unsafe fn match_version(&self, mut ver: u16, name: &CStr, hash: u32) -> bool { + // This is a helper function to check if the version indexed by + // ver matches name (which hashes to hash). + // + // The version definition table is a mess, and I don't know how + // to do this in better than linear time without allocating memory + // to build an index. I also don't know why the table has + // variable size entries in the first place. + // + // For added fun, I can't find a comprehensible specification of how + // to parse all the weird flags in the table. + // + // So I just parse the whole table every time. + + // First step: find the version definition + ver &= 0x7fff; // Apparently bit 15 means "hidden" + let mut def = self.verdef; + loop { + if (*def).vd_version != VER_DEF_CURRENT { + return false; // Failed + } + + if ((*def).vd_flags & VER_FLG_BASE) == 0 && ((*def).vd_ndx & 0x7fff) == ver { + break; + } + + if (*def).vd_next == 0 { + return false; // No definition. + } + + def = def + .cast::<u8>() + .add((*def).vd_next as usize) + .cast::<Elf_Verdef>(); + } + + // Now figure out whether it matches. + let aux = &*(def.cast::<u8>()) + .add((*def).vd_aux as usize) + .cast::<Elf_Verdaux>(); + (*def).vd_hash == hash + && (name == CStr::from_ptr(self.symstrings.add(aux.vda_name as usize).cast())) + } + + /// Look up a symbol in the vDSO. + pub(super) fn sym(&self, version: &CStr, name: &CStr) -> *mut c::c_void { + let ver_hash = elf_hash(version); + let name_hash = elf_hash(name); + + // Safety: The pointers in `self` must be valid. + unsafe { + let mut chain = *self.bucket.add((name_hash % self.nbucket) as usize); + + while chain != STN_UNDEF { + let sym = &*self.symtab.add(chain as usize); + + // Check for a defined global or weak function w/ right name. + // + // The reference parser in Linux's parse_vdso.c requires + // symbols to have type `STT_FUNC`, but on powerpc64, the vDSO + // uses `STT_NOTYPE`, so allow that too. + if (ELF_ST_TYPE(sym.st_info) != STT_FUNC && + ELF_ST_TYPE(sym.st_info) != STT_NOTYPE) + || (ELF_ST_BIND(sym.st_info) != STB_GLOBAL + && ELF_ST_BIND(sym.st_info) != STB_WEAK) + || sym.st_shndx == SHN_UNDEF + || sym.st_shndx == SHN_ABS + || ELF_ST_VISIBILITY(sym.st_other) != STV_DEFAULT + || (name != CStr::from_ptr(self.symstrings.add(sym.st_name as usize).cast())) + // Check symbol version. + || (!self.versym.is_null() + && !self.match_version(*self.versym.add(chain as usize), version, ver_hash)) + { + chain = *self.chain.add(chain as usize); + continue; + } + + let sum = self.addr_from_elf(sym.st_value).unwrap(); + assert!( + sum as usize >= self.load_addr as usize + && sum as usize <= self.load_end as usize + ); + return sum as *mut c::c_void; + } + } + + null_mut() + } + + /// Add the given address to the vDSO base address. + unsafe fn base_plus(&self, offset: usize) -> Option<*const c_void> { + // Check for overflow. + let _ = (self.load_addr as usize).checked_add(offset)?; + // Add the offset to the base. + Some(self.load_addr.cast::<u8>().add(offset).cast()) + } + + /// Translate an ELF-address-space address into a usable virtual address. + unsafe fn addr_from_elf(&self, elf_addr: usize) -> Option<*const c_void> { + self.base_plus(elf_addr.wrapping_add(self.pv_offset)) + } +} diff --git a/vendor/rustix/src/imp/linux_raw/vdso_wrappers.rs b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs index 80c8dbefd..487835314 100644 --- a/vendor/rustix/src/imp/linux_raw/vdso_wrappers.rs +++ b/vendor/rustix/src/backend/linux_raw/vdso_wrappers.rs @@ -49,7 +49,7 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu DynamicClockId::Dynamic(fd) => { // See `FD_TO_CLOCKID` in Linux's `clock_gettime` documentation. - use crate::imp::fd::AsRawFd; + use crate::backend::fd::AsRawFd; const CLOCKFD: i32 = 3; ((!fd.as_raw_fd() << 3) | CLOCKFD) as __kernel_clockid_t } @@ -86,10 +86,10 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu #[cfg(target_arch = "x86")] pub(super) mod x86_via_vdso { use super::{transmute, ArgReg, Relaxed, RetReg, SyscallNumber, A0, A1, A2, A3, A4, A5, R0}; - use crate::imp::arch::asm; + use crate::backend::arch::asm; #[inline] - pub(in crate::imp) unsafe fn syscall0(nr: SyscallNumber<'_>) -> RetReg<R0> { + pub(in crate::backend) unsafe fn syscall0(nr: SyscallNumber<'_>) -> RetReg<R0> { let callee = match transmute(super::SYSCALL.load(Relaxed)) { Some(callee) => callee, None => super::init_syscall(), @@ -98,7 +98,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall1<'a>( + pub(in crate::backend) unsafe fn syscall1<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, ) -> RetReg<R0> { @@ -110,7 +110,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall1_noreturn<'a>( + pub(in crate::backend) unsafe fn syscall1_noreturn<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, ) -> ! { @@ -122,7 +122,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall2<'a>( + pub(in crate::backend) unsafe fn syscall2<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, a1: ArgReg<'a, A1>, @@ -135,7 +135,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall3<'a>( + pub(in crate::backend) unsafe fn syscall3<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, a1: ArgReg<'a, A1>, @@ -149,7 +149,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall4<'a>( + pub(in crate::backend) unsafe fn syscall4<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, a1: ArgReg<'a, A1>, @@ -164,7 +164,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall5<'a>( + pub(in crate::backend) unsafe fn syscall5<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, a1: ArgReg<'a, A1>, @@ -180,7 +180,7 @@ pub(super) mod x86_via_vdso { } #[inline] - pub(in crate::imp) unsafe fn syscall6<'a>( + pub(in crate::backend) unsafe fn syscall6<'a>( nr: SyscallNumber<'a>, a0: ArgReg<'a, A0>, a1: ArgReg<'a, A1>, @@ -198,7 +198,7 @@ pub(super) mod x86_via_vdso { // With the indirect call, it isn't meaningful to do a separate // `_readonly` optimization. - pub(in crate::imp) use { + pub(in crate::backend) use { syscall0 as syscall0_readonly, syscall1 as syscall1_readonly, syscall2 as syscall2_readonly, syscall3 as syscall3_readonly, syscall4 as syscall4_readonly, syscall5 as syscall5_readonly, @@ -214,6 +214,7 @@ type ClockGettimeType = unsafe extern "C" fn(c::c_int, *mut Timespec) -> c::c_in #[cfg(target_arch = "x86")] pub(super) type SyscallType = unsafe extern "C" fn(); +/// Initialize `CLOCK_GETTIME` and return its value. fn init_clock_gettime() -> ClockGettimeType { init(); // Safety: Load the function address from static storage that we @@ -221,6 +222,7 @@ fn init_clock_gettime() -> ClockGettimeType { unsafe { transmute(CLOCK_GETTIME.load(Relaxed)) } } +/// Initialize `SYSCALL` and return its value. #[cfg(target_arch = "x86")] fn init_syscall() -> SyscallType { init(); @@ -242,7 +244,7 @@ unsafe extern "C" fn rustix_clock_gettime_via_syscall( ) -> c::c_int { match _rustix_clock_gettime_via_syscall(clockid, res) { Ok(()) => 0, - Err(e) => e.raw_os_error().wrapping_neg(), + Err(err) => err.raw_os_error().wrapping_neg(), } } diff --git a/vendor/rustix/src/const_assert.rs b/vendor/rustix/src/const_assert.rs index 8761a4a21..c1dd5498c 100644 --- a/vendor/rustix/src/const_assert.rs +++ b/vendor/rustix/src/const_assert.rs @@ -12,6 +12,7 @@ macro_rules! const_assert { } #[test] +#[allow(clippy::missing_const_for_fn)] fn test_const_assert() { const_assert!(true); } diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs index 25556304b..a0d6cdecb 100644 --- a/vendor/rustix/src/fs/abs.rs +++ b/vendor/rustix/src/fs/abs.rs @@ -1,33 +1,69 @@ //! POSIX-style filesystem functions which operate on bare paths. #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] use crate::fs::StatFs; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", - target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] -use crate::{imp, io, path}; +use { + crate::fs::StatVfs, + crate::{backend, io, path}, +}; /// `statfs`—Queries filesystem metadata. /// +/// Compared to [`statvfs`], this function often provides more information, +/// though it's less portable. +/// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/statfs.2.html #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] #[inline] pub fn statfs<P: path::Arg>(path: P) -> io::Result<StatFs> { - path.into_with_c_str(imp::fs::syscalls::statfs) + path.into_with_c_str(backend::fs::syscalls::statfs) +} + +/// `statvfs`—Queries filesystem metadata, POSIX version. +/// +/// Compared to [`statfs`], this function often provides less information, +/// but it is more portable. But even so, filesystems are very diverse and not +/// all the fields are meaningful for every filesystem. And `f_fsid` doesn't +/// seem to have a clear meaning anywhere. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/statvfs.html +/// [Linux]: https://man7.org/linux/man-pages/man2/statvfs.2.html +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +#[inline] +pub fn statvfs<P: path::Arg>(path: P) -> io::Result<StatVfs> { + path.into_with_c_str(backend::fs::syscalls::statvfs) } diff --git a/vendor/rustix/src/fs/at.rs b/vendor/rustix/src/fs/at.rs index 2ecd90324..463c247c0 100644 --- a/vendor/rustix/src/fs/at.rs +++ b/vendor/rustix/src/fs/at.rs @@ -5,8 +5,9 @@ //! //! [`cwd`]: crate::fs::cwd +use crate::fd::OwnedFd; use crate::ffi::{CStr, CString}; -#[cfg(not(target_os = "illumos"))] +#[cfg(not(any(target_os = "illumos", target_os = "solaris")))] use crate::fs::Access; #[cfg(any(target_os = "ios", target_os = "macos"))] use crate::fs::CloneFlags; @@ -15,28 +16,27 @@ use crate::fs::FileType; #[cfg(any(target_os = "android", target_os = "linux"))] use crate::fs::RenameFlags; use crate::fs::{AtFlags, Mode, OFlags, Stat, Timestamps}; -use crate::io::{self, OwnedFd}; use crate::path::SMALL_PATH_BUFFER_SIZE; #[cfg(not(target_os = "wasi"))] use crate::process::{Gid, Uid}; -use crate::{imp, path}; +use crate::{backend, io, path}; use alloc::vec::Vec; -use imp::fd::{AsFd, BorrowedFd}; -use imp::time::types::Nsecs; +use backend::fd::{AsFd, BorrowedFd}; +use backend::time::types::Nsecs; -pub use imp::fs::types::{Dev, RawMode}; +pub use backend::fs::types::{Dev, RawMode}; /// `UTIME_NOW` for use with [`utimensat`]. /// /// [`utimensat`]: crate::fs::utimensat #[cfg(not(target_os = "redox"))] -pub const UTIME_NOW: Nsecs = imp::fs::types::UTIME_NOW as Nsecs; +pub const UTIME_NOW: Nsecs = backend::fs::types::UTIME_NOW as Nsecs; /// `UTIME_OMIT` for use with [`utimensat`]. /// /// [`utimensat`]: crate::fs::utimensat #[cfg(not(target_os = "redox"))] -pub const UTIME_OMIT: Nsecs = imp::fs::types::UTIME_OMIT as Nsecs; +pub const UTIME_OMIT: Nsecs = backend::fs::types::UTIME_OMIT as Nsecs; /// `openat(dirfd, path, oflags, mode)`—Opens a file. /// @@ -59,7 +59,9 @@ pub fn openat<P: path::Arg, Fd: AsFd>( oflags: OFlags, create_mode: Mode, ) -> io::Result<OwnedFd> { - path.into_with_c_str(|path| imp::fs::syscalls::openat(dirfd.as_fd(), path, oflags, create_mode)) + path.into_with_c_str(|path| { + backend::fs::syscalls::openat(dirfd.as_fd(), path, oflags, create_mode) + }) } /// `readlinkat(fd, path)`—Reads the contents of a symlink. @@ -89,7 +91,7 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::R buffer.resize(buffer.capacity(), 0_u8); loop { - let nread = imp::fs::syscalls::readlinkat(dirfd.as_fd(), path, &mut buffer)?; + let nread = backend::fs::syscalls::readlinkat(dirfd.as_fd(), path, &mut buffer)?; let nread = nread as usize; assert!(nread <= buffer.len()); @@ -112,7 +114,7 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec<u8>) -> io::R /// [Linux]: https://man7.org/linux/man-pages/man2/mkdirat.2.html #[inline] pub fn mkdirat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> { - path.into_with_c_str(|path| imp::fs::syscalls::mkdirat(dirfd.as_fd(), path, mode)) + path.into_with_c_str(|path| backend::fs::syscalls::mkdirat(dirfd.as_fd(), path, mode)) } /// `linkat(old_dirfd, old_path, new_dirfd, new_path, flags)`—Creates a hard @@ -134,7 +136,7 @@ pub fn linkat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( ) -> io::Result<()> { old_path.into_with_c_str(|old_path| { new_path.into_with_c_str(|new_path| { - imp::fs::syscalls::linkat( + backend::fs::syscalls::linkat( old_dirfd.as_fd(), old_path, new_dirfd.as_fd(), @@ -159,7 +161,7 @@ pub fn linkat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( /// [Linux]: https://man7.org/linux/man-pages/man2/unlinkat.2.html #[inline] pub fn unlinkat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<()> { - path.into_with_c_str(|path| imp::fs::syscalls::unlinkat(dirfd.as_fd(), path, flags)) + path.into_with_c_str(|path| backend::fs::syscalls::unlinkat(dirfd.as_fd(), path, flags)) } /// `renameat(old_dirfd, old_path, new_dirfd, new_path)`—Renames a file or @@ -180,7 +182,12 @@ pub fn renameat<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( ) -> io::Result<()> { old_path.into_with_c_str(|old_path| { new_path.into_with_c_str(|new_path| { - imp::fs::syscalls::renameat(old_dirfd.as_fd(), old_path, new_dirfd.as_fd(), new_path) + backend::fs::syscalls::renameat( + old_dirfd.as_fd(), + old_path, + new_dirfd.as_fd(), + new_path, + ) }) }) } @@ -204,7 +211,7 @@ pub fn renameat_with<P: path::Arg, Q: path::Arg, PFd: AsFd, QFd: AsFd>( ) -> io::Result<()> { old_path.into_with_c_str(|old_path| { new_path.into_with_c_str(|new_path| { - imp::fs::syscalls::renameat2( + backend::fs::syscalls::renameat2( old_dirfd.as_fd(), old_path, new_dirfd.as_fd(), @@ -231,7 +238,7 @@ pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>( ) -> io::Result<()> { old_path.into_with_c_str(|old_path| { new_path.into_with_c_str(|new_path| { - imp::fs::syscalls::symlinkat(old_path, new_dirfd.as_fd(), new_path) + backend::fs::syscalls::symlinkat(old_path, new_dirfd.as_fd(), new_path) }) }) } @@ -252,7 +259,7 @@ pub fn symlinkat<P: path::Arg, Q: path::Arg, Fd: AsFd>( #[inline] #[doc(alias = "fstatat")] pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io::Result<Stat> { - path.into_with_c_str(|path| imp::fs::syscalls::statat(dirfd.as_fd(), path, flags)) + path.into_with_c_str(|path| backend::fs::syscalls::statat(dirfd.as_fd(), path, flags)) } /// `faccessat(dirfd, path, access, flags)`—Tests permissions for a file or @@ -264,7 +271,7 @@ pub fn statat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, flags: AtFlags) -> io: /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html /// [Linux]: https://man7.org/linux/man-pages/man2/faccessat.2.html -#[cfg(not(target_os = "illumos"))] +#[cfg(not(any(target_os = "illumos", target_os = "solaris")))] #[inline] #[doc(alias = "faccessat")] pub fn accessat<P: path::Arg, Fd: AsFd>( @@ -273,7 +280,7 @@ pub fn accessat<P: path::Arg, Fd: AsFd>( access: Access, flags: AtFlags, ) -> io::Result<()> { - path.into_with_c_str(|path| imp::fs::syscalls::accessat(dirfd.as_fd(), path, access, flags)) + path.into_with_c_str(|path| backend::fs::syscalls::accessat(dirfd.as_fd(), path, access, flags)) } /// `utimensat(dirfd, path, times, flags)`—Sets file or directory timestamps. @@ -291,7 +298,7 @@ pub fn utimensat<P: path::Arg, Fd: AsFd>( times: &Timestamps, flags: AtFlags, ) -> io::Result<()> { - path.into_with_c_str(|path| imp::fs::syscalls::utimensat(dirfd.as_fd(), path, times, flags)) + path.into_with_c_str(|path| backend::fs::syscalls::utimensat(dirfd.as_fd(), path, times, flags)) } /// `fchmodat(dirfd, path, mode, 0)`—Sets file or directory permissions. @@ -312,7 +319,7 @@ pub fn utimensat<P: path::Arg, Fd: AsFd>( #[inline] #[doc(alias = "fchmodat")] pub fn chmodat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> { - path.into_with_c_str(|path| imp::fs::syscalls::chmodat(dirfd.as_fd(), path, mode)) + path.into_with_c_str(|path| backend::fs::syscalls::chmodat(dirfd.as_fd(), path, mode)) } /// `fclonefileat(src, dst_dir, dst, flags)`—Efficiently copies between files. @@ -330,7 +337,7 @@ pub fn fclonefileat<Fd: AsFd, DstFd: AsFd, P: path::Arg>( flags: CloneFlags, ) -> io::Result<()> { dst.into_with_c_str(|dst| { - imp::fs::syscalls::fclonefileat(src.as_fd(), dst_dir.as_fd(), &dst, flags) + backend::fs::syscalls::fclonefileat(src.as_fd(), dst_dir.as_fd(), dst, flags) }) } @@ -352,7 +359,7 @@ pub fn mknodat<P: path::Arg, Fd: AsFd>( dev: Dev, ) -> io::Result<()> { path.into_with_c_str(|path| { - imp::fs::syscalls::mknodat(dirfd.as_fd(), path, file_type, mode, dev) + backend::fs::syscalls::mknodat(dirfd.as_fd(), path, file_type, mode, dev) }) } @@ -375,6 +382,6 @@ pub fn chownat<P: path::Arg, Fd: AsFd>( flags: AtFlags, ) -> io::Result<()> { path.into_with_c_str(|path| { - imp::fs::syscalls::chownat(dirfd.as_fd(), path, owner, group, flags) + backend::fs::syscalls::chownat(dirfd.as_fd(), path, owner, group, flags) }) } diff --git a/vendor/rustix/src/fs/constants.rs b/vendor/rustix/src/fs/constants.rs index b6893a92e..11b53fd2a 100644 --- a/vendor/rustix/src/fs/constants.rs +++ b/vendor/rustix/src/fs/constants.rs @@ -1,19 +1,20 @@ //! Filesystem API constants, translated into `bitflags` constants. -use crate::imp; +use crate::backend; -pub use imp::fs::types::{Access, FdFlags, Mode, OFlags}; +pub use crate::io::FdFlags; +pub use backend::fs::types::{Access, Mode, OFlags}; #[cfg(not(target_os = "redox"))] -pub use imp::fs::types::AtFlags; +pub use backend::fs::types::AtFlags; #[cfg(any(target_os = "ios", target_os = "macos"))] -pub use imp::fs::types::{CloneFlags, CopyfileFlags}; +pub use backend::fs::types::{CloneFlags, CopyfileFlags}; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use imp::fs::types::{RenameFlags, ResolveFlags}; +pub use backend::fs::types::{RenameFlags, ResolveFlags}; #[cfg(not(target_os = "redox"))] -pub use imp::fs::types::Dev; +pub use backend::fs::types::Dev; -pub use imp::time::types::{Nsecs, Secs, Timespec}; +pub use backend::time::types::{Nsecs, Secs, Timespec}; diff --git a/vendor/rustix/src/fs/copy_file_range.rs b/vendor/rustix/src/fs/copy_file_range.rs index b12190472..4b118b30e 100644 --- a/vendor/rustix/src/fs/copy_file_range.rs +++ b/vendor/rustix/src/fs/copy_file_range.rs @@ -1,5 +1,5 @@ -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; /// `copy_file_range(fd_in, off_in, fd_out, off_out, len, 0)`—Copies data /// from one file to another. @@ -16,5 +16,5 @@ pub fn copy_file_range<InFd: AsFd, OutFd: AsFd>( off_out: Option<&mut u64>, len: u64, ) -> io::Result<u64> { - imp::fs::syscalls::copy_file_range(fd_in.as_fd(), off_in, fd_out.as_fd(), off_out, len) + backend::fs::syscalls::copy_file_range(fd_in.as_fd(), off_in, fd_out.as_fd(), off_out, len) } diff --git a/vendor/rustix/src/fs/cwd.rs b/vendor/rustix/src/fs/cwd.rs index 95f97f85d..d0455cd6c 100644 --- a/vendor/rustix/src/fs/cwd.rs +++ b/vendor/rustix/src/fs/cwd.rs @@ -7,8 +7,8 @@ #![allow(unsafe_code)] -use crate::imp; -use imp::fd::{BorrowedFd, RawFd}; +use crate::backend; +use backend::fd::{BorrowedFd, RawFd}; /// `AT_FDCWD`—Returns a handle representing the current working directory. /// @@ -24,7 +24,7 @@ use imp::fd::{BorrowedFd, RawFd}; #[inline] #[doc(alias = "AT_FDCWD")] pub const fn cwd() -> BorrowedFd<'static> { - let at_fdcwd = imp::io::types::AT_FDCWD as RawFd; + let at_fdcwd = backend::io::types::AT_FDCWD as RawFd; // Safety: `AT_FDCWD` is a reserved value that is never dynamically // allocated, so it'll remain valid for the duration of `'static`. diff --git a/vendor/rustix/src/fs/dir.rs b/vendor/rustix/src/fs/dir.rs index f9d7ff871..94bc0a3ee 100644 --- a/vendor/rustix/src/fs/dir.rs +++ b/vendor/rustix/src/fs/dir.rs @@ -1,5 +1,5 @@ //! `Dir` and `Entry`. -use crate::imp; +use crate::backend; -pub use imp::fs::dir::{Dir, DirEntry}; +pub use backend::fs::dir::{Dir, DirEntry}; diff --git a/vendor/rustix/src/fs/fadvise.rs b/vendor/rustix/src/fs/fadvise.rs index ead3ad9a3..5bc3a588a 100644 --- a/vendor/rustix/src/fs/fadvise.rs +++ b/vendor/rustix/src/fs/fadvise.rs @@ -1,7 +1,7 @@ -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; -pub use imp::fs::types::Advice; +pub use backend::fs::types::Advice; /// `posix_fadvise(fd, offset, len, advice)`—Declares an expected access /// pattern for a file. @@ -15,5 +15,5 @@ pub use imp::fs::types::Advice; #[inline] #[doc(alias = "posix_fadvise")] pub fn fadvise<Fd: AsFd>(fd: Fd, offset: u64, len: u64, advice: Advice) -> io::Result<()> { - imp::fs::syscalls::fadvise(fd.as_fd(), offset, len, advice) + backend::fs::syscalls::fadvise(fd.as_fd(), offset, len, advice) } diff --git a/vendor/rustix/src/fs/fcntl.rs b/vendor/rustix/src/fs/fcntl.rs index 7f89873b5..80ac858c0 100644 --- a/vendor/rustix/src/fs/fcntl.rs +++ b/vendor/rustix/src/fs/fcntl.rs @@ -3,38 +3,16 @@ //! a type-safe API, rustix makes them all separate functions so that they //! can have dedicated static type signatures. -use crate::imp; -use crate::io::{self, OwnedFd}; -use imp::fd::{AsFd, RawFd}; -use imp::fs::types::{FdFlags, OFlags}; +use crate::{backend, io}; +use backend::fd::AsFd; +use backend::fs::types::OFlags; -/// `fcntl(fd, F_GETFD)`—Returns a file descriptor's flags. -/// -/// # References -/// - [POSIX] -/// - [Linux] -/// -/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html -/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html -#[inline] -#[doc(alias = "F_GETFD")] -pub fn fcntl_getfd<Fd: AsFd>(fd: Fd) -> io::Result<FdFlags> { - imp::fs::syscalls::fcntl_getfd(fd.as_fd()) -} - -/// `fcntl(fd, F_SETFD, flags)`—Sets a file descriptor's flags. -/// -/// # References -/// - [POSIX] -/// - [Linux] -/// -/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html -/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html -#[inline] -#[doc(alias = "F_SETFD")] -pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> { - imp::fs::syscalls::fcntl_setfd(fd.as_fd(), flags) -} +// These `fcntl` functions like in the `io` module because they're not specific +// to files, directories, or memfd objects. We re-export them here in the `fs` +// module because the other the `fcntl` functions are here. +#[cfg(not(target_os = "wasi"))] +pub use crate::io::fcntl_dupfd_cloexec; +pub use crate::io::{fcntl_getfd, fcntl_setfd}; /// `fcntl(fd, F_GETFL)`—Returns a file descriptor's access mode and status. /// @@ -47,7 +25,7 @@ pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> { #[inline] #[doc(alias = "F_GETFL")] pub fn fcntl_getfl<Fd: AsFd>(fd: Fd) -> io::Result<OFlags> { - imp::fs::syscalls::fcntl_getfl(fd.as_fd()) + backend::fs::syscalls::fcntl_getfl(fd.as_fd()) } /// `fcntl(fd, F_SETFL, flags)`—Sets a file descriptor's status. @@ -61,7 +39,7 @@ pub fn fcntl_getfl<Fd: AsFd>(fd: Fd) -> io::Result<OFlags> { #[inline] #[doc(alias = "F_SETFL")] pub fn fcntl_setfl<Fd: AsFd>(fd: Fd, flags: OFlags) -> io::Result<()> { - imp::fs::syscalls::fcntl_setfl(fd.as_fd(), flags) + backend::fs::syscalls::fcntl_setfl(fd.as_fd(), flags) } /// `fcntl(fd, F_GET_SEALS)` @@ -79,7 +57,7 @@ pub fn fcntl_setfl<Fd: AsFd>(fd: Fd, flags: OFlags) -> io::Result<()> { #[inline] #[doc(alias = "F_GET_SEALS")] pub fn fcntl_get_seals<Fd: AsFd>(fd: Fd) -> io::Result<SealFlags> { - imp::fs::syscalls::fcntl_get_seals(fd.as_fd()) + backend::fs::syscalls::fcntl_get_seals(fd.as_fd()) } #[cfg(any( @@ -88,7 +66,7 @@ pub fn fcntl_get_seals<Fd: AsFd>(fd: Fd) -> io::Result<SealFlags> { target_os = "fuchsia", target_os = "linux", ))] -pub use imp::fs::types::SealFlags; +pub use backend::fs::types::SealFlags; /// `fcntl(fd, F_ADD_SEALS)` /// @@ -105,27 +83,5 @@ pub use imp::fs::types::SealFlags; #[inline] #[doc(alias = "F_ADD_SEALS")] pub fn fcntl_add_seals<Fd: AsFd>(fd: Fd, seals: SealFlags) -> io::Result<()> { - imp::fs::syscalls::fcntl_add_seals(fd.as_fd(), seals) -} - -/// `fcntl(fd, F_DUPFD_CLOEXEC)`—Creates a new `OwnedFd` instance, with value -/// at least `min`, that has `O_CLOEXEC` set and that shares the same -/// underlying [file description] as `fd`. -/// -/// POSIX guarantees that `F_DUPFD_CLOEXEC` will use the lowest unused file -/// descriptor which is at least `min`, however it is not safe in general to -/// rely on this, as file descriptors may be unexpectedly allocated on other -/// threads or in libraries. -/// -/// # References -/// - [POSIX] -/// - [Linux] -/// -/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html -/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html -#[cfg(not(target_os = "wasi"))] -#[inline] -#[doc(alias = "F_DUPFD_CLOEXEC")] -pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> { - imp::fs::syscalls::fcntl_dupfd_cloexec(fd.as_fd(), min) + backend::fs::syscalls::fcntl_add_seals(fd.as_fd(), seals) } diff --git a/vendor/rustix/src/fs/fcntl_darwin.rs b/vendor/rustix/src/fs/fcntl_darwin.rs index 17d8f844f..6d624ee47 100644 --- a/vendor/rustix/src/fs/fcntl_darwin.rs +++ b/vendor/rustix/src/fs/fcntl_darwin.rs @@ -1,5 +1,5 @@ -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; /// `fcntl(fd, F_RDADVISE, radvisory { offset, len })` /// @@ -9,7 +9,7 @@ use imp::fd::AsFd; /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html #[inline] pub fn fcntl_rdadvise<Fd: AsFd>(fd: Fd, offset: u64, len: u64) -> io::Result<()> { - imp::fs::syscalls::fcntl_rdadvise(fd.as_fd(), offset, len) + backend::fs::syscalls::fcntl_rdadvise(fd.as_fd(), offset, len) } /// `fcntl(fd, F_FULLFSYNC)` @@ -20,5 +20,5 @@ pub fn fcntl_rdadvise<Fd: AsFd>(fd: Fd, offset: u64, len: u64) -> io::Result<()> /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html #[inline] pub fn fcntl_fullfsync<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::fs::syscalls::fcntl_fullfsync(fd.as_fd()) + backend::fs::syscalls::fcntl_fullfsync(fd.as_fd()) } diff --git a/vendor/rustix/src/fs/fcopyfile.rs b/vendor/rustix/src/fs/fcopyfile.rs index c5b00ce10..d8931733f 100644 --- a/vendor/rustix/src/fs/fcopyfile.rs +++ b/vendor/rustix/src/fs/fcopyfile.rs @@ -1,9 +1,9 @@ use crate::fs::CopyfileFlags; -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; /// `copyfile_state_t` -pub use imp::fs::types::copyfile_state_t; +pub use backend::fs::types::copyfile_state_t; /// `fcopyfile(from, to, state, flags)` /// @@ -23,7 +23,7 @@ pub unsafe fn fcopyfile<FromFd: AsFd, ToFd: AsFd>( state: copyfile_state_t, flags: CopyfileFlags, ) -> io::Result<()> { - imp::fs::syscalls::fcopyfile(from.as_fd(), to.as_fd(), state, flags) + backend::fs::syscalls::fcopyfile(from.as_fd(), to.as_fd(), state, flags) } /// `copyfile_state_alloc()` @@ -34,7 +34,7 @@ pub unsafe fn fcopyfile<FromFd: AsFd, ToFd: AsFd>( /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html #[inline] pub fn copyfile_state_alloc() -> io::Result<copyfile_state_t> { - imp::fs::syscalls::copyfile_state_alloc() + backend::fs::syscalls::copyfile_state_alloc() } /// `copyfile_state_free(state)` @@ -50,7 +50,7 @@ pub fn copyfile_state_alloc() -> io::Result<copyfile_state_t> { /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html #[inline] pub unsafe fn copyfile_state_free(state: copyfile_state_t) -> io::Result<()> { - imp::fs::syscalls::copyfile_state_free(state) + backend::fs::syscalls::copyfile_state_free(state) } /// `copyfile_state_get(state, COPYFILE_STATE_COPIED)` @@ -66,7 +66,7 @@ pub unsafe fn copyfile_state_free(state: copyfile_state_t) -> io::Result<()> { /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/fcopyfile.3.html #[inline] pub unsafe fn copyfile_state_get_copied(state: copyfile_state_t) -> io::Result<u64> { - imp::fs::syscalls::copyfile_state_get_copied(state) + backend::fs::syscalls::copyfile_state_get_copied(state) } /// `copyfile_state_get(state, flags, dst)` @@ -86,5 +86,5 @@ pub unsafe fn copyfile_state_get( flag: u32, dst: *mut core::ffi::c_void, ) -> io::Result<()> { - imp::fs::syscalls::copyfile_state_get(state, flag, dst) + backend::fs::syscalls::copyfile_state_get(state, flag, dst) } diff --git a/vendor/rustix/src/fs/fd.rs b/vendor/rustix/src/fs/fd.rs index b41579fb8..6bea89547 100644 --- a/vendor/rustix/src/fs/fd.rs +++ b/vendor/rustix/src/fs/fd.rs @@ -5,33 +5,46 @@ use crate::fs::Mode; use crate::io::SeekFrom; #[cfg(not(target_os = "wasi"))] use crate::process::{Gid, Uid}; -use crate::{imp, io}; -use imp::fd::{AsFd, BorrowedFd}; +use crate::{backend, io}; +use backend::fd::{AsFd, BorrowedFd}; -#[cfg(not(target_os = "wasi"))] -pub use imp::fs::types::FlockOperation; +#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] +pub use backend::fs::types::FlockOperation; #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::fs::types::FallocateFlags; +pub use backend::fs::types::FallocateFlags; -pub use imp::fs::types::Stat; +pub use backend::fs::types::Stat; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +pub use backend::fs::types::StatFs; + +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] -pub use imp::fs::types::StatFs; +pub use backend::fs::types::{StatVfs, StatVfsMountFlags}; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use imp::fs::types::FsWord; +pub use backend::fs::types::FsWord; /// Timestamps used by [`utimensat`] and [`futimens`]. /// @@ -55,7 +68,7 @@ pub struct Timestamps { /// /// [the `fstatfs` man page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION #[cfg(any(target_os = "android", target_os = "linux"))] -pub const PROC_SUPER_MAGIC: FsWord = imp::fs::types::PROC_SUPER_MAGIC; +pub const PROC_SUPER_MAGIC: FsWord = backend::fs::types::PROC_SUPER_MAGIC; /// The filesystem magic number for NFS. /// @@ -63,7 +76,7 @@ pub const PROC_SUPER_MAGIC: FsWord = imp::fs::types::PROC_SUPER_MAGIC; /// /// [the `fstatfs` man page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION #[cfg(any(target_os = "android", target_os = "linux"))] -pub const NFS_SUPER_MAGIC: FsWord = imp::fs::types::NFS_SUPER_MAGIC; +pub const NFS_SUPER_MAGIC: FsWord = backend::fs::types::NFS_SUPER_MAGIC; /// `lseek(fd, offset, whence)`—Repositions a file descriptor within a file. /// @@ -75,7 +88,7 @@ pub const NFS_SUPER_MAGIC: FsWord = imp::fs::types::NFS_SUPER_MAGIC; /// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html #[inline] pub fn seek<Fd: AsFd>(fd: Fd, pos: SeekFrom) -> io::Result<u64> { - imp::fs::syscalls::seek(fd.as_fd(), pos) + backend::fs::syscalls::seek(fd.as_fd(), pos) } /// `lseek(fd, 0, SEEK_CUR)`—Returns the current position within a file. @@ -92,7 +105,7 @@ pub fn seek<Fd: AsFd>(fd: Fd, pos: SeekFrom) -> io::Result<u64> { /// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html #[inline] pub fn tell<Fd: AsFd>(fd: Fd) -> io::Result<u64> { - imp::fs::syscalls::tell(fd.as_fd()) + backend::fs::syscalls::tell(fd.as_fd()) } /// `fchmod(fd)`—Sets open file or directory permissions. @@ -109,7 +122,7 @@ pub fn tell<Fd: AsFd>(fd: Fd) -> io::Result<u64> { #[cfg(not(target_os = "wasi"))] #[inline] pub fn fchmod<Fd: AsFd>(fd: Fd, mode: Mode) -> io::Result<()> { - imp::fs::syscalls::fchmod(fd.as_fd(), mode) + backend::fs::syscalls::fchmod(fd.as_fd(), mode) } /// `fchown(fd)`—Sets open file or directory ownership. @@ -123,7 +136,7 @@ pub fn fchmod<Fd: AsFd>(fd: Fd, mode: Mode) -> io::Result<()> { #[cfg(not(target_os = "wasi"))] #[inline] pub fn fchown<Fd: AsFd>(fd: Fd, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { - imp::fs::syscalls::fchown(fd.as_fd(), owner, group) + backend::fs::syscalls::fchown(fd.as_fd(), owner, group) } /// `fstat(fd)`—Queries metadata for an open file or directory. @@ -141,24 +154,55 @@ pub fn fchown<Fd: AsFd>(fd: Fd, owner: Option<Uid>, group: Option<Gid>) -> io::R /// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode #[inline] pub fn fstat<Fd: AsFd>(fd: Fd) -> io::Result<Stat> { - imp::fs::syscalls::fstat(fd.as_fd()) + backend::fs::syscalls::fstat(fd.as_fd()) } /// `fstatfs(fd)`—Queries filesystem statistics for an open file or directory. /// +/// Compared to [`fstatvfs`], this function often provides more information, +/// though it's less portable. +/// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/fstatfs.2.html #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", -)))] // not implemented in libc for netbsd yet +)))] #[inline] pub fn fstatfs<Fd: AsFd>(fd: Fd) -> io::Result<StatFs> { - imp::fs::syscalls::fstatfs(fd.as_fd()) + backend::fs::syscalls::fstatfs(fd.as_fd()) +} + +/// `fstatvfs(fd)`—Queries filesystem statistics for an open file or +/// directory, POSIX version. +/// +/// Compared to [`fstatfs`], this function often provides less information, +/// but it is more portable. But even so, filesystems are very diverse and not +/// all the fields are meaningful for every filesystem. And `f_fsid` doesn't +/// seem to have a clear meaning anywhere. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstatvfs.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fstatvfs.2.html +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +#[inline] +pub fn fstatvfs<Fd: AsFd>(fd: Fd) -> io::Result<StatVfs> { + backend::fs::syscalls::fstatvfs(fd.as_fd()) } /// `futimens(fd, times)`—Sets timestamps for an open file or directory. @@ -171,7 +215,7 @@ pub fn fstatfs<Fd: AsFd>(fd: Fd) -> io::Result<StatFs> { /// [Linux]: https://man7.org/linux/man-pages/man2/utimensat.2.html #[inline] pub fn futimens<Fd: AsFd>(fd: Fd, times: &Timestamps) -> io::Result<()> { - imp::fs::syscalls::futimens(fd.as_fd(), times) + backend::fs::syscalls::futimens(fd.as_fd(), times) } /// `fallocate(fd, mode, offset, len)`—Adjusts file allocation. @@ -190,16 +234,18 @@ pub fn futimens<Fd: AsFd>(fd: Fd, times: &Timestamps) -> io::Result<()> { /// [Linux `fallocate`]: https://man7.org/linux/man-pages/man2/fallocate.2.html /// [Linux `posix_fallocate`]: https://man7.org/linux/man-pages/man3/posix_fallocate.3.html #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] // not implemented in libc for netbsd yet #[inline] #[doc(alias = "posix_fallocate")] pub fn fallocate<Fd: AsFd>(fd: Fd, mode: FallocateFlags, offset: u64, len: u64) -> io::Result<()> { - imp::fs::syscalls::fallocate(fd.as_fd(), mode, offset, len) + backend::fs::syscalls::fallocate(fd.as_fd(), mode, offset, len) } /// `fcntl(fd, F_GETFL) & O_ACCMODE` @@ -214,7 +260,7 @@ pub fn is_file_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> { } pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { - let mode = imp::fs::syscalls::fcntl_getfl(fd)?; + let mode = backend::fs::syscalls::fcntl_getfl(fd)?; // Check for `O_PATH`. #[cfg(any( @@ -252,7 +298,7 @@ pub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool) /// [`fcntl_fullfsync`]: https://docs.rs/rustix/*/x86_64-apple-darwin/rustix/fs/fn.fcntl_fullfsync.html #[inline] pub fn fsync<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::fs::syscalls::fsync(fd.as_fd()) + backend::fs::syscalls::fsync(fd.as_fd()) } /// `fdatasync(fd)`—Ensures that file data is written to the underlying @@ -266,13 +312,14 @@ pub fn fsync<Fd: AsFd>(fd: Fd) -> io::Result<()> { /// [Linux]: https://man7.org/linux/man-pages/man2/fdatasync.2.html #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", )))] #[inline] pub fn fdatasync<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::fs::syscalls::fdatasync(fd.as_fd()) + backend::fs::syscalls::fdatasync(fd.as_fd()) } /// `ftruncate(fd, length)`—Sets the length of a file. @@ -285,7 +332,7 @@ pub fn fdatasync<Fd: AsFd>(fd: Fd) -> io::Result<()> { /// [Linux]: https://man7.org/linux/man-pages/man2/ftruncate.2.html #[inline] pub fn ftruncate<Fd: AsFd>(fd: Fd, length: u64) -> io::Result<()> { - imp::fs::syscalls::ftruncate(fd.as_fd(), length) + backend::fs::syscalls::ftruncate(fd.as_fd(), length) } /// `flock(fd, operation)`—Acquire or release an advisory lock on an open file. @@ -294,8 +341,8 @@ pub fn ftruncate<Fd: AsFd>(fd: Fd, length: u64) -> io::Result<()> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/flock.2.html -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] #[inline] pub fn flock<Fd: AsFd>(fd: Fd, operation: FlockOperation) -> io::Result<()> { - imp::fs::syscalls::flock(fd.as_fd(), operation) + backend::fs::syscalls::flock(fd.as_fd(), operation) } diff --git a/vendor/rustix/src/fs/file_type.rs b/vendor/rustix/src/fs/file_type.rs index 75935c794..cf8fc1d38 100644 --- a/vendor/rustix/src/fs/file_type.rs +++ b/vendor/rustix/src/fs/file_type.rs @@ -1,4 +1,4 @@ -use crate::imp; +use crate::backend; /// `S_IF*` constants. -pub use imp::fs::types::FileType; +pub use backend::fs::types::FileType; diff --git a/vendor/rustix/src/fs/getpath.rs b/vendor/rustix/src/fs/getpath.rs index bc40890d1..8e14ff2f2 100644 --- a/vendor/rustix/src/fs/getpath.rs +++ b/vendor/rustix/src/fs/getpath.rs @@ -1,6 +1,6 @@ use crate::ffi::CString; -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; /// `fcntl(fd, F_GETPATH)` /// @@ -10,5 +10,5 @@ use imp::fd::AsFd; /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html #[inline] pub fn getpath<Fd: AsFd>(fd: Fd) -> io::Result<CString> { - imp::fs::syscalls::getpath(fd.as_fd()) + backend::fs::syscalls::getpath(fd.as_fd()) } diff --git a/vendor/rustix/src/fs/makedev.rs b/vendor/rustix/src/fs/makedev.rs index 75cc42540..5793058ff 100644 --- a/vendor/rustix/src/fs/makedev.rs +++ b/vendor/rustix/src/fs/makedev.rs @@ -1,5 +1,5 @@ +use crate::backend; use crate::fs::Dev; -use crate::imp; /// `makedev(maj, min)` /// @@ -9,7 +9,7 @@ use crate::imp; /// [Linux]: https://man7.org/linux/man-pages/man3/makedev.3.html #[inline] pub fn makedev(maj: u32, min: u32) -> Dev { - imp::fs::makedev::makedev(maj, min) + backend::fs::makedev::makedev(maj, min) } /// `minor(dev)` @@ -20,7 +20,7 @@ pub fn makedev(maj: u32, min: u32) -> Dev { /// [Linux]: https://man7.org/linux/man-pages/man3/minor.3.html #[inline] pub fn minor(dev: Dev) -> u32 { - imp::fs::makedev::minor(dev) + backend::fs::makedev::minor(dev) } /// `major(dev)` @@ -31,5 +31,5 @@ pub fn minor(dev: Dev) -> u32 { /// [Linux]: https://man7.org/linux/man-pages/man3/major.3.html #[inline] pub fn major(dev: Dev) -> u32 { - imp::fs::makedev::major(dev) + backend::fs::makedev::major(dev) } diff --git a/vendor/rustix/src/fs/memfd_create.rs b/vendor/rustix/src/fs/memfd_create.rs index 74b432739..dad964777 100644 --- a/vendor/rustix/src/fs/memfd_create.rs +++ b/vendor/rustix/src/fs/memfd_create.rs @@ -1,7 +1,7 @@ -use crate::io::{self, OwnedFd}; -use crate::{imp, path}; +use crate::fd::OwnedFd; +use crate::{backend, io, path}; -pub use imp::fs::types::MemfdFlags; +pub use backend::fs::types::MemfdFlags; /// `memfd_create(path, flags)` /// @@ -11,5 +11,5 @@ pub use imp::fs::types::MemfdFlags; /// [Linux]: https://man7.org/linux/man-pages/man2/memfd_create.2.html #[inline] pub fn memfd_create<P: path::Arg>(path: P, flags: MemfdFlags) -> io::Result<OwnedFd> { - path.into_with_c_str(|path| imp::fs::syscalls::memfd_create(path, flags)) + path.into_with_c_str(|path| backend::fs::syscalls::memfd_create(path, flags)) } diff --git a/vendor/rustix/src/fs/mod.rs b/vendor/rustix/src/fs/mod.rs index 49b9c3b51..fa7f93aec 100644 --- a/vendor/rustix/src/fs/mod.rs +++ b/vendor/rustix/src/fs/mod.rs @@ -1,9 +1,7 @@ //! Filesystem operations. -#[cfg(feature = "fs")] mod abs; #[cfg(not(target_os = "redox"))] -#[cfg(any(feature = "fs", feature = "procfs"))] mod at; mod constants; #[cfg(any(target_os = "android", target_os = "linux"))] @@ -11,16 +9,17 @@ mod copy_file_range; #[cfg(not(target_os = "redox"))] mod cwd; #[cfg(not(target_os = "redox"))] -#[cfg(any(feature = "fs", feature = "procfs"))] mod dir; #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] mod fadvise; pub(crate) mod fcntl; @@ -35,19 +34,20 @@ mod getpath; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] mod makedev; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] mod memfd_create; #[cfg(any(target_os = "android", target_os = "linux"))] -#[cfg(feature = "fs")] mod openat2; #[cfg(target_os = "linux")] mod sendfile; @@ -55,18 +55,25 @@ mod sendfile; mod statx; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] -#[cfg(feature = "fs")] pub use abs::statfs; -#[cfg(not(any(target_os = "illumos", target_os = "redox")))] -#[cfg(feature = "fs")] +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +pub use abs::statvfs; +#[cfg(not(any(target_os = "illumos", target_os = "redox", target_os = "solaris")))] pub use at::accessat; #[cfg(any(target_os = "ios", target_os = "macos"))] -#[cfg(feature = "fs")] pub use at::fclonefileat; #[cfg(not(any( target_os = "ios", @@ -74,16 +81,12 @@ pub use at::fclonefileat; target_os = "redox", target_os = "wasi", )))] -#[cfg(feature = "fs")] pub use at::mknodat; #[cfg(any(target_os = "android", target_os = "linux"))] -#[cfg(feature = "fs")] pub use at::renameat_with; #[cfg(not(any(target_os = "redox", target_os = "wasi")))] -#[cfg(feature = "fs")] pub use at::{chmodat, chownat}; #[cfg(not(target_os = "redox"))] -#[cfg(any(feature = "fs", feature = "procfs"))] pub use at::{ linkat, mkdirat, openat, readlinkat, renameat, statat, symlinkat, unlinkat, utimensat, RawMode, UTIME_NOW, UTIME_OMIT, @@ -105,16 +108,17 @@ pub use copy_file_range::copy_file_range; #[cfg(not(target_os = "redox"))] pub use cwd::cwd; #[cfg(not(target_os = "redox"))] -#[cfg(any(feature = "fs", feature = "procfs"))] pub use dir::{Dir, DirEntry}; #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use fadvise::{fadvise, Advice}; #[cfg(not(target_os = "wasi"))] @@ -136,30 +140,44 @@ pub use fcopyfile::{ }; #[cfg(not(any( target_os = "dragonfly", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", )))] pub use fd::fdatasync; #[cfg(not(any( + target_os = "aix", target_os = "dragonfly", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use fd::{fallocate, FallocateFlags}; #[cfg(not(target_os = "wasi"))] -pub use fd::{fchmod, fchown, flock, FlockOperation}; +pub use fd::{fchmod, fchown}; +#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] +pub use fd::{flock, FlockOperation}; pub use fd::{fstat, fsync, ftruncate, futimens, is_file_read_write, seek, tell, Stat, Timestamps}; #[cfg(not(any( + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] -// not implemented in libc for netbsd yet pub use fd::{fstatfs, StatFs}; +#[cfg(not(any( + target_os = "haiku", + target_os = "illumos", + target_os = "redox", + target_os = "solaris", + target_os = "wasi", +)))] +pub use fd::{fstatvfs, StatVfs, StatVfsMountFlags}; #[cfg(any(target_os = "android", target_os = "linux"))] pub use fd::{FsWord, NFS_SUPER_MAGIC, PROC_SUPER_MAGIC}; pub use file_type::FileType; @@ -168,19 +186,20 @@ pub use getpath::getpath; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] pub use makedev::{major, makedev, minor}; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] pub use memfd_create::{memfd_create, MemfdFlags}; #[cfg(any(target_os = "android", target_os = "linux"))] -#[cfg(feature = "fs")] pub use openat2::openat2; #[cfg(target_os = "linux")] pub use sendfile::sendfile; diff --git a/vendor/rustix/src/fs/openat2.rs b/vendor/rustix/src/fs/openat2.rs index d6f77357b..4918e0034 100644 --- a/vendor/rustix/src/fs/openat2.rs +++ b/vendor/rustix/src/fs/openat2.rs @@ -1,7 +1,7 @@ -use crate::io::{self, OwnedFd}; -use crate::{imp, path}; -use imp::fd::AsFd; -use imp::fs::types::{Mode, OFlags, ResolveFlags}; +use crate::fd::OwnedFd; +use crate::{backend, io, path}; +use backend::fd::AsFd; +use backend::fs::types::{Mode, OFlags, ResolveFlags}; /// `openat2(dirfd, path, OpenHow { oflags, mode, resolve }, sizeof(OpenHow))` /// @@ -18,6 +18,6 @@ pub fn openat2<Fd: AsFd, P: path::Arg>( resolve: ResolveFlags, ) -> io::Result<OwnedFd> { path.into_with_c_str(|path| { - imp::fs::syscalls::openat2(dirfd.as_fd(), path, oflags, mode, resolve) + backend::fs::syscalls::openat2(dirfd.as_fd(), path, oflags, mode, resolve) }) } diff --git a/vendor/rustix/src/fs/sendfile.rs b/vendor/rustix/src/fs/sendfile.rs index a4d8c24d4..472ad37b2 100644 --- a/vendor/rustix/src/fs/sendfile.rs +++ b/vendor/rustix/src/fs/sendfile.rs @@ -1,5 +1,5 @@ -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; /// `sendfile(out_fd, in_fd, offset, count)` /// @@ -15,5 +15,5 @@ pub fn sendfile<OutFd: AsFd, InFd: AsFd>( offset: Option<&mut u64>, count: usize, ) -> io::Result<usize> { - imp::fs::syscalls::sendfile(out_fd.as_fd(), in_fd.as_fd(), offset, count) + backend::fs::syscalls::sendfile(out_fd.as_fd(), in_fd.as_fd(), offset, count) } diff --git a/vendor/rustix/src/fs/statx.rs b/vendor/rustix/src/fs/statx.rs index fa1d36779..383f109ce 100644 --- a/vendor/rustix/src/fs/statx.rs +++ b/vendor/rustix/src/fs/statx.rs @@ -3,10 +3,10 @@ use crate::fd::{AsFd, BorrowedFd}; use crate::ffi::CStr; use crate::fs::AtFlags; -use crate::{imp, io, path}; +use crate::{backend, io, path}; use core::sync::atomic::{AtomicU8, Ordering}; -pub use imp::fs::types::{Statx, StatxFlags, StatxTimestamp}; +pub use backend::fs::types::{Statx, StatxFlags, StatxTimestamp}; /// `statx(dirfd, path, flags, mask, statxbuf)` /// @@ -47,7 +47,7 @@ fn _statx( match STATX_STATE.load(Ordering::Relaxed) { 0 => statx_init(dirfd, path, flags, mask), 1 => Err(io::Errno::NOSYS), - _ => imp::fs::syscalls::statx(dirfd, path, flags, mask), + _ => backend::fs::syscalls::statx(dirfd, path, flags, mask), } } @@ -58,7 +58,7 @@ fn statx_init( flags: AtFlags, mask: StatxFlags, ) -> io::Result<Statx> { - match imp::fs::syscalls::statx(dirfd, path, flags, mask) { + match backend::fs::syscalls::statx(dirfd, path, flags, mask) { Err(io::Errno::NOSYS) => statx_error_nosys(), Err(io::Errno::PERM) => statx_error_perm(), result => { @@ -82,7 +82,7 @@ fn statx_error_perm() -> io::Result<Statx> { // Some old versions of Docker have `statx` fail with `PERM` when it isn't // recognized. Check whether `statx` really is available, and if so, fail // with `PERM`, and if not, treat it like `NOSYS`. - if imp::fs::syscalls::is_statx_available() { + if backend::fs::syscalls::is_statx_available() { STATX_STATE.store(2, Ordering::Relaxed); Err(io::Errno::PERM) } else { diff --git a/vendor/rustix/src/imp/linux_raw/net/ext.rs b/vendor/rustix/src/imp/linux_raw/net/ext.rs deleted file mode 100644 index 8556c9d90..000000000 --- a/vendor/rustix/src/imp/linux_raw/net/ext.rs +++ /dev/null @@ -1,64 +0,0 @@ -#![allow(unsafe_code)] - -use super::super::c; - -#[inline] -pub(crate) const fn in_addr_s_addr(addr: c::in_addr) -> u32 { - addr.s_addr -} - -#[inline] -pub(crate) const fn in_addr_new(s_addr: u32) -> c::in_addr { - c::in_addr { s_addr } -} - -#[cfg(not(feature = "std"))] -#[inline] -pub(crate) const fn in6_addr_s6_addr(addr: c::in6_addr) -> [u8; 16] { - // Safety: `in6_addr` is `repr(C)` and contains plain integer data. - unsafe { addr.in6_u.u6_addr8 } -} - -// TODO: With Rust 1.55, we can use the above `in6_addr_s6_addr` definition -// that uses a const-fn union access instead of doing a transmute. -#[cfg(not(not(feature = "std")))] -#[inline] -pub(crate) fn in6_addr_s6_addr(addr: c::in6_addr) -> [u8; 16] { - // Safety: `in6_addr` is `repr(C)` and contains plain integer data. - unsafe { core::mem::transmute(addr) } -} - -#[inline] -pub(crate) const fn in6_addr_new(s6_addr: [u8; 16]) -> c::in6_addr { - c::in6_addr { - in6_u: linux_raw_sys::general::in6_addr__bindgen_ty_1 { u6_addr8: s6_addr }, - } -} - -#[inline] -pub(crate) const fn sockaddr_in6_sin6_scope_id(addr: c::sockaddr_in6) -> u32 { - addr.sin6_scope_id -} - -#[cfg(not(feature = "std"))] -#[inline] -pub(crate) fn sockaddr_in6_sin6_scope_id_mut(addr: &mut c::sockaddr_in6) -> &mut u32 { - &mut addr.sin6_scope_id -} - -#[inline] -pub(crate) const fn sockaddr_in6_new( - sin6_family: c::sa_family_t, - sin6_port: u16, - sin6_flowinfo: u32, - sin6_addr: c::in6_addr, - sin6_scope_id: u32, -) -> c::sockaddr_in6 { - c::sockaddr_in6 { - sin6_family, - sin6_port, - sin6_flowinfo, - sin6_addr, - sin6_scope_id, - } -} diff --git a/vendor/rustix/src/imp/linux_raw/param/auxv.rs b/vendor/rustix/src/imp/linux_raw/param/auxv.rs deleted file mode 100644 index beed8613c..000000000 --- a/vendor/rustix/src/imp/linux_raw/param/auxv.rs +++ /dev/null @@ -1,203 +0,0 @@ -//! Linux auxv support. -//! -//! # Safety -//! -//! This uses raw pointers to locate and read the kernel-provided auxv array. -#![allow(unsafe_code)] - -use super::super::c; -use super::super::elf::{Elf_Ehdr, Elf_Phdr}; -#[cfg(feature = "param")] -use crate::ffi::CStr; -use core::mem::size_of; -use core::ptr::null; -#[cfg(feature = "runtime")] -use core::slice; -use linux_raw_sys::general::{ - AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, AT_PHNUM, - AT_SYSINFO_EHDR, -}; - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn page_size() -> usize { - auxv().page_size -} - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn clock_ticks_per_second() -> u64 { - auxv().clock_ticks_per_second as u64 -} - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn linux_hwcap() -> (usize, usize) { - let auxv = auxv(); - (auxv.hwcap, auxv.hwcap2) -} - -#[cfg(feature = "param")] -#[inline] -pub(crate) fn linux_execfn() -> &'static CStr { - let execfn = auxv().execfn; - - // Safety: We assume the `AT_EXECFN` value provided by the kernel is a - // valid pointer to a valid NUL-terminated array of bytes. - unsafe { CStr::from_ptr(execfn.cast()) } -} - -#[cfg(feature = "runtime")] -#[inline] -pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) { - let auxv = auxv(); - (auxv.phdr.cast(), auxv.phnum) -} - -#[cfg(feature = "runtime")] -#[inline] -pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] { - let auxv = auxv(); - - // Safety: We assume the `AT_PHDR` and `AT_PHNUM` values provided by the - // kernel form a valid slice. - unsafe { slice::from_raw_parts(auxv.phdr, auxv.phnum) } -} - -#[inline] -pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr { - auxv().sysinfo_ehdr -} - -#[inline] -fn auxv() -> &'static Auxv { - // Safety: `AUXV` is initialized from the `.init_array`, and we never - // mutate it thereafter, so it's effectively initialized read-only in all - // other code. - unsafe { - // Assert that the initialization has happened. On glibc and musl, this - // is handled automatically by `.init_array` functions. Otherwise, - // `rustix::process::init` must be called explicitly. - debug_assert_ne!(AUXV.page_size, 0); - - &AUXV - } -} - -/// A struct for holding fields obtained from the kernel-provided auxv array. -struct Auxv { - page_size: usize, - clock_ticks_per_second: usize, - hwcap: usize, - hwcap2: usize, - sysinfo_ehdr: *const Elf_Ehdr, - phdr: *const Elf_Phdr, - phnum: usize, - execfn: *const c::c_char, -} - -/// Data obtained from the kernel-provided auxv array. This is initialized at -/// program startup below. -static mut AUXV: Auxv = Auxv { - page_size: 0, - clock_ticks_per_second: 0, - hwcap: 0, - hwcap2: 0, - sysinfo_ehdr: null(), - phdr: null(), - phnum: 0, - execfn: null(), -}; - -/// GLIBC passes argc, argv, and envp to functions in .init_array, as a -/// non-standard extension. Use priority 99 so that we run before any -/// normal user-defined constructor functions. -#[cfg(all(target_env = "gnu", not(target_vendor = "mustang")))] -#[used] -#[link_section = ".init_array.00099"] -static INIT_ARRAY: unsafe extern "C" fn(c::c_int, *mut *mut u8, *mut *mut u8) = { - unsafe extern "C" fn function(_argc: c::c_int, _argv: *mut *mut u8, envp: *mut *mut u8) { - init_from_envp(envp); - } - function -}; - -/// For musl, assume that `__environ` is available and points to the original -/// environment from the kernel, so we can find the auxv array in memory after -/// it. Use priority 99 so that we run before any normal user-defined -/// constructor functions. -/// -/// <https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib---environ.html> -#[cfg(all(target_env = "musl", not(target_vendor = "mustang")))] -#[used] -#[link_section = ".init_array.00099"] -static INIT_ARRAY: unsafe extern "C" fn() = { - unsafe extern "C" fn function() { - extern "C" { - static __environ: *mut *mut u8; - } - - init_from_envp(__environ) - } - function -}; - -/// On mustang or any non-musl non-glibic platform where we don't know that we -/// have `.init_array`, we export a function to be called during -/// initialization, and passed a pointer to the original environment variable -/// block set up by the OS. -#[cfg(any( - target_vendor = "mustang", - not(any(target_env = "gnu", target_env = "musl")), -))] -#[inline] -pub(crate) unsafe fn init(envp: *mut *mut u8) { - init_from_envp(envp); -} - -/// # Safety -/// -/// This must be passed a pointer to the environment variable buffer -/// provided by the kernel, which is followed in memory by the auxv array. -unsafe fn init_from_envp(mut envp: *mut *mut u8) { - while !(*envp).is_null() { - envp = envp.add(1); - } - init_from_auxp(envp.add(1).cast()) -} - -/// # Safety -/// -/// This must be passed a pointer to the auxv array provided by the kernel. -unsafe fn init_from_auxp(mut auxp: *const Elf_auxv_t) { - loop { - let Elf_auxv_t { a_type, a_val } = *auxp; - match a_type as _ { - AT_PAGESZ => AUXV.page_size = a_val as usize, - AT_CLKTCK => AUXV.clock_ticks_per_second = a_val as usize, - AT_HWCAP => AUXV.hwcap = a_val as usize, - AT_HWCAP2 => AUXV.hwcap2 = a_val as usize, - AT_SYSINFO_EHDR => AUXV.sysinfo_ehdr = a_val.cast(), - AT_PHDR => AUXV.phdr = a_val.cast(), - AT_PHNUM => AUXV.phnum = a_val as usize, - AT_PHENT => assert_eq!(a_val as usize, size_of::<Elf_Phdr>()), - AT_EXECFN => AUXV.execfn = a_val.cast(), - AT_NULL => break, - _ => (), - } - auxp = auxp.add(1); - } -} - -// ELF ABI - -#[repr(C)] -#[derive(Copy, Clone)] -struct Elf_auxv_t { - a_type: usize, - - // Some of the values in the auxv array are pointers, so we make `a_val` a - // pointer, in order to preserve their provenance. For the values which are - // integers, we cast this to `usize`. - a_val: *const (), -} diff --git a/vendor/rustix/src/imp/linux_raw/param/mod.rs b/vendor/rustix/src/imp/linux_raw/param/mod.rs deleted file mode 100644 index 2cb2fe78a..000000000 --- a/vendor/rustix/src/imp/linux_raw/param/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub(crate) mod auxv; diff --git a/vendor/rustix/src/imp/linux_raw/vdso.rs b/vendor/rustix/src/imp/linux_raw/vdso.rs deleted file mode 100644 index bda0a4773..000000000 --- a/vendor/rustix/src/imp/linux_raw/vdso.rs +++ /dev/null @@ -1,435 +0,0 @@ -//! Parse the Linux vDSO. -//! -//! The following code is transliterated from -//! tools/testing/selftests/vDSO/parse_vdso.c in Linux 5.11, which is licensed -//! with Creative Commons Zero License, version 1.0, -//! available at <https://creativecommons.org/publicdomain/zero/1.0/legalcode> -//! -//! # Safety -//! -//! Parsing the vDSO involves a lot of raw pointer manipulation. This -//! implementation follows Linux's reference implementation, and adds several -//! additional safety checks. -#![allow(unsafe_code)] - -use super::c; -use super::elf::*; -use super::mm::syscalls::madvise; -use super::mm::types::Advice; -use crate::ffi::CStr; -use crate::io; -use core::ffi::c_void; -use core::mem::{align_of, size_of}; -use core::ptr::{null, null_mut}; - -pub(super) struct Vdso { - // Load information - load_addr: *const Elf_Ehdr, - load_end: *const c_void, // the end of the `PT_LOAD` segment - pv_offset: usize, // recorded paddr - recorded vaddr - - // Symbol table - symtab: *const Elf_Sym, - symstrings: *const u8, - bucket: *const u32, - chain: *const u32, - nbucket: u32, - //nchain: u32, - - // Version table - versym: *const u16, - verdef: *const Elf_Verdef, -} - -// Straight from the ELF specification. -fn elf_hash(name: &CStr) -> u32 { - let mut h: u32 = 0; - for b in name.to_bytes() { - h = (h << 4).wrapping_add(u32::from(*b)); - let g = h & 0xf000_0000; - if g != 0 { - h ^= g >> 24; - } - h &= !g; - } - h -} - -/// Cast `value` to a pointer type, doing some checks for validity. -fn make_pointer<T>(value: *const c_void) -> Option<*const T> { - if value.is_null() - || (value as usize).checked_add(size_of::<T>()).is_none() - || (value as usize) % align_of::<T>() != 0 - { - return None; - } - - Some(value.cast()) -} - -/// Create a `Vdso` value by parsing the vDSO at the given address. -/// -/// # Safety -/// -/// `base` must be a valid pointer to an ELF image in memory. -unsafe fn init_from_sysinfo_ehdr(base: *const Elf_Ehdr) -> Option<Vdso> { - // Check that `base` is a valid pointer to the kernel-provided vDSO. - let hdr = check_vdso_base(base)?; - - let mut vdso = Vdso { - load_addr: base, - load_end: base.cast(), - pv_offset: 0, - symtab: null(), - symstrings: null(), - bucket: null(), - chain: null(), - nbucket: 0, - //nchain: 0, - versym: null(), - verdef: null(), - }; - - let pt = make_pointer::<Elf_Phdr>(vdso.base_plus(hdr.e_phoff)?)?; - let mut dyn_: *const Elf_Dyn = null(); - let mut num_dyn = 0; - - // We need two things from the segment table: the load offset - // and the dynamic table. - let mut found_vaddr = false; - for i in 0..hdr.e_phnum { - let phdr = &*pt.add(i as usize); - if phdr.p_flags & PF_W != 0 { - // Don't trust any vDSO that claims to be loading writable - // segments into memory. - return None; - } - if phdr.p_type == PT_LOAD && !found_vaddr { - // The segment should be readable and executable, because it - // contains the symbol table and the function bodies. - if phdr.p_flags & (PF_R | PF_X) != (PF_R | PF_X) { - return None; - } - found_vaddr = true; - vdso.load_end = vdso.base_plus(phdr.p_offset.checked_add(phdr.p_memsz)?)?; - vdso.pv_offset = phdr.p_offset.wrapping_sub(phdr.p_vaddr); - } else if phdr.p_type == PT_DYNAMIC { - // If `p_offset` is zero, it's more likely that we're looking at memory - // that has been zeroed than that the kernel has somehow aliased the - // `Ehdr` and the `Elf_Dyn` array. - if phdr.p_offset < size_of::<Elf_Ehdr>() { - return None; - } - - dyn_ = make_pointer::<Elf_Dyn>(vdso.base_plus(phdr.p_offset)?)?; - num_dyn = phdr.p_memsz / size_of::<Elf_Dyn>(); - } else if phdr.p_type == PT_INTERP || phdr.p_type == PT_GNU_RELRO { - // Don't trust any ELF image that has an "interpreter" or that uses - // RELRO, which is likely to be a user ELF image rather and not the - // kernel vDSO. - return None; - } - } - - if !found_vaddr || dyn_.is_null() { - return None; // Failed - } - - // Fish out the useful bits of the dynamic table. - let mut hash: *const u32 = null(); - vdso.symstrings = null(); - vdso.symtab = null(); - vdso.versym = null(); - vdso.verdef = null(); - let mut i = 0; - loop { - if i == num_dyn { - return None; - } - let d = &*dyn_.add(i); - match d.d_tag { - DT_STRTAB => { - vdso.symstrings = make_pointer::<u8>(vdso.addr_from_elf(d.d_val)?)?; - } - DT_SYMTAB => { - vdso.symtab = make_pointer::<Elf_Sym>(vdso.addr_from_elf(d.d_val)?)?; - } - DT_HASH => { - hash = make_pointer::<u32>(vdso.addr_from_elf(d.d_val)?)?; - } - DT_VERSYM => { - vdso.versym = make_pointer::<u16>(vdso.addr_from_elf(d.d_val)?)?; - } - DT_VERDEF => { - vdso.verdef = make_pointer::<Elf_Verdef>(vdso.addr_from_elf(d.d_val)?)?; - } - DT_SYMENT => { - if d.d_val != size_of::<Elf_Sym>() { - return None; // Failed - } - } - DT_NULL => break, - _ => {} - } - i = i.checked_add(1)?; - } - if vdso.symstrings.is_null() || vdso.symtab.is_null() || hash.is_null() { - return None; // Failed - } - - if vdso.verdef.is_null() { - vdso.versym = null(); - } - - // Parse the hash table header. - vdso.nbucket = *hash.add(0); - //vdso.nchain = *hash.add(1); - vdso.bucket = hash.add(2); - vdso.chain = hash.add(vdso.nbucket as usize + 2); - - // That's all we need. - Some(vdso) -} - -/// Check that `base` is a valid pointer to the kernel-provided vDSO. -/// -/// `base` is some value we got from a `AT_SYSINFO_EHDR` aux record somewhere, -/// which hopefully holds the value of the kernel-provided vDSO in memory. Do a -/// series of checks to be as sure as we can that it's safe to use. -unsafe fn check_vdso_base<'vdso>(base: *const Elf_Ehdr) -> Option<&'vdso Elf_Ehdr> { - // In theory, we could check that we're not attempting to parse our own ELF - // image, as an additional check. However, older Linux toolchains don't - // support this, and Rust's `#[linkage = "extern_weak"]` isn't stable yet, - // so just disable this for now. - /* - { - extern "C" { - static __ehdr_start: c::c_void; - } - - let ehdr_start: *const c::c_void = &__ehdr_start; - if base == ehdr_start { - return None; - } - } - */ - - let hdr = &*make_pointer::<Elf_Ehdr>(base.cast())?; - - // Check that the vDSO is page-aligned and appropriately mapped. We call - // this after `make_pointer` so that we don't do a syscall if there's no - // chance the pointer is valid. - madvise(base as *mut c_void, size_of::<Elf_Ehdr>(), Advice::Normal).ok()?; - - if hdr.e_ident[..SELFMAG] != ELFMAG { - return None; // Wrong ELF magic - } - if hdr.e_ident[EI_CLASS] != ELFCLASS { - return None; // Wrong ELF class - } - if hdr.e_ident[EI_DATA] != ELFDATA { - return None; // Wrong ELF data - } - if !matches!(hdr.e_ident[EI_OSABI], ELFOSABI_SYSV | ELFOSABI_LINUX) { - return None; // Unrecognized ELF OS ABI - } - if hdr.e_ident[EI_ABIVERSION] != ELFABIVERSION { - return None; // Unrecognized ELF ABI version - } - if hdr.e_type != ET_DYN { - return None; // Wrong ELF type - } - // Verify that the `e_machine` matches the architecture we're running as. - // This helps catch cases where we're running under qemu. - if hdr.e_machine != EM_CURRENT { - return None; // Wrong machine type - } - - // If ELF is extended, we'll need to adjust. - if hdr.e_ident[EI_VERSION] != EV_CURRENT - || hdr.e_ehsize as usize != size_of::<Elf_Ehdr>() - || hdr.e_phentsize as usize != size_of::<Elf_Phdr>() - { - return None; - } - // We don't currently support extra-large numbers of segments. - if hdr.e_phnum == PN_XNUM { - return None; - } - - // If `e_phoff` is zero, it's more likely that we're looking at memory that - // has been zeroed than that the kernel has somehow aliased the `Ehdr` and - // the `Phdr`. - if hdr.e_phoff < size_of::<Elf_Ehdr>() { - return None; - } - - // Check that the vDSO is not writable, since that would indicate that this - // isn't the kernel vDSO. Here we're just using `clock_getres` just as an - // arbitrary system call which writes to a buffer and fails with `EFAULT` - // if the buffer is not writable. - { - use super::conv::ret; - use super::time::types::ClockId; - if ret(syscall!(__NR_clock_getres, ClockId::Monotonic, base)) != Err(io::Errno::FAULT) { - // We can't gracefully fail here because we would seem to have just - // mutated some unknown memory. - #[cfg(feature = "std")] - { - std::process::abort(); - } - #[cfg(all(not(feature = "std"), feature = "rustc-dep-of-std"))] - { - core::intrinsics::abort(); - } - } - } - - Some(hdr) -} - -impl Vdso { - /// Parse the vDSO. - /// - /// Returns None if the vDSO can't be located or if it doesn't conform - /// to our expectations. - #[inline] - pub(super) fn new() -> Option<Self> { - init_from_auxv() - } - - /// Check the version for a symbol. - /// - /// # Safety - /// - /// The raw pointers inside `self` must be valid. - unsafe fn match_version(&self, mut ver: u16, name: &CStr, hash: u32) -> bool { - // This is a helper function to check if the version indexed by - // ver matches name (which hashes to hash). - // - // The version definition table is a mess, and I don't know how - // to do this in better than linear time without allocating memory - // to build an index. I also don't know why the table has - // variable size entries in the first place. - // - // For added fun, I can't find a comprehensible specification of how - // to parse all the weird flags in the table. - // - // So I just parse the whole table every time. - - // First step: find the version definition - ver &= 0x7fff; // Apparently bit 15 means "hidden" - let mut def = self.verdef; - loop { - if (*def).vd_version != VER_DEF_CURRENT { - return false; // Failed - } - - if ((*def).vd_flags & VER_FLG_BASE) == 0 && ((*def).vd_ndx & 0x7fff) == ver { - break; - } - - if (*def).vd_next == 0 { - return false; // No definition. - } - - def = def - .cast::<u8>() - .add((*def).vd_next as usize) - .cast::<Elf_Verdef>(); - } - - // Now figure out whether it matches. - let aux = &*(def.cast::<u8>()) - .add((*def).vd_aux as usize) - .cast::<Elf_Verdaux>(); - (*def).vd_hash == hash - && (name == CStr::from_ptr(self.symstrings.add(aux.vda_name as usize).cast())) - } - - /// Look up a symbol in the vDSO. - pub(super) fn sym(&self, version: &CStr, name: &CStr) -> *mut c::c_void { - let ver_hash = elf_hash(version); - let name_hash = elf_hash(name); - - // Safety: The pointers in `self` must be valid. - unsafe { - let mut chain = *self.bucket.add((name_hash % self.nbucket) as usize); - - while chain != STN_UNDEF { - let sym = &*self.symtab.add(chain as usize); - - // Check for a defined global or weak function w/ right name. - // - // The reference parser in Linux's parse_vdso.c requires - // symbols to have type `STT_FUNC`, but on powerpc64, the vDSO - // uses `STT_NOTYPE`, so allow that too. - if (ELF_ST_TYPE(sym.st_info) != STT_FUNC && - ELF_ST_TYPE(sym.st_info) != STT_NOTYPE) - || (ELF_ST_BIND(sym.st_info) != STB_GLOBAL - && ELF_ST_BIND(sym.st_info) != STB_WEAK) - || sym.st_shndx == SHN_UNDEF - || sym.st_shndx == SHN_ABS - || ELF_ST_VISIBILITY(sym.st_other) != STV_DEFAULT - || (name != CStr::from_ptr(self.symstrings.add(sym.st_name as usize).cast())) - // Check symbol version. - || (!self.versym.is_null() - && !self.match_version(*self.versym.add(chain as usize), version, ver_hash)) - { - chain = *self.chain.add(chain as usize); - continue; - } - - let sum = self.addr_from_elf(sym.st_value).unwrap(); - assert!( - sum as usize >= self.load_addr as usize - && sum as usize <= self.load_end as usize - ); - return sum as *mut c::c_void; - } - } - - null_mut() - } - - /// Add the given address to the vDSO base address. - unsafe fn base_plus(&self, offset: usize) -> Option<*const c_void> { - // Check for overflow. - let _ = (self.load_addr as usize).checked_add(offset)?; - // Add the offset to the base. - Some(self.load_addr.cast::<u8>().add(offset).cast()) - } - - /// Translate an ELF-address-space address into a usable virtual address. - unsafe fn addr_from_elf(&self, elf_addr: usize) -> Option<*const c_void> { - self.base_plus(elf_addr.wrapping_add(self.pv_offset)) - } -} - -// Find the `AT_SYSINFO_EHDR` in auxv records in memory. We have our own code -// for reading the auxv records in memory, so we don't currently use this. -// -// # Safety -// -// `elf_auxv` must point to a valid array of AUXV records terminated by an -// `AT_NULL` record. -/* -unsafe fn init_from_auxv(elf_auxv: *const Elf_auxv_t) -> Option<Vdso> { - let mut i = 0; - while (*elf_auxv.add(i)).a_type != AT_NULL { - if (*elf_auxv.add(i)).a_type == AT_SYSINFO_EHDR { - return init_from_sysinfo_ehdr((*elf_auxv.add(i)).a_val); - } - i += 1; - } - - None -} -*/ - -/// Find the vDSO image by following the `AT_SYSINFO_EHDR` auxv record pointer. -fn init_from_auxv() -> Option<Vdso> { - // Safety: `sysinfo_ehdr` does extensive checks to ensure that the value - // we get really is an `AT_SYSINFO_EHDR` value from the kernel. - unsafe { init_from_sysinfo_ehdr(super::param::auxv::sysinfo_ehdr()) } -} diff --git a/vendor/rustix/src/io/close.rs b/vendor/rustix/src/io/close.rs index 2116f53bd..b286d2368 100644 --- a/vendor/rustix/src/io/close.rs +++ b/vendor/rustix/src/io/close.rs @@ -5,8 +5,8 @@ //! Operating on raw file descriptors is unsafe. #![allow(unsafe_code)] -use crate::imp; -use imp::fd::RawFd; +use crate::backend; +use backend::fd::RawFd; /// `close(raw_fd)`—Closes a `RawFd` directly. /// @@ -37,5 +37,5 @@ use imp::fd::RawFd; /// not valid after the call. #[inline] pub unsafe fn close(raw_fd: RawFd) { - imp::io::syscalls::close(raw_fd) + backend::io::syscalls::close(raw_fd) } diff --git a/vendor/rustix/src/io/dup.rs b/vendor/rustix/src/io/dup.rs index ffa0401f2..8da6aa091 100644 --- a/vendor/rustix/src/io/dup.rs +++ b/vendor/rustix/src/io/dup.rs @@ -1,11 +1,11 @@ //! Functions which duplicate file descriptors. -use crate::imp; -use crate::io::{self, OwnedFd}; -use imp::fd::AsFd; +use crate::fd::OwnedFd; +use crate::{backend, io}; +use backend::fd::AsFd; #[cfg(not(target_os = "wasi"))] -pub use imp::io::types::DupFlags; +pub use backend::io::types::DupFlags; /// `dup(fd)`—Creates a new `OwnedFd` instance that shares the same /// underlying [file description] as `fd`. @@ -23,14 +23,14 @@ pub use imp::io::types::DupFlags; /// - [Apple] /// /// [file description]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_258 -/// [`fcntl_dupfd_cloexec`]: crate::fs::fcntl_dupfd_cloexec +/// [`fcntl_dupfd_cloexec`]: crate::io::fcntl_dupfd_cloexec /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup.html /// [Linux]: https://man7.org/linux/man-pages/man2/dup.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/dup.2.html #[cfg(not(target_os = "wasi"))] #[inline] pub fn dup<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> { - imp::io::syscalls::dup(fd.as_fd()) + backend::io::syscalls::dup(fd.as_fd()) } /// `dup2(fd, new)`—Changes the [file description] of a file descriptor. @@ -50,14 +50,14 @@ pub fn dup<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> { /// - [Apple] /// /// [file description]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_258 -/// [`fcntl_dupfd_cloexec`]: crate::fs::fcntl_dupfd_cloexec +/// [`fcntl_dupfd_cloexec`]: crate::io::fcntl_dupfd_cloexec /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html /// [Linux]: https://man7.org/linux/man-pages/man2/dup2.2.html /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/dup2.2.html #[cfg(not(target_os = "wasi"))] #[inline] pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> io::Result<()> { - imp::io::syscalls::dup2(fd.as_fd(), new) + backend::io::syscalls::dup2(fd.as_fd(), new) } /// `dup3(fd, new, flags)`—Changes the [file description] of a file @@ -73,8 +73,8 @@ pub fn dup2<Fd: AsFd>(fd: Fd, new: &mut OwnedFd) -> io::Result<()> { /// /// [file description]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_258 /// [Linux]: https://man7.org/linux/man-pages/man2/dup3.2.html -#[cfg(not(target_os = "wasi"))] +#[cfg(not(any(target_os = "aix", target_os = "wasi")))] #[inline] pub fn dup3<Fd: AsFd>(fd: Fd, new: &mut OwnedFd, flags: DupFlags) -> io::Result<()> { - imp::io::syscalls::dup3(fd.as_fd(), new, flags) + backend::io::syscalls::dup3(fd.as_fd(), new, flags) } diff --git a/vendor/rustix/src/io/errno.rs b/vendor/rustix/src/io/errno.rs index 84ced6a37..f39573797 100644 --- a/vendor/rustix/src/io/errno.rs +++ b/vendor/rustix/src/io/errno.rs @@ -4,7 +4,7 @@ //! enum because we may not know about all of the host's error values //! and we don't want unrecognized values to create UB. -use crate::imp; +use crate::backend; use core::{fmt, result}; #[cfg(feature = "std")] use std::error; @@ -25,7 +25,7 @@ pub type Result<T> = result::Result<T, Errno>; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html /// [Linux]: https://man7.org/linux/man-pages/man3/errno.3.html -pub use imp::io::errno::Errno; +pub use backend::io::errno::Errno; impl Errno { /// Shorthand for `std::io::Error::from(self).kind()`. diff --git a/vendor/rustix/src/io/eventfd.rs b/vendor/rustix/src/io/eventfd.rs index 53e9d11f0..22ffc627c 100644 --- a/vendor/rustix/src/io/eventfd.rs +++ b/vendor/rustix/src/io/eventfd.rs @@ -1,7 +1,7 @@ -use crate::imp; -use crate::io::{self, OwnedFd}; +use crate::fd::OwnedFd; +use crate::{backend, io}; -pub use imp::io::types::EventfdFlags; +pub use backend::io::types::EventfdFlags; /// `eventfd(initval, flags)`—Creates a file descriptor for event /// notification. @@ -12,5 +12,5 @@ pub use imp::io::types::EventfdFlags; /// [Linux]: https://man7.org/linux/man-pages/man2/eventfd.2.html #[inline] pub fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> { - imp::io::syscalls::eventfd(initval, flags) + backend::io::syscalls::eventfd(initval, flags) } diff --git a/vendor/rustix/src/io/fcntl.rs b/vendor/rustix/src/io/fcntl.rs new file mode 100644 index 000000000..109e4540b --- /dev/null +++ b/vendor/rustix/src/io/fcntl.rs @@ -0,0 +1,86 @@ +//! The Unix `fcntl` function is effectively lots of different functions +//! hidden behind a single dynamic dispatch interface. In order to provide +//! a type-safe API, rustix makes them all separate functions so that they +//! can have dedicated static type signatures. +//! +//! `fcntl` functions which are not specific to files or directories live +//! in the [`io`] module instead. +//! +//! [`io`]: crate::io + +use crate::backend; +use crate::io; +use backend::fd::{AsFd, OwnedFd, RawFd}; + +pub use backend::io::types::FdFlags; + +/// `fcntl(fd, F_GETFD)`—Returns a file descriptor's flags. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[inline] +#[doc(alias = "F_GETFD")] +pub fn fcntl_getfd<Fd: AsFd>(fd: Fd) -> io::Result<FdFlags> { + backend::io::syscalls::fcntl_getfd(fd.as_fd()) +} + +/// `fcntl(fd, F_SETFD, flags)`—Sets a file descriptor's flags. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[inline] +#[doc(alias = "F_SETFD")] +pub fn fcntl_setfd<Fd: AsFd>(fd: Fd, flags: FdFlags) -> io::Result<()> { + backend::io::syscalls::fcntl_setfd(fd.as_fd(), flags) +} + +/// `fcntl(fd, F_DUPFD_CLOEXEC)`—Creates a new `OwnedFd` instance, with value +/// at least `min`, that has `O_CLOEXEC` set and that shares the same +/// underlying [file description] as `fd`. +/// +/// POSIX guarantees that `F_DUPFD_CLOEXEC` will use the lowest unused file +/// descriptor which is at least `min`, however it is not safe in general to +/// rely on this, as file descriptors may be unexpectedly allocated on other +/// threads or in libraries. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[cfg(not(any(target_os = "wasi", target_os = "espidf")))] +#[inline] +#[doc(alias = "F_DUPFD_CLOEXEC")] +pub fn fcntl_dupfd_cloexec<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> { + backend::io::syscalls::fcntl_dupfd_cloexec(fd.as_fd(), min) +} + +/// `fcntl(fd, F_DUPFD)`—Creates a new `OwnedFd` instance, with value at least +/// `min`, that shares the same underlying [file description] as `fd`. +/// +/// POSIX guarantees that `F_DUPFD` will use the lowest unused file descriptor +/// which is at least `min`, however it is not safe in general to rely on this, +/// as file descriptors may be unexpectedly allocated on other threads or in +/// libraries. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html +/// [Linux]: https://man7.org/linux/man-pages/man2/fcntl.2.html +#[cfg(target_os = "espidf")] +#[inline] +#[doc(alias = "F_DUPFD")] +pub fn fcntl_dupfd<Fd: AsFd>(fd: Fd, min: RawFd) -> io::Result<OwnedFd> { + backend::io::syscalls::fcntl_dupfd(fd.as_fd(), min) +} diff --git a/vendor/rustix/src/io/fd/owned.rs b/vendor/rustix/src/io/fd/owned.rs index d99b6a0f9..c2972b073 100644 --- a/vendor/rustix/src/io/fd/owned.rs +++ b/vendor/rustix/src/io/fd/owned.rs @@ -92,14 +92,14 @@ impl OwnedFd { // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This // is a POSIX flag that was added to Linux in 2.6.24. #[cfg(not(target_os = "espidf"))] - let fd = crate::fs::fcntl_dupfd_cloexec(self, 0)?; + let fd = crate::io::fcntl_dupfd_cloexec(self, 0)?; // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics // will never be supported, as this is a bare metal framework with // no capabilities for multi-process execution. While F_DUPFD is also // not supported yet, it might be (currently it returns ENOSYS). #[cfg(target_os = "espidf")] - let fd = crate::fs::fcntl_dupfd(self)?; + let fd = crate::io::fcntl_dupfd(self)?; Ok(fd.into()) } diff --git a/vendor/rustix/src/io/fd/raw.rs b/vendor/rustix/src/io/fd/raw.rs index 44322d9fe..a522c9794 100644 --- a/vendor/rustix/src/io/fd/raw.rs +++ b/vendor/rustix/src/io/fd/raw.rs @@ -7,7 +7,7 @@ #![cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #![allow(unsafe_code)] -use crate::imp::c; +use crate::backend::c; /// Raw file descriptors. #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] diff --git a/vendor/rustix/src/io/ioctl.rs b/vendor/rustix/src/io/ioctl.rs index be47e7958..01ded2e12 100644 --- a/vendor/rustix/src/io/ioctl.rs +++ b/vendor/rustix/src/io/ioctl.rs @@ -3,8 +3,8 @@ //! a type-safe API, rustix makes them all separate functions so that they //! can have dedicated static type signatures. -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; /// `ioctl(fd, TIOCEXCL)`—Enables exclusive mode on a terminal. /// @@ -12,11 +12,11 @@ use imp::fd::AsFd; /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))] #[inline] #[doc(alias = "TIOCEXCL")] pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::io::syscalls::ioctl_tiocexcl(fd.as_fd()) + backend::io::syscalls::ioctl_tiocexcl(fd.as_fd()) } /// `ioctl(fd, TIOCNXCL)`—Disables exclusive mode on a terminal. @@ -25,11 +25,11 @@ pub fn ioctl_tiocexcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man4/tty_ioctl.4.html -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))] #[inline] #[doc(alias = "TIOCNXCL")] pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::io::syscalls::ioctl_tiocnxcl(fd.as_fd()) + backend::io::syscalls::ioctl_tiocnxcl(fd.as_fd()) } /// `ioctl(fd, FIOCLEX)`—Set the close-on-exec flag. @@ -47,7 +47,7 @@ pub fn ioctl_tiocnxcl<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[doc(alias = "FIOCLEX")] #[doc(alias = "FD_CLOEXEC")] pub fn ioctl_fioclex<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::io::syscalls::ioctl_fioclex(fd.as_fd()) + backend::io::syscalls::ioctl_fioclex(fd.as_fd()) } /// `ioctl(fd, FIONBIO, &value)`—Enables or disables non-blocking mode. @@ -61,7 +61,7 @@ pub fn ioctl_fioclex<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[inline] #[doc(alias = "FIONBIO")] pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { - imp::io::syscalls::ioctl_fionbio(fd.as_fd(), value) + backend::io::syscalls::ioctl_fionbio(fd.as_fd(), value) } /// `ioctl(fd, FIONREAD)`—Returns the number of bytes ready to be read. @@ -79,7 +79,7 @@ pub fn ioctl_fionbio<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { #[inline] #[doc(alias = "FIONREAD")] pub fn ioctl_fionread<Fd: AsFd>(fd: Fd) -> io::Result<u64> { - imp::io::syscalls::ioctl_fionread(fd.as_fd()) + backend::io::syscalls::ioctl_fionread(fd.as_fd()) } /// `ioctl(fd, BLKSSZGET)`—Returns the logical block size of a block device. @@ -87,7 +87,7 @@ pub fn ioctl_fionread<Fd: AsFd>(fd: Fd) -> io::Result<u64> { #[inline] #[doc(alias = "BLKSSZGET")] pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - imp::io::syscalls::ioctl_blksszget(fd.as_fd()) + backend::io::syscalls::ioctl_blksszget(fd.as_fd()) } /// `ioctl(fd, BLKPBSZGET)`—Returns the physical block size of a block device. @@ -95,5 +95,5 @@ pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "BLKPBSZGET")] pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - imp::io::syscalls::ioctl_blkpbszget(fd.as_fd()) + backend::io::syscalls::ioctl_blkpbszget(fd.as_fd()) } diff --git a/vendor/rustix/src/io/is_read_write.rs b/vendor/rustix/src/io/is_read_write.rs index c6f189090..74007e7f9 100644 --- a/vendor/rustix/src/io/is_read_write.rs +++ b/vendor/rustix/src/io/is_read_write.rs @@ -1,7 +1,9 @@ //! The [`is_read_write`] function. -use crate::{imp, io}; -use imp::fd::AsFd; +#[cfg(all(feature = "fs", feature = "net"))] +use crate::{backend, io}; +#[cfg(all(feature = "fs", feature = "net"))] +use backend::fd::AsFd; /// Returns a pair of booleans indicating whether the file descriptor is /// readable and/or writable, respectively. @@ -11,6 +13,8 @@ use imp::fd::AsFd; /// /// [`is_file_read_write`]: crate::fs::is_file_read_write #[inline] +#[cfg(all(feature = "fs", feature = "net"))] +#[cfg_attr(doc_cfg, doc(cfg(all(feature = "fs", feature = "net"))))] pub fn is_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> { - imp::io::syscalls::is_read_write(fd.as_fd()) + backend::io::syscalls::is_read_write(fd.as_fd()) } diff --git a/vendor/rustix/src/io/mod.rs b/vendor/rustix/src/io/mod.rs index 5cd5e2ec9..03f06c4ac 100644 --- a/vendor/rustix/src/io/mod.rs +++ b/vendor/rustix/src/io/mod.rs @@ -6,13 +6,13 @@ mod dup; mod errno; #[cfg(any(target_os = "android", target_os = "linux"))] mod eventfd; +#[cfg(not(windows))] +mod fcntl; #[cfg(not(feature = "std"))] pub(crate) mod fd; mod ioctl; #[cfg(not(any(windows, target_os = "redox")))] -#[cfg(feature = "net")] mod is_read_write; -mod owned_fd; #[cfg(not(any(windows, target_os = "wasi")))] mod pipe; mod poll; @@ -26,13 +26,17 @@ mod seek_from; mod stdio; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use crate::imp::io::epoll; +pub use crate::backend::io::epoll; pub use close::close; -#[cfg(not(any(windows, target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "aix", target_os = "wasi")))] pub use dup::{dup, dup2, dup3, DupFlags}; pub use errno::{retry_on_intr, Errno, Result}; #[cfg(any(target_os = "android", target_os = "linux"))] pub use eventfd::{eventfd, EventfdFlags}; +#[cfg(not(any(windows, target_os = "wasi")))] +pub use fcntl::fcntl_dupfd_cloexec; +#[cfg(not(windows))] +pub use fcntl::{fcntl_getfd, fcntl_setfd, FdFlags}; #[cfg(any(target_os = "ios", target_os = "macos"))] pub use ioctl::ioctl_fioclex; pub use ioctl::ioctl_fionbio; @@ -40,29 +44,46 @@ pub use ioctl::ioctl_fionbio; pub use ioctl::ioctl_fionread; #[cfg(any(target_os = "android", target_os = "linux"))] pub use ioctl::{ioctl_blkpbszget, ioctl_blksszget}; -#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))] +#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))] pub use ioctl::{ioctl_tiocexcl, ioctl_tiocnxcl}; #[cfg(not(any(windows, target_os = "redox")))] -#[cfg(feature = "net")] +#[cfg(all(feature = "fs", feature = "net"))] pub use is_read_write::is_read_write; -pub use owned_fd::OwnedFd; #[cfg(not(any(windows, target_os = "wasi")))] pub use pipe::pipe; #[cfg(not(any( windows, + target_os = "haiku", target_os = "illumos", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] pub use pipe::PIPE_BUF; -#[cfg(not(any(windows, target_os = "ios", target_os = "macos", target_os = "wasi")))] +#[cfg(not(any( + windows, + target_os = "aix", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "wasi" +)))] pub use pipe::{pipe_with, PipeFlags}; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use pipe::{splice, vmsplice, IoSliceRaw, SpliceFlags}; pub use poll::{poll, PollFd, PollFlags}; #[cfg(all(feature = "procfs", any(target_os = "android", target_os = "linux")))] -pub use procfs::{proc_self_fd, proc_self_fdinfo_fd, proc_self_maps, proc_self_pagemap}; +pub use procfs::{ + proc_self_fd, proc_self_fdinfo_fd, proc_self_maps, proc_self_pagemap, proc_self_status, +}; #[cfg(not(windows))] pub use read_write::{pread, pwrite, read, readv, write, writev, IoSlice, IoSliceMut}; -#[cfg(not(any(windows, target_os = "redox")))] +#[cfg(not(any( + windows, + target_os = "haiku", + target_os = "redox", + target_os = "solaris" +)))] pub use read_write::{preadv, pwritev}; #[cfg(any(target_os = "android", target_os = "linux"))] pub use read_write::{preadv2, pwritev2, ReadWriteFlags}; @@ -71,4 +92,6 @@ pub use seek_from::SeekFrom; #[cfg(feature = "std")] pub use std::io::SeekFrom; #[cfg(not(windows))] -pub use stdio::{stderr, stdin, stdout, take_stderr, take_stdin, take_stdout}; +pub use stdio::{ + raw_stderr, raw_stdin, raw_stdout, stderr, stdin, stdout, take_stderr, take_stdin, take_stdout, +}; diff --git a/vendor/rustix/src/io/owned_fd.rs b/vendor/rustix/src/io/owned_fd.rs deleted file mode 100644 index 63c6145b0..000000000 --- a/vendor/rustix/src/io/owned_fd.rs +++ /dev/null @@ -1,272 +0,0 @@ -//! A wrapper around [`io_lifetimes::OwnedFd`]. -//! -//! rustix needs to wrap io-lifetimes' `OwnedFd` type so that it can call its -//! own [`close`] function when the `OwnedFd` is dropped. -//! -//! [`close`]: crate::io::close -//! -//! # Safety -//! -//! We wrap an `OwnedFd` in a `ManuallyDrop` so that we can extract the -//! file descriptor and close it ourselves. -#![allow(unsafe_code)] - -use crate::imp::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; -#[cfg(all(not(io_lifetimes_use_std), feature = "std"))] -use crate::imp::fd::{FromFd, IntoFd}; -use crate::io::close; -use core::fmt; -use core::mem::{forget, ManuallyDrop}; - -/// A wrapper around [`io_lifetimes::OwnedFd`] which closes the file descriptor -/// using rustix's own [`close`] rather than libc's `close`. -/// -/// [`close`]: crate::io::close -#[repr(transparent)] -pub struct OwnedFd { - inner: ManuallyDrop<crate::imp::fd::OwnedFd>, -} - -impl OwnedFd { - /// Creates a new `OwnedFd` instance that shares the same underlying file - /// handle as the existing `OwnedFd` instance. - #[cfg(all(unix, not(target_os = "wasi")))] - pub fn try_clone(&self) -> crate::io::Result<Self> { - // We want to atomically duplicate this file descriptor and set the - // CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This - // is a POSIX flag that was added to Linux in 2.6.24. - #[cfg(not(target_os = "espidf"))] - let fd = crate::fs::fcntl_dupfd_cloexec(self, 0)?; - - // For ESP-IDF, F_DUPFD is used instead, because the CLOEXEC semantics - // will never be supported, as this is a bare metal framework with - // no capabilities for multi-process execution. While F_DUPFD is also - // not supported yet, it might be (currently it returns ENOSYS). - #[cfg(target_os = "espidf")] - let fd = crate::fs::fcntl_dupfd(self)?; - - Ok(fd) - } - - /// Creates a new `OwnedFd` instance that shares the same underlying file - /// handle as the existing `OwnedFd` instance. - #[cfg(target_os = "wasi")] - pub fn try_clone(&self) -> std::io::Result<Self> { - Err(std::io::Error::new( - std::io::ErrorKind::Unsupported, - "operation not supported on WASI yet", - )) - } - - /// Creates a new `OwnedFd` instance that shares the same underlying file - /// handle as the existing `OwnedFd` instance. - #[cfg(target_os = "windows")] - pub fn try_clone(&self) -> std::io::Result<Self> { - use windows_sys::Win32::Networking::WinSock::{ - WSADuplicateSocketW, WSAGetLastError, WSASocketW, INVALID_SOCKET, SOCKET_ERROR, - WSAEINVAL, WSAEPROTOTYPE, WSAPROTOCOL_INFOW, WSA_FLAG_NO_HANDLE_INHERIT, - WSA_FLAG_OVERLAPPED, - }; - use windows_sys::Win32::System::Threading::GetCurrentProcessId; - - let mut info = unsafe { std::mem::zeroed::<WSAPROTOCOL_INFOW>() }; - let result = - unsafe { WSADuplicateSocketW(self.as_raw_fd() as _, GetCurrentProcessId(), &mut info) }; - match result { - SOCKET_ERROR => return Err(std::io::Error::last_os_error()), - 0 => (), - _ => panic!(), - } - let socket = unsafe { - WSASocketW( - info.iAddressFamily, - info.iSocketType, - info.iProtocol, - &mut info, - 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT, - ) - }; - - if socket != INVALID_SOCKET { - unsafe { Ok(Self::from_raw_fd(socket as _)) } - } else { - let error = unsafe { WSAGetLastError() }; - - if error != WSAEPROTOTYPE && error != WSAEINVAL { - return Err(std::io::Error::from_raw_os_error(error)); - } - - let socket = unsafe { - WSASocketW( - info.iAddressFamily, - info.iSocketType, - info.iProtocol, - &mut info, - 0, - WSA_FLAG_OVERLAPPED, - ) - }; - - if socket == INVALID_SOCKET { - return Err(std::io::Error::last_os_error()); - } - - unsafe { - let socket = Self::from_raw_fd(socket as _); - socket.set_no_inherit()?; - Ok(socket) - } - } - } - - #[cfg(windows)] - #[cfg(not(target_vendor = "uwp"))] - fn set_no_inherit(&self) -> std::io::Result<()> { - use windows_sys::Win32::Foundation::{SetHandleInformation, HANDLE, HANDLE_FLAG_INHERIT}; - match unsafe { SetHandleInformation(self.as_raw_fd() as HANDLE, HANDLE_FLAG_INHERIT, 0) } { - 0 => return Err(std::io::Error::last_os_error()), - _ => Ok(()), - } - } - - #[cfg(windows)] - #[cfg(target_vendor = "uwp")] - fn set_no_inherit(&self) -> std::io::Result<()> { - Err(std::io::Error::new( - std::io::ErrorKind::Unsupported, - "Unavailable on UWP", - )) - } -} - -#[cfg(not(windows))] -impl AsFd for OwnedFd { - #[inline] - fn as_fd(&self) -> BorrowedFd<'_> { - self.inner.as_fd() - } -} - -#[cfg(windows)] -impl io_lifetimes::AsSocket for OwnedFd { - #[inline] - fn as_socket(&self) -> BorrowedFd<'_> { - self.inner.as_socket() - } -} - -#[cfg(any(io_lifetimes_use_std, not(feature = "std")))] -impl From<OwnedFd> for crate::imp::fd::OwnedFd { - #[inline] - fn from(owned_fd: OwnedFd) -> Self { - let raw_fd = owned_fd.inner.as_fd().as_raw_fd(); - forget(owned_fd); - - // Safety: We use `as_fd().as_raw_fd()` to extract the raw file - // descriptor from `self.inner`, and then `forget` `self` so - // that they remain valid until the new `OwnedFd` acquires them. - unsafe { crate::imp::fd::OwnedFd::from_raw_fd(raw_fd) } - } -} - -#[cfg(not(any(io_lifetimes_use_std, not(feature = "std"))))] -impl IntoFd for OwnedFd { - #[inline] - fn into_fd(self) -> crate::imp::fd::OwnedFd { - let raw_fd = self.inner.as_fd().as_raw_fd(); - forget(self); - - // Safety: We use `as_fd().as_raw_fd()` to extract the raw file - // descriptor from `self.inner`, and then `forget` `self` so - // that they remain valid until the new `OwnedFd` acquires them. - unsafe { crate::imp::fd::OwnedFd::from_raw_fd(raw_fd) } - } -} - -#[cfg(any(io_lifetimes_use_std, not(feature = "std")))] -impl From<crate::imp::fd::OwnedFd> for OwnedFd { - #[inline] - fn from(owned_fd: crate::imp::fd::OwnedFd) -> Self { - Self { - inner: ManuallyDrop::new(owned_fd), - } - } -} - -#[cfg(all(not(io_lifetimes_use_std), feature = "std"))] -impl FromFd for OwnedFd { - #[inline] - fn from_fd(owned_fd: crate::imp::fd::OwnedFd) -> Self { - Self { - inner: ManuallyDrop::new(owned_fd), - } - } -} - -#[cfg(not(any(io_lifetimes_use_std, not(feature = "std"))))] -impl From<crate::imp::fd::OwnedFd> for OwnedFd { - #[inline] - fn from(fd: crate::imp::fd::OwnedFd) -> Self { - Self { - inner: ManuallyDrop::new(fd), - } - } -} - -#[cfg(not(any(io_lifetimes_use_std, not(feature = "std"))))] -impl From<OwnedFd> for crate::imp::fd::OwnedFd { - #[inline] - fn from(fd: OwnedFd) -> Self { - let raw_fd = fd.inner.as_fd().as_raw_fd(); - forget(fd); - - // Safety: We use `as_fd().as_raw_fd()` to extract the raw file - // descriptor from `self.inner`, and then `forget` `self` so - // that they remain valid until the new `OwnedFd` acquires them. - unsafe { Self::from_raw_fd(raw_fd) } - } -} - -impl AsRawFd for OwnedFd { - #[inline] - fn as_raw_fd(&self) -> RawFd { - self.inner.as_raw_fd() - } -} - -impl IntoRawFd for OwnedFd { - #[inline] - fn into_raw_fd(self) -> RawFd { - let raw_fd = self.inner.as_fd().as_raw_fd(); - forget(self); - raw_fd - } -} - -impl FromRawFd for OwnedFd { - #[inline] - unsafe fn from_raw_fd(raw_fd: RawFd) -> Self { - Self { - inner: ManuallyDrop::new(crate::imp::fd::OwnedFd::from_raw_fd(raw_fd)), - } - } -} - -impl Drop for OwnedFd { - #[inline] - fn drop(&mut self) { - // Safety: We use `as_fd().as_raw_fd()` to extract the raw file - // descriptor from `self.inner`. `self.inner` is wrapped with - // `ManuallyDrop` so dropping it doesn't invalid them. - unsafe { - close(self.as_fd().as_raw_fd()); - } - } -} - -impl fmt::Debug for OwnedFd { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.inner.fmt(f) - } -} diff --git a/vendor/rustix/src/io/pipe.rs b/vendor/rustix/src/io/pipe.rs index 2878d10b1..2b8af6a84 100644 --- a/vendor/rustix/src/io/pipe.rs +++ b/vendor/rustix/src/io/pipe.rs @@ -1,8 +1,15 @@ -use crate::imp; -use crate::io::{self, OwnedFd}; +#![allow(unsafe_code)] + +use crate::fd::OwnedFd; +use crate::{backend, io}; +#[cfg(any(target_os = "android", target_os = "linux"))] +use backend::fd::AsFd; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::io::types::PipeFlags; +pub use backend::io::types::PipeFlags; + +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use backend::io::types::{IoSliceRaw, SpliceFlags}; /// `PIPE_BUF`—The maximum length at which writes to a pipe are atomic. /// @@ -14,11 +21,13 @@ pub use imp::io::types::PipeFlags; /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html #[cfg(not(any( windows, + target_os = "haiku", target_os = "illumos", target_os = "redox", + target_os = "solaris", target_os = "wasi", )))] -pub const PIPE_BUF: usize = imp::io::types::PIPE_BUF; +pub const PIPE_BUF: usize = backend::io::types::PIPE_BUF; /// `pipe()`—Creates a pipe. /// @@ -33,7 +42,7 @@ pub const PIPE_BUF: usize = imp::io::types::PIPE_BUF; /// [Linux]: https://man7.org/linux/man-pages/man2/pipe.2.html #[inline] pub fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { - imp::io::syscalls::pipe() + backend::io::syscalls::pipe() } /// `pipe2(flags)`—Creates a pipe, with flags. @@ -45,9 +54,77 @@ pub fn pipe() -> io::Result<(OwnedFd, OwnedFd)> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/pipe2.2.html -#[cfg(not(any(target_os = "ios", target_os = "macos")))] +#[cfg(not(any( + target_os = "aix", + target_os = "haiku", + target_os = "ios", + target_os = "macos" +)))] #[inline] #[doc(alias = "pipe2")] pub fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> { - imp::io::syscalls::pipe_with(flags) + backend::io::syscalls::pipe_with(flags) +} + +/// `splice(fd_in, off_in, fd_out, off_out, len, flags)`—Transfer data between a file and a pipe. +/// +/// This function transfers up to `len` bytes of data from the file descriptor `fd_in` +/// to the file descriptor `fd_out`, where one of the file descriptors +/// must refer to a pipe. +/// +/// `off_*` must be `None` if the corresponding fd refers to a pipe. +/// Otherwise its value points to the starting offset to the file, +/// from which the data is read/written. +/// on success the number of bytes read/written is added to the offset. +/// +/// passing `None` causes the read/write to start from the file offset, +/// and the file offset is adjusted appropriately. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/splice.2.html +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub fn splice<FdIn: AsFd, FdOut: AsFd>( + fd_in: FdIn, + off_in: Option<&mut u64>, + fd_out: FdOut, + off_out: Option<&mut u64>, + len: usize, + flags: SpliceFlags, +) -> io::Result<usize> { + backend::io::syscalls::splice(fd_in.as_fd(), off_in, fd_out.as_fd(), off_out, len, flags) +} + +/// `vmsplice(fd, bufs, flags)`—Transfer data between memory and a pipe. +/// +/// If `fd` is the write end of the pipe, +/// the function maps the memory pointer at by `bufs` to the pipe. +/// +/// If `fd` is the read end of the pipe, +/// the function writes data from the pipe to said memory. +/// +/// # Safety +/// +/// If the memory must not be mutated (such as when `bufs` were originally immutable slices), +/// it is up to the caller to ensure that the write end of the pipe is placed in `fd`. +/// +/// Additionally if `SpliceFlags::GIFT` is set, the caller must also ensure +/// that the contents of `bufs` in never modified following the call, +/// and that all of the pointers in `bufs` are page aligned, +/// and the lengths are multiples of a page size in bytes. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/vmsplice.2.html +#[cfg(any(target_os = "android", target_os = "linux"))] +#[inline] +pub unsafe fn vmsplice<PipeFd: AsFd>( + fd: PipeFd, + bufs: &[io::IoSliceRaw], + flags: SpliceFlags, +) -> io::Result<usize> { + backend::io::syscalls::vmsplice(fd.as_fd(), bufs, flags) } diff --git a/vendor/rustix/src/io/poll.rs b/vendor/rustix/src/io/poll.rs index efa25045c..01f625af2 100644 --- a/vendor/rustix/src/io/poll.rs +++ b/vendor/rustix/src/io/poll.rs @@ -1,6 +1,6 @@ -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::io::poll_fd::{PollFd, PollFlags}; +pub use backend::io::poll_fd::{PollFd, PollFlags}; /// `poll(self.fds, timeout)` /// @@ -16,5 +16,5 @@ pub use imp::io::poll_fd::{PollFd, PollFlags}; /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsapoll #[inline] pub fn poll(fds: &mut [PollFd<'_>], timeout: i32) -> io::Result<usize> { - imp::io::syscalls::poll(fds, timeout) + backend::io::syscalls::poll(fds, timeout) } diff --git a/vendor/rustix/src/io/procfs.rs b/vendor/rustix/src/io/procfs.rs index a947a4e06..c6eeb08e0 100644 --- a/vendor/rustix/src/io/procfs.rs +++ b/vendor/rustix/src/io/procfs.rs @@ -16,15 +16,15 @@ //! namespace. So with the checking here, they may fail, but they won't be able //! to succeed with bogus results. -use crate::fd::{AsFd, BorrowedFd}; +use crate::fd::{AsFd, BorrowedFd, OwnedFd}; use crate::ffi::CStr; use crate::fs::{ cwd, fstat, fstatfs, major, openat, renameat, Dir, FileType, Mode, OFlags, Stat, PROC_SUPER_MAGIC, }; -use crate::io::{self, OwnedFd}; +use crate::io; use crate::path::DecInt; -use crate::process::{getgid, getpid, getuid, Gid, RawGid, RawUid, Uid}; +use crate::process::getpid; #[cfg(feature = "rustc-dep-of-std")] use core::lazy::OnceCell; #[cfg(not(feature = "rustc-dep-of-std"))] @@ -47,11 +47,9 @@ fn check_proc_entry( kind: Kind, entry: BorrowedFd<'_>, proc_stat: Option<&Stat>, - uid: RawUid, - gid: RawGid, ) -> io::Result<Stat> { let entry_stat = fstat(entry)?; - check_proc_entry_with_stat(kind, entry, entry_stat, proc_stat, uid, gid) + check_proc_entry_with_stat(kind, entry, entry_stat, proc_stat) } /// Check a subdirectory of "/proc" for anomalies, using the provided `Stat`. @@ -60,8 +58,6 @@ fn check_proc_entry_with_stat( entry: BorrowedFd<'_>, entry_stat: Stat, proc_stat: Option<&Stat>, - uid: RawUid, - gid: RawGid, ) -> io::Result<Stat> { // Check the filesystem magic. check_procfs(entry)?; @@ -72,13 +68,6 @@ fn check_proc_entry_with_stat( Kind::File => check_proc_file(&entry_stat, proc_stat)?, } - // Check the ownership of the directory. We can't do that for the toplevel - // "/proc" though, because in e.g. a user namespace scenario, root outside - // the container may be mapped to another uid like `nobody`. - if !matches!(kind, Kind::Proc) && (entry_stat.st_uid, entry_stat.st_gid) != (uid, gid) { - return Err(io::Errno::NOTSUP); - } - // "/proc" directories are typically mounted r-xr-xr-x. // "/proc/self/fd" is r-x------. Allow them to have fewer permissions, but // not more. @@ -207,6 +196,7 @@ fn is_mountpoint(file: BorrowedFd<'_>) -> bool { /// Open a directory in `/proc`, mapping all errors to `io::Errno::NOTSUP`. fn proc_opendirat<P: crate::path::Arg, Fd: AsFd>(dirfd: Fd, path: P) -> io::Result<OwnedFd> { // We could add `PATH`|`NOATIME` here but Linux 2.6.32 doesn't support it. + // Also for `NOATIME` see the comment in `open_and_check_file`. let oflags = OFlags::NOFOLLOW | OFlags::DIRECTORY | OFlags::CLOEXEC | OFlags::NOCTTY; openat(dirfd, path, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP) } @@ -229,14 +219,8 @@ fn proc() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { PROC.get_or_try_init(|| { // Open "/proc". let proc = proc_opendirat(cwd(), cstr!("/proc"))?; - let proc_stat = check_proc_entry( - Kind::Proc, - proc.as_fd(), - None, - Uid::ROOT.as_raw(), - Gid::ROOT.as_raw(), - ) - .map_err(|_err| io::Errno::NOTSUP)?; + let proc_stat = + check_proc_entry(Kind::Proc, proc.as_fd(), None).map_err(|_err| io::Errno::NOTSUP)?; Ok(new_static_fd(proc, proc_stat)) }) @@ -260,19 +244,13 @@ fn proc_self() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { .get_or_try_init(|| { let (proc, proc_stat) = proc()?; - let (uid, gid, pid) = (getuid(), getgid(), getpid()); + let pid = getpid(); // Open "/proc/self". Use our pid to compute the name rather than literally // using "self", as "self" is a symlink. let proc_self = proc_opendirat(proc, DecInt::new(pid.as_raw_nonzero().get()))?; - let proc_self_stat = check_proc_entry( - Kind::Pid, - proc_self.as_fd(), - Some(proc_stat), - uid.as_raw(), - gid.as_raw(), - ) - .map_err(|_err| io::Errno::NOTSUP)?; + let proc_self_stat = check_proc_entry(Kind::Pid, proc_self.as_fd(), Some(proc_stat)) + .map_err(|_err| io::Errno::NOTSUP)?; Ok(new_static_fd(proc_self, proc_self_stat)) }) @@ -297,18 +275,13 @@ pub fn proc_self_fd() -> io::Result<BorrowedFd<'static>> { .get_or_try_init(|| { let (_, proc_stat) = proc()?; - let (proc_self, proc_self_stat) = proc_self()?; + let (proc_self, _proc_self_stat) = proc_self()?; // Open "/proc/self/fd". let proc_self_fd = proc_opendirat(proc_self, cstr!("fd"))?; - let proc_self_fd_stat = check_proc_entry( - Kind::Fd, - proc_self_fd.as_fd(), - Some(proc_stat), - proc_self_stat.st_uid, - proc_self_stat.st_gid, - ) - .map_err(|_err| io::Errno::NOTSUP)?; + let proc_self_fd_stat = + check_proc_entry(Kind::Fd, proc_self_fd.as_fd(), Some(proc_stat)) + .map_err(|_err| io::Errno::NOTSUP)?; Ok(new_static_fd(proc_self_fd, proc_self_fd_stat)) }) @@ -333,24 +306,19 @@ fn new_static_fd(fd: OwnedFd, stat: Stat) -> (OwnedFd, Stat) { /// /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { - static PROC_SELF_FDINFO: OnceCell<(OwnedFd, Stat)> = OnceCell::new(); + static PROC_SELF_FDINFO: StaticFd = StaticFd::new(); PROC_SELF_FDINFO .get_or_try_init(|| { let (_, proc_stat) = proc()?; - let (proc_self, proc_self_stat) = proc_self()?; + let (proc_self, _proc_self_stat) = proc_self()?; // Open "/proc/self/fdinfo". let proc_self_fdinfo = proc_opendirat(proc_self, cstr!("fdinfo"))?; - let proc_self_fdinfo_stat = check_proc_entry( - Kind::Fd, - proc_self_fdinfo.as_fd(), - Some(proc_stat), - proc_self_stat.st_uid, - proc_self_stat.st_gid, - ) - .map_err(|_err| io::Errno::NOTSUP)?; + let proc_self_fdinfo_stat = + check_proc_entry(Kind::Fd, proc_self_fdinfo.as_fd(), Some(proc_stat)) + .map_err(|_err| io::Errno::NOTSUP)?; Ok((proc_self_fdinfo, proc_self_fdinfo_stat)) }) @@ -410,6 +378,21 @@ pub fn proc_self_maps() -> io::Result<OwnedFd> { proc_self_file(cstr!("maps")) } +/// Returns a handle to a Linux `/proc/self/status` file. +/// +/// This ensures that `/proc/self/status` is `procfs`, that nothing is +/// mounted on top of it, and that it looks normal. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html +#[inline] +#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] +pub fn proc_self_status() -> io::Result<OwnedFd> { + proc_self_file(cstr!("status")) +} + /// Open a file under `/proc/self`. fn proc_self_file(name: &CStr) -> io::Result<OwnedFd> { let (proc_self, proc_self_stat) = proc_self()?; @@ -420,9 +403,14 @@ fn proc_self_file(name: &CStr) -> io::Result<OwnedFd> { fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Result<OwnedFd> { let (_, proc_stat) = proc()?; - let oflags = - OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NOCTTY | OFlags::NOATIME; - let file = openat(&dir, name, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)?; + // Don't use `NOATIME`, because it [requires us to own the file], and when + // a process sets itself non-dumpable Linux changes the user:group of its + // `/proc/<pid>` files [to root:root]. + // + // [requires us to own the file]: https://man7.org/linux/man-pages/man2/openat.2.html + // [to root:root]: https://man7.org/linux/man-pages/man5/proc.5.html + let oflags = OFlags::RDONLY | OFlags::CLOEXEC | OFlags::NOFOLLOW | OFlags::NOCTTY; + let file = openat(dir, name, oflags, Mode::empty()).map_err(|_err| io::Errno::NOTSUP)?; let file_stat = fstat(&file)?; // `is_mountpoint` only works on directory mount points, not file mount @@ -455,14 +443,8 @@ fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Res && entry.file_name() == name { // We found the file. Proceed to check the file handle. - let _ = check_proc_entry_with_stat( - Kind::File, - file.as_fd(), - file_stat, - Some(proc_stat), - dir_stat.st_uid, - dir_stat.st_gid, - )?; + let _ = + check_proc_entry_with_stat(Kind::File, file.as_fd(), file_stat, Some(proc_stat))?; found_file = true; } else if entry.ino() == dir_stat.st_ino diff --git a/vendor/rustix/src/io/read_write.rs b/vendor/rustix/src/io/read_write.rs index abb96e9c1..1a4d37b65 100644 --- a/vendor/rustix/src/io/read_write.rs +++ b/vendor/rustix/src/io/read_write.rs @@ -1,19 +1,19 @@ //! `read` and `write`, optionally positioned, optionally vectored -use crate::{imp, io}; -use imp::fd::AsFd; +use crate::{backend, io}; +use backend::fd::AsFd; // Declare `IoSlice` and `IoSliceMut`. #[cfg(not(windows))] #[cfg(not(feature = "std"))] -pub use imp::io::io_slice::{IoSlice, IoSliceMut}; +pub use backend::io::io_slice::{IoSlice, IoSliceMut}; #[cfg(not(windows))] #[cfg(feature = "std")] pub use std::io::{IoSlice, IoSliceMut}; /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`]. #[cfg(any(target_os = "android", target_os = "linux"))] -pub use imp::io::types::ReadWriteFlags; +pub use backend::io::types::ReadWriteFlags; /// `read(fd, buf)`—Reads from a stream. /// @@ -27,7 +27,7 @@ pub use imp::io::types::ReadWriteFlags; /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/read.2.html #[inline] pub fn read<Fd: AsFd>(fd: Fd, buf: &mut [u8]) -> io::Result<usize> { - imp::io::syscalls::read(fd.as_fd(), buf) + backend::io::syscalls::read(fd.as_fd(), buf) } /// `write(fd, buf)`—Writes to a stream. @@ -42,7 +42,7 @@ pub fn read<Fd: AsFd>(fd: Fd, buf: &mut [u8]) -> io::Result<usize> { /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/write.2.html #[inline] pub fn write<Fd: AsFd>(fd: Fd, buf: &[u8]) -> io::Result<usize> { - imp::io::syscalls::write(fd.as_fd(), buf) + backend::io::syscalls::write(fd.as_fd(), buf) } /// `pread(fd, buf, offset)`—Reads from a file at a given position. @@ -57,7 +57,7 @@ pub fn write<Fd: AsFd>(fd: Fd, buf: &[u8]) -> io::Result<usize> { /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pread.2.html #[inline] pub fn pread<Fd: AsFd>(fd: Fd, buf: &mut [u8], offset: u64) -> io::Result<usize> { - imp::io::syscalls::pread(fd.as_fd(), buf, offset) + backend::io::syscalls::pread(fd.as_fd(), buf, offset) } /// `pwrite(fd, bufs)`—Writes to a file at a given position. @@ -72,7 +72,7 @@ pub fn pread<Fd: AsFd>(fd: Fd, buf: &mut [u8], offset: u64) -> io::Result<usize> /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/pwrite.2.html #[inline] pub fn pwrite<Fd: AsFd>(fd: Fd, buf: &[u8], offset: u64) -> io::Result<usize> { - imp::io::syscalls::pwrite(fd.as_fd(), buf, offset) + backend::io::syscalls::pwrite(fd.as_fd(), buf, offset) } /// `readv(fd, bufs)`—Reads from a stream into multiple buffers. @@ -87,7 +87,7 @@ pub fn pwrite<Fd: AsFd>(fd: Fd, buf: &[u8], offset: u64) -> io::Result<usize> { /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/readv.2.html #[inline] pub fn readv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { - imp::io::syscalls::readv(fd.as_fd(), bufs) + backend::io::syscalls::readv(fd.as_fd(), bufs) } /// `writev(fd, bufs)`—Writes to a stream from multiple buffers. @@ -102,7 +102,7 @@ pub fn readv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> /// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/writev.2.html #[inline] pub fn writev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>]) -> io::Result<usize> { - imp::io::syscalls::writev(fd.as_fd(), bufs) + backend::io::syscalls::writev(fd.as_fd(), bufs) } /// `preadv(fd, bufs, offset)`—Reads from a file at a given position into @@ -112,10 +112,10 @@ pub fn writev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>]) -> io::Result<usize> { /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/preadv.2.html -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] #[inline] pub fn preadv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> { - imp::io::syscalls::preadv(fd.as_fd(), bufs, offset) + backend::io::syscalls::preadv(fd.as_fd(), bufs, offset) } /// `pwritev(fd, bufs, offset)`—Writes to a file at a given position from @@ -125,10 +125,10 @@ pub fn preadv<Fd: AsFd>(fd: Fd, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io: /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/pwritev.2.html -#[cfg(not(target_os = "redox"))] +#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "solaris")))] #[inline] pub fn pwritev<Fd: AsFd>(fd: Fd, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> { - imp::io::syscalls::pwritev(fd.as_fd(), bufs, offset) + backend::io::syscalls::pwritev(fd.as_fd(), bufs, offset) } /// `preadv2(fd, bufs, offset, flags)`—Reads data, with several options. @@ -147,7 +147,7 @@ pub fn preadv2<Fd: AsFd>( offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { - imp::io::syscalls::preadv2(fd.as_fd(), bufs, offset, flags) + backend::io::syscalls::preadv2(fd.as_fd(), bufs, offset, flags) } /// `pwritev2(fd, bufs, offset, flags)`—Writes data, with several options. @@ -166,5 +166,5 @@ pub fn pwritev2<Fd: AsFd>( offset: u64, flags: ReadWriteFlags, ) -> io::Result<usize> { - imp::io::syscalls::pwritev2(fd.as_fd(), bufs, offset, flags) + backend::io::syscalls::pwritev2(fd.as_fd(), bufs, offset, flags) } diff --git a/vendor/rustix/src/io/stdio.rs b/vendor/rustix/src/io/stdio.rs index f9d03a701..caa8183c2 100644 --- a/vendor/rustix/src/io/stdio.rs +++ b/vendor/rustix/src/io/stdio.rs @@ -8,9 +8,9 @@ //! stdio streams. #![allow(unsafe_code)] -use crate::imp; -use crate::io::OwnedFd; -use imp::fd::{BorrowedFd, FromRawFd, RawFd}; +use crate::backend; +use crate::fd::OwnedFd; +use backend::fd::{BorrowedFd, FromRawFd, RawFd}; /// `STDIN_FILENO`—Standard input, borrowed. /// @@ -36,9 +36,10 @@ use imp::fd::{BorrowedFd, FromRawFd, RawFd}; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html /// [Linux]: https://man7.org/linux/man-pages/man3/stdin.3.html +#[doc(alias = "STDIN_FILENO")] #[inline] -pub unsafe fn stdin() -> BorrowedFd<'static> { - BorrowedFd::borrow_raw(imp::io::types::STDIN_FILENO as RawFd) +pub const unsafe fn stdin() -> BorrowedFd<'static> { + BorrowedFd::borrow_raw(backend::io::types::STDIN_FILENO as RawFd) } /// `STDIN_FILENO`—Standard input, owned. @@ -65,11 +66,10 @@ pub unsafe fn stdin() -> BorrowedFd<'static> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html /// [Linux]: https://man7.org/linux/man-pages/man3/stdin.3.html +#[doc(alias = "STDIN_FILENO")] #[inline] pub unsafe fn take_stdin() -> OwnedFd { - OwnedFd::from(imp::fd::OwnedFd::from_raw_fd( - imp::io::types::STDIN_FILENO as RawFd, - )) + backend::fd::OwnedFd::from_raw_fd(backend::io::types::STDIN_FILENO as RawFd) } /// `STDOUT_FILENO`—Standard output, borrowed. @@ -97,9 +97,10 @@ pub unsafe fn take_stdin() -> OwnedFd { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html /// [Linux]: https://man7.org/linux/man-pages/man3/stdout.3.html +#[doc(alias = "STDOUT_FILENO")] #[inline] -pub unsafe fn stdout() -> BorrowedFd<'static> { - BorrowedFd::borrow_raw(imp::io::types::STDOUT_FILENO as RawFd) +pub const unsafe fn stdout() -> BorrowedFd<'static> { + BorrowedFd::borrow_raw(backend::io::types::STDOUT_FILENO as RawFd) } /// `STDOUT_FILENO`—Standard output, owned. @@ -126,11 +127,10 @@ pub unsafe fn stdout() -> BorrowedFd<'static> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html /// [Linux]: https://man7.org/linux/man-pages/man3/stdout.3.html +#[doc(alias = "STDOUT_FILENO")] #[inline] pub unsafe fn take_stdout() -> OwnedFd { - OwnedFd::from(imp::fd::OwnedFd::from_raw_fd( - imp::io::types::STDOUT_FILENO as RawFd, - )) + backend::fd::OwnedFd::from_raw_fd(backend::io::types::STDOUT_FILENO as RawFd) } /// `STDERR_FILENO`—Standard error, borrowed. @@ -157,9 +157,10 @@ pub unsafe fn take_stdout() -> OwnedFd { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html /// [Linux]: https://man7.org/linux/man-pages/man3/stderr.3.html +#[doc(alias = "STDERR_FILENO")] #[inline] -pub unsafe fn stderr() -> BorrowedFd<'static> { - BorrowedFd::borrow_raw(imp::io::types::STDERR_FILENO as RawFd) +pub const unsafe fn stderr() -> BorrowedFd<'static> { + BorrowedFd::borrow_raw(backend::io::types::STDERR_FILENO as RawFd) } /// `STDERR_FILENO`—Standard error, owned. @@ -186,9 +187,68 @@ pub unsafe fn stderr() -> BorrowedFd<'static> { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html /// [Linux]: https://man7.org/linux/man-pages/man3/stderr.3.html +#[doc(alias = "STDERR_FILENO")] #[inline] pub unsafe fn take_stderr() -> OwnedFd { - OwnedFd::from(imp::fd::OwnedFd::from_raw_fd( - imp::io::types::STDERR_FILENO as RawFd, - )) + backend::fd::OwnedFd::from_raw_fd(backend::io::types::STDERR_FILENO as RawFd) +} + +/// `STDIN_FILENO`—Standard input, raw. +/// +/// This is similar to [`stdin`], however it returns a `RawFd`. +/// +/// # Other hazards +/// +/// This has the same hazards as [`stdin`]. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdin.html +/// [Linux]: https://man7.org/linux/man-pages/man3/stdin.3.html +#[doc(alias = "STDIN_FILENO")] +#[inline] +pub const fn raw_stdin() -> RawFd { + backend::io::types::STDIN_FILENO as RawFd +} + +/// `STDOUT_FILENO`—Standard output, raw. +/// +/// This is similar to [`stdout`], however it returns a `RawFd`. +/// +/// # Other hazards +/// +/// This has the same hazards as [`stdout`]. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html +/// [Linux]: https://man7.org/linux/man-pages/man3/stdout.3.html +#[doc(alias = "STDOUT_FILENO")] +#[inline] +pub const fn raw_stdout() -> RawFd { + backend::io::types::STDOUT_FILENO as RawFd +} + +/// `STDERR_FILENO`—Standard error, raw. +/// +/// This is similar to [`stderr`], however it returns a `RawFd`. +/// +/// # Other hazards +/// +/// This has the same hazards as [`stderr`]. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/stderr.html +/// [Linux]: https://man7.org/linux/man-pages/man3/stderr.3.html +#[doc(alias = "STDERR_FILENO")] +#[inline] +pub const fn raw_stderr() -> RawFd { + backend::io::types::STDERR_FILENO as RawFd } diff --git a/vendor/rustix/src/io_uring.rs b/vendor/rustix/src/io_uring.rs index 13f3bbd10..2f67107ba 100644 --- a/vendor/rustix/src/io_uring.rs +++ b/vendor/rustix/src/io_uring.rs @@ -19,9 +19,8 @@ //! [io_uring]: https://en.wikipedia.org/wiki/Io_uring #![allow(unsafe_code)] -use crate::fd::{AsFd, BorrowedFd, RawFd}; -use crate::imp; -use crate::io::{self, OwnedFd}; +use crate::fd::{AsFd, BorrowedFd, OwnedFd, RawFd}; +use crate::{backend, io}; use core::ffi::c_void; use core::ptr::null_mut; use linux_raw_sys::general as sys; @@ -35,7 +34,7 @@ use linux_raw_sys::general as sys; /// [Linux]: https://man.archlinux.org/man/io_uring_setup.2.en #[inline] pub fn io_uring_setup(entries: u32, params: &mut io_uring_params) -> io::Result<OwnedFd> { - imp::io_uring::syscalls::io_uring_setup(entries, params) + backend::io_uring::syscalls::io_uring_setup(entries, params) } /// `io_uring_register(fd, opcode, arg, nr_args)`—Register files or user @@ -58,7 +57,7 @@ pub unsafe fn io_uring_register<Fd: AsFd>( arg: *const c_void, nr_args: u32, ) -> io::Result<()> { - imp::io_uring::syscalls::io_uring_register(fd.as_fd(), opcode, arg, nr_args) + backend::io_uring::syscalls::io_uring_register(fd.as_fd(), opcode, arg, nr_args) } /// `io_uring_enter(fd, to_submit, min_complete, flags, arg, size)`—Initiate @@ -83,7 +82,14 @@ pub unsafe fn io_uring_enter<Fd: AsFd>( arg: *const c_void, size: usize, ) -> io::Result<u32> { - imp::io_uring::syscalls::io_uring_enter(fd.as_fd(), to_submit, min_complete, flags, arg, size) + backend::io_uring::syscalls::io_uring_enter( + fd.as_fd(), + to_submit, + min_complete, + flags, + arg, + size, + ) } bitflags::bitflags! { @@ -545,7 +551,6 @@ pub const IORING_OFF_SQES: u64 = sys::IORING_OFF_SQES as _; /// `IORING_REGISTER_FILES_SKIP` #[inline] #[doc(alias = "IORING_REGISTER_FILES_SKIP")] -#[allow(unsafe_code)] pub const fn io_uring_register_files_skip() -> BorrowedFd<'static> { let files_skip = sys::IORING_REGISTER_FILES_SKIP as RawFd; diff --git a/vendor/rustix/src/lib.rs b/vendor/rustix/src/lib.rs index ca7c6cd4e..f8bf0729f 100644 --- a/vendor/rustix/src/lib.rs +++ b/vendor/rustix/src/lib.rs @@ -117,6 +117,12 @@ )] #![cfg_attr(asm_experimental_arch, feature(asm_experimental_arch))] #![cfg_attr(not(feature = "all-apis"), allow(dead_code))] +// Clamp depends on Rust 1.50 which is newer than our MSRV. +#![allow(clippy::manual_clamp)] +// It is common in linux and libc APIs for types to vary between platforms. +#![allow(clippy::unnecessary_cast)] +// It is common in linux and libc APIs for types to vary between platforms. +#![allow(clippy::useless_conversion)] #[cfg(not(feature = "rustc-dep-of-std"))] extern crate alloc; @@ -130,27 +136,20 @@ pub(crate) mod const_assert; pub(crate) mod utils; // Pick the backend implementation to use. -#[cfg_attr(libc, path = "imp/libc/mod.rs")] -#[cfg_attr(linux_raw, path = "imp/linux_raw/mod.rs")] -#[cfg_attr(wasi, path = "imp/wasi/mod.rs")] -mod imp; +#[cfg_attr(libc, path = "backend/libc/mod.rs")] +#[cfg_attr(linux_raw, path = "backend/linux_raw/mod.rs")] +#[cfg_attr(wasi, path = "backend/wasi/mod.rs")] +mod backend; /// Export the `*Fd` types and traits that are used in rustix's public API. /// /// Users can use this to avoid needing to import anything else to use the same /// versions of these types and traits. -/// -/// Rustix APIs that use `OwnedFd` use [`rustix::io::OwnedFd`] instead, which -/// allows rustix to implement `close` for them. -/// -/// [`rustix::io::OwnedFd`]: crate::io::OwnedFd pub mod fd { - use super::imp; - pub use imp::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; + use super::backend; #[cfg(windows)] - pub use imp::fd::{AsSocket, FromSocket, IntoSocket}; - #[cfg(feature = "std")] - pub use imp::fd::{FromFd, IntoFd}; + pub use backend::fd::AsSocket; + pub use backend::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; } // The public API modules. @@ -214,9 +213,6 @@ pub mod runtime; // that they're not public, but still available for internal use. #[cfg(not(windows))] -#[cfg(not(feature = "fs"))] -pub(crate) mod fs; -#[cfg(not(windows))] #[cfg(all( not(feature = "param"), any(feature = "runtime", feature = "time", target_arch = "x86"), diff --git a/vendor/rustix/src/mm/madvise.rs b/vendor/rustix/src/mm/madvise.rs index 317c3b515..cf13f951b 100644 --- a/vendor/rustix/src/mm/madvise.rs +++ b/vendor/rustix/src/mm/madvise.rs @@ -6,10 +6,10 @@ //! mutate the memory or have other side effects. #![allow(unsafe_code)] -use crate::{imp, io}; +use crate::{backend, io}; use core::ffi::c_void; -pub use imp::mm::types::Advice; +pub use backend::mm::types::Advice; /// `posix_madvise(addr, len, advice)`—Declares an expected access pattern /// for a memory-mapped file. @@ -31,5 +31,5 @@ pub use imp::mm::types::Advice; #[inline] #[doc(alias = "posix_madvise")] pub unsafe fn madvise(addr: *mut c_void, len: usize, advice: Advice) -> io::Result<()> { - imp::mm::syscalls::madvise(addr, len, advice) + backend::mm::syscalls::madvise(addr, len, advice) } diff --git a/vendor/rustix/src/mm/mmap.rs b/vendor/rustix/src/mm/mmap.rs index 7be02464e..31d3a77b3 100644 --- a/vendor/rustix/src/mm/mmap.rs +++ b/vendor/rustix/src/mm/mmap.rs @@ -6,15 +6,15 @@ //! semantics and are wildly unsafe. #![allow(unsafe_code)] -use crate::{imp, io}; +use crate::{backend, io}; +use backend::fd::AsFd; use core::ffi::c_void; -use imp::fd::AsFd; #[cfg(any(target_os = "android", target_os = "linux"))] -pub use imp::mm::types::MlockFlags; +pub use backend::mm::types::MlockFlags; #[cfg(any(linux_raw, all(libc, target_os = "linux")))] -pub use imp::mm::types::MremapFlags; -pub use imp::mm::types::{MapFlags, MprotectFlags, ProtFlags}; +pub use backend::mm::types::MremapFlags; +pub use backend::mm::types::{MapFlags, MprotectFlags, ProtFlags}; /// `mmap(ptr, len, prot, flags, fd, offset)`—Create a file-backed memory /// mapping. @@ -41,7 +41,7 @@ pub unsafe fn mmap<Fd: AsFd>( fd: Fd, offset: u64, ) -> io::Result<*mut c_void> { - imp::mm::syscalls::mmap(ptr, len, prot, flags, fd.as_fd(), offset) + backend::mm::syscalls::mmap(ptr, len, prot, flags, fd.as_fd(), offset) } /// `mmap(ptr, len, prot, MAP_ANONYMOUS | flags, -1, 0)`—Create an anonymous @@ -67,7 +67,7 @@ pub unsafe fn mmap_anonymous( prot: ProtFlags, flags: MapFlags, ) -> io::Result<*mut c_void> { - imp::mm::syscalls::mmap_anonymous(ptr, len, prot, flags) + backend::mm::syscalls::mmap_anonymous(ptr, len, prot, flags) } /// `munmap(ptr, len)` @@ -84,7 +84,7 @@ pub unsafe fn mmap_anonymous( /// [Linux]: https://man7.org/linux/man-pages/man2/munmap.2.html #[inline] pub unsafe fn munmap(ptr: *mut c_void, len: usize) -> io::Result<()> { - imp::mm::syscalls::munmap(ptr, len) + backend::mm::syscalls::munmap(ptr, len) } /// `mremap(old_address, old_size, new_size, flags)`—Resize, modify, @@ -109,7 +109,7 @@ pub unsafe fn mremap( new_size: usize, flags: MremapFlags, ) -> io::Result<*mut c_void> { - imp::mm::syscalls::mremap(old_address, old_size, new_size, flags) + backend::mm::syscalls::mremap(old_address, old_size, new_size, flags) } /// `mremap(old_address, old_size, new_size, MREMAP_FIXED | flags)`—Resize, @@ -136,7 +136,7 @@ pub unsafe fn mremap_fixed( flags: MremapFlags, new_address: *mut c_void, ) -> io::Result<*mut c_void> { - imp::mm::syscalls::mremap_fixed(old_address, old_size, new_size, flags, new_address) + backend::mm::syscalls::mremap_fixed(old_address, old_size, new_size, flags, new_address) } /// `mprotect(ptr, len, flags)` @@ -153,7 +153,7 @@ pub unsafe fn mremap_fixed( /// [Linux]: https://man7.org/linux/man-pages/man2/mprotect.2.html #[inline] pub unsafe fn mprotect(ptr: *mut c_void, len: usize, flags: MprotectFlags) -> io::Result<()> { - imp::mm::syscalls::mprotect(ptr, len, flags) + backend::mm::syscalls::mprotect(ptr, len, flags) } /// `mlock(ptr, len)`—Lock memory into RAM. @@ -177,7 +177,7 @@ pub unsafe fn mprotect(ptr: *mut c_void, len: usize, flags: MprotectFlags) -> io /// [Linux]: https://man7.org/linux/man-pages/man2/mlock.2.html #[inline] pub unsafe fn mlock(ptr: *mut c_void, len: usize) -> io::Result<()> { - imp::mm::syscalls::mlock(ptr, len) + backend::mm::syscalls::mlock(ptr, len) } /// `mlock2(ptr, len, flags)`—Lock memory into RAM, with @@ -204,7 +204,7 @@ pub unsafe fn mlock(ptr: *mut c_void, len: usize) -> io::Result<()> { #[inline] #[doc(alias = "mlock2")] pub unsafe fn mlock_with(ptr: *mut c_void, len: usize, flags: MlockFlags) -> io::Result<()> { - imp::mm::syscalls::mlock_with(ptr, len, flags) + backend::mm::syscalls::mlock_with(ptr, len, flags) } /// `munlock(ptr, len)`—Unlock memory. @@ -227,5 +227,5 @@ pub unsafe fn mlock_with(ptr: *mut c_void, len: usize, flags: MlockFlags) -> io: /// [Linux]: https://man7.org/linux/man-pages/man2/munlock.2.html #[inline] pub unsafe fn munlock(ptr: *mut c_void, len: usize) -> io::Result<()> { - imp::mm::syscalls::munlock(ptr, len) + backend::mm::syscalls::munlock(ptr, len) } diff --git a/vendor/rustix/src/mm/msync.rs b/vendor/rustix/src/mm/msync.rs index 7117a5067..3ca418fc4 100644 --- a/vendor/rustix/src/mm/msync.rs +++ b/vendor/rustix/src/mm/msync.rs @@ -6,10 +6,10 @@ //! memory or have other side effects. #![allow(unsafe_code)] -use crate::{imp, io}; +use crate::{backend, io}; use core::ffi::c_void; -pub use imp::mm::types::MsyncFlags; +pub use backend::mm::types::MsyncFlags; /// `msync(addr, len, flags)`—Synchronizes a memory-mapping with its backing /// storage. @@ -28,5 +28,5 @@ pub use imp::mm::types::MsyncFlags; /// [Linux `msync`]: https://man7.org/linux/man-pages/man2/msync.2.html #[inline] pub unsafe fn msync(addr: *mut c_void, len: usize, flags: MsyncFlags) -> io::Result<()> { - imp::mm::syscalls::msync(addr, len, flags) + backend::mm::syscalls::msync(addr, len, flags) } diff --git a/vendor/rustix/src/mm/userfaultfd.rs b/vendor/rustix/src/mm/userfaultfd.rs index 65b4a0dd8..201d54772 100644 --- a/vendor/rustix/src/mm/userfaultfd.rs +++ b/vendor/rustix/src/mm/userfaultfd.rs @@ -6,10 +6,10 @@ //! observe and manipulate process memory in magical ways. #![allow(unsafe_code)] -use crate::imp; -use crate::io::{self, OwnedFd}; +use crate::fd::OwnedFd; +use crate::{backend, io}; -pub use imp::mm::types::UserfaultfdFlags; +pub use backend::mm::types::UserfaultfdFlags; /// `userfaultfd(flags)` /// @@ -26,5 +26,5 @@ pub use imp::mm::types::UserfaultfdFlags; /// [Linux userfaultfd]: https://www.kernel.org/doc/Documentation/vm/userfaultfd.txt #[inline] pub unsafe fn userfaultfd(flags: UserfaultfdFlags) -> io::Result<OwnedFd> { - imp::mm::syscalls::userfaultfd(flags) + backend::mm::syscalls::userfaultfd(flags) } diff --git a/vendor/rustix/src/net/addr.rs b/vendor/rustix/src/net/addr.rs index 59f4a55d7..af9e51a8a 100644 --- a/vendor/rustix/src/net/addr.rs +++ b/vendor/rustix/src/net/addr.rs @@ -1,22 +1,17 @@ //! The following is derived from Rust's -//! library/std/src/net/addr.rs at revision -//! dca3f1b786efd27be3b325ed1e01e247aa589c3b. +//! library/std/src/net/socket_addr.rs at revision +//! f7e8ba28a4785e698a55fb95e4b3e803302de0ff. //! -//! This defines `SocketAddr`, `SocketAddrV4`, and `SocketAddrV6`. These are -//! conceptually platform-independent, however in practice OS's have differing -//! representations. +//! All code in this file is licensed MIT or Apache 2.0 at your option. +//! +//! This defines `SocketAddr`, `SocketAddrV4`, and `SocketAddrV6` in a +//! platform-independent way. It is not the native representation. #![allow(unsafe_code)] -use crate::imp::c; -use crate::imp::net::ext::{ - in6_addr_s6_addr, in_addr_s_addr, sockaddr_in6_new, sockaddr_in6_sin6_scope_id, - sockaddr_in6_sin6_scope_id_mut, -}; use crate::net::ip::{IpAddr, Ipv4Addr, Ipv6Addr}; use core::cmp::Ordering; use core::hash; -use core::mem; /// An internet socket address, either IPv4 or IPv6. /// @@ -76,12 +71,11 @@ pub enum SocketAddr { /// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1)); /// assert_eq!(socket.port(), 8080); /// ``` -#[derive(Copy)] +#[derive(Copy, Clone, Eq, PartialEq)] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] pub struct SocketAddrV4 { - // Do not assume that this struct is implemented as the underlying system representation. - // The memory layout is not part of the stable interface that std exposes. - pub(crate) inner: c::sockaddr_in, + ip: Ipv4Addr, + port: u16, } /// An IPv6 socket address. @@ -110,12 +104,13 @@ pub struct SocketAddrV4 { /// assert_eq!(socket.ip(), &Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)); /// assert_eq!(socket.port(), 8080); /// ``` -#[derive(Copy)] +#[derive(Copy, Clone, Eq, PartialEq)] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] pub struct SocketAddrV6 { - // Do not assume that this struct is implemented as the underlying system representation. - // The memory layout is not part of the stable interface that std exposes. - pub(crate) inner: c::sockaddr_in6, + ip: Ipv6Addr, + port: u16, + flowinfo: u32, + scope_id: u32, } impl SocketAddr { @@ -134,34 +129,14 @@ impl SocketAddr { /// ``` #[cfg_attr(staged_api, stable(feature = "ip_addr", since = "1.7.0"))] #[must_use] - pub fn new(ip: IpAddr, port: u16) -> SocketAddr { - match ip { - IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)), - IpAddr::V6(a) => SocketAddr::V6(SocketAddrV6::new(a, port, 0, 0)), - } - } - - /// Returns the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - /// - /// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); - /// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); - /// ``` - #[cfg(const_raw_ptr_deref)] - #[must_use] - #[cfg_attr(staged_api, stable(feature = "ip_addr", since = "1.7.0"))] #[cfg_attr( staged_api, rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] - pub const fn ip(&self) -> IpAddr { - match *self { - SocketAddr::V4(ref a) => IpAddr::V4(*a.ip()), - SocketAddr::V6(ref a) => IpAddr::V6(*a.ip()), + pub const fn new(ip: IpAddr, port: u16) -> SocketAddr { + match ip { + IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)), + IpAddr::V6(a) => SocketAddr::V6(SocketAddrV6::new(a, port, 0, 0)), } } @@ -175,14 +150,13 @@ impl SocketAddr { /// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); /// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); /// ``` - #[cfg(not(const_raw_ptr_deref))] #[must_use] #[cfg_attr(staged_api, stable(feature = "ip_addr", since = "1.7.0"))] #[cfg_attr( staged_api, rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] - pub fn ip(&self) -> IpAddr { + pub const fn ip(&self) -> IpAddr { match *self { SocketAddr::V4(ref a) => IpAddr::V4(*a.ip()), SocketAddr::V6(ref a) => IpAddr::V6(*a.ip()), @@ -317,38 +291,12 @@ impl SocketAddrV4 { /// ``` #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use] - pub fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 { - SocketAddrV4 { - inner: c::sockaddr_in { - sin_family: c::AF_INET as c::sa_family_t, - sin_port: port.to_be(), - sin_addr: ip.inner, - ..unsafe { mem::zeroed() } - }, - } - } - - /// Returns the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV4, Ipv4Addr}; - /// - /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); - /// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1)); - /// ``` - #[cfg(const_raw_ptr_deref)] - #[must_use] - #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[cfg_attr( staged_api, rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] - pub const fn ip(&self) -> &Ipv4Addr { - // SAFETY: `Ipv4Addr` is `#[repr(C)] struct { _: in_addr; }`. - // It is safe to cast from `&in_addr` to `&Ipv4Addr`. - unsafe { &*(&self.inner.sin_addr as *const c::in_addr as *const Ipv4Addr) } + pub const fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 { + SocketAddrV4 { ip, port } } /// Returns the IP address associated with this socket address. @@ -361,17 +309,14 @@ impl SocketAddrV4 { /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); /// assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1)); /// ``` - #[cfg(not(const_raw_ptr_deref))] #[must_use] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[cfg_attr( staged_api, rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] - pub fn ip(&self) -> &Ipv4Addr { - // SAFETY: `Ipv4Addr` is `#[repr(C)] struct { _: in_addr; }`. - // It is safe to cast from `&in_addr` to `&Ipv4Addr`. - unsafe { &*(&self.inner.sin_addr as *const c::in_addr as *const Ipv4Addr) } + pub const fn ip(&self) -> &Ipv4Addr { + &self.ip } /// Changes the IP address associated with this socket address. @@ -387,7 +332,7 @@ impl SocketAddrV4 { /// ``` #[cfg_attr(staged_api, stable(feature = "sockaddr_setters", since = "1.9.0"))] pub fn set_ip(&mut self, new_ip: Ipv4Addr) { - self.inner.sin_addr = new_ip.inner + self.ip = new_ip; } /// Returns the port number associated with this socket address. @@ -407,7 +352,7 @@ impl SocketAddrV4 { rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] pub const fn port(&self) -> u16 { - u16::from_be(self.inner.sin_port) + self.port } /// Changes the port number associated with this socket address. @@ -423,7 +368,7 @@ impl SocketAddrV4 { /// ``` #[cfg_attr(staged_api, stable(feature = "sockaddr_setters", since = "1.9.0"))] pub fn set_port(&mut self, new_port: u16) { - self.inner.sin_port = new_port.to_be(); + self.port = new_port; } } @@ -446,37 +391,17 @@ impl SocketAddrV6 { /// ``` #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use] - pub fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 { - SocketAddrV6 { - inner: sockaddr_in6_new( - c::AF_INET6 as c::sa_family_t, - port.to_be(), - flowinfo, - ip.inner, - scope_id, - ), - } - } - - /// Returns the IP address associated with this socket address. - /// - /// # Examples - /// - /// ``` - /// use std::net::{SocketAddrV6, Ipv6Addr}; - /// - /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); - /// assert_eq!(socket.ip(), &Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); - /// ``` - #[cfg(const_raw_ptr_deref)] - #[must_use] - #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[cfg_attr( staged_api, rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] - pub const fn ip(&self) -> &Ipv6Addr { - unsafe { &*(&self.inner.sin6_addr as *const c::in6_addr as *const Ipv6Addr) } + pub const fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 { + SocketAddrV6 { + ip, + port, + flowinfo, + scope_id, + } } /// Returns the IP address associated with this socket address. @@ -489,15 +414,14 @@ impl SocketAddrV6 { /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); /// assert_eq!(socket.ip(), &Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)); /// ``` - #[cfg(not(const_raw_ptr_deref))] #[must_use] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[cfg_attr( staged_api, rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] - pub fn ip(&self) -> &Ipv6Addr { - unsafe { &*(&self.inner.sin6_addr as *const c::in6_addr as *const Ipv6Addr) } + pub const fn ip(&self) -> &Ipv6Addr { + &self.ip } /// Changes the IP address associated with this socket address. @@ -513,7 +437,7 @@ impl SocketAddrV6 { /// ``` #[cfg_attr(staged_api, stable(feature = "sockaddr_setters", since = "1.9.0"))] pub fn set_ip(&mut self, new_ip: Ipv6Addr) { - self.inner.sin6_addr = new_ip.inner + self.ip = new_ip; } /// Returns the port number associated with this socket address. @@ -533,7 +457,7 @@ impl SocketAddrV6 { rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] pub const fn port(&self) -> u16 { - u16::from_be(self.inner.sin6_port) + self.port } /// Changes the port number associated with this socket address. @@ -549,7 +473,7 @@ impl SocketAddrV6 { /// ``` #[cfg_attr(staged_api, stable(feature = "sockaddr_setters", since = "1.9.0"))] pub fn set_port(&mut self, new_port: u16) { - self.inner.sin6_port = new_port.to_be(); + self.port = new_port; } /// Returns the flow information associated with this address. @@ -579,7 +503,7 @@ impl SocketAddrV6 { rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] pub const fn flowinfo(&self) -> u32 { - self.inner.sin6_flowinfo + self.flowinfo } /// Changes the flow information associated with this socket address. @@ -597,7 +521,7 @@ impl SocketAddrV6 { /// ``` #[cfg_attr(staged_api, stable(feature = "sockaddr_setters", since = "1.9.0"))] pub fn set_flowinfo(&mut self, new_flowinfo: u32) { - self.inner.sin6_flowinfo = new_flowinfo; + self.flowinfo = new_flowinfo; } /// Returns the scope ID associated with this address. @@ -622,7 +546,7 @@ impl SocketAddrV6 { rustc_const_unstable(feature = "const_socketaddr", issue = "82485") )] pub const fn scope_id(&self) -> u32 { - sockaddr_in6_sin6_scope_id(self.inner) + self.scope_id } /// Changes the scope ID associated with this socket address. @@ -640,7 +564,7 @@ impl SocketAddrV6 { /// ``` #[cfg_attr(staged_api, stable(feature = "sockaddr_setters", since = "1.9.0"))] pub fn set_scope_id(&mut self, new_scope_id: u32) { - *sockaddr_in6_sin6_scope_id_mut(&mut self.inner) = new_scope_id; + self.scope_id = new_scope_id; } } @@ -673,40 +597,6 @@ impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr { } } -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Clone for SocketAddrV4 { - fn clone(&self) -> SocketAddrV4 { - *self - } -} -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Clone for SocketAddrV6 { - fn clone(&self) -> SocketAddrV6 { - *self - } -} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl PartialEq for SocketAddrV4 { - fn eq(&self, other: &SocketAddrV4) -> bool { - self.inner.sin_port == other.inner.sin_port - && in_addr_s_addr(self.inner.sin_addr) == in_addr_s_addr(other.inner.sin_addr) - } -} -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl PartialEq for SocketAddrV6 { - fn eq(&self, other: &SocketAddrV6) -> bool { - self.inner.sin6_port == other.inner.sin6_port - && in6_addr_s6_addr(self.inner.sin6_addr) == in6_addr_s6_addr(self.inner.sin6_addr) - && self.inner.sin6_flowinfo == other.inner.sin6_flowinfo - && sockaddr_in6_sin6_scope_id(self.inner) == sockaddr_in6_sin6_scope_id(other.inner) - } -} -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Eq for SocketAddrV4 {} -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Eq for SocketAddrV6 {} - #[cfg_attr(staged_api, stable(feature = "socketaddr_ordering", since = "1.45.0"))] impl PartialOrd for SocketAddrV4 { fn partial_cmp(&self, other: &SocketAddrV4) -> Option<Ordering> { @@ -742,18 +632,12 @@ impl Ord for SocketAddrV6 { #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] impl hash::Hash for SocketAddrV4 { fn hash<H: hash::Hasher>(&self, s: &mut H) { - (self.inner.sin_port, in_addr_s_addr(self.inner.sin_addr)).hash(s) + (self.port, self.ip).hash(s) } } #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] impl hash::Hash for SocketAddrV6 { fn hash<H: hash::Hasher>(&self, s: &mut H) { - ( - self.inner.sin6_port, - &in6_addr_s6_addr(self.inner.sin6_addr), - self.inner.sin6_flowinfo, - sockaddr_in6_sin6_scope_id(self.inner), - ) - .hash(s) + (self.port, &self.ip, self.flowinfo, self.scope_id).hash(s) } } diff --git a/vendor/rustix/src/net/ip.rs b/vendor/rustix/src/net/ip.rs index 7c587cc7a..4d921cc10 100644 --- a/vendor/rustix/src/net/ip.rs +++ b/vendor/rustix/src/net/ip.rs @@ -1,6 +1,8 @@ //! The following is derived from Rust's -//! library/std/src/net/ip.rs at revision -//! dca3f1b786efd27be3b325ed1e01e247aa589c3b. +//! library/std/src/net/ip_addr.rs at revision +//! 14230a7f8e117aa049d3ae661fa00ded7edefc68. +//! +//! All code in this file is licensed MIT or Apache 2.0 at your option. //! //! This defines `IpAddr`, `Ipv4Addr`, and `Ipv6Addr`. Ideally, these should be //! defined in `core`. See [RFC 2832]. @@ -9,10 +11,7 @@ #![allow(unsafe_code)] -use crate::imp::c; -use crate::imp::net::ext::{in6_addr_new, in6_addr_s6_addr, in_addr_new, in_addr_s_addr}; use core::cmp::Ordering; -use core::hash; use core::mem::transmute; /// An IP address, either IPv4 or IPv6. @@ -20,9 +19,6 @@ use core::mem::transmute; /// This enum can contain either an [`Ipv4Addr`] or an [`Ipv6Addr`], see their /// respective documentation for more details. /// -/// The size of an `IpAddr` instance may vary depending on the target operating -/// system. -/// /// # Examples /// /// ``` @@ -55,9 +51,6 @@ pub enum IpAddr { /// /// See [`IpAddr`] for a type encompassing both IPv4 and IPv6 addresses. /// -/// The size of an `Ipv4Addr` struct may vary depending on the target operating -/// system. -/// /// [IETF RFC 791]: https://tools.ietf.org/html/rfc791 /// /// # Textual representation @@ -82,10 +75,10 @@ pub enum IpAddr { /// assert!("0000000.0.0.0".parse::<Ipv4Addr>().is_err()); // first octet is a zero in octal /// assert!("0xcb.0x0.0x71.0x00".parse::<Ipv4Addr>().is_err()); // all octets are in hex /// ``` -#[derive(Copy)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] pub struct Ipv4Addr { - pub(crate) inner: c::in_addr, + octets: [u8; 4], } /// An IPv6 address. @@ -93,9 +86,6 @@ pub struct Ipv4Addr { /// IPv6 addresses are defined as 128-bit integers in [IETF RFC 4291]. /// They are usually represented as eight 16-bit segments. /// -/// The size of an `Ipv6Addr` struct may vary depending on the target operating -/// system. -/// /// [IETF RFC 4291]: https://tools.ietf.org/html/rfc4291 /// /// # Embedding IPv4 Addresses @@ -143,6 +133,8 @@ pub struct Ipv4Addr { /// /// To convert from an IPv4 address to an IPv4-mapped IPv6 address, use [`Ipv4Addr::to_ipv6_mapped`]. /// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-mapped IPv6 address to the canonical IPv4 address. +/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`. Use +/// [`Ipv6Addr::to_ipv4_mapped`] to avoid this. /// /// [IETF RFC 4291 Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2 /// @@ -165,10 +157,10 @@ pub struct Ipv4Addr { /// assert_eq!("::1".parse(), Ok(localhost)); /// assert_eq!(localhost.is_loopback(), true); /// ``` -#[derive(Copy)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] pub struct Ipv6Addr { - pub(crate) inner: c::in6_addr, + octets: [u8; 16], } /// Scope of an [IPv6 multicast address] as defined in [IETF RFC 7346 section 2]. @@ -240,7 +232,10 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true); /// ``` - #[cfg_attr(staged_api, rustc_const_stable(feature = "const_ip", since = "1.50.0"))] + #[cfg_attr( + staged_api, + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") + )] #[cfg_attr(staged_api, stable(feature = "ip_shared", since = "1.12.0"))] #[must_use] #[inline] @@ -264,7 +259,10 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true); /// ``` - #[cfg_attr(staged_api, rustc_const_stable(feature = "const_ip", since = "1.50.0"))] + #[cfg_attr( + staged_api, + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") + )] #[cfg_attr(staged_api, stable(feature = "ip_shared", since = "1.12.0"))] #[must_use] #[inline] @@ -317,7 +315,10 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true); /// ``` - #[cfg_attr(staged_api, rustc_const_stable(feature = "const_ip", since = "1.50.0"))] + #[cfg_attr( + staged_api, + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") + )] #[cfg_attr(staged_api, stable(feature = "ip_shared", since = "1.12.0"))] #[must_use] #[inline] @@ -398,7 +399,10 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false); /// ``` - #[cfg_attr(staged_api, rustc_const_stable(feature = "const_ip", since = "1.50.0"))] + #[cfg_attr( + staged_api, + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") + )] #[cfg_attr(staged_api, stable(feature = "ipaddr_checker", since = "1.16.0"))] #[must_use] #[inline] @@ -419,7 +423,10 @@ impl IpAddr { /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false); /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true); /// ``` - #[cfg_attr(staged_api, rustc_const_stable(feature = "const_ip", since = "1.50.0"))] + #[cfg_attr( + staged_api, + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") + )] #[cfg_attr(staged_api, stable(feature = "ipaddr_checker", since = "1.16.0"))] #[must_use] #[inline] @@ -470,16 +477,14 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.32.0") + rustc_const_stable(feature = "const_ip_32", since = "1.32.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use] #[inline] pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { - // `s_addr` is stored as BE on all machine and the array is in BE order. - // So the native endian conversion method is used so that it's never swapped. Ipv4Addr { - inner: in_addr_new(u32::from_ne_bytes([a, b, c, d])), + octets: [a, b, c, d], } } @@ -537,14 +542,13 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use] #[inline] pub const fn octets(&self) -> [u8; 4] { - // This returns the order we want because s_addr is stored in big-endian. - in_addr_s_addr(self.inner).to_ne_bytes() + self.octets } /// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`). @@ -564,13 +568,13 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.32.0") + rustc_const_stable(feature = "const_ip_32", since = "1.32.0") )] #[cfg_attr(staged_api, stable(feature = "ip_shared", since = "1.12.0"))] #[must_use] #[inline] pub const fn is_unspecified(&self) -> bool { - in_addr_s_addr(self.inner) == 0 + u32::from_be_bytes(self.octets) == 0 } /// Returns [`true`] if this is a loopback address (`127.0.0.0/8`). @@ -589,7 +593,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -623,7 +627,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -654,7 +658,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -663,25 +667,31 @@ impl Ipv4Addr { matches!(self.octets(), [169, 254, ..]) } - /// Returns [`true`] if the address appears to be globally routable. - /// See [iana-ipv4-special-registry][ipv4-sr]. + /// Returns [`true`] if the address appears to be globally reachable + /// as specified by the [IANA IPv4 Special-Purpose Address Registry]. + /// Whether or not an address is practically reachable will depend on your network configuration. /// - /// The following return [`false`]: + /// Most IPv4 addresses are globally reachable; + /// unless they are specifically defined as *not* globally reachable. /// - /// - private addresses (see [`Ipv4Addr::is_private()`]) - /// - the loopback address (see [`Ipv4Addr::is_loopback()`]) - /// - the link-local address (see [`Ipv4Addr::is_link_local()`]) - /// - the broadcast address (see [`Ipv4Addr::is_broadcast()`]) - /// - addresses used for documentation (see [`Ipv4Addr::is_documentation()`]) - /// - the unspecified address (see [`Ipv4Addr::is_unspecified()`]), and the whole - /// `0.0.0.0/8` block - /// - addresses reserved for future protocols, except - /// `192.0.0.9/32` and `192.0.0.10/32` which are globally routable - /// - addresses reserved for future use (see [`Ipv4Addr::is_reserved()`] - /// - addresses reserved for networking devices benchmarking (see - /// [`Ipv4Addr::is_benchmarking()`]) + /// Non-exhaustive list of notable addresses that are not globally reachable: /// - /// [ipv4-sr]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml + /// - The [unspecified address] ([`is_unspecified`](Ipv4Addr::is_unspecified)) + /// - Addresses reserved for private use ([`is_private`](Ipv4Addr::is_private)) + /// - Addresses in the shared address space ([`is_shared`](Ipv4Addr::is_shared)) + /// - Loopback addresses ([`is_loopback`](Ipv4Addr::is_loopback)) + /// - Link-local addresses ([`is_link_local`](Ipv4Addr::is_link_local)) + /// - Addresses reserved for documentation ([`is_documentation`](Ipv4Addr::is_documentation)) + /// - Addresses reserved for benchmarking ([`is_benchmarking`](Ipv4Addr::is_benchmarking)) + /// - Reserved addresses ([`is_reserved`](Ipv4Addr::is_reserved)) + /// - The [broadcast address] ([`is_broadcast`](Ipv4Addr::is_broadcast)) + /// + /// For the complete overview of which addresses are globally reachable, see the table at the [IANA IPv4 Special-Purpose Address Registry]. + /// + /// [IANA IPv4 Special-Purpose Address Registry]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml + /// [unspecified address]: Ipv4Addr::UNSPECIFIED + /// [broadcast address]: Ipv4Addr::BROADCAST + /// /// # Examples /// @@ -690,46 +700,44 @@ impl Ipv4Addr { /// /// use std::net::Ipv4Addr; /// - /// // private addresses are not global + /// // Most IPv4 addresses are globally reachable: + /// assert_eq!(Ipv4Addr::new(80, 9, 12, 3).is_global(), true); + /// + /// // However some addresses have been assigned a special meaning + /// // that makes them not globally reachable. Some examples are: + /// + /// // The unspecified address (`0.0.0.0`) + /// assert_eq!(Ipv4Addr::UNSPECIFIED.is_global(), false); + /// + /// // Addresses reserved for private use (`10.0.0.0/8`, `172.16.0.0/12`, 192.168.0.0/16) /// assert_eq!(Ipv4Addr::new(10, 254, 0, 0).is_global(), false); /// assert_eq!(Ipv4Addr::new(192, 168, 10, 65).is_global(), false); /// assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_global(), false); /// - /// // the 0.0.0.0/8 block is not global - /// assert_eq!(Ipv4Addr::new(0, 1, 2, 3).is_global(), false); - /// // in particular, the unspecified address is not global - /// assert_eq!(Ipv4Addr::new(0, 0, 0, 0).is_global(), false); + /// // Addresses in the shared address space (`100.64.0.0/10`) + /// assert_eq!(Ipv4Addr::new(100, 100, 0, 0).is_global(), false); /// - /// // the loopback address is not global - /// assert_eq!(Ipv4Addr::new(127, 0, 0, 1).is_global(), false); + /// // The loopback addresses (`127.0.0.0/8`) + /// assert_eq!(Ipv4Addr::LOCALHOST.is_global(), false); /// - /// // link local addresses are not global + /// // Link-local addresses (`169.254.0.0/16`) /// assert_eq!(Ipv4Addr::new(169, 254, 45, 1).is_global(), false); /// - /// // the broadcast address is not global - /// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_global(), false); - /// - /// // the address space designated for documentation is not global + /// // Addresses reserved for documentation (`192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`) /// assert_eq!(Ipv4Addr::new(192, 0, 2, 255).is_global(), false); /// assert_eq!(Ipv4Addr::new(198, 51, 100, 65).is_global(), false); /// assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_global(), false); /// - /// // shared addresses are not global - /// assert_eq!(Ipv4Addr::new(100, 100, 0, 0).is_global(), false); - /// - /// // addresses reserved for protocol assignment are not global - /// assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_global(), false); - /// assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_global(), false); + /// // Addresses reserved for benchmarking (`198.18.0.0/15`) + /// assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_global(), false); /// - /// // addresses reserved for future use are not global + /// // Reserved addresses (`240.0.0.0/4`) /// assert_eq!(Ipv4Addr::new(250, 10, 20, 30).is_global(), false); /// - /// // addresses reserved for network devices benchmarking are not global - /// assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_global(), false); + /// // The broadcast address (`255.255.255.255`) + /// assert_eq!(Ipv4Addr::BROADCAST.is_global(), false); /// - /// // All the other addresses are global - /// assert_eq!(Ipv4Addr::new(1, 1, 1, 1).is_global(), true); - /// assert_eq!(Ipv4Addr::new(80, 9, 12, 3).is_global(), true); + /// // For a complete overview see the IANA IPv4 Special-Purpose Address Registry. /// ``` #[cfg_attr( staged_api, @@ -739,25 +747,17 @@ impl Ipv4Addr { #[must_use] #[inline] pub const fn is_global(&self) -> bool { - // check if this address is 192.0.0.9 or 192.0.0.10. These addresses are the only two - // globally routable addresses in the 192.0.0.0/24 range. - if u32::from_be_bytes(self.octets()) == 0xc0000009 - || u32::from_be_bytes(self.octets()) == 0xc000000a - { - return true; - } - !self.is_private() - && !self.is_loopback() - && !self.is_link_local() - && !self.is_broadcast() - && !self.is_documentation() - && !self.is_shared() + !(self.octets()[0] == 0 // "This network" + || self.is_private() + || self.is_shared() + || self.is_loopback() + || self.is_link_local() // addresses reserved for future protocols (`192.0.0.0/24`) - && !(self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0) - && !self.is_reserved() - && !self.is_benchmarking() - // Make sure the address is not in 0.0.0.0/8 - && self.octets()[0] != 0 + ||(self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0) + || self.is_documentation() + || self.is_benchmarking() + || self.is_reserved() + || self.is_broadcast()) } /// Returns [`true`] if this address is part of the Shared Address Space defined in @@ -871,7 +871,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -896,7 +896,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -927,18 +927,16 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] #[inline] pub const fn is_documentation(&self) -> bool { - match self.octets() { - [192, 0, 2, _] => true, - [198, 51, 100, _] => true, - [203, 0, 113, _] => true, - _ => false, - } + matches!( + self.octets(), + [192, 0, 2, _] | [198, 51, 100, _] | [203, 0, 113, _] + ) } /// Converts this address to an [IPv4-compatible] [`IPv6` address]. @@ -963,7 +961,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use = "this returns the result of the operation, \ @@ -972,7 +970,7 @@ impl Ipv4Addr { pub const fn to_ipv6_compatible(&self) -> Ipv6Addr { let [a, b, c, d] = self.octets(); Ipv6Addr { - inner: in6_addr_new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d]), + octets: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, a, b, c, d], } } @@ -993,7 +991,7 @@ impl Ipv4Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv4", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use = "this returns the result of the operation, \ @@ -1002,7 +1000,7 @@ impl Ipv4Addr { pub const fn to_ipv6_mapped(&self) -> Ipv6Addr { let [a, b, c, d] = self.octets(); Ipv6Addr { - inner: in6_addr_new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, a, b, c, d]), + octets: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, a, b, c, d], } } } @@ -1051,22 +1049,6 @@ impl From<Ipv6Addr> for IpAddr { } } -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Clone for Ipv4Addr { - #[inline] - fn clone(&self) -> Ipv4Addr { - *self - } -} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl PartialEq for Ipv4Addr { - #[inline] - fn eq(&self, other: &Ipv4Addr) -> bool { - in_addr_s_addr(self.inner) == in_addr_s_addr(other.inner) - } -} - #[cfg_attr(staged_api, stable(feature = "ip_cmp", since = "1.16.0"))] impl PartialEq<Ipv4Addr> for IpAddr { #[inline] @@ -1090,21 +1072,6 @@ impl PartialEq<IpAddr> for Ipv4Addr { } #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Eq for Ipv4Addr {} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl hash::Hash for Ipv4Addr { - #[inline] - fn hash<H: hash::Hasher>(&self, s: &mut H) { - // NOTE: - // * hash in big endian order - // * in netbsd, `in_addr` has `repr(packed)`, we need to - // copy `s_addr` to avoid unsafe borrowing - { in_addr_s_addr(self.inner) }.hash(s) - } -} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] impl PartialOrd for Ipv4Addr { #[inline] fn partial_cmp(&self, other: &Ipv4Addr) -> Option<Ordering> { @@ -1138,8 +1105,7 @@ impl PartialOrd<IpAddr> for Ipv4Addr { impl Ord for Ipv4Addr { #[inline] fn cmp(&self, other: &Ipv4Addr) -> Ordering { - // Compare as native endian - u32::from_be(in_addr_s_addr(self.inner)).cmp(&u32::from_be(in_addr_s_addr(other.inner))) + self.octets.cmp(&other.octets) } } @@ -1152,13 +1118,12 @@ impl From<Ipv4Addr> for u32 { /// ``` /// use std::net::Ipv4Addr; /// - /// let addr = Ipv4Addr::new(0xca, 0xfe, 0xba, 0xbe); - /// assert_eq!(0xcafebabe, u32::from(addr)); + /// let addr = Ipv4Addr::new(0x12, 0x34, 0x56, 0x78); + /// assert_eq!(0x12345678, u32::from(addr)); /// ``` #[inline] fn from(ip: Ipv4Addr) -> u32 { - let ip = ip.octets(); - u32::from_be_bytes(ip) + u32::from_be_bytes(ip.octets) } } @@ -1171,12 +1136,14 @@ impl From<u32> for Ipv4Addr { /// ``` /// use std::net::Ipv4Addr; /// - /// let addr = Ipv4Addr::from(0xcafebabe); - /// assert_eq!(Ipv4Addr::new(0xca, 0xfe, 0xba, 0xbe), addr); + /// let addr = Ipv4Addr::from(0x12345678); + /// assert_eq!(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78), addr); /// ``` #[inline] fn from(ip: u32) -> Ipv4Addr { - Ipv4Addr::from(ip.to_be_bytes()) + Ipv4Addr { + octets: ip.to_be_bytes(), + } } } @@ -1194,7 +1161,7 @@ impl From<[u8; 4]> for Ipv4Addr { /// ``` #[inline] fn from(octets: [u8; 4]) -> Ipv4Addr { - Ipv4Addr::new(octets[0], octets[1], octets[2], octets[3]) + Ipv4Addr { octets } } } @@ -1230,7 +1197,7 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.32.0") + rustc_const_stable(feature = "const_ip_32", since = "1.32.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use] @@ -1249,9 +1216,7 @@ impl Ipv6Addr { Ipv6Addr { // All elements in `addr16` are big endian. // SAFETY: `[u16; 8]` is always safe to transmute to `[u8; 16]`. - // rustc_allow_const_fn_unstable: the transmute could be written as stable const - // code, but that leads to worse code generation (#75085) - inner: in6_addr_new(unsafe { transmute::<_, [u8; 16]>(addr16) }), + octets: unsafe { transmute::<_, [u8; 16]>(addr16) }, } } @@ -1293,18 +1258,15 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use] #[inline] pub const fn segments(&self) -> [u16; 8] { - // All elements in `s6_addr` must be big endian. + // All elements in `self.octets` must be big endian. // SAFETY: `[u8; 16]` is always safe to transmute to `[u16; 8]`. - // rustc_allow_const_fn_unstable: the transmute could be written as stable const code, but - // that leads to worse code generation (#75085) - let [a, b, c, d, e, f, g, h] = - unsafe { transmute::<_, [u16; 8]>(in6_addr_s6_addr(self.inner)) }; + let [a, b, c, d, e, f, g, h] = unsafe { transmute::<_, [u16; 8]>(self.octets) }; // We want native endian u16 [ u16::from_be(a), @@ -1334,7 +1296,7 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -1361,7 +1323,7 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -1370,13 +1332,33 @@ impl Ipv6Addr { u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets()) } - /// Returns [`true`] if the address appears to be globally routable. + /// Returns [`true`] if the address appears to be globally reachable + /// as specified by the [IANA IPv6 Special-Purpose Address Registry]. + /// Whether or not an address is practically reachable will depend on your network configuration. /// - /// The following return [`false`]: + /// Most IPv6 addresses are globally reachable; + /// unless they are specifically defined as *not* globally reachable. /// - /// - the loopback address - /// - link-local and unique local unicast addresses - /// - interface-, link-, realm-, admin- and site-local multicast addresses + /// Non-exhaustive list of notable addresses that are not globally reachable: + /// - The [unspecified address] ([`is_unspecified`](Ipv6Addr::is_unspecified)) + /// - The [loopback address] ([`is_loopback`](Ipv6Addr::is_loopback)) + /// - IPv4-mapped addresses + /// - Addresses reserved for benchmarking + /// - Addresses reserved for documentation ([`is_documentation`](Ipv6Addr::is_documentation)) + /// - Unique local addresses ([`is_unique_local`](Ipv6Addr::is_unique_local)) + /// - Unicast addresses with link-local scope ([`is_unicast_link_local`](Ipv6Addr::is_unicast_link_local)) + /// + /// For the complete overview of which addresses are globally reachable, see the table at the [IANA IPv6 Special-Purpose Address Registry]. + /// + /// Note that an address having global scope is not the same as being globally reachable, + /// and there is no direct relation between the two concepts: There exist addresses with global scope + /// that are not globally reachable (for example unique local addresses), + /// and addresses that are globally reachable without having global scope + /// (multicast addresses with non-global scope). + /// + /// [IANA IPv6 Special-Purpose Address Registry]: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml + /// [unspecified address]: Ipv6Addr::UNSPECIFIED + /// [loopback address]: Ipv6Addr::LOCALHOST /// /// # Examples /// @@ -1385,9 +1367,34 @@ impl Ipv6Addr { /// /// use std::net::Ipv6Addr; /// - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_global(), true); - /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_global(), false); - /// assert_eq!(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1).is_global(), true); + /// // Most IPv6 addresses are globally reachable: + /// assert_eq!(Ipv6Addr::new(0x26, 0, 0x1c9, 0, 0, 0xafc8, 0x10, 0x1).is_global(), true); + /// + /// // However some addresses have been assigned a special meaning + /// // that makes them not globally reachable. Some examples are: + /// + /// // The unspecified address (`::`) + /// assert_eq!(Ipv6Addr::UNSPECIFIED.is_global(), false); + /// + /// // The loopback address (`::1`) + /// assert_eq!(Ipv6Addr::LOCALHOST.is_global(), false); + /// + /// // IPv4-mapped addresses (`::ffff:0:0/96`) + /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_global(), false); + /// + /// // Addresses reserved for benchmarking (`2001:2::/48`) + /// assert_eq!(Ipv6Addr::new(0x2001, 2, 0, 0, 0, 0, 0, 1,).is_global(), false); + /// + /// // Addresses reserved for documentation (`2001:db8::/32`) + /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).is_global(), false); + /// + /// // Unique local addresses (`fc00::/7`) + /// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 1).is_global(), false); + /// + /// // Unicast addresses with link-local scope (`fe80::/10`) + /// assert_eq!(Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 1).is_global(), false); + /// + /// // For a complete overview see the IANA IPv6 Special-Purpose Address Registry. /// ``` #[cfg_attr( staged_api, @@ -1397,11 +1404,31 @@ impl Ipv6Addr { #[must_use] #[inline] pub const fn is_global(&self) -> bool { - match self.multicast_scope() { - Some(Ipv6MulticastScope::Global) => true, - None => self.is_unicast_global(), - _ => false, - } + !(self.is_unspecified() + || self.is_loopback() + // IPv4-mapped Address (`::ffff:0:0/96`) + || matches!(self.segments(), [0, 0, 0, 0, 0, 0xffff, _, _]) + // IPv4-IPv6 Translat. (`64:ff9b:1::/48`) + || matches!(self.segments(), [0x64, 0xff9b, 1, _, _, _, _, _]) + // Discard-Only Address Block (`100::/64`) + || matches!(self.segments(), [0x100, 0, 0, 0, _, _, _, _]) + // IETF Protocol Assignments (`2001::/23`) + || (matches!(self.segments(), [0x2001, b, _, _, _, _, _, _] if b < 0x200) + && !( + // Port Control Protocol Anycast (`2001:1::1`) + u128::from_be_bytes(self.octets()) == 0x2001_0001_0000_0000_0000_0000_0000_0001 + // Traversal Using Relays around NAT Anycast (`2001:1::2`) + || u128::from_be_bytes(self.octets()) == 0x2001_0001_0000_0000_0000_0000_0000_0002 + // AMT (`2001:3::/32`) + || matches!(self.segments(), [0x2001, 3, _, _, _, _, _, _]) + // AS112-v6 (`2001:4:112::/48`) + || matches!(self.segments(), [0x2001, 4, 0x112, _, _, _, _, _]) + // ORCHIDv2 (`2001:20::/28`) + || matches!(self.segments(), [0x2001, b, _, _, _, _, _, _] if b >= 0x20 && b <= 0x2F) + )) + || self.is_documentation() + || self.is_unique_local() + || self.is_unicast_link_local()) } /// Returns [`true`] if this is a unique local address (`fc00::/7`). @@ -1613,6 +1640,7 @@ impl Ipv6Addr { && !self.is_unique_local() && !self.is_unspecified() && !self.is_documentation() + && !self.is_benchmarking() } /// Returns the address's multicast scope if the address is multicast. @@ -1670,7 +1698,7 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(since = "1.7.0", feature = "ip_17"))] #[must_use] @@ -1692,8 +1720,6 @@ impl Ipv6Addr { /// # Examples /// /// ``` - /// #![feature(ip)] - /// /// use std::net::{Ipv4Addr, Ipv6Addr}; /// /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4_mapped(), None); @@ -1705,7 +1731,7 @@ impl Ipv6Addr { staged_api, rustc_const_unstable(feature = "const_ipv6", issue = "76205") )] - #[cfg_attr(staged_api, unstable(feature = "ip", issue = "27709"))] + #[cfg_attr(staged_api, stable(feature = "ipv6_to_ipv4_mapped", since = "1.63.0"))] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1723,7 +1749,10 @@ impl Ipv6Addr { /// or an [IPv4-mapped] address as defined in [IETF RFC 4291 section 2.5.5.2], /// otherwise returns [`None`]. /// - /// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d` + /// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`. Use + /// [`Ipv6Addr::to_ipv4_mapped`] to avoid this. + /// + /// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`. `::1` becomes `0.0.0.1`. /// All addresses *not* starting with either all zeroes or `::ffff` will return `None`. /// /// [`IPv4` address]: Ipv4Addr @@ -1745,7 +1774,7 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.50.0") + rustc_const_stable(feature = "const_ip_50", since = "1.50.0") )] #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] #[must_use = "this returns the result of the operation, \ @@ -1798,29 +1827,13 @@ impl Ipv6Addr { /// ``` #[cfg_attr( staged_api, - rustc_const_stable(feature = "const_ipv6", since = "1.32.0") + rustc_const_stable(feature = "const_ip_32", since = "1.32.0") )] #[cfg_attr(staged_api, stable(feature = "ipv6_to_octets", since = "1.12.0"))] #[must_use] #[inline] pub const fn octets(&self) -> [u8; 16] { - in6_addr_s6_addr(self.inner) - } -} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Clone for Ipv6Addr { - #[inline] - fn clone(&self) -> Ipv6Addr { - *self - } -} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl PartialEq for Ipv6Addr { - #[inline] - fn eq(&self, other: &Ipv6Addr) -> bool { - in6_addr_s6_addr(self.inner) == in6_addr_s6_addr(other.inner) + self.octets } } @@ -1847,17 +1860,6 @@ impl PartialEq<Ipv6Addr> for IpAddr { } #[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl Eq for Ipv6Addr {} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] -impl hash::Hash for Ipv6Addr { - #[inline] - fn hash<H: hash::Hasher>(&self, s: &mut H) { - in6_addr_s6_addr(self.inner).hash(s) - } -} - -#[cfg_attr(staged_api, stable(feature = "rust1", since = "1.0.0"))] impl PartialOrd for Ipv6Addr { #[inline] fn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering> { @@ -1912,8 +1914,7 @@ impl From<Ipv6Addr> for u128 { /// ``` #[inline] fn from(ip: Ipv6Addr) -> u128 { - let ip = ip.octets(); - u128::from_be_bytes(ip) + u128::from_be_bytes(ip.octets) } } #[cfg_attr(staged_api, stable(feature = "i128", since = "1.26.0"))] @@ -1964,9 +1965,7 @@ impl From<[u8; 16]> for Ipv6Addr { /// ``` #[inline] fn from(octets: [u8; 16]) -> Ipv6Addr { - Ipv6Addr { - inner: in6_addr_new(octets), - } + Ipv6Addr { octets } } } diff --git a/vendor/rustix/src/net/send_recv.rs b/vendor/rustix/src/net/send_recv.rs index 83ccc79d4..041077266 100644 --- a/vendor/rustix/src/net/send_recv.rs +++ b/vendor/rustix/src/net/send_recv.rs @@ -3,10 +3,10 @@ #[cfg(unix)] use crate::net::SocketAddrUnix; use crate::net::{SocketAddr, SocketAddrAny, SocketAddrV4, SocketAddrV6}; -use crate::{imp, io}; -use imp::fd::{AsFd, BorrowedFd}; +use crate::{backend, io}; +use backend::fd::{AsFd, BorrowedFd}; -pub use imp::net::send_recv::{RecvFlags, SendFlags}; +pub use backend::net::send_recv::{RecvFlags, SendFlags}; /// `recv(fd, buf, flags)`—Reads data from a socket. /// @@ -22,7 +22,7 @@ pub use imp::net::send_recv::{RecvFlags, SendFlags}; /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-recv #[inline] pub fn recv<Fd: AsFd>(fd: Fd, buf: &mut [u8], flags: RecvFlags) -> io::Result<usize> { - imp::net::syscalls::recv(fd.as_fd(), buf, flags) + backend::net::syscalls::recv(fd.as_fd(), buf, flags) } /// `send(fd, buf, flags)`—Writes data to a socket. @@ -39,7 +39,7 @@ pub fn recv<Fd: AsFd>(fd: Fd, buf: &mut [u8], flags: RecvFlags) -> io::Result<us /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send #[inline] pub fn send<Fd: AsFd>(fd: Fd, buf: &[u8], flags: SendFlags) -> io::Result<usize> { - imp::net::syscalls::send(fd.as_fd(), buf, flags) + backend::net::syscalls::send(fd.as_fd(), buf, flags) } /// `recvfrom(fd, buf, flags, addr, len)`—Reads data from a socket and @@ -61,7 +61,7 @@ pub fn recvfrom<Fd: AsFd>( buf: &mut [u8], flags: RecvFlags, ) -> io::Result<(usize, Option<SocketAddrAny>)> { - imp::net::syscalls::recvfrom(fd.as_fd(), buf, flags) + backend::net::syscalls::recvfrom(fd.as_fd(), buf, flags) } /// `sendto(fd, buf, flags, addr)`—Writes data to a socket to a specific IP @@ -93,8 +93,8 @@ fn _sendto( addr: &SocketAddr, ) -> io::Result<usize> { match addr { - SocketAddr::V4(v4) => imp::net::syscalls::sendto_v4(fd, buf, flags, v4), - SocketAddr::V6(v6) => imp::net::syscalls::sendto_v6(fd, buf, flags, v6), + SocketAddr::V4(v4) => backend::net::syscalls::sendto_v4(fd, buf, flags, v4), + SocketAddr::V6(v6) => backend::net::syscalls::sendto_v6(fd, buf, flags, v6), } } @@ -127,10 +127,10 @@ fn _sendto_any( addr: &SocketAddrAny, ) -> io::Result<usize> { match addr { - SocketAddrAny::V4(v4) => imp::net::syscalls::sendto_v4(fd, buf, flags, v4), - SocketAddrAny::V6(v6) => imp::net::syscalls::sendto_v6(fd, buf, flags, v6), + SocketAddrAny::V4(v4) => backend::net::syscalls::sendto_v4(fd, buf, flags, v4), + SocketAddrAny::V6(v6) => backend::net::syscalls::sendto_v6(fd, buf, flags, v6), #[cfg(unix)] - SocketAddrAny::Unix(unix) => imp::net::syscalls::sendto_unix(fd, buf, flags, unix), + SocketAddrAny::Unix(unix) => backend::net::syscalls::sendto_unix(fd, buf, flags, unix), } } @@ -155,7 +155,7 @@ pub fn sendto_v4<Fd: AsFd>( flags: SendFlags, addr: &SocketAddrV4, ) -> io::Result<usize> { - imp::net::syscalls::sendto_v4(fd.as_fd(), buf, flags, addr) + backend::net::syscalls::sendto_v4(fd.as_fd(), buf, flags, addr) } /// `sendto(fd, buf, flags, addr, sizeof(struct sockaddr_in6))`—Writes data @@ -179,7 +179,7 @@ pub fn sendto_v6<Fd: AsFd>( flags: SendFlags, addr: &SocketAddrV6, ) -> io::Result<usize> { - imp::net::syscalls::sendto_v6(fd.as_fd(), buf, flags, addr) + backend::net::syscalls::sendto_v6(fd.as_fd(), buf, flags, addr) } /// `sendto(fd, buf, flags, addr, sizeof(struct sockaddr_un))`—Writes data to @@ -204,7 +204,7 @@ pub fn sendto_unix<Fd: AsFd>( flags: SendFlags, addr: &SocketAddrUnix, ) -> io::Result<usize> { - imp::net::syscalls::sendto_unix(fd.as_fd(), buf, flags, addr) + backend::net::syscalls::sendto_unix(fd.as_fd(), buf, flags, addr) } // TODO: `recvmsg`, `sendmsg` diff --git a/vendor/rustix/src/net/socket.rs b/vendor/rustix/src/net/socket.rs index cd8f149f6..687022afe 100644 --- a/vendor/rustix/src/net/socket.rs +++ b/vendor/rustix/src/net/socket.rs @@ -1,11 +1,11 @@ -use crate::imp; -use crate::io::{self, OwnedFd}; +use crate::fd::OwnedFd; use crate::net::{SocketAddr, SocketAddrAny, SocketAddrV4, SocketAddrV6}; -use imp::fd::{AsFd, BorrowedFd}; +use crate::{backend, io}; +use backend::fd::{AsFd, BorrowedFd}; #[cfg(unix)] -pub use imp::net::addr::SocketAddrUnix; -pub use imp::net::types::{ +pub use backend::net::addr::SocketAddrUnix; +pub use backend::net::types::{ AcceptFlags, AddressFamily, Protocol, Shutdown, SocketFlags, SocketType, }; @@ -34,7 +34,7 @@ impl Default for Protocol { /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket #[inline] pub fn socket(domain: AddressFamily, type_: SocketType, protocol: Protocol) -> io::Result<OwnedFd> { - imp::net::syscalls::socket(domain, type_, protocol) + backend::net::syscalls::socket(domain, type_, protocol) } /// `socket_with(domain, type_ | flags, protocol)`—Creates a socket, with @@ -64,7 +64,7 @@ pub fn socket_with( flags: SocketFlags, protocol: Protocol, ) -> io::Result<OwnedFd> { - imp::net::syscalls::socket_with(domain, type_, flags, protocol) + backend::net::syscalls::socket_with(domain, type_, flags, protocol) } /// `bind(sockfd, addr)`—Binds a socket to an IP address. @@ -85,8 +85,8 @@ pub fn bind<Fd: AsFd>(sockfd: Fd, addr: &SocketAddr) -> io::Result<()> { fn _bind(sockfd: BorrowedFd<'_>, addr: &SocketAddr) -> io::Result<()> { match addr { - SocketAddr::V4(v4) => imp::net::syscalls::bind_v4(sockfd, v4), - SocketAddr::V6(v6) => imp::net::syscalls::bind_v6(sockfd, v6), + SocketAddr::V4(v4) => backend::net::syscalls::bind_v4(sockfd, v4), + SocketAddr::V6(v6) => backend::net::syscalls::bind_v6(sockfd, v6), } } @@ -109,10 +109,10 @@ pub fn bind_any<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrAny) -> io::Result<()> { fn _bind_any(sockfd: BorrowedFd<'_>, addr: &SocketAddrAny) -> io::Result<()> { match addr { - SocketAddrAny::V4(v4) => imp::net::syscalls::bind_v4(sockfd, v4), - SocketAddrAny::V6(v6) => imp::net::syscalls::bind_v6(sockfd, v6), + SocketAddrAny::V4(v4) => backend::net::syscalls::bind_v4(sockfd, v4), + SocketAddrAny::V6(v6) => backend::net::syscalls::bind_v6(sockfd, v6), #[cfg(unix)] - SocketAddrAny::Unix(unix) => imp::net::syscalls::bind_unix(sockfd, unix), + SocketAddrAny::Unix(unix) => backend::net::syscalls::bind_unix(sockfd, unix), } } @@ -132,7 +132,7 @@ fn _bind_any(sockfd: BorrowedFd<'_>, addr: &SocketAddrAny) -> io::Result<()> { #[inline] #[doc(alias = "bind")] pub fn bind_v4<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV4) -> io::Result<()> { - imp::net::syscalls::bind_v4(sockfd.as_fd(), addr) + backend::net::syscalls::bind_v4(sockfd.as_fd(), addr) } /// `bind(sockfd, addr, sizeof(struct sockaddr_in6))`—Binds a socket to an @@ -151,7 +151,7 @@ pub fn bind_v4<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV4) -> io::Result<()> { #[inline] #[doc(alias = "bind")] pub fn bind_v6<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV6) -> io::Result<()> { - imp::net::syscalls::bind_v6(sockfd.as_fd(), addr) + backend::net::syscalls::bind_v6(sockfd.as_fd(), addr) } /// `bind(sockfd, addr, sizeof(struct sockaddr_un))`—Binds a socket to a @@ -171,7 +171,7 @@ pub fn bind_v6<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV6) -> io::Result<()> { #[inline] #[doc(alias = "bind")] pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()> { - imp::net::syscalls::bind_unix(sockfd.as_fd(), addr) + backend::net::syscalls::bind_unix(sockfd.as_fd(), addr) } /// `connect(sockfd, addr)`—Initiates a connection to an IP address. @@ -192,8 +192,8 @@ pub fn connect<Fd: AsFd>(sockfd: Fd, addr: &SocketAddr) -> io::Result<()> { fn _connect(sockfd: BorrowedFd<'_>, addr: &SocketAddr) -> io::Result<()> { match addr { - SocketAddr::V4(v4) => imp::net::syscalls::connect_v4(sockfd, v4), - SocketAddr::V6(v6) => imp::net::syscalls::connect_v6(sockfd, v6), + SocketAddr::V4(v4) => backend::net::syscalls::connect_v4(sockfd, v4), + SocketAddr::V6(v6) => backend::net::syscalls::connect_v6(sockfd, v6), } } @@ -216,10 +216,10 @@ pub fn connect_any<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrAny) -> io::Result<()> fn _connect_any(sockfd: BorrowedFd<'_>, addr: &SocketAddrAny) -> io::Result<()> { match addr { - SocketAddrAny::V4(v4) => imp::net::syscalls::connect_v4(sockfd, v4), - SocketAddrAny::V6(v6) => imp::net::syscalls::connect_v6(sockfd, v6), + SocketAddrAny::V4(v4) => backend::net::syscalls::connect_v4(sockfd, v4), + SocketAddrAny::V6(v6) => backend::net::syscalls::connect_v6(sockfd, v6), #[cfg(unix)] - SocketAddrAny::Unix(unix) => imp::net::syscalls::connect_unix(sockfd, unix), + SocketAddrAny::Unix(unix) => backend::net::syscalls::connect_unix(sockfd, unix), } } @@ -239,7 +239,7 @@ fn _connect_any(sockfd: BorrowedFd<'_>, addr: &SocketAddrAny) -> io::Result<()> #[inline] #[doc(alias = "connect")] pub fn connect_v4<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV4) -> io::Result<()> { - imp::net::syscalls::connect_v4(sockfd.as_fd(), addr) + backend::net::syscalls::connect_v4(sockfd.as_fd(), addr) } /// `connect(sockfd, addr, sizeof(struct sockaddr_in6))`—Initiates a @@ -258,7 +258,7 @@ pub fn connect_v4<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV4) -> io::Result<()> { #[inline] #[doc(alias = "connect")] pub fn connect_v6<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV6) -> io::Result<()> { - imp::net::syscalls::connect_v6(sockfd.as_fd(), addr) + backend::net::syscalls::connect_v6(sockfd.as_fd(), addr) } /// `connect(sockfd, addr, sizeof(struct sockaddr_un))`—Initiates a @@ -278,7 +278,7 @@ pub fn connect_v6<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrV6) -> io::Result<()> { #[inline] #[doc(alias = "connect")] pub fn connect_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()> { - imp::net::syscalls::connect_unix(sockfd.as_fd(), addr) + backend::net::syscalls::connect_unix(sockfd.as_fd(), addr) } /// `listen(fd, backlog)`—Enables listening for incoming connections. @@ -295,7 +295,7 @@ pub fn connect_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<( /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen #[inline] pub fn listen<Fd: AsFd>(sockfd: Fd, backlog: i32) -> io::Result<()> { - imp::net::syscalls::listen(sockfd.as_fd(), backlog) + backend::net::syscalls::listen(sockfd.as_fd(), backlog) } /// `accept(fd, NULL, NULL)`—Accepts an incoming connection. @@ -319,7 +319,7 @@ pub fn listen<Fd: AsFd>(sockfd: Fd, backlog: i32) -> io::Result<()> { #[inline] #[doc(alias = "accept4")] pub fn accept<Fd: AsFd>(sockfd: Fd) -> io::Result<OwnedFd> { - imp::net::syscalls::accept(sockfd.as_fd()) + backend::net::syscalls::accept(sockfd.as_fd()) } /// `accept4(fd, NULL, NULL, flags)`—Accepts an incoming connection, with @@ -341,7 +341,7 @@ pub fn accept<Fd: AsFd>(sockfd: Fd) -> io::Result<OwnedFd> { #[inline] #[doc(alias = "accept4")] pub fn accept_with<Fd: AsFd>(sockfd: Fd, flags: AcceptFlags) -> io::Result<OwnedFd> { - imp::net::syscalls::accept_with(sockfd.as_fd(), flags) + backend::net::syscalls::accept_with(sockfd.as_fd(), flags) } /// `accept(fd, &addr, &len)`—Accepts an incoming connection and returns the @@ -362,7 +362,7 @@ pub fn accept_with<Fd: AsFd>(sockfd: Fd, flags: AcceptFlags) -> io::Result<Owned #[inline] #[doc(alias = "accept4")] pub fn acceptfrom<Fd: AsFd>(sockfd: Fd) -> io::Result<(OwnedFd, Option<SocketAddrAny>)> { - imp::net::syscalls::acceptfrom(sockfd.as_fd()) + backend::net::syscalls::acceptfrom(sockfd.as_fd()) } /// `accept4(fd, &addr, &len, flags)`—Accepts an incoming connection and @@ -383,7 +383,7 @@ pub fn acceptfrom_with<Fd: AsFd>( sockfd: Fd, flags: AcceptFlags, ) -> io::Result<(OwnedFd, Option<SocketAddrAny>)> { - imp::net::syscalls::acceptfrom_with(sockfd.as_fd(), flags) + backend::net::syscalls::acceptfrom_with(sockfd.as_fd(), flags) } /// `shutdown(fd, how)`—Closes the read and/or write sides of a stream. @@ -400,7 +400,7 @@ pub fn acceptfrom_with<Fd: AsFd>( /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-shutdown #[inline] pub fn shutdown<Fd: AsFd>(sockfd: Fd, how: Shutdown) -> io::Result<()> { - imp::net::syscalls::shutdown(sockfd.as_fd(), how) + backend::net::syscalls::shutdown(sockfd.as_fd(), how) } /// `getsockname(fd, addr, len)`—Returns the address a socket is bound to. @@ -417,7 +417,7 @@ pub fn shutdown<Fd: AsFd>(sockfd: Fd, how: Shutdown) -> io::Result<()> { /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockname #[inline] pub fn getsockname<Fd: AsFd>(sockfd: Fd) -> io::Result<SocketAddrAny> { - imp::net::syscalls::getsockname(sockfd.as_fd()) + backend::net::syscalls::getsockname(sockfd.as_fd()) } /// `getpeername(fd, addr, len)`—Returns the address a socket is connected @@ -435,5 +435,5 @@ pub fn getsockname<Fd: AsFd>(sockfd: Fd) -> io::Result<SocketAddrAny> { /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getpeername #[inline] pub fn getpeername<Fd: AsFd>(sockfd: Fd) -> io::Result<Option<SocketAddrAny>> { - imp::net::syscalls::getpeername(sockfd.as_fd()) + backend::net::syscalls::getpeername(sockfd.as_fd()) } diff --git a/vendor/rustix/src/net/socket_addr_any.rs b/vendor/rustix/src/net/socket_addr_any.rs index 4970dbf74..287c6c1ee 100644 --- a/vendor/rustix/src/net/socket_addr_any.rs +++ b/vendor/rustix/src/net/socket_addr_any.rs @@ -12,11 +12,11 @@ #[cfg(unix)] use crate::net::SocketAddrUnix; use crate::net::{AddressFamily, SocketAddrV4, SocketAddrV6}; -use crate::{imp, io}; +use crate::{backend, io}; #[cfg(feature = "std")] use core::fmt; -pub use imp::net::addr::SocketAddrStorage; +pub use backend::net::addr::SocketAddrStorage; /// `struct sockaddr_storage` as a Rust enum. #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] @@ -37,10 +37,10 @@ impl SocketAddrAny { #[inline] pub const fn address_family(&self) -> AddressFamily { match self { - SocketAddrAny::V4(_) => AddressFamily::INET, - SocketAddrAny::V6(_) => AddressFamily::INET6, + Self::V4(_) => AddressFamily::INET, + Self::V6(_) => AddressFamily::INET6, #[cfg(unix)] - SocketAddrAny::Unix(_) => AddressFamily::UNIX, + Self::Unix(_) => AddressFamily::UNIX, } } @@ -53,7 +53,7 @@ impl SocketAddrAny { /// `storage` must point to valid memory for encoding the socket /// address. pub unsafe fn write(&self, storage: *mut SocketAddrStorage) -> usize { - imp::net::write_sockaddr::write_sockaddr(self, storage) + backend::net::write_sockaddr::write_sockaddr(self, storage) } /// Reads a platform-specific encoding of a socket address from @@ -64,7 +64,7 @@ impl SocketAddrAny { /// `storage` must point to valid memory for decoding a socket /// address. pub unsafe fn read(storage: *const SocketAddrStorage, len: usize) -> io::Result<Self> { - imp::net::read_sockaddr::read_sockaddr(storage, len) + backend::net::read_sockaddr::read_sockaddr(storage, len) } } @@ -72,10 +72,10 @@ impl SocketAddrAny { impl fmt::Debug for SocketAddrAny { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - SocketAddrAny::V4(v4) => v4.fmt(fmt), - SocketAddrAny::V6(v6) => v6.fmt(fmt), + Self::V4(v4) => v4.fmt(fmt), + Self::V6(v6) => v6.fmt(fmt), #[cfg(unix)] - SocketAddrAny::Unix(unix) => unix.fmt(fmt), + Self::Unix(unix) => unix.fmt(fmt), } } } diff --git a/vendor/rustix/src/net/socketpair.rs b/vendor/rustix/src/net/socketpair.rs index 68a58f3e9..4a9568ce7 100644 --- a/vendor/rustix/src/net/socketpair.rs +++ b/vendor/rustix/src/net/socketpair.rs @@ -1,6 +1,6 @@ -use crate::imp; -use crate::io::{self, OwnedFd}; +use crate::fd::OwnedFd; use crate::net::{AddressFamily, Protocol, SocketFlags, SocketType}; +use crate::{backend, io}; /// `socketpair(domain, type_ | accept_flags, protocol)` /// @@ -17,5 +17,5 @@ pub fn socketpair( flags: SocketFlags, protocol: Protocol, ) -> io::Result<(OwnedFd, OwnedFd)> { - imp::net::syscalls::socketpair(domain, type_, flags, protocol) + backend::net::syscalls::socketpair(domain, type_, flags, protocol) } diff --git a/vendor/rustix/src/net/sockopt.rs b/vendor/rustix/src/net/sockopt.rs index f5b149b37..436d5bf86 100644 --- a/vendor/rustix/src/net/sockopt.rs +++ b/vendor/rustix/src/net/sockopt.rs @@ -7,11 +7,11 @@ #![doc(alias = "setsockopt")] use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; -use crate::{imp, io}; +use crate::{backend, io}; +use backend::fd::AsFd; use core::time::Duration; -use imp::fd::AsFd; -pub use imp::net::types::Timeout; +pub use backend::net::types::Timeout; /// `getsockopt(fd, SOL_SOCKET, SO_TYPE)`—Returns the type of a socket. /// @@ -32,7 +32,7 @@ pub use imp::net::types::Timeout; #[inline] #[doc(alias = "SO_TYPE")] pub fn get_socket_type<Fd: AsFd>(fd: Fd) -> io::Result<SocketType> { - imp::net::syscalls::sockopt::get_socket_type(fd.as_fd()) + backend::net::syscalls::sockopt::get_socket_type(fd.as_fd()) } /// `setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, value)` @@ -54,7 +54,7 @@ pub fn get_socket_type<Fd: AsFd>(fd: Fd) -> io::Result<SocketType> { #[inline] #[doc(alias = "SO_REUSEADDR")] pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_socket_reuseaddr(fd.as_fd(), value) + backend::net::syscalls::sockopt::set_socket_reuseaddr(fd.as_fd(), value) } /// `setsockopt(fd, SOL_SOCKET, SO_BROADCAST, broadcast)` @@ -76,7 +76,7 @@ pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> { #[inline] #[doc(alias = "SO_BROADCAST")] pub fn set_socket_broadcast<Fd: AsFd>(fd: Fd, broadcast: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_socket_broadcast(fd.as_fd(), broadcast) + backend::net::syscalls::sockopt::set_socket_broadcast(fd.as_fd(), broadcast) } /// `getsockopt(fd, SOL_SOCKET, SO_BROADCAST)` @@ -98,7 +98,7 @@ pub fn set_socket_broadcast<Fd: AsFd>(fd: Fd, broadcast: bool) -> io::Result<()> #[inline] #[doc(alias = "SO_BROADCAST")] pub fn get_socket_broadcast<Fd: AsFd>(fd: Fd) -> io::Result<bool> { - imp::net::syscalls::sockopt::get_socket_broadcast(fd.as_fd()) + backend::net::syscalls::sockopt::get_socket_broadcast(fd.as_fd()) } /// `setsockopt(fd, SOL_SOCKET, SO_LINGER, linger)` @@ -120,7 +120,7 @@ pub fn get_socket_broadcast<Fd: AsFd>(fd: Fd) -> io::Result<bool> { #[inline] #[doc(alias = "SO_LINGER")] pub fn set_socket_linger<Fd: AsFd>(fd: Fd, linger: Option<Duration>) -> io::Result<()> { - imp::net::syscalls::sockopt::set_socket_linger(fd.as_fd(), linger) + backend::net::syscalls::sockopt::set_socket_linger(fd.as_fd(), linger) } /// `getsockopt(fd, SOL_SOCKET, SO_LINGER)` @@ -142,7 +142,7 @@ pub fn set_socket_linger<Fd: AsFd>(fd: Fd, linger: Option<Duration>) -> io::Resu #[inline] #[doc(alias = "SO_LINGER")] pub fn get_socket_linger<Fd: AsFd>(fd: Fd) -> io::Result<Option<Duration>> { - imp::net::syscalls::sockopt::get_socket_linger(fd.as_fd()) + backend::net::syscalls::sockopt::get_socket_linger(fd.as_fd()) } /// `setsockopt(fd, SOL_SOCKET, SO_PASSCRED, passcred)` @@ -157,7 +157,7 @@ pub fn get_socket_linger<Fd: AsFd>(fd: Fd) -> io::Result<Option<Duration>> { #[inline] #[doc(alias = "SO_PASSCRED")] pub fn set_socket_passcred<Fd: AsFd>(fd: Fd, passcred: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_socket_passcred(fd.as_fd(), passcred) + backend::net::syscalls::sockopt::set_socket_passcred(fd.as_fd(), passcred) } /// `getsockopt(fd, SOL_SOCKET, SO_PASSCRED)` @@ -172,7 +172,7 @@ pub fn set_socket_passcred<Fd: AsFd>(fd: Fd, passcred: bool) -> io::Result<()> { #[inline] #[doc(alias = "SO_PASSCRED")] pub fn get_socket_passcred<Fd: AsFd>(fd: Fd) -> io::Result<bool> { - imp::net::syscalls::sockopt::get_socket_passcred(fd.as_fd()) + backend::net::syscalls::sockopt::get_socket_passcred(fd.as_fd()) } /// `setsockopt(fd, SOL_SOCKET, id, timeout)`—Set the sending @@ -200,7 +200,7 @@ pub fn set_socket_timeout<Fd: AsFd>( id: Timeout, timeout: Option<Duration>, ) -> io::Result<()> { - imp::net::syscalls::sockopt::set_socket_timeout(fd.as_fd(), id, timeout) + backend::net::syscalls::sockopt::set_socket_timeout(fd.as_fd(), id, timeout) } /// `getsockopt(fd, SOL_SOCKET, id)`—Get the sending or receiving timeout. @@ -223,7 +223,7 @@ pub fn set_socket_timeout<Fd: AsFd>( #[doc(alias = "SO_RCVTIMEO")] #[doc(alias = "SO_SNDTIMEO")] pub fn get_socket_timeout<Fd: AsFd>(fd: Fd, id: Timeout) -> io::Result<Option<Duration>> { - imp::net::syscalls::sockopt::get_socket_timeout(fd.as_fd(), id) + backend::net::syscalls::sockopt::get_socket_timeout(fd.as_fd(), id) } /// `setsockopt(fd, IPPROTO_IP, IP_TTL, ttl)` @@ -244,7 +244,7 @@ pub fn get_socket_timeout<Fd: AsFd>(fd: Fd, id: Timeout) -> io::Result<Option<Du #[inline] #[doc(alias = "IP_TTL")] pub fn set_ip_ttl<Fd: AsFd>(fd: Fd, ttl: u32) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ip_ttl(fd.as_fd(), ttl) + backend::net::syscalls::sockopt::set_ip_ttl(fd.as_fd(), ttl) } /// `getsockopt(fd, IPPROTO_IP, IP_TTL)` @@ -266,7 +266,7 @@ pub fn set_ip_ttl<Fd: AsFd>(fd: Fd, ttl: u32) -> io::Result<()> { #[inline] #[doc(alias = "IP_TTL")] pub fn get_ip_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - imp::net::syscalls::sockopt::get_ip_ttl(fd.as_fd()) + backend::net::syscalls::sockopt::get_ip_ttl(fd.as_fd()) } /// `setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, only_v6)` @@ -288,7 +288,7 @@ pub fn get_ip_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "IPV6_V6ONLY")] pub fn set_ipv6_v6only<Fd: AsFd>(fd: Fd, only_v6: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ipv6_v6only(fd.as_fd(), only_v6) + backend::net::syscalls::sockopt::set_ipv6_v6only(fd.as_fd(), only_v6) } /// `getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY)` @@ -310,7 +310,7 @@ pub fn set_ipv6_v6only<Fd: AsFd>(fd: Fd, only_v6: bool) -> io::Result<()> { #[inline] #[doc(alias = "IPV6_V6ONLY")] pub fn get_ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> { - imp::net::syscalls::sockopt::get_ipv6_v6only(fd.as_fd()) + backend::net::syscalls::sockopt::get_ipv6_v6only(fd.as_fd()) } /// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, multicast_loop)` @@ -332,7 +332,7 @@ pub fn get_ipv6_v6only<Fd: AsFd>(fd: Fd) -> io::Result<bool> { #[inline] #[doc(alias = "IP_MULTICAST_LOOP")] pub fn set_ip_multicast_loop<Fd: AsFd>(fd: Fd, multicast_loop: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ip_multicast_loop(fd.as_fd(), multicast_loop) + backend::net::syscalls::sockopt::set_ip_multicast_loop(fd.as_fd(), multicast_loop) } /// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP)` @@ -354,7 +354,7 @@ pub fn set_ip_multicast_loop<Fd: AsFd>(fd: Fd, multicast_loop: bool) -> io::Resu #[inline] #[doc(alias = "IP_MULTICAST_LOOP")] pub fn get_ip_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> { - imp::net::syscalls::sockopt::get_ip_multicast_loop(fd.as_fd()) + backend::net::syscalls::sockopt::get_ip_multicast_loop(fd.as_fd()) } /// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, multicast_ttl)` @@ -376,7 +376,7 @@ pub fn get_ip_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> { #[inline] #[doc(alias = "IP_MULTICAST_TTL")] pub fn set_ip_multicast_ttl<Fd: AsFd>(fd: Fd, multicast_ttl: u32) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ip_multicast_ttl(fd.as_fd(), multicast_ttl) + backend::net::syscalls::sockopt::set_ip_multicast_ttl(fd.as_fd(), multicast_ttl) } /// `getsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL)` @@ -398,7 +398,7 @@ pub fn set_ip_multicast_ttl<Fd: AsFd>(fd: Fd, multicast_ttl: u32) -> io::Result< #[inline] #[doc(alias = "IP_MULTICAST_TTL")] pub fn get_ip_multicast_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - imp::net::syscalls::sockopt::get_ip_multicast_ttl(fd.as_fd()) + backend::net::syscalls::sockopt::get_ip_multicast_ttl(fd.as_fd()) } /// `setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, multicast_loop)` @@ -420,7 +420,7 @@ pub fn get_ip_multicast_ttl<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "IPV6_MULTICAST_LOOP")] pub fn set_ipv6_multicast_loop<Fd: AsFd>(fd: Fd, multicast_loop: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ipv6_multicast_loop(fd.as_fd(), multicast_loop) + backend::net::syscalls::sockopt::set_ipv6_multicast_loop(fd.as_fd(), multicast_loop) } /// `getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP)` @@ -442,7 +442,51 @@ pub fn set_ipv6_multicast_loop<Fd: AsFd>(fd: Fd, multicast_loop: bool) -> io::Re #[inline] #[doc(alias = "IPV6_MULTICAST_LOOP")] pub fn get_ipv6_multicast_loop<Fd: AsFd>(fd: Fd) -> io::Result<bool> { - imp::net::syscalls::sockopt::get_ipv6_multicast_loop(fd.as_fd()) + backend::net::syscalls::sockopt::get_ipv6_multicast_loop(fd.as_fd()) +} + +/// `setsockopt(fd, IPPROTO_IP, IPV6_MULTICAST_HOPS, multicast_hops)` +/// +/// # References +/// - [POSIX `setsockopt`] +/// - [POSIX `netinet/in.h`] +/// - [Linux `setsockopt`] +/// - [Linux `ipv6`] +/// - [Winsock2 `setsockopt`] +/// - [Winsock2 `IPPROTO_IPV6` options] +/// +/// [POSIX `setsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html +/// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html +/// [Linux `setsockopt`]: https://man7.org/linux/man-pages/man2/setsockopt.2.html +/// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock2 `setsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt +/// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options +#[inline] +#[doc(alias = "IP_MULTICAST_TTL")] +pub fn set_ipv6_multicast_hops<Fd: AsFd>(fd: Fd, multicast_hops: u32) -> io::Result<()> { + backend::net::syscalls::sockopt::set_ipv6_multicast_hops(fd.as_fd(), multicast_hops) +} + +/// `getsockopt(fd, IPPROTO_IP, IPV6_MULTICAST_HOPS)` +/// +/// # References +/// - [POSIX `getsockopt`] +/// - [POSIX `netinet/in.h`] +/// - [Linux `getsockopt`] +/// - [Linux `ipv6`] +/// - [Winsock2 `getsockopt`] +/// - [Winsock2 `IPPROTO_IPV6` options] +/// +/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html +/// [POSIX `netinet/in.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html +/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html +/// [Linux `ipv6`]: https://man7.org/linux/man-pages/man7/ipv6.7.html +/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt +/// [Winsock2 `IPPROTO_IPV6` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options +#[inline] +#[doc(alias = "IP_MULTICAST_TTL")] +pub fn get_ipv6_multicast_hops<Fd: AsFd>(fd: Fd) -> io::Result<u32> { + backend::net::syscalls::sockopt::get_ipv6_multicast_hops(fd.as_fd()) } /// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, interface)` @@ -468,7 +512,7 @@ pub fn set_ip_add_membership<Fd: AsFd>( multiaddr: &Ipv4Addr, interface: &Ipv4Addr, ) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ip_add_membership(fd.as_fd(), multiaddr, interface) + backend::net::syscalls::sockopt::set_ip_add_membership(fd.as_fd(), multiaddr, interface) } /// `setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, multiaddr, interface)` @@ -497,7 +541,7 @@ pub fn set_ipv6_add_membership<Fd: AsFd>( multiaddr: &Ipv6Addr, interface: u32, ) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ipv6_add_membership(fd.as_fd(), multiaddr, interface) + backend::net::syscalls::sockopt::set_ipv6_add_membership(fd.as_fd(), multiaddr, interface) } /// `setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, multiaddr, interface)` @@ -523,7 +567,7 @@ pub fn set_ip_drop_membership<Fd: AsFd>( multiaddr: &Ipv4Addr, interface: &Ipv4Addr, ) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ip_drop_membership(fd.as_fd(), multiaddr, interface) + backend::net::syscalls::sockopt::set_ip_drop_membership(fd.as_fd(), multiaddr, interface) } /// `setsockopt(fd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, multiaddr, interface)` @@ -552,7 +596,7 @@ pub fn set_ipv6_drop_membership<Fd: AsFd>( multiaddr: &Ipv6Addr, interface: u32, ) -> io::Result<()> { - imp::net::syscalls::sockopt::set_ipv6_drop_membership(fd.as_fd(), multiaddr, interface) + backend::net::syscalls::sockopt::set_ipv6_drop_membership(fd.as_fd(), multiaddr, interface) } /// `setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, nodelay)` @@ -574,7 +618,7 @@ pub fn set_ipv6_drop_membership<Fd: AsFd>( #[inline] #[doc(alias = "TCP_NODELAY")] pub fn set_tcp_nodelay<Fd: AsFd>(fd: Fd, nodelay: bool) -> io::Result<()> { - imp::net::syscalls::sockopt::set_tcp_nodelay(fd.as_fd(), nodelay) + backend::net::syscalls::sockopt::set_tcp_nodelay(fd.as_fd(), nodelay) } /// `getsockopt(fd, IPPROTO_TCP, TCP_NODELAY)` @@ -596,5 +640,5 @@ pub fn set_tcp_nodelay<Fd: AsFd>(fd: Fd, nodelay: bool) -> io::Result<()> { #[inline] #[doc(alias = "TCP_NODELAY")] pub fn get_tcp_nodelay<Fd: AsFd>(fd: Fd) -> io::Result<bool> { - imp::net::syscalls::sockopt::get_tcp_nodelay(fd.as_fd()) + backend::net::syscalls::sockopt::get_tcp_nodelay(fd.as_fd()) } diff --git a/vendor/rustix/src/net/wsa.rs b/vendor/rustix/src/net/wsa.rs index e2a70c97b..3367ca95c 100644 --- a/vendor/rustix/src/net/wsa.rs +++ b/vendor/rustix/src/net/wsa.rs @@ -1,6 +1,6 @@ use crate::io; use core::mem::MaybeUninit; -use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSAData, WSAGetLastError, WSAStartup}; +use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSAGetLastError, WSAStartup, WSADATA}; /// `WSAStartup()`—Initialize process-wide Windows support for sockets. /// @@ -11,7 +11,7 @@ use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSAData, WSAGetLastErr /// - [Winsock2] /// /// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup -pub fn wsa_startup() -> io::Result<WSAData> { +pub fn wsa_startup() -> io::Result<WSADATA> { // Request version 2.2, which has been the latest version since far older // versions of Windows than we support here. For more information about // the version, see [here]. diff --git a/vendor/rustix/src/param/auxv.rs b/vendor/rustix/src/param/auxv.rs index 6aec061f7..03be2a29d 100644 --- a/vendor/rustix/src/param/auxv.rs +++ b/vendor/rustix/src/param/auxv.rs @@ -1,3 +1,4 @@ +use crate::backend; #[cfg(any( linux_raw, all( @@ -9,7 +10,6 @@ ) ))] use crate::ffi::CStr; -use crate::imp; /// `sysconf(_SC_PAGESIZE)`—Returns the process' page size. /// @@ -28,7 +28,7 @@ use crate::imp; #[doc(alias = "_SC_PAGE_SIZE")] #[doc(alias = "getpagesize")] pub fn page_size() -> usize { - imp::param::auxv::page_size() + backend::param::auxv::page_size() } /// `sysconf(_SC_CLK_TCK)`—Returns the process' clock ticks per second. @@ -43,7 +43,7 @@ pub fn page_size() -> usize { #[inline] #[doc(alias = "_SC_CLK_TCK")] pub fn clock_ticks_per_second() -> u64 { - imp::param::auxv::clock_ticks_per_second() + backend::param::auxv::clock_ticks_per_second() } /// `(getauxval(AT_HWCAP), getauxval(AT_HWCAP2)`—Returns the Linux "hwcap" @@ -68,7 +68,7 @@ pub fn clock_ticks_per_second() -> u64 { ))] #[inline] pub fn linux_hwcap() -> (usize, usize) { - imp::param::auxv::linux_hwcap() + backend::param::auxv::linux_hwcap() } /// `getauxval(AT_EXECFN)`—Returns the Linux "execfn" string. @@ -92,5 +92,5 @@ pub fn linux_hwcap() -> (usize, usize) { ))] #[inline] pub fn linux_execfn() -> &'static CStr { - imp::param::auxv::linux_execfn() + backend::param::auxv::linux_execfn() } diff --git a/vendor/rustix/src/param/init.rs b/vendor/rustix/src/param/init.rs index e66ff82bb..d261fabd2 100644 --- a/vendor/rustix/src/param/init.rs +++ b/vendor/rustix/src/param/init.rs @@ -7,7 +7,7 @@ //! operates on raw pointers. #![allow(unsafe_code)] -use crate::imp; +use crate::backend; /// Initialize process-wide state. /// @@ -19,5 +19,5 @@ use crate::imp; #[inline] #[doc(hidden)] pub unsafe fn init(envp: *mut *mut u8) { - imp::param::auxv::init(envp) + backend::param::auxv::init(envp) } diff --git a/vendor/rustix/src/param/mod.rs b/vendor/rustix/src/param/mod.rs index 5169d0a51..c47aca985 100644 --- a/vendor/rustix/src/param/mod.rs +++ b/vendor/rustix/src/param/mod.rs @@ -7,10 +7,7 @@ #[cfg(feature = "param")] mod auxv; -#[cfg(any( - target_vendor = "mustang", - not(any(target_env = "gnu", target_env = "musl")), -))] +#[cfg(target_vendor = "mustang")] mod init; #[cfg(feature = "param")] @@ -30,8 +27,5 @@ pub use auxv::page_size; ) ))] pub use auxv::{linux_execfn, linux_hwcap}; -#[cfg(any( - target_vendor = "mustang", - not(any(target_env = "gnu", target_env = "musl")), -))] +#[cfg(target_vendor = "mustang")] pub use init::init; diff --git a/vendor/rustix/src/path/arg.rs b/vendor/rustix/src/path/arg.rs index 7f66f71f2..0ea673d19 100644 --- a/vendor/rustix/src/path/arg.rs +++ b/vendor/rustix/src/path/arg.rs @@ -15,7 +15,8 @@ use alloc::borrow::Cow; use alloc::borrow::ToOwned; use alloc::string::String; use alloc::vec::Vec; -use core::str; +use core::mem::MaybeUninit; +use core::{ptr, slice, str}; #[cfg(feature = "std")] use std::ffi::{OsStr, OsString}; #[cfg(feature = "std")] @@ -931,6 +932,7 @@ impl Arg for DecInt { } /// Runs a closure with `bytes` passed in as a `&CStr`. +#[allow(unsafe_code, clippy::int_plus_one)] #[inline] fn with_c_str<T, F>(bytes: &[u8], f: F) -> io::Result<T> where @@ -946,10 +948,26 @@ where if bytes.len() >= SMALL_PATH_BUFFER_SIZE { return with_c_str_slow_path(bytes, f); } - let mut buffer: [u8; SMALL_PATH_BUFFER_SIZE] = [0_u8; SMALL_PATH_BUFFER_SIZE]; - // Copy the bytes in; the buffer already has zeros for the trailing NUL. - buffer[..bytes.len()].copy_from_slice(bytes); - f(CStr::from_bytes_with_nul(&buffer[..=bytes.len()]).map_err(|_cstr_err| io::Errno::INVAL)?) + + // Taken from + // https://github.com/rust-lang/rust/blob/a00f8ba7fcac1b27341679c51bf5a3271fa82df3/library/std/src/sys/common/small_c_string.rs + let mut buf = MaybeUninit::<[u8; SMALL_PATH_BUFFER_SIZE]>::uninit(); + let buf_ptr = buf.as_mut_ptr() as *mut u8; + + // SAFETY: bytes.len() < SMALL_PATH_BUFFER_SIZE which means we have space for + // bytes.len() + 1 u8s: + debug_assert!(bytes.len() + 1 <= SMALL_PATH_BUFFER_SIZE); + unsafe { + ptr::copy_nonoverlapping(bytes.as_ptr(), buf_ptr, bytes.len()); + buf_ptr.add(bytes.len()).write(0); + } + + // SAFETY: we just wrote the bytes above and they will remain valid for the + // duration of f b/c buf doesn't get dropped until the end of the function. + match CStr::from_bytes_with_nul(unsafe { slice::from_raw_parts(buf_ptr, bytes.len() + 1) }) { + Ok(s) => f(s), + Err(_) => Err(io::Errno::INVAL), + } } /// The slow path which handles any length. In theory OS's only support up diff --git a/vendor/rustix/src/path/dec_int.rs b/vendor/rustix/src/path/dec_int.rs index 4006fb06c..d0975694b 100644 --- a/vendor/rustix/src/path/dec_int.rs +++ b/vendor/rustix/src/path/dec_int.rs @@ -6,8 +6,8 @@ //! `str::from_utf8_unchecked`on the buffer that it filled itself. #![allow(unsafe_code)] +use crate::backend::fd::{AsFd, AsRawFd}; use crate::ffi::CStr; -use crate::imp::fd::{AsFd, AsRawFd}; #[cfg(feature = "std")] use core::fmt; use core::fmt::Write; diff --git a/vendor/rustix/src/process/chdir.rs b/vendor/rustix/src/process/chdir.rs index d8e251074..4951e5670 100644 --- a/vendor/rustix/src/process/chdir.rs +++ b/vendor/rustix/src/process/chdir.rs @@ -1,9 +1,9 @@ use crate::ffi::CString; use crate::path::SMALL_PATH_BUFFER_SIZE; -use crate::{imp, io, path}; +use crate::{backend, io, path}; use alloc::vec::Vec; #[cfg(not(target_os = "fuchsia"))] -use imp::fd::AsFd; +use backend::fd::AsFd; /// `chdir(path)`—Change the current working directory. /// @@ -15,7 +15,7 @@ use imp::fd::AsFd; /// [Linux]: https://man7.org/linux/man-pages/man2/chdir.2.html #[inline] pub fn chdir<P: path::Arg>(path: P) -> io::Result<()> { - path.into_with_c_str(imp::process::syscalls::chdir) + path.into_with_c_str(backend::process::syscalls::chdir) } /// `fchdir(fd)`—Change the current working directory. @@ -29,7 +29,7 @@ pub fn chdir<P: path::Arg>(path: P) -> io::Result<()> { #[cfg(not(target_os = "fuchsia"))] #[inline] pub fn fchdir<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::process::syscalls::fchdir(fd.as_fd()) + backend::process::syscalls::fchdir(fd.as_fd()) } /// `getcwd()`—Return the current working directory. @@ -56,7 +56,7 @@ fn _getcwd(mut buffer: Vec<u8>) -> io::Result<CString> { buffer.resize(buffer.capacity(), 0_u8); loop { - match imp::process::syscalls::getcwd(&mut buffer) { + match backend::process::syscalls::getcwd(&mut buffer) { Err(io::Errno::RANGE) => { buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially buffer.resize(buffer.capacity(), 0_u8); diff --git a/vendor/rustix/src/process/exit.rs b/vendor/rustix/src/process/exit.rs index 26a2340ab..56db99b4f 100644 --- a/vendor/rustix/src/process/exit.rs +++ b/vendor/rustix/src/process/exit.rs @@ -1,4 +1,4 @@ -use crate::imp; +use crate::backend; /// `EXIT_SUCCESS` for use with [`exit`]. /// @@ -10,7 +10,7 @@ use crate::imp; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html /// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html -pub const EXIT_SUCCESS: i32 = imp::process::types::EXIT_SUCCESS; +pub const EXIT_SUCCESS: i32 = backend::process::types::EXIT_SUCCESS; /// `EXIT_FAILURE` for use with [`exit`]. /// @@ -22,7 +22,7 @@ pub const EXIT_SUCCESS: i32 = imp::process::types::EXIT_SUCCESS; /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdlib.h.html /// [Linux]: https://man7.org/linux/man-pages/man3/exit.3.html -pub const EXIT_FAILURE: i32 = imp::process::types::EXIT_FAILURE; +pub const EXIT_FAILURE: i32 = backend::process::types::EXIT_FAILURE; /// The exit status used by a process terminated with `SIGABRT` signal. /// @@ -31,4 +31,4 @@ pub const EXIT_FAILURE: i32 = imp::process::types::EXIT_FAILURE; /// /// [Linux]: https://tldp.org/LDP/abs/html/exitcodes.html #[cfg(not(target_os = "wasi"))] -pub const EXIT_SIGNALED_SIGABRT: i32 = imp::process::types::EXIT_SIGNALED_SIGABRT; +pub const EXIT_SIGNALED_SIGABRT: i32 = backend::process::types::EXIT_SIGNALED_SIGABRT; diff --git a/vendor/rustix/src/process/id.rs b/vendor/rustix/src/process/id.rs index 5f6ff5bfb..e7fff7e53 100644 --- a/vendor/rustix/src/process/id.rs +++ b/vendor/rustix/src/process/id.rs @@ -7,21 +7,21 @@ //! integer values. #![allow(unsafe_code)] -use crate::{imp, io}; +use crate::{backend, io}; #[cfg(any(target_os = "android", target_os = "linux"))] -use imp::process::types::RawCpuid; +use backend::process::types::RawCpuid; /// The raw integer value of a Unix user ID. -pub use imp::process::types::RawUid; +pub use backend::process::types::RawUid; /// The raw integer value of a Unix group ID. -pub use imp::process::types::RawGid; +pub use backend::process::types::RawGid; /// The raw integer value of a Unix process ID. -pub use imp::process::types::RawPid; +pub use backend::process::types::RawPid; /// The raw integer value of a Unix process ID. -pub use imp::process::types::RawNonZeroPid; +pub use backend::process::types::RawNonZeroPid; /// `uid_t`—A Unix user ID. #[repr(transparent)] @@ -194,7 +194,7 @@ impl Cpuid { #[inline] #[must_use] pub fn getuid() -> Uid { - imp::process::syscalls::getuid() + backend::process::syscalls::getuid() } /// `geteuid()`—Returns the process' effective user ID. @@ -208,7 +208,7 @@ pub fn getuid() -> Uid { #[inline] #[must_use] pub fn geteuid() -> Uid { - imp::process::syscalls::geteuid() + backend::process::syscalls::geteuid() } /// `getgid()`—Returns the process' real group ID. @@ -222,7 +222,7 @@ pub fn geteuid() -> Uid { #[inline] #[must_use] pub fn getgid() -> Gid { - imp::process::syscalls::getgid() + backend::process::syscalls::getgid() } /// `getegid()`—Returns the process' effective group ID. @@ -236,7 +236,7 @@ pub fn getgid() -> Gid { #[inline] #[must_use] pub fn getegid() -> Gid { - imp::process::syscalls::getegid() + backend::process::syscalls::getegid() } /// `getpid()`—Returns the process' ID. @@ -250,7 +250,7 @@ pub fn getegid() -> Gid { #[inline] #[must_use] pub fn getpid() -> Pid { - imp::process::syscalls::getpid() + backend::process::syscalls::getpid() } /// `getppid()`—Returns the parent process' ID. @@ -264,7 +264,34 @@ pub fn getpid() -> Pid { #[inline] #[must_use] pub fn getppid() -> Option<Pid> { - imp::process::syscalls::getppid() + backend::process::syscalls::getppid() +} + +/// `getpgid(pid)`—Returns the process group ID of the given process. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgid.html +/// [Linux]: https://man7.org/linux/man-pages/man2/getpgid.2.html +#[inline] +pub fn getpgid(pid: Option<Pid>) -> io::Result<Pid> { + backend::process::syscalls::getpgid(pid) +} + +/// `getpgrp()`—Returns the process' group ID. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgrp.html +/// [Linux]: https://man7.org/linux/man-pages/man2/getpgrp.2.html +#[inline] +#[must_use] +pub fn getpgrp() -> Pid { + backend::process::syscalls::getpgrp() } /// `setsid()`—Create a new session. @@ -277,7 +304,7 @@ pub fn getppid() -> Option<Pid> { /// [Linux]: https://man7.org/linux/man-pages/man2/setsid.2.html #[inline] pub fn setsid() -> io::Result<Pid> { - imp::process::syscalls::setsid() + backend::process::syscalls::setsid() } // translate_fchown_args returns the raw value of the IDs. In case of `None` diff --git a/vendor/rustix/src/process/kill.rs b/vendor/rustix/src/process/kill.rs index d8daaf8da..69cfba261 100644 --- a/vendor/rustix/src/process/kill.rs +++ b/vendor/rustix/src/process/kill.rs @@ -1,7 +1,7 @@ use crate::process::Pid; -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::process::types::Signal; +pub use backend::process::types::Signal; /// `kill(pid, sig)`—Sends a signal to a process. /// @@ -14,7 +14,7 @@ pub use imp::process::types::Signal; #[inline] #[doc(alias = "kill")] pub fn kill_process(pid: Pid, sig: Signal) -> io::Result<()> { - imp::process::syscalls::kill_process(pid, sig) + backend::process::syscalls::kill_process(pid, sig) } /// `kill(-pid, sig)`—Sends a signal to all processes in a process group. @@ -32,7 +32,7 @@ pub fn kill_process(pid: Pid, sig: Signal) -> io::Result<()> { #[inline] #[doc(alias = "kill")] pub fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> { - imp::process::syscalls::kill_process_group(pid, sig) + backend::process::syscalls::kill_process_group(pid, sig) } /// `kill(0, sig)`—Sends a signal to all processes in the current process @@ -47,5 +47,5 @@ pub fn kill_process_group(pid: Pid, sig: Signal) -> io::Result<()> { #[inline] #[doc(alias = "kill")] pub fn kill_current_process_group(sig: Signal) -> io::Result<()> { - imp::process::syscalls::kill_current_process_group(sig) + backend::process::syscalls::kill_current_process_group(sig) } diff --git a/vendor/rustix/src/process/membarrier.rs b/vendor/rustix/src/process/membarrier.rs index 0062f273b..b64deb82e 100644 --- a/vendor/rustix/src/process/membarrier.rs +++ b/vendor/rustix/src/process/membarrier.rs @@ -7,9 +7,9 @@ #![allow(unsafe_code)] use crate::process::Cpuid; -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::process::types::MembarrierCommand; +pub use backend::process::types::MembarrierCommand; #[cfg(any(target_os = "android", target_os = "linux"))] bitflags::bitflags! { @@ -66,7 +66,7 @@ impl MembarrierQuery { #[inline] #[doc(alias = "MEMBARRIER_CMD_QUERY")] pub fn membarrier_query() -> MembarrierQuery { - imp::process::syscalls::membarrier_query() + backend::process::syscalls::membarrier_query() } /// `membarrier(cmd, 0, 0)`—Perform a memory barrier. @@ -77,7 +77,7 @@ pub fn membarrier_query() -> MembarrierQuery { /// [Linux]: https://man7.org/linux/man-pages/man2/membarrier.2.html #[inline] pub fn membarrier(cmd: MembarrierCommand) -> io::Result<()> { - imp::process::syscalls::membarrier(cmd) + backend::process::syscalls::membarrier(cmd) } /// `membarrier(cmd, MEMBARRIER_CMD_FLAG_CPU, cpu)`—Perform a memory barrier @@ -89,5 +89,5 @@ pub fn membarrier(cmd: MembarrierCommand) -> io::Result<()> { /// [Linux]: https://man7.org/linux/man-pages/man2/membarrier.2.html #[inline] pub fn membarrier_cpu(cmd: MembarrierCommand, cpu: Cpuid) -> io::Result<()> { - imp::process::syscalls::membarrier_cpu(cmd, cpu) + backend::process::syscalls::membarrier_cpu(cmd, cpu) } diff --git a/vendor/rustix/src/process/mod.rs b/vendor/rustix/src/process/mod.rs index 45673c0ea..e6baa1935 100644 --- a/vendor/rustix/src/process/mod.rs +++ b/vendor/rustix/src/process/mod.rs @@ -9,8 +9,12 @@ mod id; mod kill; #[cfg(any(target_os = "android", target_os = "linux"))] mod membarrier; +#[cfg(any(target_os = "android", target_os = "linux"))] +mod prctl; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] // WASI doesn't have [gs]etpriority. mod priority; +#[cfg(target_os = "freebsd")] +mod procctl; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] mod rlimit; #[cfg(any( @@ -39,8 +43,8 @@ pub use exit::{EXIT_FAILURE, EXIT_SUCCESS}; pub use id::Cpuid; #[cfg(not(target_os = "wasi"))] pub use id::{ - getegid, geteuid, getgid, getpid, getppid, getuid, setsid, Gid, Pid, RawGid, RawNonZeroPid, - RawPid, RawUid, Uid, + getegid, geteuid, getgid, getpgid, getpgrp, getpid, getppid, getuid, setsid, Gid, Pid, RawGid, + RawNonZeroPid, RawPid, RawUid, Uid, }; #[cfg(not(target_os = "wasi"))] pub use kill::{kill_current_process_group, kill_process, kill_process_group, Signal}; @@ -48,6 +52,8 @@ pub use kill::{kill_current_process_group, kill_process, kill_process_group, Sig pub use membarrier::{ membarrier, membarrier_cpu, membarrier_query, MembarrierCommand, MembarrierQuery, }; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use prctl::*; #[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))] pub use priority::nice; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] @@ -55,6 +61,8 @@ pub use priority::{ getpriority_pgrp, getpriority_process, getpriority_user, setpriority_pgrp, setpriority_process, setpriority_user, }; +#[cfg(target_os = "freebsd")] +pub use procctl::*; #[cfg(any(target_os = "android", target_os = "linux"))] pub use rlimit::prlimit; #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))] @@ -73,4 +81,5 @@ pub use uname::{uname, Uname}; pub use wait::{wait, waitpid, WaitOptions, WaitStatus}; #[cfg(not(target_os = "wasi"))] +#[cfg(feature = "fs")] pub(crate) use id::translate_fchown_args; diff --git a/vendor/rustix/src/process/prctl.rs b/vendor/rustix/src/process/prctl.rs new file mode 100644 index 000000000..49927be25 --- /dev/null +++ b/vendor/rustix/src/process/prctl.rs @@ -0,0 +1,1120 @@ +//! Bindings for the Linux `prctl` system call. +//! +//! There are similarities (but also differences) with FreeBSD's `procctl` system call, whose +//! interface is located in the `procctl.rs` file. + +#![allow(unsafe_code)] + +use core::convert::{TryFrom, TryInto}; +use core::mem::MaybeUninit; +use core::ptr::NonNull; +use core::{mem, ptr}; + +use bitflags::bitflags; + +use crate::backend::c::{c_int, c_uint, c_void}; +use crate::backend::process::syscalls; +use crate::backend::process::types::Signal; +use crate::fd::{AsRawFd, BorrowedFd}; +use crate::ffi::CStr; +use crate::io; +use crate::process::{Pid, RawPid}; + +// +// Helper functions. +// + +#[inline] +pub(crate) unsafe fn prctl_1arg(option: c_int) -> io::Result<c_int> { + const NULL: *mut c_void = ptr::null_mut(); + syscalls::prctl(option, NULL, NULL, NULL, NULL) +} + +#[inline] +pub(crate) unsafe fn prctl_2args(option: c_int, arg2: *mut c_void) -> io::Result<c_int> { + const NULL: *mut c_void = ptr::null_mut(); + syscalls::prctl(option, arg2, NULL, NULL, NULL) +} + +#[inline] +pub(crate) unsafe fn prctl_3args( + option: c_int, + arg2: *mut c_void, + arg3: *mut c_void, +) -> io::Result<c_int> { + syscalls::prctl(option, arg2, arg3, ptr::null_mut(), ptr::null_mut()) +} + +#[inline] +pub(crate) unsafe fn prctl_get_at_arg2_optional<P>(option: i32) -> io::Result<P> { + let mut value: MaybeUninit<P> = MaybeUninit::uninit(); + prctl_2args(option, value.as_mut_ptr().cast())?; + Ok(value.assume_init()) +} + +#[inline] +pub(crate) unsafe fn prctl_get_at_arg2<P, T>(option: i32) -> io::Result<T> +where + P: Default, + T: TryFrom<P, Error = io::Errno>, +{ + let mut value: P = Default::default(); + prctl_2args(option, ((&mut value) as *mut P).cast())?; + TryFrom::try_from(value) +} + +// +// PR_GET_PDEATHSIG/PR_SET_PDEATHSIG +// + +const PR_GET_PDEATHSIG: c_int = 2; + +/// Get the current value of the parent process death signal. +/// +/// # References +/// - [Linux: `prctl(PR_GET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`] +/// +/// [Linux: `prctl(PR_GET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn parent_process_death_signal() -> io::Result<Option<Signal>> { + unsafe { prctl_get_at_arg2_optional::<c_int>(PR_GET_PDEATHSIG) }.map(Signal::from_raw) +} + +const PR_SET_PDEATHSIG: c_int = 1; + +/// Set the parent-death signal of the calling process. +/// +/// # References +/// - [Linux: `prctl(PR_SET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`] +/// +/// [Linux: `prctl(PR_SET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn set_parent_process_death_signal(signal: Option<Signal>) -> io::Result<()> { + let signal = signal.map_or(0_usize, |signal| signal as usize); + unsafe { prctl_2args(PR_SET_PDEATHSIG, signal as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_DUMPABLE/PR_SET_DUMPABLE +// + +const PR_GET_DUMPABLE: c_int = 3; + +const SUID_DUMP_DISABLE: i32 = 0; +const SUID_DUMP_USER: i32 = 1; +const SUID_DUMP_ROOT: i32 = 2; + +/// `SUID_DUMP_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(i32)] +pub enum DumpableBehavior { + /// Not dumpable. + NotDumpable = SUID_DUMP_DISABLE, + /// Dumpable. + Dumpable = SUID_DUMP_USER, + /// Dumpable but only readable by root. + DumpableReadableOnlyByRoot = SUID_DUMP_ROOT, +} + +impl TryFrom<i32> for DumpableBehavior { + type Error = io::Errno; + + fn try_from(value: i32) -> Result<Self, Self::Error> { + match value { + SUID_DUMP_DISABLE => Ok(Self::NotDumpable), + SUID_DUMP_USER => Ok(Self::Dumpable), + SUID_DUMP_ROOT => Ok(Self::DumpableReadableOnlyByRoot), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get the current state of the calling process's `dumpable` attribute. +/// +/// # References +/// - [`prctl(PR_GET_DUMPABLE,...)`] +/// +/// [`prctl(PR_GET_DUMPABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn dumpable_behavior() -> io::Result<DumpableBehavior> { + unsafe { prctl_1arg(PR_GET_DUMPABLE) }.and_then(TryInto::try_into) +} + +const PR_SET_DUMPABLE: c_int = 4; + +/// Set the state of the `dumpable` attribute, which determines whether the process can be traced +/// and whether core dumps are produced for the calling process upon delivery of a signal whose +/// default behavior is to produce a core dump. +/// +/// A similar function with the same name is available on FreeBSD (as part of the `procctl` +/// interface), but it has an extra argument which allows to select a process other then the +/// current process. +/// +/// # References +/// - [`prctl(PR_SET_DUMPABLE,...)`] +/// +/// [`prctl(PR_SET_DUMPABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_dumpable_behavior(config: DumpableBehavior) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_DUMPABLE, config as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_UNALIGN/PR_SET_UNALIGN +// + +const PR_GET_UNALIGN: c_int = 5; + +bitflags! { + /// `PR_UNALIGN_*`. + pub struct UnalignedAccessControl: u32 { + /// Silently fix up unaligned user accesses. + const NO_PRINT = 1; + /// Generate `SIGBUS` on unaligned user access. + const SIGBUS = 2; + } +} + +/// Get unaligned access control bits. +/// +/// # References +/// - [`prctl(PR_GET_UNALIGN,...)`] +/// +/// [`prctl(PR_GET_UNALIGN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn unaligned_access_control() -> io::Result<UnalignedAccessControl> { + let r = unsafe { prctl_get_at_arg2_optional::<c_uint>(PR_GET_UNALIGN)? }; + UnalignedAccessControl::from_bits(r).ok_or(io::Errno::RANGE) +} + +const PR_SET_UNALIGN: c_int = 6; + +/// Set unaligned access control bits. +/// +/// # References +/// - [`prctl(PR_SET_UNALIGN,...)`] +/// +/// [`prctl(PR_SET_UNALIGN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_unaligned_access_control(config: UnalignedAccessControl) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_UNALIGN, config.bits() as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_FPEMU/PR_SET_FPEMU +// + +const PR_GET_FPEMU: c_int = 9; + +bitflags! { + /// `PR_FPEMU_*`. + pub struct FloatingPointEmulationControl: u32 { + /// Silently emulate floating point operations accesses. + const NO_PRINT = 1; + /// Don't emulate floating point operations, send `SIGFPE` instead. + const SIGFPE = 2; + } +} + +/// Get floating point emulation control bits. +/// +/// # References +/// - [`prctl(PR_GET_FPEMU,...)`] +/// +/// [`prctl(PR_GET_FPEMU,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn floating_point_emulation_control() -> io::Result<FloatingPointEmulationControl> { + let r = unsafe { prctl_get_at_arg2_optional::<c_uint>(PR_GET_FPEMU)? }; + FloatingPointEmulationControl::from_bits(r).ok_or(io::Errno::RANGE) +} + +const PR_SET_FPEMU: c_int = 10; + +/// Set floating point emulation control bits. +/// +/// # References +/// - [`prctl(PR_SET_FPEMU,...)`] +/// +/// [`prctl(PR_SET_FPEMU,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_floating_point_emulation_control( + config: FloatingPointEmulationControl, +) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_FPEMU, config.bits() as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_FPEXC/PR_SET_FPEXC +// + +const PR_GET_FPEXC: c_int = 11; + +bitflags! { + /// Zero means floating point exceptions are disabled. + pub struct FloatingPointExceptionMode: u32 { + /// Async non-recoverable exception mode. + const NONRECOV = 1; + /// Async recoverable exception mode. + const ASYNC = 2; + /// Precise exception mode. + const PRECISE = 3; + + /// Use FPEXC for floating point exception enables. + const SW_ENABLE = 0x80; + /// Floating point divide by zero. + const DIV = 0x01_0000; + /// Floating point overflow. + const OVF = 0x02_0000; + /// Floating point underflow. + const UND = 0x04_0000; + /// Floating point inexact result. + const RES = 0x08_0000; + /// Floating point invalid operation. + const INV = 0x10_0000; + } +} + +/// Get floating point exception mode. +/// +/// # References +/// - [`prctl(PR_GET_FPEXC,...)`] +/// +/// [`prctl(PR_GET_FPEXC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn floating_point_exception_mode() -> io::Result<Option<FloatingPointExceptionMode>> { + unsafe { prctl_get_at_arg2_optional::<c_uint>(PR_GET_FPEXC) } + .map(FloatingPointExceptionMode::from_bits) +} + +const PR_SET_FPEXC: c_int = 12; + +/// Set floating point exception mode. +/// +/// # References +/// - [`prctl(PR_SET_FPEXC,...)`] +/// +/// [`prctl(PR_SET_FPEXC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_floating_point_exception_mode( + config: Option<FloatingPointExceptionMode>, +) -> io::Result<()> { + let config = config.as_ref().map_or(0, FloatingPointExceptionMode::bits); + unsafe { prctl_2args(PR_SET_FPEXC, config as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_TIMING/PR_SET_TIMING +// + +const PR_GET_TIMING: c_int = 13; + +const PR_TIMING_STATISTICAL: i32 = 0; +const PR_TIMING_TIMESTAMP: i32 = 1; + +/// `PR_TIMING_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(i32)] +pub enum TimingMethod { + /// Normal, traditional, statistical process timing. + Statistical = PR_TIMING_STATISTICAL, + /// Accurate timestamp based process timing. + TimeStamp = PR_TIMING_TIMESTAMP, +} + +impl TryFrom<i32> for TimingMethod { + type Error = io::Errno; + + fn try_from(value: i32) -> Result<Self, Self::Error> { + match value { + PR_TIMING_STATISTICAL => Ok(Self::Statistical), + PR_TIMING_TIMESTAMP => Ok(Self::TimeStamp), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get which process timing method is currently in use. +/// +/// # References +/// - [`prctl(PR_GET_TIMING,...)`] +/// +/// [`prctl(PR_GET_TIMING,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn timing_method() -> io::Result<TimingMethod> { + unsafe { prctl_1arg(PR_GET_TIMING) }.and_then(TryInto::try_into) +} + +const PR_SET_TIMING: c_int = 14; + +/// Set whether to use (normal, traditional) statistical process timing or accurate +/// timestamp-based process timing. +/// +/// # References +/// - [`prctl(PR_SET_TIMING,...)`] +/// +/// [`prctl(PR_SET_TIMING,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_timing_method(method: TimingMethod) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_TIMING, method as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_ENDIAN/PR_SET_ENDIAN +// + +const PR_GET_ENDIAN: c_int = 19; + +const PR_ENDIAN_BIG: u32 = 0; +const PR_ENDIAN_LITTLE: u32 = 1; +const PR_ENDIAN_PPC_LITTLE: u32 = 2; + +/// `PR_ENDIAN_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum EndianMode { + /// Big endian mode. + Big = PR_ENDIAN_BIG, + /// True little endian mode. + Little = PR_ENDIAN_LITTLE, + /// `PowerPC` pseudo little endian. + PowerPCLittle = PR_ENDIAN_PPC_LITTLE, +} + +impl TryFrom<u32> for EndianMode { + type Error = io::Errno; + + fn try_from(value: u32) -> Result<Self, Self::Error> { + match value { + PR_ENDIAN_BIG => Ok(Self::Big), + PR_ENDIAN_LITTLE => Ok(Self::Little), + PR_ENDIAN_PPC_LITTLE => Ok(Self::PowerPCLittle), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get the endianness of the calling process. +/// +/// # References +/// - [`prctl(PR_GET_ENDIAN,...)`] +/// +/// [`prctl(PR_GET_ENDIAN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn endian_mode() -> io::Result<EndianMode> { + unsafe { prctl_get_at_arg2::<c_uint, _>(PR_GET_ENDIAN) } +} + +const PR_SET_ENDIAN: c_int = 20; + +/// Set the endianness of the calling process. +/// +/// # References +/// - [`prctl(PR_SET_ENDIAN,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_ENDIAN,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn set_endian_mode(mode: EndianMode) -> io::Result<()> { + prctl_2args(PR_SET_ENDIAN, mode as usize as *mut _).map(|_r| ()) +} + +// +// PR_GET_TSC/PR_SET_TSC +// + +const PR_GET_TSC: c_int = 25; + +const PR_TSC_ENABLE: u32 = 1; +const PR_TSC_SIGSEGV: u32 = 2; + +/// `PR_TSC_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum TimeStampCounterReadability { + /// Allow the use of the timestamp counter. + Readable = PR_TSC_ENABLE, + /// Throw a `SIGSEGV` instead of reading the TSC. + RaiseSIGSEGV = PR_TSC_SIGSEGV, +} + +impl TryFrom<u32> for TimeStampCounterReadability { + type Error = io::Errno; + + fn try_from(value: u32) -> Result<Self, Self::Error> { + match value { + PR_TSC_ENABLE => Ok(Self::Readable), + PR_TSC_SIGSEGV => Ok(Self::RaiseSIGSEGV), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get the state of the flag determining if the timestamp counter can be read. +/// +/// # References +/// - [`prctl(PR_GET_TSC,...)`] +/// +/// [`prctl(PR_GET_TSC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn time_stamp_counter_readability() -> io::Result<TimeStampCounterReadability> { + unsafe { prctl_get_at_arg2::<c_uint, _>(PR_GET_TSC) } +} + +const PR_SET_TSC: c_int = 26; + +/// Set the state of the flag determining if the timestamp counter can be read by the process. +/// +/// # References +/// - [`prctl(PR_SET_TSC,...)`] +/// +/// [`prctl(PR_SET_TSC,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_time_stamp_counter_readability( + readability: TimeStampCounterReadability, +) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_TSC, readability as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_TASK_PERF_EVENTS_DISABLE/PR_TASK_PERF_EVENTS_ENABLE +// + +const PR_TASK_PERF_EVENTS_DISABLE: c_int = 31; +const PR_TASK_PERF_EVENTS_ENABLE: c_int = 32; + +/// Enable or disable all performance counters attached to the calling process. +/// +/// # References +/// - [`prctl(PR_TASK_PERF_EVENTS_ENABLE,...)`] +/// - [`prctl(PR_TASK_PERF_EVENTS_DISABLE,...)`] +/// +/// [`prctl(PR_TASK_PERF_EVENTS_ENABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [`prctl(PR_TASK_PERF_EVENTS_DISABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn configure_performance_counters(enable: bool) -> io::Result<()> { + let option = if enable { + PR_TASK_PERF_EVENTS_ENABLE + } else { + PR_TASK_PERF_EVENTS_DISABLE + }; + + unsafe { prctl_1arg(option) }.map(|_r| ()) +} + +// +// PR_MCE_KILL_GET/PR_MCE_KILL +// + +const PR_MCE_KILL_GET: c_int = 34; + +const PR_MCE_KILL_LATE: u32 = 0; +const PR_MCE_KILL_EARLY: u32 = 1; +const PR_MCE_KILL_DEFAULT: u32 = 2; + +/// `PR_MCE_KILL_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum MachineCheckMemoryCorruptionKillPolicy { + /// Late kill policy. + Late = PR_MCE_KILL_LATE, + /// Early kill policy. + Early = PR_MCE_KILL_EARLY, + /// System-wide default policy. + Default = PR_MCE_KILL_DEFAULT, +} + +impl TryFrom<u32> for MachineCheckMemoryCorruptionKillPolicy { + type Error = io::Errno; + + fn try_from(value: u32) -> Result<Self, Self::Error> { + match value { + PR_MCE_KILL_LATE => Ok(Self::Late), + PR_MCE_KILL_EARLY => Ok(Self::Early), + PR_MCE_KILL_DEFAULT => Ok(Self::Default), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get the current per-process machine check kill policy. +/// +/// # References +/// - [`prctl(PR_MCE_KILL_GET,...)`] +/// +/// [`prctl(PR_MCE_KILL_GET,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn machine_check_memory_corruption_kill_policy( +) -> io::Result<MachineCheckMemoryCorruptionKillPolicy> { + let r = unsafe { prctl_1arg(PR_MCE_KILL_GET)? } as c_uint; + MachineCheckMemoryCorruptionKillPolicy::try_from(r) +} + +const PR_MCE_KILL: c_int = 33; + +const PR_MCE_KILL_CLEAR: usize = 0; +const PR_MCE_KILL_SET: usize = 1; + +/// Set the machine check memory corruption kill policy for the calling thread. +/// +/// # References +/// - [`prctl(PR_MCE_KILL,...)`] +/// +/// [`prctl(PR_MCE_KILL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_machine_check_memory_corruption_kill_policy( + policy: Option<MachineCheckMemoryCorruptionKillPolicy>, +) -> io::Result<()> { + let (sub_operation, policy) = if let Some(policy) = policy { + (PR_MCE_KILL_SET, policy as usize as *mut _) + } else { + (PR_MCE_KILL_CLEAR, ptr::null_mut()) + }; + + unsafe { prctl_3args(PR_MCE_KILL, sub_operation as *mut _, policy) }.map(|_r| ()) +} + +// +// PR_SET_MM +// + +const PR_SET_MM: c_int = 35; + +const PR_SET_MM_START_CODE: u32 = 1; +const PR_SET_MM_END_CODE: u32 = 2; +const PR_SET_MM_START_DATA: u32 = 3; +const PR_SET_MM_END_DATA: u32 = 4; +const PR_SET_MM_START_STACK: u32 = 5; +const PR_SET_MM_START_BRK: u32 = 6; +const PR_SET_MM_BRK: u32 = 7; +const PR_SET_MM_ARG_START: u32 = 8; +const PR_SET_MM_ARG_END: u32 = 9; +const PR_SET_MM_ENV_START: u32 = 10; +const PR_SET_MM_ENV_END: u32 = 11; +const PR_SET_MM_AUXV: usize = 12; +const PR_SET_MM_EXE_FILE: usize = 13; +const PR_SET_MM_MAP: usize = 14; +const PR_SET_MM_MAP_SIZE: usize = 15; + +/// `PR_SET_MM_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum VirtualMemoryMapAddress { + /// Set the address above which the program text can run. + CodeStart = PR_SET_MM_START_CODE, + /// Set the address below which the program text can run. + CodeEnd = PR_SET_MM_END_CODE, + /// Set the address above which initialized and uninitialized (bss) data are placed. + DataStart = PR_SET_MM_START_DATA, + /// Set the address below which initialized and uninitialized (bss) data are placed. + DataEnd = PR_SET_MM_END_DATA, + /// Set the start address of the stack. + StackStart = PR_SET_MM_START_STACK, + /// Set the address above which the program heap can be expanded with `brk` call. + BrkStart = PR_SET_MM_START_BRK, + /// Set the current `brk` value. + BrkCurrent = PR_SET_MM_BRK, + /// Set the address above which the program command line is placed. + ArgStart = PR_SET_MM_ARG_START, + /// Set the address below which the program command line is placed. + ArgEnd = PR_SET_MM_ARG_END, + /// Set the address above which the program environment is placed. + EnvironmentStart = PR_SET_MM_ENV_START, + /// Set the address below which the program environment is placed. + EnvironmentEnd = PR_SET_MM_ENV_END, +} + +/// Modify certain kernel memory map descriptor addresses of the calling process. +/// +/// # References +/// - [`prctl(PR_SET_MM,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_MM,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn set_virtual_memory_map_address( + option: VirtualMemoryMapAddress, + address: Option<NonNull<c_void>>, +) -> io::Result<()> { + let address = address.map_or_else(ptr::null_mut, NonNull::as_ptr); + prctl_3args(PR_SET_MM, option as usize as *mut _, address).map(|_r| ()) +} + +/// Supersede the `/proc/pid/exe` symbolic link with a new one pointing to a new executable file. +/// +/// # References +/// - [`prctl(PR_SET_MM,PR_SET_MM_EXE_FILE,...)`] +/// +/// [`prctl(PR_SET_MM,PR_SET_MM_EXE_FILE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_executable_file(fd: BorrowedFd) -> io::Result<()> { + let fd = usize::try_from(fd.as_raw_fd()).map_err(|_r| io::Errno::RANGE)?; + unsafe { prctl_3args(PR_SET_MM, PR_SET_MM_EXE_FILE as *mut _, fd as *mut _) }.map(|_r| ()) +} + +/// Set a new auxiliary vector. +/// +/// # References +/// - [`prctl(PR_SET_MM,PR_SET_MM_AUXV,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_MM,PR_SET_MM_AUXV,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn set_auxiliary_vector(auxv: &[*const c_void]) -> io::Result<()> { + syscalls::prctl( + PR_SET_MM, + PR_SET_MM_AUXV as *mut _, + auxv.as_ptr() as *mut _, + auxv.len() as *mut _, + ptr::null_mut(), + ) + .map(|_r| ()) +} + +/// Get the size of the [`PrctlMmMap`] the kernel expects. +/// +/// # References +/// - [`prctl(PR_SET_MM,PR_SET_MM_MAP_SIZE,...)`] +/// +/// [`prctl(PR_SET_MM,PR_SET_MM_MAP_SIZE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn virtual_memory_map_config_struct_size() -> io::Result<usize> { + let mut value: c_uint = 0; + let value_ptr = (&mut value) as *mut c_uint; + unsafe { prctl_3args(PR_SET_MM, PR_SET_MM_MAP_SIZE as *mut _, value_ptr.cast())? }; + Ok(value as usize) +} + +/// This structure provides new memory descriptor map which mostly modifies `/proc/pid/stat[m]` +/// output for a task. +/// This mostly done in a sake of checkpoint/restore functionality. +#[repr(C)] +#[derive(Debug, Clone)] +pub struct PrctlMmMap { + /// Code section start address. + pub start_code: u64, + /// Code section end address. + pub end_code: u64, + /// Data section start address. + pub start_data: u64, + /// Data section end address. + pub end_data: u64, + /// brk() start address. + pub start_brk: u64, + /// brk() current address. + pub brk: u64, + /// Stack start address. + pub start_stack: u64, + /// Program command line start address. + pub arg_start: u64, + /// Program command line end address. + pub arg_end: u64, + /// Program environment start address. + pub env_start: u64, + /// Program environment end address. + pub env_end: u64, + /// Auxiliary vector start address. + pub auxv: *mut u64, + /// Auxiliary vector size. + pub auxv_size: u32, + /// File descriptor of executable file that was used to create this process. + pub exe_fd: u32, +} + +/// Provides one-shot access to all the addresses by passing in a [`PrctlMmMap`]. +/// +/// # References +/// - [`prctl(PR_SET_MM,PR_SET_MM_MAP,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_MM,PR_SET_MM_MAP,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn configure_virtual_memory_map(config: &PrctlMmMap) -> io::Result<()> { + syscalls::prctl( + PR_SET_MM, + PR_SET_MM_MAP as *mut _, + config as *const PrctlMmMap as *mut _, + mem::size_of::<PrctlMmMap>() as *mut _, + ptr::null_mut(), + ) + .map(|_r| ()) +} + +// +// PR_SET_PTRACER +// + +const PR_SET_PTRACER: c_int = 0x59_61_6d_61; + +const PR_SET_PTRACER_ANY: usize = usize::MAX; + +/// Process ptracer. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum PTracer { + /// None. + None, + /// Disable `ptrace` restrictions for the calling process. + Any, + /// Specific process. + ProcessID(Pid), +} + +/// Declare that the ptracer process can `ptrace` the calling process as if it were a direct +/// process ancestor. +/// +/// # References +/// - [`prctl(PR_SET_PTRACER,...)`] +/// +/// [`prctl(PR_SET_PTRACER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_ptracer(tracer: PTracer) -> io::Result<()> { + let pid = match tracer { + PTracer::None => ptr::null_mut(), + PTracer::Any => PR_SET_PTRACER_ANY as *mut _, + PTracer::ProcessID(pid) => pid.as_raw_nonzero().get() as usize as *mut _, + }; + + unsafe { prctl_2args(PR_SET_PTRACER, pid) }.map(|_r| ()) +} + +// +// PR_GET_CHILD_SUBREAPER/PR_SET_CHILD_SUBREAPER +// + +const PR_GET_CHILD_SUBREAPER: c_int = 37; + +/// Get the `child subreaper` setting of the calling process. +/// +/// # References +/// - [`prctl(PR_GET_CHILD_SUBREAPER,...)`] +/// +/// [`prctl(PR_GET_CHILD_SUBREAPER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn child_subreaper() -> io::Result<Option<Pid>> { + unsafe { + let r = prctl_get_at_arg2_optional::<c_uint>(PR_GET_CHILD_SUBREAPER)?; + Ok(Pid::from_raw(r as RawPid)) + } +} + +const PR_SET_CHILD_SUBREAPER: c_int = 36; + +/// Set the `child subreaper` attribute of the calling process. +/// +/// # References +/// - [`prctl(PR_SET_CHILD_SUBREAPER,...)`] +/// +/// [`prctl(PR_SET_CHILD_SUBREAPER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_child_subreaper(pid: Option<Pid>) -> io::Result<()> { + let pid = pid.map_or(0_usize, |pid| pid.as_raw_nonzero().get() as usize); + unsafe { prctl_2args(PR_SET_CHILD_SUBREAPER, pid as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_FP_MODE/PR_SET_FP_MODE +// + +const PR_GET_FP_MODE: c_int = 46; + +const PR_FP_MODE_FR: u32 = 1_u32 << 0; +const PR_FP_MODE_FRE: u32 = 1_u32 << 1; + +/// `PR_FP_MODE_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum FloatingPointMode { + /// 64-bit floating point registers. + FloatingPointRegisters = PR_FP_MODE_FR, + /// Enable emulation of 32-bit floating-point mode. + FloatingPointEmulation = PR_FP_MODE_FRE, +} + +impl TryFrom<u32> for FloatingPointMode { + type Error = io::Errno; + + fn try_from(value: u32) -> Result<Self, Self::Error> { + match value { + PR_FP_MODE_FR => Ok(Self::FloatingPointRegisters), + PR_FP_MODE_FRE => Ok(Self::FloatingPointEmulation), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get the current floating point mode. +/// +/// # References +/// - [`prctl(PR_GET_FP_MODE,...)`] +/// +/// [`prctl(PR_GET_FP_MODE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn floating_point_mode() -> io::Result<FloatingPointMode> { + let r = unsafe { prctl_1arg(PR_GET_FP_MODE)? } as c_uint; + FloatingPointMode::try_from(r) +} + +const PR_SET_FP_MODE: c_int = 45; + +/// Allow control of the floating point mode from user space. +/// +/// # References +/// - [`prctl(PR_SET_FP_MODE,...)`] +/// +/// [`prctl(PR_SET_FP_MODE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_floating_point_mode(mode: FloatingPointMode) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_FP_MODE, mode as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_SPECULATION_CTRL/PR_SET_SPECULATION_CTRL +// + +const PR_GET_SPECULATION_CTRL: c_int = 52; + +const PR_SPEC_STORE_BYPASS: u32 = 0; +const PR_SPEC_INDIRECT_BRANCH: u32 = 1; +const PR_SPEC_L1D_FLUSH: u32 = 2; + +/// `PR_SPEC_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum SpeculationFeature { + /// Set the state of the speculative store bypass misfeature. + SpeculativeStoreBypass = PR_SPEC_STORE_BYPASS, + /// Set the state of the indirect branch speculation misfeature. + IndirectBranchSpeculation = PR_SPEC_INDIRECT_BRANCH, + /// Flush L1D Cache on context switch out of the task. + FlushL1DCacheOnContextSwitchOutOfTask = PR_SPEC_L1D_FLUSH, +} + +impl TryFrom<u32> for SpeculationFeature { + type Error = io::Errno; + + fn try_from(value: u32) -> Result<Self, Self::Error> { + match value { + PR_SPEC_STORE_BYPASS => Ok(Self::SpeculativeStoreBypass), + PR_SPEC_INDIRECT_BRANCH => Ok(Self::IndirectBranchSpeculation), + PR_SPEC_L1D_FLUSH => Ok(Self::FlushL1DCacheOnContextSwitchOutOfTask), + _ => Err(io::Errno::RANGE), + } + } +} + +bitflags! { + /// `PR_SPEC_*`. + pub struct SpeculationFeatureControl: u32 { + /// The speculation feature is enabled, mitigation is disabled. + const ENABLE = 1_u32 << 1; + /// The speculation feature is disabled, mitigation is enabled. + const DISABLE = 1_u32 << 2; + /// The speculation feature is disabled, mitigation is enabled, and it cannot be undone. + const FORCE_DISABLE = 1_u32 << 3; + /// The speculation feature is disabled, mitigation is enabled, and the state will be cleared on `execve`. + const DISABLE_NOEXEC = 1_u32 << 4; + } +} + +bitflags! { + /// Zero means the processors are not vulnerable. + pub struct SpeculationFeatureState: u32 { + /// Mitigation can be controlled per thread by `PR_SET_SPECULATION_CTRL`. + const PRCTL = 1_u32 << 0; + /// The speculation feature is enabled, mitigation is disabled. + const ENABLE = 1_u32 << 1; + /// The speculation feature is disabled, mitigation is enabled. + const DISABLE = 1_u32 << 2; + /// The speculation feature is disabled, mitigation is enabled, and it cannot be undone. + const FORCE_DISABLE = 1_u32 << 3; + /// The speculation feature is disabled, mitigation is enabled, and the state will be cleared on `execve`. + const DISABLE_NOEXEC = 1_u32 << 4; + } +} + +/// Get the state of the speculation misfeature. +/// +/// # References +/// - [`prctl(PR_GET_SPECULATION_CTRL,...)`] +/// +/// [`prctl(PR_GET_SPECULATION_CTRL,...)`]: https://www.kernel.org/doc/html/v5.18/userspace-api/spec_ctrl.html +#[inline] +pub fn speculative_feature_state( + feature: SpeculationFeature, +) -> io::Result<Option<SpeculationFeatureState>> { + let r = unsafe { prctl_2args(PR_GET_SPECULATION_CTRL, feature as usize as *mut _)? } as c_uint; + Ok(SpeculationFeatureState::from_bits(r)) +} + +const PR_SET_SPECULATION_CTRL: c_int = 53; + +/// Sets the state of the speculation misfeature. +/// +/// # References +/// - [`prctl(PR_SET_SPECULATION_CTRL,...)`] +/// +/// [`prctl(PR_SET_SPECULATION_CTRL,...)`]: https://www.kernel.org/doc/html/v5.18/userspace-api/spec_ctrl.html +#[inline] +pub fn control_speculative_feature( + feature: SpeculationFeature, + config: SpeculationFeatureControl, +) -> io::Result<()> { + let feature = feature as usize as *mut _; + let config = config.bits() as usize as *mut _; + unsafe { prctl_3args(PR_SET_SPECULATION_CTRL, feature, config) }.map(|_r| ()) +} + +// +// PR_GET_IO_FLUSHER/PR_SET_IO_FLUSHER +// + +const PR_GET_IO_FLUSHER: c_int = 58; + +/// Get the `IO_FLUSHER` state of the caller. +/// +/// # References +/// - [`prctl(PR_GET_IO_FLUSHER,...)`] +/// +/// [`prctl(PR_GET_IO_FLUSHER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn is_io_flusher() -> io::Result<bool> { + unsafe { prctl_1arg(PR_GET_IO_FLUSHER) }.map(|r| r != 0) +} + +const PR_SET_IO_FLUSHER: c_int = 57; + +/// Put the process in the `IO_FLUSHER` state, allowing it to make progress when +/// allocating memory. +/// +/// # References +/// - [`prctl(PR_SET_IO_FLUSHER,...)`] +/// +/// [`prctl(PR_SET_IO_FLUSHER,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn configure_io_flusher_behavior(enable: bool) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_IO_FLUSHER, enable as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_PAC_GET_ENABLED_KEYS/PR_PAC_SET_ENABLED_KEYS +// + +const PR_PAC_GET_ENABLED_KEYS: c_int = 61; + +bitflags! { + /// `PR_PAC_AP*`. + pub struct PointerAuthenticationKeys: u32 { + /// Instruction authentication key `A`. + const INSTRUCTION_AUTHENTICATION_KEY_A = 1_u32 << 0; + /// Instruction authentication key `B`. + const INSTRUCTION_AUTHENTICATION_KEY_B = 1_u32 << 1; + /// Data authentication key `A`. + const DATA_AUTHENTICATION_KEY_A = 1_u32 << 2; + /// Data authentication key `B`. + const DATA_AUTHENTICATION_KEY_B = 1_u32 << 3; + /// Generic authentication `A` key. + const GENERIC_AUTHENTICATION_KEY_A = 1_u32 << 4; + } +} + +/// Get enabled pointer authentication keys. +/// +/// # References +/// - [`prctl(PR_PAC_GET_ENABLED_KEYS,...)`] +/// +/// [`prctl(PR_PAC_GET_ENABLED_KEYS,...)`]: https://www.kernel.org/doc/html/v5.18/arm64/pointer-authentication.html +#[inline] +pub fn enabled_pointer_authentication_keys() -> io::Result<PointerAuthenticationKeys> { + let r = unsafe { prctl_1arg(PR_PAC_GET_ENABLED_KEYS)? } as c_uint; + PointerAuthenticationKeys::from_bits(r).ok_or(io::Errno::RANGE) +} + +const PR_PAC_SET_ENABLED_KEYS: c_int = 60; + +/// Set enabled pointer authentication keys. +/// +/// # References +/// - [`prctl(PR_PAC_SET_ENABLED_KEYS,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_PAC_SET_ENABLED_KEYS,...)`]: https://www.kernel.org/doc/html/v5.18/arm64/pointer-authentication.html +#[inline] +pub unsafe fn configure_pointer_authentication_keys( + config: impl Iterator<Item = (PointerAuthenticationKeys, bool)>, +) -> io::Result<()> { + let mut affected_keys: u32 = 0; + let mut enabled_keys: u32 = 0; + + for (key, enable) in config { + let key = key.bits(); + affected_keys |= key; + + if enable { + enabled_keys |= key; + } else { + enabled_keys &= !key; + } + } + + if affected_keys == 0 { + return Ok(()); // Nothing to do. + } + + prctl_3args( + PR_PAC_SET_ENABLED_KEYS, + affected_keys as usize as *mut _, + enabled_keys as usize as *mut _, + ) + .map(|_r| ()) +} + +// +// PR_SET_VMA +// + +const PR_SET_VMA: c_int = 0x53_56_4d_41; + +const PR_SET_VMA_ANON_NAME: usize = 0; + +/// Set the name for a virtual memory region. +/// +/// # References +/// - [`prctl(PR_SET_VMA,PR_SET_VMA_ANON_NAME,...)`] +/// +/// [`prctl(PR_SET_VMA,PR_SET_VMA_ANON_NAME,...)`]: https://lwn.net/Articles/867818/ +#[inline] +pub fn set_virtual_memory_region_name(region: &[u8], name: Option<&CStr>) -> io::Result<()> { + unsafe { + syscalls::prctl( + PR_SET_VMA, + PR_SET_VMA_ANON_NAME as *mut _, + region.as_ptr() as *mut _, + region.len() as *mut _, + name.map_or_else(ptr::null, CStr::as_ptr) as *mut _, + ) + .map(|_r| ()) + } +} diff --git a/vendor/rustix/src/process/priority.rs b/vendor/rustix/src/process/priority.rs index ae43a0b75..4835ceaa2 100644 --- a/vendor/rustix/src/process/priority.rs +++ b/vendor/rustix/src/process/priority.rs @@ -1,5 +1,5 @@ use crate::process::{Pid, Uid}; -use crate::{imp, io}; +use crate::{backend, io}; /// `nice()`—Adjust the scheduling priority of the current process. /// @@ -11,7 +11,7 @@ use crate::{imp, io}; /// [Linux]: https://man7.org/linux/man-pages/man2/nice.2.html #[inline] pub fn nice(inc: i32) -> io::Result<i32> { - imp::process::syscalls::nice(inc) + backend::process::syscalls::nice(inc) } /// `getpriority(PRIO_USER, uid)`—Get the scheduling priority of the given @@ -29,7 +29,7 @@ pub fn nice(inc: i32) -> io::Result<i32> { #[inline] #[doc(alias = "getpriority")] pub fn getpriority_user(uid: Uid) -> io::Result<i32> { - imp::process::syscalls::getpriority_user(uid) + backend::process::syscalls::getpriority_user(uid) } /// `getpriority(PRIO_PGRP, gid)`—Get the scheduling priority of the given @@ -49,7 +49,7 @@ pub fn getpriority_user(uid: Uid) -> io::Result<i32> { #[inline] #[doc(alias = "getpriority")] pub fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> { - imp::process::syscalls::getpriority_pgrp(pgid) + backend::process::syscalls::getpriority_pgrp(pgid) } /// `getpriority(PRIO_PROCESS, pid)`—Get the scheduling priority of the given @@ -69,7 +69,7 @@ pub fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> { #[inline] #[doc(alias = "getpriority")] pub fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> { - imp::process::syscalls::getpriority_process(pid) + backend::process::syscalls::getpriority_process(pid) } /// `setpriority(PRIO_USER, uid)`—Get the scheduling priority of the given @@ -87,7 +87,7 @@ pub fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> { #[inline] #[doc(alias = "setpriority")] pub fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> { - imp::process::syscalls::setpriority_user(uid, priority) + backend::process::syscalls::setpriority_user(uid, priority) } /// `setpriority(PRIO_PGRP, pgid)`—Get the scheduling priority of the given @@ -107,7 +107,7 @@ pub fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> { #[inline] #[doc(alias = "setpriority")] pub fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> { - imp::process::syscalls::setpriority_pgrp(pgid, priority) + backend::process::syscalls::setpriority_pgrp(pgid, priority) } /// `setpriority(PRIO_PROCESS, pid)`—Get the scheduling priority of the given @@ -127,5 +127,5 @@ pub fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> { #[inline] #[doc(alias = "setpriority")] pub fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result<()> { - imp::process::syscalls::setpriority_process(pid, priority) + backend::process::syscalls::setpriority_process(pid, priority) } diff --git a/vendor/rustix/src/process/procctl.rs b/vendor/rustix/src/process/procctl.rs new file mode 100644 index 000000000..ff842513f --- /dev/null +++ b/vendor/rustix/src/process/procctl.rs @@ -0,0 +1,180 @@ +//! Bindings for the FreeBSD `procctl` system call. +//! +//! There are similarities (but also differences) with Linux's `prctl` system call, whose interface +//! is located in the `prctl.rs` file. + +#![allow(unsafe_code)] + +use core::mem::MaybeUninit; + +use crate::backend::c::{c_int, c_uint, c_void}; +use crate::backend::process::syscalls; +use crate::backend::process::types::{RawId, Signal}; +use crate::io; +use crate::process::{Pid, RawPid}; + +// +// Helper functions. +// + +/// Subset of `idtype_t` C enum, with only the values allowed by `procctl`. +#[repr(i32)] +pub enum IdType { + /// Process id. + Pid = 0, + /// Process group id. + Pgid = 2, +} + +/// A process selector for use with the `procctl` interface. +/// +/// `None` represents the current process. `Some((IdType::Pid, pid))` represents the process +/// with pid `pid`. `Some((IdType::Pgid, pgid))` represents the control processes belonging to +/// the process group with id `pgid`. +pub type ProcSelector = Option<(IdType, Pid)>; +fn proc_selector_to_raw(selector: ProcSelector) -> (IdType, RawPid) { + match selector { + Some((idtype, id)) => (idtype, id.as_raw_nonzero().get()), + None => (IdType::Pid, 0), + } +} + +#[inline] +pub(crate) unsafe fn procctl( + option: c_int, + process: ProcSelector, + data: *mut c_void, +) -> io::Result<()> { + let (idtype, id) = proc_selector_to_raw(process); + syscalls::procctl(idtype as c_uint, id as RawId, option, data) +} + +#[inline] +pub(crate) unsafe fn procctl_set<P>( + option: c_int, + process: ProcSelector, + data: &P, +) -> io::Result<()> { + procctl(option, process, (data as *const P as *mut P).cast()) +} + +#[inline] +pub(crate) unsafe fn procctl_get_optional<P>( + option: c_int, + process: ProcSelector, +) -> io::Result<P> { + let mut value: MaybeUninit<P> = MaybeUninit::uninit(); + procctl(option, process, value.as_mut_ptr().cast())?; + Ok(value.assume_init()) +} + +// +// PROC_PDEATHSIG_STATUS/PROC_PDEATHSIG_CTL +// + +const PROC_PDEATHSIG_STATUS: c_int = 12; + +/// Get the current value of the parent process death signal. +/// +/// # References +/// - [Linux: `prctl(PR_GET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`] +/// +/// [Linux: `prctl(PR_GET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [FreeBSD: `procctl(PROC_PDEATHSIG_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn parent_process_death_signal() -> io::Result<Option<Signal>> { + unsafe { procctl_get_optional::<c_int>(PROC_PDEATHSIG_STATUS, None) }.map(Signal::from_raw) +} + +const PROC_PDEATHSIG_CTL: c_int = 11; + +/// Set the parent-death signal of the calling process. +/// +/// # References +/// - [Linux: `prctl(PR_SET_PDEATHSIG,...)`] +/// - [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`] +/// +/// [Linux: `prctl(PR_SET_PDEATHSIG,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +/// [FreeBSD: `procctl(PROC_PDEATHSIG_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn set_parent_process_death_signal(signal: Option<Signal>) -> io::Result<()> { + let signal = signal.map_or(0, |signal| signal as c_int); + unsafe { procctl_set::<c_int>(PROC_PDEATHSIG_CTL, None, &signal) } +} + +// +// PROC_TRACE_CTL +// + +const PROC_TRACE_CTL: c_int = 7; + +const PROC_TRACE_CTL_ENABLE: i32 = 1; +const PROC_TRACE_CTL_DISABLE: i32 = 2; +const PROC_TRACE_CTL_DISABLE_EXEC: i32 = 3; + +/// `PROC_TRACE_CTL_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(i32)] +pub enum DumpableBehavior { + /// Not dumpable. + NotDumpable = PROC_TRACE_CTL_DISABLE, + /// Dumpable. + Dumpable = PROC_TRACE_CTL_ENABLE, + /// Not dumpable, and this behaviour is preserved across `execve` calls. + NotDumpableExecPreserved = PROC_TRACE_CTL_DISABLE_EXEC, +} + +/// Set the state of the `dumpable` attribute for the process indicated by `idtype` and `id`. +/// This determines whether the process can be traced and whether core dumps are produced for +/// the process upon delivery of a signal whose default behavior is to produce a core dump. +/// +/// This is similar to `set_dumpable_behavior` on Linux, with the exception that on FreeBSD +/// there is an extra argument `process`. When `process` is set to `None`, the operation is +/// performed for the current process, like on Linux. +/// +/// # References +/// - [`procctl(PROC_TRACE_CTL,...)`] +/// +/// [`procctl(PROC_TRACE_CTL,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn set_dumpable_behavior(process: ProcSelector, config: DumpableBehavior) -> io::Result<()> { + unsafe { procctl(PROC_TRACE_CTL, process, config as usize as *mut _) } +} + +// +// PROC_TRACE_STATUS +// + +const PROC_TRACE_STATUS: c_int = 8; + +/// Tracing status as returned by [`trace_status`]. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum TracingStatus { + /// Tracing is disabled for the process. + NotTraceble, + /// Tracing is not disabled for the process, but not debugger/tracer is attached. + Tracable, + /// The process is being traced by the process whose pid is stored in the first + /// component of this variant. + BeingTraced(Pid), +} + +/// Get the tracing status of the process indicated by `idtype` and `id`. +/// +/// # References +/// - [`procctl(PROC_TRACE_STATUS,...)`] +/// +/// [`procctl(PROC_TRACE_STATUS,...)`]: https://www.freebsd.org/cgi/man.cgi?query=procctl&sektion=2 +#[inline] +pub fn trace_status(process: ProcSelector) -> io::Result<TracingStatus> { + let val = unsafe { procctl_get_optional::<c_int>(PROC_TRACE_STATUS, process) }?; + match val { + -1 => Ok(TracingStatus::NotTraceble), + 0 => Ok(TracingStatus::Tracable), + pid => { + let pid = unsafe { Pid::from_raw(pid as RawPid) }.ok_or(io::Errno::RANGE)?; + Ok(TracingStatus::BeingTraced(pid)) + } + } +} diff --git a/vendor/rustix/src/process/rlimit.rs b/vendor/rustix/src/process/rlimit.rs index ffb22d2ae..e8216af79 100644 --- a/vendor/rustix/src/process/rlimit.rs +++ b/vendor/rustix/src/process/rlimit.rs @@ -1,8 +1,8 @@ #[cfg(any(target_os = "android", target_os = "linux"))] use crate::process::Pid; -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::process::types::Resource; +pub use backend::process::types::Resource; /// `struct rlimit`—Current and maximum values used in [`getrlimit`], /// [`setrlimit`], and [`prlimit`]. @@ -24,7 +24,7 @@ pub struct Rlimit { /// [Linux]: https://man7.org/linux/man-pages/man2/getrlimit.2.html #[inline] pub fn getrlimit(resource: Resource) -> Rlimit { - imp::process::syscalls::getrlimit(resource) + backend::process::syscalls::getrlimit(resource) } /// `setrlimit(resource, new)`—Set a process resource limit value. @@ -37,7 +37,7 @@ pub fn getrlimit(resource: Resource) -> Rlimit { /// [Linux]: https://man7.org/linux/man-pages/man2/setrlimit.2.html #[inline] pub fn setrlimit(resource: Resource, new: Rlimit) -> io::Result<()> { - imp::process::syscalls::setrlimit(resource, new) + backend::process::syscalls::setrlimit(resource, new) } /// `prlimit(pid, resource, new)`—Get and set a process resource limit value. @@ -49,5 +49,5 @@ pub fn setrlimit(resource: Resource, new: Rlimit) -> io::Result<()> { #[cfg(any(target_os = "android", target_os = "linux"))] #[inline] pub fn prlimit(pid: Option<Pid>, resource: Resource, new: Rlimit) -> io::Result<Rlimit> { - imp::process::syscalls::prlimit(pid, resource, new) + backend::process::syscalls::prlimit(pid, resource, new) } diff --git a/vendor/rustix/src/process/sched.rs b/vendor/rustix/src/process/sched.rs index 56ba95a6b..88e661670 100644 --- a/vendor/rustix/src/process/sched.rs +++ b/vendor/rustix/src/process/sched.rs @@ -1,5 +1,5 @@ use crate::process::Pid; -use crate::{imp, io}; +use crate::{backend, io}; /// `CpuSet` represents a bit-mask of CPUs. /// @@ -15,18 +15,18 @@ use crate::{imp, io}; #[repr(C)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct CpuSet { - cpu_set: imp::process::types::RawCpuSet, + cpu_set: backend::process::types::RawCpuSet, } impl CpuSet { /// The maximum number of CPU in `CpuSet`. - pub const MAX_CPU: usize = imp::process::types::CPU_SETSIZE; + pub const MAX_CPU: usize = backend::process::types::CPU_SETSIZE; /// Create a new and empty `CpuSet`. #[inline] pub fn new() -> Self { Self { - cpu_set: imp::process::types::raw_cpu_set_new(), + cpu_set: backend::process::types::raw_cpu_set_new(), } } @@ -35,7 +35,7 @@ impl CpuSet { /// `field` is the CPU id to test. #[inline] pub fn is_set(&self, field: usize) -> bool { - imp::process::cpu_set::CPU_ISSET(field, &self.cpu_set) + backend::process::cpu_set::CPU_ISSET(field, &self.cpu_set) } /// Add a CPU to `CpuSet`. @@ -43,7 +43,7 @@ impl CpuSet { /// `field` is the CPU id to add. #[inline] pub fn set(&mut self, field: usize) { - imp::process::cpu_set::CPU_SET(field, &mut self.cpu_set) + backend::process::cpu_set::CPU_SET(field, &mut self.cpu_set) } /// Remove a CPU from `CpuSet`. @@ -51,20 +51,20 @@ impl CpuSet { /// `field` is the CPU id to remove. #[inline] pub fn unset(&mut self, field: usize) { - imp::process::cpu_set::CPU_CLR(field, &mut self.cpu_set) + backend::process::cpu_set::CPU_CLR(field, &mut self.cpu_set) } /// Count the number of CPUs set in the `CpuSet`. #[cfg(any(target_os = "android", target_os = "linux"))] #[inline] pub fn count(&self) -> u32 { - imp::process::cpu_set::CPU_COUNT(&self.cpu_set) + backend::process::cpu_set::CPU_COUNT(&self.cpu_set) } /// Zeroes the `CpuSet`. #[inline] pub fn clear(&mut self) { - imp::process::cpu_set::CPU_ZERO(&mut self.cpu_set) + backend::process::cpu_set::CPU_ZERO(&mut self.cpu_set) } } @@ -89,7 +89,7 @@ impl Default for CpuSet { /// [Linux]: https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html #[inline] pub fn sched_setaffinity(pid: Option<Pid>, cpuset: &CpuSet) -> io::Result<()> { - imp::process::syscalls::sched_setaffinity(pid, &cpuset.cpu_set) + backend::process::syscalls::sched_setaffinity(pid, &cpuset.cpu_set) } /// `sched_getaffinity(pid)`—Get a thread's CPU affinity mask. @@ -106,5 +106,5 @@ pub fn sched_setaffinity(pid: Option<Pid>, cpuset: &CpuSet) -> io::Result<()> { #[inline] pub fn sched_getaffinity(pid: Option<Pid>) -> io::Result<CpuSet> { let mut cpuset = CpuSet::new(); - imp::process::syscalls::sched_getaffinity(pid, &mut cpuset.cpu_set).and(Ok(cpuset)) + backend::process::syscalls::sched_getaffinity(pid, &mut cpuset.cpu_set).and(Ok(cpuset)) } diff --git a/vendor/rustix/src/process/sched_yield.rs b/vendor/rustix/src/process/sched_yield.rs index 24367773f..0324f67cb 100644 --- a/vendor/rustix/src/process/sched_yield.rs +++ b/vendor/rustix/src/process/sched_yield.rs @@ -1,4 +1,4 @@ -use crate::imp; +use crate::backend; /// `sched_yield()`—Hints to the OS that other processes should run. /// @@ -12,5 +12,5 @@ use crate::imp; /// [Linux]: https://man7.org/linux/man-pages/man2/sched_yield.2.html #[inline] pub fn sched_yield() { - imp::process::syscalls::sched_yield() + backend::process::syscalls::sched_yield() } diff --git a/vendor/rustix/src/process/uname.rs b/vendor/rustix/src/process/uname.rs index a17d0be7a..95dec2699 100644 --- a/vendor/rustix/src/process/uname.rs +++ b/vendor/rustix/src/process/uname.rs @@ -6,20 +6,20 @@ //! kernel into `&str` references, which assumes that they're NUL-terminated. #![allow(unsafe_code)] +use crate::backend; use crate::ffi::CStr; -use crate::imp; use core::fmt; /// `uname()`—Returns high-level information about the runtime OS and /// hardware. #[inline] pub fn uname() -> Uname { - Uname(imp::process::syscalls::uname()) + Uname(backend::process::syscalls::uname()) } /// `struct utsname`—Return type for [`uname`]. #[doc(alias = "utsname")] -pub struct Uname(imp::process::types::RawUname); +pub struct Uname(backend::process::types::RawUname); impl Uname { /// `sysname`—Operating system release name diff --git a/vendor/rustix/src/process/wait.rs b/vendor/rustix/src/process/wait.rs index 383b34d06..a4bd1b528 100644 --- a/vendor/rustix/src/process/wait.rs +++ b/vendor/rustix/src/process/wait.rs @@ -1,16 +1,16 @@ use crate::process::Pid; -use crate::{imp, io}; +use crate::{backend, io}; use bitflags::bitflags; bitflags! { /// Options for modifying the behavior of wait/waitpid pub struct WaitOptions: u32 { /// Return immediately if no child has exited. - const NOHANG = imp::process::wait::WNOHANG as _; + const NOHANG = backend::process::wait::WNOHANG as _; /// Return if a child has stopped (but not traced via `ptrace(2)`) - const UNTRACED = imp::process::wait::WUNTRACED as _; + const UNTRACED = backend::process::wait::WUNTRACED as _; /// Return if a stopped child has been resumed by delivery of `SIGCONT` - const CONTINUED = imp::process::wait::WCONTINUED as _; + const CONTINUED = backend::process::wait::WCONTINUED as _; } } @@ -34,13 +34,13 @@ impl WaitStatus { /// Returns whether the process is currently stopped. #[inline] pub fn stopped(self) -> bool { - imp::process::wait::WIFSTOPPED(self.0 as _) + backend::process::wait::WIFSTOPPED(self.0 as _) } /// Returns whether the process has continued from a job control stop. #[inline] pub fn continued(self) -> bool { - imp::process::wait::WIFCONTINUED(self.0 as _) + backend::process::wait::WIFCONTINUED(self.0 as _) } /// Returns the number of the signal that stopped the process, @@ -48,7 +48,7 @@ impl WaitStatus { #[inline] pub fn stopping_signal(self) -> Option<u32> { if self.stopped() { - Some(imp::process::wait::WSTOPSIG(self.0 as _) as _) + Some(backend::process::wait::WSTOPSIG(self.0 as _) as _) } else { None } @@ -58,8 +58,8 @@ impl WaitStatus { /// if it exited normally. #[inline] pub fn exit_status(self) -> Option<u32> { - if imp::process::wait::WIFEXITED(self.0 as _) { - Some(imp::process::wait::WEXITSTATUS(self.0 as _) as _) + if backend::process::wait::WIFEXITED(self.0 as _) { + Some(backend::process::wait::WEXITSTATUS(self.0 as _) as _) } else { None } @@ -69,8 +69,8 @@ impl WaitStatus { /// if the process was terminated by a signal. #[inline] pub fn terminating_signal(self) -> Option<u32> { - if imp::process::wait::WIFSIGNALED(self.0 as _) { - Some(imp::process::wait::WTERMSIG(self.0 as _) as _) + if backend::process::wait::WIFSIGNALED(self.0 as _) { + Some(backend::process::wait::WTERMSIG(self.0 as _) as _) } else { None } @@ -104,7 +104,7 @@ impl WaitStatus { #[cfg(not(target_os = "wasi"))] #[inline] pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<WaitStatus>> { - Ok(imp::process::syscalls::waitpid(pid, waitopts)?.map(|(_, status)| status)) + Ok(backend::process::syscalls::waitpid(pid, waitopts)?.map(|(_, status)| status)) } /// `wait(waitopts)`—Wait for any of the children of calling process to @@ -125,5 +125,5 @@ pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<Wai #[cfg(not(target_os = "wasi"))] #[inline] pub fn wait(waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> { - imp::process::syscalls::wait(waitopts) + backend::process::syscalls::wait(waitopts) } diff --git a/vendor/rustix/src/rand/getrandom.rs b/vendor/rustix/src/rand/getrandom.rs index f5d7e365d..83043800d 100644 --- a/vendor/rustix/src/rand/getrandom.rs +++ b/vendor/rustix/src/rand/getrandom.rs @@ -1,7 +1,7 @@ -use crate::{imp, io}; +use crate::{backend, io}; /// `GRND_*` -pub use imp::rand::types::GetRandomFlags; +pub use backend::rand::types::GetRandomFlags; /// `getrandom(buf, flags)`—Reads a sequence of random bytes. /// @@ -17,5 +17,5 @@ pub use imp::rand::types::GetRandomFlags; /// [Linux]: https://man7.org/linux/man-pages/man2/getrandom.2.html #[inline] pub fn getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result<usize> { - imp::rand::syscalls::getrandom(buf, flags) + backend::rand::syscalls::getrandom(buf, flags) } diff --git a/vendor/rustix/src/runtime.rs b/vendor/rustix/src/runtime.rs index 187da6341..84baeb463 100644 --- a/vendor/rustix/src/runtime.rs +++ b/vendor/rustix/src/runtime.rs @@ -19,45 +19,47 @@ //! serious problems. #![allow(unsafe_code)] +use crate::backend; #[cfg(linux_raw)] use crate::ffi::CStr; #[cfg(linux_raw)] +#[cfg(feature = "fs")] use crate::fs::AtFlags; -use crate::imp; #[cfg(linux_raw)] use crate::io; #[cfg(linux_raw)] use crate::process::Pid; #[cfg(linux_raw)] -use core::ffi::c_void; +#[cfg(feature = "fs")] +use backend::fd::AsFd; #[cfg(linux_raw)] -use imp::fd::AsFd; +use core::ffi::c_void; #[cfg(linux_raw)] #[cfg(target_arch = "x86")] #[inline] pub unsafe fn set_thread_area(u_info: &mut UserDesc) -> io::Result<()> { - imp::runtime::syscalls::tls::set_thread_area(u_info) + backend::runtime::syscalls::tls::set_thread_area(u_info) } #[cfg(linux_raw)] #[cfg(target_arch = "arm")] #[inline] pub unsafe fn arm_set_tls(data: *mut c_void) -> io::Result<()> { - imp::runtime::syscalls::tls::arm_set_tls(data) + backend::runtime::syscalls::tls::arm_set_tls(data) } #[cfg(linux_raw)] #[cfg(target_arch = "x86_64")] #[inline] pub unsafe fn set_fs(data: *mut c_void) { - imp::runtime::syscalls::tls::set_fs(data) + backend::runtime::syscalls::tls::set_fs(data) } #[cfg(linux_raw)] #[inline] pub unsafe fn set_tid_address(data: *mut c_void) -> Pid { - imp::runtime::syscalls::tls::set_tid_address(data) + backend::runtime::syscalls::tls::set_tid_address(data) } /// `prctl(PR_SET_NAME, name)` @@ -74,12 +76,12 @@ pub unsafe fn set_tid_address(data: *mut c_void) -> Pid { #[cfg(linux_raw)] #[inline] pub unsafe fn set_thread_name(name: &CStr) -> io::Result<()> { - imp::runtime::syscalls::tls::set_thread_name(name) + backend::runtime::syscalls::tls::set_thread_name(name) } #[cfg(linux_raw)] #[cfg(target_arch = "x86")] -pub use imp::runtime::tls::UserDesc; +pub use backend::runtime::tls::UserDesc; /// `syscall(SYS_exit, status)`—Exit the current thread. /// @@ -89,7 +91,7 @@ pub use imp::runtime::tls::UserDesc; #[cfg(linux_raw)] #[inline] pub unsafe fn exit_thread(status: i32) -> ! { - imp::runtime::syscalls::tls::exit_thread(status) + backend::runtime::syscalls::tls::exit_thread(status) } /// Exit all the threads in the current process' thread group. @@ -112,7 +114,7 @@ pub unsafe fn exit_thread(status: i32) -> ! { #[doc(alias = "_Exit")] #[inline] pub fn exit_group(status: i32) -> ! { - imp::process::syscalls::exit_group(status) + backend::process::syscalls::exit_group(status) } /// Return fields from the main executable segment headers ("phdrs") relevant @@ -120,7 +122,7 @@ pub fn exit_group(status: i32) -> ! { #[cfg(linux_raw)] #[inline] pub fn startup_tls_info() -> StartupTlsInfo { - imp::runtime::tls::startup_tls_info() + backend::runtime::tls::startup_tls_info() } /// `(getauxval(AT_PHDR), getauxval(AT_PHNUM))`—Returns the address and @@ -134,11 +136,11 @@ pub fn startup_tls_info() -> StartupTlsInfo { #[cfg(any(target_os = "android", target_os = "linux"))] #[inline] pub fn exe_phdrs() -> (*const c_void, usize) { - imp::param::auxv::exe_phdrs() + backend::param::auxv::exe_phdrs() } #[cfg(linux_raw)] -pub use imp::runtime::tls::StartupTlsInfo; +pub use backend::runtime::tls::StartupTlsInfo; /// `fork()`—Creates a new process by duplicating the calling process. /// @@ -219,7 +221,7 @@ pub use imp::runtime::tls::StartupTlsInfo; /// [async-signal-safe]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03 #[cfg(linux_raw)] pub unsafe fn fork() -> io::Result<Option<Pid>> { - imp::runtime::syscalls::fork() + backend::runtime::syscalls::fork() } /// `execveat(dirfd, path.as_c_str(), argv, envp, flags)`—Execute a new @@ -236,6 +238,8 @@ pub unsafe fn fork() -> io::Result<Option<Pid>> { /// [Linux]: https://man7.org/linux/man-pages/man2/execveat.2.html #[cfg(linux_raw)] #[inline] +#[cfg(feature = "fs")] +#[cfg_attr(doc_cfg, doc(cfg(feature = "fs")))] pub unsafe fn execveat<Fd: AsFd>( dirfd: Fd, path: &CStr, @@ -243,7 +247,7 @@ pub unsafe fn execveat<Fd: AsFd>( envp: *const *const u8, flags: AtFlags, ) -> io::Errno { - imp::runtime::syscalls::execveat(dirfd.as_fd(), path, argv, envp, flags) + backend::runtime::syscalls::execveat(dirfd.as_fd(), path, argv, envp, flags) } /// `execve(path.as_c_str(), argv, envp)`—Execute a new command using the @@ -261,5 +265,5 @@ pub unsafe fn execveat<Fd: AsFd>( #[cfg(linux_raw)] #[inline] pub unsafe fn execve(path: &CStr, argv: *const *const u8, envp: *const *const u8) -> io::Errno { - imp::runtime::syscalls::execve(path, argv, envp) + backend::runtime::syscalls::execve(path, argv, envp) } diff --git a/vendor/rustix/src/termios/cf.rs b/vendor/rustix/src/termios/cf.rs index d28b65e03..d79eab5c8 100644 --- a/vendor/rustix/src/termios/cf.rs +++ b/vendor/rustix/src/termios/cf.rs @@ -1,40 +1,40 @@ use crate::termios::{Speed, Termios}; -use crate::{imp, io}; +use crate::{backend, io}; /// `cfgetospeed(termios)` #[inline] #[must_use] pub fn cfgetospeed(termios: &Termios) -> Speed { - imp::termios::syscalls::cfgetospeed(termios) + backend::termios::syscalls::cfgetospeed(termios) } /// `cfgetispeed(termios)` #[inline] #[must_use] pub fn cfgetispeed(termios: &Termios) -> Speed { - imp::termios::syscalls::cfgetispeed(termios) + backend::termios::syscalls::cfgetispeed(termios) } /// `cfmakeraw(termios)` #[inline] pub fn cfmakeraw(termios: &mut Termios) { - imp::termios::syscalls::cfmakeraw(termios) + backend::termios::syscalls::cfmakeraw(termios) } /// `cfsetospeed(termios, speed)` #[inline] pub fn cfsetospeed(termios: &mut Termios, speed: Speed) -> io::Result<()> { - imp::termios::syscalls::cfsetospeed(termios, speed) + backend::termios::syscalls::cfsetospeed(termios, speed) } /// `cfsetispeed(termios, speed)` #[inline] pub fn cfsetispeed(termios: &mut Termios, speed: Speed) -> io::Result<()> { - imp::termios::syscalls::cfsetispeed(termios, speed) + backend::termios::syscalls::cfsetispeed(termios, speed) } /// `cfsetspeed(termios, speed)` #[inline] pub fn cfsetspeed(termios: &mut Termios, speed: Speed) -> io::Result<()> { - imp::termios::syscalls::cfsetspeed(termios, speed) + backend::termios::syscalls::cfsetspeed(termios, speed) } diff --git a/vendor/rustix/src/termios/constants.rs b/vendor/rustix/src/termios/constants.rs index 5c10c12ed..e96f139eb 100644 --- a/vendor/rustix/src/termios/constants.rs +++ b/vendor/rustix/src/termios/constants.rs @@ -1,102 +1,142 @@ -use crate::imp; +use crate::backend; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B1000000; +pub use backend::termios::types::B1000000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B1152000; +pub use backend::termios::types::B1152000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B1500000; +pub use backend::termios::types::B1500000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B2000000; +pub use backend::termios::types::B2000000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B2500000; +pub use backend::termios::types::B2500000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B3000000; +pub use backend::termios::types::B3000000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B3500000; +pub use backend::termios::types::B3500000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B4000000; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] -pub use imp::termios::types::B460800; +pub use backend::termios::types::B4000000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +)))] +pub use backend::termios::types::B460800; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B500000; +pub use backend::termios::types::B500000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::B576000; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] -pub use imp::termios::types::B921600; +pub use backend::termios::types::B576000; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +)))] +pub use backend::termios::types::B921600; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::BRKINT; +pub use backend::termios::types::BRKINT; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -107,8 +147,9 @@ pub use imp::termios::types::BRKINT; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::BS0; +pub use backend::termios::types::BS0; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -121,8 +162,9 @@ pub use imp::termios::types::BS0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::BS1; +pub use backend::termios::types::BS1; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -132,54 +174,61 @@ pub use imp::termios::types::BS1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::BSDLY; +pub use backend::termios::types::BSDLY; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", )))] -pub use imp::termios::types::CBAUD; +pub use backend::termios::types::CBAUD; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CBAUDEX; +pub use backend::termios::types::CBAUDEX; #[cfg(not(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", )))] -pub use imp::termios::types::CIBAUD; +pub use backend::termios::types::CIBAUD; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CLOCAL; +pub use backend::termios::types::CLOCAL; #[cfg(not(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CMSPAR; +pub use backend::termios::types::CMSPAR; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -190,8 +239,9 @@ pub use imp::termios::types::CMSPAR; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CR0; +pub use backend::termios::types::CR0; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -204,8 +254,9 @@ pub use imp::termios::types::CR0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CR1; +pub use backend::termios::types::CR1; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -218,8 +269,9 @@ pub use imp::termios::types::CR1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CR2; +pub use backend::termios::types::CR2; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -232,8 +284,9 @@ pub use imp::termios::types::CR2; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CR3; +pub use backend::termios::types::CR3; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -243,56 +296,66 @@ pub use imp::termios::types::CR3; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::CRDLY; +pub use backend::termios::types::CRDLY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CREAD; +pub use backend::termios::types::CREAD; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::CRTSCTS; +pub use backend::termios::types::CRTSCTS; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CS5; +pub use backend::termios::types::CS5; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CS6; +pub use backend::termios::types::CS6; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CS7; +pub use backend::termios::types::CS7; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CS8; +pub use backend::termios::types::CS8; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CSIZE; +pub use backend::termios::types::CSIZE; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::CSTOPB; +pub use backend::termios::types::CSTOPB; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ECHO; +pub use backend::termios::types::ECHO; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::ECHOCTL; +pub use backend::termios::types::ECHOCTL; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ECHOE; +pub use backend::termios::types::ECHOE; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ECHOK; +pub use backend::termios::types::ECHOK; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::ECHOKE; +pub use backend::termios::types::ECHOKE; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ECHONL; +pub use backend::termios::types::ECHONL; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::ECHOPRT; +pub use backend::termios::types::ECHOPRT; #[cfg(not(any( target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::EXTA; +pub use backend::termios::types::EXTA; #[cfg(not(any( target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::EXTB; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::EXTPROC; +pub use backend::termios::types::EXTB; +#[cfg(not(any( + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "redox" +)))] +pub use backend::termios::types::EXTPROC; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -303,8 +366,9 @@ pub use imp::termios::types::EXTPROC; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::FF0; +pub use backend::termios::types::FF0; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -317,8 +381,9 @@ pub use imp::termios::types::FF0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::FF1; +pub use backend::termios::types::FF1; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -329,32 +394,38 @@ pub use imp::termios::types::FF1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::FFDLY; +pub use backend::termios::types::FFDLY; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::FLUSHO; +pub use backend::termios::types::FLUSHO; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::HUPCL; +pub use backend::termios::types::HUPCL; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ICRNL; +pub use backend::termios::types::ICRNL; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::IEXTEN; +pub use backend::termios::types::IEXTEN; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::IGNBRK; +pub use backend::termios::types::IGNBRK; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::IGNCR; +pub use backend::termios::types::IGNCR; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::IGNPAR; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::IMAXBEL; +pub use backend::termios::types::IGNPAR; +#[cfg(not(any( + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "redox" +)))] +pub use backend::termios::types::IMAXBEL; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::INLCR; +pub use backend::termios::types::INLCR; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::INPCK; +pub use backend::termios::types::INPCK; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ISIG; +pub use backend::termios::types::ISIG; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ISTRIP; +pub use backend::termios::types::ISTRIP; #[cfg(any( linux_raw, all( @@ -362,25 +433,27 @@ pub use imp::termios::types::ISTRIP; any(target_os = "haiku", target_os = "illumos", target_os = "solaris"), ) ))] -pub use imp::termios::types::IUCLC; +pub use backend::termios::types::IUCLC; #[cfg(not(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::IUTF8; +pub use backend::termios::types::IUTF8; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::IXANY; +pub use backend::termios::types::IXANY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::IXOFF; +pub use backend::termios::types::IXOFF; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::IXON; +pub use backend::termios::types::IXON; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -391,8 +464,9 @@ pub use imp::termios::types::IXON; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::NL0; +pub use backend::termios::types::NL0; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -403,8 +477,9 @@ pub use imp::termios::types::NL0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::NL1; +pub use backend::termios::types::NL1; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -414,12 +489,13 @@ pub use imp::termios::types::NL1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::NLDLY; +pub use backend::termios::types::NLDLY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::NOFLSH; +pub use backend::termios::types::NOFLSH; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::OCRNL; +pub use backend::termios::types::OCRNL; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -428,7 +504,7 @@ pub use imp::termios::types::OCRNL; target_os = "netbsd", target_os = "openbsd", )))] -pub use imp::termios::types::OFDEL; +pub use backend::termios::types::OFDEL; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -437,7 +513,7 @@ pub use imp::termios::types::OFDEL; target_os = "netbsd", target_os = "openbsd", )))] -pub use imp::termios::types::OFILL; +pub use backend::termios::types::OFILL; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -446,24 +522,25 @@ pub use imp::termios::types::OFILL; target_os = "netbsd", target_os = "redox", )))] -pub use imp::termios::types::OLCUC; +pub use backend::termios::types::OLCUC; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ONLCR; +pub use backend::termios::types::ONLCR; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ONLRET; +pub use backend::termios::types::ONLRET; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::ONOCR; +pub use backend::termios::types::ONOCR; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::OPOST; +pub use backend::termios::types::OPOST; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::PARENB; +pub use backend::termios::types::PARENB; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::PARMRK; +pub use backend::termios::types::PARMRK; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::PARODD; +pub use backend::termios::types::PARODD; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] -pub use imp::termios::types::PENDIN; +pub use backend::termios::types::PENDIN; #[cfg(not(any( + target_os = "dragonfly", target_os = "fuchsia", target_os = "illumos", target_os = "ios", @@ -471,8 +548,9 @@ pub use imp::termios::types::PENDIN; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::TAB0; +pub use backend::termios::types::TAB0; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -485,8 +563,9 @@ pub use imp::termios::types::TAB0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::TAB1; +pub use backend::termios::types::TAB1; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -499,10 +578,12 @@ pub use imp::termios::types::TAB1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::TAB2; +pub use backend::termios::types::TAB2; #[cfg(not(any( all(libc, target_env = "musl"), + target_os = "dragonfly", target_os = "emscripten", target_os = "fuchsia", target_os = "illumos", @@ -511,29 +592,34 @@ pub use imp::termios::types::TAB2; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::TAB3; +pub use backend::termios::types::TAB3; #[cfg(not(any( + target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "illumos", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::TABDLY; +pub use backend::termios::types::TABDLY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] -pub use imp::termios::types::TOSTOP; +pub use backend::termios::types::TOSTOP; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] -pub use imp::termios::types::VSWTC; +pub use backend::termios::types::VSWTC; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", @@ -544,8 +630,9 @@ pub use imp::termios::types::VSWTC; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::VT0; +pub use backend::termios::types::VT0; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -558,8 +645,9 @@ pub use imp::termios::types::VT0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::VT1; +pub use backend::termios::types::VT1; #[cfg(not(any( all(libc, target_env = "musl"), target_os = "dragonfly", @@ -570,26 +658,31 @@ pub use imp::termios::types::VT1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::VTDLY; +pub use backend::termios::types::VTDLY; #[cfg(any(linux_raw, all(libc, any(target_arch = "s390x", target_os = "haiku"))))] -pub use imp::termios::types::XCASE; +pub use backend::termios::types::XCASE; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] -pub use imp::termios::types::XTABS; -pub use imp::termios::types::{ +pub use backend::termios::types::XTABS; +pub use backend::termios::types::{ B0, B110, B115200, B1200, B134, B150, B1800, B19200, B200, B230400, B2400, B300, B38400, B4800, - B50, B57600, B600, B75, B9600, ICANON, VDISCARD, VEOF, VEOL, VEOL2, VERASE, VINTR, VKILL, - VLNEXT, VMIN, VQUIT, VREPRINT, VSTART, VSTOP, VSUSP, VTIME, VWERASE, + B50, B57600, B600, B75, B9600, ICANON, VEOF, VEOL, VEOL2, VERASE, VINTR, VKILL, VMIN, VQUIT, + VSTART, VSTOP, VSUSP, VTIME, }; +#[cfg(not(target_os = "haiku"))] +pub use backend::termios::types::{VDISCARD, VLNEXT, VREPRINT, VWERASE}; /// Translate from a `Speed` code to a speed value `u32`. /// @@ -597,123 +690,163 @@ pub use imp::termios::types::{ /// let speed = rustix::termios::speed_value(rustix::termios::B57600); /// assert_eq!(speed, Some(57600)); /// ``` -pub fn speed_value(speed: imp::termios::types::Speed) -> Option<u32> { +pub fn speed_value(speed: backend::termios::types::Speed) -> Option<u32> { match speed { - imp::termios::types::B0 => Some(0), - imp::termios::types::B50 => Some(50), - imp::termios::types::B75 => Some(75), - imp::termios::types::B110 => Some(110), - imp::termios::types::B134 => Some(134), - imp::termios::types::B150 => Some(150), - imp::termios::types::B200 => Some(200), - imp::termios::types::B300 => Some(300), - imp::termios::types::B600 => Some(600), - imp::termios::types::B1200 => Some(1200), - imp::termios::types::B1800 => Some(1800), - imp::termios::types::B2400 => Some(2400), - imp::termios::types::B4800 => Some(4800), - imp::termios::types::B9600 => Some(9600), - imp::termios::types::B19200 => Some(19200), - imp::termios::types::B38400 => Some(38400), - imp::termios::types::B57600 => Some(57600), - imp::termios::types::B115200 => Some(115_200), - imp::termios::types::B230400 => Some(230_400), - #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] - imp::termios::types::B460800 => Some(460_800), + backend::termios::types::B0 => Some(0), + backend::termios::types::B50 => Some(50), + backend::termios::types::B75 => Some(75), + backend::termios::types::B110 => Some(110), + backend::termios::types::B134 => Some(134), + backend::termios::types::B150 => Some(150), + backend::termios::types::B200 => Some(200), + backend::termios::types::B300 => Some(300), + backend::termios::types::B600 => Some(600), + backend::termios::types::B1200 => Some(1200), + backend::termios::types::B1800 => Some(1800), + backend::termios::types::B2400 => Some(2400), + backend::termios::types::B4800 => Some(4800), + backend::termios::types::B9600 => Some(9600), + backend::termios::types::B19200 => Some(19200), + backend::termios::types::B38400 => Some(38400), + backend::termios::types::B57600 => Some(57600), + backend::termios::types::B115200 => Some(115_200), + backend::termios::types::B230400 => Some(230_400), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" + )))] + backend::termios::types::B460800 => Some(460_800), #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B500000 => Some(500_000), + backend::termios::types::B500000 => Some(500_000), #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", + )))] + backend::termios::types::B576000 => Some(576_000), + #[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" )))] - imp::termios::types::B576000 => Some(576_000), - #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] - imp::termios::types::B921600 => Some(921_600), + backend::termios::types::B921600 => Some(921_600), #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B1000000 => Some(1_000_000), + backend::termios::types::B1000000 => Some(1_000_000), #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B1152000 => Some(1_152_000), + backend::termios::types::B1152000 => Some(1_152_000), #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B1500000 => Some(1_500_000), + backend::termios::types::B1500000 => Some(1_500_000), #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B2000000 => Some(2_000_000), + backend::termios::types::B2000000 => Some(2_000_000), #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B2500000 => Some(2_500_000), + backend::termios::types::B2500000 => Some(2_500_000), #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B3000000 => Some(3_000_000), + backend::termios::types::B3000000 => Some(3_000_000), #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B3500000 => Some(3_500_000), + backend::termios::types::B3500000 => Some(3_500_000), #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] - imp::termios::types::B4000000 => Some(4_000_000), + backend::termios::types::B4000000 => Some(4_000_000), _ => None, } } diff --git a/vendor/rustix/src/termios/mod.rs b/vendor/rustix/src/termios/mod.rs index 79f2f6b38..ec35f96fb 100644 --- a/vendor/rustix/src/termios/mod.rs +++ b/vendor/rustix/src/termios/mod.rs @@ -10,98 +10,138 @@ pub use cf::{cfgetispeed, cfgetospeed, cfmakeraw, cfsetispeed, cfsetospeed, cfse #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B1000000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B1152000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B1500000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B2000000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B2500000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B3000000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B3500000; #[cfg(not(any( + target_arch = "sparc", + target_arch = "sparc64", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B4000000; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +)))] pub use constants::B460800; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B500000; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::B576000; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "openbsd")))] +#[cfg(not(any( + target_os = "dragonfly", + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "openbsd" +)))] pub use constants::B921600; #[cfg(not(any(target_os = "ios", target_os = "macos")))] pub use constants::BRKINT; @@ -115,6 +155,7 @@ pub use constants::BRKINT; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::BS0; #[cfg(not(any( @@ -129,6 +170,7 @@ pub use constants::BS0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::BS1; #[cfg(not(any( @@ -140,11 +182,13 @@ pub use constants::BS1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::BSDLY; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -155,18 +199,21 @@ pub use constants::CBAUD; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CBAUDEX; #[cfg(not(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -180,12 +227,14 @@ pub use constants::CLOCAL; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CMSPAR; #[cfg(not(any( @@ -198,6 +247,7 @@ pub use constants::CMSPAR; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CR0; #[cfg(not(any( @@ -212,6 +262,7 @@ pub use constants::CR0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CR1; #[cfg(not(any( @@ -226,6 +277,7 @@ pub use constants::CR1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CR2; #[cfg(not(any( @@ -240,6 +292,7 @@ pub use constants::CR2; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CR3; #[cfg(not(any( @@ -251,6 +304,7 @@ pub use constants::CR3; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::CRDLY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] @@ -285,21 +339,30 @@ pub use constants::ECHONL; pub use constants::ECHOPRT; #[cfg(not(any( target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] pub use constants::EXTA; #[cfg(not(any( target_os = "emscripten", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "solaris", )))] pub use constants::EXTB; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +#[cfg(not(any( + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "redox" +)))] pub use constants::EXTPROC; #[cfg(not(any( target_os = "dragonfly", @@ -311,6 +374,7 @@ pub use constants::EXTPROC; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::FF0; #[cfg(not(any( @@ -325,6 +389,7 @@ pub use constants::FF0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::FF1; #[cfg(not(any( @@ -337,6 +402,7 @@ pub use constants::FF1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::FFDLY; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] @@ -353,7 +419,12 @@ pub use constants::IGNBRK; pub use constants::IGNCR; #[cfg(not(any(target_os = "ios", target_os = "macos")))] pub use constants::IGNPAR; -#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +#[cfg(not(any( + target_os = "haiku", + target_os = "ios", + target_os = "macos", + target_os = "redox" +)))] pub use constants::IMAXBEL; #[cfg(not(any(target_os = "ios", target_os = "macos")))] pub use constants::INLCR; @@ -375,12 +446,14 @@ pub use constants::IUCLC; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::IUTF8; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] @@ -399,6 +472,7 @@ pub use constants::IXON; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::NL0; #[cfg(not(any( @@ -411,6 +485,7 @@ pub use constants::NL0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::NL1; #[cfg(not(any( @@ -422,6 +497,7 @@ pub use constants::NL1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::NLDLY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] @@ -472,6 +548,7 @@ pub use constants::PARODD; #[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] pub use constants::PENDIN; #[cfg(not(any( + target_os = "dragonfly", target_os = "fuchsia", target_os = "illumos", target_os = "ios", @@ -479,6 +556,7 @@ pub use constants::PENDIN; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::TAB0; #[cfg(not(any( @@ -493,6 +571,7 @@ pub use constants::TAB0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::TAB1; #[cfg(not(any( @@ -507,10 +586,12 @@ pub use constants::TAB1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::TAB2; #[cfg(not(any( all(libc, target_env = "musl"), + target_os = "dragonfly", target_os = "emscripten", target_os = "fuchsia", target_os = "illumos", @@ -519,15 +600,18 @@ pub use constants::TAB2; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::TAB3; #[cfg(not(any( + target_os = "dragonfly", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "illumos", target_os = "redox", + target_os = "solaris", )))] pub use constants::TABDLY; #[cfg(not(any(target_os = "ios", target_os = "macos")))] @@ -535,11 +619,13 @@ pub use constants::TOSTOP; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", )))] pub use constants::VSWTC; #[cfg(not(any( @@ -552,6 +638,7 @@ pub use constants::VSWTC; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::VT0; #[cfg(not(any( @@ -566,6 +653,7 @@ pub use constants::VT0; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::VT1; #[cfg(not(any( @@ -578,6 +666,7 @@ pub use constants::VT1; target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::VTDLY; #[cfg(any(linux_raw, all(libc, any(target_arch = "s390x", target_os = "haiku"))))] @@ -585,19 +674,23 @@ pub use constants::XCASE; #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "solaris", )))] pub use constants::XTABS; pub use constants::{ speed_value, B0, B110, B115200, B1200, B134, B150, B1800, B19200, B200, B230400, B2400, B300, - B38400, B4800, B50, B57600, B600, B75, B9600, ICANON, VDISCARD, VEOF, VEOL, VEOL2, VERASE, - VINTR, VKILL, VLNEXT, VMIN, VQUIT, VREPRINT, VSTART, VSTOP, VSUSP, VTIME, VWERASE, + B38400, B4800, B50, B57600, B600, B75, B9600, ICANON, VEOF, VEOL, VEOL2, VERASE, VINTR, VKILL, + VMIN, VQUIT, VSTART, VSTOP, VSUSP, VTIME, }; +#[cfg(not(target_os = "haiku"))] +pub use constants::{VDISCARD, VLNEXT, VREPRINT, VWERASE}; pub use tc::{ tcdrain, tcflow, tcflush, tcgetattr, tcgetpgrp, tcgetsid, tcgetwinsize, tcsendbreak, tcsetattr, tcsetpgrp, tcsetwinsize, Action, OptionalActions, QueueSelector, Speed, Tcflag, Termios, diff --git a/vendor/rustix/src/termios/tc.rs b/vendor/rustix/src/termios/tc.rs index b44eafde3..e1a87b623 100644 --- a/vendor/rustix/src/termios/tc.rs +++ b/vendor/rustix/src/termios/tc.rs @@ -1,8 +1,8 @@ use crate::fd::AsFd; use crate::process::Pid; -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::termios::types::{ +pub use backend::termios::types::{ Action, OptionalActions, QueueSelector, Speed, Tcflag, Termios, Winsize, }; @@ -22,7 +22,7 @@ pub use imp::termios::types::{ #[inline] #[doc(alias = "TCGETS")] pub fn tcgetattr<Fd: AsFd>(fd: Fd) -> io::Result<Termios> { - imp::termios::syscalls::tcgetattr(fd.as_fd()) + backend::termios::syscalls::tcgetattr(fd.as_fd()) } /// `tcgetwinsize(fd)`—Get the current terminal window size. @@ -37,7 +37,7 @@ pub fn tcgetattr<Fd: AsFd>(fd: Fd) -> io::Result<Termios> { #[inline] #[doc(alias = "TIOCGWINSZ")] pub fn tcgetwinsize<Fd: AsFd>(fd: Fd) -> io::Result<Winsize> { - imp::termios::syscalls::tcgetwinsize(fd.as_fd()) + backend::termios::syscalls::tcgetwinsize(fd.as_fd()) } /// `tcgetpgrp(fd)`—Get the terminal foreground process group. @@ -54,7 +54,7 @@ pub fn tcgetwinsize<Fd: AsFd>(fd: Fd) -> io::Result<Winsize> { #[inline] #[doc(alias = "TIOCGPGRP")] pub fn tcgetpgrp<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { - imp::termios::syscalls::tcgetpgrp(fd.as_fd()) + backend::termios::syscalls::tcgetpgrp(fd.as_fd()) } /// `tcsetpgrp(fd, pid)`—Set the terminal foreground process group. @@ -71,7 +71,7 @@ pub fn tcgetpgrp<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { #[inline] #[doc(alias = "TIOCSPGRP")] pub fn tcsetpgrp<Fd: AsFd>(fd: Fd, pid: Pid) -> io::Result<()> { - imp::termios::syscalls::tcsetpgrp(fd.as_fd(), pid) + backend::termios::syscalls::tcsetpgrp(fd.as_fd(), pid) } /// `tcsetattr(fd)`—Set terminal attributes. @@ -93,7 +93,7 @@ pub fn tcsetattr<Fd: AsFd>( optional_actions: OptionalActions, termios: &Termios, ) -> io::Result<()> { - imp::termios::syscalls::tcsetattr(fd.as_fd(), optional_actions, termios) + backend::termios::syscalls::tcsetattr(fd.as_fd(), optional_actions, termios) } /// `tcsendbreak(fd, 0)`—Transmit zero-valued bits. @@ -115,7 +115,7 @@ pub fn tcsetattr<Fd: AsFd>( #[inline] #[doc(alias = "TCSBRK")] pub fn tcsendbreak<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::termios::syscalls::tcsendbreak(fd.as_fd()) + backend::termios::syscalls::tcsendbreak(fd.as_fd()) } /// `tcdrain(fd, duration)`—Wait until all pending output has been written. @@ -130,7 +130,7 @@ pub fn tcsendbreak<Fd: AsFd>(fd: Fd) -> io::Result<()> { /// [Linux `termios`]: https://man7.org/linux/man-pages/man3/termios.3.html #[inline] pub fn tcdrain<Fd: AsFd>(fd: Fd) -> io::Result<()> { - imp::termios::syscalls::tcdrain(fd.as_fd()) + backend::termios::syscalls::tcdrain(fd.as_fd()) } /// `tcflush(fd, queue_selector)`—Wait until all pending output has been @@ -147,7 +147,7 @@ pub fn tcdrain<Fd: AsFd>(fd: Fd) -> io::Result<()> { #[inline] #[doc(alias = "TCFLSH")] pub fn tcflush<Fd: AsFd>(fd: Fd, queue_selector: QueueSelector) -> io::Result<()> { - imp::termios::syscalls::tcflush(fd.as_fd(), queue_selector) + backend::termios::syscalls::tcflush(fd.as_fd(), queue_selector) } /// `tcflow(fd, action)`—Suspend or resume transmission or reception. @@ -163,7 +163,7 @@ pub fn tcflush<Fd: AsFd>(fd: Fd, queue_selector: QueueSelector) -> io::Result<() #[inline] #[doc(alias = "TCXONC")] pub fn tcflow<Fd: AsFd>(fd: Fd, action: Action) -> io::Result<()> { - imp::termios::syscalls::tcflow(fd.as_fd(), action) + backend::termios::syscalls::tcflow(fd.as_fd(), action) } /// `tcgetsid(fd)`—Return the session ID of the current session with `fd` as @@ -178,7 +178,7 @@ pub fn tcflow<Fd: AsFd>(fd: Fd, action: Action) -> io::Result<()> { #[inline] #[doc(alias = "TIOCGSID")] pub fn tcgetsid<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { - imp::termios::syscalls::tcgetsid(fd.as_fd()) + backend::termios::syscalls::tcgetsid(fd.as_fd()) } /// `tcsetwinsize(fd)`—Set the current terminal window size. @@ -192,5 +192,5 @@ pub fn tcgetsid<Fd: AsFd>(fd: Fd) -> io::Result<Pid> { #[inline] #[doc(alias = "TIOCSWINSZ")] pub fn tcsetwinsize<Fd: AsFd>(fd: Fd, winsize: Winsize) -> io::Result<()> { - imp::termios::syscalls::tcsetwinsize(fd.as_fd(), winsize) + backend::termios::syscalls::tcsetwinsize(fd.as_fd(), winsize) } diff --git a/vendor/rustix/src/termios/tty.rs b/vendor/rustix/src/termios/tty.rs index 1651a3c3b..9a1692330 100644 --- a/vendor/rustix/src/termios/tty.rs +++ b/vendor/rustix/src/termios/tty.rs @@ -1,19 +1,20 @@ //! Functions which operate on file descriptors which might be terminals. -use crate::imp; +use crate::backend; #[cfg(any( all(linux_raw, feature = "procfs"), all(libc, not(any(target_os = "fuchsia", target_os = "wasi"))), ))] #[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))] use crate::io; -use imp::fd::AsFd; +use backend::fd::AsFd; #[cfg(any( all(linux_raw, feature = "procfs"), all(libc, not(any(target_os = "fuchsia", target_os = "wasi"))), ))] use { - crate::ffi::CString, crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec, imp::fd::BorrowedFd, + crate::ffi::CString, crate::path::SMALL_PATH_BUFFER_SIZE, alloc::vec::Vec, + backend::fd::BorrowedFd, }; /// `isatty(fd)`—Tests whether a file descriptor refers to a terminal. @@ -26,7 +27,7 @@ use { /// [Linux]: https://man7.org/linux/man-pages/man3/isatty.3.html #[inline] pub fn isatty<Fd: AsFd>(fd: Fd) -> bool { - imp::termios::syscalls::isatty(fd.as_fd()) + backend::termios::syscalls::isatty(fd.as_fd()) } /// `ttyname_r(fd)` @@ -57,7 +58,7 @@ fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> { buffer.resize(buffer.capacity(), 0_u8); loop { - match imp::termios::syscalls::ttyname(dirfd, &mut buffer) { + match backend::termios::syscalls::ttyname(dirfd, &mut buffer) { Err(io::Errno::RANGE) => { buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially buffer.resize(buffer.capacity(), 0_u8); diff --git a/vendor/rustix/src/thread/clock.rs b/vendor/rustix/src/thread/clock.rs index 206703088..57672fa17 100644 --- a/vendor/rustix/src/thread/clock.rs +++ b/vendor/rustix/src/thread/clock.rs @@ -1,6 +1,6 @@ -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::time::types::Timespec; +pub use backend::time::types::Timespec; #[cfg(not(any( target_os = "dragonfly", @@ -12,7 +12,7 @@ pub use imp::time::types::Timespec; target_os = "redox", target_os = "wasi", )))] -pub use imp::time::types::ClockId; +pub use backend::time::types::ClockId; /// `clock_nanosleep(id, 0, request, remain)`—Sleeps for a duration on a /// given clock. @@ -30,6 +30,7 @@ pub use imp::time::types::ClockId; target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "openbsd", @@ -38,7 +39,7 @@ pub use imp::time::types::ClockId; )))] #[inline] pub fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> NanosleepRelativeResult { - imp::thread::syscalls::clock_nanosleep_relative(id, request) + backend::thread::syscalls::clock_nanosleep_relative(id, request) } /// `clock_nanosleep(id, TIMER_ABSTIME, request, NULL)`—Sleeps until an @@ -57,6 +58,7 @@ pub fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> NanosleepRel target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", // FreeBSD 12 has clock_nanosleep, but libc targets FreeBSD 11. + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "openbsd", @@ -65,7 +67,7 @@ pub fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> NanosleepRel )))] #[inline] pub fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::Result<()> { - imp::thread::syscalls::clock_nanosleep_absolute(id, request) + backend::thread::syscalls::clock_nanosleep_absolute(id, request) } /// `nanosleep(request, remain)`—Sleeps for a duration. @@ -80,7 +82,7 @@ pub fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::Result<( /// [Linux]: https://man7.org/linux/man-pages/man2/nanosleep.2.html #[inline] pub fn nanosleep(request: &Timespec) -> NanosleepRelativeResult { - imp::thread::syscalls::nanosleep(request) + backend::thread::syscalls::nanosleep(request) } /// A return type for `nanosleep` and `clock_nanosleep_relative`. diff --git a/vendor/rustix/src/thread/futex.rs b/vendor/rustix/src/thread/futex.rs index df5b561f1..7c4399f7a 100644 --- a/vendor/rustix/src/thread/futex.rs +++ b/vendor/rustix/src/thread/futex.rs @@ -7,9 +7,9 @@ #![allow(unsafe_code)] use crate::thread::Timespec; -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::thread::{FutexFlags, FutexOperation}; +pub use backend::thread::{FutexFlags, FutexOperation}; /// `futex(uaddr, op, val, utime, uaddr2, val3)` /// @@ -34,5 +34,5 @@ pub unsafe fn futex( uaddr2: *mut u32, val3: u32, ) -> io::Result<usize> { - imp::thread::syscalls::futex(uaddr, op, flags, val, utime, uaddr2, val3) + backend::thread::syscalls::futex(uaddr, op, flags, val, utime, uaddr2, val3) } diff --git a/vendor/rustix/src/thread/id.rs b/vendor/rustix/src/thread/id.rs index 964d2654c..0d2fef026 100644 --- a/vendor/rustix/src/thread/id.rs +++ b/vendor/rustix/src/thread/id.rs @@ -1,4 +1,4 @@ -use crate::imp; +use crate::backend; use crate::process::Pid; /// `gettid()`—Returns the thread ID. @@ -13,5 +13,5 @@ use crate::process::Pid; #[inline] #[must_use] pub fn gettid() -> Pid { - imp::thread::syscalls::gettid() + backend::thread::syscalls::gettid() } diff --git a/vendor/rustix/src/thread/mod.rs b/vendor/rustix/src/thread/mod.rs index ac48b435b..b1dc849d9 100644 --- a/vendor/rustix/src/thread/mod.rs +++ b/vendor/rustix/src/thread/mod.rs @@ -6,11 +6,16 @@ mod clock; mod futex; #[cfg(any(target_os = "android", target_os = "linux"))] mod id; +#[cfg(any(target_os = "android", target_os = "linux"))] +mod prctl; +#[cfg(any(target_os = "android", target_os = "linux"))] +mod setns; #[cfg(not(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "openbsd", @@ -24,3 +29,7 @@ pub use clock::{nanosleep, NanosleepRelativeResult, Timespec}; pub use futex::{futex, FutexFlags, FutexOperation}; #[cfg(any(target_os = "android", target_os = "linux"))] pub use id::gettid; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use prctl::*; +#[cfg(any(target_os = "android", target_os = "linux"))] +pub use setns::*; diff --git a/vendor/rustix/src/thread/prctl.rs b/vendor/rustix/src/thread/prctl.rs new file mode 100644 index 000000000..a2191f7c3 --- /dev/null +++ b/vendor/rustix/src/thread/prctl.rs @@ -0,0 +1,989 @@ +#![allow(unsafe_code)] + +use core::convert::TryFrom; +use core::mem::MaybeUninit; +use core::num::NonZeroU64; +use core::ptr; +use core::ptr::NonNull; +use core::sync::atomic::AtomicU8; + +use bitflags::bitflags; + +use crate::backend::c::{c_int, c_uint, c_void}; +use crate::backend::process::syscalls; +use crate::ffi::{CStr, CString}; +use crate::io; +use crate::process::{ + prctl_1arg, prctl_2args, prctl_3args, prctl_get_at_arg2_optional, Pid, + PointerAuthenticationKeys, +}; + +// +// PR_GET_KEEPCAPS/PR_SET_KEEPCAPS +// + +const PR_GET_KEEPCAPS: c_int = 7; + +/// Get the current state of the calling thread's `keep capabilities` flag. +/// +/// # References +/// - [`prctl(PR_GET_KEEPCAPS,...)`] +/// +/// [`prctl(PR_GET_KEEPCAPS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn get_keep_capabilities() -> io::Result<bool> { + unsafe { prctl_1arg(PR_GET_KEEPCAPS) }.map(|r| r != 0) +} + +const PR_SET_KEEPCAPS: c_int = 8; + +/// Set the state of the calling thread's `keep capabilities` flag. +/// +/// # References +/// - [`prctl(PR_SET_KEEPCAPS,...)`] +/// +/// [`prctl(PR_SET_KEEPCAPS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_keep_capabilities(enable: bool) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_KEEPCAPS, enable as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_NAME/PR_SET_NAME +// + +const PR_GET_NAME: c_int = 16; + +/// Get the name of the calling thread. +/// +/// # References +/// - [`prctl(PR_GET_NAME,...)`] +/// +/// [`prctl(PR_GET_NAME,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn name() -> io::Result<CString> { + let mut buffer = [0_u8; 16]; + unsafe { prctl_2args(PR_GET_NAME, buffer.as_mut_ptr().cast())? }; + + let len = buffer.iter().position(|&x| x == 0_u8).unwrap_or(0); + CString::new(&buffer[..len]).map_err(|_r| io::Errno::ILSEQ) +} + +const PR_SET_NAME: c_int = 15; + +/// Set the name of the calling thread. +/// +/// # References +/// - [`prctl(PR_SET_NAME,...)`] +/// +/// [`prctl(PR_SET_NAME,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_name(name: &CStr) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_NAME, name.as_ptr() as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_SECCOMP/PR_SET_SECCOMP +// + +//const PR_GET_SECCOMP: c_int = 21; + +const SECCOMP_MODE_DISABLED: i32 = 0; +const SECCOMP_MODE_STRICT: i32 = 1; +const SECCOMP_MODE_FILTER: i32 = 2; + +/// `SECCOMP_MODE_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(i32)] +pub enum SecureComputingMode { + /// Secure computing is not in use. + Disabled = SECCOMP_MODE_DISABLED, + /// Use hard-coded filter. + Strict = SECCOMP_MODE_STRICT, + /// Use user-supplied filter. + Filter = SECCOMP_MODE_FILTER, +} + +impl TryFrom<i32> for SecureComputingMode { + type Error = io::Errno; + + fn try_from(value: i32) -> Result<Self, Self::Error> { + match value { + SECCOMP_MODE_DISABLED => Ok(Self::Disabled), + SECCOMP_MODE_STRICT => Ok(Self::Strict), + SECCOMP_MODE_FILTER => Ok(Self::Filter), + _ => Err(io::Errno::RANGE), + } + } +} + +/* +/// Get the secure computing mode of the calling thread. +/// +/// If the caller is not in secure computing mode, this returns [`SecureComputingMode::Disabled`]. +/// If the caller is in strict secure computing mode, then this call will cause a `SIGKILL` signal +/// to be sent to the process. +/// If the caller is in filter mode, and this system call is allowed by the seccomp filters, +/// it returns [`SecureComputingMode::Filter`]; otherwise, the process is killed with +/// a `SIGKILL` signal. +/// +/// Since Linux 3.8, the Seccomp field of the `/proc/[pid]/status` file provides a method +/// of obtaining the same information, without the risk that the process is killed; see `proc(5)`. +/// +/// # References +/// - [`prctl(PR_GET_SECCOMP,...)`] +/// +/// [`prctl(PR_GET_SECCOMP,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn secure_computing_mode() -> io::Result<SecureComputingMode> { + unsafe { prctl_1arg(PR_GET_SECCOMP) }.and_then(TryInto::try_into) +} +*/ + +const PR_SET_SECCOMP: c_int = 22; + +/// Set the secure computing mode for the calling thread, to limit the available system calls. +/// +/// # References +/// - [`prctl(PR_SET_SECCOMP,...)`] +/// +/// [`prctl(PR_SET_SECCOMP,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_secure_computing_mode(mode: SecureComputingMode) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_SECCOMP, mode as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_CAPBSET_READ/PR_CAPBSET_DROP +// + +const PR_CAPBSET_READ: c_int = 23; + +const CAP_CHOWN: u32 = 0; +const CAP_DAC_OVERRIDE: u32 = 1; +const CAP_DAC_READ_SEARCH: u32 = 2; +const CAP_FOWNER: u32 = 3; +const CAP_FSETID: u32 = 4; +const CAP_KILL: u32 = 5; +const CAP_SETGID: u32 = 6; +const CAP_SETUID: u32 = 7; +const CAP_SETPCAP: u32 = 8; +const CAP_LINUX_IMMUTABLE: u32 = 9; +const CAP_NET_BIND_SERVICE: u32 = 10; +const CAP_NET_BROADCAST: u32 = 11; +const CAP_NET_ADMIN: u32 = 12; +const CAP_NET_RAW: u32 = 13; +const CAP_IPC_LOCK: u32 = 14; +const CAP_IPC_OWNER: u32 = 15; +const CAP_SYS_MODULE: u32 = 16; +const CAP_SYS_RAWIO: u32 = 17; +const CAP_SYS_CHROOT: u32 = 18; +const CAP_SYS_PTRACE: u32 = 19; +const CAP_SYS_PACCT: u32 = 20; +const CAP_SYS_ADMIN: u32 = 21; +const CAP_SYS_BOOT: u32 = 22; +const CAP_SYS_NICE: u32 = 23; +const CAP_SYS_RESOURCE: u32 = 24; +const CAP_SYS_TIME: u32 = 25; +const CAP_SYS_TTY_CONFIG: u32 = 26; +const CAP_MKNOD: u32 = 27; +const CAP_LEASE: u32 = 28; +const CAP_AUDIT_WRITE: u32 = 29; +const CAP_AUDIT_CONTROL: u32 = 30; +const CAP_SETFCAP: u32 = 31; +const CAP_MAC_OVERRIDE: u32 = 32; +const CAP_MAC_ADMIN: u32 = 33; +const CAP_SYSLOG: u32 = 34; +const CAP_WAKE_ALARM: u32 = 35; +const CAP_BLOCK_SUSPEND: u32 = 36; +const CAP_AUDIT_READ: u32 = 37; +const CAP_PERFMON: u32 = 38; +const CAP_BPF: u32 = 39; +const CAP_CHECKPOINT_RESTORE: u32 = 40; + +/// Linux per-thread capability. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum Capability { + /// In a system with the `_POSIX_CHOWN_RESTRICTED` option defined, this overrides + /// the restriction of changing file ownership and group ownership. + ChangeOwnership = CAP_CHOWN, + /// Override all DAC access, including ACL execute access if `_POSIX_ACL` is defined. + /// Excluding DAC access covered by [`Capability::LinuxImmutable`]. + DACOverride = CAP_DAC_OVERRIDE, + /// Overrides all DAC restrictions regarding read and search on files and directories, + /// including ACL restrictions if `_POSIX_ACL` is defined. Excluding DAC access covered + /// by [`Capability::LinuxImmutable`]. + DACReadSearch = CAP_DAC_READ_SEARCH, + /// Overrides all restrictions about allowed operations on files, where file owner ID must be + /// equal to the user ID, except where [`Capability::FileSetID`] is applicable. + /// It doesn't override MAC and DAC restrictions. + FileOwner = CAP_FOWNER, + /// Overrides the following restrictions that the effective user ID shall match the file owner + /// ID when setting the `S_ISUID` and `S_ISGID` bits on that file; that the effective group ID + /// (or one of the supplementary group IDs) shall match the file owner ID when setting the + /// `S_ISGID` bit on that file; that the `S_ISUID` and `S_ISGID` bits are cleared on successful + /// return from `chown` (not implemented). + FileSetID = CAP_FSETID, + /// Overrides the restriction that the real or effective user ID of a process sending a signal + /// must match the real or effective user ID of the process receiving the signal. + Kill = CAP_KILL, + /// Allows `setgid` manipulation. Allows `setgroups`. Allows forged gids on socket + /// credentials passing. + SetGroupID = CAP_SETGID, + /// Allows `set*uid` manipulation (including fsuid). Allows forged pids on socket + /// credentials passing. + SetUserID = CAP_SETUID, + /// Without VFS support for capabilities: + /// - Transfer any capability in your permitted set to any pid. + /// - remove any capability in your permitted set from any pid. + /// With VFS support for capabilities (neither of above, but) + /// - Add any capability from current's capability bounding set to the current process' + /// inheritable set. + /// - Allow taking bits out of capability bounding set. + /// - Allow modification of the securebits for a process. + SetPermittedCapabilities = CAP_SETPCAP, + /// Allow modification of `S_IMMUTABLE` and `S_APPEND` file attributes. + LinuxImmutable = CAP_LINUX_IMMUTABLE, + /// Allows binding to TCP/UDP sockets below 1024. Allows binding to ATM VCIs below 32. + NetBindService = CAP_NET_BIND_SERVICE, + /// Allow broadcasting, listen to multicast. + NetBroadcast = CAP_NET_BROADCAST, + /// Allow interface configuration. Allow administration of IP firewall, masquerading and + /// accounting. Allow setting debug option on sockets. Allow modification of routing tables. + /// Allow setting arbitrary process / process group ownership on sockets. Allow binding to any + /// address for transparent proxying (also via [`Capability::NetRaw`]). Allow setting TOS + /// (type of service). Allow setting promiscuous mode. Allow clearing driver statistics. + /// Allow multicasting. Allow read/write of device-specific registers. Allow activation of ATM + /// control sockets. + NetAdmin = CAP_NET_ADMIN, + /// Allow use of `RAW` sockets. Allow use of `PACKET` sockets. Allow binding to any address for + /// transparent proxying (also via [`Capability::NetAdmin`]). + NetRaw = CAP_NET_RAW, + /// Allow locking of shared memory segments. Allow mlock and mlockall (which doesn't really have + /// anything to do with IPC). + IPCLock = CAP_IPC_LOCK, + /// Override IPC ownership checks. + IPCOwner = CAP_IPC_OWNER, + /// Insert and remove kernel modules - modify kernel without limit. + SystemModule = CAP_SYS_MODULE, + /// Allow ioperm/iopl access. Allow sending USB messages to any device via `/dev/bus/usb`. + SystemRawIO = CAP_SYS_RAWIO, + /// Allow use of `chroot`. + SystemChangeRoot = CAP_SYS_CHROOT, + /// Allow `ptrace` of any process. + SystemProcessTrace = CAP_SYS_PTRACE, + /// Allow configuration of process accounting. + SystemProcessAccounting = CAP_SYS_PACCT, + /// Allow configuration of the secure attention key. Allow administration of the random device. + /// Allow examination and configuration of disk quotas. Allow setting the domainname. + /// Allow setting the hostname. Allow `mount` and `umount`, setting up new smb connection. + /// Allow some autofs root ioctls. Allow nfsservctl. Allow `VM86_REQUEST_IRQ`. + /// Allow to read/write pci config on alpha. Allow `irix_prctl` on mips (setstacksize). + /// Allow flushing all cache on m68k (`sys_cacheflush`). Allow removing semaphores. + /// Used instead of [`Capability::ChangeOwnership`] to "chown" IPC message queues, semaphores + /// and shared memory. Allow locking/unlocking of shared memory segment. Allow turning swap + /// on/off. Allow forged pids on socket credentials passing. Allow setting readahead and + /// flushing buffers on block devices. Allow setting geometry in floppy driver. Allow turning + /// DMA on/off in `xd` driver. Allow administration of md devices (mostly the above, but some + /// extra ioctls). Allow tuning the ide driver. Allow access to the nvram device. Allow + /// administration of `apm_bios`, serial and bttv (TV) device. Allow manufacturer commands in + /// isdn CAPI support driver. Allow reading non-standardized portions of pci configuration + /// space. Allow DDI debug ioctl on sbpcd driver. Allow setting up serial ports. Allow sending + /// raw qic-117 commands. Allow enabling/disabling tagged queuing on SCSI controllers and + /// sending arbitrary SCSI commands. Allow setting encryption key on loopback filesystem. + /// Allow setting zone reclaim policy. Allow everything under + /// [`Capability::BerkeleyPacketFilters`] and [`Capability::PerformanceMonitoring`] for backward + /// compatibility. + SystemAdmin = CAP_SYS_ADMIN, + /// Allow use of `reboot`. + SystemBoot = CAP_SYS_BOOT, + /// Allow raising priority and setting priority on other (different UID) processes. Allow use of + /// FIFO and round-robin (realtime) scheduling on own processes and setting the scheduling + /// algorithm used by another process. Allow setting cpu affinity on other processes. + /// Allow setting realtime ioprio class. Allow setting ioprio class on other processes. + SystemNice = CAP_SYS_NICE, + /// Override resource limits. Set resource limits. Override quota limits. Override reserved + /// space on ext2 filesystem. Modify data journaling mode on ext3 filesystem (uses journaling + /// resources). NOTE: ext2 honors fsuid when checking for resource overrides, so you can + /// override using fsuid too. Override size restrictions on IPC message queues. Allow more than + /// 64hz interrupts from the real-time clock. Override max number of consoles on console + /// allocation. Override max number of keymaps. Control memory reclaim behavior. + SystemResource = CAP_SYS_RESOURCE, + /// Allow manipulation of system clock. Allow `irix_stime` on mips. Allow setting the real-time + /// clock. + SystemTime = CAP_SYS_TIME, + /// Allow configuration of tty devices. Allow `vhangup` of tty. + SystemTTYConfig = CAP_SYS_TTY_CONFIG, + /// Allow the privileged aspects of `mknod`. + MakeNode = CAP_MKNOD, + /// Allow taking of leases on files. + Lease = CAP_LEASE, + /// Allow writing the audit log via unicast netlink socket. + AuditWrite = CAP_AUDIT_WRITE, + /// Allow configuration of audit via unicast netlink socket. + AuditControl = CAP_AUDIT_CONTROL, + /// Set or remove capabilities on files. Map `uid=0` into a child user namespace. + SetFileCapabilities = CAP_SETFCAP, + /// Override MAC access. The base kernel enforces no MAC policy. An LSM may enforce a MAC + /// policy, and if it does and it chooses to implement capability based overrides of that + /// policy, this is the capability it should use to do so. + MACOverride = CAP_MAC_OVERRIDE, + /// Allow MAC configuration or state changes. The base kernel requires no MAC configuration. + /// An LSM may enforce a MAC policy, and if it does and it chooses to implement capability based + /// checks on modifications to that policy or the data required to maintain it, this is the + /// capability it should use to do so. + MACAdmin = CAP_MAC_ADMIN, + /// Allow configuring the kernel's `syslog` (`printk` behaviour). + SystemLog = CAP_SYSLOG, + /// Allow triggering something that will wake the system. + WakeAlarm = CAP_WAKE_ALARM, + /// Allow preventing system suspends. + BlockSuspend = CAP_BLOCK_SUSPEND, + /// Allow reading the audit log via multicast netlink socket. + AuditRead = CAP_AUDIT_READ, + /// Allow system performance and observability privileged operations using `perf_events`, + /// `i915_perf` and other kernel subsystems. + PerformanceMonitoring = CAP_PERFMON, + /// This capability allows the following BPF operations: + /// - Creating all types of BPF maps + /// - Advanced verifier features + /// - Indirect variable access + /// - Bounded loops + /// - BPF to BPF function calls + /// - Scalar precision tracking + /// - Larger complexity limits + /// - Dead code elimination + /// - And potentially other features + /// - Loading BPF Type Format (BTF) data + /// - Retrieve `xlated` and JITed code of BPF programs + /// - Use `bpf_spin_lock` helper + /// + /// [`Capability::PerformanceMonitoring`] relaxes the verifier checks further: + /// - BPF progs can use of pointer-to-integer conversions + /// - speculation attack hardening measures are bypassed + /// - `bpf_probe_read` to read arbitrary kernel memory is allowed + /// - `bpf_trace_printk` to print kernel memory is allowed + /// + /// [`Capability::SystemAdmin`] is required to use bpf_probe_write_user. + /// + /// [`Capability::SystemAdmin`] is required to iterate system wide loaded + /// programs, maps, links, BTFs and convert their IDs to file descriptors. + /// + /// [`Capability::PerformanceMonitoring`] and [`Capability::BerkeleyPacketFilters`] are required + /// to load tracing programs. + /// [`Capability::NetAdmin`] and [`Capability::BerkeleyPacketFilters`] are required to load + /// networking programs. + BerkeleyPacketFilters = CAP_BPF, + /// Allow checkpoint/restore related operations. Allow PID selection during `clone3`. + /// Allow writing to `ns_last_pid`. + CheckpointRestore = CAP_CHECKPOINT_RESTORE, +} + +/// Check if the specified capability is in the calling thread's capability bounding set. +/// +/// # References +/// - [`prctl(PR_CAPBSET_READ,...)`] +/// +/// [`prctl(PR_CAPBSET_READ,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn is_in_capability_bounding_set(capability: Capability) -> io::Result<bool> { + unsafe { prctl_2args(PR_CAPBSET_READ, capability as usize as *mut _) }.map(|r| r != 0) +} + +const PR_CAPBSET_DROP: c_int = 24; + +/// If the calling thread has the [`Capability::SetPermittedCapabilities`] capability within its +/// user namespace, then drop the specified capability from the thread's capability bounding set. +/// +/// # References +/// - [`prctl(PR_CAPBSET_DROP,...)`] +/// +/// [`prctl(PR_CAPBSET_DROP,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn remove_capability_from_capability_bounding_set(capability: Capability) -> io::Result<()> { + unsafe { prctl_2args(PR_CAPBSET_DROP, capability as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_SECUREBITS/PR_SET_SECUREBITS +// + +const PR_GET_SECUREBITS: c_int = 27; + +bitflags! { + /// `SECBIT_*`. + pub struct CapabilitiesSecureBits: u32 { + /// If this bit is set, then the kernel does not grant capabilities when + /// a `set-user-ID-root` program is executed, or when a process with an effective or real + /// UID of 0 calls `execve`. + const NO_ROOT = 1_u32 << 0; + /// Set [`NO_ROOT`] irreversibly. + const NO_ROOT_LOCKED = 1_u32 << 1; + /// Setting this flag stops the kernel from adjusting the process's permitted, effective, + /// and ambient capability sets when the thread's effective and filesystem UIDs are switched + /// between zero and nonzero values. + const NO_SETUID_FIXUP = 1_u32 << 2; + /// Set [`NO_SETUID_FIXUP`] irreversibly. + const NO_SETUID_FIXUP_LOCKED = 1_u32 << 3; + /// Setting this flag allows a thread that has one or more 0 UIDs to retain capabilities in + /// its permitted set when it switches all of its UIDs to nonzero values. + const KEEP_CAPS = 1_u32 << 4; + /// Set [`KEEP_CAPS`] irreversibly. + const KEEP_CAPS_LOCKED = 1_u32 << 5; + /// Setting this flag disallows raising ambient capabilities via the `prctl`'s + /// `PR_CAP_AMBIENT_RAISE` operation. + const NO_CAP_AMBIENT_RAISE = 1_u32 << 6; + /// Set [`NO_CAP_AMBIENT_RAISE`] irreversibly. + const NO_CAP_AMBIENT_RAISE_LOCKED = 1_u32 << 7; + } +} + +/// Get the `securebits` flags of the calling thread. +/// +/// # References +/// - [`prctl(PR_GET_SECUREBITS,...)`] +/// +/// [`prctl(PR_GET_SECUREBITS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn capabilities_secure_bits() -> io::Result<CapabilitiesSecureBits> { + let r = unsafe { prctl_1arg(PR_GET_SECUREBITS)? } as c_uint; + CapabilitiesSecureBits::from_bits(r).ok_or(io::Errno::RANGE) +} + +const PR_SET_SECUREBITS: c_int = 28; + +/// Set the `securebits` flags of the calling thread. +/// +/// # References +/// - [`prctl(PR_SET_SECUREBITS,...)`] +/// +/// [`prctl(PR_SET_SECUREBITS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_capabilities_secure_bits(bits: CapabilitiesSecureBits) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_SECUREBITS, bits.bits() as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_TIMERSLACK/PR_SET_TIMERSLACK +// + +const PR_GET_TIMERSLACK: c_int = 30; + +/// Get the `current` timer slack value of the calling thread. +/// +/// # References +/// - [`prctl(PR_GET_TIMERSLACK,...)`] +/// +/// [`prctl(PR_GET_TIMERSLACK,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn current_timer_slack() -> io::Result<u64> { + unsafe { prctl_1arg(PR_GET_TIMERSLACK) }.map(|r| r as u64) +} + +const PR_SET_TIMERSLACK: c_int = 29; + +/// Sets the `current` timer slack value for the calling thread. +/// +/// # References +/// - [`prctl(PR_SET_TIMERSLACK,...)`] +/// +/// [`prctl(PR_SET_TIMERSLACK,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_current_timer_slack(value: Option<NonZeroU64>) -> io::Result<()> { + let value = usize::try_from(value.map_or(0, NonZeroU64::get)).map_err(|_r| io::Errno::RANGE)?; + unsafe { prctl_2args(PR_SET_TIMERSLACK, value as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_NO_NEW_PRIVS/PR_SET_NO_NEW_PRIVS +// + +const PR_GET_NO_NEW_PRIVS: c_int = 39; + +/// Get the value of the `no_new_privs` attribute for the calling thread. +/// +/// # References +/// - [`prctl(PR_GET_NO_NEW_PRIVS,...)`] +/// +/// [`prctl(PR_GET_NO_NEW_PRIVS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn no_new_privs() -> io::Result<bool> { + unsafe { prctl_1arg(PR_GET_NO_NEW_PRIVS) }.map(|r| r != 0) +} + +const PR_SET_NO_NEW_PRIVS: c_int = 38; + +/// Set the calling thread's `no_new_privs` attribute. +/// +/// # References +/// - [`prctl(PR_SET_NO_NEW_PRIVS,...)`] +/// +/// [`prctl(PR_SET_NO_NEW_PRIVS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn set_no_new_privs(no_new_privs: bool) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_NO_NEW_PRIVS, no_new_privs as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_GET_TID_ADDRESS +// + +const PR_GET_TID_ADDRESS: c_int = 40; + +/// Get the `clear_child_tid` address set by `set_tid_address` +/// and `clone`'s `CLONE_CHILD_CLEARTID` flag. +/// +/// # References +/// - [`prctl(PR_GET_TID_ADDRESS,...)`] +/// +/// [`prctl(PR_GET_TID_ADDRESS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn get_clear_child_tid_address() -> io::Result<Option<NonNull<c_void>>> { + unsafe { prctl_get_at_arg2_optional::<*mut c_void>(PR_GET_TID_ADDRESS) }.map(NonNull::new) +} + +// +// PR_GET_THP_DISABLE/PR_SET_THP_DISABLE +// + +const PR_GET_THP_DISABLE: c_int = 42; + +/// Get the current setting of the `THP disable` flag for the calling thread. +/// +/// # References +/// - [`prctl(PR_GET_THP_DISABLE,...)`] +/// +/// [`prctl(PR_GET_THP_DISABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn transparent_huge_pages_are_disabled() -> io::Result<bool> { + unsafe { prctl_1arg(PR_GET_THP_DISABLE) }.map(|r| r != 0) +} + +const PR_SET_THP_DISABLE: c_int = 41; + +/// Set the state of the `THP disable` flag for the calling thread. +/// +/// # References +/// - [`prctl(PR_SET_THP_DISABLE,...)`] +/// +/// [`prctl(PR_SET_THP_DISABLE,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn disable_transparent_huge_pages(thp_disable: bool) -> io::Result<()> { + unsafe { prctl_2args(PR_SET_THP_DISABLE, thp_disable as usize as *mut _) }.map(|_r| ()) +} + +// +// PR_CAP_AMBIENT +// + +const PR_CAP_AMBIENT: c_int = 47; + +const PR_CAP_AMBIENT_IS_SET: usize = 1; + +/// Check if the specified capability is in the ambient set. +/// +/// # References +/// - [`prctl(PR_CAP_AMBIENT,PR_CAP_AMBIENT_IS_SET,...)`] +/// +/// [`prctl(PR_CAP_AMBIENT,PR_CAP_AMBIENT_IS_SET,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn capability_is_in_ambient_capability_set(capability: Capability) -> io::Result<bool> { + let cap = capability as usize as *mut _; + unsafe { prctl_3args(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET as *mut _, cap) }.map(|r| r != 0) +} + +const PR_CAP_AMBIENT_CLEAR_ALL: usize = 4; + +/// Remove all capabilities from the ambient set. +/// +/// # References +/// - [`prctl(PR_CAP_AMBIENT,PR_CAP_AMBIENT_CLEAR_ALL,...)`] +/// +/// [`prctl(PR_CAP_AMBIENT,PR_CAP_AMBIENT_CLEAR_ALL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn clear_ambient_capability_set() -> io::Result<()> { + unsafe { prctl_2args(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL as *mut _) }.map(|_r| ()) +} + +const PR_CAP_AMBIENT_RAISE: usize = 2; +const PR_CAP_AMBIENT_LOWER: usize = 3; + +/// Add or remove the specified capability to the ambient set. +/// +/// # References +/// - [`prctl(PR_CAP_AMBIENT,...)`] +/// +/// [`prctl(PR_CAP_AMBIENT,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn configure_capability_in_ambient_capability_set( + capability: Capability, + enable: bool, +) -> io::Result<()> { + let sub_operation = if enable { + PR_CAP_AMBIENT_RAISE + } else { + PR_CAP_AMBIENT_LOWER + }; + let cap = capability as usize as *mut _; + + unsafe { prctl_3args(PR_CAP_AMBIENT, sub_operation as *mut _, cap) }.map(|_r| ()) +} + +// +// PR_SVE_GET_VL/PR_SVE_SET_VL +// + +const PR_SVE_GET_VL: c_int = 51; + +const PR_SVE_VL_LEN_MASK: u32 = 0xffff; +const PR_SVE_VL_INHERIT: u32 = 1_u32 << 17; + +/// Scalable Vector Extension vector length configuration. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct SVEVectorLengthConfig { + /// Vector length in bytes. + pub vector_length_in_bytes: u32, + /// Vector length inherited across `execve`. + pub vector_length_inherited_across_execve: bool, +} + +/// Get the thread's current SVE vector length configuration. +/// +/// # References +/// - [`prctl(PR_SVE_GET_VL,...)`] +/// +/// [`prctl(PR_SVE_GET_VL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn sve_vector_length_configuration() -> io::Result<SVEVectorLengthConfig> { + let bits = unsafe { prctl_1arg(PR_SVE_GET_VL)? } as c_uint; + Ok(SVEVectorLengthConfig { + vector_length_in_bytes: bits & PR_SVE_VL_LEN_MASK, + vector_length_inherited_across_execve: (bits & PR_SVE_VL_INHERIT) != 0, + }) +} + +const PR_SVE_SET_VL: c_int = 50; + +const PR_SVE_SET_VL_ONEXEC: u32 = 1_u32 << 18; + +/// Configure the thread's vector length of Scalable Vector Extension. +/// +/// # References +/// - [`prctl(PR_SVE_SET_VL,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SVE_SET_VL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn set_sve_vector_length_configuration( + vector_length_in_bytes: usize, + vector_length_inherited_across_execve: bool, + defer_change_to_next_execve: bool, +) -> io::Result<()> { + let vector_length_in_bytes = + u32::try_from(vector_length_in_bytes).map_err(|_r| io::Errno::RANGE)?; + + let mut bits = vector_length_in_bytes & PR_SVE_VL_LEN_MASK; + + if vector_length_inherited_across_execve { + bits |= PR_SVE_VL_INHERIT; + } + + if defer_change_to_next_execve { + bits |= PR_SVE_SET_VL_ONEXEC; + } + + prctl_2args(PR_SVE_SET_VL, bits as usize as *mut _).map(|_r| ()) +} + +// +// PR_PAC_RESET_KEYS +// + +const PR_PAC_RESET_KEYS: c_int = 54; + +/// Securely reset the thread's pointer authentication keys to fresh random values generated +/// by the kernel. +/// +/// # References +/// - [`prctl(PR_PAC_RESET_KEYS,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_PAC_RESET_KEYS,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn reset_pointer_authentication_keys( + keys: Option<PointerAuthenticationKeys>, +) -> io::Result<()> { + let keys = keys.as_ref().map_or(0_u32, PointerAuthenticationKeys::bits); + prctl_2args(PR_PAC_RESET_KEYS, keys as usize as *mut _).map(|_r| ()) +} + +// +// PR_GET_TAGGED_ADDR_CTRL/PR_SET_TAGGED_ADDR_CTRL +// + +const PR_GET_TAGGED_ADDR_CTRL: c_int = 56; + +const PR_MTE_TAG_SHIFT: u32 = 3; +const PR_MTE_TAG_MASK: u32 = 0xffff_u32 << PR_MTE_TAG_SHIFT; + +bitflags! { + /// Zero means addresses that are passed for the purpose of being dereferenced by the kernel must be untagged. + pub struct TaggedAddressMode: u32 { + /// Addresses that are passed for the purpose of being dereferenced by the kernel may be tagged. + const ENABLED = 1_u32 << 0; + /// Synchronous tag check fault mode. + const TCF_SYNC = 1_u32 << 1; + /// Asynchronous tag check fault mode. + const TCF_ASYNC = 1_u32 << 2; + } +} + +/// Get the current tagged address mode for the calling thread. +/// +/// # References +/// - [`prctl(PR_GET_TAGGED_ADDR_CTRL,...)`] +/// +/// [`prctl(PR_GET_TAGGED_ADDR_CTRL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub fn current_tagged_address_mode() -> io::Result<(Option<TaggedAddressMode>, u32)> { + let r = unsafe { prctl_1arg(PR_GET_TAGGED_ADDR_CTRL)? } as c_uint; + let mode = r & 0b111_u32; + let mte_tag = (r & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT; + Ok((TaggedAddressMode::from_bits(mode), mte_tag)) +} + +const PR_SET_TAGGED_ADDR_CTRL: c_int = 55; + +/// Controls support for passing tagged user-space addresses to the kernel. +/// +/// # References +/// - [`prctl(PR_SET_TAGGED_ADDR_CTRL,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_TAGGED_ADDR_CTRL,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn set_current_tagged_address_mode( + mode: Option<TaggedAddressMode>, + mte_tag: u32, +) -> io::Result<()> { + let config = mode.as_ref().map_or(0_u32, TaggedAddressMode::bits) + | ((mte_tag << PR_MTE_TAG_SHIFT) & PR_MTE_TAG_MASK); + prctl_2args(PR_SET_TAGGED_ADDR_CTRL, config as usize as *mut _).map(|_r| ()) +} + +// +// PR_SET_SYSCALL_USER_DISPATCH +// + +const PR_SET_SYSCALL_USER_DISPATCH: c_int = 59; + +const PR_SYS_DISPATCH_OFF: usize = 0; + +/// Disable Syscall User Dispatch mechanism. +/// +/// # References +/// - [`prctl(PR_SET_SYSCALL_USER_DISPATCH,PR_SYS_DISPATCH_OFF,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_SYSCALL_USER_DISPATCH,PR_SYS_DISPATCH_OFF,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn disable_syscall_user_dispatch() -> io::Result<()> { + prctl_2args(PR_SET_SYSCALL_USER_DISPATCH, PR_SYS_DISPATCH_OFF as *mut _).map(|_r| ()) +} + +const PR_SYS_DISPATCH_ON: usize = 1; + +/// Allow system calls to be executed. +const SYSCALL_DISPATCH_FILTER_ALLOW: u8 = 0; +/// Block system calls from executing. +const SYSCALL_DISPATCH_FILTER_BLOCK: u8 = 1; + +/// Value of the fast switch flag controlling system calls user dispatch mechanism without the need +/// to issue a syscall. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u8)] +pub enum SysCallUserDispatchFastSwitch { + /// System calls are allowed to execute. + Allow = SYSCALL_DISPATCH_FILTER_ALLOW, + /// System calls are blocked from executing. + Block = SYSCALL_DISPATCH_FILTER_BLOCK, +} + +impl TryFrom<u8> for SysCallUserDispatchFastSwitch { + type Error = io::Errno; + + fn try_from(value: u8) -> Result<Self, Self::Error> { + match value { + SYSCALL_DISPATCH_FILTER_ALLOW => Ok(Self::Allow), + SYSCALL_DISPATCH_FILTER_BLOCK => Ok(Self::Block), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Enable Syscall User Dispatch mechanism. +/// +/// # References +/// - [`prctl(PR_SET_SYSCALL_USER_DISPATCH,PR_SYS_DISPATCH_ON,...)`] +/// +/// # Safety +/// +/// Please ensure the conditions necessary to safely call this function, +/// as detailed in the references above. +/// +/// [`prctl(PR_SET_SYSCALL_USER_DISPATCH,PR_SYS_DISPATCH_ON,...)`]: https://man7.org/linux/man-pages/man2/prctl.2.html +#[inline] +pub unsafe fn enable_syscall_user_dispatch( + always_allowed_region: &[u8], + fast_switch_flag: &AtomicU8, +) -> io::Result<()> { + syscalls::prctl( + PR_SET_SYSCALL_USER_DISPATCH, + PR_SYS_DISPATCH_ON as *mut _, + always_allowed_region.as_ptr() as *mut _, + always_allowed_region.len() as *mut _, + fast_switch_flag as *const AtomicU8 as *mut _, + ) + .map(|_r| ()) +} + +// +// PR_SCHED_CORE +// + +const PR_SCHED_CORE: c_int = 62; + +const PR_SCHED_CORE_GET: usize = 0; + +const PR_SCHED_CORE_SCOPE_THREAD: u32 = 0; +const PR_SCHED_CORE_SCOPE_THREAD_GROUP: u32 = 1; +const PR_SCHED_CORE_SCOPE_PROCESS_GROUP: u32 = 2; + +/// `PR_SCHED_CORE_SCOPE_*`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum CoreSchedulingScope { + /// Operation will be performed for the thread. + Thread = PR_SCHED_CORE_SCOPE_THREAD, + /// Operation will be performed for all tasks in the task group of the process. + ThreadGroup = PR_SCHED_CORE_SCOPE_THREAD_GROUP, + /// Operation will be performed for all processes in the process group. + ProcessGroup = PR_SCHED_CORE_SCOPE_PROCESS_GROUP, +} + +impl TryFrom<u32> for CoreSchedulingScope { + type Error = io::Errno; + + fn try_from(value: u32) -> Result<Self, Self::Error> { + match value { + PR_SCHED_CORE_SCOPE_THREAD => Ok(Self::Thread), + PR_SCHED_CORE_SCOPE_THREAD_GROUP => Ok(Self::ThreadGroup), + PR_SCHED_CORE_SCOPE_PROCESS_GROUP => Ok(Self::ProcessGroup), + _ => Err(io::Errno::RANGE), + } + } +} + +/// Get core scheduling cookie of a process. +/// +/// # References +/// - [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_GET,...)`] +/// +/// [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_GET,...)`]: https://www.kernel.org/doc/html/v5.18/admin-guide/hw-vuln/core-scheduling.html +#[inline] +pub fn core_scheduling_cookie(pid: Pid, scope: CoreSchedulingScope) -> io::Result<u64> { + let mut value: MaybeUninit<u64> = MaybeUninit::uninit(); + unsafe { + syscalls::prctl( + PR_SCHED_CORE, + PR_SCHED_CORE_GET as *mut _, + pid.as_raw_nonzero().get() as usize as *mut _, + scope as usize as *mut _, + value.as_mut_ptr().cast(), + )?; + Ok(value.assume_init()) + } +} + +const PR_SCHED_CORE_CREATE: usize = 1; + +/// Create unique core scheduling cookie. +/// +/// # References +/// - [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_CREATE,...)`] +/// +/// [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_CREATE,...)`]: https://www.kernel.org/doc/html/v5.18/admin-guide/hw-vuln/core-scheduling.html +#[inline] +pub fn create_core_scheduling_cookie(pid: Pid, scope: CoreSchedulingScope) -> io::Result<()> { + unsafe { + syscalls::prctl( + PR_SCHED_CORE, + PR_SCHED_CORE_CREATE as *mut _, + pid.as_raw_nonzero().get() as usize as *mut _, + scope as usize as *mut _, + ptr::null_mut(), + ) + .map(|_r| ()) + } +} + +const PR_SCHED_CORE_SHARE_TO: usize = 2; + +/// Push core scheduling cookie to a process. +/// +/// # References +/// - [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_SHARE_TO,...)`] +/// +/// [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_SHARE_TO,...)`]: https://www.kernel.org/doc/html/v5.18/admin-guide/hw-vuln/core-scheduling.html +#[inline] +pub fn push_core_scheduling_cookie(pid: Pid, scope: CoreSchedulingScope) -> io::Result<()> { + unsafe { + syscalls::prctl( + PR_SCHED_CORE, + PR_SCHED_CORE_SHARE_TO as *mut _, + pid.as_raw_nonzero().get() as usize as *mut _, + scope as usize as *mut _, + ptr::null_mut(), + ) + .map(|_r| ()) + } +} + +const PR_SCHED_CORE_SHARE_FROM: usize = 3; + +/// Pull core scheduling cookie from a process. +/// +/// # References +/// - [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_SHARE_FROM,...)`] +/// +/// [`prctl(PR_SCHED_CORE,PR_SCHED_CORE_SHARE_FROM,...)`]: https://www.kernel.org/doc/html/v5.18/admin-guide/hw-vuln/core-scheduling.html +#[inline] +pub fn pull_core_scheduling_cookie(pid: Pid, scope: CoreSchedulingScope) -> io::Result<()> { + unsafe { + syscalls::prctl( + PR_SCHED_CORE, + PR_SCHED_CORE_SHARE_FROM as *mut _, + pid.as_raw_nonzero().get() as usize as *mut _, + scope as usize as *mut _, + ptr::null_mut(), + ) + .map(|_r| ()) + } +} diff --git a/vendor/rustix/src/thread/setns.rs b/vendor/rustix/src/thread/setns.rs new file mode 100644 index 000000000..0a5564ae1 --- /dev/null +++ b/vendor/rustix/src/thread/setns.rs @@ -0,0 +1,89 @@ +#![allow(unsafe_code)] + +use bitflags::bitflags; +use linux_raw_sys::general::{ + CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWTIME, + CLONE_NEWUSER, CLONE_NEWUTS, +}; + +use crate::backend::c::c_int; +use crate::backend::thread::syscalls; +use crate::fd::BorrowedFd; +use crate::io; + +bitflags! { + /// Thread name space type. + pub struct ThreadNameSpaceType: u32 { + /// Time name space. + const TIME = CLONE_NEWTIME; + /// Mount name space. + const MOUNT = CLONE_NEWNS; + /// Control group (CGroup) name space. + const CONTROL_GROUP = CLONE_NEWCGROUP; + /// `Host name` and `NIS domain name` (UTS) name space. + const HOST_NAME_AND_NIS_DOMAIN_NAME = CLONE_NEWUTS; + /// Inter-process communication (IPC) name space. + const INTER_PROCESS_COMMUNICATION = CLONE_NEWIPC; + /// User name space. + const USER = CLONE_NEWUSER; + /// Process ID name space. + const PROCESS_ID = CLONE_NEWPID; + /// Network name space. + const NETWORK = CLONE_NEWNET; + } +} + +/// Type of name space referred to by a link. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[repr(u32)] +pub enum LinkNameSpaceType { + /// Time name space. + Time = CLONE_NEWTIME, + /// Mount name space. + Mount = CLONE_NEWNS, + /// Control group (CGroup) name space. + ControlGroup = CLONE_NEWCGROUP, + /// `Host name` and `NIS domain name` (UTS) name space. + HostNameAndNISDomainName = CLONE_NEWUTS, + /// Inter-process communication (IPC) name space. + InterProcessCommunication = CLONE_NEWIPC, + /// User name space. + User = CLONE_NEWUSER, + /// Process ID name space. + ProcessID = CLONE_NEWPID, + /// Network name space. + Network = CLONE_NEWNET, +} + +/// Reassociate the calling thread with the namespace associated with link referred to by `fd`. +/// +/// `fd` must refer to one of the magic links in a `/proc/[pid]/ns/` directory, or a bind mount +/// to such a link. +/// +/// # References +/// - [`setns`] +/// +/// [`setns`]: https://man7.org/linux/man-pages/man2/setns.2.html +pub fn move_into_link_name_space( + fd: BorrowedFd, + allowed_type: Option<LinkNameSpaceType>, +) -> io::Result<()> { + let allowed_type = allowed_type.map_or(0, |t| t as c_int); + syscalls::setns(fd, allowed_type).map(|_r| ()) +} + +/// Atomically move the calling thread into one or more of the same namespaces as the thread +/// referred to by `fd`. +/// +/// `fd` must refer to a thread ID. See: `pidfd_open` and `clone`. +/// +/// # References +/// - [`setns`] +/// +/// [`setns`]: https://man7.org/linux/man-pages/man2/setns.2.html +pub fn move_into_thread_name_spaces( + fd: BorrowedFd, + allowed_types: ThreadNameSpaceType, +) -> io::Result<()> { + syscalls::setns(fd, allowed_types.bits() as c_int).map(|_r| ()) +} diff --git a/vendor/rustix/src/time/clock.rs b/vendor/rustix/src/time/clock.rs index 32d888749..2e23f91b8 100644 --- a/vendor/rustix/src/time/clock.rs +++ b/vendor/rustix/src/time/clock.rs @@ -1,10 +1,10 @@ -use crate::{imp, io}; +use crate::{backend, io}; -pub use imp::time::types::{Nsecs, Secs, Timespec}; +pub use backend::time::types::{Nsecs, Secs, Timespec}; /// `clockid_t` #[cfg(any(not(target_os = "wasi")))] -pub use imp::time::types::{ClockId, DynamicClockId}; +pub use backend::time::types::{ClockId, DynamicClockId}; /// `clock_getres(id)`—Returns the resolution of a clock. /// @@ -18,7 +18,7 @@ pub use imp::time::types::{ClockId, DynamicClockId}; #[inline] #[must_use] pub fn clock_getres(id: ClockId) -> Timespec { - imp::time::syscalls::clock_getres(id) + backend::time::syscalls::clock_getres(id) } /// `clock_gettime(id)`—Returns the current value of a clock. @@ -38,7 +38,7 @@ pub fn clock_getres(id: ClockId) -> Timespec { #[inline] #[must_use] pub fn clock_gettime(id: ClockId) -> Timespec { - imp::time::syscalls::clock_gettime(id) + backend::time::syscalls::clock_gettime(id) } /// Like [`clock_gettime`] but with support for dynamic clocks. @@ -52,5 +52,5 @@ pub fn clock_gettime(id: ClockId) -> Timespec { #[cfg(not(target_os = "wasi"))] #[inline] pub fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timespec> { - imp::time::syscalls::clock_gettime_dynamic(id) + backend::time::syscalls::clock_gettime_dynamic(id) } diff --git a/vendor/rustix/src/time/timerfd.rs b/vendor/rustix/src/time/timerfd.rs index 5abe6ff52..7f661f7d9 100644 --- a/vendor/rustix/src/time/timerfd.rs +++ b/vendor/rustix/src/time/timerfd.rs @@ -1,8 +1,7 @@ -use crate::fd::AsFd; -use crate::imp; -use crate::io::{self, OwnedFd}; +use crate::fd::{AsFd, OwnedFd}; +use crate::{backend, io}; -pub use imp::time::types::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}; +pub use backend::time::types::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}; /// `timerfd_create(clockid, flags)`—Create a timer. /// @@ -12,7 +11,7 @@ pub use imp::time::types::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTime /// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_create.2.html #[inline] pub fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> { - imp::time::syscalls::timerfd_create(clockid, flags) + backend::time::syscalls::timerfd_create(clockid, flags) } /// `timerfd_settime(clockid, flags, new_value)`—Set the time on a timer. @@ -27,7 +26,7 @@ pub fn timerfd_settime<Fd: AsFd>( flags: TimerfdTimerFlags, new_value: &Itimerspec, ) -> io::Result<Itimerspec> { - imp::time::syscalls::timerfd_settime(fd.as_fd(), flags, new_value) + backend::time::syscalls::timerfd_settime(fd.as_fd(), flags, new_value) } /// `timerfd_gettime(clockid, flags)`—Query a timer. @@ -38,5 +37,5 @@ pub fn timerfd_settime<Fd: AsFd>( /// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_gettime.2.html #[inline] pub fn timerfd_gettime<Fd: AsFd>(fd: Fd) -> io::Result<Itimerspec> { - imp::time::syscalls::timerfd_gettime(fd.as_fd()) + backend::time::syscalls::timerfd_gettime(fd.as_fd()) } diff --git a/vendor/rustix/src/utils.rs b/vendor/rustix/src/utils.rs index efbbe81aa..dcbadb260 100644 --- a/vendor/rustix/src/utils.rs +++ b/vendor/rustix/src/utils.rs @@ -11,3 +11,19 @@ pub(crate) const fn as_ptr<T>(t: &T) -> *const T { pub(crate) fn as_mut_ptr<T>(t: &mut T) -> *mut T { t } + +/// Convert a `*mut c_void` to a `*mut T`, checking that it is not null, +/// misaligned, or pointing to a region of memory that wraps around the address +/// space. +#[allow(dead_code)] +pub(crate) fn check_raw_pointer<T>(value: *mut core::ffi::c_void) -> Option<core::ptr::NonNull<T>> { + if (value as usize) + .checked_add(core::mem::size_of::<T>()) + .is_none() + || (value as usize) % core::mem::align_of::<T>() != 0 + { + return None; + } + + core::ptr::NonNull::new(value.cast()) +} |