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 <jostarks@microsoft.com>
This commit is contained in:
parent
d70faf86e8
commit
335e27d88c
3 changed files with 27 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
9
system/syscall_windows_test.go
Normal file
9
system/syscall_windows_test.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue