Skip to content

Commit

Permalink
[release-branch.go1.13] runtime: ignore error returned by PowerRegist…
Browse files Browse the repository at this point in the history
…erSuspendResumeNotification

It appears that PowerRegisterSuspendResumeNotification is not supported
when running inside Docker - see issues #35447, #36557 and #37149.

Our current code relies on error number to determine Docker environment.
But we already saw PowerRegisterSuspendResumeNotification return
ERROR_FILE_NOT_FOUND, ERROR_INVALID_PARAMETERS and ERROR_ACCESS_DENIED
(see issues above). So this approach is not sustainable.

Just ignore PowerRegisterSuspendResumeNotification returned error.

For #37149
Fixes #37230

Change-Id: I2beba9d45cdb8c1efac5e974e747827a6261915a
Reviewed-on: https://go-review.googlesource.com/c/go/+/219657
Run-TryBot: Alex Brainman <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
Reviewed-by: Jason A. Donenfeld <[email protected]>
(cherry picked from commit d467f3b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/224585
Run-TryBot: Ian Lance Taylor <[email protected]>
  • Loading branch information
alexbrainman authored and ianlancetaylor committed Mar 25, 2020
1 parent 33554bc commit d6224d3
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/runtime/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ func loadOptionalSyscalls() {

func monitorSuspendResume() {
const (
_DEVICE_NOTIFY_CALLBACK = 2
_ERROR_FILE_NOT_FOUND = 2
_ERROR_INVALID_PARAMETERS = 87
_DEVICE_NOTIFY_CALLBACK = 2
)
type _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS struct {
callback uintptr
Expand All @@ -292,25 +290,8 @@ func monitorSuspendResume() {
callback: compileCallback(*efaceOf(&fn), true),
}
handle := uintptr(0)
ret := stdcall3(powerRegisterSuspendResumeNotification, _DEVICE_NOTIFY_CALLBACK,
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
case _ERROR_INVALID_PARAMETERS:
// This is seen when running in Windows Docker.
// See issue 36557.
return
default:
println("runtime: PowerRegisterSuspendResumeNotification failed with errno=", ret)
throw("runtime: PowerRegisterSuspendResumeNotification failure")
}
}

//go:nosplit
Expand Down

0 comments on commit d6224d3

Please sign in to comment.