summaryrefslogtreecommitdiff
path: root/src/hypervisor_check.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/hypervisor_check.adb')
-rw-r--r--src/hypervisor_check.adb54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/hypervisor_check.adb b/src/hypervisor_check.adb
index 998070b..83bb107 100644
--- a/src/hypervisor_check.adb
+++ b/src/hypervisor_check.adb
@@ -12,6 +12,7 @@ package body Hypervisor_Check is
return (eax, ebx, ecx, edx);
end CPUID;
+ -- Convert an unsigned 32-bit integer to a string of 4 characters
function String_of_U32 (Arg : Unsigned_32) return US.Unbounded_String is
Word : Unsigned_32;
Result : US.Unbounded_String;
@@ -24,6 +25,32 @@ package body Hypervisor_Check is
return Result;
end String_of_U32;
+ function Contains (Haystack : US.Unbounded_String; Needle : String)
+ return Boolean is
+ Position : Natural;
+ begin
+ Position := US.Index (Source => Haystack, Pattern => Needle);
+ if Position > 0 then
+ return True;
+ else
+ return False;
+ end if;
+ end Contains;
+
+ -- Read the first line of file, return empty string in case of errors
+ -- Pretty much what we need for reading /proc files etc.
+ function Head_Of_File (Path : String) return US.Unbounded_String is
+ File : IO.File_Type;
+ Result : US.Unbounded_String;
+ begin
+ IO.Open(File => File, Name => Path, Mode => IO.In_File);
+ UIO.Get_Line (File, Result);
+ IO.Close(File);
+ return Result;
+ exception
+ when others => return US.To_Unbounded_String ("");
+ end Head_Of_File;
+
-- Hypervisors should set the bit 31 of %ecx to 1 in CPUID leaf 1
function Hypervisor_Present return Boolean is
Registers : CPUID_Registers;
@@ -69,4 +96,31 @@ package body Hypervisor_Check is
return Vendor_Name;
end Get_Vendor_Name;
+ function Get_DMI_Vendor_String return US.Unbounded_String is
+ Name : US.Unbounded_String;
+ begin
+ -- Linux
+ Name := Head_Of_File (Linux_Sys_Vendor_File);
+ return Name;
+
+ end Get_DMI_Vendor_String;
+
+ function Get_DMI_Vendor_Name return US.Unbounded_String is
+ Vendor_String, Vendor_Name : US.Unbounded_String;
+ begin
+ Vendor_String := Get_DMI_Vendor_String;
+ if Contains(Vendor_String, VMWare_DMI_Pattern) then
+ Vendor_Name := US.To_Unbounded_String (VMWare);
+ elsif Contains(Vendor_String, HyperV_DMI_Pattern) then
+ Vendor_Name := US.To_Unbounded_String (HyperV);
+ elsif Contains(Vendor_String, VirtualBox_DMI_Pattern) then
+ Vendor_Name := US.To_Unbounded_String (VirtualBox);
+ elsif Contains(Vendor_String, Parallels_DMI_Pattern) then
+ Vendor_Name := US.To_Unbounded_String (Parallels);
+ else
+ Vendor_Name := US.To_Unbounded_String ("");
+ end if;
+ return Vendor_Name;
+ end Get_DMI_Vendor_Name;
+
end Hypervisor_Check;