entry.cpp
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 #include <gsl/gsl>
23 
24 #include <debug.h>
25 #include <vcpuid.h>
26 #include <user_data.h>
27 
28 #include <entry/entry.h>
29 #include <guard_exceptions.h>
30 #include <vcpu/vcpu_manager.h>
31 
32 user_data *
33 __attribute__((weak)) pre_create_vcpu(vcpuid::type id)
34 { (void) id; return nullptr; }
35 
36 user_data *
37 __attribute__((weak)) pre_run_vcpu(vcpuid::type id)
38 { (void) id; return nullptr; }
39 
40 extern "C" int64_t
41 start_vmm(uint64_t arg) noexcept
42 {
44  {
45  g_vcm->create_vcpu(arg, pre_create_vcpu(arg));
46 
47  auto ___ = gsl::on_failure([&]
48  { g_vcm->delete_vcpu(arg); });
49 
50  g_vcm->run_vcpu(arg, pre_run_vcpu(arg));
51 
52  bfdebug << "success: host os is " << bfcolor_green "now " << bfcolor_end
53  << "in a vm on vcpuid = " << arg << bfendl;
54 
55  return ENTRY_SUCCESS;
56  });
57 }
58 
59 user_data *
60 __attribute__((weak)) pre_hlt_vcpu(vcpuid::type id)
61 { (void) id; return nullptr; }
62 
63 user_data *
64 __attribute__((weak)) pre_delete_vcpu(vcpuid::type id)
65 { (void) id; return nullptr; }
66 
67 extern "C" int64_t
68 stop_vmm(uint64_t arg) noexcept
69 {
71  {
72  g_vcm->hlt_vcpu(arg, pre_hlt_vcpu(arg));
73  g_vcm->delete_vcpu(arg, pre_delete_vcpu(arg));
74 
75  bfdebug << "success: host os is " << bfcolor_red "not " << bfcolor_end
76  << "in a vm on vcpuid = " << arg << bfendl;
77 
78  return ENTRY_SUCCESS;
79  });
80 }
#define ENTRY_ERROR_VMM_START_FAILED
Definition: error_codes.h:51
user_data * __attribute__((weak)) pre_create_vcpu(vcpuid
Definition: entry.cpp:33
uint64_t type
Definition: vcpuid.h:31
int64_t stop_vmm(uint64_t arg) noexcept
Definition: entry.cpp:68
void uint64_t uint64_t uint64_t *rdx noexcept
int64_t start_vmm(uint64_t arg) noexcept
Definition: entry.cpp:41
#define ENTRY_SUCCESS
Definition: error_codes.h:48
E guard_exceptions(E error_code, T func)
#define ENTRY_ERROR_VMM_STOP_FAILED
Definition: error_codes.h:52
#define g_vcm
Definition: vcpu_manager.h:155