github.com/olljanat/moby@v1.13.1/pkg/system/syscall_windows.go (about)

     1  package system
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  
     7  	"github.com/Sirupsen/logrus"
     8  )
     9  
    10  var (
    11  	ntuserApiset      = syscall.NewLazyDLL("ext-ms-win-ntuser-window-l1-1-0")
    12  	procGetVersionExW = modkernel32.NewProc("GetVersionExW")
    13  )
    14  
    15  // OSVersion is a wrapper for Windows version information
    16  // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
    17  type OSVersion struct {
    18  	Version      uint32
    19  	MajorVersion uint8
    20  	MinorVersion uint8
    21  	Build        uint16
    22  }
    23  
    24  // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
    25  type osVersionInfoEx struct {
    26  	OSVersionInfoSize uint32
    27  	MajorVersion      uint32
    28  	MinorVersion      uint32
    29  	BuildNumber       uint32
    30  	PlatformID        uint32
    31  	CSDVersion        [128]uint16
    32  	ServicePackMajor  uint16
    33  	ServicePackMinor  uint16
    34  	SuiteMask         uint16
    35  	ProductType       byte
    36  	Reserve           byte
    37  }
    38  
    39  // GetOSVersion gets the operating system version on Windows. Note that
    40  // docker.exe must be manifested to get the correct version information.
    41  func GetOSVersion() OSVersion {
    42  	var err error
    43  	osv := OSVersion{}
    44  	osv.Version, err = syscall.GetVersion()
    45  	if err != nil {
    46  		// GetVersion never fails.
    47  		panic(err)
    48  	}
    49  	osv.MajorVersion = uint8(osv.Version & 0xFF)
    50  	osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF)
    51  	osv.Build = uint16(osv.Version >> 16)
    52  	return osv
    53  }
    54  
    55  // IsWindowsClient returns true if the SKU is client
    56  // @engine maintainers - this function should not be removed or modified as it
    57  // is used to enforce licensing restrictions on Windows.
    58  func IsWindowsClient() bool {
    59  	osviex := &osVersionInfoEx{OSVersionInfoSize: 284}
    60  	r1, _, err := procGetVersionExW.Call(uintptr(unsafe.Pointer(osviex)))
    61  	if r1 == 0 {
    62  		logrus.Warnf("GetVersionExW failed - assuming server SKU: %v", err)
    63  		return false
    64  	}
    65  	const verNTWorkstation = 0x00000001
    66  	return osviex.ProductType == verNTWorkstation
    67  }
    68  
    69  // Unmount is a platform-specific helper function to call
    70  // the unmount syscall. Not supported on Windows
    71  func Unmount(dest string) error {
    72  	return nil
    73  }
    74  
    75  // CommandLineToArgv wraps the Windows syscall to turn a commandline into an argument array.
    76  func CommandLineToArgv(commandLine string) ([]string, error) {
    77  	var argc int32
    78  
    79  	argsPtr, err := syscall.UTF16PtrFromString(commandLine)
    80  	if err != nil {
    81  		return nil, err
    82  	}
    83  
    84  	argv, err := syscall.CommandLineToArgv(argsPtr, &argc)
    85  	if err != nil {
    86  		return nil, err
    87  	}
    88  	defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv))))
    89  
    90  	newArgs := make([]string, argc)
    91  	for i, v := range (*argv)[:argc] {
    92  		newArgs[i] = string(syscall.UTF16ToString((*v)[:]))
    93  	}
    94  
    95  	return newArgs, nil
    96  }
    97  
    98  // HasWin32KSupport determines whether containers that depend on win32k can
    99  // run on this machine. Win32k is the driver used to implement windowing.
   100  func HasWin32KSupport() bool {
   101  	// For now, check for ntuser API support on the host. In the future, a host
   102  	// may support win32k in containers even if the host does not support ntuser
   103  	// APIs.
   104  	return ntuserApiset.Load() == nil
   105  }