On Wed, Nov 6, 2024 at 11:53 AM Noah Goldstein <goldstein....@gmail.com> wrote: > > On Wed, Nov 6, 2024 at 11:26 AM Richard Henderson > <richard.hender...@linaro.org> wrote: > > > > On 11/6/24 17:03, Noah Goldstein wrote: > > > On Wed, Nov 6, 2024 at 3:38 AM Richard Henderson > > > <richard.hender...@linaro.org> wrote: > > >> > > >> On 11/5/24 23:54, Noah Goldstein wrote: > > >>>>> You still need to handle is_proc_myself, for the guest binary. > > >>> > > >>> Would this by handled by basically do: > > >>> > > >>> ``` > > >>> if (is_proc_myself(p, "exe")) { > > >>> exe = exec_path; > > >>> if (through_qemu) > > >>> argp[argp_offset] = exec_path; > > >>> } > > >>> ``` > > >>> Or am I missing something? > > >> > > >> Something like that, yes. > > >> > > >>>>> I wonder if those two cases are related. Do we need to also add an > > >>>>> argument so that we > > >>>>> can pass the executable to the next qemu via file descriptor? I.e. > > >>>>> execvat becomes > > >>>>> > > >>>>> f = openat() > > >>>>> execv(qemu, "-execfd", f) > > >>>>> > > >>>>> and is_proc_myself uses execfd, which we already have open. > > >>> > > >>> How does passing a fd from one process to another work? > > >> As long as the fd is not marked O_CLOEXEC, it stays open in the new > > >> process. Providing > > >> the number via command-line, or whatever, is sufficient for the new > > >> process to know what > > >> is going on. > > > > > > Err I guess I was thinking its a bit weird having an option that is > > > only really applicable > > > if qemu is a child process. I.e the `-execfd` argument is not usable > > > from commandline. > > > > qemu-foo -execfd 3 3< /some/file > > > > Or perhaps opened via other tooling. > > > > >> I now realize this is necessary for the AT_EMPTY_PATH flag, where we > > >> only have the file > > >> descriptor. > > > > > > We could also do something along the lines of: > > > > > > ``` > > > fd = openat(dirfd, exe); > > > char new_exe[PATH_MAX]; > > > char fd_path[PATH_MAX]; > > > sprintf(fd_path, "/proc/self/fd/%d", fd); > > > readlink(fd_path, new_exe, PATH_MAX); > > > > Reading the link doesn't always work. > > Reading or passing the link means AT_SYMLINK_NOFOLLOW isn't honored. > > Okay, fair enough, I will get started on adding `-execfd`
Question about impl regarding handling of `-execfd` with/without a program name. 1) `-execfd` + program name ie: `qemu -execfd <some_fd> ls -a`. 2) `-execfd` without program name i.e: `qemu -execfd <some_fd> -a`. Do you want to allow both of these? If you want to allow (1), what should we use for `argv[0]`/`exec_path`. The program pass ("ls") or `readlink(<some_fd>)`?