From 97c5ff206a224e98eb2048b91b0ae5623ede3646 Mon Sep 17 00:00:00 2001 From: Kasper Sauramo Date: Tue, 18 Mar 2025 14:19:32 +0200 Subject: [PATCH] he -> hi --- include/hiload/hiload.h | 18 ++++++++-------- src/hiload.c | 34 +++++++++++++++---------------- src/symbols.c | 8 ++++---- {include/hiload => src}/symbols.h | 4 ++-- 4 files changed, 33 insertions(+), 31 deletions(-) rename {include/hiload => src}/symbols.h (75%) diff --git a/include/hiload/hiload.h b/include/hiload/hiload.h index e436ffe..a610cc8 100644 --- a/include/hiload/hiload.h +++ b/include/hiload/hiload.h @@ -7,16 +7,18 @@ extern "C" { // Return codes for reload_module typedef enum { - RELOAD_SUCCESS = 0, - RELOAD_NOT_FOUND, - RELOAD_CLOSE_ERROR, - RELOAD_OPEN_ERROR + HI_RELOAD_SUCCESS = 0, + HI_RELOAD_NOT_FOUND, + HI_RELOAD_CLOSE_ERROR, + HI_RELOAD_OPEN_ERROR } ReloadResult; -int he_init(); -void he_deinit(); -void he_print_module_infos(); -ReloadResult he_reload_module(const char *module_name); +/* Initialiez the module. Must be called before anything else */ +int hi_init(); +/* Frees memory and cleans up */ +void hi_deinit(); +void hi_print_module_infos(); +ReloadResult hi_reload_module(const char *module_name); #ifdef __cplusplus } diff --git a/src/hiload.c b/src/hiload.c index 1e59664..a7836ce 100644 --- a/src/hiload.c +++ b/src/hiload.c @@ -1,5 +1,5 @@ #include "hiload/hiload.h" -#include "hiload/symbols.h" +#include "symbols.h" #include #include @@ -51,7 +51,7 @@ static int gather_module_infos_callback(struct dl_phdr_info *info, size_t size, infos->handles[infos->count] = dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD); - if (he_create_symbol_info(&infos->symbols[infos->count], info) != CREATE_SUCCESS) { + if (hi_create_symbol_info(&infos->symbols[infos->count], info) != CREATE_SUCCESS) { fprintf(stderr, "Failed to create symbol info for %s\n", infos->names[infos->count]); } infos->count++; @@ -65,7 +65,7 @@ static void free_module_infos(ModuleInfos *modules) { for (size_t i = 0; i < modules->count; i++) { if (modules->names[i]) free(modules->names[i]); - he_free_symbol_info(&modules->symbols[i]); + hi_free_symbol_info(&modules->symbols[i]); } free(modules->names); @@ -110,7 +110,7 @@ static ModuleInfos *gather_shared_libraries(void) { return result; } -int he_init() { +int hi_init() { assert(!module_infos); ModuleInfos *infos = gather_shared_libraries(); @@ -125,7 +125,7 @@ int he_init() { return 0; } -void he_deinit() { free_module_infos(module_infos); } +void hi_deinit() { free_module_infos(module_infos); } /** * Reloads a shared library module @@ -138,7 +138,7 @@ void he_deinit() { free_module_infos(module_infos); } static ReloadResult reload_module(ModuleInfos *modules, const char *filename, void **updated_handle) { if (!modules || !filename) { - return RELOAD_NOT_FOUND; + return HI_RELOAD_NOT_FOUND; } // Find the module by filename @@ -165,20 +165,20 @@ static ReloadResult reload_module(ModuleInfos *modules, const char *filename, } if (!found) { - return RELOAD_NOT_FOUND; + return HI_RELOAD_NOT_FOUND; } // Save the full path char *fullpath = strdup(modules->names[index]); if (!fullpath) { - return RELOAD_OPEN_ERROR; + return HI_RELOAD_OPEN_ERROR; } // Close the old handle if (modules->handles[index]) { if (dlclose(modules->handles[index]) != 0) { free(fullpath); - return RELOAD_CLOSE_ERROR; + return HI_RELOAD_CLOSE_ERROR; } } @@ -187,7 +187,7 @@ static ReloadResult reload_module(ModuleInfos *modules, const char *filename, if (!new_handle) { fprintf(stderr, "Error reloading module: %s\n", dlerror()); free(fullpath); - return RELOAD_OPEN_ERROR; + return HI_RELOAD_OPEN_ERROR; } // Update the handle in our structure @@ -199,23 +199,23 @@ static ReloadResult reload_module(ModuleInfos *modules, const char *filename, } free(fullpath); - return RELOAD_SUCCESS; + return HI_RELOAD_SUCCESS; } /** * Helper function to print the result of a module reload */ static void print_reload_result(ReloadResult result, const char *filename) { switch (result) { - case RELOAD_SUCCESS: + case HI_RELOAD_SUCCESS: printf("Successfully reloaded module: %s\n", filename); break; - case RELOAD_NOT_FOUND: + case HI_RELOAD_NOT_FOUND: printf("Module not found: %s\n", filename); break; - case RELOAD_CLOSE_ERROR: + case HI_RELOAD_CLOSE_ERROR: printf("Error closing module: %s\n", filename); break; - case RELOAD_OPEN_ERROR: + case HI_RELOAD_OPEN_ERROR: printf("Error reopening module: %s\n", filename); break; default: @@ -223,7 +223,7 @@ static void print_reload_result(ReloadResult result, const char *filename) { } } -ReloadResult he_reload_module(const char *module_name) { +ReloadResult hi_reload_module(const char *module_name) { assert(module_infos); void *new_handle = NULL; @@ -233,7 +233,7 @@ ReloadResult he_reload_module(const char *module_name) { return result; } -void he_print_module_infos() { +void hi_print_module_infos() { assert(module_infos); const ModuleInfos *modules = module_infos; diff --git a/src/symbols.c b/src/symbols.c index bc90eda..f81ef42 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -1,4 +1,4 @@ -#include "hiload/symbols.h" +#include "symbols.h" #include #include @@ -14,13 +14,13 @@ * Will clear and free the given SymbolInfo struct. Allocates enough memory to * hold found symbols. */ -CreateResult he_create_symbol_info(SymbolInfos *symbols, +CreateResult hi_create_symbol_info(SymbolInfos *symbols, struct dl_phdr_info *info) { if (!symbols) return CREATE_FAILED; - he_free_symbol_info(symbols); + hi_free_symbol_info(symbols); for (int i = 0; i < info->dlpi_phnum; i++) { const ElfW(Phdr) *phdr = &info->dlpi_phdr[i]; @@ -103,7 +103,7 @@ CreateResult he_create_symbol_info(SymbolInfos *symbols, return CREATE_SUCCESS; } -void he_free_symbol_info(SymbolInfos *symbols) { +void hi_free_symbol_info(SymbolInfos *symbols) { for (size_t i = 0; i < symbols->count; i++) { free(symbols->names[i]); } diff --git a/include/hiload/symbols.h b/src/symbols.h similarity index 75% rename from include/hiload/symbols.h rename to src/symbols.h index c7a533e..5236b15 100644 --- a/include/hiload/symbols.h +++ b/src/symbols.h @@ -16,7 +16,7 @@ typedef enum { CREATE_SUCCESS = 0, CREATE_FAILED } CreateResult; struct dl_phdr_info; -CreateResult he_create_symbol_info(SymbolInfos *, struct dl_phdr_info *); -void he_free_symbol_info(SymbolInfos *); +CreateResult hi_create_symbol_info(SymbolInfos *, struct dl_phdr_info *); +void hi_free_symbol_info(SymbolInfos *); #endif // SYMBOLS_H_