L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
factory
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 * economic rights: Technische Universität Dresden (Germany)
10 *
11 * License: see LICENSE.spdx (in this directory or the directories above)
12 */
13
14#pragma once
15
16#include <l4/sys/factory.h>
17#include <l4/sys/capability>
18#include <l4/sys/cxx/ipc_iface>
19#include <l4/sys/cxx/ipc_varg>
20
21namespace L4 {
22
37class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
38{
39public:
40
41 typedef l4_mword_t Proto;
42
46 struct Nil {};
47
53 struct Lstr
54 {
58 char const *s;
59
63 unsigned len;
64
69 Lstr(char const *s, unsigned len) noexcept : s(s), len(len) {}
70 };
71
78 class S
79 {
80 private:
81 l4_utcb_t *u;
84
85 template<typename T>
86 static T &&_move(T &c) { return static_cast<T &&>(c); }
87
88 public:
89 S(S const &) = delete;
90 S &operator = (S const &) & = delete;
91
97 S(S &&o) noexcept
98 : u(o.u), t(o.t), f(o.f)
99 { o.t.raw = 0; }
100
101 S &operator = (S &&o) & noexcept
102 {
103 u = o.u;
104 t = o.t;
105 f = o.f;
106 o.t.raw = 0;
107 return *this;
108 }
109
124 S(l4_cap_idx_t f, long obj, L4::Cap<void> target,
125 l4_utcb_t *utcb) noexcept
126 : u(utcb), t(l4_factory_create_start_u(obj, target.cap(), u)), f(f)
127 {}
128
138 ~S() noexcept
139 {
140 if (t.raw)
141 l4_factory_create_commit_u(f, t, u);
142 }
143
156 operator l4_msgtag_t () noexcept
157 {
158 l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
159 t.raw = 0;
160 return r;
161 }
162
168 void put(l4_mword_t i) noexcept
169 {
170 l4_factory_create_add_int_u(i, &t, u);
171 }
172
178 void put(l4_umword_t i) noexcept
179 {
180 l4_factory_create_add_uint_u(i, &t, u);
181 }
182
190 void put(char const *s) & noexcept
191 {
192 l4_factory_create_add_str_u(s, &t, u);
193 }
194
204 void put(Lstr const &s) & noexcept
205 {
206 l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
207 }
208
212 void put(Nil) & noexcept
213 {
214 l4_factory_create_add_nil_u(&t, u);
215 }
216
222 void put(l4_fpage_t d) & noexcept
223 {
224 l4_factory_create_add_fpage_u(d, &t, u);
225 }
226
235 template<typename T>
236 S &operator << (T const &d) & noexcept
237 {
238 put(d);
239 return *this;
240 }
241
250 template<typename T>
251 S &&operator << (T const &d) && noexcept
252 {
253 put(d);
254 return _move(*this);
255 }
256 };
257
258
259public:
260
291 S create(Cap<void> target, long obj, l4_utcb_t *utcb = l4_utcb()) noexcept
292 {
293 return S(cap(), obj, target, utcb);
294 }
295
327 template<typename OBJ>
328 S create(Cap<OBJ> target, l4_utcb_t *utcb = l4_utcb()) noexcept
329 {
330 return S(cap(), OBJ::Protocol, target, utcb);
331 }
332
335 L4::Ipc::Varg const *args),
337
370 l4_fpage_t *utcb_area,
371 l4_utcb_t *utcb = l4_utcb()) noexcept
372 { return l4_factory_create_task_u(cap(), target_cap.cap(), utcb_area, utcb); }
373
404 unsigned long limit,
405 l4_utcb_t *utcb = l4_utcb()) noexcept
406 { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
407
439 Cap<Thread> const &thread_cap, l4_umword_t label,
440 l4_utcb_t *utcb = l4_utcb()) noexcept
441 { return l4_factory_create_gate_u(cap(), target_cap.cap(), thread_cap.cap(), label, utcb); }
442
444};
445
446}
L4::Cap related definitions.
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
C++ interface for capabilities.
Definition capability.h:224
Stream class for the create() argument stream.
Definition factory:79
S(S &&o) noexcept
Move constructor.
Definition factory:97
void put(Lstr const &s) &noexcept
Add a pascal string as next argument.
Definition factory:204
void put(l4_fpage_t d) &noexcept
Add a flexpage as next argument.
Definition factory:222
void put(l4_umword_t i) noexcept
Put a single l4_umword_t as next argument.
Definition factory:178
S & operator<<(T const &d) &noexcept
Add next argument.
Definition factory:236
~S() noexcept
Commit the create() operation if not already done explicitly via operator l4_msgtag_t().
Definition factory:138
S(l4_cap_idx_t f, long obj, L4::Cap< void > target, l4_utcb_t *utcb) noexcept
Create a stream for a specific create() call.
Definition factory:124
void put(Nil) &noexcept
Add an empty argument.
Definition factory:212
void put(char const *s) &noexcept
Add a zero-terminated string as next argument.
Definition factory:190
void put(l4_mword_t i) noexcept
Put a single l4_mword_t as next argument.
Definition factory:168
C++ Factory interface, see Factory for the C interface.
Definition factory:38
l4_msgtag_t create_factory(Cap< Factory > const &target_cap, unsigned long limit, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new factory.
Definition factory:403
l4_msgtag_t create_task(Cap< Task > const &target_cap, l4_fpage_t *utcb_area, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new task.
Definition factory:369
l4_msgtag_t create_gate(Cap< void > const &target_cap, Cap< Thread > const &thread_cap, l4_umword_t label, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new IPC gate.
Definition factory:438
S create(Cap< void > target, long obj, l4_utcb_t *utcb=l4_utcb()) noexcept
Generic create call to the factory.
Definition factory:291
S create(Cap< OBJ > target, l4_utcb_t *utcb=l4_utcb()) noexcept
Create call for typed capabilities.
Definition factory:328
Variably sized RPC argument.
Definition ipc_varg:97
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
L4::Cap< Class > c() const noexcept
Get the capability to ourselves.
Definition __typeinfo.h:769
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition kobject:69
Common factory related definitions.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
signed long l4_mword_t
Signed machine word.
Definition l4int.h:37
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
Interface Definition Language.
#define L4_INLINE_RPC_NF(res, name, args...)
Define an inline RPC call type (the type only, no callable).
Definition ipc_iface:453
L4 low-level kernel interface.
Special type to add a pascal string into the factory create stream.
Definition factory:54
Lstr(char const *s, unsigned len) noexcept
Definition factory:69
unsigned len
The number of characters in the buffer.
Definition factory:63
char const * s
The character buffer.
Definition factory:58
Special type to add a void argument into the factory create stream.
Definition factory:46
RPC attribute for an RPC call with required rights.
Definition ipc_iface:271
Mark an argument as a output value in an RPC signature.
Definition ipc_types:31
List of RPCs of an interface using a single operation without an opcode.
Definition __typeinfo.h:454
Message tag data structure.
Definition types.h:153
l4_mword_t raw
raw value
Definition types.h:154
L4 flexpage type.
Definition __l4_fpage.h:76