L4Re - L4 Runtime Environment
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  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU General Public License 2.
13  * Please see the COPYING-GPL-2 file for details.
14  *
15  * As a special exception, you may use this file as part of a free software
16  * library without restriction. Specifically, if other files instantiate
17  * templates or use macros or inline functions from this file, or you compile
18  * this file and link it with other files to produce an executable, this
19  * file does not by itself cause the resulting executable to be covered by
20  * the GNU General Public License. This exception does not however
21  * invalidate any other reasons why the executable file might be covered by
22  * the GNU General Public License.
23  */
24 
25 #pragma once
26 
27 #include <l4/sys/factory.h>
28 #include <l4/sys/capability>
29 #include <l4/sys/cxx/ipc_iface>
30 #include <l4/sys/cxx/ipc_varg>
31 
32 namespace L4 {
33 
48 class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
49 {
50 public:
51 
52  typedef l4_mword_t Proto;
53 
57  struct Nil {};
58 
64  struct Lstr
65  {
69  char const *s;
70 
74  unsigned len;
75 
80  Lstr(char const *s, unsigned len) noexcept : s(s), len(len) {}
81  };
82 
89  class S
90  {
91  private:
92  l4_utcb_t *u;
93  l4_msgtag_t t;
94  l4_cap_idx_t f;
95 
96  template<typename T>
97  static T &&_move(T &c) { return static_cast<T &&>(c); }
98 
99  public:
100  S(S const &) = delete;
101  S &operator = (S const &) & = delete;
102 
108  S(S &&o) noexcept
109  : u(o.u), t(o.t), f(o.f)
110  { o.t.raw = 0; }
111 
112  S &operator = (S &&o) & noexcept
113  {
114  u = o.u;
115  t = o.t;
116  f = o.f;
117  o.t.raw = 0;
118  return *this;
119  }
120 
132  S(l4_cap_idx_t f, long obj, L4::Cap<void> target,
133  l4_utcb_t *utcb) noexcept
134  : u(utcb), t(l4_factory_create_start_u(obj, target.cap(), u)), f(f)
135  {}
136 
141  ~S() noexcept
142  {
143  if (t.raw)
144  l4_factory_create_commit_u(f, t, u);
145  }
146 
152  operator l4_msgtag_t () noexcept
153  {
154  l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
155  t.raw = 0;
156  return r;
157  }
158 
166  void put(l4_mword_t i) noexcept
167  {
168  l4_factory_create_add_int_u(i, &t, u);
169  }
170 
178  void put(l4_umword_t i) noexcept
179  {
180  l4_factory_create_add_uint_u(i, &t, u);
181  }
182 
192  void put(char const *s) & noexcept
193  {
194  l4_factory_create_add_str_u(s, &t, u);
195  }
196 
208  void put(Lstr const &s) & noexcept
209  {
210  l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
211  }
212 
218  void put(Nil) & noexcept
219  {
220  l4_factory_create_add_nil_u(&t, u);
221  }
222 
230  void put(l4_fpage_t d) & noexcept
231  {
232  l4_factory_create_add_fpage_u(d, &t, u);
233  }
234 
235  template<typename T>
236  S &operator << (T const &d) & noexcept
237  {
238  put(d);
239  return *this;
240  }
241 
242  template<typename T>
243  S &&operator << (T const &d) && noexcept
244  {
245  put(d);
246  return _move(*this);
247  }
248  };
249 
250 
251 public:
252 
277  S create(Cap<void> target, long obj, l4_utcb_t *utcb = l4_utcb()) noexcept
278  {
279  return S(cap(), obj, target, utcb);
280  }
281 
307  template<typename OBJ>
308  S create(Cap<OBJ> target, l4_utcb_t *utcb = l4_utcb()) noexcept
309  {
310  return S(cap(), OBJ::Protocol, target, utcb);
311  }
312 
315  L4::Ipc::Varg const *args),
317 
341  l4_msgtag_t create_task(Cap<Task> const & target_cap,
342  l4_fpage_t const &utcb_area,
343  l4_utcb_t *utcb = l4_utcb()) noexcept
344  { return l4_factory_create_task_u(cap(), target_cap.cap(), utcb_area, utcb); }
345 
360  l4_utcb_t *utcb = l4_utcb()) noexcept
361  L4_DEPRECATED("Call create with Cap<Thread> as argument instead.")
362  { return l4_factory_create_thread_u(cap(), target_cap.cap(), utcb); }
363 
384  unsigned long limit,
385  l4_utcb_t *utcb = l4_utcb()) noexcept
386  { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
387 
416  l4_msgtag_t create_gate(Cap<void> const &target_cap,
417  Cap<Thread> const &thread_cap, l4_umword_t label,
418  l4_utcb_t *utcb = l4_utcb()) noexcept
419  { return l4_factory_create_gate_u(cap(), target_cap.cap(), thread_cap.cap(), label, utcb); }
420 
434  l4_msgtag_t create_irq(Cap<Irq>const &target_cap,
435  l4_utcb_t *utcb = l4_utcb()) throw()
436  L4_DEPRECATED("Call create with Cap<Irq> as argument instead.")
437  { return l4_factory_create_irq_u(cap(), target_cap.cap(), utcb); }
438 
452  l4_msgtag_t create_vm(Cap<Vm>const &target_cap,
453  l4_utcb_t *utcb = l4_utcb()) noexcept
454  L4_DEPRECATED("Call create with Cap<Vm> as argument instead.")
455  { return l4_factory_create_vm_u(cap(), target_cap.cap(), utcb); }
456 
458 };
459 
460 }
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:416
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition: capability.h:52
l4_msgtag_t create_vm(Cap< Vm >const &target_cap, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new virtual machine.
Definition: factory:452
void put(Nil) &noexcept
Add an empty argument.
Definition: factory:218
l4_msgtag_t create_irq(Cap< Irq >const &target_cap, l4_utcb_t *utcb=l4_utcb())
Create a new IRQ.
Definition: factory:434
C++ Factory interface.
Definition: factory:48
l4_msgtag_t l4_factory_create_vm_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW
Create a new virtual machine.
Definition: factory.h:347
l4_mword_t raw
raw value
Definition: types.h:161
signed long l4_mword_t
Signed machine word.
Definition: l4int.h:49
Variably sized RPC argument.
Definition: ipc_varg:96
char const * s
The character buffer.
Definition: factory:69
L4 low-level kernel interface.
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:132
S(S &&o) noexcept
Move ...
Definition: factory:108
C++ Irq interface.
Definition: irq:117
Special type to add a void argument into the factory create stream.
Definition: factory:57
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
Special type to add a pascal string into the factory create stream.
Definition: factory:64
S create(Cap< void > target, long obj, l4_utcb_t *utcb=l4_utcb()) noexcept
Generic create call to the factory.
Definition: factory:277
l4_msgtag_t l4_factory_create_factory_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, unsigned long limit, l4_utcb_t *utcb) L4_NOTHROW
Create a new factory.
Definition: factory.h:307
C++ L4 kernel thread interface.
Definition: thread:58
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
l4_msgtag_t l4_factory_create_gate_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_cap_idx_t thread_cap, l4_umword_t label, l4_utcb_t *utcb) L4_NOTHROW
Create a new IPC gate.
Definition: factory.h:318
Mark an argument as a output value in an RPC signature.
Definition: ipc_types:42
L4::Cap related definitions.
void put(Lstr const &s) &noexcept
Add a pascal string as next argument.
Definition: factory:208
Stream class for the create() argument stream.
Definition: factory:89
List of RPCs of an interface using a single operation without an opcode.
Definition: __typeinfo.h:464
l4_msgtag_t l4_factory_create_irq_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW
Create a new IRQ.
Definition: factory.h:340
l4_msgtag_t create_task(Cap< Task > const &target_cap, l4_fpage_t const &utcb_area, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new task.
Definition: factory:341
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:383
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
L4::Cap< Class > c() const noexcept
Get the capability to ourselves.
Definition: __typeinfo.h:779
Common factory related definitions.
Interface Definition Language.
void put(l4_mword_t i) noexcept
Put a single l4_mword_t as next argument.
Definition: factory:166
Virtual machine host address space.
Definition: __vm-arm.h:36
l4_msgtag_t l4_factory_create_thread_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW
Create a new thread.
Definition: factory.h:300
void put(l4_umword_t i) noexcept
Put a single l4_umword_t as next argument.
Definition: factory:178
~S() noexcept
Commit the operation in the destructor to have a cool syntax for create().
Definition: factory:141
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
void put(char const *s) &noexcept
Add a zero-terminated string as next argument.
Definition: factory:192
RPC attribute for an RPC call with required rights.
Definition: ipc_iface:257
l4_msgtag_t create_thread(Cap< Thread > const &target_cap, l4_utcb_t *utcb=l4_utcb()) noexcept
Create a new thread.
Definition: factory:359
l4_msgtag_t l4_factory_create_task_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_fpage_t utcb_area, l4_utcb_t *utcb) L4_NOTHROW
Create a new task.
Definition: factory.h:289
L4 flexpage type.
Definition: __l4_fpage.h:83
Helper class to create an L4Re interface class that is derived from a single base class...
Definition: __typeinfo.h:759
unsigned len
The number of characters in the buffer.
Definition: factory:74
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition: kobject:79
struct l4_msgtag_t l4_msgtag_t
Message tag data structure.
Lstr(char const *s, unsigned len) noexcept
Definition: factory:80
C++ interface for capabilities.
Definition: capability.h:13
S create(Cap< OBJ > target, l4_utcb_t *utcb=l4_utcb()) noexcept
Create call for typed capabilities.
Definition: factory:308
void put(l4_fpage_t d) &noexcept
Add a flex page as next argument.
Definition: factory:230
Message tag data structure.
Definition: types.h:159
#define L4_INLINE_RPC_NF(res, name, args...)
Define an inline RPC call type (the type only, no callable).
Definition: ipc_iface:440
#define L4_DEPRECATED(s)
Mark symbol deprecated.
Definition: compiler.h:243