L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
15 */
16#pragma once
17
18#include <l4/sys/compiler.h>
19#include <l4/sys/types.h>
20#include <l4/sys/utcb.h>
21
87 l4_fpage_t *utcb_area) L4_NOTHROW;
88
94l4_factory_create_task_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
95 l4_fpage_t *utcb_area, l4_utcb_t *utcb) L4_NOTHROW;
96
116 l4_cap_idx_t target_cap) L4_NOTHROW;
117
123l4_factory_create_thread_u(l4_cap_idx_t factory,
124 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
125
152 unsigned long limit) L4_NOTHROW;
153
159l4_factory_create_factory_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
160 unsigned long limit, l4_utcb_t *utcb) L4_NOTHROW;
161
189 l4_cap_idx_t target_cap,
190 l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW;
191
197l4_factory_create_gate_u(l4_cap_idx_t factory,
198 l4_cap_idx_t target_cap,
199 l4_cap_idx_t thread_cap, l4_umword_t label,
200 l4_utcb_t *utcb) L4_NOTHROW;
201
219 l4_cap_idx_t target_cap) L4_NOTHROW;
220
226l4_factory_create_irq_u(l4_cap_idx_t factory,
227 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
228
248 l4_cap_idx_t target_cap) L4_NOTHROW;
249
270 l4_cap_idx_t target_cap) L4_NOTHROW;
271
277l4_factory_create_vm_u(l4_cap_idx_t factory,
278 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
279
285l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
286 l4_cap_idx_t target_cap,
287 l4_utcb_t *utcb) L4_NOTHROW;
288
294l4_factory_create_start_u(long obj, l4_cap_idx_t target,
295 l4_utcb_t *utcb) L4_NOTHROW;
296
301L4_INLINE int
302l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
303 l4_utcb_t *utcb) L4_NOTHROW;
304
309L4_INLINE int
310l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
311 l4_utcb_t *utcb) L4_NOTHROW;
312
317L4_INLINE int
318l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
319 l4_utcb_t *utcb) L4_NOTHROW;
320
325L4_INLINE int
326l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
327 l4_utcb_t *utcb) L4_NOTHROW;
328
333L4_INLINE int
334l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
335 l4_utcb_t *utcb) L4_NOTHROW;
336
341L4_INLINE int
342l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
343
349l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
350 l4_utcb_t *utcb) L4_NOTHROW;
351
357l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
358 l4_utcb_t *utcb) L4_NOTHROW;
359
360
378l4_factory_create(l4_cap_idx_t factory, long obj,
379 l4_cap_idx_t target) L4_NOTHROW;
380
381/* IMPLEMENTATION -----------------------------------------------------------*/
382
383#include <l4/sys/ipc.h>
384
386l4_factory_create_task_u(l4_cap_idx_t factory,
387 l4_cap_idx_t target_cap, l4_fpage_t *utcb_area,
389{
390 l4_msgtag_t t;
391 t = l4_factory_create_start_u(L4_PROTO_TASK, target_cap, u);
392 l4_factory_create_add_fpage_u(*utcb_area, &t, u);
393 t = l4_factory_create_commit_u(factory, t, u);
394 if (!l4_msgtag_has_error(t))
395 {
396 l4_msg_regs_t *v = l4_utcb_mr_u(u);
397 utcb_area->raw = v->mr[0];
398 }
399 return t;
400}
401
403l4_factory_create_thread_u(l4_cap_idx_t factory,
404 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
405{
406 return l4_factory_create_u(factory, L4_PROTO_THREAD, target_cap, u);
407}
408
410l4_factory_create_factory_u(l4_cap_idx_t factory,
411 l4_cap_idx_t target_cap, unsigned long limit,
413{
414 l4_msgtag_t t;
415 t = l4_factory_create_start_u(L4_PROTO_FACTORY, target_cap, u);
416 l4_factory_create_add_uint_u(limit, &t, u);
417 return l4_factory_create_commit_u(factory, t, u);
418}
419
421l4_factory_create_gate_u(l4_cap_idx_t factory,
422 l4_cap_idx_t target_cap,
423 l4_cap_idx_t thread_cap, l4_umword_t label,
425{
426 l4_msgtag_t t;
427 l4_msg_regs_t *v;
428 int items = 0;
429 t = l4_factory_create_start_u(0, target_cap, u);
430 l4_factory_create_add_uint_u(label, &t, u);
431 v = l4_utcb_mr_u(u);
432 if (!(thread_cap & L4_INVALID_CAP_BIT))
433 {
434 items = 1;
435 v->mr[3] = l4_map_obj_control(0,0);
436 v->mr[4] = l4_obj_fpage(thread_cap, 0, L4_CAP_FPAGE_RWS).raw;
437 }
439 return l4_factory_create_commit_u(factory, t, u);
440}
441
443l4_factory_create_irq_u(l4_cap_idx_t factory,
444 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
445{
446 return l4_factory_create_u(factory, L4_PROTO_IRQ_SENDER, target_cap, u);
447}
448
450l4_factory_create_vm_u(l4_cap_idx_t factory,
451 l4_cap_idx_t target_cap,
453{
454 return l4_factory_create_u(factory, L4_PROTO_VM, target_cap, u);
455}
456
458l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
459 l4_cap_idx_t target_cap,
461{
462 return l4_factory_create_u(factory, L4_PROTO_VCPU_CONTEXT, target_cap, u);
463}
464
465
466
467
468
471 l4_cap_idx_t target_cap, l4_fpage_t *utcb_area) L4_NOTHROW
472{
473 return l4_factory_create_task_u(factory, target_cap, utcb_area, l4_utcb());
474}
475
478 l4_cap_idx_t target_cap) L4_NOTHROW
479{
480 return l4_factory_create_thread_u(factory, target_cap, l4_utcb());
481}
482
485 l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
486
487{
488 return l4_factory_create_factory_u(factory, target_cap, limit, l4_utcb());
489}
490
493 l4_cap_idx_t target_cap,
494 l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW
495{
496 return l4_factory_create_gate_u(factory, target_cap, thread_cap, label, l4_utcb());
497}
498
501 l4_cap_idx_t target_cap) L4_NOTHROW
502{
503 return l4_factory_create_irq_u(factory, target_cap, l4_utcb());
504}
505
508 l4_cap_idx_t target_cap) L4_NOTHROW
509{
510 return l4_factory_create_vm_u(factory, target_cap, l4_utcb());
511}
512
515 l4_cap_idx_t target_cap) L4_NOTHROW
516{
517 return l4_factory_create_vcpu_context_u(factory, target_cap, l4_utcb());
518}
519
521l4_factory_create_start_u(long obj, l4_cap_idx_t target_cap,
523{
524 l4_msg_regs_t *v = l4_utcb_mr_u(u);
525 l4_buf_regs_t *b = l4_utcb_br_u(u);
526 v->mr[0] = obj;
527 b->bdr = 0;
528 b->br[0] = target_cap | L4_RCV_ITEM_SINGLE_CAP;
529 return l4_msgtag(L4_PROTO_FACTORY, 1, 0, 0);
530}
531
532L4_INLINE int
533l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
535{
536 l4_msg_regs_t *v = l4_utcb_mr_u(u);
537 int w = l4_msgtag_words(*tag);
538 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
539 return 0;
540 v->mr[w] = L4_VARG_TYPE_FPAGE | (sizeof(l4_fpage_t) << 16);
541 v->mr[w + 1] = d.raw;
542 w += 2;
543 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
544 return 1;
545}
546
547L4_INLINE int
548l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
550{
551 l4_msg_regs_t *v = l4_utcb_mr_u(u);
552 int w = l4_msgtag_words(*tag);
553 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
554 return 0;
555 v->mr[w] = L4_VARG_TYPE_MWORD | (sizeof(l4_mword_t) << 16);
556 v->mr[w + 1] = d;
557 w += 2;
558 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
559 return 1;
560}
561
562L4_INLINE int
563l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
565{
566 l4_msg_regs_t *v = l4_utcb_mr_u(u);
567 int w = l4_msgtag_words(*tag);
568 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
569 return 0;
570 v->mr[w] = L4_VARG_TYPE_UMWORD | (sizeof(l4_umword_t) << 16);
571 v->mr[w + 1] = d;
572 w += 2;
573 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
574 return 1;
575}
576
577L4_INLINE int
578l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
580{
581 return l4_factory_create_add_lstr_u(s, __builtin_strlen(s) + 1, tag, u);
582}
583
584L4_INLINE int
585l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
587{
588
589 l4_msg_regs_t *v = l4_utcb_mr_u(u);
590 unsigned w = l4_msgtag_words(*tag);
591 char *c;
592 unsigned i;
593
594 if (w + 1 + l4_bytes_to_mwords(len) > L4_UTCB_GENERIC_DATA_SIZE)
595 return 0;
596
597 v->mr[w] = L4_VARG_TYPE_STRING | (len << 16);
598 c = (char*)&v->mr[w + 1];
599 for (i = 0; i < len; ++i)
600 *c++ = *s++;
601
602 w = w + 1 + l4_bytes_to_mwords(len);
603
604 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
605 return 1;
606}
607
608L4_INLINE int
609l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
610{
611 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
612 int w = l4_msgtag_words(*tag);
613 v->mr[w] = L4_VARG_TYPE_NIL;
614 ++w;
615 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
616 return 1;
617}
618
619
621l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
623{
624 return l4_ipc_call(factory, u, tag, L4_IPC_NEVER);
625}
626
628l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
629 l4_utcb_t *utcb) L4_NOTHROW
630{
631 l4_msgtag_t t = l4_factory_create_start_u(obj, target, utcb);
632 return l4_factory_create_commit_u(factory, t, utcb);
633}
634
635
639{
640 return l4_factory_create_u(factory, obj, target, l4_utcb());
641}
L4 compiler related defines.
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
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:492
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:477
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:500
l4_msgtag_t l4_factory_create_vcpu_context(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new vCPU context.
Definition factory.h:514
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:484
l4_msgtag_t l4_factory_create_task(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_fpage_t *utcb_area) L4_NOTHROW
Create a new task.
Definition factory.h:470
l4_msgtag_t l4_factory_create(l4_cap_idx_t factory, long obj, l4_cap_idx_t target) L4_NOTHROW
Create a new object.
Definition factory.h:637
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:507
l4_fpage_t l4_obj_fpage(l4_cap_idx_t obj, unsigned int order, unsigned char rights) L4_NOTHROW
Create a kernel-object flexpage.
Definition __l4_fpage.h:696
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flexpages.
Definition __l4_fpage.h:206
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:565
unsigned l4_bytes_to_mwords(unsigned size) L4_NOTHROW
Determine how many machine words (l4_umword_t) are required to store a buffer of 'size' bytes.
Definition consts.h:500
l4_umword_t l4_map_obj_control(l4_umword_t spot, unsigned grant) L4_NOTHROW
Create the first word for a map item that is a send item for the object space.
Definition __l4_fpage.h:730
@ L4_RCV_ITEM_SINGLE_CAP
Mark the receive buffer to be a small receive item that describes a buffer for a single object capabi...
Definition consts.h:279
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:439
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:404
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition types.h:426
unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
Get the flags.
Definition types.h:434
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:416
@ L4_PROTO_FACTORY
Protocol for messages to a factory object.
Definition types.h:56
@ L4_PROTO_IRQ_SENDER
Protocol for IRQ senders (IRQ -> IPC)
Definition types.h:59
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:52
@ L4_PROTO_VM
Protocol for messages to a virtual machine object.
Definition types.h:57
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:53
@ L4_PROTO_VCPU_CONTEXT
Protocol for hardware vCPU contexts.
Definition types.h:66
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
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
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:159
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
Common L4 ABI Data Types.
Encapsulation of the buffer-registers block in the UTCB.
Definition utcb.h:83
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition utcb.h:88
l4_umword_t bdr
Buffer descriptor.
Definition utcb.h:85
Message tag data structure.
Definition types.h:153
L4 flexpage type.
Definition __l4_fpage.h:76
l4_umword_t raw
Raw value.
Definition __l4_fpage.h:78
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69