1.1 --- a/libexec/lib/src/process.cc Fri Jun 17 23:36:03 2022 +0200
1.2 +++ b/libexec/lib/src/process.cc Fri Jun 17 23:54:54 2022 +0200
1.3 @@ -132,12 +132,12 @@
1.4 /* Define capability mappings for the new task. */
1.5
1.6 struct ipc_mapped_cap mapped_caps[] = {
1.7 - {L4_BASE_TASK_CAP, _task, L4_CAP_FPAGE_RWS},
1.8 - {_env.factory, l4re_env()->factory, L4_CAP_FPAGE_RWS},
1.9 - {_env.log, l4re_env()->log, L4_CAP_FPAGE_RWS},
1.10 - {_env.scheduler, l4re_env()->scheduler, L4_CAP_FPAGE_RWS},
1.11 - {_env.mem_alloc, l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS},
1.12 - {0, L4_INVALID_CAP, 0},
1.13 + {L4_BASE_TASK_CAP, _task, L4_CAP_FPAGE_RWS, 0},
1.14 + {_env.factory, l4re_env()->factory, L4_CAP_FPAGE_RWS, 0},
1.15 + {_env.log, l4re_env()->log, L4_CAP_FPAGE_RWS, 0},
1.16 + {_env.scheduler, l4re_env()->scheduler, L4_CAP_FPAGE_RWS, 0},
1.17 + {_env.mem_alloc, l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS, 0},
1.18 + {0, L4_INVALID_CAP, 0, 0},
1.19 };
1.20
1.21 return map_capabilities(mapped_caps, false);
1.22 @@ -145,19 +145,21 @@
1.23
1.24 /* Configure the thread environment. */
1.25
1.26 -long Process::configure_thread(l4_cap_idx_t server)
1.27 +long Process::configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap)
1.28 {
1.29 /* Employ a distinct region mapper for each thread's environment, this acting
1.30 as pager. */
1.31
1.32 - _env.rm = allocate_cap();
1.33 -
1.34 - struct ipc_mapped_cap mapped_caps[] = {
1.35 - {_env.rm, server, L4_CAP_FPAGE_RWS},
1.36 - {0, L4_INVALID_CAP, 0},
1.37 - };
1.38 -
1.39 - return map_capabilities(mapped_caps, false);
1.40 + if (l4_is_valid_cap(mapped_cap))
1.41 + {
1.42 + _env.rm = mapped_cap;
1.43 + return L4_EOK;
1.44 + }
1.45 + else
1.46 + {
1.47 + _env.rm = allocate_cap();
1.48 + return ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.rm, server, L4_CAP_FPAGE_RWS, 0});
1.49 + }
1.50 }
1.51
1.52 /* Map capabilities into the task, counting them if indicated. */
1.53 @@ -205,13 +207,20 @@
1.54
1.55 _env.main_thread = allocate_cap();
1.56
1.57 - ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS});
1.58 + ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS, 0});
1.59
1.60 /* Populate the initial environment in the thread. */
1.61
1.62 st.set_l4re_aux(&_aux);
1.63 st.set_l4re_env(&_env);
1.64
1.65 + /* Reserve some extra space for capabilities used by this thread.
1.66 + NOTE: Surely the capability allocator should be able to avoid conflicts,
1.67 + but concurrency issues have been observed before, leading to various
1.68 + measures in libipc. */
1.69 +
1.70 + _env.first_free_cap += 0x20;
1.71 +
1.72 /* Set the start details. */
1.73
1.74 err = l4_error(l4_thread_ex_regs(thread, program_start, st.start_address(), 0));