L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
15 *
16 * As a special exception, you may use this file as part of a free software
17 * library without restriction. Specifically, if other files instantiate
18 * templates or use macros or inline functions from this file, or you compile
19 * this file and link it with other files to produce an executable, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU General Public License. This exception does not however
22 * invalidate any other reasons why the executable file might be covered by
23 * the GNU General Public License.
24 */
25#pragma once
26
27#include <l4/cxx/l4types.h>
28#include <l4/cxx/basic_ostream>
29#include <l4/sys/err.h>
30#include <l4/sys/capability>
31
32
39#ifndef L4_CXX_NO_EXCEPTION_BACKTRACE
40# define L4_CXX_EXCEPTION_BACKTRACE 20
41#endif
42
43#if defined(L4_CXX_EXCEPTION_BACKTRACE)
44#include <l4/util/backtrace.h>
45#endif
46
48namespace L4
49{
63 {
64#if defined(L4_CXX_EXCEPTION_BACKTRACE)
65 private:
66 void *_pc_array[L4_CXX_EXCEPTION_BACKTRACE];
67 int _frame_cnt;
68
69 protected:
73#if defined(__PIC__)
74 Exception_tracer() noexcept : _frame_cnt(0) {}
75#else
77 : _frame_cnt(l4util_backtrace(_pc_array, L4_CXX_EXCEPTION_BACKTRACE)) {}
78#endif
79
80 public:
84 void const *const *pc_array() const noexcept { return _pc_array; }
88 int frame_count() const noexcept { return _frame_cnt; }
89#else
90 protected:
94 Exception_tracer() noexcept {}
95
96 public:
100 void const *const *pc_array() const noexcept { return 0; }
104 int frame_count() const noexcept { return 0; }
105#endif
106 };
107
117 {
118 protected:
120 Base_exception() noexcept {}
121
122 public:
126 virtual char const *str() const noexcept = 0;
127
129 virtual ~Base_exception() noexcept {}
130 };
131
140 {
141 private:
142 long _errno;
143 char _extra[80];
144
145 public:
152 explicit Runtime_error(long err_no, char const *extra = 0) noexcept
153 : _errno(err_no)
154 {
155 if (!extra)
156 _extra[0] = 0;
157 else
158 {
159 unsigned i = 0;
160 for (; i < sizeof(_extra) && extra[i]; ++i)
161 _extra[i] = extra[i];
162 _extra[i < sizeof(_extra) ? i : sizeof(_extra) - 1] = 0;
163 }
164 }
165 char const *str() const noexcept override
166 { return l4sys_errtostr(_errno); }
167
173 char const *extra_str() const { return _extra; }
174 ~Runtime_error() noexcept {}
175
181 long err_no() const noexcept { return _errno; }
182 };
183
189 {
190 public:
192 explicit Out_of_memory(char const *extra = "") noexcept
193 : Runtime_error(-L4_ENOMEM, extra) {}
195 ~Out_of_memory() noexcept {}
196 };
197
198
204 {
205 public:
206 explicit Element_already_exists(char const *e = "") noexcept
207 : Runtime_error(-L4_EEXIST, e) {}
208 ~Element_already_exists() noexcept {}
209 };
210
220 {
221 public:
222 Unknown_error() noexcept {}
223 char const *str() const noexcept override { return "unknown error"; }
224 ~Unknown_error() noexcept {}
225 };
226
232 {
233 public:
234 explicit Element_not_found(char const *e = "") noexcept
235 : Runtime_error(-L4_ENOENT, e) {}
236 };
237
246 {
247 private:
248 Cap<void> const _o;
249
250 public:
255 explicit Invalid_capability(Cap<void> const &o) noexcept : _o(o) {}
256 template< typename T>
257 explicit Invalid_capability(Cap<T> const &o) noexcept : _o(o.cap()) {}
258 char const *str() const noexcept override { return "invalid object"; }
259
264 Cap<void> const &cap() const noexcept { return _o; }
265 ~Invalid_capability() noexcept {}
266 };
267
275 {
276 public:
281 explicit Com_error(long err) noexcept : Runtime_error(err) {}
282
283 ~Com_error() noexcept {}
284 };
285
290 {
291 public:
292 explicit Bounds_error(char const *e = "") noexcept
293 : Runtime_error(-L4_ERANGE, e) {}
294 ~Bounds_error() noexcept {}
295 };
297};
298
299inline
300L4::BasicOStream &
301operator << (L4::BasicOStream &o, L4::Base_exception const &e)
302{
303 o << "Exception: " << e.str() << ", backtrace ...\n";
304 for (int i = 0; i < e.frame_count(); ++i)
305 o << L4::n_hex(l4_addr_t(e.pc_array()[i])) << '\n';
306
307 return o;
308}
309
310inline
311L4::BasicOStream &
312operator << (L4::BasicOStream &o, L4::Runtime_error const &e)
313{
314 o << "Exception: " << e.str() << ": ";
315 if (e.extra_str())
316 o << e.extra_str() << ": ";
317 o << "backtrace ...\n";
318 for (int i = 0; i < e.frame_count(); ++i)
319 o << L4::n_hex(l4_addr_t(e.pc_array()[i])) << '\n';
320
321 return o;
322}
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:117
virtual char const * str() const noexcept=0
Return a human readable string for the exception.
Base_exception() noexcept
Create a base exception.
Definition exceptions:120
Access out of bounds.
Definition exceptions:290
C++ interface for capabilities.
Definition capability.h:219
Error conditions during IPC.
Definition exceptions:275
Com_error(long err) noexcept
Create a Com_error for the given L4 IPC error code.
Definition exceptions:281
Exception for duplicate element insertions.
Definition exceptions:204
Exception for a failed lookup (element not found).
Definition exceptions:232
Back-trace support for exceptions.
Definition exceptions:63
void const *const * pc_array() const noexcept
Get the array containing the call trace.
Definition exceptions:84
Exception_tracer() noexcept
Create a back trace.
Definition exceptions:76
int frame_count() const noexcept
Get the number of entries that are valid in the call trace.
Definition exceptions:88
Indicates that an invalid object was invoked.
Definition exceptions:246
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:258
Invalid_capability(Cap< void > const &o) noexcept
Create an Invalid_object exception for the Object o.
Definition exceptions:255
Cap< void > const & cap() const noexcept
Get the object that caused the error.
Definition exceptions:264
Exception signalling insufficient memory.
Definition exceptions:189
Out_of_memory(char const *extra="") noexcept
Create an out-of-memory exception.
Definition exceptions:192
~Out_of_memory() noexcept
Destruction.
Definition exceptions:195
Exception for an abstract runtime error.
Definition exceptions:140
long err_no() const noexcept
Get the error value for this runtime error.
Definition exceptions:181
char const * extra_str() const
Get the description text for this runtime error.
Definition exceptions:173
Runtime_error(long err_no, char const *extra=0) noexcept
Create a new Runtime_error.
Definition exceptions:152
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:165
Exception for an unknown condition.
Definition exceptions:220
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:223
Error codes.
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
@ L4_EEXIST
Already exists.
Definition err.h:54
@ L4_ENOENT
No such entity.
Definition err.h:45
@ L4_ERANGE
Range error.
Definition err.h:59
@ L4_ENOMEM
No memory.
Definition err.h:50
#define L4_CXX_EXCEPTION_BACKTRACE
Number of instruction pointers in backtrace.
Definition exceptions:40
L4 Types.
L4 low-level kernel interface.
Definition io_regblock.h:19