From 2d20c80198a4c8f8853c5b6eb16dce780947b974 Mon Sep 17 00:00:00 2001 From: Steve Sanders Date: Tue, 30 Oct 2018 14:27:00 -0700 Subject: [PATCH 1/2] update vendored go-winio --- go/vendor/github.com/keybase/go-winio/file.go | 52 +++++++++++++++++-- go/vendor/vendor.json | 7 +++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/go/vendor/github.com/keybase/go-winio/file.go b/go/vendor/github.com/keybase/go-winio/file.go index 5ddbf7606b75..a0df1ceb5da8 100644 --- a/go/vendor/github.com/keybase/go-winio/file.go +++ b/go/vendor/github.com/keybase/go-winio/file.go @@ -10,6 +10,7 @@ import ( "sync/atomic" "syscall" "time" + "unsafe" ) //sys cancelIoEx(file syscall.Handle, o *syscall.Overlapped) (err error) = CancelIoEx @@ -17,6 +18,48 @@ import ( //sys getQueuedCompletionStatus(port syscall.Handle, bytes *uint32, key *uintptr, o **ioOperation, timeout uint32) (err error) = GetQueuedCompletionStatus //sys setFileCompletionNotificationModes(h syscall.Handle, flags uint8) (err error) = SetFileCompletionNotificationModes +// --- copied from https://golang.org/src/internal/poll/fd_windows.go --- +// This package uses the SetFileCompletionNotificationModes Windows +// API to skip calling GetQueuedCompletionStatus if an IO operation +// completes synchronously. There is a known bug where +// SetFileCompletionNotificationModes crashes on some systems (see +// https://support.microsoft.com/kb/2568167 for details). + +var useSetFileCompletionNotificationModes bool // determines is SetFileCompletionNotificationModes is present and safe to use + +// checkSetFileCompletionNotificationModes verifies that +// SetFileCompletionNotificationModes Windows API is present +// on the system and is safe to use. +// See https://support.microsoft.com/kb/2568167 for details. +func checkSetFileCompletionNotificationModes() { + err := syscall.LoadSetFileCompletionNotificationModes() + if err != nil { + return + } + protos := [2]int32{syscall.IPPROTO_TCP, 0} + var buf [32]syscall.WSAProtocolInfo + len := uint32(unsafe.Sizeof(buf)) + n, err := syscall.WSAEnumProtocols(&protos[0], &buf[0], &len) + if err != nil { + return + } + for i := int32(0); i < n; i++ { + if buf[i].ServiceFlags1&syscall.XP1_IFS_HANDLES == 0 { + return + } + } + useSetFileCompletionNotificationModes = true +} + +func initFileCompletionNotificationModes() { + var d syscall.WSAData + syscall.WSAStartup(uint32(0x202), &d) + + checkSetFileCompletionNotificationModes() +} + +// END --- copied from https://golang.org/src/internal/poll/fd_windows.go --- + type atomicBool int32 func (b *atomicBool) isSet() bool { return atomic.LoadInt32((*int32)(b)) != 0 } @@ -64,6 +107,7 @@ type ioOperation struct { } func initIo() { + initFileCompletionNotificationModes() h, err := createIoCompletionPort(syscall.InvalidHandle, 0, 0, 0xffffffff) if err != nil { panic(err) @@ -99,9 +143,11 @@ func makeWin32File(h syscall.Handle) (*win32File, error) { if err != nil { return nil, err } - err = setFileCompletionNotificationModes(h, cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS|cFILE_SKIP_SET_EVENT_ON_HANDLE) - if err != nil { - return nil, err + if useSetFileCompletionNotificationModes { + err = setFileCompletionNotificationModes(h, cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS|cFILE_SKIP_SET_EVENT_ON_HANDLE) + if err != nil { + return nil, err + } } f.readDeadline.channel = make(timeoutChan) f.writeDeadline.channel = make(timeoutChan) diff --git a/go/vendor/vendor.json b/go/vendor/vendor.json index 276625813c0a..ab733d4b7187 100644 --- a/go/vendor/vendor.json +++ b/go/vendor/vendor.json @@ -396,6 +396,13 @@ "revision": "2acca6d00b278821df4a39569955d8b42c77b6cc", "revisionTime": "2018-01-18T23:10:18Z" }, + { + "checksumSHA1": "3dP57YjvS8nVX6GMCgbA9fTSXKc=", + "origin": "github.com/keybase/client/go/vendor/github.com/keybase/go-winio", + "path": "github.com/keybase/go-winio", + "revision": "41191563760e6b6b3374d77fc0a3b1cb58094433", + "revisionTime": "2018-10-30T21:08:04Z" + }, { "checksumSHA1": "0g+4y2vw5URLtwp0YZLoRYDymkg=", "path": "github.com/keybase/keybase-test-vectors/go", From 69aa394c1469c016eecc477748b90dadfeb84617 Mon Sep 17 00:00:00 2001 From: Steve Sanders Date: Wed, 31 Oct 2018 13:40:01 -0700 Subject: [PATCH 2/2] use master of github.com/keybase/go-winio --- go/vendor/vendor.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/go/vendor/vendor.json b/go/vendor/vendor.json index ab733d4b7187..fcc577c8cba1 100644 --- a/go/vendor/vendor.json +++ b/go/vendor/vendor.json @@ -398,10 +398,9 @@ }, { "checksumSHA1": "3dP57YjvS8nVX6GMCgbA9fTSXKc=", - "origin": "github.com/keybase/client/go/vendor/github.com/keybase/go-winio", "path": "github.com/keybase/go-winio", - "revision": "41191563760e6b6b3374d77fc0a3b1cb58094433", - "revisionTime": "2018-10-30T21:08:04Z" + "revision": "0903bf878a72fe2b9d1459d43026e3e8a3a02d46", + "revisionTime": "2018-10-31T20:34:17Z" }, { "checksumSHA1": "0g+4y2vw5URLtwp0YZLoRYDymkg=",