1.1 --- a/libexec/lib/src/process_creating.cc Wed Jan 24 21:12:41 2024 +0100
1.2 +++ b/libexec/lib/src/process_creating.cc Wed Jan 24 21:17:37 2024 +0100
1.3 @@ -284,7 +284,8 @@
1.4 thread. */
1.5
1.6 long ProcessCreating::start_program(l4_cap_idx_t monitor, int argc,
1.7 - const char *argv[], l4_cap_idx_t writer)
1.8 + const char *argv[], l4_cap_idx_t reader,
1.9 + l4_cap_idx_t writer)
1.10 {
1.11 /* NOTE: Environment vector is currently not defined. */
1.12
1.13 @@ -317,14 +318,17 @@
1.14 l4_cap_idx_t fsserver_cap = _process.allocate_cap();
1.15 l4_cap_idx_t fsserver = l4re_env_get_cap(ENV_FILESYSTEM_SERVER_NAME);
1.16
1.17 - /* Also reserve a capability for the writer. */
1.18 + /* Also reserve capabilities for the reader and writer. If the reader or
1.19 + writer are invalid capabilities, these will not actually be transferred. */
1.20
1.21 + l4_cap_idx_t reader_cap = _process.allocate_cap();
1.22 l4_cap_idx_t writer_cap = _process.allocate_cap();
1.23
1.24 /* Define the capabilities to be mapped for the filesystem. */
1.25
1.26 struct ipc_mapped_cap program_mapped_caps[] = {
1.27 {fsserver_cap, fsserver, L4_CAP_FPAGE_RWS, L4_FPAGE_C_OBJ_RIGHTS},
1.28 + {reader_cap, reader, L4_CAP_FPAGE_RWS, L4_FPAGE_C_OBJ_RIGHTS},
1.29 {writer_cap, writer, L4_CAP_FPAGE_RWS, L4_FPAGE_C_OBJ_RIGHTS},
1.30 {L4_INVALID_CAP, L4_INVALID_CAP, 0, 0},
1.31 };
1.32 @@ -340,8 +344,15 @@
1.33 l4re_env API. Each capability index is assigned above when mapping the
1.34 capability and encoded in the entry below. */
1.35
1.36 + if (l4_is_invalid_cap(reader))
1.37 + reader_cap = L4_INVALID_CAP;
1.38 +
1.39 + if (l4_is_invalid_cap(writer))
1.40 + writer_cap = L4_INVALID_CAP;
1.41 +
1.42 l4re_env_cap_entry_t program_init_caps[] = {
1.43 l4re_env_cap_entry_t(ENV_FILESYSTEM_SERVER_NAME, fsserver_cap, L4_CAP_FPAGE_RWS),
1.44 + l4re_env_cap_entry_t(ENV_INPUT_STREAM_NAME, reader_cap, L4_CAP_FPAGE_R),
1.45 l4re_env_cap_entry_t(ENV_OUTPUT_STREAM_NAME, writer_cap, L4_CAP_FPAGE_W),
1.46 l4re_env_cap_entry_t()
1.47 };
1.48 @@ -368,12 +379,12 @@
1.49 }
1.50
1.51 /* Start a new process for the payload indicated by the first of the given
1.52 - program arguments, employing the given writer pipe, and returning a
1.53 - reference to the process monitor as an object for interacting with the
1.54 + program arguments, employing the given reader and writer pipes, and returning
1.55 + a reference to the process monitor as an object for interacting with the
1.56 process. */
1.57
1.58 -long ProcessCreating::_start(int argc, const char *argv[], l4_cap_idx_t writer,
1.59 - l4_cap_idx_t process)
1.60 +long ProcessCreating::_start(int argc, const char *argv[], l4_cap_idx_t reader,
1.61 + l4_cap_idx_t writer, l4_cap_idx_t process)
1.62 {
1.63 /* Open the program file, handling any error conditions. If successfully
1.64 opened, it will be closed when the process terminates. */
1.65 @@ -419,7 +430,7 @@
1.66 if (err)
1.67 return err;
1.68
1.69 - err = start_program(process, argc, argv, writer);
1.70 + err = start_program(process, argc, argv, reader, writer);
1.71 if (err)
1.72 return err;
1.73
1.74 @@ -444,15 +455,16 @@
1.75
1.76 /* Start the given program, notifying the process monitor upon any error. */
1.77
1.78 -long ProcessCreating::start(int argc, const char *argv[], l4_cap_idx_t writer,
1.79 - l4_cap_idx_t process)
1.80 +long ProcessCreating::start(int argc, const char *argv[], l4_cap_idx_t reader,
1.81 + l4_cap_idx_t writer, l4_cap_idx_t process)
1.82 {
1.83 std::lock_guard<std::mutex> guard(_lock);
1.84
1.85 - long err = _start(argc, argv, writer, process);
1.86 + long err = _start(argc, argv, reader, writer, process);
1.87
1.88 - /* Discard the writer since it will not be used in this task. */
1.89 + /* Discard the reader and writer since they will not be used in this task. */
1.90
1.91 + ipc_cap_free_um(reader);
1.92 ipc_cap_free_um(writer);
1.93
1.94 /* Communicate the error using the signal value. */