//--- // fxBoot:hypervisor:loader - ELF loader interface //--- #include "fxBoot/hypervisor.h" #include "fxBoot/fs/smemfs.h" #include "fxBoot/terminal.h" #include "./src/hypervisor/internal/elf.h" #include #include //--- // Internal helpers //--- /* hypervisor_get_image_list(): Dump all ELF file stored into the SMEM */ static int hypervisor_get_img_list(struct himage ***image, struct smemfs_inode *inode) { if (inode == NULL) return (0); int counter = 0; if (inode->type != BFile_Type_Archived) { counter += hypervisor_get_img_list(image, inode->child); goto anchor; } if (hypervisor_elf_loader_header_check(inode) == hel_header_valid) { (**image) = calloc(sizeof(struct himage), 1); if ((**image) == NULL) { terminal_write("hypervisor: out of memory :(\n"); goto anchor; } (**image)->name = inode->name; (**image)->private = inode; *image = &((**image)->next); } anchor: return (hypervisor_get_img_list(image, inode->sibling) + counter); } //--- // User API //--- /* hypervisor_loader(): Load a ELF (must be PIE) and start it */ int hypervisor_loader(struct himage *image) { (void)image; //TODO: create a new world context //TODO: try to load the image //TODO: link the new world context //TODO: perform a world switch. return (0); } /* hypervisor_loader_list(): Return a list of all supported file on SMEM */ int hypervisor_loader_list(struct himage **list) { return (hypervisor_get_img_list(&list, smemfs_superblock.root_inode)); } /* hypervisor_loader_list_destroy(): Destroy the image image list */ void hypervisor_loader_list_destroy(struct himage **list) { if (list == NULL || *list == NULL) return; hypervisor_loader_list_destroy(&(*list)->next); free(*list); *list = NULL; }