2015-09-09 22:23:06 -04:00
|
|
|
package system
|
|
|
|
|
2015-10-15 14:40:14 -04:00
|
|
|
import (
|
|
|
|
"syscall"
|
2016-03-18 14:50:19 -04:00
|
|
|
"unsafe"
|
2016-04-14 20:12:02 -04:00
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2015-10-15 14:40:14 -04:00
|
|
|
)
|
|
|
|
|
2016-03-16 21:45:40 -04:00
|
|
|
var (
|
2016-04-14 20:12:02 -04:00
|
|
|
ntuserApiset = syscall.NewLazyDLL("ext-ms-win-ntuser-window-l1-1-0")
|
|
|
|
procGetVersionExW = modkernel32.NewProc("GetVersionExW")
|
2016-03-16 21:45:40 -04:00
|
|
|
)
|
|
|
|
|
2015-10-15 14:40:14 -04:00
|
|
|
// OSVersion is a wrapper for Windows version information
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
|
|
|
|
type OSVersion struct {
|
|
|
|
Version uint32
|
|
|
|
MajorVersion uint8
|
|
|
|
MinorVersion uint8
|
|
|
|
Build uint16
|
|
|
|
}
|
|
|
|
|
2016-04-14 20:12:02 -04:00
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
|
|
|
|
type osVersionInfoEx struct {
|
|
|
|
OSVersionInfoSize uint32
|
|
|
|
MajorVersion uint32
|
|
|
|
MinorVersion uint32
|
|
|
|
BuildNumber uint32
|
|
|
|
PlatformID uint32
|
|
|
|
CSDVersion [128]uint16
|
|
|
|
ServicePackMajor uint16
|
|
|
|
ServicePackMinor uint16
|
|
|
|
SuiteMask uint16
|
|
|
|
ProductType byte
|
|
|
|
Reserve byte
|
|
|
|
}
|
|
|
|
|
2015-10-15 14:40:14 -04:00
|
|
|
// GetOSVersion gets the operating system version on Windows. Note that
|
|
|
|
// docker.exe must be manifested to get the correct version information.
|
2016-03-16 21:45:40 -04:00
|
|
|
func GetOSVersion() OSVersion {
|
2015-10-15 14:40:14 -04:00
|
|
|
var err error
|
|
|
|
osv := OSVersion{}
|
|
|
|
osv.Version, err = syscall.GetVersion()
|
|
|
|
if err != nil {
|
2016-03-16 21:45:40 -04:00
|
|
|
// GetVersion never fails.
|
|
|
|
panic(err)
|
2015-10-15 14:40:14 -04:00
|
|
|
}
|
|
|
|
osv.MajorVersion = uint8(osv.Version & 0xFF)
|
|
|
|
osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF)
|
|
|
|
osv.Build = uint16(osv.Version >> 16)
|
2016-03-16 21:45:40 -04:00
|
|
|
return osv
|
2015-10-15 14:40:14 -04:00
|
|
|
}
|
|
|
|
|
2016-04-14 20:12:02 -04:00
|
|
|
// IsWindowsClient returns true if the SKU is client
|
|
|
|
func IsWindowsClient() bool {
|
|
|
|
osviex := &osVersionInfoEx{OSVersionInfoSize: 284}
|
|
|
|
r1, _, err := procGetVersionExW.Call(uintptr(unsafe.Pointer(osviex)))
|
|
|
|
if r1 == 0 {
|
|
|
|
logrus.Warnf("GetVersionExW failed - assuming server SKU: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const verNTWorkstation = 0x00000001
|
|
|
|
return osviex.ProductType == verNTWorkstation
|
|
|
|
}
|
|
|
|
|
2015-10-26 16:34:49 -04:00
|
|
|
// Unmount is a platform-specific helper function to call
|
2015-09-09 22:23:06 -04:00
|
|
|
// the unmount syscall. Not supported on Windows
|
2015-11-02 16:18:07 -05:00
|
|
|
func Unmount(dest string) error {
|
|
|
|
return nil
|
2015-09-09 22:23:06 -04:00
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
// CommandLineToArgv wraps the Windows syscall to turn a commandline into an argument array.
|
|
|
|
func CommandLineToArgv(commandLine string) ([]string, error) {
|
|
|
|
var argc int32
|
|
|
|
|
|
|
|
argsPtr, err := syscall.UTF16PtrFromString(commandLine)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
argv, err := syscall.CommandLineToArgv(argsPtr, &argc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv))))
|
|
|
|
|
|
|
|
newArgs := make([]string, argc)
|
|
|
|
for i, v := range (*argv)[:argc] {
|
|
|
|
newArgs[i] = string(syscall.UTF16ToString((*v)[:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
return newArgs, nil
|
|
|
|
}
|
2016-03-16 21:45:40 -04:00
|
|
|
|
|
|
|
// HasWin32KSupport determines whether containers that depend on win32k can
|
|
|
|
// run on this machine. Win32k is the driver used to implement windowing.
|
|
|
|
func HasWin32KSupport() bool {
|
|
|
|
// For now, check for ntuser API support on the host. In the future, a host
|
|
|
|
// may support win32k in containers even if the host does not support ntuser
|
|
|
|
// APIs.
|
|
|
|
return ntuserApiset.Load() == nil
|
|
|
|
}
|