summaryrefslogtreecommitdiffstats
path: root/src/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/module.c')
-rw-r--r--src/module.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c
index fde93fe..ad50d7a 100644
--- a/src/module.c
+++ b/src/module.c
@@ -5,6 +5,8 @@
struct module modules[64U] = { 0U };
u64 modules_list = ~0ULL;
+// u64 module_symbols
+
u8 add_module() {
// struct module* add_module() {
assert(!modules_list);
@@ -12,9 +14,43 @@ u8 add_module() {
_BitScanForward64((unsigned long*)&module_index, modules_list);
modules_list ^= (u64)(0x1 << module_index);
+#ifdef HASHMAP
+ modules[module_index].symbols = create_unordered_flat();
+#endif
+
return (u8)module_index;
};
void remove_module(u8 index) {
modules_list |= (u64)(0x1 << (((i8)index) - 1U));
}
+
+#ifdef HASHMAP
+struct element* find_function(struct module* module, u32 rip_offset) {
+ for (u32 sym_index = 0U; sym_index < module->symbols.capacity; sym_index++) {
+ struct element* cur_sym = &module->symbols.arr[sym_index];
+ if (cur_sym->start != 0U && cur_sym->start <= rip_offset && rip_offset < cur_sym->end) {
+ return cur_sym;
+ }
+ }
+ return NULL;
+}
+#else
+u32 find_function(struct module* module, u64 rip_offset) {
+ if (module->functions_count == 0U) {
+ return (u32)-1;
+ }
+ u32 min = 0U, max = module->functions_count - 1U;
+
+ while(min != max) {
+ u32 mid = (min + max) / 2U;
+ if (module->functions_start[mid] < rip_offset) {
+ min = mid + 1U;
+ } else {
+ max = mid - 1U;
+ }
+ }
+
+ return min;
+}
+#endif