1.1 --- a/libexec/lib/src/process.cc Mon Jun 13 00:58:21 2022 +0200
1.2 +++ b/libexec/lib/src/process.cc Mon Jun 13 17:32:24 2022 +0200
1.3 @@ -61,15 +61,18 @@
1.4 /* Populate the common initial environment for the threads. */
1.5
1.6 _env.factory = L4_BASE_FACTORY_CAP;
1.7 - _env.main_thread = L4_BASE_THREAD_CAP;
1.8 _env.log = L4_BASE_LOG_CAP;
1.9 _env.scheduler = L4_BASE_SCHEDULER_CAP;
1.10 - _env.rm = L4_EXEC_RM_CAP;
1.11 _env.mem_alloc = L4_EXEC_MA_CAP;
1.12 - _env.first_free_cap = L4_EXEC_FIRST_FREE_CAP_INDEX;
1.13 _env.utcb_area = utcb_fpage;
1.14 _env.first_free_utcb = l4_fpage_memaddr(utcb_fpage) + reserved_threads * L4_UTCB_OFFSET;
1.15
1.16 + /* Capability details that are updated for each thread. */
1.17 +
1.18 + _env.main_thread = L4_BASE_THREAD_CAP;
1.19 + _env.rm = L4_EXEC_RM_CAP;
1.20 + _env.first_free_cap = L4_EXEC_FIRST_FREE_CAP_INDEX;
1.21 +
1.22 /* Populate auxiliary information. */
1.23
1.24 _aux.kip_ds = L4_EXEC_KIP_CAP;
1.25 @@ -77,6 +80,13 @@
1.26 _aux.ldr_flags = 0;
1.27 }
1.28
1.29 +/* Capability index allocation. */
1.30 +
1.31 +l4_cap_idx_t Process::allocate_cap()
1.32 +{
1.33 + return (_env.first_free_cap++ << L4_CAP_SHIFT);
1.34 +}
1.35 +
1.36 /* Task and thread initialisation. */
1.37
1.38 long Process::create_task()
1.39 @@ -137,8 +147,12 @@
1.40
1.41 long Process::configure_thread(l4_cap_idx_t server)
1.42 {
1.43 + /* Employ a distinct region mapper for each thread's environment, this acting
1.44 + as pager. */
1.45 +
1.46 + _env.rm = allocate_cap();
1.47 +
1.48 struct ipc_mapped_cap mapped_caps[] = {
1.49 - {L4_EXEC_PAGER_CAP, server, L4_CAP_FPAGE_RWS},
1.50 {_env.rm, server, L4_CAP_FPAGE_RWS},
1.51 {0, L4_INVALID_CAP, 0},
1.52 };
1.53 @@ -151,7 +165,13 @@
1.54 long Process::map_capabilities(struct ipc_mapped_cap mapped_caps[],
1.55 bool to_count)
1.56 {
1.57 - return ipc_map_capabilities(_task, mapped_caps, to_count ? &_num_mapped_caps : NULL);
1.58 + unsigned int num_mapped_caps;
1.59 + long err = ipc_map_capabilities(_task, mapped_caps, to_count ? &num_mapped_caps : NULL);
1.60 +
1.61 + if (to_count)
1.62 + _env.first_free_cap += num_mapped_caps;
1.63 +
1.64 + return err;
1.65 }
1.66
1.67 /* Create, initialise and start a thread. */
1.68 @@ -169,8 +189,8 @@
1.69 /* Initialise the thread with pager, UTCB and task details. */
1.70
1.71 l4_thread_control_start();
1.72 - l4_thread_control_pager(L4_EXEC_PAGER_CAP);
1.73 - l4_thread_control_exc_handler(L4_EXEC_PAGER_CAP);
1.74 + l4_thread_control_pager(_env.rm);
1.75 + l4_thread_control_exc_handler(_env.rm);
1.76 l4_thread_control_bind((l4_utcb_t *) _utcb_start, _task);
1.77
1.78 err = l4_error(l4_thread_control_commit(thread));
1.79 @@ -181,14 +201,12 @@
1.80 return err;
1.81 }
1.82
1.83 - /* Map the thread capability to the task. */
1.84 + /* Map the thread capability to the task using a distinct capability index. */
1.85 +
1.86 + _env.main_thread = allocate_cap();
1.87
1.88 ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS});
1.89
1.90 - /* Update the environment for any mapped capabilities. */
1.91 -
1.92 - _env.first_free_cap = L4_EXEC_FIRST_FREE_CAP_INDEX + _num_mapped_caps;
1.93 -
1.94 /* Populate the initial environment in the thread. */
1.95
1.96 st.set_l4re_aux(&_aux);