From 335e27d88cf0a053e546bbf27313c4bbb3a84541 Mon Sep 17 00:00:00 2001 From: John Starks Date: Wed, 16 Mar 2016 18:45:40 -0700 Subject: [PATCH] Add os_version and os_features to Image These fields are needed to specify the exact version of Windows that an image can run on. They may be useful for other platforms in the future. This also changes image.store.Create to validate that the loaded image is supported on the current machine. This change affects Linux as well, since it now validates the architecture and OS fields. Signed-off-by: John Starks --- system/syscall_windows.go | 21 +++++++++++++++++---- system/syscall_windows_test.go | 9 +++++++++ term/term_windows.go | 5 +---- 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 system/syscall_windows_test.go diff --git a/system/syscall_windows.go b/system/syscall_windows.go index 061e220..ef596f3 100644 --- a/system/syscall_windows.go +++ b/system/syscall_windows.go @@ -1,11 +1,14 @@ package system import ( - "fmt" "syscall" "unsafe" ) +var ( + ntuserApiset = syscall.NewLazyDLL("ext-ms-win-ntuser-window-l1-1-0") +) + // 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 { @@ -17,17 +20,18 @@ type OSVersion struct { // GetOSVersion gets the operating system version on Windows. Note that // docker.exe must be manifested to get the correct version information. -func GetOSVersion() (OSVersion, error) { +func GetOSVersion() OSVersion { var err error osv := OSVersion{} osv.Version, err = syscall.GetVersion() if err != nil { - return osv, fmt.Errorf("Failed to call GetVersion()") + // GetVersion never fails. + panic(err) } osv.MajorVersion = uint8(osv.Version & 0xFF) osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF) osv.Build = uint16(osv.Version >> 16) - return osv, nil + return osv } // Unmount is a platform-specific helper function to call @@ -58,3 +62,12 @@ func CommandLineToArgv(commandLine string) ([]string, error) { return newArgs, nil } + +// 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 +} diff --git a/system/syscall_windows_test.go b/system/syscall_windows_test.go new file mode 100644 index 0000000..4886b2b --- /dev/null +++ b/system/syscall_windows_test.go @@ -0,0 +1,9 @@ +package system + +import "testing" + +func TestHasWin32KSupport(t *testing.T) { + s := HasWin32KSupport() // make sure this doesn't panic + + t.Logf("win32k: %v", s) // will be different on different platforms -- informative only +} diff --git a/term/term_windows.go b/term/term_windows.go index a02e681..905c022 100644 --- a/term/term_windows.go +++ b/term/term_windows.go @@ -59,10 +59,7 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { // console which supports ANSI emulation, or fall-back to the golang emulator // (github.com/azure/go-ansiterm). func useNativeConsole() bool { - osv, err := system.GetOSVersion() - if err != nil { - return false - } + osv := system.GetOSVersion() // Native console is not available before major version 10 if osv.MajorVersion < 10 {