Skip to content

Commit b570a41

Browse files
zx2c4dmitshur
authored andcommitted
[release-branch.go1.13] 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. Updates #35447 Updates #35482 Fixes #35746 Change-Id: I9e1ce5bbc54b9da55ff7a3918b5da28112647eee Reviewed-on: https://go-review.googlesource.com/c/go/+/211280 Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Jason A. Donenfeld <[email protected]>
1 parent b0a2a81 commit b570a41

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/runtime/os_windows.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ func loadOptionalSyscalls() {
262262
}
263263

264264
func monitorSuspendResume() {
265-
const _DEVICE_NOTIFY_CALLBACK = 2
265+
const (
266+
_DEVICE_NOTIFY_CALLBACK = 2
267+
_ERROR_FILE_NOT_FOUND = 2
268+
)
266269
type _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS struct {
267270
callback uintptr
268271
context uintptr
@@ -288,10 +291,20 @@ func monitorSuspendResume() {
288291
callback: compileCallback(*efaceOf(&fn), true),
289292
}
290293
handle := uintptr(0)
291-
if stdcall3(powerRegisterSuspendResumeNotification, _DEVICE_NOTIFY_CALLBACK,
292-
uintptr(unsafe.Pointer(&params)),
293-
uintptr(unsafe.Pointer(&handle))) != 0 {
294-
throw("PowerRegisterSuspendResumeNotification failure")
294+
ret := stdcall3(powerRegisterSuspendResumeNotification, _DEVICE_NOTIFY_CALLBACK,
295+
uintptr(unsafe.Pointer(&params)), uintptr(unsafe.Pointer(&handle)))
296+
// This function doesn't use GetLastError(), so we use the return value directly.
297+
switch ret {
298+
case 0:
299+
return // Successful, nothing more to do.
300+
case _ERROR_FILE_NOT_FOUND:
301+
// Systems without access to the suspend/resume notifier
302+
// also have their clock on "program time", and therefore
303+
// don't want or need this anyway.
304+
return
305+
default:
306+
println("runtime: PowerRegisterSuspendResumeNotification failed with errno=", ret)
307+
throw("runtime: PowerRegisterSuspendResumeNotification failure")
295308
}
296309
}
297310

0 commit comments

Comments
 (0)