about summary refs log tree commit diff stats
path: root/src/elfs/elfloader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/elfs/elfloader.c')
-rwxr-xr-xsrc/elfs/elfloader.c44
1 files changed, 9 insertions, 35 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index f93ce1df..35a7d3a2 100755
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -54,7 +54,7 @@ elfheader_t* LoadAndCheckElfHeader(FILE* f, const char* name, int exec)
     if(!h)
         return NULL;
 
-    if ((h->path = realpath(name, NULL)) == NULL) {
+    if ((h->path = box_realpath(name, NULL)) == NULL) {
         h->path = (char*)box_malloc(1);
         h->path[0] = '\0';
     }
@@ -821,6 +821,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t
     }
     return bindnow?ret_ok:0;
 }
+void checkHookedSymbols(lib_t *maplib, elfheader_t* h); // in mallochook.c
 int RelocateElf(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t* head)
 {
     if(head->rel) {
@@ -837,7 +838,7 @@ int RelocateElf(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t* he
         if(RelocateElfRELA(maplib, local_maplib, bindnow, head, cnt, (Elf64_Rela *)(head->rela + head->delta), NULL))
             return -1;
     }
-   
+    checkHookedSymbols(maplib, head);
     return 0;
 }
 
@@ -945,22 +946,6 @@ uintptr_t GetLastByte(elfheader_t* h)
 void AddSymbols(lib_t *maplib, kh_mapsymbols_t* mapsymbols, kh_mapsymbols_t* weaksymbols, kh_mapsymbols_t* localsymbols, elfheader_t* h)
 {
     if(box64_dump && h->DynSym) DumpDynSym(h);
-    int libcef = (strstr(h->name, "libcef.so"))?1:0;
-    //libcef.so is linked with tcmalloc staticaly, but this cannot be easily supported in box64, so hacking some "unlink" here
-    const char* avoid_libcef[] = {"malloc", "realloc", "free", "calloc", "cfree",
-        "__libc_malloc", "__libc_calloc", "__libc_free", "__libc_memallign", "__libc_pvalloc",
-        "__libc_realloc", "__libc_valloc", "__posix_memalign",
-        "valloc", "pvalloc", "posix_memalign", "malloc_stats", "malloc_usable_size",
-        /*"mallopt",*/ "localtime_r",
-        //c++ symbol from libstdc++ too
-        //"_ZnwmRKSt9nothrow_t", "_ZdaPv",    // operator new(unsigned long, std::nothrow_t const&), operator delete[](void*)
-        //"_Znwm", "_ZdlPv", "_Znam",         // operator new(unsigned long), operator delete(void*), operator new[](unsigned long)
-        //"_ZnwmSt11align_val_t", "_ZnwmSt11align_val_tRKSt9nothrow_t",   // operator new(unsigned long, std::align_val_t)
-        //"_ZnamSt11align_val_t", "_ZnamSt11align_val_tRKSt9nothrow_t",   // operator new[](unsigned long, std::align_val_t)
-        //"_ZdlPvRKSt9nothrow_t", "_ZdaPvSt11align_val_tRKSt9nothrow_t",  // more delete operators
-        //"_ZdlPvmSt11align_val_t", "_ZdaPvRKSt9nothrow_t",
-        //"_ZdaPvSt11align_val_t", "_ZdlPvSt11align_val_t",
-    };
     printf_dump(LOG_NEVER, "Will look for Symbol to add in SymTable(%zu)\n", h->numSymTab);
     for (size_t i=0; i<h->numSymTab; ++i) {
         const char * symname = h->StrTab+h->SymTab[i].st_name;
@@ -994,13 +979,6 @@ void AddSymbols(lib_t *maplib, kh_mapsymbols_t* mapsymbols, kh_mapsymbols_t* wea
                     }
             } else {
                 int to_add = 1;
-                if(libcef) {
-                    if(strstr(symname, "_Zn")==symname || strstr(symname, "_Zd")==symname)
-                        to_add = 0;
-                    for(int j=0; j<sizeof(avoid_libcef)/sizeof(avoid_libcef[0]) && to_add; ++j)
-                        if(!strcmp(symname, avoid_libcef[j]))
-                            to_add = 0;
-                }
                 if(!to_add || (bind==STB_GNU_UNIQUE && FindGlobalSymbol(maplib, symname, -1, NULL)))
                     continue;
                 uintptr_t offs = (type==STT_TLS)?h->SymTab[i].st_value:(h->SymTab[i].st_value + h->delta);
@@ -1036,13 +1014,6 @@ void AddSymbols(lib_t *maplib, kh_mapsymbols_t* mapsymbols, kh_mapsymbols_t* wea
                 printf_dump(LOG_NEVER, "Adding Default Version \"%s\" for Symbol\"%s\"\n", vername, symname);
             }
             int to_add = 1;
-            if(libcef) {
-                if(strstr(symname, "_Zn")==symname || strstr(symname, "_Zd")==symname)
-                    to_add = 0;
-                for(int j=0; j<sizeof(avoid_libcef)/sizeof(avoid_libcef[0]) && to_add; ++j)
-                    if(!strcmp(symname, avoid_libcef[j]))
-                        to_add = 0;
-            }
             if(!to_add || (bind==STB_GNU_UNIQUE && FindGlobalSymbol(maplib, symname, version, vername)))
                 continue;
             printf_dump(LOG_NEVER, "Adding Versionned Symbol(bind=%s) \"%s\" (ver=%d/%s) with offset=%p sz=%zu\n", (bind==STB_LOCAL)?"LOCAL":((bind==STB_WEAK)?"WEAK":"GLOBAL"), symname, version, vername?vername:"(none)", (void*)offs, sz);
@@ -1056,7 +1027,6 @@ void AddSymbols(lib_t *maplib, kh_mapsymbols_t* mapsymbols, kh_mapsymbols_t* wea
                 }
         }
     }
-    
 }
 
 /*
@@ -1188,7 +1158,11 @@ void RefreshElfTLS(elfheader_t* h)
         }
     }
 }
-
+void MarkElfInitDone(elfheader_t* h)
+{
+    if(h)
+        h->init_done = 1;
+}
 void RunElfInit(elfheader_t* h, x64emu_t *emu)
 {
     if(!h || h->init_done)
@@ -1209,6 +1183,7 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
         return;
     }
     printf_log(LOG_DEBUG, "Calling Init for %s @%p\n", ElfName(h), (void*)p);
+    h->init_done = 1;
     if(h->initentry)
         RunFunctionWithEmu(emu, 0, p, 3, context->argc, context->argv, context->envv);
     printf_log(LOG_DEBUG, "Done Init for %s\n", ElfName(h));
@@ -1221,7 +1196,6 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
         }
     }
 
-    h->init_done = 1;
     h->fini_done = 0;   // can be fini'd now (in case it was re-inited)
     printf_log(LOG_DEBUG, "All Init Done for %s\n", ElfName(h));
     return;