debug_ring_interface.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 
23 #ifndef DEBUG_RING_INTERFACE_H
24 #define DEBUG_RING_INTERFACE_H
25 
26 #pragma GCC system_header
27 
28 #include <types.h>
29 #include <constants.h>
30 #include <error_codes.h>
31 
32 #pragma pack(push, 1)
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
47 typedef struct debug_ring_resources_t *(*get_drr_t)(uint64_t vcpuid);
48 
96 {
97  uint64_t epos;
98  uint64_t spos;
99 
100  uint64_t tag1;
102  uint64_t tag2;
103 };
104 
123 extern inline uint64_t
124 debug_ring_read(struct debug_ring_resources_t *drr, char *str, uint64_t len)
125 {
126  uint64_t i;
127  uint64_t spos;
128  uint64_t content;
129 
130  if (drr == 0 || str == 0 || len == 0)
131  return 0;
132 
133  spos = drr->spos % DEBUG_RING_SIZE;
134  content = drr->epos - drr->spos;
135 
136  for (i = 0; i < content && i < len - 1; i++)
137  {
138  if (spos == DEBUG_RING_SIZE)
139  spos = 0;
140 
141  if (drr->buf[spos] != '\0')
142  str[i] = drr->buf[spos];
143  else
144  {
145  i--;
146  content--;
147  }
148 
149  spos++;
150  }
151 
152  str[i] = '\0';
153 
154  return content;
155 }
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #pragma pack(pop)
162 
163 #endif
char buf[DEBUG_RING_SIZE]
uint64_t debug_ring_read(struct debug_ring_resources_t *drr, char *str, uint64_t len)
Definition: vcpuid.h:29
debug_ring_resources_t * drr
#define DEBUG_RING_SIZE
Definition: constants.h:206