procfs: quick-and-dirty /proc/kallsyms, missing modules
This commit is contained in:
parent
9d609d15df
commit
39ebb4b6c0
@ -5,3 +5,4 @@
|
|||||||
extern void ksym_install(void);
|
extern void ksym_install(void);
|
||||||
extern void ksym_bind(const char * symname, void * value);
|
extern void ksym_bind(const char * symname, void * value);
|
||||||
extern void * ksym_lookup(const char * symname);
|
extern void * ksym_lookup(const char * symname);
|
||||||
|
extern list_t * ksym_list(void);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* boot methods to provide symbol tables for use with linking
|
* boot methods to provide symbol tables for use with linking
|
||||||
* kernel modules.
|
* kernel modules.
|
||||||
*/
|
*/
|
||||||
|
#include <kernel/types.h>
|
||||||
#include <kernel/hashmap.h>
|
#include <kernel/hashmap.h>
|
||||||
#include <kernel/assert.h>
|
#include <kernel/assert.h>
|
||||||
#include <kernel/ksym.h>
|
#include <kernel/ksym.h>
|
||||||
@ -26,3 +27,8 @@ void ksym_bind(const char * symname, void * value) {
|
|||||||
void * ksym_lookup(const char * symname) {
|
void * ksym_lookup(const char * symname) {
|
||||||
return hashmap_get(ksym_hash, symname);
|
return hashmap_get(ksym_hash, symname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_t * ksym_list(void) {
|
||||||
|
assert(ksym_hash != NULL);
|
||||||
|
return hashmap_keys(ksym_hash);
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <kernel/mmu.h>
|
#include <kernel/mmu.h>
|
||||||
#include <kernel/misc.h>
|
#include <kernel/misc.h>
|
||||||
#include <kernel/module.h>
|
#include <kernel/module.h>
|
||||||
|
#include <kernel/ksym.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))
|
||||||
@ -674,6 +675,39 @@ static ssize_t idle_func(fs_node_t *node, off_t offset, size_t size, uint8_t *bu
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ssize_t kallsyms_func(fs_node_t *node, off_t offset, size_t size, uint8_t * buffer) {
|
||||||
|
/* This doesn't include module symbols at the moment... */
|
||||||
|
list_t * syms = ksym_list();
|
||||||
|
|
||||||
|
/* Figure out how much space needs to go in this buffer */
|
||||||
|
size_t total_size = 0;
|
||||||
|
foreach (node, syms) {
|
||||||
|
/* 16 for the address, one space, len(sym), one linefeed = 18 + strlen() */
|
||||||
|
total_size += 18 + strlen((char*)node->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
char * buf = malloc(total_size);
|
||||||
|
|
||||||
|
size_t soffset = 0;
|
||||||
|
foreach(node, syms) {
|
||||||
|
soffset += snprintf(&buf[soffset], 100, "%016zx %s\n", this_core->current_process->user == USER_ROOT_UID ? (uintptr_t)ksym_lookup(node->value) : (uintptr_t)0, (char*)node->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((size_t)offset >= soffset) {
|
||||||
|
size = 0;
|
||||||
|
goto free_results;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > soffset - offset) size = soffset - offset;
|
||||||
|
memcpy(buffer, buf + offset, size);
|
||||||
|
|
||||||
|
free_results:
|
||||||
|
list_free(syms);
|
||||||
|
free(syms);
|
||||||
|
free(buf);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
static struct procfs_entry std_entries[] = {
|
static struct procfs_entry std_entries[] = {
|
||||||
{-1, "cpuinfo", cpuinfo_func},
|
{-1, "cpuinfo", cpuinfo_func},
|
||||||
{-2, "meminfo", meminfo_func},
|
{-2, "meminfo", meminfo_func},
|
||||||
@ -686,10 +720,11 @@ static struct procfs_entry std_entries[] = {
|
|||||||
{-9, "filesystems", filesystems_func},
|
{-9, "filesystems", filesystems_func},
|
||||||
{-10,"loader", loader_func},
|
{-10,"loader", loader_func},
|
||||||
{-11,"idle", idle_func},
|
{-11,"idle", idle_func},
|
||||||
|
{-12,"kallsyms", kallsyms_func},
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
{-12,"irq", irq_func},
|
{-13,"irq", irq_func},
|
||||||
{-13,"pat", pat_func},
|
{-14,"pat", pat_func},
|
||||||
{-14,"pci", pci_func},
|
{-15,"pci", pci_func},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user