From 68ca83f2f8260b20ec7d6875ecb610417bf48f50 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 9 Mar 2026 14:19:23 +0800 Subject: [PATCH] fix: windows crash for golang1.26 on WSARecvFrom syscall --- .../{cl747663.patch => issue77731.patch} | 0 .github/patch/issue77975.patch | 55 +++++++++++++++++++ .github/workflows/build.yml | 13 ++++- .github/workflows/test.yml | 7 +++ 4 files changed, 72 insertions(+), 3 deletions(-) rename .github/patch/{cl747663.patch => issue77731.patch} (100%) create mode 100644 .github/patch/issue77975.patch diff --git a/.github/patch/cl747663.patch b/.github/patch/issue77731.patch similarity index 100% rename from .github/patch/cl747663.patch rename to .github/patch/issue77731.patch diff --git a/.github/patch/issue77975.patch b/.github/patch/issue77975.patch new file mode 100644 index 00000000..64079e2b --- /dev/null +++ b/.github/patch/issue77975.patch @@ -0,0 +1,55 @@ +Subject: [PATCH] move lpFromlen to heap for WSARecvFrom syscall +--- +Index: src/internal/poll/fd_windows.go +IDEA additional info: +Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP +<+>UTF-8 +=================================================================== +diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go +--- a/src/internal/poll/fd_windows.go (revision 8149d992682ce76c6af804b507878e19fc966f7b) ++++ b/src/internal/poll/fd_windows.go (revision 25efab96145f416bbae4024e9c110429770b22d1) +@@ -76,6 +76,8 @@ + // fields used by runtime.netpoll + runtimeCtx uintptr + mode int32 ++ ++ rsan int32 + } + + func (fd *FD) overlapped(o *operation) *syscall.Overlapped { +@@ -740,9 +742,9 @@ + rsa := wsaRsaPool.Get().(*syscall.RawSockaddrAny) + defer wsaRsaPool.Put(rsa) + n, err := fd.execIO('r', func(o *operation) (qty uint32, err error) { +- rsan := int32(unsafe.Sizeof(*rsa)) ++ o.rsan = int32(unsafe.Sizeof(*rsa)) + var flags uint32 +- err = syscall.WSARecvFrom(fd.Sysfd, newWsaBuf(buf), 1, &qty, &flags, rsa, &rsan, &o.o, nil) ++ err = syscall.WSARecvFrom(fd.Sysfd, newWsaBuf(buf), 1, &qty, &flags, rsa, &o.rsan, &o.o, nil) + return qty, err + }) + err = fd.eofError(n, err) +@@ -771,9 +773,9 @@ + rsa := wsaRsaPool.Get().(*syscall.RawSockaddrAny) + defer wsaRsaPool.Put(rsa) + n, err := fd.execIO('r', func(o *operation) (qty uint32, err error) { +- rsan := int32(unsafe.Sizeof(*rsa)) ++ o.rsan = int32(unsafe.Sizeof(*rsa)) + var flags uint32 +- err = syscall.WSARecvFrom(fd.Sysfd, newWsaBuf(buf), 1, &qty, &flags, rsa, &rsan, &o.o, nil) ++ err = syscall.WSARecvFrom(fd.Sysfd, newWsaBuf(buf), 1, &qty, &flags, rsa, &o.rsan, &o.o, nil) + return qty, err + }) + err = fd.eofError(n, err) +@@ -802,9 +804,9 @@ + rsa := wsaRsaPool.Get().(*syscall.RawSockaddrAny) + defer wsaRsaPool.Put(rsa) + n, err := fd.execIO('r', func(o *operation) (qty uint32, err error) { +- rsan := int32(unsafe.Sizeof(*rsa)) ++ o.rsan = int32(unsafe.Sizeof(*rsa)) + var flags uint32 +- err = syscall.WSARecvFrom(fd.Sysfd, newWsaBuf(buf), 1, &qty, &flags, rsa, &rsan, &o.o, nil) ++ err = syscall.WSARecvFrom(fd.Sysfd, newWsaBuf(buf), 1, &qty, &flags, rsa, &o.rsan, &o.o, nil) + return qty, err + }) + err = fd.eofError(n, err) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5b55fd6..48ef8d5f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -179,12 +179,19 @@ jobs: tar zxf go1.26.0.linux-amd64-abi1.tar.gz -C $HOME/usr/local echo "$HOME/usr/local/go/bin" >> $GITHUB_PATH - # TODO: remove after CL747663 merged, see: https://github.com/golang/go/issues/77731 - - name: Apply CL747663 for Golang1.26 + # TODO: remove after issue77731 merged, see: https://github.com/golang/go/issues/77731 + - name: Apply issue77731 for Golang1.26 if: ${{ matrix.jobs.goversion == '' }} run: | cd $(go env GOROOT) - patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/patch/cl747663.patch + patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/patch/issue77731.patch + + # TODO: remove after issue77975 fixed, see: https://github.com/golang/go/issues/77975 + - name: Fix issue77975 for Golang1.26 + if: ${{ matrix.jobs.goversion == '' }} + run: | + cd $(go env GOROOT) + patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/patch/issue77975.patch # this patch file only works on golang1.26.x # that means after golang1.27 release it must be changed diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 064507bc..052ee965 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,6 +50,13 @@ jobs: go-version: ${{ matrix.go-version }} check-latest: true # Always check for the latest patch release + # TODO: remove after issue77975 fixed, see: https://github.com/golang/go/issues/77975 + - name: Fix issue77975 for Golang1.26 + if: ${{ matrix.jobs.goversion == '1.26' }} + run: | + cd $(go env GOROOT) + patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/patch/issue77975.patch + - name: Revert Golang commit for Windows7/8 if: ${{ runner.os == 'Windows' && matrix.go-version != '1.20' }} run: |