Swap usage of LazyDLL and LoadDLL to LazySystemDLL.
Signed-off-by: Darren Stahl <darst@microsoft.com>
(cherry picked from commit 22c83c567f
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
f9f8a94f42
commit
00fd466e00
8 changed files with 30 additions and 35 deletions
|
@ -27,7 +27,7 @@ var (
|
|||
flUnregisterService *bool
|
||||
flRunService *bool
|
||||
|
||||
setStdHandle = syscall.NewLazyDLL("kernel32.dll").NewProc("SetStdHandle")
|
||||
setStdHandle = windows.NewLazySystemDLL("kernel32.dll").NewProc("SetStdHandle")
|
||||
oldStderr syscall.Handle
|
||||
panicFile *os.File
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ import (
|
|||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/longpath"
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/docker/go-units"
|
||||
units "github.com/docker/go-units"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// filterDriver is an HCSShim driver type for the Windows Filter driver.
|
||||
|
@ -115,7 +116,7 @@ func win32FromHresult(hr uintptr) uintptr {
|
|||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
|
||||
func getFileSystemType(drive string) (fsType string, hr error) {
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
procGetVolumeInformation = modkernel32.NewProc("GetVolumeInformationW")
|
||||
buf = make([]uint16, 255)
|
||||
size = syscall.MAX_PATH + 1
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
type etwLogs struct {
|
||||
|
@ -35,7 +36,12 @@ const (
|
|||
win32CallSuccess = 0
|
||||
)
|
||||
|
||||
var win32Lib *syscall.DLL
|
||||
var (
|
||||
modAdvapi32 = windows.NewLazySystemDLL("Advapi32.dll")
|
||||
procEventRegister = modAdvapi32.NewProc("EventRegister")
|
||||
procEventWriteString = modAdvapi32.NewProc("EventWriteString")
|
||||
procEventUnregister = modAdvapi32.NewProc("EventUnregister")
|
||||
)
|
||||
var providerHandle syscall.Handle
|
||||
var refCount int
|
||||
var mu sync.Mutex
|
||||
|
@ -106,12 +112,7 @@ func registerETWProvider() error {
|
|||
defer mu.Unlock()
|
||||
if refCount == 0 {
|
||||
var err error
|
||||
if win32Lib, err = syscall.LoadDLL("Advapi32.dll"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = callEventRegister(); err != nil {
|
||||
win32Lib.Release()
|
||||
win32Lib = nil
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -127,8 +128,6 @@ func unregisterETWProvider() {
|
|||
if callEventUnregister() {
|
||||
refCount--
|
||||
providerHandle = syscall.InvalidHandle
|
||||
win32Lib.Release()
|
||||
win32Lib = nil
|
||||
}
|
||||
// Not returning an error if EventUnregister fails, because etwLogs will continue to work
|
||||
} else {
|
||||
|
@ -137,17 +136,13 @@ func unregisterETWProvider() {
|
|||
}
|
||||
|
||||
func callEventRegister() error {
|
||||
proc, err := win32Lib.FindProc("EventRegister")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// The provider's GUID is {a3693192-9ed6-46d2-a981-f8226c8363bd}
|
||||
guid := syscall.GUID{
|
||||
0xa3693192, 0x9ed6, 0x46d2,
|
||||
[8]byte{0xa9, 0x81, 0xf8, 0x22, 0x6c, 0x83, 0x63, 0xbd},
|
||||
}
|
||||
|
||||
ret, _, _ := proc.Call(uintptr(unsafe.Pointer(&guid)), 0, 0, uintptr(unsafe.Pointer(&providerHandle)))
|
||||
ret, _, _ := procEventRegister.Call(uintptr(unsafe.Pointer(&guid)), 0, 0, uintptr(unsafe.Pointer(&providerHandle)))
|
||||
if ret != win32CallSuccess {
|
||||
errorMessage := fmt.Sprintf("Failed to register ETW provider. Error: %d", ret)
|
||||
logrus.Error(errorMessage)
|
||||
|
@ -157,11 +152,7 @@ func callEventRegister() error {
|
|||
}
|
||||
|
||||
func callEventWriteString(message string) error {
|
||||
proc, err := win32Lib.FindProc("EventWriteString")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ret, _, _ := proc.Call(uintptr(providerHandle), 0, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(message))))
|
||||
ret, _, _ := procEventWriteString.Call(uintptr(providerHandle), 0, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(message))))
|
||||
if ret != win32CallSuccess {
|
||||
errorMessage := fmt.Sprintf("ETWLogs provider failed to log message. Error: %d", ret)
|
||||
logrus.Error(errorMessage)
|
||||
|
@ -171,11 +162,7 @@ func callEventWriteString(message string) error {
|
|||
}
|
||||
|
||||
func callEventUnregister() bool {
|
||||
proc, err := win32Lib.FindProc("EventUnregister")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ret, _, _ := proc.Call(uintptr(providerHandle))
|
||||
ret, _, _ := procEventUnregister.Call(uintptr(providerHandle))
|
||||
if ret != win32CallSuccess {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@ import (
|
|||
"unsafe"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func openEvent(desiredAccess uint32, inheritHandle bool, name string, proc *syscall.LazyProc) (handle syscall.Handle, err error) {
|
||||
func openEvent(desiredAccess uint32, inheritHandle bool, name string, proc *windows.LazyProc) (handle syscall.Handle, err error) {
|
||||
namep, _ := syscall.UTF16PtrFromString(name)
|
||||
var _p2 uint32
|
||||
if inheritHandle {
|
||||
|
@ -23,7 +24,7 @@ func openEvent(desiredAccess uint32, inheritHandle bool, name string, proc *sysc
|
|||
return
|
||||
}
|
||||
|
||||
func pulseEvent(handle syscall.Handle, proc *syscall.LazyProc) (err error) {
|
||||
func pulseEvent(handle syscall.Handle, proc *windows.LazyProc) (err error) {
|
||||
r0, _, _ := proc.Call(uintptr(handle))
|
||||
if r0 != 0 {
|
||||
err = syscall.Errno(r0)
|
||||
|
@ -32,7 +33,7 @@ func pulseEvent(handle syscall.Handle, proc *syscall.LazyProc) (err error) {
|
|||
}
|
||||
|
||||
func signalDaemonDump(pid int) {
|
||||
modkernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
modkernel32 := windows.NewLazySystemDLL("kernel32.dll")
|
||||
procOpenEvent := modkernel32.NewProc("OpenEventW")
|
||||
procPulseEvent := modkernel32.NewProc("PulseEvent")
|
||||
|
||||
|
|
|
@ -4,10 +4,12 @@ import (
|
|||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
|
||||
)
|
||||
|
||||
|
|
|
@ -4,12 +4,13 @@ package sysinfo
|
|||
|
||||
import (
|
||||
"runtime"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
getCurrentProcess = kernel32.NewProc("GetCurrentProcess")
|
||||
getProcessAffinityMask = kernel32.NewProc("GetProcessAffinityMask")
|
||||
)
|
||||
|
|
|
@ -6,6 +6,8 @@ package system
|
|||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -67,7 +69,7 @@ func PulseEvent(handle syscall.Handle) (err error) {
|
|||
return setResetPulse(handle, procPulseEvent)
|
||||
}
|
||||
|
||||
func setResetPulse(handle syscall.Handle, proc *syscall.LazyProc) (err error) {
|
||||
func setResetPulse(handle syscall.Handle, proc *windows.LazyProc) (err error) {
|
||||
r0, _, _ := proc.Call(uintptr(handle))
|
||||
if r0 != 0 {
|
||||
err = syscall.Errno(r0)
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||
|
||||
procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue