From 4bbf10e7efdbe1950f6007d477bfae6745c1a2a3 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 26 May 2022 11:48:32 +0100 Subject: [PATCH] launch() now sends the stdio handles to the interpreter automatically The same handles are used in both messages. This works because libc destroys the first message and closes its handles before reading the second one, so only one copy of each handle will exist in the new process at one time. --- photon/libc/sys/horizon/launch.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/photon/libc/sys/horizon/launch.c b/photon/libc/sys/horizon/launch.c index ae24786..2b2e6e6 100644 --- a/photon/libc/sys/horizon/launch.c +++ b/photon/libc/sys/horizon/launch.c @@ -78,6 +78,10 @@ struct cleanup { size_t inherited_ns_len; int *fd; + + /* this is used to send STDIO handles to the interpreter. + * the same handles are sent in both messages. */ + mx_handle_t stdio[LAUNCH_MAX_FDS]; }; static void set_error_msg(const char *s, ...) @@ -366,6 +370,7 @@ static int collect_handles(const struct launch_info *info, struct cleanup *clean b_idx++; cleanup->auto_handles[auto_idx++] = fd_handle; + cleanup->stdio[i] = fd_handle; } if (info->flags & LAUNCH_INHERIT_NS) { @@ -1034,6 +1039,9 @@ static int send_interp_bootstrap_message(const struct launch_info *args, struct ARG_HANDLE(cleanup->exec.remote_exec_vmar, MX_B_HND(MX_B_VMAR_EXEC, 0)), ARG_HANDLE(vdso_vmo, MX_B_HND(MX_B_VMO_VDSO, 0)), ARG_HANDLE(ldsvc, MX_B_HND(MX_B_TUNNEL_LDSVC, cleanup->ldsvc_version)), + ARG_HANDLE(cleanup->stdio[0], MX_B_HND(MX_B_FD, 0)), + ARG_HANDLE(cleanup->stdio[1], MX_B_HND(MX_B_FD, 1)), + ARG_HANDLE(cleanup->stdio[2], MX_B_HND(MX_B_FD, 2)), }; static size_t handle_count = sizeof handles / sizeof handles[0];