1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-22 07:37:38 +01:00

eh_elf: fix memory map

This commit is contained in:
Théophile Bastian 2018-06-05 18:22:15 +02:00
parent 3691f0c18d
commit 1068aa2368

View file

@ -14,8 +14,15 @@ static int _mmap_init_done = 0;
int mmap_init_procdir(const char* procdir);
static int compare_mmap_entry(const void* e1, const void* e2) {
return ((mmap_entry_t*)e1)->beg_ip - ((mmap_entry_t*)e2)->beg_ip;
static int compare_mmap_entry(const void* _e1, const void* _e2) {
// We can't return e1->beg_ip - e2->beg_ip because of int overflows
const mmap_entry_t *e1 = _e1,
*e2 = _e2;
if(e1->beg_ip < e2->beg_ip)
return -1;
if(e1->beg_ip > e2->beg_ip)
return 1;
return 0;
}
int mmap_init_local() {
@ -76,7 +83,7 @@ int mmap_init_procdir(const char* procdir) {
continue;
_memory_map[cur_entry].id = cur_entry;
_memory_map[cur_entry].offset = offset;
_memory_map[cur_entry].offset = ip_beg - offset;
_memory_map[cur_entry].beg_ip = ip_beg;
_memory_map[cur_entry].end_ip = ip_end;
_memory_map[cur_entry].object_name =
@ -88,7 +95,7 @@ int mmap_init_procdir(const char* procdir) {
free(line);
// Shrink _memory_map to only use up the number of relevant entries
assert(_memory_map_size >= cur_entry);
assert(_memory_map_size >= (size_t)cur_entry);
_memory_map_size = cur_entry; // Because of skipped entries
_memory_map = (mmap_entry_t*)
realloc(_memory_map, _memory_map_size * sizeof(mmap_entry_t));