github.com/metacubex/mihomo@v1.18.5/.github/patch_go122/7c1157f9544922e96945196b47b95664b1e39108.diff (about) 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