1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-25 16:47:38 +01:00

eh_elf: handle properly reinit

This commit is contained in:
Théophile Bastian 2018-06-13 19:07:52 +02:00
parent 1493c0ca4b
commit 96ed4c4d82

View file

@ -46,6 +46,8 @@ int mmap_init_pid(pid_t pid) {
int mmap_init_procdir(const char* procdir) {
// This function reads /proc/pid/maps and deduces the memory map
mmap_clear();
// Open the mmap file
char map_path[128];
sprintf(map_path, "%s/maps", procdir);
@ -123,21 +125,24 @@ int mmap_init_procdir(const char* procdir) {
int mmap_init_mmap(unw_mmap_entry_t* entries, size_t count) {
Debug(3, "Start reading mmap (entries=%016lx)\n", (uintptr_t)entries);
Debug(3, "%lu entries\n", count);
mmap_clear();
_memory_map = (mmap_entry_t*) calloc(count, sizeof(mmap_entry_t));
_memory_map_size = count;
int mmap_pos = 0;
for(int pos=0; pos < (int)count; ++pos) {
Debug(3, "> MMAP %016lx-%016lx %s\n",
entries[pos].beg_ip,
entries[pos].end_ip,
entries[pos].object_name);
if(entries[pos].object_name[0] == '[') {
// Special entry (stack,vdso, …)
continue;
}
Debug(3, "> MMAP %016lx-%016lx %s\n",
entries[pos].beg_ip,
entries[pos].end_ip,
entries[pos].object_name);
_memory_map[mmap_pos].id = pos;
_memory_map[mmap_pos].offset = entries[pos].offset;
_memory_map[mmap_pos].beg_ip = entries[pos].beg_ip;
@ -158,7 +163,9 @@ int mmap_init_mmap(unw_mmap_entry_t* entries, size_t count) {
return -3;
if(mmap_dlopen_eh_elfs(_memory_map, _memory_map_size) < 0)
return -4;
Debug(3, "Init complete");
_mmap_init_done = 1;
Debug(3, "Init complete\n");
return 0;
}
@ -210,9 +217,11 @@ static int bsearch_compar_mmap_entry(const void* vkey, const void* vmmap_elt) {
mmap_entry_t* mmap_get_entry(uintptr_t ip) {
// Perform a binary search to find the requested ip
if(!_mmap_init_done)
Debug(3, "Getting mmap entry %016lx\n", ip);
if(!_mmap_init_done) {
Debug(1, "Mmap access before init! Aborting\n");
return NULL;
}
return bsearch(
(void*)&ip,
(void*)_memory_map,