diff options
author | Stefan Bucur <stefanb@zytor.com> | 2008-07-01 17:03:46 +0300 |
---|---|---|
committer | Stefan Bucur <stefan@stefan-ubumac.(none)> | 2009-03-15 10:03:13 +0200 |
commit | 096c21fc8d76c3a9dc97f1ed5ba3abc8c51481cd (patch) | |
tree | 9aa0d46c1687856dd4c11170d45a220c5b0e2db0 /com32/elflink/elftest.c | |
parent | 7bb46a5400abb256e96ba3b637db8afe7bb321e9 (diff) | |
download | syslinux-elf-096c21fc8d76c3a9dc97f1ed5ba3abc8c51481cd.tar.gz syslinux-elf-096c21fc8d76c3a9dc97f1ed5ba3abc8c51481cd.tar.xz syslinux-elf-096c21fc8d76c3a9dc97f1ed5ba3abc8c51481cd.zip |
Moved the module loading code onto SYSLINUX, as a COM32 module.
The code does nothing for now. It simply compiles the code and ensures
all the dependencies are satisfied.
Diffstat (limited to 'com32/elflink/elftest.c')
-rw-r--r-- | com32/elflink/elftest.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/com32/elflink/elftest.c b/com32/elflink/elftest.c new file mode 100644 index 00000000..0a38bbe6 --- /dev/null +++ b/com32/elflink/elftest.c @@ -0,0 +1,101 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> + +#include "elf_module.h" + +void print_usage() { + fprintf(stderr, "Usage:\n"); + fprintf(stderr, "\telftest objfile ...\n"); +} + +void test_hello() { + int i; + + struct elf_module *module; + Elf32_Sym *symbol; + + symbol = global_find_symbol("undef_func", &module); + + void (*undef_func)(int) = module_get_absolute(symbol->st_value, module); + + symbol = global_find_symbol("test_func", &module); + + int (*test_func)(void) = module_get_absolute(symbol->st_value, module); + + undef_func(0); + + for (i=0; i < 10; i++) { + printf("%d\n", test_func()); + } +} + +int main(int argc, char **argv) { + int res; + int i; + struct elf_module *module; + const char *module_name = NULL; + + // Skip program name + argc--; + argv++; + + if (argc < 1) { + print_usage(); + return 1; + } + + res = modules_init(); + + if (res < 0) { + fprintf(stderr, "Could not initialize module subsystem\n"); + exit(1); + } + + for (i=0; i < argc; i++){ + module_name = argv[i]; + + module = module_alloc(module_name); + + if (module == NULL) { + fprintf(stderr, "Could not allocate the module\n"); + goto error; + } + + res = module_load(module); + + if (res < 0) { + fprintf(stderr, "Could not load the module\n"); + goto error; + } + + } + + test_hello(); + + for (i=argc-1; i >= 0; i--) { + module_name = argv[i]; + module = module_find(module_name); + + res = module_unload(module); + + if (res < 0) { + fprintf(stderr, "Could not unload the module\n"); + goto error; + } + } + + modules_term(); + + return 0; + +error: + modules_term(); + + return 1; +} |