L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
exceptions
Go to the documentation of this file.
1// vi:set ft=cpp: -*- Mode: C++ -*-
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
11 *
12 * License: see LICENSE.spdx (in this directory or the directories above)
13 */
14#pragma once
15
16#include <l4/cxx/l4types.h>
17#include <l4/cxx/basic_ostream>
18#include <l4/sys/err.h>
19#include <l4/sys/capability>
20
21
28#ifndef L4_CXX_NO_EXCEPTION_BACKTRACE
29# define L4_CXX_EXCEPTION_BACKTRACE 20
30#endif
31
32#if defined(L4_CXX_EXCEPTION_BACKTRACE)
33#include <l4/util/backtrace.h>
34#endif
35
37namespace L4
38{
52 {
53#if defined(L4_CXX_EXCEPTION_BACKTRACE)
54 private:
55 void *_pc_array[L4_CXX_EXCEPTION_BACKTRACE];
56 int _frame_cnt;
57
58 protected:
62#if defined(__PIC__)
63 Exception_tracer() noexcept : _frame_cnt(0) {}
64#else
66 : _frame_cnt(l4util_backtrace(_pc_array, L4_CXX_EXCEPTION_BACKTRACE)) {}
67#endif
68
69 public:
73 void const *const *pc_array() const noexcept { return _pc_array; }
77 int frame_count() const noexcept { return _frame_cnt; }
78#else
79 protected:
83 Exception_tracer() noexcept {}
84
85 public:
89 void const *const *pc_array() const noexcept { return 0; }
93 int frame_count() const noexcept { return 0; }
94#endif
95 };
96
106 {
107 protected:
109 Base_exception() noexcept {}
110
111 public:
115 virtual char const *str() const noexcept = 0;
116
118 virtual ~Base_exception() noexcept {}
119 };
120
129 {
130 private:
131 long _errno;
132 char _extra[80];
133
134 public:
141 explicit Runtime_error(long err_no, char const *extra = 0) noexcept
142 : _errno(err_no)
143 {
144 if (!extra)
145 _extra[0] = 0;
146 else
147 {
148 unsigned i = 0;
149 for (; i < sizeof(_extra) && extra[i]; ++i)
150 _extra[i] = extra[i];
151 _extra[i < sizeof(_extra) ? i : sizeof(_extra) - 1] = 0;
152 }
153 }
154 char const *str() const noexcept override
155 { return l4sys_errtostr(_errno); }
156
162 char const *extra_str() const { return _extra; }
163 ~Runtime_error() noexcept {}
164
170 long err_no() const noexcept { return _errno; }
171 };
172
178 {
179 public:
181 explicit Out_of_memory(char const *extra = "") noexcept
182 : Runtime_error(-L4_ENOMEM, extra) {}
184 ~Out_of_memory() noexcept {}
185 };
186
187
193 {
194 public:
195 explicit Element_already_exists(char const *e = "") noexcept
196 : Runtime_error(-L4_EEXIST, e) {}
197 ~Element_already_exists() noexcept {}
198 };
199
209 {
210 public:
211 Unknown_error() noexcept {}
212 char const *str() const noexcept override { return "unknown error"; }
213 ~Unknown_error() noexcept {}
214 };
215
221 {
222 public:
223 explicit Element_not_found(char const *e = "") noexcept
224 : Runtime_error(-L4_ENOENT, e) {}
225 };
226
235 {
236 private:
237 Cap<void> const _o;
238
239 public:
244 explicit Invalid_capability(Cap<void> const &o) noexcept : _o(o) {}
245 template< typename T>
246 explicit Invalid_capability(Cap<T> const &o) noexcept : _o(o.cap()) {}
247 char const *str() const noexcept override { return "invalid object"; }
248
253 Cap<void> const &cap() const noexcept { return _o; }
254 ~Invalid_capability() noexcept {}
255 };
256
264 {
265 public:
270 explicit Com_error(long err) noexcept : Runtime_error(err) {}
271
272 ~Com_error() noexcept {}
273 };
274
279 {
280 public:
281 explicit Bounds_error(char const *e = "") noexcept
282 : Runtime_error(-L4_ERANGE, e) {}
283 ~Bounds_error() noexcept {}
284 };
286};
287
288inline
289L4::BasicOStream &
290operator << (L4::BasicOStream &o, L4::Base_exception const &e)
291{
292 o << "Exception: " << e.str() << ", backtrace ...\n";
293 for (int i = 0; i < e.frame_count(); ++i)
294 o << L4::n_hex(l4_addr_t(e.pc_array()[i])) << '\n';
295
296 return o;
297}
298
299inline
300L4::BasicOStream &
301operator << (L4::BasicOStream &o, L4::Runtime_error const &e)
302{
303 o << "Exception: " << e.str() << ": ";
304 if (e.extra_str())
305 o << e.extra_str() << ": ";
306 o << "backtrace ...\n";
307 for (int i = 0; i < e.frame_count(); ++i)
308 o << L4::n_hex(l4_addr_t(e.pc_array()[i])) << '\n';
309
310 return o;
311}
Backtrace.
int l4util_backtrace(void **pc_array, int max_len)
Fill backtrace structure.
Basic IO stream.
L4::Cap related definitions.
Base class for all exceptions, thrown by the L4Re framework.
Definition exceptions:106
virtual char const * str() const noexcept=0
Return a human readable string for the exception.
Base_exception() noexcept
Create a base exception.
Definition exceptions:109
Access out of bounds.
Definition exceptions:279
C++ interface for capabilities.
Definition capability.h:219
Error conditions during IPC.
Definition exceptions:264
Com_error(long err) noexcept
Create a Com_error for the given L4 IPC error code.
Definition exceptions:270
Exception for duplicate element insertions.
Definition exceptions:193
Exception for a failed lookup (element not found).
Definition exceptions:221
Back-trace support for exceptions.
Definition exceptions:52
void const *const * pc_array() const noexcept
Get the array containing the call trace.
Definition exceptions:73
Exception_tracer() noexcept
Create a back trace.
Definition exceptions:65
int frame_count() const noexcept
Get the number of entries that are valid in the call trace.
Definition exceptions:77
Indicates that an invalid object was invoked.
Definition exceptions:235
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:247
Invalid_capability(Cap< void > const &o) noexcept
Create an Invalid_object exception for the Object o.
Definition exceptions:244
Cap< void > const & cap() const noexcept
Get the object that caused the error.
Definition exceptions:253
Exception signalling insufficient memory.
Definition exceptions:178
Out_of_memory(char const *extra="") noexcept
Create an out-of-memory exception.
Definition exceptions:181
~Out_of_memory() noexcept
Destruction.
Definition exceptions:184
Exception for an abstract runtime error.
Definition exceptions:129
long err_no() const noexcept
Get the error value for this runtime error.
Definition exceptions:170
char const * extra_str() const
Get the description text for this runtime error.
Definition exceptions:162
Runtime_error(long err_no, char const *extra=0) noexcept
Create a new Runtime_error.
Definition exceptions:141
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:154
Exception for an unknown condition.
Definition exceptions:209
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:212
Error codes.
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
@ L4_EEXIST
Already exists.
Definition err.h:43
@ L4_ENOENT
No such entity.
Definition err.h:34
@ L4_ERANGE
Range error.
Definition err.h:48
@ L4_ENOMEM
No memory.
Definition err.h:39
#define L4_CXX_EXCEPTION_BACKTRACE
Number of instruction pointers in backtrace.
Definition exceptions:29
L4 Types.
L4 low-level kernel interface.