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 
55 class Factory : public Kobject_t<Factory, Kobject, L4_PROTO_FACTORY>
56 {
57 public:
58 
59  typedef l4_mword_t Proto;
60 
64  struct Nil {};
65 
71  struct Lstr
72  {
76  char const *s;
77 
81  int len;
82 
87  Lstr(char const *s, int len) : s(s), len(len) {}
88  };
89 
96  class S
97  {
98  private:
99  l4_utcb_t *u;
100  l4_msgtag_t t;
101  l4_cap_idx_t f;
102 
103  public:
109  S(S const &o)
110  : u(o.u), t(o.t), f(o.f)
111  { const_cast<S&>(o).t.raw = 0; }
112 
124  S(l4_cap_idx_t f, long obj, L4::Cap<void> target,
125  l4_utcb_t *utcb) throw()
126  : u(utcb), t(l4_factory_create_start_u(obj, target.cap(), u)), f(f)
127  {}
128 
133  ~S()
134  {
135  if (t.raw)
136  l4_factory_create_commit_u(f, t, u);
137  }
138 
144  operator l4_msgtag_t ()
145  {
146  l4_msgtag_t r = l4_factory_create_commit_u(f, t, u);
147  t.raw = 0;
148  return r;
149  }
150 
158  S &operator << (l4_mword_t i)
159  {
160  l4_factory_create_add_int_u(i, &t, u);
161  return *this;
162  }
163 
171  S &operator << (l4_umword_t i)
172  {
173  l4_factory_create_add_uint_u(i, &t, u);
174  return *this;
175  }
176 
186  S &operator << (char const *s)
187  {
188  l4_factory_create_add_str_u(s, &t, u);
189  return *this;
190  }
191 
203  S &operator << (Lstr const &s)
204  {
205  l4_factory_create_add_lstr_u(s.s, s.len, &t, u);
206  return *this;
207  }
208 
214  S &operator << (Nil)
215  {
216  l4_factory_create_add_nil_u(&t, u);
217  return *this;
218  }
219 
227  S &operator << (l4_fpage_t d)
228  {
229  l4_factory_create_add_fpage_u(d, &t, u);
230  return *this;
231  }
232  };
233 
234 
235 public:
236 
259  S create(Cap<void> target, long obj, l4_utcb_t *utcb = l4_utcb()) throw()
260  {
261  return S(cap(), obj, target, utcb);
262  }
263 
275  template<typename OBJ>
276  S create(Cap<OBJ> target, l4_utcb_t *utcb = l4_utcb()) throw()
277  {
278  return S(cap(), OBJ::Protocol, target, utcb);
279  }
280 
283  L4::Ipc::Varg const *args),
285 
306  l4_msgtag_t create_task(Cap<Task> const & target_cap,
307  l4_fpage_t const &utcb_area,
308  l4_utcb_t *utcb = l4_utcb()) throw()
309  { return l4_factory_create_task_u(cap(), target_cap.cap(), utcb_area, utcb); }
310 
325  l4_utcb_t *utcb = l4_utcb()) throw()
326  L4_DEPRECATED("Call create with Cap<Thread> as argument instead.")
327  { return l4_factory_create_thread_u(cap(), target_cap.cap(), utcb); }
328 
343  unsigned long limit,
344  l4_utcb_t *utcb = l4_utcb()) throw()
345  { return l4_factory_create_factory_u(cap(), target_cap.cap(), limit, utcb); }
346 
372  l4_msgtag_t create_gate(Cap<void> const &target_cap,
373  Cap<Thread> const &thread_cap, l4_umword_t label,
374  l4_utcb_t *utcb = l4_utcb()) throw()
375  { return l4_factory_create_gate_u(cap(), target_cap.cap(), thread_cap.cap(), label, utcb); }
376 
390  l4_msgtag_t create_irq(Cap<Irq>const &target_cap,
391  l4_utcb_t *utcb = l4_utcb()) throw()
392  L4_DEPRECATED("Call create with Cap<Irq> as argument instead.")
393  { return l4_factory_create_irq_u(cap(), target_cap.cap(), utcb); }
394 
408  l4_msgtag_t create_vm(Cap<Vm>const &target_cap,
409  l4_utcb_t *utcb = l4_utcb()) throw()
410  L4_DEPRECATED("Call create with Cap<Vm> as argument instead.")
411  { return l4_factory_create_vm_u(cap(), target_cap.cap(), utcb); }
412 
414 };
415 
416 }
l4_msgtag_t create_irq(Cap< Irq >const &target_cap, l4_utcb_t *utcb=l4_utcb())
Create a new IRQ.
Definition: factory:390
C++ Factory interface to create kernel objects.
Definition: factory:55
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:76
L4 low-level kernel interface.
l4_msgtag_t l4_factory_create_task_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_fpage_t const utcb_area, l4_utcb_t *utcb) L4_NOTHROW
Create a new task.
Definition: factory.h:289
C++ Irq interface.
Definition: irq:117
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())
Create a new IPC gate.
Definition: factory:372
Special type to add a void argument into the factory create stream.
Definition: factory:64
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:71
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
S(l4_cap_idx_t f, long obj, L4::Cap< void > target, l4_utcb_t *utcb)
Create a stream for a specific create() call.
Definition: factory:124
Mark an argument as a output value in an RPC signature.
Definition: ipc_types:42
L4::Cap related definitions.
Stream class for the create() argument stream.
Definition: factory:96
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_thread(Cap< Thread > const &target_cap, l4_utcb_t *utcb=l4_utcb())
Create a new thread.
Definition: factory:324
l4_cap_idx_t cap() const
Return capability selector.
Definition: capability.h:52
Lstr(char const *s, int len)
Definition: factory:87
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_msgtag_t create_factory(Cap< Factory > const &target_cap, unsigned long limit, l4_utcb_t *utcb=l4_utcb())
Create a new factory.
Definition: factory:342
S create(Cap< void > target, long obj, l4_utcb_t *utcb=l4_utcb())
Generic create call to the factory.
Definition: factory:259
Common factory related definitions.
Interface Definition Language.
S create(Cap< OBJ > target, l4_utcb_t *utcb=l4_utcb())
Create call for typed capabilities.
Definition: factory:276
Virtual machine.
Definition: vm:40
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
S(S const &o)
Create a copy.
Definition: factory:109
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
l4_msgtag_t create_task(Cap< Task > const &target_cap, l4_fpage_t const &utcb_area, l4_utcb_t *utcb=l4_utcb())
Create a new task.
Definition: factory:306
RPC attribute for an RPC call with required rights.
Definition: ipc_iface:246
l4_cap_idx_t cap() const
Return capability selector.
Definition: kobject:79
L4 flexpage type.
Definition: __l4_fpage.h:81
Helper class to create an L4Re interface class that is derived from a single base class...
Definition: __typeinfo.h:759
int len
The number of characters in the buffer.
Definition: factory:81
struct l4_msgtag_t l4_msgtag_t
Message tag data structure.
C++ interface for capabilities.
Definition: capability.h:13
Message tag data structure.
Definition: types.h:159
l4_msgtag_t create_vm(Cap< Vm >const &target_cap, l4_utcb_t *utcb=l4_utcb())
Create a new virtual machine.
Definition: factory:408
#define L4_INLINE_RPC_NF(res, name, args...)
Define an inline RPC call type (the type only, no callable).
Definition: ipc_iface:429
#define L4_DEPRECATED(s)
Mark symbol deprecated.
Definition: compiler.h:239
~S()
Commit the operation in the destructor to have a cool syntax for create().
Definition: factory:133