misc.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 <unistd.h>
23 
24 #include <vcpu/vcpu_manager.h>
26 
27 extern "C" int
28 write(int file, const void *buffer, size_t count)
29 {
30  if (buffer == nullptr || count == 0)
31  return 0;
32 
33  if (file != 1 && file != 2)
34  return 0;
35 
36  try
37  {
38  std::string str(static_cast<const char *>(buffer), count);
39  if (str.length() >= 26 && str.compare(0, 8, "$vcpuid=") == 0)
40  {
41  str.erase(0, 8);
42 
43  auto vcpuid_str = str.substr(0, 18);
44  auto vcpuid_num = std::stoull(vcpuid_str, 0, 16);
45 
46  str.erase(0, 18);
47 
48  g_vcm->write(vcpuid_num, str);
49  return static_cast<int>(count);
50  }
51  else
52  {
53  g_vcm->write(0, str);
55  return static_cast<int>(count);
56  }
57  }
58  catch (...) { }
59 
60  return 0;
61 }
Definition: file.h:35
void write(char c) noexcept
int write(int file, const void *buffer, size_t count)
Definition: misc.cpp:28
static serial_port_intel_x64 * instance() noexcept
#define g_vcm
Definition: vcpu_manager.h:155