Loading...
Searching...
No Matches
factory.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>,
* Björn Döbel <doebel@os.inf.tu-dresden.de>,
* Torsten Frenzel <frenzel@os.inf.tu-dresden.de>,
* Henning Schild <hschild@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/sys/compiler.h>
#include <l4/sys/types.h>
#include <l4/sys/utcb.h>
L4_INLINE 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;
L4_INLINE 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;
L4_INLINE l4_msgtag_t
l4_factory_create_thread(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW;
L4_INLINE 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;
L4_INLINE l4_msgtag_t
l4_factory_create_factory(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
unsigned long limit) L4_NOTHROW;
L4_INLINE 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;
L4_INLINE 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;
L4_INLINE l4_msgtag_t
l4_factory_create_gate_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
l4_cap_idx_t snd_dst_cap, l4_umword_t label,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_irq(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW;
L4_INLINE 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;
L4_INLINE l4_msgtag_t
l4_factory_create_vm(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_vcpu_context(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_thread_group(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
unsigned policy) L4_NOTHROW;
L4_INLINE 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;
L4_INLINE l4_msgtag_t
l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_thread_group_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
unsigned policy,
l4_utcb_t *u) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_start_u(long obj, l4_cap_idx_t target,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE int
l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
l4_utcb_t *utcb) L4_NOTHROW;
L4_INLINE l4_msgtag_t
l4_factory_create(l4_cap_idx_t factory, long obj,
l4_cap_idx_t target) L4_NOTHROW;
/* IMPLEMENTATION -----------------------------------------------------------*/
#include <l4/sys/ipc.h>
L4_INLINE 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 *u) L4_NOTHROW
{
l4_msgtag_t t;
t = l4_factory_create_start_u(L4_PROTO_TASK, target_cap, u);
l4_factory_create_add_fpage_u(*utcb_area, &t, u);
t = l4_factory_create_commit_u(factory, t, u);
if (!l4_msgtag_has_error(t))
{
l4_msg_regs_t *v = l4_utcb_mr_u(u);
utcb_area->raw = v->mr[0];
}
return t;
}
L4_INLINE l4_msgtag_t
l4_factory_create_thread_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
{
return l4_factory_create_u(factory, L4_PROTO_THREAD, target_cap, u);
}
L4_INLINE 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 *u) L4_NOTHROW
{
l4_msgtag_t t;
t = l4_factory_create_start_u(L4_PROTO_FACTORY, target_cap, u);
l4_factory_create_add_uint_u(limit, &t, u);
return l4_factory_create_commit_u(factory, t, u);
}
L4_INLINE l4_msgtag_t
l4_factory_create_gate_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
l4_cap_idx_t snd_dst_cap, l4_umword_t label,
l4_utcb_t *u) L4_NOTHROW
{
l4_msgtag_t t;
l4_msg_regs_t *v;
int items = 0;
t = l4_factory_create_start_u(0, target_cap, u);
l4_factory_create_add_uint_u(label, &t, u);
v = l4_utcb_mr_u(u);
if (!(snd_dst_cap & L4_INVALID_CAP_BIT))
{
items = 1;
v->mr[3] = l4_map_obj_control(0,0);
v->mr[4] = l4_obj_fpage(snd_dst_cap, 0, L4_CAP_FPAGE_RWS).raw;
}
t = l4_msgtag(l4_msgtag_label(t), l4_msgtag_words(t), items, l4_msgtag_flags(t));
return l4_factory_create_commit_u(factory, t, u);
}
L4_INLINE l4_msgtag_t
l4_factory_create_irq_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
{
return l4_factory_create_u(factory, L4_PROTO_IRQ_SENDER, target_cap, u);
}
L4_INLINE l4_msgtag_t
l4_factory_create_vm_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
l4_utcb_t *u) L4_NOTHROW
{
return l4_factory_create_u(factory, L4_PROTO_VM, target_cap, u);
}
L4_INLINE l4_msgtag_t
l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
l4_utcb_t *u) L4_NOTHROW
{
return l4_factory_create_u(factory, L4_PROTO_VCPU_CONTEXT, target_cap, u);
}
L4_INLINE l4_msgtag_t
l4_factory_create_thread_group_u(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
unsigned policy,
l4_utcb_t *u) L4_NOTHROW
{
l4_msgtag_t t = l4_factory_create_start_u(L4_PROTO_THREAD_GROUP, target_cap, u);
l4_factory_create_add_uint_u(policy, &t, u);
return l4_factory_create_commit_u(factory, t, u);
}
L4_INLINE 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
{
return l4_factory_create_task_u(factory, target_cap, utcb_area, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_thread(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW
{
return l4_factory_create_thread_u(factory, target_cap, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_factory(l4_cap_idx_t factory,
l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
{
return l4_factory_create_factory_u(factory, target_cap, limit, l4_utcb());
}
L4_INLINE 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
{
return l4_factory_create_gate_u(factory, target_cap, snd_dst_cap, label, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_irq(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW
{
return l4_factory_create_irq_u(factory, target_cap, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_vm(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW
{
return l4_factory_create_vm_u(factory, target_cap, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_vcpu_context(l4_cap_idx_t factory,
l4_cap_idx_t target_cap) L4_NOTHROW
{
return l4_factory_create_vcpu_context_u(factory, target_cap, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_thread_group(l4_cap_idx_t factory,
l4_cap_idx_t target_cap,
unsigned policy) L4_NOTHROW
{
return l4_factory_create_thread_group_u(factory, target_cap, policy, l4_utcb());
}
L4_INLINE l4_msgtag_t
l4_factory_create_start_u(long obj, l4_cap_idx_t target_cap,
l4_utcb_t *u) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(u);
l4_buf_regs_t *b = l4_utcb_br_u(u);
v->mr[0] = obj;
b->bdr = 0;
b->br[0] = target_cap | L4_RCV_ITEM_SINGLE_CAP;
return l4_msgtag(L4_PROTO_FACTORY, 1, 0, 0);
}
L4_INLINE int
l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
l4_utcb_t *u) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(u);
int w = l4_msgtag_words(*tag);
if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
return 0;
v->mr[w] = L4_VARG_TYPE_FPAGE | (sizeof(l4_fpage_t) << 16);
v->mr[w + 1] = d.raw;
w += 2;
tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
return 1;
}
L4_INLINE int
l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
l4_utcb_t *u) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(u);
int w = l4_msgtag_words(*tag);
if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
return 0;
v->mr[w] = L4_VARG_TYPE_MWORD | (sizeof(l4_mword_t) << 16);
v->mr[w + 1] = d;
w += 2;
tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
return 1;
}
L4_INLINE int
l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
l4_utcb_t *u) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(u);
int w = l4_msgtag_words(*tag);
if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
return 0;
v->mr[w] = L4_VARG_TYPE_UMWORD | (sizeof(l4_umword_t) << 16);
v->mr[w + 1] = d;
w += 2;
tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
return 1;
}
L4_INLINE int
l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
l4_utcb_t *u) L4_NOTHROW
{
return l4_factory_create_add_lstr_u(s, __builtin_strlen(s) + 1, tag, u);
}
L4_INLINE int
l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
l4_utcb_t *u) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(u);
unsigned w = l4_msgtag_words(*tag);
char *c;
unsigned i;
if (w + 1 + l4_bytes_to_mwords(len) > L4_UTCB_GENERIC_DATA_SIZE)
return 0;
v->mr[w] = L4_VARG_TYPE_STRING | (len << 16);
c = (char*)&v->mr[w + 1];
for (i = 0; i < len; ++i)
*c++ = *s++;
w = w + 1 + l4_bytes_to_mwords(len);
tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
return 1;
}
L4_INLINE int
l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
{
l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
int w = l4_msgtag_words(*tag);
v->mr[w] = L4_VARG_TYPE_NIL;
++w;
tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
return 1;
}
L4_INLINE l4_msgtag_t
l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
l4_utcb_t *u) L4_NOTHROW
{
return l4_ipc_call(factory, u, tag, L4_IPC_NEVER);
}
L4_INLINE l4_msgtag_t
l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
l4_utcb_t *utcb) L4_NOTHROW
{
l4_msgtag_t t = l4_factory_create_start_u(obj, target, utcb);
return l4_factory_create_commit_u(factory, t, utcb);
}
L4_INLINE l4_msgtag_t
l4_factory_create(l4_cap_idx_t factory, long obj,
l4_cap_idx_t target) L4_NOTHROW
{
return l4_factory_create_u(factory, obj, target, l4_utcb());
}
compiler.h
L4 compiler related defines.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
l4_mword_t
signed long l4_mword_t
Signed machine word.
Definition l4int.h:37
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
l4_factory_create_thread_group
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_factory_create_thread
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_factory_create_irq
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_factory_create_vcpu_context
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_factory_create_factory
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_factory_create_task
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_factory_create
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_factory_create_vm
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_factory_create_gate
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_obj_fpage
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
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flexpages.
Definition __l4_fpage.h:206
l4_ipc_call
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
l4_bytes_to_mwords
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_map_obj_control
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
@ 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
l4_msgtag_has_error
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:440
l4_msgtag
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
l4_msgtag_words
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition types.h:427
l4_msgtag_flags
unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
Get the flags.
Definition types.h:435
l4_msgtag_label
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:417
L4_PROTO_FACTORY
@ L4_PROTO_FACTORY
Protocol for messages to a factory object.
Definition types.h:57
L4_PROTO_IRQ_SENDER
@ L4_PROTO_IRQ_SENDER
Protocol for IRQ senders (IRQ -> IPC).
Definition types.h:60
L4_PROTO_TASK
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:53
L4_PROTO_VM
@ L4_PROTO_VM
Protocol for messages to a virtual machine object.
Definition types.h:58
L4_PROTO_THREAD_GROUP
@ L4_PROTO_THREAD_GROUP
Protocol for messages to a thread group obj.
Definition types.h:51
L4_PROTO_THREAD
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:54
L4_PROTO_VCPU_CONTEXT
@ L4_PROTO_VCPU_CONTEXT
Protocol for hardware vCPU contexts.
Definition types.h:67
L4_IPC_NEVER
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb_t
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4_NOTHROW
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:161
L4_INLINE
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
ipc.h
Common IPC interface.
types.h
Common L4 ABI Data Types.
utcb.h
UTCB definitions.
l4_buf_regs_t
Encapsulation of the buffer-registers block in the UTCB.
Definition utcb.h:83
l4_buf_regs_t::br
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition utcb.h:88
l4_buf_regs_t::bdr
l4_umword_t bdr
Buffer descriptor.
Definition utcb.h:85
l4_msgtag_t
Message tag data structure.
Definition types.h:154
l4_fpage_t
L4 flexpage type.
Definition __l4_fpage.h:76
l4_fpage_t::raw
l4_umword_t raw
Raw value.
Definition __l4_fpage.h:78
l4_msg_regs_t
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:68
l4_msg_regs_t::mr
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:69