diff --git a/src/generic/capability.c b/src/generic/capability.c index 0d40639..890eec5 100644 --- a/src/generic/capability.c +++ b/src/generic/capability.c @@ -6,6 +6,12 @@ #include #include +void capability_init(struct capability *cap) +{ + cap->capid = id_new(&kernel_container.capability_ids); + link_init(&cap->list); +} + struct capability *capability_create(void) { struct capability *cap = alloc_capability(); @@ -15,9 +21,3 @@ struct capability *capability_create(void) return cap; } -void capability_init(struct capability *cap) -{ - cap->capid = id_new(&kernel_container.capability_ids); - link_init(&cap->list); -} - diff --git a/tasks/mm0/include/capability.h b/tasks/mm0/include/capability.h index 3460500..3294bc4 100644 --- a/tasks/mm0/include/capability.h +++ b/tasks/mm0/include/capability.h @@ -37,5 +37,6 @@ extern struct cap_list capability_list; struct initdata; int read_kernel_capabilities(struct initdata *); +void copy_boot_capabilities(struct initdata *initdata); #endif /* __MM0_CAPABILITY_H__ */ diff --git a/tasks/mm0/include/linker.lds b/tasks/mm0/include/linker.lds index 0d5ba22..ffd56a2 100644 --- a/tasks/mm0/include/linker.lds +++ b/tasks/mm0/include/linker.lds @@ -36,16 +36,20 @@ SECTIONS .bss : AT (ADDR(.bss) - pager_offset) { *(.bss) } . = ALIGN(4K); . += 0x2000; /* BSS doesnt increment link counter??? */ + .stack : AT (ADDR(.stack) - pager_offset) + { + *(.stack) + } + . = ALIGN(4K); + __stack = .; /* This is the preallocated boot stack */ + /* Below part is to be discarded after boot */ _start_init = .; .init : AT (ADDR(.init) - pager_offset) { *(.init.data) *(.init.bootmem) - *(.init.stack) } _end_init = .; - __stack = .; /* This is the preallocated boot stack */ - _end_init = .; _end = .; } diff --git a/tasks/mm0/src/bootm.c b/tasks/mm0/src/bootm.c index 393f99a..cf7a602 100644 --- a/tasks/mm0/src/bootm.c +++ b/tasks/mm0/src/bootm.c @@ -20,7 +20,7 @@ #define BOOTMEM_SIZE SZ_32K SECTION(".init.bootmem") char bootmem[BOOTMEM_SIZE]; -SECTION(".init.stack") char stack[4096]; +SECTION(".stack") char stack[4096]; // SECTION("init.data") extern unsigned long __stack[]; /* Linker defined */ diff --git a/tasks/mm0/src/capability.c b/tasks/mm0/src/capability.c index e82653b..b89acb9 100644 --- a/tasks/mm0/src/capability.c +++ b/tasks/mm0/src/capability.c @@ -5,14 +5,36 @@ */ #include #include +#include #include #include #include #include /* TODO: Move this to API */ +#include -extern struct cap_list capability_list; +struct cap_list capability_list; __initdata static struct capability *caparray; +__initdata static int total_caps = 0; + +/* Copy all init-memory allocated capabilities */ +void copy_boot_capabilities(struct initdata *initdata) +{ + struct capability *cap; + + for (int i = 0; i < total_caps; i++) { + cap = kzalloc(sizeof(struct capability)); + + /* This copies kernel-allocated unique cap id as well */ + memcpy(cap, &caparray[i], sizeof(struct capability)); + + /* Initialize capability list */ + link_init(&cap->list); + + /* Add capability to global cap list */ + list_insert(&capability_list.caps, &cap->list); + } +} int read_kernel_capabilities(struct initdata *initdata) { @@ -25,6 +47,7 @@ int read_kernel_capabilities(struct initdata *initdata) "Could not complete CAP_CONTROL_NCAPS request.\n"); goto error; } + total_caps = ncaps; /* Allocate array of caps from boot memory */ caparray = alloc_bootmem(sizeof(struct capability) * ncaps, 0); diff --git a/tasks/mm0/src/init.c b/tasks/mm0/src/init.c index d3521b7..e35530f 100644 --- a/tasks/mm0/src/init.c +++ b/tasks/mm0/src/init.c @@ -207,6 +207,33 @@ int start_boot_tasks(struct initdata *initdata) return 0; } +extern unsigned long _start_init[]; +extern unsigned long _end_init[]; + +/* + * Copy all necessary data from initmem to real memory, + * release initdata and any init memory used + */ +void copy_release_initdata(struct initdata *initdata) +{ + /* + * Copy boot capabilities to a list of + * real capabilities + */ + copy_boot_capabilities(initdata); + + /* Free and unmap init memory: + * + * FIXME: We can and do safely unmap the boot + * memory here, but because we don't utilize it yet, + * it remains as if it is a used block + */ + + l4_unmap(_start_init, + __pfn(page_align_up(_end_init - _start_init)), + self_tid()); +} + void init_mm(struct initdata *initdata) { @@ -257,6 +284,9 @@ void init_pager(void) start_boot_tasks(&initdata); + /* Copy necessary initdata info */ + copy_release_initdata(&initdata); + mm0_test_global_vm_integrity(); } diff --git a/tasks/mm0/src/pagers.c b/tasks/mm0/src/pagers.c index 4c356ca..ed3512f 100644 --- a/tasks/mm0/src/pagers.c +++ b/tasks/mm0/src/pagers.c @@ -304,7 +304,11 @@ int init_boot_files(struct initdata *initdata) for (int i = 0; i < bd->total_images; i++) { img = &bd->images[i]; boot_file = vm_file_create(); - boot_file->priv_data = img; + + /* Allocate private data */ + boot_file->priv_data = kzalloc(sizeof(*img)); + memcpy(boot_file->priv_data, img, sizeof(*img)); + boot_file->length = img->phys_end - img->phys_start; boot_file->type = VM_FILE_BOOTFILE; boot_file->destroy_priv_data =