func signalDaemonDump(pid int) { modkernel32 := windows.NewLazySystemDLL("kernel32.dll") procOpenEvent := modkernel32.NewProc("OpenEventW") procPulseEvent := modkernel32.NewProc("PulseEvent") ev := "Global\\docker-daemon-" + strconv.Itoa(pid) h2, _ := openEvent(0x0002, false, ev, procOpenEvent) if h2 == 0 { return } pulseEvent(h2, procPulseEvent) }
// checkSystem validates platform-specific requirements func checkSystem() error { // Validate the OS version. Note that docker.exe must be manifested for this // call to return the correct version. osv := system.GetOSVersion() if osv.MajorVersion < 10 { return fmt.Errorf("This version of Windows does not support the docker daemon") } if osv.Build < 14393 { return fmt.Errorf("The docker daemon requires build 14393 or later of Windows Server 2016 or Windows 10") } vmcompute := windows.NewLazySystemDLL("vmcompute.dll") if vmcompute.Load() != nil { return fmt.Errorf("Failed to load vmcompute.dll. Ensure that the Containers role is installed.") } return nil }
// getFileSystemType obtains the type of a file system through GetVolumeInformation // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx func getFileSystemType(drive string) (fsType string, hr error) { var ( modkernel32 = windows.NewLazySystemDLL("kernel32.dll") procGetVolumeInformation = modkernel32.NewProc("GetVolumeInformationW") buf = make([]uint16, 255) size = syscall.MAX_PATH + 1 ) if len(drive) != 1 { hr = errors.New("getFileSystemType must be called with a drive letter") return } drive += `:\` n := uintptr(unsafe.Pointer(nil)) r0, _, _ := syscall.Syscall9(procGetVolumeInformation.Addr(), 8, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(drive))), n, n, n, n, n, uintptr(unsafe.Pointer(&buf[0])), uintptr(size), 0) if int32(r0) < 0 { hr = syscall.Errno(win32FromHresult(r0)) } fsType = syscall.UTF16ToString(buf) return }
// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT package winio import ( "syscall" "unsafe" "golang.org/x/sys/windows" ) var _ unsafe.Pointer var ( modkernel32 = windows.NewLazySystemDLL("kernel32.dll") modwinmm = windows.NewLazySystemDLL("winmm.dll") modadvapi32 = windows.NewLazySystemDLL("advapi32.dll") procCancelIoEx = modkernel32.NewProc("CancelIoEx") procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort") procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus") procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes") proctimeBeginPeriod = modwinmm.NewProc("timeBeginPeriod") procConnectNamedPipe = modkernel32.NewProc("ConnectNamedPipe") procCreateNamedPipeW = modkernel32.NewProc("CreateNamedPipeW") procCreateFileW = modkernel32.NewProc("CreateFileW") procWaitNamedPipeW = modkernel32.NewProc("WaitNamedPipeW") procGetNamedPipeInfo = modkernel32.NewProc("GetNamedPipeInfo") procGetNamedPipeHandleStateW = modkernel32.NewProc("GetNamedPipeHandleStateW") procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW") procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT package win32 import ( "syscall" "unsafe" "golang.org/x/sys/windows" ) var _ unsafe.Pointer var ( moduser32 = windows.NewLazySystemDLL("user32.dll") procGetDC = moduser32.NewProc("GetDC") procReleaseDC = moduser32.NewProc("ReleaseDC") procSendMessageW = moduser32.NewProc("SendMessageW") procCreateWindowExW = moduser32.NewProc("CreateWindowExW") procDefWindowProcW = moduser32.NewProc("DefWindowProcW") procDestroyWindow = moduser32.NewProc("DestroyWindow") procDispatchMessageW = moduser32.NewProc("DispatchMessageW") procGetClientRect = moduser32.NewProc("GetClientRect") procGetKeyboardLayout = moduser32.NewProc("GetKeyboardLayout") procGetKeyboardState = moduser32.NewProc("GetKeyboardState") procGetKeyState = moduser32.NewProc("GetKeyState") procGetMessageW = moduser32.NewProc("GetMessageW") procLoadCursorW = moduser32.NewProc("LoadCursorW") procLoadIconW = moduser32.NewProc("LoadIconW") procPostMessageW = moduser32.NewProc("PostMessageW")
package system import ( "unsafe" "golang.org/x/sys/windows" ) var ( modkernel32 = windows.NewLazySystemDLL("kernel32.dll") procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx") ) // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx type memorystatusex struct { dwLength uint32 dwMemoryLoad uint32 ullTotalPhys uint64 ullAvailPhys uint64 ullTotalPageFile uint64 ullAvailPageFile uint64 ullTotalVirtual uint64 ullAvailVirtual uint64 ullAvailExtendedVirtual uint64 } // ReadMemInfo retrieves memory statistics of the host system and returns a // MemInfo type. func ReadMemInfo() (*MemInfo, error) {
) type etwLogs struct { containerName string imageName string containerID string imageID string } const ( name = "etwlogs" win32CallSuccess = 0 ) 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 func init() { providerHandle = syscall.InvalidHandle if err := logger.RegisterLogDriver(name, New); err != nil { logrus.Fatal(err) } }
// allocations at runtime. func errnoErr(e syscall.Errno) error { switch e { case 0: return nil case errnoERROR_IO_PENDING: return errERROR_IO_PENDING } // TODO: add more here, after collecting data on the common // error values see on Windows. (perhaps when running // all.bat?) return e } var ( modole32 = windows.NewLazySystemDLL("ole32.dll") modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll") modvmcompute = windows.NewLazySystemDLL("vmcompute.dll") procCoTaskMemFree = modole32.NewProc("CoTaskMemFree") procSetCurrentThreadCompartmentId = modiphlpapi.NewProc("SetCurrentThreadCompartmentId") procActivateLayer = modvmcompute.NewProc("ActivateLayer") procCopyLayer = modvmcompute.NewProc("CopyLayer") procCreateLayer = modvmcompute.NewProc("CreateLayer") procCreateSandboxLayer = modvmcompute.NewProc("CreateSandboxLayer") procExpandSandboxSize = modvmcompute.NewProc("ExpandSandboxSize") procDeactivateLayer = modvmcompute.NewProc("DeactivateLayer") procDestroyLayer = modvmcompute.NewProc("DestroyLayer") procExportLayer = modvmcompute.NewProc("ExportLayer") procGetLayerMountPath = modvmcompute.NewProc("GetLayerMountPath") procGetBaseImages = modvmcompute.NewProc("GetBaseImages")
"golang.org/x/sys/windows" ) type GUID struct { Data1 uint32 Data2 uint16 Data3 uint16 Data4 [8]byte } var ( FOLDERID_RoamingAppData = GUID{0x3EB685DB, 0x65F9, 0x4CF6, [8]byte{0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D}} ) var ( modShell32 = windows.NewLazySystemDLL("Shell32.dll") modOle32 = windows.NewLazySystemDLL("Ole32.dll") procSHGetKnownFolderPath = modShell32.NewProc("SHGetKnownFolderPath") procCoTaskMemFree = modOle32.NewProc("CoTaskMemFree") ) // LookPath searches for an executable binary named file // in the directories named by the PATH environment variable. // If file contains a slash, it is tried directly and the PATH is not consulted. func canExec(s string) error { if strings.IndexAny(s, `:\/`) == -1 { s = s + "/" } _, err := exec.LookPath(s) return err