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.
This commit is contained in:
2022-05-26 11:48:32 +01:00
parent 659d196d60
commit 4bbf10e7ef

View File

@@ -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];