error_codes.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 ERROR_CODES_H
24 #define ERROR_CODES_H
25 
26 #include <types.h>
27 
28 /* -------------------------------------------------------------------------- */
29 /* Helper Macros */
30 /* -------------------------------------------------------------------------- */
31 
32 #ifdef __cplusplus
33 #define ec_sign(a) static_cast<int64_t>(a)
34 #else
35 #define ec_sign(a) ((int64_t)(a))
36 #endif
37 
38 /* -------------------------------------------------------------------------- */
39 /* Success */
40 /* -------------------------------------------------------------------------- */
41 
42 #define SUCCESS 0
43 
44 /* -------------------------------------------------------------------------- */
45 /* Entry Error Codes */
46 /* -------------------------------------------------------------------------- */
47 
48 #define ENTRY_SUCCESS ec_sign(SUCCESS)
49 #define ENTRY_ERROR_STACK_OVERFLOW ec_sign(0x8000000000000010)
50 #define ENTRY_ERROR_VMM_INIT_FAILED ec_sign(0x8000000000000020)
51 #define ENTRY_ERROR_VMM_START_FAILED ec_sign(0x8000000000000030)
52 #define ENTRY_ERROR_VMM_STOP_FAILED ec_sign(0x8000000000000040)
53 #define ENTRY_ERROR_UNKNOWN ec_sign(0x8000000000000050)
54 
55 /* -------------------------------------------------------------------------- */
56 /* C Runtime Error Codes */
57 /* -------------------------------------------------------------------------- */
58 
59 #define CRT_SUCCESS ec_sign(SUCCESS)
60 #define CRT_FAILURE ec_sign(0x8000000000000100)
61 
62 /* -------------------------------------------------------------------------- */
63 /* Unwinder Error Codes */
64 /* -------------------------------------------------------------------------- */
65 
66 #define REGISTER_EH_FRAME_SUCCESS ec_sign(SUCCESS)
67 #define REGISTER_EH_FRAME_FAILURE ec_sign(0x8000000000001000)
68 
69 /* -------------------------------------------------------------------------- */
70 /* Debug Ring Error Codes */
71 /* -------------------------------------------------------------------------- */
72 
73 #define GET_DRR_SUCCESS ec_sign(SUCCESS)
74 #define GET_DRR_FAILURE ec_sign(0x8000000000010000)
75 
76 /* -------------------------------------------------------------------------- */
77 /* ELF Loader Error Codes */
78 /* -------------------------------------------------------------------------- */
79 
80 #define BFELF_SUCCESS ec_sign(SUCCESS)
81 #define BFELF_ERROR_INVALID_ARG ec_sign(0x8000000000100000)
82 #define BFELF_ERROR_INVALID_FILE ec_sign(0x8000000000200000)
83 #define BFELF_ERROR_INVALID_INDEX ec_sign(0x8000000000300000)
84 #define BFELF_ERROR_INVALID_SIGNATURE ec_sign(0x8000000000500000)
85 #define BFELF_ERROR_UNSUPPORTED_FILE ec_sign(0x8000000000600000)
86 #define BFELF_ERROR_INVALID_SEGMENT ec_sign(0x8000000000700000)
87 #define BFELF_ERROR_INVALID_SECTION ec_sign(0x8000000000800000)
88 #define BFELF_ERROR_LOADER_FULL ec_sign(0x8000000000900000)
89 #define BFELF_ERROR_NO_SUCH_SYMBOL ec_sign(0x8000000000A00000)
90 #define BFELF_ERROR_MISMATCH ec_sign(0x8000000000B00000)
91 #define BFELF_ERROR_UNSUPPORTED_RELA ec_sign(0x8000000000C00000)
92 #define BFELF_ERROR_OUT_OF_ORDER ec_sign(0x8000000000D00000)
93 
94 /* -------------------------------------------------------------------------- */
95 /* Memory Manager Error Codes */
96 /* -------------------------------------------------------------------------- */
97 
98 #define MEMORY_MANAGER_SUCCESS ec_sign(SUCCESS)
99 #define MEMORY_MANAGER_FAILURE ec_sign(0x8000000001000000)
100 
101 /* -------------------------------------------------------------------------- */
102 /* Common Error Codes */
103 /* -------------------------------------------------------------------------- */
104 
105 #define BF_SUCCESS ec_sign(SUCCESS)
106 #define BF_ERROR_INVALID_ARG ec_sign(0x8000000010000000)
107 #define BF_ERROR_INVALID_INDEX ec_sign(0x8000000020000000)
108 #define BF_ERROR_NO_MODULES_ADDED ec_sign(0x8000000030000000)
109 #define BF_ERROR_MAX_MODULES_REACHED ec_sign(0x8000000040000000)
110 #define BF_ERROR_VMM_INVALID_STATE ec_sign(0x8000000050000000)
111 #define BF_ERROR_FAILED_TO_ADD_FILE ec_sign(0x8000000060000000)
112 #define BF_ERROR_FAILED_TO_DUMP_DR ec_sign(0x8000000070000000)
113 #define BF_ERROR_OUT_OF_MEMORY ec_sign(0x8000000080000000)
114 #define BF_ERROR_VMM_CORRUPTED ec_sign(0x8000000090000000)
115 #define BF_ERROR_UNKNOWN ec_sign(0x80000000A0000000)
116 
117 /* -------------------------------------------------------------------------- */
118 /* IOCTL Error Codes */
119 /* -------------------------------------------------------------------------- */
120 
121 #define BF_IOCTL_SUCCESS ec_sign(SUCCESS)
122 #define BF_IOCTL_FAILURE ec_sign(-1)
123 
124 /* -------------------------------------------------------------------------- */
125 /* Bad Alloc */
126 /* -------------------------------------------------------------------------- */
127 
128 #define BF_BAD_ALLOC ec_sign(0x8000000100000000)
129 
130 /* -------------------------------------------------------------------------- */
131 /* VMCall */
132 /* -------------------------------------------------------------------------- */
133 
134 #define BF_VMCALL_SUCCESS ec_sign(SUCCESS)
135 #define BF_VMCALL_FAILURE ec_sign(0x8000001000000000)
136 
137 /* -------------------------------------------------------------------------- */
138 /* Stringify Error Codes */
139 /* -------------------------------------------------------------------------- */
140 
141 #define EC_CASE(a) \
142  case a: return #a
143 
144 static inline const char *
145 ec_to_str(int64_t value)
146 {
147  switch (value)
148  {
149  EC_CASE(SUCCESS);
183 
184  default:
185  return "UNDEFINED_ERROR_CODE";
186  }
187 }
188 
189 #endif
#define BFELF_ERROR_UNSUPPORTED_RELA
Definition: error_codes.h:91
#define ENTRY_ERROR_VMM_START_FAILED
Definition: error_codes.h:51
#define BFELF_ERROR_INVALID_ARG
Definition: error_codes.h:81
#define BFELF_ERROR_NO_SUCH_SYMBOL
Definition: error_codes.h:89
#define BFELF_ERROR_INVALID_SECTION
Definition: error_codes.h:87
#define BF_ERROR_FAILED_TO_DUMP_DR
Definition: error_codes.h:112
#define BF_ERROR_VMM_INVALID_STATE
Definition: error_codes.h:110
#define BF_ERROR_MAX_MODULES_REACHED
Definition: error_codes.h:109
#define REGISTER_EH_FRAME_FAILURE
Definition: error_codes.h:67
#define MEMORY_MANAGER_FAILURE
Definition: error_codes.h:99
#define BFELF_ERROR_MISMATCH
Definition: error_codes.h:90
#define GET_DRR_FAILURE
Definition: error_codes.h:74
#define BFELF_ERROR_INVALID_INDEX
Definition: error_codes.h:83
#define BFELF_ERROR_UNSUPPORTED_FILE
Definition: error_codes.h:85
#define BFELF_ERROR_OUT_OF_ORDER
Definition: error_codes.h:92
#define BF_IOCTL_FAILURE
Definition: error_codes.h:122
#define BF_BAD_ALLOC
Definition: error_codes.h:128
#define ENTRY_ERROR_UNKNOWN
Definition: error_codes.h:53
#define CRT_FAILURE
Definition: error_codes.h:60
#define BFELF_ERROR_INVALID_FILE
Definition: error_codes.h:82
#define BF_ERROR_INVALID_INDEX
Definition: error_codes.h:107
#define BFELF_ERROR_INVALID_SEGMENT
Definition: error_codes.h:86
#define BFELF_ERROR_LOADER_FULL
Definition: error_codes.h:88
#define BFELF_ERROR_INVALID_SIGNATURE
Definition: error_codes.h:84
#define BF_ERROR_OUT_OF_MEMORY
Definition: error_codes.h:113
#define ENTRY_ERROR_STACK_OVERFLOW
Definition: error_codes.h:49
#define BF_ERROR_NO_MODULES_ADDED
Definition: error_codes.h:108
#define ENTRY_ERROR_VMM_STOP_FAILED
Definition: error_codes.h:52
#define BF_ERROR_INVALID_ARG
Definition: error_codes.h:106
#define EC_CASE(a)
Definition: error_codes.h:141
#define BF_ERROR_FAILED_TO_ADD_FILE
Definition: error_codes.h:111
#define BF_ERROR_VMM_CORRUPTED
Definition: error_codes.h:114
#define ENTRY_ERROR_VMM_INIT_FAILED
Definition: error_codes.h:50
#define SUCCESS
Definition: error_codes.h:42
#define BF_ERROR_UNKNOWN
Definition: error_codes.h:115