1.1 --- a/libexec/lib/src/process_creating.cc Mon Mar 06 16:19:15 2023 +0100
1.2 +++ b/libexec/lib/src/process_creating.cc Mon Mar 06 18:30:22 2023 +0100
1.3 @@ -109,22 +109,26 @@
1.4
1.5 long ProcessCreating::configure_task(l4_cap_idx_t pager)
1.6 {
1.7 - l4_cap_idx_t task, rtask;
1.8 - long err = _process.configure_task(&task, &rtask);
1.9 + l4_cap_idx_t task, mapped_task;
1.10 + long err = _process.configure_task(&task, &mapped_task);
1.11
1.12 if (err)
1.13 return err;
1.14
1.15 - _exec_pager->set_task(task, rtask);
1.16 + /* Record the task details in the pager for eventual resource deallocation. */
1.17 +
1.18 + _exec_pager->set_task(task, mapped_task);
1.19
1.20 - l4_cap_idx_t rparent;
1.21 + /* Note the pager as the parent of the new task, recording its capability
1.22 + details in the new task. */
1.23
1.24 - err = _process.set_parent(pager, &rparent);
1.25 + l4_cap_idx_t mapped_parent;
1.26 + err = _process.set_parent(pager, &mapped_parent);
1.27
1.28 if (err)
1.29 return err;
1.30
1.31 - _exec_pager->set_parent(pager, rparent);
1.32 + _exec_pager->set_parent(pager, mapped_parent);
1.33 return L4_EOK;
1.34 }
1.35
1.36 @@ -139,8 +143,16 @@
1.37 if (l4_is_invalid_cap(_ipc_gate))
1.38 return -L4_ENOMEM;
1.39
1.40 + long err = l4_error(l4_factory_create_gate(l4re_env()->factory, _ipc_gate, L4_INVALID_CAP, 0));
1.41 +
1.42 + if (err)
1.43 + return err;
1.44 +
1.45 + /* The gate is retained because even after being mapped to the new task,
1.46 + releasing it will cause it to be deallocated. */
1.47 +
1.48 _exec_pager->set_gate(_ipc_gate);
1.49 - return l4_error(l4_factory_create_gate(l4re_env()->factory, _ipc_gate, L4_INVALID_CAP, 0));
1.50 + return L4_EOK;
1.51 }
1.52
1.53 /* Initialise and assign a region in a list to the created process. */
1.54 @@ -224,13 +236,13 @@
1.55 /* Configure the environment for the thread, specifying the pager (and
1.56 exception handler plus region mapper). */
1.57
1.58 - l4_cap_idx_t rpager = L4_INVALID_CAP;
1.59 - long err = _process.configure_thread(pager, &rpager);
1.60 + l4_cap_idx_t mapped_pager = L4_INVALID_CAP;
1.61 + long err = _process.configure_thread(pager, &mapped_pager);
1.62
1.63 if (err)
1.64 return err;
1.65
1.66 - _exec_pager->set_pager(pager, rpager);
1.67 + _exec_pager->set_pager(pager, mapped_pager);
1.68
1.69 /* Populate a thread stack with argument and environment details for the
1.70 region mapper, plus the initial server capability and region details. */
1.71 @@ -244,13 +256,13 @@
1.72
1.73 /* Start the region mapper thread in the appropriate stack. */
1.74
1.75 - l4_cap_idx_t thread, rthread;
1.76 - err = _process.thread_start(_rm_payload->entry_point(), rm_st, &thread, &rthread);
1.77 + l4_cap_idx_t thread, mapped_thread;
1.78 + err = _process.thread_start(_rm_payload->entry_point(), rm_st, &thread, &mapped_thread);
1.79
1.80 if (err)
1.81 return err;
1.82
1.83 - _exec_pager->add_thread(thread, rthread);
1.84 + _exec_pager->add_thread(thread, mapped_thread);
1.85 return L4_EOK;
1.86 }
1.87
1.88 @@ -266,8 +278,8 @@
1.89 /* Configure the environment for the thread, specifying the pager (and
1.90 exception handler plus region mapper). */
1.91
1.92 - l4_cap_idx_t rpager = _ipc_gate_cap;
1.93 - long err = _process.configure_thread(_ipc_gate, &rpager);
1.94 + l4_cap_idx_t mapped_pager = _ipc_gate_cap;
1.95 + long err = _process.configure_thread(_ipc_gate, &mapped_pager);
1.96
1.97 if (err)
1.98 return err;
1.99 @@ -282,13 +294,13 @@
1.100
1.101 /* Start the program thread in the appropriate stack. */
1.102
1.103 - l4_cap_idx_t thread, rthread;
1.104 - err = _process.thread_start(_program_payload->entry_point(), program_st, &thread, &rthread);
1.105 + l4_cap_idx_t thread, mapped_thread;
1.106 + err = _process.thread_start(_program_payload->entry_point(), program_st, &thread, &mapped_thread);
1.107
1.108 if (err)
1.109 return err;
1.110
1.111 - _exec_pager->add_thread(thread, rthread);
1.112 + _exec_pager->add_thread(thread, mapped_thread);
1.113 return L4_EOK;
1.114 }
1.115