summary refs log tree commit diff
path: root/library/std/src/os
AgeCommit message (Collapse)AuthorLines
2024-04-09Document Windows argument splittingChris Denton-2/+54
2024-03-14Rollup merge of #121650 - GrigorenkoPV:cap_setgid, r=AmanieuMatthias Krüger-0/+7
change std::process to drop supplementary groups based on CAP_SETGID A trivial rebase of #95982 Should fix #39186 (from what I can tell) Original description: > Fixes #88716 > > * Before this change, when a process was given a uid via `std::os::unix::process::CommandExt.uid`, there would be a `setgroups` call (when the process runs) to clear supplementary groups for the child **if the parent was root** (to remove potentially unwanted permissions). > * After this change, supplementary groups are cleared if we have permission to do so, that is, if we have the CAP_SETGID capability. > > This new behavior was agreed upon in #88716 but there was a bit of uncertainty from `@Amanieu` here: [#88716 (comment)](https://github.com/rust-lang/rust/issues/88716#issuecomment-973366600) > > > I agree with this change, but is it really necessary to ignore an EPERM from setgroups? If you have permissions to change UID then you should also have permissions to change groups. I would feel more comfortable if we documented set_uid as requiring both UID and GID changing permissions. > > The way I've currently written it, we ignore an EPERM as that's what #88716 originally suggested. I'm not at all an expert in any of this so I'd appreciate feedback on whether that was the right way to go.
2024-03-14Rollup merge of #119029 - dylni:avoid-closing-invalid-handles, r=ChrisDentonMatthias Krüger-21/+47
Avoid closing invalid handles Documentation for [`HandleOrInvalid`] has this note: > If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. Documentation for [`HandleOrNull`] has this note: > If this holds a non-null handle, it will close the handle on drop. Currently, both will call `CloseHandle` on their invalid handles as a result of using `OwnedHandle` internally, contradicting the above paragraphs. This PR adds destructors that match the documentation. ```@rustbot``` label A-io O-windows T-libs [`HandleOrInvalid`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrInvalid.html [`HandleOrNull`]: https://doc.rust-lang.org/std/os/windows/io/struct.HandleOrNull.html
2024-03-11Auto merge of #117156 - jmillikin:os-unix-socket-ext, r=Amanieu,dtolnaybors-128/+230
Convert `Unix{Datagram,Stream}::{set_}passcred()` to per-OS traits These methods are the pre-stabilized API for obtaining peer credentials from an `AF_UNIX` socket, part of the `unix_socket_ancillary_data` feature. Their current behavior is to get/set one of the `SO_PASSCRED` (Linux), `LOCAL_CREDS_PERSISTENT` (FreeBSD), or `LOCAL_CREDS` (NetBSD) socket options. On other targets the `{set_}passcred()` methods do not exist. There are two problems with this approach: 1. Having public methods only exist for certain targets isn't permitted in a stable `std` API. 2. These options have generally similar purposes, but they are non-POSIX and their details can differ in subtle and surprising ways (such as whether they continue to be set after the next call to `recvmsg()`). Splitting into OS-specific extension traits is the preferred solution to both problems.
2024-03-09Rollup merge of #121711 - ChrisDenton:junction, r=Mark-SimulacrumGuillaume Boisseau-0/+12
Implement junction_point Implements https://github.com/rust-lang/rust/issues/121709 We already had a private implementation that we use for tests so we could just make that public. Except it was very hacky as it was only ever intended for use in testing. I've made an improved version that at least handles path conversion correctly and has less need for things like the `Align8` hack. There's still room for further improvement though.
2024-03-09Rollup merge of #114655 - nbdd0121:io-safety, r=dtolnayGuillaume Boisseau-10/+10
Make `impl<Fd: AsFd>` impl take `?Sized` `@rustbot` labels: +T-libs-api +needs-fcp
2024-03-09Avoid closing invalid handlesdylni-21/+47
2024-03-07make `std::os::unix::ucred` module privateKalle Wachsmuth-48/+44
2024-02-27Implement junction_pointChris Denton-0/+12
2024-02-27Auto merge of #119616 - rylev:wasm32-wasi-preview2, r=petrochenkov,m-ou-sebors-1/+10
Add a new `wasm32-wasi-preview2` target This is the initial implementation of the MCP https://github.com/rust-lang/compiler-team/issues/694 creating a new tier 3 target `wasm32-wasi-preview2`. That MCP has been seconded and will most likely be approved in a little over a week from now. For more information on the need for this target, please read the [MCP](https://github.com/rust-lang/compiler-team/issues/694). There is one aspect of this PR that will become insta-stable once these changes reach a stable compiler: * A new `target_family` named `wasi` is introduced. This target family incorporates all wasi targets including `wasm32-wasi` and its derivative `wasm32-wasi-preview1-threads`. The difference between `target_family = wasi` and `target_os = wasi` will become much clearer when `wasm32-wasi` is renamed to `wasm32-wasi-preview1` and the `target_os` becomes `wasm32-wasi-preview1`. You can read about this target rename in [this MCP](https://github.com/rust-lang/compiler-team/issues/695) which has also been seconded and will hopefully be officially approved soon. Additional technical details include: * Both `std::sys::wasi_preview2` and `std::os::wasi_preview2` have been created and mostly use `#[path]` annotations on their submodules to reach into the existing `wasi` (soon to be `wasi_preview1`) modules. Over time the differences between `wasi_preview1` and `wasi_preview2` will grow and most like all `#[path]` based module aliases will fall away. * Building `wasi-preview2` relies on a [`wasi-sdk`](https://github.com/WebAssembly/wasi-sdk) in the same way that `wasi-preview1` does (one must include a `wasi-root` path in the `Config.toml` pointing to sysroot included in the wasi-sdk). The target should build against [wasi-sdk v21](https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-21) without modifications. However, the wasi-sdk itself is growing [preview2 support](https://github.com/WebAssembly/wasi-sdk/pull/370) so this might shift rapidly. We will be following along quickly to make sure that building the target remains possible as the wasi-sdk changes. * This requires a [patch to libc](https://github.com/rylev/rust-libc/tree/wasm32-wasi-preview2) that we'll need to land in conjunction with this change. Until that patch lands the target won't actually build.
2024-02-27Auto merge of #119636 - devnexen:linux_tcp_defer_accept, r=m-ou-sebors-0/+81
os::net: expanding TcpStreamExt for Linux with `tcp_deferaccept`. allows for socket to process only when there is data to process, the option sets a number of seconds until the data is ready.
2024-02-27Rename wasm32-wasi-preview2 to wasm32-wasip2Ryan Levick-4/+4
Signed-off-by: Ryan Levick <me@ryanlevick.com>
2024-02-27Add the wasm32-wasi-preview2 targetRyan Levick-1/+10
Signed-off-by: Ryan Levick <me@ryanlevick.com>
2024-02-26change std::process to drop supplementary groups based on CAP_SETGIDElliot Roberts-0/+7
2024-02-24library: use `addr_of!`Pavel Grigorenko-17/+21
2024-02-21os::net: expanding TcpStreamExt for Linux with `tcp_deferaccept`.David Carlier-0/+81
allows for socket to process only when there is data to process, the option sets a number of seconds until the data is ready.
2024-02-18Rollup merge of #121266 - SabrinaJewson:easy-syscall-aliases, r=Mark-SimulacrumMatthias Krüger-0/+14
Add uncontroversial syscall doc aliases to std docs This PR contains the parts of #113891 that don’t break the doc alias policy. r? `@Mark-Simulacrum`
2024-02-18Add uncontroversial syscall doc aliases to std docsSabrinaJewson-0/+14
2024-02-18By tracking import use types to check whether it is scope uses or the other ↵surechen-1/+0
situations like module-relative uses, we can do more accurate redundant import checking. fixes #117448 For example unnecessary imports in std::prelude that can be eliminated: ```rust use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly use std::option::Option::None; //~ WARNING the item `None` is imported redundantly ```
2024-02-11Rollup merge of #120459 - rytheo:handle-conversion-docs, r=Mark-SimulacrumMatthias Krüger-0/+25
Document various I/O descriptor/handle conversions Related to #51430
2024-02-04Document various I/O handle conversionsRyan Lowe-0/+25
2024-01-30Rollup merge of #120434 - fmease:revert-speeder, r=petrochenkovGuillaume Gomez-10/+1
Revert outdated version of "Add the wasm32-wasi-preview2 target" An outdated version of #119616 was merged in rollup #120309. This reverts those changes to enable #119616 to “retain the intended diff” after a rebase. ```@rylev``` has agreed that this would be the cleanest approach with respect to the history. Unblocks #119616. r? ```@petrochenkov``` or compiler or libs
2024-01-30Rollup merge of #120452 - alexcrichton:update-windows-seek-write-docs, ↵Guillaume Gomez-1/+1
r=ChrisDenton std: Update documentation of seek_write on Windows Currently the documentation of `FileExt::seek_write` on Windows indicates that writes beyond the end of the file leave intermediate bytes uninitialized. This commentary dates back to the original inclusion of these functions in #35704 (wow blast from the past!). At the time the functionality here was implemented using `WriteFile`, but nowadays the `NtWriteFile` method is used instead. The documentation for `NtWriteFile` explicitly states: > If Length and ByteOffset specify a write operation past the current > end-of-file mark, NtWriteFile automatically extends the file and updates > the end-of-file mark; any bytes that are not explicitly written between > such old and new end-of-file marks are defined to be zero. This commentary has had a downstream impact in the `system-interface` crate where it tries to handle this by explicitly writing zeros, but I don't believe that's necessary any more. I'm sending a PR upstream here to avoid future confusion and codify that zeros are written in the intermediate bytes matching what Windows currently provides.
2024-01-28Make `impl<T: AsHandle>` impl take `?Sized`Gary Guo-5/+5
2024-01-28Make `impl<Fd: AsFd>` impl take `?Sized`Gary Guo-5/+5
2024-01-28std: Update documentation of seek_write on WindowsAlex Crichton-1/+1
Currently the documentation of `FileExt::seek_write` on Windows indicates that writes beyond the end of the file leave intermediate bytes uninitialized. This commentary dates back to the original inclusion of these functions in #35704 (wow blast from the past!). At the time the functionality here was implemented using `WriteFile`, but nowadays the `NtWriteFile` method is used instead. The documentation for `NtWriteFile` explicitly states: > If Length and ByteOffset specify a write operation past the current > end-of-file mark, NtWriteFile automatically extends the file and updates > the end-of-file mark; any bytes that are not explicitly written between > such old and new end-of-file marks are defined to be zero. This commentary has had a downstream impact in the `system-interface` crate where it tries to handle this by explicitly writing zeros, but I don't believe that's necessary any more. I'm sending a PR upstream here to avoid future confusion and codify that zeros are written in the intermediate bytes matching what Windows currently provides.
2024-01-28Revert "Add the wasm32-wasi-preview2 target"León Orell Valerian Liehr-10/+1
This reverts commit 31ecf341250a889ac1154b2cbe3f0b97f9d008c1. Co-authored-by: Ryan Levick <me@ryanlevick.com>
2024-01-25Rollup merge of #120306 - safinaskar:clone3-clean-up, r=petrochenkovMatthias Krüger-2/+1
Clean up after clone3 removal from pidfd code (docs and tests) https://github.com/rust-lang/rust/pull/113939 removed clone3 from pidfd code. This patchset does necessary clean up: fixes docs and tests
2024-01-24Finishing clone3 clean upAskar Safin-2/+1
2024-01-23Add the wasm32-wasi-preview2 targetRyan Levick-1/+10
Signed-off-by: Ryan Levick <me@ryanlevick.com>
2024-01-22Rollup merge of #119943 - devnexen:listener_update3, r=thomccMatthias Krüger-1/+7
std::net: bind update for using backlog as `-1` too. Albeit not documented, macOs also support negative value for the backlog argument. ref: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/kern/uipc_socket.c#L1061
2024-01-22Rollup merge of #119408 - betrusted-io:xous-fixes-add-network, r=Mark-SimulacrumMatthias Krüger-10/+152
xous: misc fixes + add network support This patchset makes several fixes to Xous support. Additionally, this patch adds networking support. Many of these fixes are the result of the recent patch to get `unwinding` support merged. As a result of this patch, we can now run rust tests. As a result of these tests, we now have 729 tests passing: ``` failures: env::tests::test env::tests::test_self_exe_path env::tests::vars_debug env::tests::vars_os_debug os::raw::tests::same path::tests::test_push path::tests::test_set_file_name time::tests::since_epoch test result: FAILED. 729 passed; 8 failed; 1 ignored; 0 measured; 0 filtered out; finished in 214.54s ``` In the course of fixing several tests and getting the test sequence to reliably run, several issues were found. This patchset fixes those issues.
2024-01-15std::net: bind update for using backlog as `-1` too.David Carlier-1/+7
Albeit not documented, macOs also support negative value for the backlog argument. ref: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/kern/uipc_socket.c#L1061
2024-01-13std: xous: use constants for stdout and stderrSean Cross-0/+11
Use constants for the opcodes when writing to stdout or stderr. There still is no stdin operation. Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13xous: net: initial commit of network supportSean Cross-0/+129
This is an initial commit of network support for Xous. On hardware, is backed by smoltcp running via a Xous server in a separate process space. This patch adds TCP and UDP client and server support as well as DNS resolution support using the dns Xous server. Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13std: xous: pass entire memory range to flag updaterSean Cross-1/+1
When updating memory flags via `update_memory_flags()`, ensure we multiply the slice length by the element size to get the full memory size. Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13xous: ffi: correct size of freed memorySean Cross-1/+1
The amount of memory allocated was multiplied by sizeof::<T>(), so the amount of memory to be freed should also be multiplied by sizeof::<T>(). Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-13xous: ffi: fix lend_impl() return valuesSean Cross-8/+10
The `ret1` and `ret2` return values from lend operations are returned in $a1 and $a2. This function incorrectly pulled them from $a6 and $a7, causing them to always be `0`. Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-09Backlog for HorizonOS UnixListenerAndrea Ciliberti-2/+8
2024-01-05Fix broken build for ESP IDF due to #119026ivmarkov-2/+3
2024-01-04Rollup merge of #119026 - devnexen:listener_upd, r=Mark-SimulacrumMatthias Krüger-2/+12
std::net::bind using -1 for openbsd which in turn sets it to somaxconn. trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
2023-12-24Fix doc typo for read_exact_atAlexBuz-1/+1
2023-12-24std::net::bind using -1 for openbsd which in turn sets it to somaxconn.David Carlier-2/+12
trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
2023-11-23Fix tracking issue of Windows ExitCodeExtDavid Tolnay-3/+3
2023-11-23Auto merge of #115159 - solid-rs:patch/kmc-solid/io-safety, r=workingjubileebors-4/+298
kmc-solid: I/O safety Adds the I/O safety API (#87329) for socket file descriptors in [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. All new public items are gated by the `solid_ext` library feature. This PR adds the following public types and traits: std::os::solid::io::AsFd std::os::solid::io::BorrowedFd std::os::solid::io::OwnedFd std::os::solid::prelude::AsFd (re-export) std::os::solid::prelude::BorrowedFd (re-export) std::os::solid::prelude::OwnedFd (re-export) And trait implementations: From<std::net::TcpListener> for std::os::solid::io::OwnedFd From<std::net::TcpStream> for std::os::solid::io::OwnedFd From<std::net::UdpSocket> for std::os::solid::io::OwnedFd From<std::os::solid::io::OwnedFd> for std::net::TcpListener From<std::os::solid::io::OwnedFd> for std::net::TcpStream From<std::os::solid::io::OwnedFd> for std::net::UdpSocket std::fmt::Debug for std::os::solid::io::BorrowedFd<'_> std::fmt::Debug for std::os::solid::io::OwnedFd std::io::IsTerminal for std::os::solid::io::BorrowedFd<'_> std::io::IsTerminal for std::os::solid::io::OwnedFd std::os::fd::AsRawFd for std::os::solid::io::BorrowedFd<'_> std::os::fd::AsRawFd for std::os::solid::io::OwnedFd std::os::fd::FromRawFd for std::os::solid::io::OwnedFd std::os::fd::IntoRawFd for std::os::solid::io::OwnedFd std::os::solid::io::AsFd for &impl std::os::solid::io::AsFd std::os::solid::io::AsFd for &mut impl std::os::solid::io::AsFd std::os::solid::io::AsFd for Arc<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for Box<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for Rc<impl std::os::solid::io::AsFd> std::os::solid::io::AsFd for std::net::TcpListener std::os::solid::io::AsFd for std::net::TcpStream std::os::solid::io::AsFd for std::net::UdpSocket std::os::solid::io::AsFd for std::os::solid::io::BorrowedFd<'_> std::os::solid::io::AsFd for std::os::solid::io::OwnedFd Taking advantage of the above change, this PR also refactors the internal details of `std::sys::solid::net` to match the design of other targets, e.g., by redefining `Socket` as a newtype of `OwnedFd`.
2023-11-22unnecessary_mut_passedChris Denton-2/+2
This is where our Windows API bindings previously (and incorrectly) used `*mut` instead of `*const` pointers. Now that the bindings have been corrected, the mutable references (which auto-convert to `*mut`) are unnecessary and we can use shared references.
2023-11-22useless_conversionChris Denton-1/+1
2023-11-19Rollup merge of #117957 - the8472:pidfd-wait, r=Mark-SimulacrumMichael Goulet-0/+6
if available use a Child's pidfd for kill/wait This should get us closer to stabilization of pidfds since they now do something useful. And they're `CLOEXEC` now. ``` $ strace -ffe clone,sendmsg,recvmsg,execve,kill,pidfd_open,pidfd_send_signal,waitpid,waitid ./x test std --no-doc -- pidfd [...] running 1 tests strace: Process 816007 attached [pid 816007] pidfd_open(816006, 0) = 3 [pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f0c6b787990) = 816008 strace: Process 816008 attached [pid 816007] recvmsg(3, <unfinished ...> [pid 816008] pidfd_open(816008, 0) = 3 [pid 816008] sendmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0 [pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0 [pid 816008] execve("/usr/bin/false", ["false"], 0x7ffcf2100048 /* 105 vars */) = 0 [pid 816007] waitid(P_PIDFD, 4, <unfinished ...> [pid 816008] +++ exited with 1 +++ [pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0}, WEXITED, NULL) = 0 [pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=816008, si_uid=1001, si_status=1, si_utime=0, si_stime=0} --- [pid 816007] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 816009 attached , child_tidptr=0x7f0c6b787990) = 816009 [pid 816007] recvmsg(3, <unfinished ...> [pid 816009] pidfd_open(816009, 0) = 3 [pid 816009] sendmsg(5, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[3]}], msg_controllen=24, msg_flags=0}, 0) = 0 [pid 816007] <... recvmsg resumed>{msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="", iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[5]}], msg_controllen=24, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 0 [pid 816009] execve("/usr/bin/sleep", ["sleep", "1000"], 0x7ffcf2100048 /* 105 vars */) = 0 [pid 816007] waitid(P_PIDFD, 5, {}, WNOHANG|WEXITED, NULL) = 0 [pid 816007] pidfd_send_signal(5, SIGKILL, NULL, 0) = 0 [pid 816007] waitid(P_PIDFD, 5, <unfinished ...> [pid 816009] +++ killed by SIGKILL +++ [pid 816007] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0}, WEXITED, NULL) = 0 [pid 816007] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=816009, si_uid=1001, si_status=SIGKILL, si_utime=0, si_stime=0} --- [pid 816007] +++ exited with 0 +++ ```
2023-11-17Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naberMatthias Krüger-2/+0
Remove asmjs Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668). `asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-16if available use a Child's pidfd for kill/waitThe 8472-0/+6