modules: track loaded sizes so we can free modules later

This commit is contained in:
K. Lange 2021-07-19 10:28:26 +09:00
parent ae7cdb00c2
commit d406a6948f
3 changed files with 9 additions and 1 deletions

View File

@ -11,6 +11,8 @@ struct Module {
struct LoadedModule {
struct Module * metadata;
uintptr_t baseAddress;
size_t fileSize;
size_t loadedSize;
};
hashmap_t * modules_get_list(void);

View File

@ -162,6 +162,10 @@ int elf_module(const char * path) {
struct LoadedModule * loadedData = malloc(sizeof(struct LoadedModule));
loadedData->metadata = moduleData;
loadedData->baseAddress = (uintptr_t)module_load_address;
loadedData->fileSize = file->length;
loadedData->loadedSize = (uintptr_t)mmu_map_module(0) - (uintptr_t)module_load_address;
close_fs(file);
hashmap_set(_modules_table, moduleData->name, loadedData);

View File

@ -482,8 +482,10 @@ static ssize_t modules_func(fs_node_t *node, off_t offset, size_t size, uint8_t
foreach(_key, hash_keys) {
char * key = (char *)_key->value;
struct LoadedModule * mod_info = hashmap_get(modules_get_list(), key);
soffset += snprintf(&buf[soffset], 100, "%#zx %s\n",
soffset += snprintf(&buf[soffset], 100, "%#zx %zu %zu %s\n",
mod_info->baseAddress,
mod_info->fileSize,
mod_info->loadedSize,
key);
}
free(hash_keys);