diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-23 22:33:05 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-23 22:33:05 +0100 |
| commit | 1c57eacab858c41cd5565d468982094e46312b86 (patch) | |
| tree | 6fd1b0f1d035663e12863124a0b102bfb98fe10e /liblfvm/vm_config.ccm | |
| download | lfvm-1c57eacab858c41cd5565d468982094e46312b86.tar.gz lfvm-1c57eacab858c41cd5565d468982094e46312b86.tar.bz2 | |
initial commit
Diffstat (limited to 'liblfvm/vm_config.ccm')
| -rw-r--r-- | liblfvm/vm_config.ccm | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/liblfvm/vm_config.ccm b/liblfvm/vm_config.ccm new file mode 100644 index 0000000..e49a540 --- /dev/null +++ b/liblfvm/vm_config.ccm @@ -0,0 +1,157 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <cstdint> +#include <string> + +import nihil; + +export module liblfvm:vm_config; + +namespace lfvm { + +/* + * Represents the configuration for a virtual machine. + */ + +export struct vm_config { + // Create a new, empty configuration. + vm_config(std::string_view name) + : _name(name) + { + } + + // The virtual machine name. + auto name(this vm_config const &self) -> std::string_view + { + return self._name; + } + + // The virtual machine UUID. + // Default: a random UUID. + auto uuid(this vm_config const &self) -> nihil::uuid + { + return self._uuid; + } + + auto uuid(this vm_config &self, nihil::uuid const &new_value) -> void + { + self._uuid = new_value; + } + + // How many virtual CPUs the VM will have. Default is 1. + // TODO: support the full bhyve CPU topology here. + auto ncpus(this vm_config const &self) -> unsigned + { + return self.c_flag; + } + + auto ncpus(this vm_config &self, unsigned new_value) -> void + { + self.c_flag = new_value; + } + + // How much memory to allocate to the guest. + // Default is 256MB. + auto memory_size(this vm_config const &self) -> std::uint64_t + { + return self.m_flag; + } + + auto memory_size(this vm_config &self, std::uint64_t new_value) -> void + { + self.m_flag = new_value; + } + + // Whether to destroy this vm_config when the guest powers off. + // Defaults to true. + auto destroy_on_poweroff(this vm_config const &self) -> bool + { + return self.D_flag; + } + + auto destroy_on_poweroff(this vm_config &self, bool new_value) + -> void + { + self.D_flag = new_value; + } + + // Whether to wire guard memory. + // Defaults to false. + auto wire_memory(this vm_config const &self) -> bool + { + return self.S_flag; + } + + auto wire_memory(this vm_config &self, bool new_value) -> void + { + self.S_flag = new_value; + } + + // Whether to include memory in core files. + // Defaults to false. + auto include_memory_in_core(this vm_config const &self) -> bool + { + return self.C_flag; + } + + auto include_memory_in_core(this vm_config &self, bool new_value) -> void + { + self.C_flag = new_value; + } + + // Whether to yield when the guest issues a HLT instruction. + // Defaults to true. + auto yield_on_halt(this vm_config const &self) -> bool + { + return self.H_flag; + } + + auto yield_on_halt(this vm_config &self, bool new_value) -> void + { + self.H_flag = new_value; + } + + // Whether to exit when the guest issues a PAUSE instruction. + // Defaults to true. + auto exit_on_pause(this vm_config const &self) -> bool + { + return self.P_flag; + } + + auto exit_on_pause(this vm_config &self, bool new_value) -> void + { + self.P_flag = new_value; + } + + // Whether the RTC keeps UTC time. + // Defaults to true. + auto rtc_is_utc(this vm_config const &self) -> bool + { + return self.u_flag; + } + + auto rtc_is_utc(this vm_config &self, bool new_value) -> void + { + self.u_flag = new_value; + } + +private: + std::string _name; + nihil::uuid _uuid = nihil::random_uuid(); + + unsigned c_flag = 1; // number of CPUs + std::uint64_t m_flag = 256 * 1024 * 1024; + // guest memory size + bool C_flag = false; // include memory in core dumps + bool D_flag = true; // destroy VM on poweroff + bool H_flag = true; // yield on HLT + bool P_flag = true; // exit on PAUSE + bool S_flag = false; // wire guest memory + bool u_flag = true; // RTC is UTC +}; + +} // namespace lfvm |
