about summary refs log tree commit diff stats
path: root/src/emu
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/emu
parent0f73133debd70f02a2447038c60378c2049b2486 (diff)
downloadbox64-bd8506cb06fab2b0ddde3196c59ae42533289a61.tar.gz
box64-bd8506cb06fab2b0ddde3196c59ae42533289a61.zip
Added fork wrapped function
Diffstat (limited to 'src/emu')
-rwxr-xr-xsrc/emu/x64int3.c66
-rwxr-xr-xsrc/emu/x64run.c18
-rwxr-xr-xsrc/emu/x64run_private.h2
3 files changed, 43 insertions, 43 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)