Loading...
Searching...
No Matches
exceptions
Go to the documentation of this file.
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/cxx/l4types.h>
#include <l4/cxx/basic_ostream>
#include <l4/sys/err.h>
#include <l4/sys/capability>
#ifndef L4_CXX_NO_EXCEPTION_BACKTRACE
# define L4_CXX_EXCEPTION_BACKTRACE 20
#endif
#if defined(L4_CXX_EXCEPTION_BACKTRACE)
#include <l4/util/backtrace.h>
#endif
namespace L4
{
class Exception_tracer
{
#if defined(L4_CXX_EXCEPTION_BACKTRACE)
private:
void *_pc_array[L4_CXX_EXCEPTION_BACKTRACE];
int _frame_cnt;
protected:
#if defined(__PIC__)
Exception_tracer() noexcept : _frame_cnt(0) {}
#else
Exception_tracer() noexcept
: _frame_cnt(l4util_backtrace(_pc_array, L4_CXX_EXCEPTION_BACKTRACE)) {}
#endif
public:
void const *const *pc_array() const noexcept { return _pc_array; }
int frame_count() const noexcept { return _frame_cnt; }
#else
protected:
Exception_tracer() noexcept {}
public:
void const *const *pc_array() const noexcept { return 0; }
int frame_count() const noexcept { return 0; }
#endif
};
class Base_exception : public Exception_tracer
{
protected:
Base_exception() noexcept {}
public:
virtual char const *str() const noexcept = 0;
virtual ~Base_exception() noexcept {}
};
class Runtime_error : public Base_exception
{
private:
long _errno;
char _extra[80];
public:
explicit Runtime_error(long err_no, char const *extra = 0) noexcept
: _errno(err_no)
{
if (!extra)
_extra[0] = 0;
else
{
unsigned i = 0;
for (; i < sizeof(_extra) && extra[i]; ++i)
_extra[i] = extra[i];
_extra[i < sizeof(_extra) ? i : sizeof(_extra) - 1] = 0;
}
}
char const *str() const noexcept override
{ return l4sys_errtostr(_errno); }
char const *extra_str() const { return _extra; }
~Runtime_error() noexcept {}
long err_no() const noexcept { return _errno; }
};
class Out_of_memory : public Runtime_error
{
public:
explicit Out_of_memory(char const *extra = "") noexcept
: Runtime_error(-L4_ENOMEM, extra) {}
~Out_of_memory() noexcept {}
};
class Element_already_exists : public Runtime_error
{
public:
explicit Element_already_exists(char const *e = "") noexcept
: Runtime_error(-L4_EEXIST, e) {}
~Element_already_exists() noexcept {}
};
class Unknown_error : public Base_exception
{
public:
Unknown_error() noexcept {}
char const *str() const noexcept override { return "unknown error"; }
~Unknown_error() noexcept {}
};
class Element_not_found : public Runtime_error
{
public:
explicit Element_not_found(char const *e = "") noexcept
: Runtime_error(-L4_ENOENT, e) {}
};
class Invalid_capability : public Base_exception
{
private:
Cap<void> const _o;
public:
explicit Invalid_capability(Cap<void> const &o) noexcept : _o(o) {}
template< typename T>
explicit Invalid_capability(Cap<T> const &o) noexcept : _o(o.cap()) {}
char const *str() const noexcept override { return "invalid object"; }
Cap<void> const &cap() const noexcept { return _o; }
~Invalid_capability() noexcept {}
};
class Com_error : public Runtime_error
{
public:
explicit Com_error(long err) noexcept : Runtime_error(err) {}
~Com_error() noexcept {}
};
class Bounds_error : public Runtime_error
{
public:
explicit Bounds_error(char const *e = "") noexcept
: Runtime_error(-L4_ERANGE, e) {}
~Bounds_error() noexcept {}
};
};
inline
L4::BasicOStream &
operator << (L4::BasicOStream &o, L4::Base_exception const &e)
{
o << "Exception: " << e.str() << ".\n";
o << "Backtrace:\n";
for (int i = 0; i < e.frame_count(); ++i)
o << " " << L4::n_hex(l4_addr_t(e.pc_array()[i])) << '\n';
return o;
}
inline
L4::BasicOStream &
operator << (L4::BasicOStream &o, L4::Runtime_error const &e)
{
o << "Exception: " << e.str();
if (e.extra_str())
o << ": " << e.extra_str();
o << "\n" << "Backtrace:\n";
for (int i = 0; i < e.frame_count(); ++i)
o << " " << L4::n_hex(l4_addr_t(e.pc_array()[i])) << '\n';
return o;
}
backtrace.h
Backtrace.
l4util_backtrace
L4_BEGIN_DECLS int l4util_backtrace(void **pc_array, int max_len)
Fill backtrace structure.
basic_ostream
Basic IO stream.
capability
L4::Cap related definitions.
L4::Base_exception
Base class for all exceptions, thrown by the L4Re framework.
Definition exceptions:106
L4::Base_exception::str
virtual char const * str() const noexcept=0
Return a human readable string for the exception.
L4::Base_exception::Base_exception
Base_exception() noexcept
Create a base exception.
Definition exceptions:109
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Com_error
Error conditions during IPC.
Definition exceptions:264
L4::Com_error::Com_error
Com_error(long err) noexcept
Create a Com_error for the given L4 IPC error code.
Definition exceptions:270
L4::Exception_tracer::pc_array
void const *const * pc_array() const noexcept
Get the array containing the call trace.
Definition exceptions:73
L4::Exception_tracer::Exception_tracer
Exception_tracer() noexcept
Create a back trace.
Definition exceptions:65
L4::Exception_tracer::frame_count
int frame_count() const noexcept
Get the number of entries that are valid in the call trace.
Definition exceptions:77
L4::Invalid_capability
Indicates that an invalid object was invoked.
Definition exceptions:235
L4::Invalid_capability::str
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:247
L4::Invalid_capability::Invalid_capability
Invalid_capability(Cap< void > const &o) noexcept
Create an Invalid_object exception for the Object o.
Definition exceptions:244
L4::Invalid_capability::cap
Cap< void > const & cap() const noexcept
Get the object that caused the error.
Definition exceptions:253
L4::Out_of_memory::Out_of_memory
Out_of_memory(char const *extra="") noexcept
Create an out-of-memory exception.
Definition exceptions:181
L4::Out_of_memory::~Out_of_memory
~Out_of_memory() noexcept
Destruction.
Definition exceptions:184
L4::Runtime_error
Exception for an abstract runtime error.
Definition exceptions:129
L4::Runtime_error::err_no
long err_no() const noexcept
Get the error value for this runtime error.
Definition exceptions:170
L4::Runtime_error::extra_str
char const * extra_str() const
Get the description text for this runtime error.
Definition exceptions:162
L4::Runtime_error::Runtime_error
Runtime_error(long err_no, char const *extra=0) noexcept
Create a new Runtime_error.
Definition exceptions:141
L4::Runtime_error::str
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:154
L4::Unknown_error
Exception for an unknown condition.
Definition exceptions:209
L4::Unknown_error::str
char const * str() const noexcept override
Return a human readable string for the exception.
Definition exceptions:212
err.h
Error codes.
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
L4_EEXIST
@ L4_EEXIST
Already exists.
Definition err.h:43
L4_ENOENT
@ L4_ENOENT
No such entity.
Definition err.h:34
L4_ERANGE
@ L4_ERANGE
Range error.
Definition err.h:48
L4_ENOMEM
@ L4_ENOMEM
No memory.
Definition err.h:39
L4_CXX_EXCEPTION_BACKTRACE
#define L4_CXX_EXCEPTION_BACKTRACE
Number of instruction pointers in backtrace.
Definition exceptions:29
l4types.h
L4 Types.
L4
L4 low-level kernel interface.
Definition l4sys-l4f-groups.dox:50