Loading...
Searching...
No Matches
error_helper
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>,
* Torsten Frenzel <frenzel@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/sys/types.h>
#include <l4/cxx/exceptions>
#include <l4/cxx/type_traits>
#include <l4/sys/err.h>
#include <stdarg.h>
#include <stdio.h>
namespace L4Re {
#ifdef __EXCEPTIONS
[[noreturn]] inline void throw_error(long err, char const *extra = "")
{
switch (err)
{
case -L4_ENOENT: throw (L4::Element_not_found(extra));
case -L4_ENOMEM: throw (L4::Out_of_memory(extra));
case -L4_EEXIST: throw (L4::Element_already_exists(extra));
case -L4_ERANGE: throw (L4::Bounds_error(extra));
default: throw (L4::Runtime_error(err, extra));
}
}
[[noreturn]] inline void throw_error_fmt(long err, char const *const fmt, ...)
__attribute__((format(printf, 2, 3)));
[[noreturn]] inline void throw_error_fmt(long err, char const *const fmt, ...)
{
char extra[80];
va_list argp;
va_start(argp, fmt);
vsnprintf(extra, sizeof(extra), fmt, argp);
va_end(argp);
throw_error(err, extra);
}
inline
long chksys(long err, char const *extra = "", long ret = 0)
{
if (L4_UNLIKELY(err < 0))
throw_error(ret ? ret : err, extra);
return err;
}
inline
long chksys(l4_msgtag_t const &t, char const *extra = "",
l4_utcb_t *utcb = l4_utcb(), long ret = 0)
{
if (L4_UNLIKELY(t.has_error()))
throw_error(ret ? ret : l4_error_u(t, utcb), extra);
else if (L4_UNLIKELY(t.label() < 0))
throw_error(ret ? ret: t.label(), extra);
return t.label();
}
inline
long chksys(l4_msgtag_t const &t, l4_utcb_t *utcb, char const *extra = "")
{ return chksys(t, extra, utcb); }
#if 0
inline
long chksys(long ret, long err, char const *extra = "")
{
if (L4_UNLIKELY(ret < 0))
throw_error(err, extra);
return ret;
}
#endif
template<typename T>
inline
#if __cplusplus >= 201103L
T chkcap(T &&cap, char const *extra = "", long err = -L4_ENOMEM)
#else
T chkcap(T cap, char const *extra = "", long err = -L4_ENOMEM)
#endif
{
if (L4_UNLIKELY(!cap.is_valid()))
throw_error(err ? err : cap.invalid_cap_error(), extra);
#if __cplusplus >= 201103L
return cxx::forward<T>(cap);
#else
return cap;
#endif
}
inline
l4_msgtag_t
chkipc(l4_msgtag_t tag, char const *extra = "",
l4_utcb_t *utcb = l4_utcb())
{
if (L4_UNLIKELY(tag.has_error()))
chksys(l4_error_u(tag, utcb), extra);
return tag;
}
#endif
}
L4::Bounds_error
Access out of bounds.
Definition exceptions:279
L4::Element_already_exists
Exception for duplicate element insertions.
Definition exceptions:193
L4::Element_not_found
Exception for a failed lookup (element not found).
Definition exceptions:221
L4::Out_of_memory
Exception signalling insufficient memory.
Definition exceptions:178
L4::Runtime_error
Exception for an abstract runtime error.
Definition exceptions:129
err.h
Error codes.
exceptions
Base exceptions.
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_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4_UNLIKELY
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:284
types.h
Common L4 ABI Data Types.
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4Re::chksys
long chksys(long err, char const *extra="", long ret=0)
Generate C++ exception on error.
Definition error_helper:72
L4Re::chkcap
T chkcap(T &&cap, char const *extra="", long err=-L4_ENOMEM)
Check for valid capability or raise C++ exception.
Definition error_helper:149
L4Re::chkipc
l4_msgtag_t chkipc(l4_msgtag_t tag, char const *extra="", l4_utcb_t *utcb=l4_utcb())
Test a message tag for IPC errors.
Definition error_helper:180
L4Re::throw_error
void throw_error(long err, char const *extra="")
Generate C++ exception.
Definition error_helper:37
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_msgtag_t::label
long label() const L4_NOTHROW
Get the protocol value.
Definition types.h:158
l4_msgtag_t::has_error
bool has_error() const L4_NOTHROW
Test if flags indicate an error.
Definition types.h:191