| 1 | |
| 2 | |
| 3 | |
| 4 | package qemu |
| 5 | |
| 6 | import ( |
| 7 | "unsafe" |
| 8 | |
| 9 | "github.com/sirupsen/logrus" |
| 10 | "golang.org/x/sys/windows" |
| 11 | ) |
| 12 | |
| 13 | func whpxQEMU64() string { |
| 14 | |
| 15 | |
| 16 | query := windows.NewLazySystemDLL("WinHvPlatform.dll").NewProc("WHvGetCapability") |
| 17 | if err := query.Find(); err != nil { |
| 18 | logrus.WithError(err).Warn("Cannot query WHPX processor features; using qemu64 defaults") |
| 19 | return "qemu64" |
| 20 | } |
| 21 | const processorFeatures = 0x1001 |
| 22 | var bits uint64 |
| 23 | var written uint32 |
| 24 | status, _, _ := query.Call(processorFeatures, uintptr(unsafe.Pointer(&bits)), |
| 25 | unsafe.Sizeof(bits), uintptr(unsafe.Pointer(&written))) |
| 26 | if int32(status) < 0 || uintptr(written) != unsafe.Sizeof(bits) { |
| 27 | logrus.Warnf("Cannot query WHPX processor features (HRESULT %#x, %d bytes); using qemu64 defaults", uint32(status), written) |
| 28 | return "qemu64" |
| 29 | } |
| 30 | return whpxQEMU64Model(bits) |
| 31 | } |
| 32 | |
| 33 | |
| 34 | func whpxQEMU64Model(bits uint64) string { |
| 35 | model := "qemu64" |
| 36 | for _, feature := range []struct { |
| 37 | mask uint64 |
| 38 | flag string |
| 39 | }{ |
| 40 | {1 << 2, "+ssse3"}, |
| 41 | {1 << 3, "+sse4.1"}, |
| 42 | {1 << 4, "+sse4.2"}, |
| 43 | {1 << 7, "+popcnt"}, |
| 44 | } { |
| 45 | if bits&feature.mask != 0 { |
| 46 | model += "," + feature.flag |
| 47 | } |
| 48 | } |
| 49 | return model |
| 50 | } |