spawn: Find and map module, print magic, add test
This commit is contained in:
parent
ec5ccea70c
commit
6b911752f0
@ -619,6 +619,7 @@ errors spawn SPAWN_ERR_ {
|
||||
failure FILL_SMALLCN "Failure filling smallcn of new domain",
|
||||
failure MAP_BOOTINFO "Failure mapping bootinfo to new domain",
|
||||
failure FIND_MODULE "Didn't find module to be spawned",
|
||||
failure MODULE_FRAME_TOO_SMALL "Module frame is too small",
|
||||
failure MAP_MODULE "Failed mapping in module",
|
||||
failure UNMAP_MODULE "Failed unmapping module",
|
||||
failure CREATE_SEGCN "Failed to create segment CNode",
|
||||
|
||||
@ -5,5 +5,6 @@
|
||||
bootdriver /armv8/sbin/boot_armv8_generic
|
||||
cpudriver /armv8/sbin/cpu_a57_qemu loglevel=3 serial=0x9000000 logmask=128
|
||||
module /armv8/sbin/init
|
||||
module /armv8/sbin/hello
|
||||
|
||||
# End of file, this needs to have a certain length...
|
||||
|
||||
@ -5,4 +5,4 @@
|
||||
bootdriver /armv8/sbin/boot_armv8_generic
|
||||
cpudriver /armv8/sbin/cpu_imx8x
|
||||
module /armv8/sbin/init
|
||||
|
||||
module /armv8/sbin/hello
|
||||
|
||||
8
include/test_spawn.h
Normal file
8
include/test_spawn.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef __TEST_SPAWN_H
|
||||
#define __TEST_SPAWN_H
|
||||
|
||||
#include <aos/aos.h>
|
||||
|
||||
void do_test_spawn(void);
|
||||
|
||||
#endif /* __TEST_SPAWN_H */
|
||||
@ -18,7 +18,8 @@
|
||||
"grading.c",
|
||||
"test_helper.c",
|
||||
"test_mm.c",
|
||||
"test_paging.c"
|
||||
"test_paging.c",
|
||||
"test_spawn.c"
|
||||
],
|
||||
addLibraries = [
|
||||
]
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <test_helper.h>
|
||||
#include <test_mm.h>
|
||||
#include <test_paging.h>
|
||||
#include <test_spawn.h>
|
||||
|
||||
void
|
||||
grading_setup_bsp_init(int argc, char **argv) {
|
||||
@ -34,6 +35,7 @@ grading_test_mm(struct mm *test) {
|
||||
|
||||
void
|
||||
grading_test_early(void) {
|
||||
do_test_spawn();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
9
lib/grading/test_spawn.c
Normal file
9
lib/grading/test_spawn.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <test_helper.h>
|
||||
#include <test_spawn.h>
|
||||
#include <spawn/spawn.h>
|
||||
|
||||
void do_test_spawn(void) {
|
||||
struct spawninfo si;
|
||||
domainid_t pid;
|
||||
CHECK_ERR(spawn_load_by_name("hello", &si, &pid));
|
||||
}
|
||||
@ -22,7 +22,7 @@ extern coreid_t my_core_id;
|
||||
|
||||
/**
|
||||
* \brief Set the base address of the .got (Global Offset Table) section of the ELF binary
|
||||
*
|
||||
*
|
||||
* \param arch_load_info This must be the base address of the .got section (local to the
|
||||
* child's VSpace). Must not be NULL.
|
||||
* \param handle The handle for the new dispatcher that is to be spawned. Must not be NULL.
|
||||
@ -56,11 +56,11 @@ static void armv8_set_registers(void *arch_load_info,
|
||||
/**
|
||||
* TODO(M2): Implement this function.
|
||||
* \brief Spawn a new dispatcher called 'argv[0]' with 'argc' arguments.
|
||||
*
|
||||
*
|
||||
* This function spawns a new dispatcher running the ELF binary called
|
||||
* 'argv[0]' with 'argc' - 1 additional arguments. It fills out 'si'
|
||||
* and 'pid'.
|
||||
*
|
||||
*
|
||||
* \param argc The number of command line arguments. Must be > 0.
|
||||
* \param argv An array storing 'argc' command line arguments.
|
||||
* \param si A pointer to the spawninfo struct representing
|
||||
@ -90,25 +90,47 @@ errval_t spawn_load_argv(int argc, char *argv[], struct spawninfo *si,
|
||||
/**
|
||||
* TODO(M2): Implement this function.
|
||||
* \brief Spawn a new dispatcher executing 'binary_name'
|
||||
*
|
||||
*
|
||||
* \param binary_name The name of the binary.
|
||||
* \param si A pointer to a spawninfo struct that will be
|
||||
* filled out by spawn_load_by_name. Must not be NULL.
|
||||
* \param pid A pointer to a domainid_t that will be
|
||||
* filled out by spawn_load_by_name. Must not be NULL.
|
||||
*
|
||||
*
|
||||
* \return Either SYS_ERR_OK if no error occured or an error
|
||||
* indicating what went wrong otherwise.
|
||||
*/
|
||||
errval_t spawn_load_by_name(char *binary_name, struct spawninfo * si,
|
||||
domainid_t *pid) {
|
||||
// TODO: Implement me
|
||||
errval_t err;
|
||||
|
||||
// - Get the mem_region from the multiboot image
|
||||
struct mem_region *module = multiboot_find_module(bi, binary_name);
|
||||
if (module == NULL) return SPAWN_ERR_FIND_MODULE;
|
||||
|
||||
struct capref child_frame = {
|
||||
.cnode = cnode_module,
|
||||
.slot = module->mrmod_slot,
|
||||
};
|
||||
|
||||
struct capability c;
|
||||
err = cap_direct_identify(child_frame, &c);
|
||||
if (err_is_fail(err)) return err;
|
||||
gensize_t frame_size = get_size(&c);
|
||||
if (frame_size < module->mr_bytes) return SPAWN_ERR_MODULE_FRAME_TOO_SMALL;
|
||||
|
||||
char *module_data;
|
||||
err = paging_map_frame_attr(
|
||||
get_current_paging_state(), (void **)&module_data,
|
||||
frame_size, child_frame, VREGION_FLAGS_READ
|
||||
);
|
||||
if (err_is_fail(err)) return err_push(err, SPAWN_ERR_MAP_MODULE);
|
||||
|
||||
debug_printf("SPAWN: mapped %s, magic: %"PRIx8" %c%c%c\n",
|
||||
binary_name, module_data[0], module_data[1], module_data[2], module_data[3]);
|
||||
|
||||
// - Fill in argc/argv from the multiboot command line
|
||||
// - Call spawn_load_argv
|
||||
|
||||
return LIB_ERR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
let
|
||||
-- Default list of modules to build/install
|
||||
modules_common = [ "/sbin/" ++ f | f <- [ "init"
|
||||
modules_common = [ "/sbin/" ++ f | f <- [ "init", "hello"
|
||||
] ]
|
||||
in
|
||||
[
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
"mem_alloc.c"
|
||||
],
|
||||
addLinkFlags = [ "-e _start_init"], -- this is only needed for init
|
||||
addLibraries = [ "mm", "getopt", "elf",
|
||||
addLibraries = [ "mm", "getopt", "elf", "spawn",
|
||||
"grading"],
|
||||
architectures = allArchitectures
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user