VirtualMachine
public final class VirtualMachine
A type representing a full VM (virtual machine) including cpus and memory.
-
Undocumented
Declaration
Swift
public private(set) var vcpus: [VCPU] { get } -
Undocumented
Declaration
Swift
public private(set) var memoryRegions: [MemoryRegion] { get } -
Initialise the VM subsystem
Throws
VMError.vmCreateVMFailureDeclaration
Swift
public init(logger: Logger) throwsParameters
loggerLoggerobject fordebugandtracemessages. -
Adds a memory region into the physical address space of the VM.
The VM requires at least one MemoryRegion to be added before starting the vCPU.Precondition
guestAddressmust be page aligned.Precondition
sizeis non-zero and is a multiple of the page size of the VM.Throws
VMError.addMemoryFailure.Declaration
Swift
public func addMemory(at guestAddress: UInt64, size: UInt64, readOnly: Bool = false) throws -> MemoryRegionParameters
guestAddressPhysical Address inside the VM where the region will start.
sizeSize in bytes of the memory region.
readOnlyFlag to indicate if the memory should be treated as ROM or RAM by the Virtual CPUs.
Return Value
The new
MemoryRegion. -
Returns the memory region containing a specific physical address in the address space of the VM.
Declaration
Swift
public func memoryRegion(containing guestAddress: PhysicalAddress) -> MemoryRegion?Parameters
guestAddressThe Physical Address in the VM.
Return Value
The
MemoryRegioncontaining the address ornilif no region is found. -
Returns an
UnsafeMutableRawPointerto a region of bytes at a specified physical address.Declaration
Swift
public func memory(at guestAddress: PhysicalAddress, count: UInt64) throws -> UnsafeMutableRawPointerParameters
guestAddressPhysical Address inside the VM where the region will start.
countThe size in bytes of the region.
Return Value
An
UnsafeMutableRawPointerpointing to a region ofcountbytes. -
Add a VCPU to the Virtual Machine.
Creates a new Thread and initialises a vCPU in that thread. The `startup` function is executed to setup the vCPU and then it waits until the `.start()` method is called to begin executing code.Throws
VMError.vcpuCreateFailure.Declaration
Swift
@discardableResult public func addVCPU() throws -> VCPUReturn Value
The
VCPUthat has been added to the VM. -
Query all of the vCPUs to determine if they have been shutdown
Use this method to check the shutdown status of all of the vCPUs. Before shutting down the VirtualMachine, all of the vCPUs must be in the shutdown state. The `.shutdownAllVcpus` method can be called to shutdown all the vCPUS.Declaration
Swift
public func areVcpusShutdown() -> BoolReturn Value
trueif all vCPUs have been shutdown,falseif any are still running. -
Request all of the vCPUs to enter the shutdown state.
Use this method to request all vCPUs to shutdown.Declaration
Swift
@discardableResult public func shutdownAllVcpus() -> BoolReturn Value
trueif all vCPUs have been shutdown,falseif any are still running. -
Shutdown the VM.
shutdown() must be called before the VirtualMachine object is deallocated. Before calling, all vCPUS must be individually shutdown and a check is run to ensure the vCPUS are in the shutdown state. All MemoryRegions and VCPUS are deallocated by this method and the underlying hypervisor is shutdown by the OS.Throws
VMError.vcpusStillRunningif any vCPU is still running.Throws
VMError.vmShutdownFailureif an internal subsystem error occurs.Declaration
Swift
public func shutdown() throws -
Undocumented
See moreDeclaration
Swift
public final class VCPU
View on GitHub
VirtualMachine Class Reference