32 gsl::not_null<ioctl *> ctl,
33 gsl::not_null<command_line_parser *> clp) :
48 return this->load_vmm();
51 return this->unload_vmm();
54 return this->start_vmm();
57 return this->stop_vmm();
60 return this->dump_vmm();
63 return this->vmm_status();
66 return this->vmcall();
74 ioctl_driver::load_vmm()
85 auto &&modules = json::parse(m_file->read_text(m_clp->modules()));
87 auto ___ = gsl::on_failure([&]
90 auto &&module_list = modules[
"modules"];
92 std::random_device rd;
95 std::shuffle(module_list.begin(), module_list.end(), g);
97 for (
const auto &module : module_list)
98 m_ioctl->call_ioctl_add_module(m_file->read_binary(module));
100 m_ioctl->call_ioctl_load_vmm();
104 ioctl_driver::unload_vmm()
106 switch (get_status())
115 m_ioctl->call_ioctl_unload_vmm();
119 ioctl_driver::start_vmm()
121 switch (get_status())
130 m_ioctl->call_ioctl_start_vmm();
134 ioctl_driver::stop_vmm()
136 switch (get_status())
145 m_ioctl->call_ioctl_stop_vmm();
149 ioctl_driver::dump_vmm()
154 switch (get_status())
163 m_ioctl->call_ioctl_dump_vmm(&
drr, m_clp->vcpuid());
166 std::cout << buffer.get();
170 ioctl_driver::vmm_status()
172 switch (get_status())
174 case VMM_UNLOADED: std::cout <<
"VMM_UNLOADED\n";
return;
175 case VMM_LOADED: std::cout <<
"VMM_LOADED\n";
return;
176 case VMM_RUNNING: std::cout <<
"VMM_RUNNING\n";
return;
177 case VMM_CORRUPT: std::cout <<
"VMM_CORRUPT\n";
return;
183 ioctl_driver::vmcall()
185 auto regs = m_clp->registers();
187 switch (get_status())
203 this->vmcall_registers(regs);
207 this->vmcall_data(regs);
211 this->vmcall_event(regs);
215 this->vmcall_unittest(regs);
219 throw std::logic_error(
"unknown vmcall opcode");
224 ioctl_driver::vmcall_send_regs(registers_type ®s)
226 m_ioctl->call_ioctl_vmcall(®s, m_clp->cpuid());
233 ioctl_driver::vmcall_versions(registers_type ®s)
235 this->vmcall_send_regs(regs);
240 std::cout <<
"VMCALL_VERSIONS: " <<
view_as_pointer(regs.r03) << std::endl;
244 std::cout <<
"BAREFLANK_VERSION_MAJOR: " <<
view_as_pointer(regs.r03) << std::endl;
245 std::cout <<
"BAREFLANK_VERSION_MINOR: " <<
view_as_pointer(regs.r04) << std::endl;
246 std::cout <<
"BAREFLANK_VERSION_PATCH: " <<
view_as_pointer(regs.r05) << std::endl;
250 std::cout <<
"USER_VERSION_MAJOR: " <<
view_as_pointer(regs.r03) << std::endl;
251 std::cout <<
"USER_VERSION_MINOR: " <<
view_as_pointer(regs.r04) << std::endl;
252 std::cout <<
"USER_VERSION_PATCH: " <<
view_as_pointer(regs.r05) << std::endl;
261 ioctl_driver::vmcall_registers(registers_type ®s)
263 this->vmcall_send_regs(regs);
282 ioctl_driver::vmcall_data(registers_type ®s)
288 this->vmcall_data_string(regs);
292 this->vmcall_data_binary(regs);
296 throw std::logic_error(
"unknown vmcall data type");
302 ioctl_driver::vmcall_data_string(registers_type ®s)
305 regs.r08 =
reinterpret_cast<decltype(regs.r08)
>(obuffer.get());
308 vmcall_send_regs(regs);
315 throw std::out_of_range(
"return output buffer size out of range");
317 std::cout <<
"received from vmm: \n" << json::parse(
std::string(obuffer.get(), regs.r09)).dump(4) <<
'\n';
323 throw std::out_of_range(
"return output buffer size out of range");
325 std::cout <<
"received from vmm: " <<
std::string(obuffer.get(), regs.r09) <<
'\n';
334 ioctl_driver::vmcall_data_binary(registers_type ®s)
336 auto &&ifile_buffer = m_file->read_binary(m_clp->ifile());
338 regs.r05 =
reinterpret_cast<decltype(regs.r05)
>(ifile_buffer.data());
339 regs.r06 = ifile_buffer.size();
340 regs.r08 =
reinterpret_cast<decltype(regs.r08)
>(ofile_buffer.data());
343 vmcall_send_regs(regs);
350 throw std::out_of_range(
"return output buffer size out of range");
352 ofile_buffer.resize(regs.r09);
353 m_file->write_binary(m_clp->ofile(), ofile_buffer);
362 ioctl_driver::vmcall_event(registers_type ®s)
364 vmcall_send_regs(regs);
365 std::cout <<
"success" << std::endl;
369 ioctl_driver::vmcall_unittest(registers_type ®s)
371 vmcall_send_regs(regs);
372 std::cout <<
"\033[1;36m" << std::hex <<
"0x" << regs.r02 << std::dec <<
":\033[1;32m passed\033[0m\n";
376 ioctl_driver::get_status()
const 379 m_ioctl->call_ioctl_vmm_status(&status);
#define invalid_vmm_state(a)
ioctl::status_type status_type
#define VMCALL_OUT_BUFFER_SIZE
uint64_t debug_ring_read(struct debug_ring_resources_t *drr, char *str, uint64_t len)
debug_ring_resources_t * drr
ioctl_driver(gsl::not_null< file *> f, gsl::not_null< ioctl *> ctl, gsl::not_null< command_line_parser *> clp)
constexpr const auto string
const void * view_as_pointer(const T val)
std::vector< char > binary_data