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 FILL_SMALLCN "Failure filling smallcn of new domain",
|
||||||
failure MAP_BOOTINFO "Failure mapping bootinfo to new domain",
|
failure MAP_BOOTINFO "Failure mapping bootinfo to new domain",
|
||||||
failure FIND_MODULE "Didn't find module to be spawned",
|
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 MAP_MODULE "Failed mapping in module",
|
||||||
failure UNMAP_MODULE "Failed unmapping module",
|
failure UNMAP_MODULE "Failed unmapping module",
|
||||||
failure CREATE_SEGCN "Failed to create segment CNode",
|
failure CREATE_SEGCN "Failed to create segment CNode",
|
||||||
|
|||||||
@ -5,5 +5,6 @@
|
|||||||
bootdriver /armv8/sbin/boot_armv8_generic
|
bootdriver /armv8/sbin/boot_armv8_generic
|
||||||
cpudriver /armv8/sbin/cpu_a57_qemu loglevel=3 serial=0x9000000 logmask=128
|
cpudriver /armv8/sbin/cpu_a57_qemu loglevel=3 serial=0x9000000 logmask=128
|
||||||
module /armv8/sbin/init
|
module /armv8/sbin/init
|
||||||
|
module /armv8/sbin/hello
|
||||||
|
|
||||||
# End of file, this needs to have a certain length...
|
# End of file, this needs to have a certain length...
|
||||||
|
|||||||
@ -5,4 +5,4 @@
|
|||||||
bootdriver /armv8/sbin/boot_armv8_generic
|
bootdriver /armv8/sbin/boot_armv8_generic
|
||||||
cpudriver /armv8/sbin/cpu_imx8x
|
cpudriver /armv8/sbin/cpu_imx8x
|
||||||
module /armv8/sbin/init
|
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",
|
"grading.c",
|
||||||
"test_helper.c",
|
"test_helper.c",
|
||||||
"test_mm.c",
|
"test_mm.c",
|
||||||
"test_paging.c"
|
"test_paging.c",
|
||||||
|
"test_spawn.c"
|
||||||
],
|
],
|
||||||
addLibraries = [
|
addLibraries = [
|
||||||
]
|
]
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#include <test_helper.h>
|
#include <test_helper.h>
|
||||||
#include <test_mm.h>
|
#include <test_mm.h>
|
||||||
#include <test_paging.h>
|
#include <test_paging.h>
|
||||||
|
#include <test_spawn.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
grading_setup_bsp_init(int argc, char **argv) {
|
grading_setup_bsp_init(int argc, char **argv) {
|
||||||
@ -34,6 +35,7 @@ grading_test_mm(struct mm *test) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
grading_test_early(void) {
|
grading_test_early(void) {
|
||||||
|
do_test_spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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));
|
||||||
|
}
|
||||||
@ -102,13 +102,35 @@ errval_t spawn_load_argv(int argc, char *argv[], struct spawninfo *si,
|
|||||||
*/
|
*/
|
||||||
errval_t spawn_load_by_name(char *binary_name, struct spawninfo * si,
|
errval_t spawn_load_by_name(char *binary_name, struct spawninfo * si,
|
||||||
domainid_t *pid) {
|
domainid_t *pid) {
|
||||||
// TODO: Implement me
|
errval_t err;
|
||||||
|
|
||||||
// - Get the mem_region from the multiboot image
|
// - 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
|
// - Fill in argc/argv from the multiboot command line
|
||||||
// - Call spawn_load_argv
|
// - Call spawn_load_argv
|
||||||
|
|
||||||
return LIB_ERR_NOT_IMPLEMENTED;
|
return LIB_ERR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
-- Default list of modules to build/install
|
-- Default list of modules to build/install
|
||||||
modules_common = [ "/sbin/" ++ f | f <- [ "init"
|
modules_common = [ "/sbin/" ++ f | f <- [ "init", "hello"
|
||||||
] ]
|
] ]
|
||||||
in
|
in
|
||||||
[
|
[
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
"mem_alloc.c"
|
"mem_alloc.c"
|
||||||
],
|
],
|
||||||
addLinkFlags = [ "-e _start_init"], -- this is only needed for init
|
addLinkFlags = [ "-e _start_init"], -- this is only needed for init
|
||||||
addLibraries = [ "mm", "getopt", "elf",
|
addLibraries = [ "mm", "getopt", "elf", "spawn",
|
||||||
"grading"],
|
"grading"],
|
||||||
architectures = allArchitectures
|
architectures = allArchitectures
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user