unmake str as submodule
This commit is contained in:
13
src/hiload.c
13
src/hiload.c
@@ -3,6 +3,7 @@
|
||||
#include "logger.h"
|
||||
#include "memory.h"
|
||||
#include "symbols.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <dlfcn.h>
|
||||
@@ -19,6 +20,12 @@ typedef struct {
|
||||
size_t capacity; // Allocated capacity
|
||||
} ModuleInfos;
|
||||
|
||||
typedef struct {
|
||||
struct sc_array_memreg *memory_regions;
|
||||
} HiloadContext;
|
||||
|
||||
static HiloadContext context = {0};
|
||||
|
||||
static ModuleInfos *module_infos = 0;
|
||||
|
||||
// Callback function for dl_iterate_phdr
|
||||
@@ -259,7 +266,11 @@ int hi_init() {
|
||||
}
|
||||
sc_log_set_level("DEBUG");
|
||||
|
||||
read_memory_maps_self();
|
||||
|
||||
if (read_memory_maps_self(context.memory_regions) != HILOAD_OK) {
|
||||
sc_log_error("Could not populate program memory maps.\n");
|
||||
return HILOAD_FAIL;
|
||||
}
|
||||
|
||||
ModuleInfos *infos = gather_shared_libraries();
|
||||
if (!infos) {
|
||||
|
||||
15
src/memory.c
15
src/memory.c
@@ -4,15 +4,22 @@
|
||||
#include "logger.h"
|
||||
#include "types.h"
|
||||
|
||||
static
|
||||
str read_memory_maps_self() {
|
||||
void hi_clear_memreg(struct sc_array_memreg *regions)
|
||||
{
|
||||
MemoryRegions *reg;
|
||||
sc_array_foreach(regions, *reg) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
HiloadResult read_memory_maps_self(struct sc_array_memreg *regions) {
|
||||
str memory_str = str_null;
|
||||
|
||||
HiloadResult res = read_stream_to_str(&memory_str, "/proc/self/maps");
|
||||
if (res == HILOAD_FAIL)
|
||||
return str_null;
|
||||
return HILOAD_FAIL;
|
||||
|
||||
sc_log_debug("Memory Map\n-- /proc/self/maps:\n%s\n", str_ptr(memory_str));
|
||||
|
||||
return memory_str;
|
||||
return HILOAD_OK;
|
||||
}
|
||||
|
||||
23
src/memory.h
23
src/memory.h
@@ -5,6 +5,8 @@
|
||||
#include "types.h"
|
||||
#include "array.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
enum MemoryPermissions {
|
||||
HI_MEMORY_READ = 1 << 0,
|
||||
HI_MEMORY_WRITE = 1 << 1,
|
||||
@@ -13,13 +15,22 @@ enum MemoryPermissions {
|
||||
HI_MEMORY_PRIVATE = 1 << 4
|
||||
};
|
||||
|
||||
#define REGIONS_MAX 256
|
||||
#define HI_MEM_REG_MAX 256
|
||||
typedef struct {
|
||||
void *region_starts[REGIONS_MAX];
|
||||
void *region_end[REGIONS_MAX];
|
||||
u32 region_flags[REGIONS_MAX]; // enum MemoryPermissions
|
||||
u32 offset[REGIONS_MAX];
|
||||
str pathname[REGIONS_MAX];
|
||||
void *region_starts[HI_MEM_REG_MAX];
|
||||
void *region_end[HI_MEM_REG_MAX];
|
||||
u32 region_flags[HI_MEM_REG_MAX]; // enum MemoryPermissions
|
||||
u32 offset[HI_MEM_REG_MAX];
|
||||
str pathname[HI_MEM_REG_MAX];
|
||||
} MemoryRegions;
|
||||
|
||||
sc_array_def(MemoryRegions, memreg);
|
||||
_Static_assert(sizeof(MemoryRegions) < 1024 * 11, "MemoryRegion size has increased. Fix this assert.");
|
||||
|
||||
/* Needed to free the underlying pathnames before clear */
|
||||
void hi_clear_memreg(struct sc_array_memreg *regions);
|
||||
|
||||
/* A pointer that can be used to place the memory regions into. If mr isn't cleared, the content will be cleared. */
|
||||
HiloadResult read_memory_maps_self(struct sc_array_memreg *regions);
|
||||
|
||||
#endif // MEMORY_H_
|
||||
|
||||
Reference in New Issue
Block a user