aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-11-21 16:16:56 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-12-16 17:37:20 +0000
commit056a3d1c6f6f92b095f88b01d004eb2656a688c5 (patch)
treec1a9b84a45ff37306f4c8e898c1b052cc70476e7
parent499dc1c5d583a2a0735d4e408078819b84697e2e (diff)
downloadgo-056a3d1c6f6f92b095f88b01d004eb2656a688c5.tar.gz
go-056a3d1c6f6f92b095f88b01d004eb2656a688c5.zip
runtime: do not use PowerRegisterSuspendResumeNotification on systems with "program time" timer
Systems where PowerRegisterSuspendResumeNotification returns ERROR_ FILE_NOT_FOUND are also systems where nanotime() is on "program time" rather than "real time". The chain for this is: powrprof.dll!PowerRegisterSuspendResumeNotification -> umpdc.dll!PdcPortOpen -> ntdll.dll!ZwAlpcConnectPort("\\PdcPort") -> syscall -> ntoskrnl.exe!AlpcpConnectPort Opening \\.\PdcPort fails with STATUS_OBJECT_NAME_NOT_FOUND when pdc.sys hasn't been initialized. Pdc.sys also provides the various hooks for sleep resumption events, which means if it's not loaded, then our "real time" timer is actually on "program time". Finally STATUS_OBJECT_NAME_ NOT_FOUND is passed through RtlNtStatusToDosError, which returns ERROR_ FILE_NOT_FOUND. Therefore, in the case where the function returns ERROR_ FILE_NOT_FOUND, we don't mind, since the timer we're using will correspond fine with the lack of sleep resumption notifications. This applies, for example, to Docker users. Fixes #35447 Fixes #35482 Change-Id: I9e1ce5bbc54b9da55ff7a3918b5da28112647eee Reviewed-on: https://go-review.googlesource.com/c/go/+/208317 Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/runtime/os_windows.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go
index cf5837c1f0..4b590aa9ef 100644
--- a/src/runtime/os_windows.go
+++ b/src/runtime/os_windows.go
@@ -270,7 +270,10 @@ func loadOptionalSyscalls() {
}
func monitorSuspendResume() {
- const _DEVICE_NOTIFY_CALLBACK = 2
+ const (
+ _DEVICE_NOTIFY_CALLBACK = 2
+ _ERROR_FILE_NOT_FOUND = 2
+ )
type _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS struct {
callback uintptr
context uintptr
@@ -296,10 +299,20 @@ func monitorSuspendResume() {
callback: compileCallback(*efaceOf(&fn), true),
}
handle := uintptr(0)
- if stdcall3(powerRegisterSuspendResumeNotification, _DEVICE_NOTIFY_CALLBACK,
- uintptr(unsafe.Pointer(&params)),
- uintptr(unsafe.Pointer(&handle))) != 0 {
- throw("PowerRegisterSuspendResumeNotification failure")
+ ret := stdcall3(powerRegisterSuspendResumeNotification, _DEVICE_NOTIFY_CALLBACK,
+ uintptr(unsafe.Pointer(&params)), uintptr(unsafe.Pointer(&handle)))
+ // This function doesn't use GetLastError(), so we use the return value directly.
+ switch ret {
+ case 0:
+ return // Successful, nothing more to do.
+ case _ERROR_FILE_NOT_FOUND:
+ // Systems without access to the suspend/resume notifier
+ // also have their clock on "program time", and therefore
+ // don't want or need this anyway.
+ return
+ default:
+ println("runtime: PowerRegisterSuspendResumeNotification failed with errno=", ret)
+ throw("runtime: PowerRegisterSuspendResumeNotification failure")
}
}