about summary refs log tree commit diff
path: root/library/std/src/sys/pal/windows
AgeCommit message (Collapse)AuthorLines
2025-01-21Remove test panic from File::openChris Denton-3/+0
2025-01-14std: lazily allocate the main thread handlejoboet-4/+4
Thereby, we also allow accessing thread::current before main: as the runtime no longer tries to install its own handle, this will no longer trigger an abort. Rather, the name returned from name will only be "main" after the runtime initialization code has run, but I think that is acceptable. This new approach also requires some changes to the signal handling code, as calling `thread::current` would now allocate when called on the main thread, which is not acceptable. I fixed this by adding a new function (`with_current_name`) that performs all the naming logic without allocation or without initializing the thread ID (which could allocate on some platforms).
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-4/+4
2025-01-07Avoid naming variables `str`Josh Triplett-3/+3
This renames variables named `str` to other names, to make sure `str` always refers to a type. It's confusing to read code where `str` (or another standard type name) is used as an identifier. It also produces misleading syntax highlighting.
2025-01-03Fix UWP buildbdbai-2/+3
2024-12-27Auto merge of #134822 - jieyouxu:rollup-5xuaq82, r=jieyouxubors-2/+27
Rollup of 8 pull requests Successful merges: - #134606 (ptr::copy: fix docs for the overlapping case) - #134622 (Windows: Use WriteFile to write to a UTF-8 console) - #134759 (compiletest: Remove the `-test` suffix from normalize directives) - #134787 (Spruce up the docs of several queries related to the type/trait system and const eval) - #134806 (rustdoc: use shorter paths as preferred canonical paths) - #134815 (Sort triples by name in platform_support.md) - #134816 (tools: fix build failure caused by PR #134420) - #134819 (Fix mistake in windows file open) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-27Rollup merge of #134819 - ChrisDenton:trunc, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-1/+1
Fix mistake in windows file open In #134722 this should have been `c::FileAllocationInfo` not `c::FileEndOfFileInfo`. Oops.
2024-12-27Rollup merge of #134622 - ChrisDenton:write-file-utf8, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-1/+26
Windows: Use WriteFile to write to a UTF-8 console If the console code page is UTF-8 then we can simply write to it without needing to convert to UTF-16 and calling `WriteConsole`.
2024-12-27Fix renaming symlinks on WindowsChris Denton-7/+10
Previously we only detected mount points and not other types of links when determining reparse point behaviour.
2024-12-27Fix mistake in windows file openChris Denton-1/+1
2024-12-24Windows: Use FILE_ALLOCATION_INFO for truncationChris Denton-8/+20
But fallback to FILE_END_OF_FILE_INFO for WINE
2024-12-21Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, ↵Matthias Krüger-1/+153
r=ChrisDenton Win: Use POSIX rename semantics for `std::fs::rename` if available Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming and renaming if the target file is has already been opened with `FILE_SHARE_DELETE`, in which case the file gets renamed on disk while the open file handle still refers to the old file, just like in POSIX. This resolves #123985, where atomic renaming proved difficult to impossible due to race conditions. If `FileRenameInfoEx` isn't available due to missing support from the underlying filesystem or missing OS support, the renaming is retried with `FileRenameInfo`, which matches the behavior of `MoveFileEx`. This PR also manually replicates parts of `MoveFileEx`'s internal logic, as reverse-engineered from the disassembly: If the source file is a reparse point and said reparse point is a mount point, the mount point itself gets renamed; otherwise the reparse point is resolved and the result renamed. Notes: - Currently, the `win7` target doesn't bother with `FileRenameInfoEx` at all; it's probably desirable to remove that special casing and try `FileRenameInfoEx` anyway if it doesn't exist, in case the binary is run on newer OS versions. Fixes #123985
2024-12-21Windows: Use WriteFile to write to a UTF-8 consoleChris Denton-1/+26
2024-12-21Rollup merge of #123604 - michaelvanstraten:proc_thread_attribute_list, ↵Matthias Krüger-90/+13
r=ChrisDenton Abstract `ProcThreadAttributeList` into its own struct As extensively discussed in issue #114854, the current implementation of the unstable `windows_process_extensions_raw_attribute` features lacks support for passing a raw pointer. This PR wants to explore the opportunity to abstract away the `ProcThreadAttributeList` into its own struct to for one improve safety and usability and secondly make it possible to maybe also use it to spawn new threads. try-job: x86_64-mingw
2024-12-20mri: add track_caller to thread spawning methods for better backtracesRalf Jung-0/+1
2024-12-06Rollup merge of #130254 - GrigorenkoPV:QuotaExceeded, r=dtolnayMatthias Krüger-2/+2
Stabilize `std::io::ErrorKind::QuotaExceeded` Also drop "Filesystem" from its name. See #130190 for more info. FCP in #130190 cc #86442 r? `@dtolnay`
2024-11-30Abstract `ProcThreadAttributeList` into its own structMichael van Straten-90/+13
2024-11-30Rollup merge of #132515 - kornelski:home_fix, r=jhpratt许杰友 Jieyou Xu (Joe)-2/+2
Fix and undeprecate home_dir() `home_dir()` has been deprecated for 6 years due to using `HOME` env var on Windows. It's been a long time, and having a perpetually buggy and deprecated function in the standard library is not useful. I propose fixing and undeprecating it. 6 years seems more than long enough to warn users against relying on this function. The change in behavior is minor, and it's more of a bug fix than breakage. The old behavior is unlikely to be useful, and even if anybody actually needed to specifically use the non-standard `HOME` on Windows, they can trivially mitigate this change by reading the env var themselves. ---- Use of `USERPROFILE` is in line with the `home` crate: https://github.com/rust-lang/cargo/blob/37bc5f0232a0bb72dedd2c14149614fd8cdae649/crates/home/src/windows.rs#L12 The `home` crate uses `SHGetKnownFolderPath` instead of `GetUserProfileDirectoryW`. AFAIK it doesn't make any difference in practice, because `SHGetKnownFolderPath` merely adds support for more kinds of folders, including virtual (non-filesystem) folders identified by a GUID, but the specific case of [`FOLDERID_Profile`](https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid#FOLDERID_Profile) is documented as a FIXED folder (a regular filesystem path). Just in case, I've added a note to documentation that the use of `GetUserProfileDirectoryW` can change. I've used `CURRENT_RUSTC_VERSION` in a doccomment. `replace-version-placeholder` tool seems to perform a simple string replacement, so hopefully it'll get updated.
2024-11-26std: update internal uses of `io::const_error!`joboet-27/+22
2024-11-14Rollup merge of #132790 - aDotInTheVoid:ioslice-asslice-rides-again, r=cuviperJubilee-1/+6
Add as_slice/into_slice for IoSlice/IoSliceMut. ACP: https://github.com/rust-lang/libs-team/issues/93 Tracking issue: #132818 Based on a623c5233ae7f6b540e5c00f2be02f40b33b0793 (CC `@mpdn)` and #111277 (CC `@Lucretiel).` Closes: #124659 Tracking Issue: TODO try-job: test-various try-job: dist-various-1 try-job: dist-various-2 r? libs
2024-11-11Rollup merge of #130999 - cberner:flock_pr, r=joboetMatthias Krüger-0/+123
Implement file_lock feature This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag This is the initial implementation of https://github.com/rust-lang/rust/issues/130994 for Unix and Windows platforms. I will follow it up with an implementation for WASI preview 2
2024-11-09Add as_slice/into_slice for IoSlice/IoSliceMut.Alona Enraght-Moony-1/+6
Co-authored-by: Mike Pedersen <mike@mikepedersen.dk> Co-authored-by: Nathan West <Lucretiel@gmail.com>
2024-11-08Address review commentsChristopher Berner-32/+24
2024-11-08Update library/std/src/sys/pal/windows/fs.rsChristopher Berner-6/+4
Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2024-11-04Fix and undeprecate home_dir()Kornel-2/+2
2024-11-02Fix type reference in documents which was being confused with html tags.Houtamelo-1/+1
2024-10-29Win: rename: Use offset_of! in struct size calculationGeorge Tokmaji-4/+7
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-7/+7
2024-10-20fix docsklensy-6/+6
2024-10-20replace FindFirstFileW with FindFirstFileExW and apply optimizationklensy-4/+25
2024-10-20replace FindFirstFileW with FindFirstFileExW and regenerate bindingsklensy-3/+9
2024-10-19Support lock() and lock_shared() on async IO FilesChristopher Berner-13/+49
2024-10-17Abstract the state type for futexesPaul Menage-15/+20
In the same way that we expose SmallAtomic and SmallPrimitive to allow Windows to use a value other than an AtomicU32 for its futex state, this patch switches the primary futex state type from AtomicU32 to futex::Atomic. The futex::Atomic type should be usable as an atomic value with underlying primitive type equal to futex::Primitive. This allows supporting the futex API on systems where the underlying kernel futex implementation requires more state than simply an AtomicU32. All in-tree futex implementations simply define {Atomic,Primitive} directly as {AtomicU32,u32}.
2024-10-17Win: Remove special casing of the win7 target for `std::fs::rename`George Tokmaji-14/+1
2024-10-14Fix two const-hacksGeorge Bateman-15/+4
2024-10-13Implement file_lock featureChristopher Berner-0/+97
This adds lock(), lock_shared(), try_lock(), try_lock_shared(), and unlock() to File gated behind the file_lock feature flag
2024-10-13remove outdated comment now that Miri is on CIRalf Jung-1/+0
2024-10-13sys/windows: remove miri hack that is only needed for win7Ralf Jung-7/+3
2024-10-05Stabilize `std::io::ErrorKind::QuotaExceeded`Pavel Grigorenko-2/+2
Also drop "Filesystem" from its name
2024-09-30Win: Use `FILE_RENAME_FLAG_POSIX_SEMANTICS` for `std::fs::rename` if availableGeorge Tokmaji-1/+163
Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming. If it isn't supported, we fall back to `FileRenameInfo`. This commit also replicates `MoveFileExW`'s behavior of checking whether the source file is a mount point and moving the mount point instead of resolving the target path.
2024-09-25Use `&raw` in the standard libraryJosh Stone-29/+24
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!` and `ptr::addr_of_mut!` can stop allowing the unstable feature. I intentionally did not change any documentation or tests, but the rest of those macro uses are all now using `&raw const` or `&raw mut` in the standard library.
2024-09-23std: implement the `random` featurejoboet-32/+4
Implements the ACP https://github.com/rust-lang/libs-team/issues/393.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-26/+26
2024-09-18Rollup merge of #129934 - ChrisDenton:remove-dir-all3, r=AmanieuJubilee-3/+12
Win: Open dir for sync access in remove_dir_all A small follow up to #129800. We should explicitly open directories for synchronous access. We ultimately use `GetFileInformationByHandleEx` to read directories which should paper over any issues caused by using async directory reads (or else return an error) but it's better to do the right thing in the first place. Note though that `delete` does not read or write any data so it's not necessary there.
2024-09-12Rollup merge of #130101 - RalfJung:const-cleanup, r=fee1-deadMatthias Krüger-1/+1
some const cleanup: remove unnecessary attributes, add const-hack indications I learned that we use `FIXME(const-hack)` on top of the "const-hack" label. That seems much better since it marks the right place in the code and moves around with the code. So I went through the PRs with that label and added appropriate FIXMEs in the code. IMO this means we can then remove the label -- Cc ``@rust-lang/wg-const-eval.`` I also noticed some const stability attributes that don't do anything useful, and removed them. r? ``@fee1-dead``
2024-09-11Rollup merge of #130207 - GrigorenkoPV:ERROR_CANT_RESOLVE_FILENAME, ↵Matthias Krüger-0/+1
r=ChrisDenton Map `ERROR_CANT_RESOLVE_FILENAME` to `ErrorKind::FilesystemLoop` cc #86442 As summarized in #130188, there seems to be a consensus that this should be done.
2024-09-11Map `ERROR_CANT_RESOLVE_FILENAME` to `ErrorKind::FilesystemLoop`Pavel Grigorenko-0/+1
2024-09-11Map `WSAEDQUOT` to `ErrorKind::FilesystemQuotaExceeded`Pavel Grigorenko-0/+1
2024-09-08add FIXME(const-hack)Ralf Jung-1/+1
2024-09-03Win: Open dir for sync access in remove_dir_allChris Denton-3/+12