Fixing merge conflict resolution
This commit is contained in:
15
src/files.c
Normal file
15
src/files.c
Normal 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
9
src/files.h
Normal 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_
|
||||
54
src/hiload.c
54
src/hiload.c
@@ -1,4 +1,7 @@
|
||||
#include "hiload/hiload.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "memory.h"
|
||||
#include "symbols.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] =
|
||||
dlopen(info->dlpi_name, RTLD_LAZY | RTLD_NOLOAD);
|
||||
|
||||
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]);
|
||||
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++;
|
||||
return 0; // Continue iteration
|
||||
@@ -110,23 +115,6 @@ static ModuleInfos *gather_shared_libraries(void) {
|
||||
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
|
||||
*
|
||||
@@ -261,3 +249,31 @@ void hi_print_module_infos() {
|
||||
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
14
src/memory.c
Normal 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
28
src/memory.h
Normal 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
19
src/types.h
Normal 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_
|
||||
Reference in New Issue
Block a user