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
93 l4_cap_idx_t target_cap, l4_fpage_t utcb_area) L4_NOTHROW;
94
100l4_factory_create_task_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
101 l4_fpage_t utcb_area, l4_utcb_t *utcb) L4_NOTHROW;
102
122 l4_cap_idx_t target_cap) L4_NOTHROW;
123
129l4_factory_create_thread_u(l4_cap_idx_t factory,
130 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
131
158 unsigned long limit) L4_NOTHROW;
159
165l4_factory_create_factory_u(l4_cap_idx_t factory, l4_cap_idx_t target_cap,
166 unsigned long limit, l4_utcb_t *utcb) L4_NOTHROW;
167
195 l4_cap_idx_t target_cap,
196 l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW;
197
203l4_factory_create_gate_u(l4_cap_idx_t factory,
204 l4_cap_idx_t target_cap,
205 l4_cap_idx_t thread_cap, l4_umword_t label,
206 l4_utcb_t *utcb) L4_NOTHROW;
207
225 l4_cap_idx_t target_cap) L4_NOTHROW;
226
232l4_factory_create_irq_u(l4_cap_idx_t factory,
233 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
234
254 l4_cap_idx_t target_cap) L4_NOTHROW;
255
261l4_factory_create_vm_u(l4_cap_idx_t factory,
262 l4_cap_idx_t target_cap, l4_utcb_t *utcb) L4_NOTHROW;
263
269l4_factory_create_start_u(long obj, l4_cap_idx_t target,
270 l4_utcb_t *utcb) L4_NOTHROW;
271
276L4_INLINE int
277l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
278 l4_utcb_t *utcb) L4_NOTHROW;
279
284L4_INLINE int
285l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
286 l4_utcb_t *utcb) L4_NOTHROW;
287
292L4_INLINE int
293l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
294 l4_utcb_t *utcb) L4_NOTHROW;
295
300L4_INLINE int
301l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
302 l4_utcb_t *utcb) L4_NOTHROW;
303
308L4_INLINE int
309l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
310 l4_utcb_t *utcb) L4_NOTHROW;
311
316L4_INLINE int
317l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
318
324l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
325 l4_utcb_t *utcb) L4_NOTHROW;
326
332l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
333 l4_utcb_t *utcb) L4_NOTHROW;
334
335
353l4_factory_create(l4_cap_idx_t factory, long obj,
354 l4_cap_idx_t target) L4_NOTHROW;
355
356/* IMPLEMENTATION -----------------------------------------------------------*/
357
358#include <l4/sys/ipc.h>
359
361l4_factory_create_task_u(l4_cap_idx_t factory,
362 l4_cap_idx_t target_cap, l4_fpage_t utcb_area,
364{
365 l4_msgtag_t t;
366 t = l4_factory_create_start_u(L4_PROTO_TASK, target_cap, u);
367 l4_factory_create_add_fpage_u(utcb_area, &t, u);
368 return l4_factory_create_commit_u(factory, t, u);
369}
370
372l4_factory_create_thread_u(l4_cap_idx_t factory,
373 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
374{
375 return l4_factory_create_u(factory, L4_PROTO_THREAD, target_cap, u);
376}
377
379l4_factory_create_factory_u(l4_cap_idx_t factory,
380 l4_cap_idx_t target_cap, unsigned long limit,
382{
383 l4_msgtag_t t;
384 t = l4_factory_create_start_u(L4_PROTO_FACTORY, target_cap, u);
385 l4_factory_create_add_uint_u(limit, &t, u);
386 return l4_factory_create_commit_u(factory, t, u);
387}
388
390l4_factory_create_gate_u(l4_cap_idx_t factory,
391 l4_cap_idx_t target_cap,
392 l4_cap_idx_t thread_cap, l4_umword_t label,
394{
395 l4_msgtag_t t;
396 l4_msg_regs_t *v;
397 int items = 0;
398 t = l4_factory_create_start_u(0, target_cap, u);
399 l4_factory_create_add_uint_u(label, &t, u);
400 v = l4_utcb_mr_u(u);
401 if (!(thread_cap & L4_INVALID_CAP_BIT))
402 {
403 items = 1;
404 v->mr[3] = l4_map_obj_control(0,0);
405 v->mr[4] = l4_obj_fpage(thread_cap, 0, L4_CAP_FPAGE_RWS).raw;
406 }
408 return l4_factory_create_commit_u(factory, t, u);
409}
410
412l4_factory_create_irq_u(l4_cap_idx_t factory,
413 l4_cap_idx_t target_cap, l4_utcb_t *u) L4_NOTHROW
414{
415 return l4_factory_create_u(factory, L4_PROTO_IRQ_SENDER, target_cap, u);
416}
417
419l4_factory_create_vm_u(l4_cap_idx_t factory,
420 l4_cap_idx_t target_cap,
422{
423 return l4_factory_create_u(factory, L4_PROTO_VM, target_cap, u);
424}
425
426
427
428
429
432 l4_cap_idx_t target_cap, l4_fpage_t utcb_area) L4_NOTHROW
433{
434 return l4_factory_create_task_u(factory, target_cap, utcb_area, l4_utcb());
435}
436
439 l4_cap_idx_t target_cap) L4_NOTHROW
440{
441 return l4_factory_create_thread_u(factory, target_cap, l4_utcb());
442}
443
446 l4_cap_idx_t target_cap, unsigned long limit) L4_NOTHROW
447
448{
449 return l4_factory_create_factory_u(factory, target_cap, limit, l4_utcb());
450}
451
454 l4_cap_idx_t target_cap,
455 l4_cap_idx_t thread_cap, l4_umword_t label) L4_NOTHROW
456{
457 return l4_factory_create_gate_u(factory, target_cap, thread_cap, label, l4_utcb());
458}
459
462 l4_cap_idx_t target_cap) L4_NOTHROW
463{
464 return l4_factory_create_irq_u(factory, target_cap, l4_utcb());
465}
466
469 l4_cap_idx_t target_cap) L4_NOTHROW
470{
471 return l4_factory_create_vm_u(factory, target_cap, l4_utcb());
472}
473
475l4_factory_create_start_u(long obj, l4_cap_idx_t target_cap,
477{
478 l4_msg_regs_t *v = l4_utcb_mr_u(u);
479 l4_buf_regs_t *b = l4_utcb_br_u(u);
480 v->mr[0] = obj;
481 b->bdr = 0;
482 b->br[0] = target_cap | L4_RCV_ITEM_SINGLE_CAP;
483 return l4_msgtag(L4_PROTO_FACTORY, 1, 0, 0);
484}
485
486L4_INLINE int
487l4_factory_create_add_fpage_u(l4_fpage_t d, l4_msgtag_t *tag,
489{
490 l4_msg_regs_t *v = l4_utcb_mr_u(u);
491 int w = l4_msgtag_words(*tag);
492 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
493 return 0;
494 v->mr[w] = L4_VARG_TYPE_FPAGE | (sizeof(l4_fpage_t) << 16);
495 v->mr[w + 1] = d.raw;
496 w += 2;
497 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
498 return 1;
499}
500
501L4_INLINE int
502l4_factory_create_add_int_u(l4_mword_t d, l4_msgtag_t *tag,
504{
505 l4_msg_regs_t *v = l4_utcb_mr_u(u);
506 int w = l4_msgtag_words(*tag);
507 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
508 return 0;
509 v->mr[w] = L4_VARG_TYPE_MWORD | (sizeof(l4_mword_t) << 16);
510 v->mr[w + 1] = d;
511 w += 2;
512 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
513 return 1;
514}
515
516L4_INLINE int
517l4_factory_create_add_uint_u(l4_umword_t d, l4_msgtag_t *tag,
519{
520 l4_msg_regs_t *v = l4_utcb_mr_u(u);
521 int w = l4_msgtag_words(*tag);
522 if (w + 2 > L4_UTCB_GENERIC_DATA_SIZE)
523 return 0;
524 v->mr[w] = L4_VARG_TYPE_UMWORD | (sizeof(l4_umword_t) << 16);
525 v->mr[w + 1] = d;
526 w += 2;
527 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
528 return 1;
529}
530
531L4_INLINE int
532l4_factory_create_add_str_u(char const *s, l4_msgtag_t *tag,
534{
535 return l4_factory_create_add_lstr_u(s, __builtin_strlen(s) + 1, tag, u);
536}
537
538L4_INLINE int
539l4_factory_create_add_lstr_u(char const *s, unsigned len, l4_msgtag_t *tag,
541{
542
543 l4_msg_regs_t *v = l4_utcb_mr_u(u);
544 unsigned w = l4_msgtag_words(*tag);
545 char *c;
546 unsigned i;
547
548 if (w + 1 + l4_bytes_to_mwords(len) > L4_UTCB_GENERIC_DATA_SIZE)
549 return 0;
550
551 v->mr[w] = L4_VARG_TYPE_STRING | (len << 16);
552 c = (char*)&v->mr[w + 1];
553 for (i = 0; i < len; ++i)
554 *c++ = *s++;
555
556 w = w + 1 + l4_bytes_to_mwords(len);
557
558 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
559 return 1;
560}
561
562L4_INLINE int
563l4_factory_create_add_nil_u(l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
564{
565 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
566 int w = l4_msgtag_words(*tag);
567 v->mr[w] = L4_VARG_TYPE_NIL;
568 ++w;
569 tag->raw = (tag->raw & ~0x3fUL) | (w & 0x3f);
570 return 1;
571}
572
573
575l4_factory_create_commit_u(l4_cap_idx_t factory, l4_msgtag_t tag,
577{
578 return l4_ipc_call(factory, u, tag, L4_IPC_NEVER);
579}
580
582l4_factory_create_u(l4_cap_idx_t factory, long obj, l4_cap_idx_t target,
583 l4_utcb_t *utcb) L4_NOTHROW
584{
585 l4_msgtag_t t = l4_factory_create_start_u(obj, target, utcb);
586 return l4_factory_create_commit_u(factory, t, utcb);
587}
588
589
593{
594 return l4_factory_create_u(factory, obj, target, l4_utcb());
595}
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:358
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:453
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:438
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:461
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:445
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:591
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:431
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:468
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:550
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
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:427
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
Definition types.h:443
unsigned l4_msgtag_flags(l4_msgtag_t t) L4_NOTHROW
Get the flags.
Definition types.h:451
long l4_msgtag_label(l4_msgtag_t t) L4_NOTHROW
Get the protocol of tag.
Definition types.h:439
@ 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
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:82
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:163
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