From 270c3cd23333668696da3e81c3f60ff5d4fc1ad8 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 21 Nov 2014 00:23:39 +0100 Subject: [PATCH gnumach] XXX --- kern/bootstrap.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/kern/bootstrap.c b/kern/bootstrap.c index 4edae7b..9c2eb87 100644 --- a/kern/bootstrap.c +++ b/kern/bootstrap.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -422,23 +423,19 @@ boot_read(void *handle, vm_offset_t file_ofs, void *buf, vm_size_t size, } static int -read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size, +read_in(void *handle, vm_offset_t file_ofs, vm_size_t file_size, vm_offset_t mem_addr, vm_size_t mem_size, - exec_sectype_t sec_type) + vm_prot_t mem_prot) { struct multiboot_module *mod = handle; vm_map_t user_map = current_task()->map; vm_offset_t start_page, end_page; - vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK; int err; if (mod->mod_start + file_ofs + file_size > mod->mod_end) return -1; - if (!(sec_type & EXEC_SECTYPE_ALLOC)) - return 0; - assert(mem_size > 0); assert(mem_size >= file_size); @@ -470,6 +467,19 @@ read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size, return 0; } +static int +read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size, + vm_offset_t mem_addr, vm_size_t mem_size, + exec_sectype_t sec_type) +{ + if (!(sec_type & EXEC_SECTYPE_ALLOC)) + return 0; + + return read_in (handle, file_ofs, file_size, + mem_addr, mem_size, + sec_type & EXEC_SECTYPE_PROT_MASK); +} + static void copy_bootstrap(void *e, exec_info_t *boot_exec_info) { //register vm_map_t user_map = current_task()->map; @@ -746,9 +756,20 @@ static void user_bootstrap(void) exec_info_t boot_exec_info; int err; char **av; + boolean_t executable = TRUE; /* Load this task up from the executable file in the module. */ err = exec_load(boot_read, read_exec, info->mod, &boot_exec_info); + if (err == EX_NOT_EXECUTABLE) + { + struct multiboot_module *mod = info->mod; + printf("reading %d bytes into map %p\n", mod->mod_end - mod->mod_start, current_task()->map); + err = read_in (mod, + 0, mod->mod_end - mod->mod_start, + 0, mod->mod_end - mod->mod_start, + VM_PROT_READ); + executable = FALSE; + } if (err) panic ("Cannot load user executable module (error code %d): %s", err, info->argv[0]); @@ -770,6 +791,9 @@ static void user_bootstrap(void) info->done = 1; thread_wakeup ((event_t) info); + if (! executable) + thread_terminate (current_thread ()); + /* * Exit to user thread. */ -- 2.1.4