L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
error_helper
Go to the documentation of this file.
1// vi:set ft=cpp: -*- Mode: C++ -*-
6/*
7 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8 * Alexander Warg <warg@os.inf.tu-dresden.de>,
9 * Torsten Frenzel <frenzel@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/sys/types.h>
28#include <l4/cxx/exceptions>
29#include <l4/cxx/type_traits>
30#include <l4/sys/err.h>
31
32namespace L4Re {
33
34#ifdef __EXCEPTIONS
35
45[[noreturn]] inline void throw_error(long err, char const *extra = "")
46{
47 switch (err)
48 {
49 case -L4_ENOENT: throw (L4::Element_not_found(extra));
50 case -L4_ENOMEM: throw (L4::Out_of_memory(extra));
51 case -L4_EEXIST: throw (L4::Element_already_exists(extra));
52 case -L4_ERANGE: throw (L4::Bounds_error(extra));
53 default: throw (L4::Runtime_error(err, extra));
54 }
55}
56
67inline
68long chksys(long err, char const *extra = "", long ret = 0)
69{
70 if (L4_UNLIKELY(err < 0))
71 throw_error(ret ? ret : err, extra);
72
73 return err;
74}
75
88inline
89long chksys(l4_msgtag_t const &t, char const *extra = "",
90 l4_utcb_t *utcb = l4_utcb(), long ret = 0)
91{
92 if (L4_UNLIKELY(t.has_error()))
93 throw_error(ret ? ret : l4_error_u(t, utcb), extra);
94 else if (L4_UNLIKELY(t.label() < 0))
95 throw_error(ret ? ret: t.label(), extra);
96
97 return t.label();
98}
99
111inline
112long chksys(l4_msgtag_t const &t, l4_utcb_t *utcb, char const *extra = "")
113{ return chksys(t, extra, utcb); }
114
115#if 0
116inline
117long chksys(long ret, long err, char const *extra = "")
118{
119 if (L4_UNLIKELY(ret < 0))
120 throw_error(err, extra);
121
122 return ret;
123}
124#endif
125
142template<typename T>
143inline
144#if __cplusplus >= 201103L
145T chkcap(T &&cap, char const *extra = "", long err = -L4_ENOMEM)
146#else
147T chkcap(T cap, char const *extra = "", long err = -L4_ENOMEM)
148#endif
149{
150 if (L4_UNLIKELY(!cap.is_valid()))
151 throw_error(err ? err : cap.cap(), extra);
152
153#if __cplusplus >= 201103L
154 return cxx::forward<T>(cap);
155#else
156 return cap;
157#endif
158}
159
174inline
176chkipc(l4_msgtag_t tag, char const *extra = "",
177 l4_utcb_t *utcb = l4_utcb())
178{
179 if (L4_UNLIKELY(tag.has_error()))
180 chksys(l4_error_u(tag, utcb), extra);
181
182 return tag;
183}
184#endif
185
186}
Access out of bounds.
Definition exceptions:290
Exception for duplicate element insertions.
Definition exceptions:204
Exception for a failed lookup (element not found).
Definition exceptions:232
Exception signalling insufficient memory.
Definition exceptions:189
Exception for an abstract runtime error.
Definition exceptions:140
Error codes.
Base exceptions.
@ 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
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:296
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition l4re.dox:17
long chksys(long err, char const *extra="", long ret=0)
Generate C++ exception on error.
Definition error_helper:68
T chkcap(T &&cap, char const *extra="", long err=-L4_ENOMEM)
Check for valid capability or raise C++ exception.
Definition error_helper:145
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:176
void throw_error(long err, char const *extra="")
Generate C++ exception.
Definition error_helper:45
Message tag data structure.
Definition types.h:164
long label() const L4_NOTHROW
Get the protocol value.
Definition types.h:168
unsigned has_error() const L4_NOTHROW
Test if flags indicate an error.
Definition types.h:195