mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-21 10:27:30 +00:00
ipn/desktop: fix panics on Windows 10, x86
[G,S]etWindowLongPtrW are not available on 32-bit Windows, where [G,S]etWindowLongW should be used instead. The initial revision of #14945 imported the win package for calling and other Win32 API functions, which exported the correct API depending on the platform. However, the same logic wasn't implemented when we removed the win package dependency in a later revision, resulting in panics on Windows 10 x86 (there's no 32-bit Windows 11). In this PR, we update the ipn/desktop package to use either [G,S]etWindowLongPtrW or [G,S]etWindowLongW depending on the platform. Fixes #15684 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -670,3 +670,38 @@ func (cs _WTS_CONNECTSTATE_CLASS) ToSessionStatus() SessionStatus {
|
||||
return ClosedSession
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
procGetWindowLongPtrW *windows.LazyProc
|
||||
procSetWindowLongPtrW *windows.LazyProc
|
||||
)
|
||||
|
||||
func init() {
|
||||
// GetWindowLongPtrW and SetWindowLongPtrW are only available on 64-bit platforms.
|
||||
// https://web.archive.org/web/20250414195520/https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptrw
|
||||
if runtime.GOARCH == "386" || runtime.GOARCH == "arm" {
|
||||
procGetWindowLongPtrW = moduser32.NewProc("GetWindowLongW")
|
||||
procSetWindowLongPtrW = moduser32.NewProc("SetWindowLongW")
|
||||
} else {
|
||||
procGetWindowLongPtrW = moduser32.NewProc("GetWindowLongPtrW")
|
||||
procSetWindowLongPtrW = moduser32.NewProc("SetWindowLongPtrW")
|
||||
}
|
||||
}
|
||||
|
||||
func getWindowLongPtr(hwnd windows.HWND, index int32) (res uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall(procGetWindowLongPtrW.Addr(), 2, uintptr(hwnd), uintptr(index), 0)
|
||||
res = uintptr(r0)
|
||||
if res == 0 && e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setWindowLongPtr(hwnd windows.HWND, index int32, newLong uintptr) (res uintptr, err error) {
|
||||
r0, _, e1 := syscall.Syscall(procSetWindowLongPtrW.Addr(), 3, uintptr(hwnd), uintptr(index), uintptr(newLong))
|
||||
res = uintptr(r0)
|
||||
if res == 0 && e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user