about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/elfs/elfloader.c10
-rw-r--r--src/emu/x64run_private.c8
2 files changed, 15 insertions, 3 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index 10bb7b02..6c782c52 100644
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -1169,8 +1169,12 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
                 RunElfInit(lib_elf, emu);
         }
     printf_dump(LOG_DEBUG, "Calling Init for %s @%p\n", ElfName(h), (void*)p);
-    if(h->initentry)
-        RunFunctionWithEmu(emu, 0, p, 3, my_context->argc, my_context->argv, my_context->envv);
+    if(h->initentry) {
+        if(box64_is32bits)
+            RunFunctionWithEmu(emu, 0, p, 3, my_context->argc, my_context->argv32, my_context->envv32);
+        else
+            RunFunctionWithEmu(emu, 0, p, 3, my_context->argc, my_context->argv, my_context->envv);
+    }
     printf_dump(LOG_DEBUG, "Done Init for %s\n", ElfName(h));
     // and check init array now
     #ifdef BOX32
@@ -1179,7 +1183,7 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
         for (size_t i=0; i<h->initarray_sz; ++i) {
             if(addr[i]) {
                 printf_dump(LOG_DEBUG, "Calling Init[%zu] for %s @%p\n", i, ElfName(h), from_ptrv(addr[i]));
-                RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv, my_context->envv);
+                RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv32, my_context->envv32);
             }
         }
     } else
diff --git a/src/emu/x64run_private.c b/src/emu/x64run_private.c
index deba1a05..5cb8141f 100644
--- a/src/emu/x64run_private.c
+++ b/src/emu/x64run_private.c
@@ -146,6 +146,14 @@ int32_t EXPORT my32___libc_start_main(x64emu_t* emu, int *(main) (int, char * *,
         if(emu->error)  // any error, don't bother with more
             return 0;
         emu->quit = 0;
+    } else {
+        if(my_context->elfs[0]) {
+            printf_dump(LOG_DEBUG, "Calling init from main elf\n");
+            RunElfInit(my_context->elfs[0], emu);
+        }
+    }
+    if(my_context->elfs[0]) {
+        MarkElfInitDone(my_context->elfs[0]);
     }
     printf_log(LOG_DEBUG, "Transfert to main(%d, %p, %p)=>%p from __libc_start_main\n", my_context->argc, my_context->argv, my_context->envv, main);
     // call main and finish