#include #include #include #include #include #include static char new_task_stack[4096]; static void function_in_new_task (void) { printf ("goodbye world task %d\n", l4_myself ().id.task); for (;;) {} } int main (void) { int ret; l4_threadid_t new_id; printf ("hello world task %u\n", l4_myself ().id.task); /* initialize Rmgr interface */ ret = rmgr_init (); assert (ret); /* get a task-creation right */ ret = rmgr_get_task (10); assert (ret == 0); /* task-creation arguments: use myself as prototype */ new_id = l4_myself(); new_id.id.task = 10; /* create new task */ new_id = l4_task_new (new_id, /* New ID */ 0, /* MCP */ (dword_t) (new_task_stack + sizeof(new_task_stack)), /* Stack */ (dword_t) (function_in_new_task), /* Program counter */ l4_myself()); /* Pager: Let me be the pager. */ assert (! thread_equal (new_id, L4_NIL_ID)); /* handle paging requests */ for (;;) { int error; l4_msgdope_t result; dword_t word0, word1; error = l4_i386_ipc_receive (new_id, L4_IPC_SHORT_MSG, &word0, &word1, L4_IPC_NEVER, &result); if (error) { printf("IPC receive error 0x%x\n", error); exit (1); } /* Page fault */ if (word0 & 2) /* write page fault */ { /* Ensure that this is not optimized away by the compiler... */ *(volatile char *)word0 |= 0; } else /* read page_fault */ { volatile char c = *(char *)word0; (void) c; } error = l4_i386_ipc_send(new_id, L4_IPC_SHORT_FPAGE, word0 & ~(4096-1), l4_fpage(word0, L4_LOG2_PAGESIZE, 1, 0).fpage, L4_IPC_NEVER, &result); if (error) { printf("ipc send error 0x%x\n", error); exit(1); } } return 0; }