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 * 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
98 l4_fpage_t *utcb_area) L4_NOTHROW;
99
105l4_factory_create_task_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
106 l4_fpage_t *utcb_area, l4_utcb_t *utcb) L4_NOTHROW;
107
127 l4_cap_idx_t target_cap) L4_NOTHROW;
128
134l4_factory_create_thread_u(l4_cap_idx_t factory,
135 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
136
163 unsigned long limit) L4_NOTHROW;
164
170l4_factory_create_factory_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
171 unsigned long limit, l4_utcb_t *utcb) L4_NOTHROW;
172
200 l4_cap_idx_t target_cap,
201 l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW;
202
208l4_factory_create_gate_u(l4_cap_idx_t factory,
209 l4_cap_idx_t target_cap,
210 l4_cap_idx_t thread_cap, l4_umword_t label,
211 l4_utcb_t *utcb) L4_NOTHROW;
212
230 l4_cap_idx_t target_cap) L4_NOTHROW;
231
237l4_factory_create_irq_u(l4_cap_idx_t factory,
238 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
239
259 l4_cap_idx_t target_cap) L4_NOTHROW;
260
281 l4_cap_idx_t target_cap) L4_NOTHROW;
282
288l4_factory_create_vm_u(l4_cap_idx_t factory,
289 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
290
296l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
297 l4_cap_idx_t target_cap,
298 l4_utcb_t *utcb) L4_NOTHROW;
299
305l4_factory_create_start_u(long obj, l4_cap_idx_t target,
306 l4_utcb_t *utcb) L4_NOTHROW;
307
312L4_INLINE int
313l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
314 l4_utcb_t *utcb) L4_NOTHROW;
315
320L4_INLINE int
321l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
322 l4_utcb_t *utcb) L4_NOTHROW;
323
328L4_INLINE int
329l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
330 l4_utcb_t *utcb) L4_NOTHROW;
331
336L4_INLINE int
337l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
338 l4_utcb_t *utcb) L4_NOTHROW;
339
344L4_INLINE int
345l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
346 l4_utcb_t *utcb) L4_NOTHROW;
347
352L4_INLINE int
353l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
354
360l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
361 l4_utcb_t *utcb) L4_NOTHROW;
362
368l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
369 l4_utcb_t *utcb) L4_NOTHROW;
370
371
389l4_factory_create(l4_cap_idx_t factory, long obj,
390 l4_cap_idx_t target) L4_NOTHROW;
391
392/* IMPLEMENTATION -----------------------------------------------------------*/
393
394#include <l4/sys/ipc.h>
395
397l4_factory_create_task_u(l4_cap_idx_t factory,
398 l4_cap_idx_t target_cap, l4_fpage_t *utcb_area,
400{
401 l4_msgtag_t t;
402 t = l4_factory_create_start_u(L4_PROTO_TASK, target_cap, u);
403 l4_factory_create_add_fpage_u(*utcb_area, &t, u);
404 t = l4_factory_create_commit_u(factory, t, u);
405 if (!l4_msgtag_has_error(t))
406 {
407 l4_msg_regs_t *v = l4_utcb_mr_u(u);
408 utcb_area->raw = v->mr[0];
409 }
410 return t;
411}
412
414l4_factory_create_thread_u(l4_cap_idx_t factory,
415 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
416{
417 return l4_factory_create_u(factory, L4_PROTO_THREAD, target_cap, u);
418}
419
421l4_factory_create_factory_u(l4_cap_idx_t factory,
422 l4_cap_idx_t target_cap, unsigned long limit,
424{
425 l4_msgtag_t t;
426 t = l4_factory_create_start_u(L4_PROTO_FACTORY, target_cap, u);
427 l4_factory_create_add_uint_u(limit, &t, u);
428 return l4_factory_create_commit_u(factory, t, u);
429}
430
432l4_factory_create_gate_u(l4_cap_idx_t factory,
433 l4_cap_idx_t target_cap,
434 l4_cap_idx_t thread_cap, l4_umword_t label,
436{
437 l4_msgtag_t t;
438 l4_msg_regs_t *v;
439 int items = 0;
440 t = l4_factory_create_start_u(0, target_cap, u);
441 l4_factory_create_add_uint_u(label, &t, u);
442 v = l4_utcb_mr_u(u);
443 if (!(thread_cap & L4_INVALID_CAP_BIT))
444 {
445 items = 1;
446 v->mr[3] = l4_map_obj_control(0,0);
447 v->mr[4] = l4_obj_fpage(thread_cap, 0, L4_CAP_FPAGE_RWS).raw;
448 }
450 return l4_factory_create_commit_u(factory, t, u);
451}
452
454l4_factory_create_irq_u(l4_cap_idx_t factory,
455 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
456{
457 return l4_factory_create_u(factory, L4_PROTO_IRQ_SENDER, target_cap, u);
458}
459
461l4_factory_create_vm_u(l4_cap_idx_t factory,
462 l4_cap_idx_t target_cap,
464{
465 return l4_factory_create_u(factory, L4_PROTO_VM, target_cap, u);
466}
467
469l4_factory_create_vcpu_context_u(l4_cap_idx_t factory,
470 l4_cap_idx_t target_cap,
472{
473 return l4_factory_create_u(factory, L4_PROTO_VCPU_CONTEXT, target_cap, u);
474}
475
476
477
478
479
482 l4_cap_idx_t target_cap, l4_fpage_t *utcb_area) L4_NOTHROW
483{
484 return l4_factory_create_task_u(factory, target_cap, utcb_area, l4_utcb());
485}
486
489 l4_cap_idx_t target_cap) L4_NOTHROW
490{
491 return l4_factory_create_thread_u(factory, target_cap, l4_utcb());
492}
493
496 l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
497
498{
499 return l4_factory_create_factory_u(factory, target_cap, limit, l4_utcb());
500}
501
504 l4_cap_idx_t target_cap,
505 l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW
506{
507 return l4_factory_create_gate_u(factory, target_cap, thread_cap, label, l4_utcb());
508}
509
512 l4_cap_idx_t target_cap) L4_NOTHROW
513{
514 return l4_factory_create_irq_u(factory, target_cap, l4_utcb());
515}
516
519 l4_cap_idx_t target_cap) L4_NOTHROW
520{
521 return l4_factory_create_vm_u(factory, target_cap, l4_utcb());
522}
523
526 l4_cap_idx_t target_cap) L4_NOTHROW
527{
528 return l4_factory_create_vcpu_context_u(factory, target_cap, l4_utcb());
529}
530
532l4_factory_create_start_u(long obj, l4_cap_idx_t target_cap,
534{
535 l4_msg_regs_t *v = l4_utcb_mr_u(u);
536 l4_buf_regs_t *b = l4_utcb_br_u(u);
537 v->mr[0] = obj;
538 b->bdr = 0;
539 b->br[0] = target_cap | L4_RCV_ITEM_SINGLE_CAP;
540 return l4_msgtag(L4_PROTO_FACTORY, 1, 0, 0);
541}
542
543L4_INLINE int
544l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
546{
547 l4_msg_regs_t *v = l4_utcb_mr_u(u);
548 int w = l4_msgtag_words(*tag);
549 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
550 return 0;
551 v->mr[w] = L4_VARG_TYPE_FPAGE | (sizeof(l4_fpage_t) << 16);
552 v->mr[w + 1] = d.raw;
553 w += 2;
554 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
555 return 1;
556}
557
558L4_INLINE int
559l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
561{
562 l4_msg_regs_t *v = l4_utcb_mr_u(u);
563 int w = l4_msgtag_words(*tag);
564 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
565 return 0;
566 v->mr[w] = L4_VARG_TYPE_MWORD | (sizeof(l4_mword_t) << 16);
567 v->mr[w + 1] = d;
568 w += 2;
569 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
570 return 1;
571}
572
573L4_INLINE int
574l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
576{
577 l4_msg_regs_t *v = l4_utcb_mr_u(u);
578 int w = l4_msgtag_words(*tag);
579 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
580 return 0;
581 v->mr[w] = L4_VARG_TYPE_UMWORD | (sizeof(l4_umword_t) << 16);
582 v->mr[w + 1] = d;
583 w += 2;
584 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
585 return 1;
586}
587
588L4_INLINE int
589l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
591{
592 return l4_factory_create_add_lstr_u(s, __builtin_strlen(s) + 1, tag, u);
593}
594
595L4_INLINE int
596l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
598{
599
600 l4_msg_regs_t *v = l4_utcb_mr_u(u);
601 unsigned w = l4_msgtag_words(*tag);
602 char *c;
603 unsigned i;
604
605 if (w + 1 + l4_bytes_to_mwords(len) > L4_UTCB_GENERIC_DATA_SIZE)
606 return 0;
607
608 v->mr[w] = L4_VARG_TYPE_STRING | (len << 16);
609 c = (char*)&v->mr[w + 1];
610 for (i = 0; i < len; ++i)
611 *c++ = *s++;
612
613 w = w + 1 + l4_bytes_to_mwords(len);
614
615 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
616 return 1;
617}
618
619L4_INLINE int
620l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
621{
622 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
623 int w = l4_msgtag_words(*tag);
624 v->mr[w] = L4_VARG_TYPE_NIL;
625 ++w;
626 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
627 return 1;
628}
629
630
632l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
634{
635 return l4_ipc_call(factory, u, tag, L4_IPC_NEVER);
636}
637
639l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
640 l4_utcb_t *utcb) L4_NOTHROW
641{
642 l4_msgtag_t t = l4_factory_create_start_u(obj, target, utcb);
643 return l4_factory_create_commit_u(factory, t, utcb);
644}
645
646
650{
651 return l4_factory_create_u(factory, obj, target, l4_utcb());
652}
L4 compiler related defines.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
signed long l4_mword_t
Signed machine word.
Definition l4int.h:48
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:359
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:503
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:488
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:511
l4_msgtag_t l4_factory_create_vcpu_context(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new hardware vCPU context.
Definition factory.h:525
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:495
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:481
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:648
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:518
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:680
@ L4_CAP_FPAGE_RWS
Read, interface specific 'W', and 'S' rights for capability flex-pages.
Definition __l4_fpage.h:209
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:576
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:485
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:714
@ 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:266
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
Definition types.h:457
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:428
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition types.h:444
unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
Get the flags.
Definition types.h:452
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:440
@ L4_PROTO_FACTORY
Protocol for messages to a factory object.
Definition types.h:67
@ L4_PROTO_IRQ_SENDER
Protocol for IRQ senders (IRQ -> IPC)
Definition types.h:70
@ L4_PROTO_TASK
Protocol for messages to a task object.
Definition types.h:63
@ L4_PROTO_VM
Protocol for messages to a virtual machine object.
Definition types.h:68
@ L4_PROTO_THREAD
Protocol for messages to a thread object.
Definition types.h:64
@ L4_PROTO_VCPU_CONTEXT
Protocol for hardware vCPU contexts.
Definition types.h:77
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:84
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:188
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
Common L4 ABI Data Types.
Encapsulation of the buffer-registers block in the UTCB.
Definition utcb.h:94
l4_umword_t br[L4_UTCB_GENERIC_BUFFERS_SIZE]
Buffer registers.
Definition utcb.h:99
l4_umword_t bdr
Buffer descriptor.
Definition utcb.h:96
Message tag data structure.
Definition types.h:164
L4 flexpage type.
Definition __l4_fpage.h:85
l4_umword_t raw
Raw value.
Definition __l4_fpage.h:87
Encapsulation of the message-register block in the UTCB.
Definition utcb.h:79
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition utcb.h:80