Clunky hack to get unrecognized executables to run via emulated /bin/sh, add ./n...
authorNick Downing <nick@ndcode.org>
Thu, 6 Jun 2019 12:39:27 +0000 (22:39 +1000)
committerNick Downing <nick@ndcode.org>
Thu, 6 Jun 2019 12:39:43 +0000 (22:39 +1000)
Makefile
n.sh [new file with mode: 0755]
v7trap.c

index 255280b..3443f41 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ CC?=gcc
 #APOUT_OPTIONS?= -DEMU211 -DEMUV1 -DNATIVES -DRUN_V1_RAW \
        -DDEBUG -DZERO_MEMORY -DWRITEBASE
 # These flags should be fine for most cases
-APOUT_OPTIONS?= -DEMU211 -DEMUv1 -DNATIVES
+APOUT_OPTIONS?= -DEMU211 -DEMUv1 -DNATIVES -DDEBUG
 
 # These flags for speed
 #CFLAGS+= -DEMU211 -DNATIVES -DINLINE=inline -O2 -Winline -Wall \
diff --git a/n.sh b/n.sh
new file mode 100755 (executable)
index 0000000..460fe5f
--- /dev/null
+++ b/n.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+echo ":apout410:M::\\x08\\x01::`pwd`/apout:" >/proc/sys/fs/binfmt_misc/register
+echo ":apout411:M::\\x09\\x01::`pwd`/apout:" >/proc/sys/fs/binfmt_misc/register
index e7df4ac..7e5ee7f 100644 (file)
--- a/v7trap.c
+++ b/v7trap.c
@@ -667,6 +667,21 @@ static int trap_exec(int want_env)
     Envp[Envc] = NULL;
 
     if (load_a_out(name, origpath, want_env) == -1) {
+#if 1 // Nick
+        struct stat statbuf;
+        if (stat(name, &statbuf) == 0) {
+            free(origpath); // note: clobbers name
+            if (Argc >= MAX_ARGS)
+                Argv[--Argc] = NULL;
+            for (i = Argc++; i >= 1; --i)
+                Argv[i + 1] = Argv[i];
+            Argv[1] = strdup((char *) &dspace[uarg1]);
+            origpath = "/bin/sh";
+            name = xlate_filename(origpath);
+            if (load_a_out(name, origpath, want_env) != -1)
+                goto ok;
+        }
+#endif
         for (Argc--; Argc >= 0; Argc--)
             free(Argv[Argc]);
         for (Envc--; Envc >= 0; Envc--)
@@ -674,6 +689,10 @@ static int trap_exec(int want_env)
         errno = ENOENT;
         return (-1);
     }
+    free(origpath); // Nick... fix memory leak
+#if 1 // Nick
+ok:
+#endif
     run();                     /* Ok, so it's recursive, I dislike setjmp */
     return (0);
 }