Fixing merge conflict resolution

This commit is contained in:
2025-03-18 19:22:43 +02:00
parent d75dd85209
commit bf8c8f9dad
10 changed files with 123 additions and 27 deletions

View File

@@ -42,6 +42,8 @@ endif()
add_library(hiload SHARED add_library(hiload SHARED
src/hiload.c src/hiload.c
src/symbols.c src/symbols.c
src/files.c
src/memory.c
# dependencies # dependencies
src/str.c src/str.c

View File

@@ -29,6 +29,7 @@ void hi_print_module_infos();
ReloadResult hi_reload_module(const char *module_name); ReloadResult hi_reload_module(const char *module_name);
#pragma GCC visibility pop #pragma GCC visibility pop
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

15
src/files.c Normal file
View File

@@ -0,0 +1,15 @@
#include "files.h"
#include "logger.h"
#include "str.h"
#include "types.h"
HiloadResult read_file_to_str(str *s, const char *filename) {
int copied = str_from_file(s, filename);
if (copied == 0) {
sc_log_error("Failed to read file: %s\n", filename);
return HILOAD_FAIL;
}
return HILOAD_OK;
}

9
src/files.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef FILES_H_
#define FILES_H_
#include "str.h"
#include "types.h"
HiloadResult read_file_to_str(str *s, const char *);
#endif // FILES_H_

View File

@@ -1,4 +1,7 @@
#include "hiload/hiload.h" #include "hiload/hiload.h"
#include "logger.h"
#include "memory.h"
#include "symbols.h" #include "symbols.h"
#include <assert.h> #include <assert.h>
@@ -51,8 +54,10 @@ static int gather_module_infos_callback(struct dl_phdr_info *info, size_t size,
infos->handles[infos->count] = infos->handles[infos->count] =
dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD); dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD);
if (hi_create_symbol_info(&infos->symbols[infos->count], info) != CREATE_SUCCESS) { if (hi_create_symbol_info(&infos->symbols[infos->count], info) !=
fprintf(stderr, "Failed to create symbol info for %s\n", infos->names[infos->count]); CREATE_SUCCESS) {
fprintf(stderr, "Failed to create symbol info for %s\n",
infos->names[infos->count]);
} }
infos->count++; infos->count++;
return 0; // Continue iteration return 0; // Continue iteration
@@ -110,23 +115,6 @@ static ModuleInfos *gather_shared_libraries(void) {
return result; return result;
} }
int hi_init() {
assert(!module_infos);
ModuleInfos *infos = gather_shared_libraries();
if (!infos) {
fprintf(stderr, "Failed to gather module infos.\n");
return 1;
}
if (module_infos) {
free_module_infos(module_infos);
}
module_infos = infos;
return 0;
}
void hi_deinit() { free_module_infos(module_infos); }
/** /**
* Reloads a shared library module * Reloads a shared library module
* *
@@ -261,3 +249,31 @@ void hi_print_module_infos() {
printf("\n"); printf("\n");
} }
} }
int hi_init() {
assert(!module_infos);
if (sc_log_init() != 0) {
fprintf(stderr, "Failed to init logger.\n");
return 1;
}
sc_log_set_level("DEBUG");
read_memory_maps_self();
ModuleInfos *infos = gather_shared_libraries();
if (!infos) {
fprintf(stderr, "Failed to gather module infos.\n");
return 1;
}
if (module_infos) {
free_module_infos(module_infos);
}
module_infos = infos;
return 0;
}
void hi_deinit() {
free_module_infos(module_infos);
sc_log_term();
}

14
src/memory.c Normal file
View File

@@ -0,0 +1,14 @@
#include "memory.h"
#include "logger.h"
#include "files.h"
#include "types.h"
str read_memory_maps_self() {
str memory_str = str_null;
HiloadResult res = read_file_to_str(&memory_str, "/proc/self/maps");
sc_log_debug("Memory Map (/proc/self/maps):\n%s\n", str_ptr(memory_str));
return memory_str;
}

28
src/memory.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef MEMORY_H_
#define MEMORY_H_
#include "str.h"
#include "types.h"
#include "array.h"
enum MemoryPermissions {
HI_MEMORY_READ = 1 << 0,
HI_MEMORY_WRITE = 1 << 1,
HI_MEMORY_EXECUTE = 1 << 2,
HI_MEMORY_SHARED = 1 << 3,
HI_MEMORY_PRIVATE = 1 << 4
};
typedef struct {
void *region_start;
void *redion_end;
u32 region_flags; // enum MemoryPermissions
u32 offset;
str pathname;
} MemoryRegion;
str read_memory_maps_self();
sc_array_def(MemoryRegion, memreg);
#endif // MEMORY_H_

19
src/types.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef TYPES_H_
#define TYPES_H_
#include <stdint.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef float f32;
typedef double f64;
typedef enum { HILOAD_OK = 0, HILOAD_FAIL } HiloadResult;
#endif // TYPES_H_

View File

@@ -11,11 +11,4 @@ add_library(mini SHARED
) )
# find_library(HILOAD_LIB NAMES hiload PATHS ${CMAKE_BINARY_DIR})
# if (${HILOAD_LIB} STREQUAL 'HILOAD_LIB-NOTFOUND')
# message(FATAL_ERROR "Couldn't find hiload library")
# endif()
# target_link_libraries(minimal mini ${HILOAD_LIB})
target_link_libraries(minimal mini hiload) target_link_libraries(minimal mini hiload)

View File

@@ -1,6 +1,5 @@
#include "minimal_lib.h" #include "minimal_lib.h"
// We're not installing anything, so this is a bit weird here
#include "../../include/hiload/hiload.h" #include "../../include/hiload/hiload.h"
#include <chrono> #include <chrono>