#include "app.h"
#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <l4/sys/consts.h>
#include <l4/env/errno.h>
#include <l4/sys/kdebug.h>
#include <l4/sys/syscalls.h>
#include <l4/sys/cache.h>
#include <l4/l4rm/l4rm.h>
#include <l4/log/l4log.h>
#include <l4/env/mb_info.h>
#include <l4/util/util.h>
#include <l4/util/stack.h>
#include <l4/util/macros.h>
#include <l4/util/memdesc.h>
#include <l4/dm_mem/dm_mem.h>
#include <l4/dm_phys/dm_phys.h>
#include <l4/generic_ts/generic_ts.h>
#include <l4/loader/loader.h>
#include <l4/util/elf.h>
#include <l4/ipcmon/ipcmon.h>
#include "elf-loader.h"
#include "fprov-if.h"
#include "dm-if.h"
#include "trampoline.h"
#include "pager.h"
#include "debug.h"
Defines | |
#define | MAX_APP 32 |
#define | APP_ADDR_ENVPAGE 0x00007000 |
position of L4 environment infopage in target app's address space. | |
#define | APP_ADDR_STACK 0x00009000 |
position of initial stack in target application's address space. | |
#define | APP_ADDR_LIBLOADER 0x00010000 |
position of libloader.s.so in target application's address space. | |
#define | APP_ADDR_LDSO 0x00010000 |
position of libld-l4.s.so in target application's address space. | |
#define | APP_TRAMP_SIZE L4_PAGESIZE |
must be set to PAGESIZE since startup code in l4env/lib/src/startup.c depends on it | |
Functions | |
app_t * | task_to_app (l4_threadid_t tid) |
Return the address of the task struct. | |
void | app_msg (app_t *app, const char *format,...) |
Dump a message corresponding to an application. | |
static void | dump_l4env_infopage (app_t *app) |
Debug function to show sections of the L4 environment infopage. | |
int | create_app_desc (app_t **new_app) |
Create a new app_t descriptor. | |
static void | app_publish_symbols (app_t *app) |
Make symbolic information known by Fiasco. | |
static void | app_publish_lines (app_t *app) |
Make debug line number information known by Fiasco. | |
static void | app_publish_lines_symbols (app_t *app) |
static void | app_unpublish_symbols (app_t *app) |
Retire symbolic debug information of an application from Fiasco. | |
static void | app_unpublish_lines (app_t *app) |
Retire symbolic debug information of an application from Fiasco. | |
static int | app_create_infopage (app_t *app) |
Create the application's infopage. | |
static int | app_create_iobitmap (app_t *app, cfg_task_t *ct) |
Create I/O permission bitmap. | |
int | init_infopage (l4env_infopage_t *env) |
Initialize the application's environment infopage. | |
static l4_addr_t | alloc_from_tramp_page (l4_size_t size, app_addr_t *tramp_page, l4_addr_t *tramp_page_addr) |
allocate space from a "page" _downwards_. | |
Application sections | |
static app_area_t * | create_app_area_desc (app_t *app) |
Create a new area application descriptor. | |
static void | list_app_areas (app_t *app) |
static int | sanity_check_app_area (app_t *app, app_area_t **check_aa) |
Check if new app_area overlaps with exisiting areas. | |
static l4_addr_t | app_find_free_virtual_area (app_t *app, l4_size_t size, l4_addr_t low, l4_addr_t high) |
Find a free virtual address range. | |
void | app_list_addr (app_t *app) |
Dump all app_areas for debugging purposes. | |
int | app_attach_ds_to_pager (app_t *app, l4dm_dataspace_t *ds, l4_addr_t addr, l4_size_t size, l4_uint16_t type, l4_uint32_t rights, const char *dbg_name, app_area_t **aa) |
Attach dataspace to pager. | |
static int | app_attach_section_to_pager (l4exec_section_t *l4exc_start, l4env_infopage_t *env, app_t *app) |
Attach a section which should be paged by the loader pager. | |
static int | app_attach_sections_to_pager (app_t *app) |
Go through all sections of the infopage and try to attach the section to our address space so the pager thread can page the section. | |
static int | app_create_ds (app_t *app, l4_addr_t app_addr, l4_size_t size, app_area_t **ret_aa, const char *dbg_name) |
Create dataspace of anonymous memory mapped into the new application. | |
void | app_share_sections_with_client (app_t *app, l4_threadid_t client) |
Share all sections which are not exclusiv owned by the applications to the application. | |
Create application resources | |
static int | load_modules (cfg_task_t *ct, app_t *app, l4_threadid_t fprov_id, app_addr_t *tramp_page, l4_addr_t *tramp_page_addr, l4util_mb_info_t *mbi) |
Load boot modules. | |
static void | load_vbe_info (app_t *app, app_addr_t *tramp_page, l4_addr_t *tramp_page_addr, l4util_mb_info_t *mbi) |
static int | app_create_mb_info (cfg_task_t *ct, app_t *app, app_addr_t *tramp_page, l4_addr_t *tramp_page_addr, l4_threadid_t fprov_id, l4util_mb_info_t **multiboot_info) |
Create multiboot info at stack page. | |
static int | app_create_phys_memory (app_t *app, l4_size_t size, int cfg_flags, int pool) |
Create physical memory for an application. | |
Start application | |
static int | app_create_tid (app_t *app) |
Allocate the task number. | |
static int | app_start_static (cfg_task_t *ct, app_t *app) |
Start application the old way. | |
static void | app_setup_caps (app_t *app) |
static l4_quota_desc_t | app_setup_kquota (app_t *app) |
static int | app_cont_static (app_t *app) |
static int | app_start_interp (cfg_task_t *ct, app_t *app) |
static int | app_cont_interp (app_t *app) |
Task actions | |
static int | app_cleanup_extern (app_t *app) |
Cleanup application (external resources). | |
static int | app_cleanup_intern (app_t *app) |
Cleanup application (internal resources). | |
static int | app_init (cfg_task_t *ct, l4_taskid_t owner, app_t **ret_val) |
Start the application. | |
int | app_cont (app_t *app) |
int | app_boot (cfg_task_t *ct, l4_taskid_t owner) |
int | app_kill (l4_taskid_t task_id, l4_taskid_t caller) |
Kill application. | |
int | app_dump (unsigned long task_id) |
Dump application to standard output. | |
int | app_info (unsigned long task_id, l4dm_dataspace_t *l4env_ds, l4_threadid_t client, char **fname) |
Deliver application info to flexpage. | |
Variables | |
static int | app_next_free = 0 |
number of next free app_t in app_array. | |
static app_t | app_array [32] |
int | use_events |
use events server. |
applications
static l4_addr_t alloc_from_tramp_page | ( | l4_size_t | size, | |
app_addr_t * | tramp_page, | |||
l4_addr_t * | tramp_page_addr | |||
) | [static] |
allocate space from a "page" _downwards_.
int app_attach_ds_to_pager | ( | app_t * | app, | |
l4dm_dataspace_t * | ds, | |||
l4_addr_t | addr, | |||
l4_size_t | size, | |||
l4_uint16_t | type, | |||
l4_uint32_t | rights, | |||
const char * | dbg_name, | |||
app_area_t ** | aa | |||
) |
Attach dataspace to pager.
Therefore it is accessible by the application.
app | application | |
ds | dataspace to attach | |
addr | start address of dataspace inside application. If L4_MAX_ADDRESS, then do not make the dataspace accessible from the application but only register to allow smoothly shutdown of dataspace on exit of the application. | |
size | size of dataspace | |
type | type | |
rights | rights for the pager | |
dbg_name | name of application area for debugging purposes |
aa | application area |
< forward pagefaults to ds
static int app_attach_section_to_pager | ( | l4exec_section_t * | l4exc_start, | |
l4env_infopage_t * | env, | |||
app_t * | app | |||
) | [static] |
Attach a section which should be paged by the loader pager.
l4exc_start | first l4exec_section | |
env | L4 environment infopage | |
app | application |
< don't page superpages
< don't page superpages
static int app_attach_sections_to_pager | ( | app_t * | app | ) | [static] |
Go through all sections of the infopage and try to attach the section to our address space so the pager thread can page the section.
We only attach sections which are
(1) relocated (L4_DSTYPE_RELOCME bit is cleared) (2) are not yet attached (L4_DSTYPE_PAGEME bit is set)
app | application descriptor |
int app_boot | ( | cfg_task_t * | ct, | |
l4_taskid_t | owner | |||
) |
< stop app just before start
static int app_cleanup_intern | ( | app_t * | app | ) | [static] |
Cleanup application (internal resources).
Do only cleanup for loader and exec server.
int app_cont | ( | app_t * | app | ) |
< ensure that we cont only once
< ensure that we cont only once
< emulate sigma0 style application
static int app_cont_static | ( | app_t * | app | ) | [static] |
< show app areas before start
static int app_create_ds | ( | app_t * | app, | |
l4_addr_t | app_addr, | |||
l4_size_t | size, | |||
app_area_t ** | ret_aa, | |||
const char * | dbg_name | |||
) | [static] |
Create dataspace of anonymous memory mapped into the new application.
The dataspace is also mapped into this application.
app | application descriptor | |
app_addr | virtual address of dataspace in application may be L4_MAX_ADDRESS of area is not pageable to application (status information an so on) | |
size | size of dataspace |
ret_aa | filled out app_area |
dbg_name | name of dataspace for debugging purposes |
static int app_create_infopage | ( | app_t * | app | ) | [static] |
Create the application's infopage.
app | application descriptor |
static int app_create_iobitmap | ( | app_t * | app, | |
cfg_task_t * | ct | |||
) | [static] |
Create I/O permission bitmap.
app | application descriptor | |
ct | config task descriptor |
static int app_create_mb_info | ( | cfg_task_t * | ct, | |
app_t * | app, | |||
app_addr_t * | tramp_page, | |||
l4_addr_t * | tramp_page_addr, | |||
l4_threadid_t | fprov_id, | |||
l4util_mb_info_t ** | multiboot_info | |||
) | [static] |
Create multiboot info at stack page.
Load boot modules.
ct | config task descriptor | |
app | application descriptor | |
tramp_page | base address in our / application's address space | |
tramp_page_addr | address in our address space | |
fprov_id | file provider | |
multiboot_info | pointer to mbi |
static int app_create_phys_memory | ( | app_t * | app, | |
l4_size_t | size, | |||
int | cfg_flags, | |||
int | pool | |||
) | [static] |
Create physical memory for an application.
< emulate sigma0 style application
< don't page superpages
static int app_create_tid | ( | app_t * | app | ) | [static] |
Allocate the task number.
app | application descriptor |
int app_dump | ( | unsigned long | task_id | ) |
Dump application to standard output.
task_id | L4 task id or 0 to dump all tasks |
static l4_addr_t app_find_free_virtual_area | ( | app_t * | app, | |
l4_size_t | size, | |||
l4_addr_t | low, | |||
l4_addr_t | high | |||
) | [static] |
Find a free virtual address range.
This is only necessary for sigma0 applications because in l4env-style applications, we let the region manager manager decide where a region lives.
< entry is valid
int app_info | ( | unsigned long | task_id, | |
l4dm_dataspace_t * | l4env_ds, | |||
l4_threadid_t | client, | |||
char ** | fname | |||
) |
Deliver application info to flexpage.
task_id | L4 task id | |
l4env_ds | dataspace containing l4env infopage information | |
client | Client to transfer the ownership to |
fname | application name |
static int app_init | ( | cfg_task_t * | ct, | |
l4_taskid_t | owner, | |||
app_t ** | ret_val | |||
) | [static] |
Start the application.
ct | config task descriptor | |
owner | the owner of the task (for transfering the ownership of the task ID) |
ret_val | created application descriptor |
< sections are mapped 1:1
< map program sections one-by-one
< allow access to vga memory
< access to VGA memory allowed
< allow killing other apps
< killing other apps is allowed
< allow access to BIOS memory
< access to BIOS allowed
< dont page other regions
< don't page other regions
< task may execute cli/sti
< task may execute cli/sti
< show app areas before start
< show app areas before start
< stop app just before start
< stop app just before start
< don't use superpages
< don't page superpages
< all sections writable
< all sections writable
< load symbols
< load lines information
< interpret using libld-l4.s.so
< interpret using libld-l4.s.so
< l4env binary with infopage
< emulate sigma0 style application
int app_kill | ( | l4_taskid_t | task_id, | |
l4_taskid_t | caller | |||
) |
Kill application.
task_id | task to be killed | |
caller_id | task which wants to kill task_id |
< killing other apps is allowed
void app_list_addr | ( | app_t * | app | ) |
Dump all app_areas for debugging purposes.
void app_msg | ( | app_t * | app, | |
const char * | format, | |||
... | ||||
) |
Dump a message corresponding to an application.
If the application has already an task number, print it in hashes after the name of the application.
static void app_publish_lines | ( | app_t * | app | ) | [inline, static] |
Make debug line number information known by Fiasco.
static void app_publish_lines_symbols | ( | app_t * | app | ) | [static] |
< load symbols
< load lines information
static void app_publish_symbols | ( | app_t * | app | ) | [inline, static] |
Make symbolic information known by Fiasco.
void app_share_sections_with_client | ( | app_t * | app, | |
l4_threadid_t | client | |||
) |
Share all sections which are not exclusiv owned by the applications to the application.
Modules have the L4_DSTYPE_APP_IS_OWNER bit set which means that their ownership is already transfered to the application
static int app_start_static | ( | cfg_task_t * | ct, | |
app_t * | app | |||
) | [static] |
Start application the old way.
Create stack page, create a valid multiboot info structure and copy the trampoline code. Then start the new task
ct | config task descriptor | |
app | application descriptor |
< l4env binary with infopage
< l4env binary with infopage
static void app_unpublish_lines | ( | app_t * | app | ) | [inline, static] |
Retire symbolic debug information of an application from Fiasco.
static void app_unpublish_symbols | ( | app_t * | app | ) | [inline, static] |
Retire symbolic debug information of an application from Fiasco.
static app_area_t* create_app_area_desc | ( | app_t * | app | ) | [static] |
Create a new area application descriptor.
app | application descriptor |
new_app_area | new application area descriptor |
< maximum entries for memory regions of an application
< maximum entries for memory regions of an application
int create_app_desc | ( | app_t ** | new_app | ) |
Create a new app_t descriptor.
new_app | pointer to new app descriptor |
static void dump_l4env_infopage | ( | app_t * | app | ) | [static] |
Debug function to show sections of the L4 environment infopage.
int init_infopage | ( | l4env_infopage_t * | env | ) |
Initialize the application's environment infopage.
env | pointer to L4env infopage |
static void list_app_areas | ( | app_t * | app | ) | [static] |
< entry is valid
static int load_modules | ( | cfg_task_t * | ct, | |
app_t * | app, | |||
l4_threadid_t | fprov_id, | |||
app_addr_t * | tramp_page, | |||
l4_addr_t * | tramp_page_addr, | |||
l4util_mb_info_t * | mbi | |||
) | [static] |
Load boot modules.
ct | config task descriptor | |
app | application descriptor | |
fprov_id | file provider | |
tramp_page | address of trampoline page in our / application's address space | |
tramp_page_addr | address in our address space | |
mbi | pointer to mbi |
< map program sections one-by-one
< hash multi-boot modules, too
< hash multi-boot modules, too
< map program sections one-by-one
< emulate sigma0 style application
< emulate sigma0 style application
< map program sections one-by-one
static int sanity_check_app_area | ( | app_t * | app, | |
app_area_t ** | check_aa | |||
) | [static] |
Check if new app_area overlaps with exisiting areas.
< entry is valid
< entry is valid
app_t* task_to_app | ( | l4_threadid_t | tid | ) |
Return the address of the task struct.
tid | L4 thread ID |
int app_next_free = 0 [static] |
number of next free app_t in app_array.
int use_events |
use events server.