From 89451005c47b443c9ab48de4e84b74f7acc73804 Mon Sep 17 00:00:00 2001 From: Armin Luntzer <armin.luntzer@univie.ac.at> Date: Thu, 23 Feb 2017 17:35:37 +0100 Subject: [PATCH] modules image: add new function module_read_embedded() --- init/main.c | 12 ++++++++---- init/modules-image.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/init/main.c b/init/main.c index 4d1531f..4db57e8 100644 --- a/init/main.c +++ b/init/main.c @@ -19,7 +19,7 @@ void module_image_load_embedded(void); void *module_lookup_embedded(char *mod_name); void *module_lookup_symbol_embedded(char *sym_name); - +void *module_read_embedded(char *mod_name); static void kernel_init(void) { @@ -40,7 +40,6 @@ int main(void) module_image_load_embedded(); - /* look up a kernel symbol */ printk("%s at %p\n", "printk", lookup_symbol("printk")); @@ -48,7 +47,6 @@ int main(void) printk("%s at %p\n", "testmodule.ko", module_lookup_embedded("testmodule.ko")); - /* to load an arbitrary image, you may upload it via grmon, e.g. * load -binary kernel/test.ko 0xA0000000 * then load it: @@ -56,7 +54,13 @@ int main(void) */ /* lookup the module containing <symbol> */ - addr = module_lookup_symbol_embedded("somefunction"); + /* addr = module_lookup_symbol_embedded("somefunction"); */ + /* XXX the image is not necessary aligned properly, so we can't access + * it directly, until we have a MNA trap */ + + + addr = module_read_embedded("testmodule.ko"); + if (addr) module_load(&m, addr); diff --git a/init/modules-image.c b/init/modules-image.c index ae18f7f..dec2c27 100644 --- a/init/modules-image.c +++ b/init/modules-image.c @@ -4,6 +4,7 @@ #include <kernel/printk.h> #include <kernel/ar.h> +#include <kernel/kmem.h> extern unsigned char _binary_modules_image_start __attribute__((weak)); extern unsigned char _binary_modules_image_end __attribute__((weak)); @@ -31,3 +32,23 @@ void *module_lookup_embedded(char *mod_name) { return ar_find_file(&mod_ar, mod_name); } + +void *module_read_embedded(char *mod_name) +{ + unsigned int fsize; + + void *ptr; + + fsize = ar_read_file(&mod_ar, mod_name, NULL); + + ptr = kmalloc(fsize); + if (!ptr) + return NULL; + + if (!ar_read_file(&mod_ar, mod_name, ptr)) { + kfree(ptr); + return NULL; + } + + return ptr; +} -- GitLab