L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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
88 l4_fpage_t *utcb_area) L4_NOTHROW;
89
95l4_factory_create_task_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
96 l4_fpage_t *utcb_area, l4_utcb_t *utcb) L4_NOTHROW;
97
118 l4_cap_idx_t target_cap) L4_NOTHROW;
119
125l4_factory_create_thread_u(l4_cap_idx_t factory,
126 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
127
155 unsigned long limit) L4_NOTHROW;
156
162l4_factory_create_factory_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
163 unsigned long limit, l4_utcb_t *utcb) L4_NOTHROW;
164
196 l4_cap_idx_t target_cap,
197 l4_cap_idx_t snd_dst_cap, l4_umword_t label) L4_NOTHROW;
198
204l4_factory_create_gate_u(l4_cap_idx_t factory,
205 l4_cap_idx_t target_cap,
206 l4_cap_idx_t snd_dst_cap, l4_umword_t label,
207 l4_utcb_t *utcb) L4_NOTHROW;
208
227 l4_cap_idx_t target_cap) L4_NOTHROW;
228
234l4_factory_create_irq_u(l4_cap_idx_t factory,
235 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
236
257 l4_cap_idx_t target_cap) L4_NOTHROW;
258
280 l4_cap_idx_t target_cap) L4_NOTHROW;
281
311 l4_cap_idx_t target_cap,
312 unsigned policy) L4_NOTHROW;
313
319l4_factory_create_vm_u(l4_cap_idx_t factory,
320 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
321
327l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
328 l4_cap_idx_t target_cap,
329 l4_utcb_t *utcb) L4_NOTHROW;
330
336l4_factory_create_thread_group_u(l4_cap_idx_t factory,
337 l4_cap_idx_t target_cap,
338 unsigned policy,
340
346l4_factory_create_start_u(long obj, l4_cap_idx_t target,
347 l4_utcb_t *utcb) L4_NOTHROW;
348
353L4_INLINE int
354l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
355 l4_utcb_t *utcb) L4_NOTHROW;
356
361L4_INLINE int
362l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
363 l4_utcb_t *utcb) L4_NOTHROW;
364
369L4_INLINE int
370l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
371 l4_utcb_t *utcb) L4_NOTHROW;
372
377L4_INLINE int
378l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
379 l4_utcb_t *utcb) L4_NOTHROW;
380
385L4_INLINE int
386l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
387 l4_utcb_t *utcb) L4_NOTHROW;
388
393L4_INLINE int
394l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
395
401l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
402 l4_utcb_t *utcb) L4_NOTHROW;
403
409l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
410 l4_utcb_t *utcb) L4_NOTHROW;
411
412
431l4_factory_create(l4_cap_idx_t factory, long obj,
432 l4_cap_idx_t target) L4_NOTHROW;
433
434/* IMPLEMENTATION -----------------------------------------------------------*/
435
436#include <l4/sys/ipc.h>
437
439l4_factory_create_task_u(l4_cap_idx_t factory,
440 l4_cap_idx_t target_cap, l4_fpage_t *utcb_area,
442{
443 l4_msgtag_t t;
444 t = l4_factory_create_start_u(L4_PROTO_TASK, target_cap, u);
445 l4_factory_create_add_fpage_u(*utcb_area, &t, u);
446 t = l4_factory_create_commit_u(factory, t, u);
447 if (!l4_msgtag_has_error(t))
448 {
449 l4_msg_regs_t *v = l4_utcb_mr_u(u);
450 utcb_area->raw = v->mr[0];
451 }
452 return t;
453}
454
456l4_factory_create_thread_u(l4_cap_idx_t factory,
457 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
458{
459 return l4_factory_create_u(factory, L4_PROTO_THREAD, target_cap, u);
460}
461
463l4_factory_create_factory_u(l4_cap_idx_t factory,
464 l4_cap_idx_t target_cap, unsigned long limit,
466{
467 l4_msgtag_t t;
468 t = l4_factory_create_start_u(L4_PROTO_FACTORY, target_cap, u);
469 l4_factory_create_add_uint_u(limit, &t, u);
470 return l4_factory_create_commit_u(factory, t, u);
471}
472
474l4_factory_create_gate_u(l4_cap_idx_t factory,
475 l4_cap_idx_t target_cap,
476 l4_cap_idx_t snd_dst_cap, l4_umword_t label,
478{
479 l4_msgtag_t t;
480 l4_msg_regs_t *v;
481 int items = 0;
482 t = l4_factory_create_start_u(0, target_cap, u);
483 l4_factory_create_add_uint_u(label, &t, u);
484 v = l4_utcb_mr_u(u);
485 if (!(snd_dst_cap & L4_INVALID_CAP_BIT))
486 {
487 items = 1;
488 v->mr[3] = l4_map_obj_control(0,0);
489 v->mr[4] = l4_obj_fpage(snd_dst_cap, 0, L4_CAP_FPAGE_RWS).raw;
490 }
492 return l4_factory_create_commit_u(factory, t, u);
493}
494
496l4_factory_create_irq_u(l4_cap_idx_t factory,
497 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
498{
499 return l4_factory_create_u(factory, L4_PROTO_IRQ_SENDER, target_cap, u);
500}
501
503l4_factory_create_vm_u(l4_cap_idx_t factory,
504 l4_cap_idx_t target_cap,
506{
507 return l4_factory_create_u(factory, L4_PROTO_VM, target_cap, u);
508}
509
511l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
512 l4_cap_idx_t target_cap,
514{
515 return l4_factory_create_u(factory, L4_PROTO_VCPU_CONTEXT, target_cap, u);
516}
517
519l4_factory_create_thread_group_u(l4_cap_idx_t factory,
520 l4_cap_idx_t target_cap,
521 unsigned policy,
523{
524 l4_msgtag_t t = l4_factory_create_start_u(L4_PROTO_THREAD_GROUP, target_cap, u);
525 l4_factory_create_add_uint_u(policy, &t, u);
526 return l4_factory_create_commit_u(factory, t, u);
527}
528
529
532 l4_cap_idx_t target_cap, l4_fpage_t *utcb_area) L4_NOTHROW
533{
534 return l4_factory_create_task_u(factory, target_cap, utcb_area, l4_utcb());
535}
536
539 l4_cap_idx_t target_cap) L4_NOTHROW
540{
541 return l4_factory_create_thread_u(factory, target_cap, l4_utcb());
542}
543
546 l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
547
548{
549 return l4_factory_create_factory_u(factory, target_cap, limit, l4_utcb());
550}
551
554 l4_cap_idx_t target_cap,
555 l4_cap_idx_t snd_dst_cap, l4_umword_t label) L4_NOTHROW
556{
557 return l4_factory_create_gate_u(factory, target_cap, snd_dst_cap, label, l4_utcb());
558}
559
562 l4_cap_idx_t target_cap) L4_NOTHROW
563{
564 return l4_factory_create_irq_u(factory, target_cap, l4_utcb());
565}
566
569 l4_cap_idx_t target_cap) L4_NOTHROW
570{
571 return l4_factory_create_vm_u(factory, target_cap, l4_utcb());
572}
573
576 l4_cap_idx_t target_cap) L4_NOTHROW
577{
578 return l4_factory_create_vcpu_context_u(factory, target_cap, l4_utcb());
579}
580
583 l4_cap_idx_t target_cap,
584 unsigned policy) L4_NOTHROW
585{
586 return l4_factory_create_thread_group_u(factory, target_cap, policy, l4_utcb());
587}
588
589
591l4_factory_create_start_u(long obj, l4_cap_idx_t target_cap,
593{
594 l4_msg_regs_t *v = l4_utcb_mr_u(u);
595 l4_buf_regs_t *b = l4_utcb_br_u(u);
596 v->mr[0] = obj;
597 b->bdr = 0;
598 b->br[0] = target_cap | L4_RCV_ITEM_SINGLE_CAP;
599 return l4_msgtag(L4_PROTO_FACTORY, 1, 0, 0);
600}
601
602L4_INLINE int
603l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
605{
606 l4_msg_regs_t *v = l4_utcb_mr_u(u);
607 int w = l4_msgtag_words(*tag);
608 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
609 return 0;
610 v->mr[w] = L4_VARG_TYPE_FPAGE | (sizeof(l4_fpage_t) << 16);
611 v->mr[w + 1] = d.raw;
612 w += 2;
613 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
614 return 1;
615}
616
617L4_INLINE int
618l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
620{
621 l4_msg_regs_t *v = l4_utcb_mr_u(u);
622 int w = l4_msgtag_words(*tag);
623 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
624 return 0;
625 v->mr[w] = L4_VARG_TYPE_MWORD | (sizeof(l4_mword_t) << 16);
626 v->mr[w + 1] = d;
627 w += 2;
628 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
629 return 1;
630}
631
632L4_INLINE int
633l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
635{
636 l4_msg_regs_t *v = l4_utcb_mr_u(u);
637 int w = l4_msgtag_words(*tag);
638 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
639 return 0;
640 v->mr[w] = L4_VARG_TYPE_UMWORD | (sizeof(l4_umword_t) << 16);
641 v->mr[w + 1] = d;
642 w += 2;
643 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
644 return 1;
645}
646
647L4_INLINE int
648l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
650{
651 return l4_factory_create_add_lstr_u(s, __builtin_strlen(s) + 1, tag, u);
652}
653
654L4_INLINE int
655l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
657{
658
659 l4_msg_regs_t *v = l4_utcb_mr_u(u);
660 unsigned w = l4_msgtag_words(*tag);
661 char *c;
662 unsigned i;
663
664 if (w + 1 + l4_bytes_to_mwords(len) > L4_UTCB_GENERIC_DATA_SIZE)
665 return 0;
666
667 v->mr[w] = L4_VARG_TYPE_STRING | (len << 16);
668 c = (char*)&v->mr[w + 1];
669 for (i = 0; i < len; ++i)
670 *c++ = *s++;
671
672 w = w + 1 + l4_bytes_to_mwords(len);
673
674 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
675 return 1;
676}
677
678L4_INLINE int
679l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
680{
681 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
682 int w = l4_msgtag_words(*tag);
683 v->mr[w] = L4_VARG_TYPE_NIL;
684 ++w;
685 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
686 return 1;
687}
688
689
691l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
693{
694 return l4_ipc_call(factory, u, tag, L4_IPC_NEVER);
695}
696
698l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
699 l4_utcb_t *utcb) L4_NOTHROW
700{
701 l4_msgtag_t t = l4_factory_create_start_u(obj, target, utcb);
702 return l4_factory_create_commit_u(factory, t, utcb);
703}
704
705
709{
710 return l4_factory_create_u(factory, obj, target, l4_utcb());
711}
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:336
l4_msgtag_t l4_factory_create_thread_group(l4_cap_idx_t factory, l4_cap_idx_t target_cap, unsigned policy) L4_NOTHROW
Create a new thread group.
Definition factory.h:582
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:538
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:561
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:575
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:545
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:531
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:707
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:568
l4_msgtag_t l4_factory_create_gate(l4_cap_idx_t factory, l4_cap_idx_t target_cap, l4_cap_idx_t snd_dst_cap, l4_umword_t label) L4_NOTHROW
Create a new IPC gate, optionally bound to a send destination (a thread or thread group).
Definition factory.h:553
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:715
@ 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:496
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:749
@ 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:275
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:440
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:405
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition types.h:427
unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
Get the flags.
Definition types.h:435
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:417
@ L4_PROTO_FACTORY
Protocol for messages to a factory object.
Definition types.h:57
@ L4_PROTO_IRQ_SENDER
Protocol for IRQ senders (IRQ -> IPC)
Definition types.h:60
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:53
@ L4_PROTO_VM
Protocol for messages to a virtual machine object.
Definition types.h:58
@ L4_PROTO_THREAD_GROUP
Protocol for messages to a thread group obj.
Definition types.h:51
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:54
@ L4_PROTO_VCPU_CONTEXT
Protocol for hardware vCPU contexts.
Definition types.h:67
#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:161
#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:154
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