about summary refs log tree commit diff
path: root/library/std/src/os/windows
AgeCommit message (Collapse)AuthorLines
2023-11-22useless_conversionChris Denton-1/+1
2023-11-15Substitute version placeholdersMark Rousskov-3/+3
2023-10-31Stabilize `file_set_times`Josh Triplett-3/+3
Approved via FCP in https://github.com/rust-lang/rust/issues/98245 .
2023-10-03Bump version placeholdersMark Rousskov-3/+3
2023-09-28Auto merge of #114882 - ChrisDenton:riddle-me, r=dtolnaybors-4/+4
Update windows ffi bindings Bump `windows-bindgen` to version 0.51.1. This brings with it some changes to the generated FFI bindings, but little that affects the code. One change that does have more of an impact is `SOCKET` being `usize` instead of either `u64` or `u32` (as is used in std's public `SOCKET` type). However, it's now easy enough to abstract over that difference. Finally I added a few new bindings that are likely to be used in pending PRs, mostly to make sure they're ok with the new metadata. r? libs
2023-09-28Auto merge of #98704 - vthib:impl-from-raw-for-childstd-structs, r=dtolnaybors-0/+39
Implement From<OwnedFd/Handle> for ChildStdin/out/err object ## Summary Comments in `library/std/src/process.rs` ( https://github.com/rust-lang/rust/commit/ab08639e5950f5c8a42a2870c9636181308c3686 ) indicates that `ChildStdin`, `ChildStdout`, `ChildStderr` implements some traits that are not actually implemented: `FromRawFd`, `FromRawHandle`, and the `From<OwnedFd>/From<OwnedHandle>` from the io_safety feature. In this PR I implement `FromRawHandle` and `FromRawFd` for those 3 objects. ## Usecase I have a usecase where those implementations are basically needed. I want to customize in the `Command::spawn` API how the pipes for the parent/child communications are created (mainly to strengthen the security attributes on them). I can properly setup the pipes, and the "child" handles can be provided to `Child::spawn` easily using `Stdio::from_raw_handle`. However, there is no way to generate the `ChildStd*` objects from the raw handle of the created name pipe, which would be very useful to still expose the same API than in other OS (basically a `spawn(...) -> (Child, ChildStdin, ChildStdout, ChildSterr)`, where on windows this is customized), and to for example use `tokio::ChildStdin::from_std` afterwards. ## Questions * Are those impls OK to add? I have searched to see if those impls were missing on purpose, or if it was just never implemented because never needed. I haven't found any indication on why they couldn't be added, although the user clearly has to be very careful that the handle provided makes sense (i think, mainly that it is in overlapped mode for windows). * If this change is ok, adding the impls for the io_safety feature would probably be best, or should it be done in another PR? * I just copy-pasted the `#[stable(...)]` attributes, but the `since` value has to be updated, I'm not sure to which value.
2023-09-28Update stability attribute for child stream From implsDavid Tolnay-3/+3
2023-09-22fix OS-specific I/O safety docs since the io_safety feature is stableRalf Jung-4/+7
2023-09-22Auto merge of #114780 - RalfJung:io-safety, r=Amanieubors-3/+6
add more explicit I/O safety documentation Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/434 Cc https://github.com/rust-lang/rust/issues/114167 Cc `@Manishearth` `@sunfishcode` `@joshtriplett`
2023-08-28Abstract over internal `SOCKET` typeChris Denton-4/+4
This allows `SOCKET` to be `usize` internally
2023-08-25Added option to set ProcThreadAttributes for Windows processesMichael van Straten-0/+69
This implements the ability to add arbitrary attributes to a command on Windows targets using a new `raw_attribute` method on the [`CommandExt`](https://doc.rust-lang.org/stable/std/os/windows/process/trait.CommandExt.html) trait. Setting these attributes provides extended configuration options for Windows processes. Co-authored-by: Tyler Ruckinger <t.ruckinger@gmail.com>
2023-08-14wording; and explain some of the possible consequences of violating io-safetyRalf Jung-1/+1
2023-08-14sync the various FromRawFd trait docs, and remove 'valid'Ralf Jung-2/+4
2023-08-13add more explicit I/O safety documentationRalf Jung-1/+2
2023-05-30add doc on From<OwnedFd/Handle> impl for ChildStd*Vincent Thiberville-0/+12
2023-05-30add FromOwnedFd/FromOwnedHandle for ChildStdin/out/errVincent Thiberville-0/+27
2023-05-30Swap out CURRENT_RUSTC_VERSION to 1.71.0Mark Rousskov-6/+6
2023-05-15Add creation time support to `FileTimes` on apple and windowsbeetrees-1/+18
2023-05-14Auto merge of #108196 - sunfishcode:sunfishcode/windows-as-socket-impls, ↵bors-0/+72
r=dtolnay Implement `AsHandle`/`AsSocket` for `Arc`/`Rc`/`Box` on Windows Implement the Windows counterpart to #97437 and #107317: Implement `AsHandle` and `AsSocket` for `Arc<T>`, `Rc<T>`, and `Box<T>`.
2023-05-09Don't force include Windows goop when documentingChris Denton-34/+40
2023-05-05Use new bindingsChris Denton-1/+1
2023-04-28replace version placeholdersPietro Albini-1/+1
2023-04-26Spelling library/Josh Soref-2/+2
* advance * aligned * borrowed * calculate * debugable * debuggable * declarations * desugaring * documentation * enclave * ignorable * initialized * iterator * kaboom * monomorphization * nonexistent * optimizer * panicking * process * reentrant * rustonomicon * the * uninitialized Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-10Stabilize IsTerminalJosh Triplett-1/+1
closes: https://github.com/rust-lang/rust/issues/98070
2023-02-17Implement `AsHandle`/`AsSocket` for `Arc`/`Rc`/`Box` on WindowsDan Gohman-0/+72
Implement the Windows counterpart to #97437 and #107317: Implement `AsHandle` and `AsSocket` for `Arc<T>`, `Rc<T>`, and `Box<T>`.
2022-11-20enable fuzzy_provenance_casts lint in libstdRalf Jung-0/+1
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+17
The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-07-27Rollup merge of #98583 - joshtriplett:stabilize-windows-symlink-types, r=thomccYuki Okushi-5/+9
Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file` These calls allow detecting whether a symlink is a file or a directory, a distinction Windows maintains, and one important to software that wants to do further operations on the symlink (e.g. removing it).
2022-07-11Auto merge of #97841 - nvzqz:inline-encode-wide, r=thomccbors-0/+1
Inline Windows `OsStrExt::encode_wide` User crates currently produce much more code than necessary because the optimizer fails to make assumptions about this method.
2022-07-07Rollup merge of #97917 - AronParker:master, r=ChrisDentonMatthias Krüger-0/+23
Implement ExitCodeExt for Windows Fixes #97914 ### Motivation: On Windows it is common for applications to return `HRESULT` (`i32`) or `DWORD` (`u32`) values. These stem from COM based components ([HRESULTS](https://docs.microsoft.com/en-us/windows/win32/api/objbase/nf-objbase-coinitialize)), Win32 errors ([GetLastError](https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror)), GUI applications ([WM_QUIT](https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-quit)) and more. The newly stabilized `ExitCode` provides an excellent fit for propagating these values, because `std::process::exit` does not run deconstructors which can result in errors. However, `ExitCode` currently only implements `From<u8> for ExitCode`, which disallows the full range of `i32`/`u32` values. This pull requests attempts to address that shortcoming by providing windows specific extensions that accept a `u32` value (which covers all possible `HRESULTS` and Win32 errors) analog to [ExitStatusExt::from_raw](https://doc.rust-lang.org/std/os/windows/process/trait.ExitStatusExt.html#tymethod.from_raw). This was also intended by the original Stabilization https://github.com/rust-lang/rust/pull/93840#issue-1129209143= as pointed out by ``@eggyal`` in https://github.com/rust-lang/rust/issues/97914#issuecomment-1151076755: > Issues around platform specific representations: We resolved this issue by changing the return type of report from i32 to the opaque type ExitCode. __That way we can change the underlying representation without affecting the API, letting us offer full support for platform specific exit code APIs in the future.__ [Emphasis added] ### API ```rust /// Windows-specific extensions to [`process::ExitCode`]. /// /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] pub trait ExitCodeExt: Sealed { /// Creates a new `ExitCode` from the raw underlying `u32` return value of /// a process. #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] fn from_raw(raw: u32) -> Self; } #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] impl ExitCodeExt for process::ExitCode { fn from_raw(raw: u32) -> Self { process::ExitCode::from_inner(From::from(raw)) } } ``` ### Misc I apologize in advance if I misplaced any attributes regarding stabilzation, as far as I learned traits are insta-stable so I chose to make them stable. If this is an error, please let me know and I'll correct it. I also added some additional machinery to make it work, analog to [ExitStatus](https://doc.rust-lang.org/std/process/struct.ExitStatus.html#). EDIT: Proposal: https://github.com/rust-lang/libs-team/issues/48
2022-06-27Seal Windows `FileTypeExt` extension trait to allow adding future methodsJosh Triplett-1/+5
2022-06-27Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`Josh Triplett-4/+4
These calls allow detecting whether a symlink is a file or a directory, a distinction Windows maintains, and one important to software that wants to do further operations on the symlink (e.g. removing it).
2022-06-20Rollup merge of #97149 - ChrisDenton:win_async_pipes, r=m-ou-seDylan DPC-0/+40
Windows: `CommandExt::async_pipes` Discussed in https://github.com/tokio-rs/tokio/issues/4670 was the need for third party crates to be able to force `process::Command::spawn` to create pipes as async. This implements the suggestion for a `async_pipes` method that gives third party crates that option. # Example: ```rust use std::process::{Command, Stdio}; Command::new("cmd") .async_pipes(true) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() .unwrap(); ```
2022-06-20Windows: `CommandExt::async_pipes`Chris Denton-0/+40
2022-06-15Add the new stability attributes, for Windows.Dan Gohman-0/+2
2022-06-15Revise the documentation for `try_clone`.Dan Gohman-4/+4
On Unix, describe these in terms of the underlying "file description". On Windows, describe them in terms of the underlying "object".
2022-06-15Add `BorrowedFd::try_clone_to_owned`.Dan Gohman-14/+30
And `BorrowedHandle::try_clone_to_owned` and `BorrowedSocket::try_clone_to_owned` on Windows.
2022-06-15Document that `BorrowedFd` may be used to do a `dup`.Dan Gohman-3/+9
2022-06-14Implement stabilization of `#[feature(io_safety)]`.Dan Gohman-28/+89
Implement stabilization of [I/O safety], aka `#[feature(io_safety)]`. Fixes #87074. [I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
2022-06-10Make "windows_process_exit_code_from" unstableAron Parker-3/+3
2022-06-10Incorporate warning for potential exit code ambiguitiesAron Parker-0/+4
2022-06-10Fix copy paste errorAron Parker-1/+1
2022-06-09Implement ExitCodeExt for WindowsAron Parker-0/+19
2022-06-07Inline Windows `OsStrExt::encode_wide`Nikolai Vazquez-0/+1
User crates currently produce much more code than necessary because the optimizer fails to make assumptions about this method.
2022-05-17Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se"Mark Rousskov-13/+0
This reverts commit ddb7fbe8434be481607ae199fe2aee976ee2fc2e, reversing changes made to baaa3b682986879c7784b5733ecea942e9ae7de3.
2022-05-15Rollup merge of #97060 - bdbai:fix/uwphandle, r=ChrisDentonDylan DPC-0/+2
Fix use of SetHandleInformation on UWP The use of `SetHandleInformation` (introduced in #96441 to make `HANDLE` inheritable) breaks UWP builds because it is not available for UWP targets. Proposed workaround: duplicate the `HANDLE` with `inherit = true` and immediately close the old one. Traditional Windows Desktop programs are not affected. cc `@ChrisDenton`
2022-05-15Rollup merge of #96947 - ↵Dylan DPC-0/+26
sunfishcode:sunfishcode/rustc-nonnull-optimization-guaranteed, r=joshtriplett Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket PR #94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that #94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
2022-05-15fix use of SetHandleInformation on UWPbdbai-0/+2
2022-05-11Fix comment syntax.Dan Gohman-0/+1
2022-05-11Relax the wording about the meaning of -1.Dan Gohman-6/+11