aboutsummaryrefslogtreecommitdiff
path: root/src/internal/syscall/windows/syscall_windows.go
AgeCommit message (Collapse)Author
2026-02-24internal/cpu: use IsProcessorFeaturePresent to calculate ARM64 on windowsAlex Brainman
This CL also adds internal/syscall/windows.IsProcessorFeaturePresent and all processor feature consts to test internal/cpu changes. For #76791 Change-Id: Iba9cc812f676b700e767a1ed7f194fcb4a67f61b Cq-Include-Trybots: luci.golang.try:gotip-windows-arm64 Reviewed-on: https://go-review.googlesource.com/c/go/+/745560 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: David Chase <drchase@google.com>
2026-02-17internal/syscall/windows: correct some enums and syscall signaturesMichal Pristas
This CL corrects code submitted in CL 741040. Fixes #77402 Change-Id: I1c22c1a9f77028f3c2a8e3905f2ec5b071b5445e GitHub-Last-Rev: 2bfb07310b4707484b5bdce96ad367db567741c4 GitHub-Pull-Request: golang/go#77525 Reviewed-on: https://go-review.googlesource.com/c/go/+/743780 Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2026-02-06os: support deleting inaccessible files in RemoveAllMichal Pristas
windows: retry file open with DELETE access after access denied Additional access rights when opening files, including SYNCHRONIZE, break deletion when the caller has FILE_DELETE_CHILD on the parent directory but not the file. Retry with DELETE only restores correct Windows semantics. Fixes #77402 Change-Id: Ie53bc6f1673de1a8af4dcfb7496daf99e71098cb GitHub-Last-Rev: 0ad635cf1a13c0242e3b1922cf47a8c594dd7215 GitHub-Pull-Request: golang/go#77403 Reviewed-on: https://go-review.googlesource.com/c/go/+/741040 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-11-04internal/syscall/windows: fix ReOpenFile sentinel error valueqmuntal
ReOpenFile is documented to return INVALID_HANDLE_VALUE on error, but the previous definition was checking for 0 instead. Change-Id: Idec5e75e40b9f6c409e068d63a9b606781e80a46 Reviewed-on: https://go-review.googlesource.com/c/go/+/717320 Auto-Submit: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-21os: support deleting read-only files in RemoveAll on older Windows versionsqmuntal
The Windows implementation of RemoveAll supports deleting read-only files only on file systems that supports POSIX semantics and on newer Windows versions (Windows 10 RS5 and latter). For all the other cases, the read-only bit was not clearer before deleting read-only files, so they fail to delete. Note that this case was supported prior to CL 75922, which landed on Go 1.25. Fixes #75922 Change-Id: Id6e6477f42e1952d08318ca3e4ab7c1648969f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/713480 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-09-26internal/poll: simplify WriteMsg and ReadMsg on Windowsqmuntal
Let newWSAMsg retrieve the socket from the sync pool for unconnected sockets instead of forcing the caller to do it. Change-Id: I9b3d30bf3f5be187cbde5735d519b3b14f7b3008 Reviewed-on: https://go-review.googlesource.com/c/go/+/704116 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-09-26internal/poll: don't call SetFilePointerEx in Seek for overlapped handlesqmuntal
Overlapped handles don't have the file pointer updated when performing I/O operations, so there is no need to call syscall.SetFilePointerEx in FD.Seek. Updating the in-memory offset is sufficient. Updates #74951 (provides a more complete fix) Change-Id: Ibede6625cdbd501fc92cfdf8ce2782ec291af2b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/698035 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-05-21os: add Root.MkdirAllDamien Neil
For #67002 Change-Id: Idd74b5b59e787e89bdfad82171b6a7719465f501 Reviewed-on: https://go-review.googlesource.com/c/go/+/674116 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-05net,os: support converting between *os.File and net.Conn on Windowsqmuntal
The runtime poller and os.NewFile recently gained support for disassociating the handle from the runtime poller IOCP (see CL 664455). This was the main blocker for allowing the conversion between *os.File and net.Conn. Implementing the conversion is now trivial. The only remaining work, implemented in this CL, is improving os.NewFile to also support socket handles and updating some build tags so that Windows can share almost the same net's File implementation as Unix. There is one important limitation, though: the duplicated socket handle returned by the various File methods in the net package is not usable on other process. If someone needs to pass a socket handle to another process, they should manually call the WSADuplicateSocket Windows API passing the process ID of the target process. Fixes #9503. Fixes #10350. Updates #19098. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race,gotip-windows-amd64-longtest,gotip-windows-arm64 Change-Id: Ic43cadaac2662b925d57a9d362ddc7ae21d1b56e Reviewed-on: https://go-review.googlesource.com/c/go/+/668195 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-04-24os,internal/poll: disassociate handle from IOCP in File.Fdqmuntal
Go 1.25 will gain support for overlapped IO on handles passed to os.NewFile thanks to CL 662236. It was previously not possible to add an overlapped handle to the Go runtime's IO completion port (IOCP), and now happens on the first call the an IO method. This means that there is code that relies on the fact that File.Fd returns a handle that can always be associated with a custom IOCP. That wouldn't be the case anymore, as a handle can only be associated with one IOCP at a time and it must be explicitly disassociated. To fix this breaking change, File.Fd will disassociate the handle from the Go runtime IOCP before returning it. It is then not necessary to defer the association until the first IO method is called, which was recently added in CL 661955 to support this same use case, but in a more complex and unreliable way. Updates #19098. Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race,gotip-windows-amd64-longtest,gotip-windows-arm64 Change-Id: Id8a7e04d35057047c61d1733bad5bf45494b2c28 Reviewed-on: https://go-review.googlesource.com/c/go/+/664455 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-04-04internal/syscall/windows: use unsafe.Pointer instead of uintptrqmuntal
Some functions accept a uintptr when they should accept an unsafe.Pointer, else the compiler won't know that the pointer should be kept alive across the call, potentially causing undefined behavior. Fixes #73156 (potentially) Change-Id: I29c847eb8ffbb785fabf217e9f3718d10cfb5047 Reviewed-on: https://go-review.googlesource.com/c/go/+/662855 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-04-04internal/poll: simplify execIOqmuntal
execIO has multiple return paths and multiple places where error is mangled. This CL simplifies the function by just having one return path. Some more tests have been added to ensure that the error handling is done correctly. Updates #19098. Change-Id: Ida0b1e85d4d123914054306e5bef8da94408b91c Reviewed-on: https://go-review.googlesource.com/c/go/+/662215 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Carlos Amedee <carlos@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-04-03internal/syscall/windows: define NtQueryInformationFile buffer as unsafe.Pointerqmuntal
The unsafe.Pointer -> uintptr conversion must happen when calling syscall.Syscall, not when calling the auto-generated wrapper function, else the Go compiler doesn't know that it has to keep the pointer alive. This can cause undefined behavior and stack corruption. Fixes #73135. Fixes #73112 (potentially). Fixes #73128 (potentially). Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race Change-Id: Ib3ad8b99618d8997bfd0742c0e44aeda696856c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/662575 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Carlos Amedee <carlos@golang.org>
2025-04-01internal/poll: defer IOCP association until first IO operationqmuntal
Defer the association of the IOCP to the handle until the first I/O operation is performed. A handle can only be associated with one IOCP at a time, so this allows external code to associate the handle with their own IOCP and still be able to use a FD (through os.NewFile) to pass the handle around (e.g. to a child process standard input, output, and error) without having to worry about the IOCP association. This CL doesn't change any user-visible behavior, as os.NewFile still initializes the FD as non-pollable. For #19098. Change-Id: Id22a49846d4fda3a66ffcc0bc1b48eb39b395dc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/661955 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-31os,internal/poll: support I/O on overlapped handles not added to the pollerqmuntal
Calling syscall.ReadFile and syscall.WriteFile on overlapped handles always need to be passed a valid *syscall.Overlapped structure, even if the handle is not added to a IOCP (like the Go runtime poller). Else, the syscall will fail with ERROR_INVALID_PARAMETER. We also need to handle ERROR_IO_PENDING errors when the overlapped handle is not added to the poller, in which case we need to block until the operation completes. Previous CLs already added support for overlapped handles to the poller, mostly to keep track of the file offset independently of the file pointer (which is not supported for overlapped handles). Fixed #15388. Updates #19098. Change-Id: I2103ab892a37d0e326752ae8c2771a43c13ba42e Reviewed-on: https://go-review.googlesource.com/c/go/+/661795 Auto-Submit: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2025-03-28internal/poll: don't skip empty writes on Windowsqmuntal
Empty writes might be important for some protocols. Let Windows decide what do with them rather than skipping them on our side. This is inline with the behavior of other platforms. While here, refactor the Read/Write/Pwrite methods to reduce one indentation level and make the code easier to read. Fixes #73084. Change-Id: Ic5393358e237d53b8be6097cd7359ac0ff205309 Reviewed-on: https://go-review.googlesource.com/c/go/+/661435 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-26internal/poll: support async file operations on Windowsqmuntal
This CL adds support for async file operations on Windows. The affected functions are Read, Write, Pread, and Pwrite. The code has been slightly refactored to avoid duplication. Both the async and sync variants follow the same code path, with the exception of the async variant passes an overlapped structure to the syscalls and supports the use of a completion port. This doesn't change any user-facing behavior, as the os package still sets the pollable parameter to false when calling FD.Init. For #19098. Change-Id: Iead6e51fa8f57e83456eb5ccdce28c2ea3846cc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/660595 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-02-19path/filepath: use RtlIsDosDeviceName_U to detect Windows devicesqmuntal
RtlIsDosDeviceName_U is specifically designed to detect Windows devices. We were using GetFullPathName to do this, but it's not the right API for the job, as it is slower and allocates more memory. goos: windows goarch: amd64 pkg: path/filepath cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ IsLocal-12 5.685µ ± 59% 1.853µ ± 12% -67.41% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ IsLocal-12 496.00 ± 0% 48.00 ± 0% -90.32% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ IsLocal-12 10.000 ± 0% 6.000 ± 0% -40.00% (p=0.000 n=10) Change-Id: Ib40ad7a90ab93cf7051c8d6becbce4d287f10f4e Reviewed-on: https://go-review.googlesource.com/c/go/+/650578 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-11-20os: add Root.Stat and Root.LstatDamien Neil
For #67002 Change-Id: I0903f45dbb4c44ea0280c340c96c5f3c3c0781be Reviewed-on: https://go-review.googlesource.com/c/go/+/627475 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
2024-11-20os: add Root.RemoveDamien Neil
For #67002 Change-Id: Ibbf44c0bf62f53695a7399ba0dae5b84d5efd374 Reviewed-on: https://go-review.googlesource.com/c/go/+/627076 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-11internal/syscall/windows: add Openat, MkdiratDamien Neil
Windows versions of openat and mkdirat, implemented using NtCreateFile. For #67002 Change-Id: If43b1c1069733e5c45f7d45a69699fec30187308 Reviewed-on: https://go-review.googlesource.com/c/go/+/619435 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-07internal/syscall/windows: add NtCreateFileDamien Neil
Mostly copied from x/sys/windows. This adds a various related types and functions, but the purpose is to give access to NtCreateFile, which can be used as an equivalent to openat. For #67002 Change-Id: I04e6f630445a55c2000c9c323ce8dcdc7fc0d0e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/617377 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-08-27os/user: test that Current does not depend on netapi32.dllqmuntal
Updates #21867. Change-Id: I1eb923ef66aa0f338bfa0d683159edc1d8ae2a6c Reviewed-on: https://go-review.googlesource.com/c/go/+/604415 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-08-08os/user: support calling Current on impersonated threadsqmuntal
The syscall.OpenCurrentProcessToken call in user.Current fails when called from an impersonated thread, as the process token is normally in that case. This change ensures that the current thread is not impersonated when calling OpenCurrentProcessToken, and then restores the impersonation state, if any. Fixes #68647 Change-Id: I3197535dd8355d21029a42f7aa3936d8fb021202 Reviewed-on: https://go-review.googlesource.com/c/go/+/602415 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-26testing: use QueryPerformanceCounter on WindowsEgon Elbre
Windows time.Now granularity is around 0.5ms on modern systems, which introduces a significant noise into benchmark results. Instead of relying time.Now use QueryPerformanceCounter, which has significantly better granularity compared to time.Now. │ TimeNow-32 │ HighPrecisionTimeNow-32 │ │ sec/op │ sec/op vs base │ 4.812n ± 0% 30.580n ± 0% +535.43% (p=0.000 n=20) Fixes #31160 Change-Id: Ib2a574d638c9c6762a2524212def02265574e267 Reviewed-on: https://go-review.googlesource.com/c/go/+/557315 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-03-27os: make readdir more robust on Windowsqmuntal
On Windows, File.readdir currently fails if the volume information can't be retrieved via GetVolumeInformationByHandle and if the directory path is relative and can't be converted to an absolute path. This change makes readdir more robust by not failing in these cases, as these steps are just necessary to support a potential call to os.SameFile, but not for the actual readdir operation. os.SameFile will still fail in these cases, but that's a separate issue tracked in #62042. Change-Id: I8d98d8379bdac4b2832fa433432a5f027756abaa Reviewed-on: https://go-review.googlesource.com/c/go/+/574155 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2024-03-15net: fixes to dnsReadConfig in dnsconfig_windows.goQuentin McGaw
- Only search DNS servers for network interfaces with at least one gateway - Clarify comment on deprecated site local anycast fec0/10 DNS IPv6 addresses - Minor maintenance: skip not "up" interfaces earlier in outer loop Change-Id: I98ca7b81d3d51e6aa6bfa4a10dcd651305a843df GitHub-Last-Rev: 3b358c7e3f89971d069286f997dc19e092ec8f08 GitHub-Pull-Request: golang/go#64441 Reviewed-on: https://go-review.googlesource.com/c/go/+/545775 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2024-03-12internal/syscall/windows: implement SupportUnixSocket by enumerating protocolsqmuntal
windows.SupportUnixSocket is currently implemented using a Windows version check. This approach is not reliable, see #27943 and #28061. Also, it uses the undocumented RtlGetNtVersionNumbers API, which we should try to avoid. This PR implements SupportUnixSocket by enumerating the available protocols and checking for AF_UNIX support. Cq-Include-Trybots: luci.golang.try:gotip-windows-arm64 Change-Id: I76cd635067309f09571ad0eac4a5699450a2709a Reviewed-on: https://go-review.googlesource.com/c/go/+/570075 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-02-07runtime,internal/syscall/windows: remove long path support checkqmuntal
The runtime currently enables long path support process-wide by updating the process environment block (PEB). It then tries to create a file using a long path to check if the PEB update made any difference. There hasn't been any report that the PEB update was not effective, and the check itself is quite tricky, so it's time to remove it. While here, linkname `runtime.canUseLongPaths` to a variable in internal/syscall/windows instead of the os package so it is easier to consume from other packages. Change-Id: I549380b7f2c242dc4db20d5be603840282de69b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/536495 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com>
2024-01-23runtime,internal/poll: move websocket handling out of the runtime on Windowsqmuntal
On Windows, the netpoll is currently coupled with the websocket usage in the internal/poll package. This CL moves the websocket handling out of the runtime and puts it into the internal/poll package, which already contains most of the async I/O logic for websockets. This is a good refactor per se, as the Go runtime shouldn't know about websockets. In addition, it will make it easier (in a future CL) to only load ws2_32.dll when the Go program actually uses websockets. Change-Id: Ic820872cf9bdbbf092505ed7f7504edb6687735e Reviewed-on: https://go-review.googlesource.com/c/go/+/556936 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-12-18internal/syscall/windows: fix the signature of SetFileInformationByHandleBryan C. Mills
Also fix its call site in internal/poll to pass the length of the actual buffer instead of an unrelated variable, and update the definition of FILE_BASIC_INFO to match the documented field types and add padding that is empirically needed on the 386 architecture. Passing a pointer to a Go-allocated buffer as type uintptr violates the unsafe.Pointer conversion rules, which allow such a conversion only in the call expression itself for a call to syscall.Syscall or equivalent. That can allow the buffer to be corrupted arbitrarily if the Go runtime happens to garbage-collect it while the call to SetFileInformationByHandle is in progress. The Microsoft documentation for SetFileInformationByHandle specifies its third argument type as LPVOID, which corresponds to Go's unsafe.Pointer, not uintptr. Fixes #58933 (maybe). Change-Id: If577b57adea9922f5fcca55e46030c703d8f035c Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/549256 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2023-10-20crypto/rand,runtime: switch RtlGenRandom for ProcessPrngRoland Shoemaker
RtlGenRandom is a semi-undocumented API, also known as SystemFunction036, which we use to generate random data on Windows. It's definition, in cryptbase.dll, is an opaque wrapper for the documented API ProcessPrng. Instead of using RtlGenRandom, switch to using ProcessPrng, since the former is simply a wrapper for the latter, there should be no practical change on the user side, other than a minor change in the DLLs we load. Change-Id: Ie6891bf97b1d47f5368cccbe92f374dba2c2672a Reviewed-on: https://go-review.googlesource.com/c/go/+/536235 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-25os: omit existence check for GetFinalPathNameByHandleqmuntal
GetFinalPathNameByHandle exists since Windows Vista, which we no longer support, so we don't need to prove that it exists before using it. Updates #57003 Change-Id: Iff2bbe51d3baa3aabcaacf39ea3cbeda0088b9d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/522195 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-08-16os: support file systems without file IDs when reading directories on windowsqmuntal
Some file systems do not support file IDs. We should not use FILE_ID_BOTH_DIR_INFO when reading directories on these file systems, as it will fail. Instead, we should use FILE_ID_FULL_DIR_INFO, which doesn't require file ID support. Fixes #61907 Fixes #61918 Change-Id: I83d0a898f8eb254dffe5b8fc68a4ca4ef21c0d85 Reviewed-on: https://go-review.googlesource.com/c/go/+/518195 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-08-09os: make MkdirAll support volume namesqmuntal
MkdirAll fails to create directories under root paths using volume names (e.g. //?/Volume{GUID}/foo). This is because fixRootDirectory only handle extended length paths using drive letters (e.g. //?/C:/foo). This CL fixes that issue by also detecting volume names without path separator. Updates #22230 Fixes #39785 Change-Id: I813fdc0b968ce71a4297f69245b935558e6cd789 Reviewed-on: https://go-review.googlesource.com/c/go/+/517015 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-08-07os: fix test failure when Workstation service is not enabledqiulaidongfeng
TestNetworkSymbolicLink needs to enable the Workstation service, otherwise it will fail. This CL avoids failure by skipping testing when the Workstation service is not enabled. Fixes #61467 Change-Id: I395952fc18329e0b0dfdec55c8a18f4007ea91de Change-Id: I395952fc18329e0b0dfdec55c8a18f4007ea91de GitHub-Last-Rev: 7f089d1dff3ca939915fc8b3e49eba3908f15180 GitHub-Pull-Request: golang/go#61564 Reviewed-on: https://go-review.googlesource.com/c/go/+/512736 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-07-25os: mark the share created by TestNetworkSymbolicLink as temporaryBryan C. Mills
Also use a unique share name for each run of the test. This may help with #61467, but since I couldn't reproduce the failure in the first place I don't know. It passes locally for me. For #61467. Change-Id: Ie51e3cf381063e02e4849af5c1a1ed7441ce21c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/512075 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-05-15os, syscall: support ill-formed UTF-16 strings on Windowsqmuntal
Windows UTF-16 strings can contain unpaired surrogates, which can't be decoded into a valid UTF-8 string. This file defines a set of functions that can be used to encode and decode potentially ill-formed UTF-16 strings by using the [the WTF-8 encoding](https://simonsapin.github.io/wtf-8/). WTF-8 is a strict superset of UTF-8, i.e. any string that is well-formed in UTF-8 is also well-formed in WTF-8 and the content is unchanged. Also, the conversion never fails and is lossless. The benefit of using WTF-8 instead of UTF-8 when decoding a UTF-16 string is that the conversion is lossless even for ill-formed UTF-16 strings. This property allows to read an ill-formed UTF-16 string, convert it to a Go string, and convert it back to the same original UTF-16 string. Fixes #59971 Change-Id: Id6007f6e537844913402b233e73d698688cd5ba6 Reviewed-on: https://go-review.googlesource.com/c/go/+/493036 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Paul Hampson <Paul.Hampson@Pobox.com>
2023-05-02cmd/link: generate .xdata PE sectionqmuntal
This CL adds a .xdata section to the PE file generated by the Go linker. It is also the first CL of the SEH chain that adds effective support for unwinding the Go stack, as demonstrated by the newly added tests. The .xdata section is a standard PE section that contains an array of unwind data info structures. This structures are used to record the effects a function has on the stack pointer, and where the nonvolatile registers are saved on the stack [1]. Note that this CL still does not support unwinding the cgo stack. Updates #57302 [1] https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64#struct-unwind_info Change-Id: I6f305a51ed130b758ff9ca7b90c091e50a109a6f Reviewed-on: https://go-review.googlesource.com/c/go/+/457455 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Davis Goodin <dagood@microsoft.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
2023-05-02cmd/link: generate .pdata PE sectionqmuntal
This CL adds a .pdata section to the PE file generated by the Go linker. The .pdata section is a standard section [1] that contains an array of function table entries that are used for stack unwinding. The table entries layout is taken from [2]. This CL just generates the table entries without any unwinding information, which is enough to start doing some E2E tests between the Go linker and the Win32 APIs. The goal of the .pdata table is to allow Windows retrieve unwind information for a function at a given PC. It does so by doing a binary search on the table, looking for an entry that meets BeginAddress >= PC < EndAddress. Each table entry takes 12 bytes and only non-leaf functions with frame pointer needs an entry on the .pdata table. The result is that PE binaries will be ~0.7% bigger due to the unwind information, a reasonable amount considering the benefits in debuggability. Updates #57302 [1] https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-pdata-section [2] https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64#struct-runtime_function Change-Id: If675d10c64452946dbab76709da20569651e3e9f Reviewed-on: https://go-review.googlesource.com/c/go/+/461738 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-04-11runtime: filter i/o async entries using completion key on windowsWill Hawkins
In the case where a user program requests overlapped I/O directly on a handlethat is managed by the runtime, it is possible that runtime.netpoll will attempt to dereference a pointer with an invalid value. This CL prevents the runtime from accessing the invalid pointer value by adding a special key to each overlapped I/O operation that it creates. Fixes #58870 Co-authored-by: quimmuntal@gmail.com Change-Id: Ib58ee757bb5555efba24c29101fc6d1a0dedd61a Reviewed-on: https://go-review.googlesource.com/c/go/+/482495 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-28os: use GetTempPath2 on Windows if availableThanonchai W
This generates GetTempPath2. Go now tries to determine if the windows it runs on has GetTempPath2 by finding it only once at the loading time. If GetTempPath2 exists, it sets the flag so that any calls to tempDir will use it. If it doesn't exist, Go then uses GetTempPath. GetTempPath2 was generated into internal/syscall/windows since syscall is locked down. Fixes #56899 Change-Id: Iff08502aebc787fde802ee9496c070c982fbdc08 GitHub-Last-Rev: b77938953404b4e8e11f829c742e3eb109580c5e GitHub-Pull-Request: golang/go#57980 Reviewed-on: https://go-review.googlesource.com/c/go/+/463219 Run-TryBot: Quim Muntal <quimmuntal@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-01-24os: use handle based APIs to read directories on windowsqmuntal
This CL updates File.readdir() on windows so it uses GetFileInformationByHandleEx with FILE_ID_BOTH_DIR_INFO instead of Find* APIs. The former is more performant because it allows us to buffer IO calls and reduces the number of system calls, passing from 1 per file to 1 every ~100 files (depending on the size of the file name and the size of the buffer). This change improve performance of File.ReadDir by 20-30%. name old time/op new time/op delta ReadDir-12 562µs ±14% 385µs ± 9% -31.60% (p=0.000 n=9+9) name old alloc/op new alloc/op delta ReadDir-12 29.7kB ± 0% 29.5kB ± 0% -0.88% (p=0.000 n=8+10) name old allocs/op new allocs/op delta ReadDir-12 399 ± 0% 397 ± 0% -0.50% (p=0.000 n=10+10) This change also speeds up calls to os.SameFile when using FileStats returned from File.readdir(), as their file ID can be inferred while reading the directory. Change-Id: Id56a338ee66c39656b564105cac131099218fb5d Reviewed-on: https://go-review.googlesource.com/c/go/+/452995 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-09internal/syscall/windows: simplify unsafe.Slice usageCuong Manh Le
CL 428780 used unsafe.Slice instead of unsafeheader for simplifiying the code. However, it can be even simpler, since "p" is already a *uin16, the unsafe cast is not necessary. Change-Id: Idc492b73518637997e85c0b33f8591bd19b7929f Reviewed-on: https://go-review.googlesource.com/c/go/+/429915 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-09-09internal/syscall/windows: use unsafe.Slice instead of unsafeheader packageTobias Klauser
Follow CL 428777. Change-Id: I5ce49322e92c5d6539bb08248e3366187c30dcd8 Reviewed-on: https://go-review.googlesource.com/c/go/+/428780 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2022-08-20runtime/pprof: add memory mapping info for WindowsEgon Elbre
Fixes #43296 Change-Id: Ib277c2e82c95f71a7a9b7fe1b22215ead7a54a88 Reviewed-on: https://go-review.googlesource.com/c/go/+/416975 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Than McIntosh <thanm@google.com>
2022-06-03cmd/go: add functions to read index fileMichael Matloob
The data read is used for three primary functions: ImportPackage, IsDirWithGoFiles and ScanDir. Functions are also provided to get this information from the intermediate package representation to cache the information from reads for non-indexed packages. Change-Id: I5eed629bb0d6ee5b88ab706d06b074475004c081 Reviewed-on: https://go-review.googlesource.com/c/go/+/403975 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2022-04-04Revert "os: add handling of os.Interrupt for windows"Bryan Mills
This reverts CL 367495. Reason for revert: broke `x/tools` tests on Windows. Change-Id: Iab6b33259181c9520cf8db1e5b6edfeba763f974 Reviewed-on: https://go-review.googlesource.com/c/go/+/397997 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-04-03os: add handling of os.Interrupt for windowsConstantin Konstantinidis
Add GenerateConsoleCtrlEvent call to internal syscall package. Define ErrProcessDone while reviewing handling of os.Signal(). Update test to run for windows using the added call. Fixes #42311 Fixes #46354 Change-Id: I460955efc76c4febe04b612ac9a0670e62ba5ff3 Reviewed-on: https://go-review.googlesource.com/c/go/+/367495 Trust: Patrik Nyblom <pnyb@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-01-15syscall: remove RtlGenRandom and move it into internal/syscallJason A. Donenfeld
There's on need to expose this to the frozen syscall package, and it also doesn't need to be unsafe. So we move it into internal/syscall and have the generator make a safer function signature. Fixes #43704. Change-Id: Iccae69dc273a0aa97ee6846eb537f1dc1412f2de Reviewed-on: https://go-review.googlesource.com/c/go/+/283992 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com>