vcpu_manager.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 VCPU_MANAGER_H
23 #define VCPU_MANAGER_H
24 
25 #include <map>
26 #include <memory>
27 
28 #include <vcpuid.h>
29 #include <user_data.h>
30 #include <vcpu/vcpu_factory.h>
31 
40 {
41 public:
42 
48  virtual ~vcpu_manager() = default;
49 
57  static vcpu_manager *instance() noexcept;
58 
71  virtual void create_vcpu(vcpuid::type vcpuid, user_data *data = nullptr);
72 
81  virtual void delete_vcpu(vcpuid::type vcpuid, user_data *data = nullptr);
82 
94  virtual void run_vcpu(vcpuid::type vcpuid, user_data *data = nullptr);
95 
107  virtual void hlt_vcpu(vcpuid::type vcpuid, user_data *data = nullptr);
108 
119  virtual void write(vcpuid::type vcpuid, const std::string &str) noexcept;
120 
121 private:
122 
124  std::unique_ptr<vcpu> &add_vcpu(vcpuid::type vcpuid, user_data *data);
125  std::unique_ptr<vcpu> &get_vcpu(vcpuid::type vcpuid);
126 
127 private:
128 
129  friend class vcpu_ut;
130 
131  std::map<vcpuid::type, std::unique_ptr<vcpu>> m_vcpus;
132 
133 private:
134 
135  std::unique_ptr<vcpu_factory> m_vcpu_factory;
136 
137  void set_factory(std::unique_ptr<vcpu_factory> factory)
138  { m_vcpu_factory = std::move(factory); }
139 
140 public:
141 
142  vcpu_manager(const vcpu_manager &) = delete;
143  vcpu_manager &operator=(const vcpu_manager &) = delete;
144 };
145 
155 #define g_vcm vcpu_manager::instance()
156 
157 #endif
virtual void run_vcpu(vcpuid::type vcpuid, user_data *data=nullptr)
virtual ~vcpu_manager()=default
uint64_t type
Definition: vcpuid.h:31
int64_t unsigned long void * data
vcpu_manager & operator=(const vcpu_manager &)=delete
Definition: test.h:27
Definition: vcpuid.h:29
virtual void create_vcpu(vcpuid::type vcpuid, user_data *data=nullptr)
void uint64_t uint64_t uint64_t *rdx noexcept
virtual void write(vcpuid::type vcpuid, const std::string &str) noexcept
virtual void hlt_vcpu(vcpuid::type vcpuid, user_data *data=nullptr)
virtual void delete_vcpu(vcpuid::type vcpuid, user_data *data=nullptr)
static vcpu_manager * instance() noexcept