about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-03-05 20:39:53 +0100
committerptitSeb <sebastien.chev@gmail.com>2021-03-05 20:39:53 +0100
commitbd8506cb06fab2b0ddde3196c59ae42533289a61 (patch)
tree000a09fbb0fe11b5cab5563861d5d774e45816cf /src
parent0f73133debd70f02a2447038c60378c2049b2486 (diff)
downloadbox64-bd8506cb06fab2b0ddde3196c59ae42533289a61.tar.gz
box64-bd8506cb06fab2b0ddde3196c59ae42533289a61.zip
Added fork wrapped function
Diffstat (limited to 'src')
-rwxr-xr-xsrc/emu/x64int3.c66
-rwxr-xr-xsrc/emu/x64run.c18
-rwxr-xr-xsrc/emu/x64run_private.h2
-rwxr-xr-xsrc/wrapped/wrappedlibc.c4
-rwxr-xr-xsrc/wrapped/wrappedlibc_private.h2
5 files changed, 46 insertions, 46 deletions
diff --git a/src/emu/x64int3.c b/src/emu/x64int3.c
index 54ae632a..6a8d51ca 100755
--- a/src/emu/x64int3.c
+++ b/src/emu/x64int3.c
@@ -30,39 +30,39 @@
 
 typedef int32_t (*iFpppp_t)(void*, void*, void*, void*);
 
-//x64emu_t* x64emu_fork(x64emu_t* emu, int forktype)
-//{
-//    // execute atforks prepare functions, in reverse order
-//    for (int i=my_context->atfork_sz-1; i>=0; --i)
-//        if(my_context->atforks[i].prepare)
-//            EmuCall(emu, my_context->atforks[i].prepare);
-//    int type = emu->type;
-//    int v;
-//    if(forktype==2) {
-//        iFpppp_t forkpty = (iFpppp_t)emu->forkpty_info->f;
-//        v = forkpty(emu->forkpty_info->amaster, emu->forkpty_info->name, emu->forkpty_info->termp, emu->forkpty_info->winp);
-//        emu->forkpty_info = NULL;
-//    } else
-//        v = fork();
-//    if(type == EMUTYPE_MAIN)
-//        thread_set_emu(emu);
-//    if(v==EAGAIN || v==ENOMEM) {
-//        // error...
-//    } else if(v!=0) {  
-//        // execute atforks parent functions
-//        for (int i=0; i<my_context->atfork_sz; --i)
-//            if(my_context->atforks[i].parent)
-//                EmuCall(emu, my_context->atforks[i].parent);
-//
-//    } else if(v==0) {
-//        // execute atforks child functions
-//        for (int i=0; i<my_context->atfork_sz; --i)
-//            if(my_context->atforks[i].child)
-//                EmuCall(emu, my_context->atforks[i].child);
-//    }
-//    R_EAX = v;
-//    return emu;
-//}
+x64emu_t* x64emu_fork(x64emu_t* emu, int forktype)
+{
+    // execute atforks prepare functions, in reverse order
+    for (int i=my_context->atfork_sz-1; i>=0; --i)
+        if(my_context->atforks[i].prepare)
+            EmuCall(emu, my_context->atforks[i].prepare);
+    int type = emu->type;
+    int v;
+    if(forktype==2) {
+        iFpppp_t forkpty = (iFpppp_t)emu->forkpty_info->f;
+        v = forkpty(emu->forkpty_info->amaster, emu->forkpty_info->name, emu->forkpty_info->termp, emu->forkpty_info->winp);
+        emu->forkpty_info = NULL;
+    } else
+        v = fork();
+    if(type == EMUTYPE_MAIN)
+        thread_set_emu(emu);
+    if(v==EAGAIN || v==ENOMEM) {
+        // error...
+    } else if(v!=0) {  
+        // execute atforks parent functions
+        for (int i=0; i<my_context->atfork_sz; --i)
+            if(my_context->atforks[i].parent)
+                EmuCall(emu, my_context->atforks[i].parent);
+
+    } else if(v==0) {
+        // execute atforks child functions
+        for (int i=0; i<my_context->atfork_sz; --i)
+            if(my_context->atforks[i].child)
+                EmuCall(emu, my_context->atforks[i].child);
+    }
+    R_EAX = v;
+    return emu;
+}
 
 extern int errno;
 void x64Int3(x64emu_t* emu)
diff --git a/src/emu/x64run.c b/src/emu/x64run.c
index 96bf5aa8..10f4c9f2 100755
--- a/src/emu/x64run.c
+++ b/src/emu/x64run.c
@@ -656,15 +656,15 @@ fini:
         UnimpOpcode(emu);
     }
     // fork handling
-//    if(emu->fork) {
-//        if(step)
-//            return 0;
-//        int forktype = emu->fork;
-//        emu->quit = 0;
-//        emu->fork = 0;
-//        emu = x64emu_fork(emu, forktype);
-//        goto x64emurun;
-//    }
+    if(emu->fork) {
+        if(step)
+            return 0;
+        int forktype = emu->fork;
+        emu->quit = 0;
+        emu->fork = 0;
+        emu = x64emu_fork(emu, forktype);
+        goto x64emurun;
+    }
     // setcontext handling
 //    else if(emu->uc_link) {
 //        emu->quit = 0;
diff --git a/src/emu/x64run_private.h b/src/emu/x64run_private.h
index 4d53a98e..3c842d0f 100755
--- a/src/emu/x64run_private.h
+++ b/src/emu/x64run_private.h
@@ -244,7 +244,7 @@ int RunF30F(x64emu_t *emu, rex_t rex);
 
 void x64Syscall(x64emu_t *emu);
 void x64Int3(x64emu_t* emu);
-//x64emu_t* x64emu_fork(x64emu_t* e, int forktype);
+x64emu_t* x64emu_fork(x64emu_t* e, int forktype);
 
 uintptr_t GetSegmentBaseEmu(x64emu_t* emu, int seg);
 #define GetGSBaseEmu(emu)    GetSegmentBaseEmu(emu, _GS)
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 56b04f3b..e7ac5156 100755
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -429,7 +429,7 @@ int my_swapcontext(x64emu_t* emu, void* ucp1, void* ucp2);
 // this one is defined in elfloader.c
 int my_dl_iterate_phdr(x64emu_t *emu, void* F, void *data);
 
-
+#endif
 pid_t EXPORT my_fork(x64emu_t* emu)
 {
     // execute atforks prepare functions, in reverse order
@@ -469,7 +469,7 @@ pid_t EXPORT my_vfork(x64emu_t* emu)
     return 0;
     #endif
 }
-#endif
+
 int EXPORT my_uname(struct utsname *buf)
 {
     //TODO: check sizeof(struct utsname)
diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h
index aa5a9434..72f3a4a8 100755
--- a/src/wrapped/wrappedlibc_private.h
+++ b/src/wrapped/wrappedlibc_private.h
@@ -370,7 +370,7 @@ GOM(__cxa_finalize, vFEp)
 //GOW(fopen64, 
 //GO(fopencookie, 
 //GO(__fork, 
-//GOW(fork, 
+GOM(fork, iFEv) // Weak
 //GO(__fortify_fail, 
 //GOW(fpathconf, 
 //GO(__fpending,