vcpu.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_H
23 #define VCPU_H
24 
25 #include <string>
26 #include <memory>
27 
28 #include <vcpuid.h>
29 #include <user_data.h>
30 #include <debug_ring/debug_ring.h>
31 
94 class vcpu
95 {
96 public:
97 
113  vcpu(vcpuid::type id, std::unique_ptr<debug_ring> dr = nullptr);
114 
120  virtual ~vcpu() = default;
121 
137  virtual void init(user_data *data = nullptr);
138 
154  virtual void fini(user_data *data = nullptr);
155 
174  virtual void run(user_data *data = nullptr);
175 
200  virtual void hlt(user_data *data = nullptr);
201 
209  virtual vcpuid::type id() const
210  { return m_id; }
211 
219  virtual bool is_running()
220  { return m_is_running; }
221 
229  virtual bool is_initialized()
230  { return m_is_initialized; }
231 
239  virtual bool is_bootstrap_vcpu()
240  { return m_id == 0; }
241 
249  virtual bool is_host_vm_vcpu()
250  { return (m_id & (vcpuid::guest_mask & ~vcpuid::reserved)) == 0; }
251 
259  virtual bool is_guest_vm_vcpu()
260  { return (m_id & (vcpuid::guest_mask & ~vcpuid::reserved)) != 0; }
261 
284  virtual void write(const std::string &str) noexcept;
285 
286 private:
287 
288  vcpuid::type m_id;
289  std::unique_ptr<debug_ring> m_debug_ring;
290 
291  bool m_is_running;
292  bool m_is_initialized;
293 
294 public:
295 
296  vcpu(vcpu &&) = default;
297  vcpu &operator=(vcpu &&) = default;
298 
299  vcpu(const vcpu &) = delete;
300  vcpu &operator=(const vcpu &) = delete;
301 };
302 
303 #endif
virtual bool is_running()
Definition: vcpu.h:219
uint64_t type
Definition: vcpuid.h:31
int64_t unsigned long void * data
virtual void run(user_data *data=nullptr)
Definition: vcpu.cpp:58
Definition: vcpu.h:94
void uint64_t uint64_t uint64_t *rdx noexcept
virtual void init(user_data *data=nullptr)
Definition: vcpu.cpp:39
virtual bool is_host_vm_vcpu()
Definition: vcpu.h:249
virtual ~vcpu()=default
virtual bool is_bootstrap_vcpu()
Definition: vcpu.h:239
constexpr const auto reserved
Definition: vcpuid.h:33
virtual void hlt(user_data *data=nullptr)
Definition: vcpu.cpp:66
virtual bool is_guest_vm_vcpu()
Definition: vcpu.h:259
constexpr const auto guest_mask
Definition: vcpuid.h:38
vcpu(vcpuid::type id, std::unique_ptr< debug_ring > dr=nullptr)
Definition: vcpu.cpp:25
vcpu & operator=(vcpu &&)=default
debug_ring * dr
virtual vcpuid::type id() const
Definition: vcpu.h:209
virtual void write(const std::string &str) noexcept
Definition: vcpu.cpp:74
virtual bool is_initialized()
Definition: vcpu.h:229
virtual void fini(user_data *data=nullptr)
Definition: vcpu.cpp:47