Skip to content

Commit

Permalink
feat: hypervisor vendor
Browse files Browse the repository at this point in the history
Read hypervisor vendor as per https://lwn.net/Articles/301888/.
  • Loading branch information
brianmcgee committed Jul 29, 2024
1 parent 6b818cd commit d07d3d2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
23 changes: 23 additions & 0 deletions cpuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const (
Qualcomm
Marvell

QEMU
QNX
ACRN
SRE
Apple

lastVendor
)

Expand Down Expand Up @@ -881,6 +887,8 @@ var vendorMapping = map[string]Vendor{
"Geode by NSC": NSC,
"VIA VIA VIA ": VIA,
"KVMKVMKVM": KVM,
"Linux KVM Hv": KVM,
"TCGTCGTCGTCG": QEMU,
"Microsoft Hv": MSVM,
"VMwareVMware": VMware,
"XenVMMXenVMM": XenHVM,
Expand All @@ -890,6 +898,10 @@ var vendorMapping = map[string]Vendor{
"SiS SiS SiS ": SiS,
"RiseRiseRise": SiS,
"Genuine RDC": RDC,
"QNXQVMBSQG": QNX,
"ACRNACRNACRN": ACRN,
"SRESRESRESRE": SRE,
"Apple VZ": Apple,
}

func vendorID() (Vendor, string) {
Expand All @@ -902,6 +914,17 @@ func vendorID() (Vendor, string) {
return vend, v
}

func hypervisorVendorID() (Vendor, string) {
// https://lwn.net/Articles/301888/
_, b, c, d := cpuid(0x40000000)
v := string(valAsString(b, c, d))
vend, ok := vendorMapping[v]
if !ok {
return VendorUnknown, v
}
return vend, v
}

func cacheLine() int {
if maxFunctionID() < 0x1 {
return 0
Expand Down
1 change: 1 addition & 0 deletions detect_x86.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func addInfo(c *CPUInfo, safe bool) {
c.LogicalCores = logicalCores()
c.PhysicalCores = physicalCores()
c.VendorID, c.VendorString = vendorID()
c.HypervisorVendorID, c.HypervisorVendorString = hypervisorVendorID()
c.AVX10Level = c.supportAVX10()
c.cacheSize()
c.frequencies()
Expand Down
11 changes: 8 additions & 3 deletions featureid_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mockcpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func mockCPU(def []byte) func() {
}(idfuncs{cpuid: cpuid, cpuidex: cpuidex, xgetbv: xgetbv})

cpuid = func(op uint32) (eax, ebx, ecx, edx uint32) {
if op == 0x80000000 || op == 0 || op == 0x4000000c {
if op == 0x80000000 || op == 0 || op == 0x4000000c || op == 0x40000000 {
var ok bool
_, ok = fakeID[op]
if !ok {
Expand Down

0 comments on commit d07d3d2

Please sign in to comment.