On 8/27/23 08:57, Karim Taha wrote:
From: Stacey Son<s...@freebsd.org>

Signed-off-by: Stacey Son<s...@freebsd.org>
Signed-off-by: Karim Taha<kariem.taha...@gmail.com>
---
  bsd-user/freebsd/os-proc.c | 177 +++++++++++++++++++++++++++++++++++++
  1 file changed, 177 insertions(+)

Acked-by: Richard Henderson <richard.hender...@linaro.org>

+    if (do_fexec) {
+        if (((int)path_or_fd > 0 &&
+            is_target_elf_binary((int)path_or_fd)) == 1) {
+            char execpath[PATH_MAX];
+
+            /*
+             * The executable is an elf binary for the target
+             * arch.  execve() it using the emulator if we can
+             * determine the filename path from the fd.
+             */
+            if (get_filename_from_fd(getpid(), (int)path_or_fd, execpath,
+                        sizeof(execpath)) != NULL) {
+                memmove(qarg1 + 2, qarg1, (qargend-qarg1) * sizeof(*qarg1));
+               qarg1[1] = qarg1[0];
+               qarg1[0] = (char *)"-0";
+               qarg1 += 2;
+               qargend += 2;
+                *qarg1 = execpath;
+#ifndef DONT_INHERIT_INTERP_PREFIX
+                memmove(qarg1 + 2, qarg1, (qargend-qarg1) * sizeof(*qarg1));
+                *qarg1++ = (char *)"-L";
+                *qarg1++ = (char *)interp_prefix;
+#endif

I'm not especailly keen on the ifdef, but I'll let that go.

As for get_filename_from_fd, perhaps it would be cleaner to add a command-line parameter which would allow qemu to run from an open file descriptor? Although perhaps that has CLOEXEC implications too...


r~

Reply via email to