Skip to content

Commit ed1e7e3

Browse files
committed
action: revert more golang1.22 commit for win7
1 parent 5da9cca commit ed1e7e3

4 files changed

+237
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
2+
index 06e684c7116b4..b311a5c74684b 100644
3+
--- a/src/syscall/exec_windows.go
4+
+++ b/src/syscall/exec_windows.go
5+
@@ -319,17 +319,6 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
6+
}
7+
}
8+
9+
- var maj, min, build uint32
10+
- rtlGetNtVersionNumbers(&maj, &min, &build)
11+
- isWin7 := maj < 6 || (maj == 6 && min <= 1)
12+
- // NT kernel handles are divisible by 4, with the bottom 3 bits left as
13+
- // a tag. The fully set tag correlates with the types of handles we're
14+
- // concerned about here. Except, the kernel will interpret some
15+
- // special handle values, like -1, -2, and so forth, so kernelbase.dll
16+
- // checks to see that those bottom three bits are checked, but that top
17+
- // bit is not checked.
18+
- isLegacyWin7ConsoleHandle := func(handle Handle) bool { return isWin7 && handle&0x10000003 == 3 }
19+
-
20+
p, _ := GetCurrentProcess()
21+
parentProcess := p
22+
if sys.ParentProcess != 0 {
23+
@@ -338,15 +327,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
24+
fd := make([]Handle, len(attr.Files))
25+
for i := range attr.Files {
26+
if attr.Files[i] > 0 {
27+
- destinationProcessHandle := parentProcess
28+
-
29+
- // On Windows 7, console handles aren't real handles, and can only be duplicated
30+
- // into the current process, not a parent one, which amounts to the same thing.
31+
- if parentProcess != p && isLegacyWin7ConsoleHandle(Handle(attr.Files[i])) {
32+
- destinationProcessHandle = p
33+
- }
34+
-
35+
- err := DuplicateHandle(p, Handle(attr.Files[i]), destinationProcessHandle, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
36+
+ err := DuplicateHandle(p, Handle(attr.Files[i]), parentProcess, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
37+
if err != nil {
38+
return 0, 0, err
39+
}
40+
@@ -377,14 +358,6 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
41+
42+
fd = append(fd, sys.AdditionalInheritedHandles...)
43+
44+
- // On Windows 7, console handles aren't real handles, so don't pass them
45+
- // through to PROC_THREAD_ATTRIBUTE_HANDLE_LIST.
46+
- for i := range fd {
47+
- if isLegacyWin7ConsoleHandle(fd[i]) {
48+
- fd[i] = 0
49+
- }
50+
- }
51+
-
52+
// The presence of a NULL handle in the list is enough to cause PROC_THREAD_ATTRIBUTE_HANDLE_LIST
53+
// to treat the entire list as empty, so remove NULL handles.
54+
j := 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
diff --git a/src/net/hook_windows.go b/src/net/hook_windows.go
2+
index ab8656cbbf343..28c49cc6de7e7 100644
3+
--- a/src/net/hook_windows.go
4+
+++ b/src/net/hook_windows.go
5+
@@ -14,7 +14,6 @@ var (
6+
testHookDialChannel = func() { time.Sleep(time.Millisecond) } // see golang.org/issue/5349
7+
8+
// Placeholders for socket system calls.
9+
- socketFunc func(int, int, int) (syscall.Handle, error) = syscall.Socket
10+
wsaSocketFunc func(int32, int32, int32, *syscall.WSAProtocolInfo, uint32, uint32) (syscall.Handle, error) = windows.WSASocket
11+
connectFunc func(syscall.Handle, syscall.Sockaddr) error = syscall.Connect
12+
listenFunc func(syscall.Handle, int) error = syscall.Listen
13+
diff --git a/src/net/internal/socktest/main_test.go b/src/net/internal/socktest/main_test.go
14+
index 0197feb3f199a..967ce6795aedb 100644
15+
--- a/src/net/internal/socktest/main_test.go
16+
+++ b/src/net/internal/socktest/main_test.go
17+
@@ -2,7 +2,7 @@
18+
// Use of this source code is governed by a BSD-style
19+
// license that can be found in the LICENSE file.
20+
21+
-//go:build !js && !plan9 && !wasip1
22+
+//go:build !js && !plan9 && !wasip1 && !windows
23+
24+
package socktest_test
25+
26+
diff --git a/src/net/internal/socktest/main_windows_test.go b/src/net/internal/socktest/main_windows_test.go
27+
deleted file mode 100644
28+
index df1cb97784b51..0000000000000
29+
--- a/src/net/internal/socktest/main_windows_test.go
30+
+++ /dev/null
31+
@@ -1,22 +0,0 @@
32+
-// Copyright 2015 The Go Authors. All rights reserved.
33+
-// Use of this source code is governed by a BSD-style
34+
-// license that can be found in the LICENSE file.
35+
-
36+
-package socktest_test
37+
-
38+
-import "syscall"
39+
-
40+
-var (
41+
- socketFunc func(int, int, int) (syscall.Handle, error)
42+
- closeFunc func(syscall.Handle) error
43+
-)
44+
-
45+
-func installTestHooks() {
46+
- socketFunc = sw.Socket
47+
- closeFunc = sw.Closesocket
48+
-}
49+
-
50+
-func uninstallTestHooks() {
51+
- socketFunc = syscall.Socket
52+
- closeFunc = syscall.Closesocket
53+
-}
54+
diff --git a/src/net/internal/socktest/sys_windows.go b/src/net/internal/socktest/sys_windows.go
55+
index 8c1c862f33c9b..1c42e5c7f34b7 100644
56+
--- a/src/net/internal/socktest/sys_windows.go
57+
+++ b/src/net/internal/socktest/sys_windows.go
58+
@@ -9,38 +9,6 @@ import (
59+
"syscall"
60+
)
61+
62+
-// Socket wraps syscall.Socket.
63+
-func (sw *Switch) Socket(family, sotype, proto int) (s syscall.Handle, err error) {
64+
- sw.once.Do(sw.init)
65+
-
66+
- so := &Status{Cookie: cookie(family, sotype, proto)}
67+
- sw.fmu.RLock()
68+
- f, _ := sw.fltab[FilterSocket]
69+
- sw.fmu.RUnlock()
70+
-
71+
- af, err := f.apply(so)
72+
- if err != nil {
73+
- return syscall.InvalidHandle, err
74+
- }
75+
- s, so.Err = syscall.Socket(family, sotype, proto)
76+
- if err = af.apply(so); err != nil {
77+
- if so.Err == nil {
78+
- syscall.Closesocket(s)
79+
- }
80+
- return syscall.InvalidHandle, err
81+
- }
82+
-
83+
- sw.smu.Lock()
84+
- defer sw.smu.Unlock()
85+
- if so.Err != nil {
86+
- sw.stats.getLocked(so.Cookie).OpenFailed++
87+
- return syscall.InvalidHandle, so.Err
88+
- }
89+
- nso := sw.addLocked(s, family, sotype, proto)
90+
- sw.stats.getLocked(nso.Cookie).Opened++
91+
- return s, nil
92+
-}
93+
-
94+
// WSASocket wraps [syscall.WSASocket].
95+
func (sw *Switch) WSASocket(family, sotype, proto int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (s syscall.Handle, err error) {
96+
sw.once.Do(sw.init)
97+
diff --git a/src/net/main_windows_test.go b/src/net/main_windows_test.go
98+
index 07f21b72eb1fc..bc024c0bbd82d 100644
99+
--- a/src/net/main_windows_test.go
100+
+++ b/src/net/main_windows_test.go
101+
@@ -8,7 +8,6 @@ import "internal/poll"
102+
103+
var (
104+
// Placeholders for saving original socket system calls.
105+
- origSocket = socketFunc
106+
origWSASocket = wsaSocketFunc
107+
origClosesocket = poll.CloseFunc
108+
origConnect = connectFunc
109+
@@ -18,7 +17,6 @@ var (
110+
)
111+
112+
func installTestHooks() {
113+
- socketFunc = sw.Socket
114+
wsaSocketFunc = sw.WSASocket
115+
poll.CloseFunc = sw.Closesocket
116+
connectFunc = sw.Connect
117+
@@ -28,7 +26,6 @@ func installTestHooks() {
118+
}
119+
120+
func uninstallTestHooks() {
121+
- socketFunc = origSocket
122+
wsaSocketFunc = origWSASocket
123+
poll.CloseFunc = origClosesocket
124+
connectFunc = origConnect
125+
diff --git a/src/net/sock_windows.go b/src/net/sock_windows.go
126+
index fa11c7af2e727..5540135a2c43e 100644
127+
--- a/src/net/sock_windows.go
128+
+++ b/src/net/sock_windows.go
129+
@@ -19,21 +19,6 @@ func maxListenerBacklog() int {
130+
func sysSocket(family, sotype, proto int) (syscall.Handle, error) {
131+
s, err := wsaSocketFunc(int32(family), int32(sotype), int32(proto),
132+
nil, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
133+
- if err == nil {
134+
- return s, nil
135+
- }
136+
- // WSA_FLAG_NO_HANDLE_INHERIT flag is not supported on some
137+
- // old versions of Windows, see
138+
- // https://msdn.microsoft.com/en-us/library/windows/desktop/ms742212(v=vs.85).aspx
139+
- // for details. Just use syscall.Socket, if windows.WSASocket failed.
140+
-
141+
- // See ../syscall/exec_unix.go for description of ForkLock.
142+
- syscall.ForkLock.RLock()
143+
- s, err = socketFunc(family, sotype, proto)
144+
- if err == nil {
145+
- syscall.CloseOnExec(s)
146+
- }
147+
- syscall.ForkLock.RUnlock()
148+
if err != nil {
149+
return syscall.InvalidHandle, os.NewSyscallError("socket", err)
150+
}
151+
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
152+
index 0a93bc0a80d4e..06e684c7116b4 100644
153+
--- a/src/syscall/exec_windows.go
154+
+++ b/src/syscall/exec_windows.go
155+
@@ -14,6 +14,7 @@ import (
156+
"unsafe"
157+
)
158+
159+
+// ForkLock is not used on Windows.
160+
var ForkLock sync.RWMutex
161+
162+
// EscapeArg rewrites command line argument s as prescribed

.github/workflows/build.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ jobs:
6464
- { goos: android, goarch: arm, ndk: armv7a-linux-androideabi34, output: armv7 }
6565
- { goos: android, goarch: arm64, ndk: aarch64-linux-android34, output: arm64-v8 }
6666

67+
# Go 1.21 can revert commit `9e4385` to work on Windows 7
68+
# https://github.com/golang/go/issues/64622#issuecomment-1847475161
69+
# (OR we can just use golang1.21.4 which unneeded any patch)
70+
- { goos: windows, goarch: '386', output: '386-go121', goversion: '1.21' }
71+
- { goos: windows, goarch: amd64, goamd64: v1, output: amd64-compatible-go121, goversion: '1.21' }
72+
- { goos: windows, goarch: amd64, goamd64: v3, output: amd64-go121, goversion: '1.21' }
73+
6774
# Go 1.20 is the last release that will run on any release of Windows 7, 8, Server 2008 and Server 2012. Go 1.21 will require at least Windows 10 or Server 2016.
6875
- { goos: windows, goarch: '386', output: '386-go120', goversion: '1.20' }
6976
- { goos: windows, goarch: amd64, goamd64: v1, output: amd64-compatible-go120, goversion: '1.20' }
@@ -111,11 +118,24 @@ jobs:
111118
# modify from https://github.com/restic/restic/issues/4636#issuecomment-1896455557
112119
# this patch file only works on golang1.22.x
113120
# that means after golang1.23 release it must be changed
121+
# revert:
122+
# 693def151adff1af707d82d28f55dba81ceb08e1: "crypto/rand,runtime: switch RtlGenRandom for ProcessPrng"
123+
# 7c1157f9544922e96945196b47b95664b1e39108: "net: remove sysSocket fallback for Windows 7"
124+
# 48042aa09c2f878c4faa576948b07fe625c4707a: "syscall: remove Windows 7 console handle workaround"
114125
- name: Revert Golang1.22 commit for Windows7/8
115126
if: ${{ matrix.jobs.goos == 'windows' && matrix.jobs.goversion == '' }}
116127
run: |
117128
cd $(go env GOROOT)
118-
patch --verbose -R -p 1 < $GITHUB_WORKSPACE/.github/693def151adff1af707d82d28f55dba81ceb08e1.diff
129+
patch --verbose -R -p 1 < $GITHUB_WORKSPACE/.github/patch_go122/693def151adff1af707d82d28f55dba81ceb08e1.diff
130+
patch --verbose -R -p 1 < $GITHUB_WORKSPACE/.github/patch_go122/7c1157f9544922e96945196b47b95664b1e39108.diff
131+
patch --verbose -R -p 1 < $GITHUB_WORKSPACE/.github/patch_go122/48042aa09c2f878c4faa576948b07fe625c4707a.diff
132+
133+
# modify from https://github.com/restic/restic/issues/4636#issuecomment-1896455557
134+
- name: Revert Golang1.21 commit for Windows7/8
135+
if: ${{ matrix.jobs.goos == 'windows' && matrix.jobs.goversion == '1.21' }}
136+
run: |
137+
cd $(go env GOROOT)
138+
curl https://github.com/golang/go/commit/9e43850a3298a9b8b1162ba0033d4c53f8637571.diff | patch --verbose -R -p 1
119139
120140
- name: Set variables
121141
if: ${{github.ref_name=='Alpha'}}

0 commit comments

Comments
 (0)