diff --git a/windows/svc/service.go b/windows/svc/service.go index 806baa055..023ace2e7 100644 --- a/windows/svc/service.go +++ b/windows/svc/service.go @@ -10,6 +10,7 @@ package svc import ( "errors" + "runtime/cgo" "sync" "unsafe" @@ -192,7 +193,7 @@ var ( ) func ctlHandler(ctl, evtype, evdata, context uintptr) uintptr { - s := (*service)(unsafe.Pointer(context)) + s := cgo.Handle(context).Value().(service) e := ctlEvent{cmd: Cmd(ctl), eventType: uint32(evtype), eventData: evdata, context: 123456} // Set context to 123456 to test issue #25660. s.c <- e return 0 @@ -203,7 +204,7 @@ var theService service // This is, unfortunately, a global, which means only one // serviceMain is the entry point called by the service manager, registered earlier by // the call to StartServiceCtrlDispatcher. func serviceMain(argc uint32, argv **uint16) uintptr { - handle, err := windows.RegisterServiceCtrlHandlerEx(windows.StringToUTF16Ptr(theService.name), ctlHandlerCallback, uintptr(unsafe.Pointer(&theService))) + handle, err := windows.RegisterServiceCtrlHandlerEx(windows.StringToUTF16Ptr(theService.name), ctlHandlerCallback, uintptr(cgo.NewHandle(theService))) if sysErr, ok := err.(windows.Errno); ok { return uintptr(sysErr) } else if err != nil {