exit_handler_intel_x64.h
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef EXIT_HANDLER_INTEL_X64_H
23 #define EXIT_HANDLER_INTEL_X64_H
24 
25 #include <memory>
26 
27 #include <json.h>
28 #include <vmcall_interface.h>
29 #include <vmcs/vmcs_intel_x64.h>
31 
32 class vcpu_intel_x64;
33 
34 // -----------------------------------------------------------------------------
35 // Exit Handler
36 // -----------------------------------------------------------------------------
37 
53 {
54 public:
55 
56  using ret_type = int64_t;
57 
64 
70  virtual ~exit_handler_intel_x64() = default;
71 
80  virtual void dispatch();
81 
90  virtual void halt() noexcept;
91 
107  virtual void complete_vmcall(ret_type ret, vmcall_registers_t &regs) noexcept;
108 
109 protected:
110 
111  virtual void handle_exit(intel_x64::vmcs::value_type reason);
112 
113  void handle_cpuid();
114  void handle_invd();
115  void handle_vmcall();
116  void handle_vmxoff();
117  void handle_rdmsr();
118  void handle_wrmsr();
119 
120  void advance_rip() noexcept;
121  void unimplemented_handler() noexcept;
122 
123  virtual void handle_vmcall_versions(vmcall_registers_t &regs);
124  virtual void handle_vmcall_registers(vmcall_registers_t &regs);
125  virtual void handle_vmcall_data(vmcall_registers_t &regs);
126  virtual void handle_vmcall_event(vmcall_registers_t &regs);
127  virtual void handle_vmcall_start(vmcall_registers_t &regs);
128  virtual void handle_vmcall_stop(vmcall_registers_t &regs);
129  virtual void handle_vmcall_unittest(vmcall_registers_t &regs);
130 
132  const std::string &istr, std::string &ostr);
133 
134  virtual void handle_vmcall_data_string_json(
135  const json &ijson, json &ojson);
136 
138  const bfn::unique_map_ptr_x64<char> &imap,
139  const bfn::unique_map_ptr_x64<char> &omap);
140 
141  void reply_with_string(
142  vmcall_registers_t &regs, const std::string &str,
143  const bfn::unique_map_ptr_x64<char> &omap);
144 
145  void reply_with_json(
146  vmcall_registers_t &regs, const json &str,
147  const bfn::unique_map_ptr_x64<char> &omap);
148 
149 public:
150 
151  // The following are only marked public for unit testing. Do not use
152  // these APIs directly as they may change at any time, and their direct
153  // use may be unstable. You have been warned.
154 
157 
158  virtual void set_vmcs(gsl::not_null<vmcs_intel_x64 *> vmcs)
159  { m_vmcs = vmcs; }
160 
161  virtual void set_state_save(gsl::not_null<state_save_intel_x64 *> state_save)
162  { m_state_save = state_save; }
163 
164 private:
165 
166 #ifdef INCLUDE_LIBCXX_UNITTESTS
167  void unittest_1001_containers_array() const;
168  void unittest_1002_containers_vector() const;
169  void unittest_1003_containers_deque() const;
170  void unittest_1004_containers_forward_list() const;
171  void unittest_1005_containers_list() const;
172  void unittest_1006_containers_stack() const;
173  void unittest_1007_containers_queue() const;
174  void unittest_1008_containers_priority_queue() const;
175  void unittest_1009_containers_set() const;
176  void unittest_100A_containers_map() const;
177 
178  void unittest_1100_io_cout() const;
179  void unittest_1101_io_manipulators() const;
180 #endif
181 
182 };
183 
184 #endif
virtual void set_vmcs(gsl::not_null< vmcs_intel_x64 *> vmcs)
virtual void handle_vmcall_data_binary_unformatted(const bfn::unique_map_ptr_x64< char > &imap, const bfn::unique_map_ptr_x64< char > &omap)
void reply_with_string(vmcall_registers_t &regs, const std::string &str, const bfn::unique_map_ptr_x64< char > &omap)
virtual void handle_exit(intel_x64::vmcs::value_type reason)
virtual void handle_vmcall_registers(vmcall_registers_t &regs)
void reply_with_json(vmcall_registers_t &regs, const json &str, const bfn::unique_map_ptr_x64< char > &omap)
virtual void handle_vmcall_start(vmcall_registers_t &regs)
virtual ~exit_handler_intel_x64()=default
virtual void handle_vmcall_data(vmcall_registers_t &regs)
uint32_t value_type
Definition: cpuid_x64.h:41
virtual void handle_vmcall_event(vmcall_registers_t &regs)
void uint64_t uint64_t uint64_t *rdx noexcept
virtual void handle_vmcall_stop(vmcall_registers_t &regs)
virtual void set_state_save(gsl::not_null< state_save_intel_x64 *> state_save)
virtual void handle_vmcall_data_string_json(const json &ijson, json &ojson)
virtual void complete_vmcall(ret_type ret, vmcall_registers_t &regs) noexcept
virtual void halt() noexcept
virtual void handle_vmcall_unittest(vmcall_registers_t &regs)
virtual void handle_vmcall_data_string_unformatted(const std::string &istr, std::string &ostr)
virtual void handle_vmcall_versions(vmcall_registers_t &regs)
state_save_intel_x64 * m_state_save