L4Re - L4 Runtime Environment
factory.h
Go to the documentation of this file.
1 
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Björn Döbel <doebel@os.inf.tu-dresden.de>,
10  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>,
11  * Henning Schild <hschild@os.inf.tu-dresden.de>
12  * economic rights: Technische Universität Dresden (Germany)
13  *
14  * This file is part of TUD:OS and distributed under the terms of the
15  * GNU General Public License 2.
16  * Please see the COPYING-GPL-2 file for details.
17  *
18  * As a special exception, you may use this file as part of a free software
19  * library without restriction. Specifically, if other files instantiate
20  * templates or use macros or inline functions from this file, or you compile
21  * this file and link it with other files to produce an executable, this
22  * file does not by itself cause the resulting executable to be covered by
23  * the GNU General Public License. This exception does not however
24  * invalidate any other reasons why the executable file might be covered by
25  * the GNU General Public License.
26  */
27 #pragma once
28 
29 #include <l4/sys/compiler.h>
30 #include <l4/sys/types.h>
31 #include <l4/sys/utcb.h>
32 
86 L4_INLINE l4_msgtag_t
88  l4_cap_idx_t target_cap, l4_fpage_t const utcb_area) L4_NOTHROW;
89 
96 L4_INLINE l4_msgtag_t
98  l4_fpage_t const utcb_area, l4_utcb_t *utcb) L4_NOTHROW;
99 
111 L4_INLINE l4_msgtag_t
113  l4_cap_idx_t target_cap) L4_NOTHROW;
114 
121 L4_INLINE l4_msgtag_t
123  l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
124 
138 L4_INLINE l4_msgtag_t
140  unsigned long limit) L4_NOTHROW;
141 
148 L4_INLINE l4_msgtag_t
150  unsigned long limit, l4_utcb_t *utcb) L4_NOTHROW;
151 
176 L4_INLINE l4_msgtag_t
178  l4_cap_idx_t target_cap,
179  l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW;
180 
187 L4_INLINE l4_msgtag_t
189  l4_cap_idx_t target_cap,
190  l4_cap_idx_t thread_cap, l4_umword_t label,
191  l4_utcb_t *utcb) L4_NOTHROW;
192 
205 L4_INLINE l4_msgtag_t
207  l4_cap_idx_t target_cap) L4_NOTHROW;
208 
215 L4_INLINE l4_msgtag_t
217  l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
218 
230 L4_INLINE l4_msgtag_t
232  l4_cap_idx_t target_cap) L4_NOTHROW;
233 
240 L4_INLINE l4_msgtag_t
242  l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
243 
244 L4_INLINE l4_msgtag_t
245 l4_factory_create_start_u(long obj, l4_cap_idx_t target,
246  l4_utcb_t *utcb) L4_NOTHROW;
247 
248 L4_INLINE int
249 l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
250  l4_utcb_t *utcb) L4_NOTHROW;
251 
252 L4_INLINE int
253 l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
254  l4_utcb_t *utcb) L4_NOTHROW;
255 
256 L4_INLINE int
257 l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
258  l4_utcb_t *utcb) L4_NOTHROW;
259 
260 L4_INLINE int
261 l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
262  l4_utcb_t *utcb) L4_NOTHROW;
263 
264 L4_INLINE int
265 l4_factory_create_add_lstr_u(char const *s, int len, l4_msgtag_t *tag,
266  l4_utcb_t *utcb) L4_NOTHROW;
267 
268 L4_INLINE int
269 l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
270 
271 L4_INLINE l4_msgtag_t
272 l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
273  l4_utcb_t *utcb) L4_NOTHROW;
274 
275 L4_INLINE l4_msgtag_t
276 l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
277  l4_utcb_t *utcb) L4_NOTHROW;
278 
279 
280 L4_INLINE l4_msgtag_t
281 l4_factory_create(l4_cap_idx_t factory, long obj,
282  l4_cap_idx_t target) L4_NOTHROW;
283 
284 /* IMPLEMENTATION -----------------------------------------------------------*/
285 
286 #include <l4/sys/ipc.h>
287 
288 L4_INLINE l4_msgtag_t
290  l4_cap_idx_t target_cap, l4_fpage_t utcb_area,
292 {
293  l4_msgtag_t t;
294  t = l4_factory_create_start_u(L4_PROTO_TASK, target_cap, u);
295  l4_factory_create_add_fpage_u(utcb_area, &t, u);
296  return l4_factory_create_commit_u(factory, t, u);
297 }
298 
299 L4_INLINE l4_msgtag_t
301  l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
302 {
303  return l4_factory_create_u(factory, L4_PROTO_THREAD, target_cap, u);
304 }
305 
306 L4_INLINE l4_msgtag_t
308  l4_cap_idx_t target_cap, unsigned long limit,
310 {
311  l4_msgtag_t t;
312  t = l4_factory_create_start_u(L4_PROTO_FACTORY, target_cap, u);
313  l4_factory_create_add_uint_u(limit, &t, u);
314  return l4_factory_create_commit_u(factory, t, u);
315 }
316 
317 L4_INLINE l4_msgtag_t
319  l4_cap_idx_t target_cap,
320  l4_cap_idx_t thread_cap, l4_umword_t label,
322 {
323  l4_msgtag_t t;
324  l4_msg_regs_t *v;
325  int items = 0;
326  t = l4_factory_create_start_u(0, target_cap, u);
327  l4_factory_create_add_uint_u(label, &t, u);
328  v = l4_utcb_mr_u(u);
329  if (!(thread_cap & L4_INVALID_CAP_BIT))
330  {
331  items = 1;
332  v->mr[3] = l4_map_obj_control(0,0);
333  v->mr[4] = l4_obj_fpage(thread_cap, 0, L4_FPAGE_RWX).raw;
334  }
336  return l4_factory_create_commit_u(factory, t, u);
337 }
338 
339 L4_INLINE l4_msgtag_t
341  l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
342 {
343  return l4_factory_create_u(factory, L4_PROTO_IRQ_SENDER, target_cap, u);
344 }
345 
346 L4_INLINE l4_msgtag_t
348  l4_cap_idx_t target_cap,
350 {
351  return l4_factory_create_u(factory, L4_PROTO_VM, target_cap, u);
352 }
353 
354 
355 
356 
357 
358 L4_INLINE l4_msgtag_t
360  l4_cap_idx_t target_cap, l4_fpage_t const utcb_area) L4_NOTHROW
361 {
362  return l4_factory_create_task_u(factory, target_cap, utcb_area, l4_utcb());
363 }
364 
365 L4_INLINE l4_msgtag_t
367  l4_cap_idx_t target_cap) L4_NOTHROW
368 {
369  return l4_factory_create_thread_u(factory, target_cap, l4_utcb());
370 }
371 
372 L4_INLINE l4_msgtag_t
374  l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
375 
376 {
377  return l4_factory_create_factory_u(factory, target_cap, limit, l4_utcb());
378 }
379 
380 L4_INLINE l4_msgtag_t
382  l4_cap_idx_t target_cap,
383  l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW
384 {
385  return l4_factory_create_gate_u(factory, target_cap, thread_cap, label, l4_utcb());
386 }
387 
388 L4_INLINE l4_msgtag_t
390  l4_cap_idx_t target_cap) L4_NOTHROW
391 {
392  return l4_factory_create_irq_u(factory, target_cap, l4_utcb());
393 }
394 
395 L4_INLINE l4_msgtag_t
397  l4_cap_idx_t target_cap) L4_NOTHROW
398 {
399  return l4_factory_create_vm_u(factory, target_cap, l4_utcb());
400 }
401 
402 L4_INLINE l4_msgtag_t
403 l4_factory_create_start_u(long obj, l4_cap_idx_t target_cap,
405 {
406  l4_msg_regs_t *v = l4_utcb_mr_u(u);
407  l4_buf_regs_t *b = l4_utcb_br_u(u);
408  v->mr[0] = obj;
409  b->bdr = 0;
410  b->br[0] = target_cap | L4_RCV_ITEM_SINGLE_CAP;
411  return l4_msgtag(L4_PROTO_FACTORY, 1, 0, 0);
412 }
413 
414 L4_INLINE int
415 l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
417 {
418  l4_msg_regs_t *v = l4_utcb_mr_u(u);
419  int w = l4_msgtag_words(*tag);
420  if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
421  return 0;
422  v->mr[w] = L4_VARG_TYPE_FPAGE | (sizeof(l4_fpage_t) << 16);
423  v->mr[w + 1] = d.raw;
424  w += 2;
425  tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
426  return 1;
427 }
428 
429 L4_INLINE int
430 l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
432 {
433  l4_msg_regs_t *v = l4_utcb_mr_u(u);
434  int w = l4_msgtag_words(*tag);
435  if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
436  return 0;
437  v->mr[w] = L4_VARG_TYPE_MWORD | (sizeof(l4_mword_t) << 16);
438  v->mr[w + 1] = d;
439  w += 2;
440  tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
441  return 1;
442 }
443 
444 L4_INLINE int
445 l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
447 {
448  l4_msg_regs_t *v = l4_utcb_mr_u(u);
449  int w = l4_msgtag_words(*tag);
450  if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
451  return 0;
452  v->mr[w] = L4_VARG_TYPE_UMWORD | (sizeof(l4_umword_t) << 16);
453  v->mr[w + 1] = d;
454  w += 2;
455  tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
456  return 1;
457 }
458 
459 L4_INLINE int
460 l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
462 {
463  return l4_factory_create_add_lstr_u(s, __builtin_strlen(s) + 1, tag, u);
464 }
465 
466 L4_INLINE int
467 l4_factory_create_add_lstr_u(char const *s, int len, l4_msgtag_t *tag,
469 {
470 
471  l4_msg_regs_t *v = l4_utcb_mr_u(u);
472  int w = l4_msgtag_words(*tag);
473  char *c;
474  int i;
475 
476  if (w + 1 + (len + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t)
478  return 0;
479 
480  v->mr[w] = L4_VARG_TYPE_STRING | (len << 16);
481  c = (char*)&v->mr[w + 1];
482  for (i = 0; i < len; ++i)
483  *c++ = *s++;
484 
485  w = w + 1 + (len + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t);
486 
487  tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
488  return 1;
489 }
490 
491 L4_INLINE int
492 l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
493 {
494  l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
495  int w = l4_msgtag_words(*tag);
496  v->mr[w] = L4_VARG_TYPE_NIL;
497  ++w;
498  tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
499  return 1;
500 }
501 
502 
503 L4_INLINE l4_msgtag_t
504 l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
506 {
507  return l4_ipc_call(factory, u, tag, L4_IPC_NEVER);
508 }
509 
510 L4_INLINE l4_msgtag_t
511 l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
512  l4_utcb_t *utcb) L4_NOTHROW
513 {
514  l4_msgtag_t t = l4_factory_create_start_u(obj, target, utcb);
515  return l4_factory_create_commit_u(factory, t, utcb);
516 }
517 
518 
519 L4_INLINE l4_msgtag_t
520 l4_factory_create(l4_cap_idx_t factory, long obj,
521  l4_cap_idx_t target) L4_NOTHROW
522 {
523  return l4_factory_create_u(factory, obj, target, l4_utcb());
524 }
Encapsulation of the message-register block in the UTCB.
Definition: utcb.h:78
Total number of message register (MRs) available.
Definition: utcb.h:47
l4_msgtag_t l4_factory_create_thread(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new thread.
Definition: factory.h:366
Protocol for messages to a factory object.
Definition: types.h:67
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
l4_msgtag_t l4_factory_create_factory(l4_cap_idx_t factory, l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
Create a new factory.
Definition: factory.h:373
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
Common L4 ABI Data Types.
Read-write-execute flex page.
Definition: __l4_fpage.h:114
l4_msgtag_t l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Object call (usual invocation).
Definition: ipc.h:445
l4_msgtag_t l4_factory_create_irq(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new IRQ sender.
Definition: factory.h:389
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
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
Protocol for messages to a virtual machine object.
Definition: types.h:68
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
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
#define L4_IPC_NEVER
never timeout
Definition: __timeout.h:80
Encapsulation of the buffer-registers block in the UTCB.
Definition: utcb.h:93
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition: types.h:419
Protocol for messages to a thread object.
Definition: types.h:64
l4_msgtag_flags
Flags for message tags.
Definition: types.h:95
L4 compiler related defines.
l4_msgtag_t l4_factory_create_gate(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW
Create a new IPC gate.
Definition: factory.h:381
l4_umword_t bdr
Buffer descriptor.
Definition: utcb.h:96
l4_msgtag_t l4_factory_create_task(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_fpage_t const utcb_area) L4_NOTHROW
Create a new task.
Definition: factory.h:359
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
Protocol for messages to a task object.
Definition: types.h:63
Protocol for IRQ senders (IRQ -> IPC)
Definition: types.h:70
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition: types.h:423
l4_umword_t raw
Raw value.
Definition: __l4_fpage.h:83
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
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item for the object space.
Definition: __l4_fpage.h:679
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
L4 flexpage type.
Definition: __l4_fpage.h:81
Mark the receive buffer to be a small receive item that describes a buffer for a single capability...
Definition: consts.h:206
Message tag data structure.
Definition: types.h:159
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition: utcb.h:99
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flex page.
Definition: __l4_fpage.h:645
l4_msgtag_t l4_factory_create_vm(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new virtual machine.
Definition: factory.h:396
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185