25 #define MODULE_FMT "root»/system/modules/%s.o" 27 extern void pedigree_module_load(
char *file);
28 extern int pedigree_module_is_loaded(
char *name);
29 int load_module(
char *name);
31 int load_module(
char *name)
34 char *file = (
char *) malloc(
35 strlen(name) + strlen(MODULE_FMT) -
37 sprintf(file, MODULE_FMT, name);
39 FILE *fp = fopen(file,
"r");
42 printf(
"Module file %s not found!\n", file);
45 fseek(fp, 0, SEEK_END);
46 size_t len = ftell(fp);
47 fseek(fp, 0, SEEK_SET);
49 uint8_t *buffer = (uint8_t *) malloc(len);
50 fread(buffer, len, 1, fp);
53 Elf_t *elf = elf_create(buffer, len);
62 ElfSymbol_t *name_sym = elf_get_symbol(elf,
"g_pModuleName"),
63 *deps_sym = elf_get_symbol(elf,
"g_pDepends");
66 printf(
"g_pModuleName symbol not found!\n");
71 printf(
"g_pDepends symbols not found!\n");
75 char *modname = (
char *) elf_relptr(elf, name_sym, *SYM_PTR(elf, name_sym));
76 if (pedigree_module_is_loaded(modname))
78 printf(
"Module %s is already loaded!\n", modname);
82 printf(
"Module %s being loaded...\n", modname);
83 uint32_t *deps = SYM_PTR(elf, deps_sym);
84 for (
size_t i = 0; deps[i]; i++)
86 char *depname = (
char *) elf_relptr(elf, deps_sym, deps[i]);
87 if (pedigree_module_is_loaded(depname))
89 if (!load_module(depname) && pedigree_module_is_loaded(depname))
91 printf(
"Dependency %s of %s couldn't been loaded!\n", depname, modname);
96 pedigree_module_load(file);
97 if (pedigree_module_is_loaded(modname))
99 printf(
"Module %s couldn't been loaded\n", modname);
103 int main(
int argc,
char **argv)
107 printf(
"Usage: %s <module name>\n", argv[0]);
111 return load_module(argv[1]);