So that it can be used for other purposes (e.g. syscall.c) after the elf loader closed it.
Signed-off-by: YAMAMOTO Takashi <yamam...@midokura.com> --- linux-user/main.c | 8 ++++++++ linux-user/qemu.h | 2 ++ linux-user/syscall.c | 5 ++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 1f9f4e3820..86ddba8b62 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -56,6 +56,7 @@ char *exec_path; char exec_path_store[PATH_MAX]; +int exec_fd = -1; int singlestep; static const char *argv0; @@ -833,6 +834,13 @@ int main(int argc, char **argv, char **envp) cpu->opaque = ts; task_settid(ts); + /* + * dup execfd to a global so that it can be used after loader_exec + * closes it. + */ + + exec_fd = dup(execfd); + ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs, info, &bprm); if (ret != 0) { diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 3b0b6b75fe..ee4e9a1779 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -160,6 +160,8 @@ typedef struct TaskState { } __attribute__((aligned(16))) TaskState; extern char *exec_path; +extern int exec_fd; + void init_task_state(TaskState *ts); void task_settid(TaskState *); void stop_all_tasks(void); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 14a63518e2..2947e79dc0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8117,12 +8117,11 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, }; if (is_proc_myself(pathname, "exe")) { - int execfd = qemu_getauxval(AT_EXECFD); - if (execfd) { + if (exec_fd != -1) { char filename[PATH_MAX]; int ret; - snprintf(filename, sizeof(filename), "/proc/self/fd/%d", execfd); + snprintf(filename, sizeof(filename), "/proc/self/fd/%d", exec_fd); ret = safe_openat(dirfd, filename, flags, mode); if (ret != -1) { return ret; -- 2.21.1 (Apple Git-122.3)