modules: list modules in /proc/modules
This commit is contained in:
parent
236c8bacb3
commit
9ad39394e4
@ -1,7 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <kernel/hashmap.h>
|
||||||
|
|
||||||
struct Module {
|
struct Module {
|
||||||
const char * name;
|
const char * name;
|
||||||
int (*init)(int argc, char * argv[]);
|
int (*init)(int argc, char * argv[]);
|
||||||
int (*fini)(void);
|
int (*fini)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LoadedModule {
|
||||||
|
struct Module * metadata;
|
||||||
|
uintptr_t baseAddress;
|
||||||
|
};
|
||||||
|
|
||||||
|
hashmap_t * modules_get_list(void);
|
||||||
|
@ -18,44 +18,15 @@
|
|||||||
#include <kernel/mmu.h>
|
#include <kernel/mmu.h>
|
||||||
#include <kernel/misc.h>
|
#include <kernel/misc.h>
|
||||||
#include <kernel/ksym.h>
|
#include <kernel/ksym.h>
|
||||||
|
#include <kernel/module.h>
|
||||||
|
#include <kernel/hashmap.h>
|
||||||
|
|
||||||
static Elf64_Shdr * elf_getSection(Elf64_Header * this, Elf64_Word index) {
|
static hashmap_t * _modules_table = NULL;
|
||||||
return (Elf64_Shdr*)((uintptr_t)this + this->e_shoff + index * this->e_shentsize);
|
|
||||||
|
hashmap_t * modules_get_list(void) {
|
||||||
|
return _modules_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * sectionHeaderTypeToStr(Elf64_Word type) {
|
|
||||||
static char buf[64];
|
|
||||||
switch (type) {
|
|
||||||
case SHT_NULL: return "NULL";
|
|
||||||
case SHT_PROGBITS: return "PROGBITS";
|
|
||||||
case SHT_SYMTAB: return "SYMTAB";
|
|
||||||
case SHT_STRTAB: return "STRTAB";
|
|
||||||
case SHT_RELA: return "RELA";
|
|
||||||
case SHT_HASH: return "HASH";
|
|
||||||
case SHT_DYNAMIC: return "DYNAMIC";
|
|
||||||
case SHT_NOTE: return "NOTE";
|
|
||||||
case SHT_NOBITS: return "NOBITS";
|
|
||||||
case SHT_REL: return "REL";
|
|
||||||
case SHT_SHLIB: return "SHLIB";
|
|
||||||
case SHT_DYNSYM: return "DYNSYM";
|
|
||||||
|
|
||||||
case 0xE: return "INIT_ARRAY";
|
|
||||||
case 0xF: return "FINI_ARRAY";
|
|
||||||
case 0x6ffffff6: return "GNU_HASH";
|
|
||||||
case 0x6ffffffe: return "VERNEED";
|
|
||||||
case 0x6fffffff: return "VERSYM";
|
|
||||||
default:
|
|
||||||
snprintf(buf, 63, "(%x)", type);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Module {
|
|
||||||
const char * name;
|
|
||||||
int (*init)(int argc, char * argv[]);
|
|
||||||
int (*fini)(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
int elf_module(const char * path) {
|
int elf_module(const char * path) {
|
||||||
Elf64_Header header;
|
Elf64_Header header;
|
||||||
|
|
||||||
@ -184,6 +155,16 @@ int elf_module(const char * path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_modules_table) {
|
||||||
|
_modules_table = hashmap_create(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LoadedModule * loadedData = malloc(sizeof(struct LoadedModule));
|
||||||
|
loadedData->metadata = moduleData;
|
||||||
|
loadedData->baseAddress = (uintptr_t)module_load_address;
|
||||||
|
|
||||||
|
hashmap_set(_modules_table, moduleData->name, loadedData);
|
||||||
|
|
||||||
return moduleData->init(0,NULL);
|
return moduleData->init(0,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <kernel/syscall.h>
|
#include <kernel/syscall.h>
|
||||||
#include <kernel/mmu.h>
|
#include <kernel/mmu.h>
|
||||||
#include <kernel/misc.h>
|
#include <kernel/misc.h>
|
||||||
|
#include <kernel/module.h>
|
||||||
|
|
||||||
#define PROCFS_STANDARD_ENTRIES (sizeof(std_entries) / sizeof(struct procfs_entry))
|
#define PROCFS_STANDARD_ENTRIES (sizeof(std_entries) / sizeof(struct procfs_entry))
|
||||||
#define PROCFS_PROCDIR_ENTRIES (sizeof(procdir_entries) / sizeof(struct procfs_entry))
|
#define PROCFS_PROCDIR_ENTRIES (sizeof(procdir_entries) / sizeof(struct procfs_entry))
|
||||||
@ -475,33 +476,15 @@ static ssize_t mounts_func(fs_node_t *node, off_t offset, size_t size, uint8_t *
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t modules_func(fs_node_t *node, off_t offset, size_t size, uint8_t *buffer) {
|
static ssize_t modules_func(fs_node_t *node, off_t offset, size_t size, uint8_t *buffer) {
|
||||||
#if 0
|
|
||||||
list_t * hash_keys = hashmap_keys(modules_get_list());
|
list_t * hash_keys = hashmap_keys(modules_get_list());
|
||||||
char * buf = malloc(hash_keys->length * 512);
|
char * buf = malloc(hash_keys->length * 512);
|
||||||
unsigned int soffset = 0;
|
unsigned int soffset = 0;
|
||||||
foreach(_key, hash_keys) {
|
foreach(_key, hash_keys) {
|
||||||
char * key = (char *)_key->value;
|
char * key = (char *)_key->value;
|
||||||
module_data_t * mod_info = hashmap_get(modules_get_list(), key);
|
struct LoadedModule * mod_info = hashmap_get(modules_get_list(), key);
|
||||||
|
soffset += snprintf(&buf[soffset], 100, "%#zx %s\n",
|
||||||
soffset += sprintf(&buf[soffset], "0x%x {.init=0x%x, .fini=0x%x} %s",
|
mod_info->baseAddress,
|
||||||
mod_info->bin_data,
|
key);
|
||||||
mod_info->mod_info->initialize,
|
|
||||||
mod_info->mod_info->finalize,
|
|
||||||
mod_info->mod_info->name);
|
|
||||||
|
|
||||||
if (mod_info->deps) {
|
|
||||||
unsigned int i = 0;
|
|
||||||
soffset += sprintf(&buf[soffset], " Deps: ");
|
|
||||||
while (i < mod_info->deps_length) {
|
|
||||||
/* Skip padding bytes */
|
|
||||||
if (strlen(&mod_info->deps[i])) {
|
|
||||||
soffset += sprintf(&buf[soffset], "%s ", &mod_info->deps[i]);
|
|
||||||
}
|
|
||||||
i += strlen(&mod_info->deps[i]) + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
soffset += sprintf(&buf[soffset], "\n");
|
|
||||||
}
|
}
|
||||||
free(hash_keys);
|
free(hash_keys);
|
||||||
|
|
||||||
@ -515,8 +498,6 @@ static ssize_t modules_func(fs_node_t *node, off_t offset, size_t size, uint8_t
|
|||||||
memcpy(buffer, buf + offset, size);
|
memcpy(buffer, buf + offset, size);
|
||||||
free(buf);
|
free(buf);
|
||||||
return size;
|
return size;
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern hashmap_t * fs_types; /* from kernel/fs/vfs.c */
|
extern hashmap_t * fs_types; /* from kernel/fs/vfs.c */
|
||||||
|
Loading…
Reference in New Issue
Block a user