This example shows how to send IPC using the UTCB to store payload.
This example shows how to send IPC using the UTCB to store payload.
#include <l4/sys/ipc.h>
#include <l4/sys/thread.h>
#include <l4/sys/utcb.h>
#include <l4/sys/task.h>
#include <stdio.h>
static unsigned char stack2[8 << 10] __attribute__((aligned(8)));
static void vlogprintn(const char *s, int l)
{
}
static void vlogprint(const char *s)
{
vlogprintn(s, strlen(s));
}
static void vlogprintc(const char c)
{
vlogprintn(&c, 1);
}
static void thread1(void)
{
int i, j;
printf(
"Thread1 up (%p)\n",
l4_utcb());
for (i = 0; i < 10; i++)
{
for (j = 0; j < L4_UTCB_GENERIC_DATA_SIZE; j++)
mr->
mr[j] =
'A' + (i + j) % (
'~' -
'A' + 1);
tag =
l4_msgtag(0, L4_UTCB_GENERIC_DATA_SIZE, 0, 0);
printf("IPC-send error\n");
}
printf("IPC-send error\n");
printf("Thread1 done\n");
}
L4UTIL_THREAD_STATIC_FUNC(thread2)
{
unsigned i;
vlogprint("Thread2 up\n");
while (1)
{
vlogprint("IPC receive error\n");
break;
vlogprint("Thread2 receive: ");
vlogprintc((
char)mr.
mr[i]);
vlogprint("\n");
}
vlogprint("Thread2 done, switching to thread1\n");
vlogprint("IPC-send error\n");
__builtin_trap();
}
int main(void)
{
{
printf("Cannot allocate thread2 capability\n");
return 1;
}
{
printf("Cannot create thread2\n");
return 2;
}
{
printf("Cannot allocate UTCB for thread2\n");
return 3;
}
{
printf("Cannot set thread2 thread parameters\n");
return 4;
}
{
printf("Cannot set thread2 IP/SP\n");
return 5;
}
{
printf("Cannot start thread2\n");
return 6;
}
thread1();
printf("IPC-receive error\n");
printf("Terminated thread2. Terminating.\n");
return 0;
}
Capability allocator C interface.
Common factory related definitions.
l4_cap_idx_t l4re_util_cap_alloc(void) L4_NOTHROW
Get free capability index at capability allocator.
l4re_env_t * l4re_env(void) L4_NOTHROW
Get L4Re initial environment.
unsigned long l4_umword_t
Unsigned machine word.
unsigned long l4_addr_t
Address type.
unsigned long l4_cap_idx_t
Capability selector type.
unsigned l4_is_invalid_cap(l4_cap_idx_t c) L4_NOTHROW
Test if a capability selector is the invalid capability.
@ L4_BASE_LOG_CAP
Capability selector for the log object.
l4_msgtag_t l4_factory_create_thread(l4_cap_idx_t factory, l4_cap_idx_t target_cap) L4_NOTHROW
Create a new thread.
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.
@ L4_FPAGE_RWX
Read-write-execute flex page.
l4_msgtag_t l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb, l4_timeout_t timeout) L4_NOTHROW
Wait for a message from a specific source.
l4_msgtag_t l4_ipc_send(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag, l4_timeout_t timeout) L4_NOTHROW
Send a message to an object (do not wait for a reply).
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
unsigned l4_msgtag_has_error(l4_msgtag_t t) L4_NOTHROW
Test for error indicator flag.
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
unsigned l4_msgtag_words(l4_msgtag_t t) L4_NOTHROW
Get the number of untyped words.
l4_msgtag_t l4_scheduler_run_thread(l4_cap_idx_t scheduler, l4_cap_idx_t thread, l4_sched_param_t const *sp) L4_NOTHROW)
Run a thread on a Scheduler.
l4_sched_param_t l4_sched_param(unsigned prio, l4_umword_t quantum=0) L4_NOTHROW
Construct scheduler parameter.
l4_msgtag_t l4_task_unmap(l4_cap_idx_t task, l4_fpage_t fpage, l4_umword_t map_mask) L4_NOTHROW
Revoke rights from the task.
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to revoke permissions from all child mappings including the mapping ...
l4_msgtag_t l4_thread_ex_regs(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp, l4_umword_t flags) L4_NOTHROW
Exchange basic thread registers.
void l4_thread_control_bind(l4_utcb_t *thread_utcb, l4_cap_idx_t task) L4_NOTHROW
Bind the thread to a task.
l4_msgtag_t l4_thread_control_commit(l4_cap_idx_t thread) L4_NOTHROW
Commit the thread control parameters.
void l4_thread_control_exc_handler(l4_cap_idx_t exc_handler) L4_NOTHROW
Set the exception handler.
void l4_thread_control_start(void) L4_NOTHROW
Start a thread control API sequence.
void l4_thread_control_pager(l4_cap_idx_t pager) L4_NOTHROW
Set the pager.
#define L4_IPC_NEVER
never timeout
l4_msg_regs_t * l4_utcb_mr(void) L4_NOTHROW L4_PURE
Get the message-register block of a UTCB.
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
l4_msgtag_t l4_vcon_send(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Send data to virtual console.
@ L4_VCON_WRITE_SIZE
Maximum size that can be written with one l4_vcon_write call.
Kumem allocator utility C interface.
int l4re_util_kumem_alloc(l4_addr_t *mem, unsigned pages_order, l4_cap_idx_t task, l4_cap_idx_t rm) L4_NOTHROW
Allocate state area.
Low-level Thread Functions.
Message tag data structure.
l4_cap_idx_t main_thread
Object-capability of the first user thread.
Encapsulation of the message-register block in the UTCB.
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Virtual console interface.