1.1 --- a/libexec/lib/src/external_pager.cc Tue Feb 28 22:40:02 2023 +0100
1.2 +++ b/libexec/lib/src/external_pager.cc Fri Mar 03 18:15:38 2023 +0100
1.3 @@ -20,8 +20,10 @@
1.4 */
1.5
1.6 #include <l4/re/env.h>
1.7 +#include <l4/sys/task.h>
1.8 #include <l4/util/util.h>
1.9
1.10 +#include <ipc/cap_alloc.h>
1.11 #include <ipc/mem_ipc.h>
1.12 #include <mem/memory_utils.h>
1.13 #include <systypes/base.h>
1.14 @@ -46,9 +48,50 @@
1.15
1.16 ipc_server_default_config_type ExternalPager::config()
1.17 {
1.18 - return config_ParentPagerObject;
1.19 + return config_ParentPagerObject;
1.20 +}
1.21 +
1.22 +
1.23 +
1.24 +/* Close the pager. */
1.25 +
1.26 +void ExternalPager::close()
1.27 +{
1.28 + printf("Pager closing...\n");
1.29 +
1.30 + /* Unmap all regions. */
1.31 +
1.32 + MappedRegions::iterator it;
1.33 +
1.34 + for (it = _regions.begin(); it != _regions.end(); it++)
1.35 + {
1.36 + MappedRegion &r = it->second;
1.37 +
1.38 + ipc_detach_dataspace((void *) r.ds_start);
1.39 + }
1.40 }
1.41
1.42 +
1.43 +
1.44 +/* Manage the task and thread capabilities. */
1.45 +
1.46 +void ExternalPager::set_task(l4_cap_idx_t cap)
1.47 +{
1.48 + _task = cap;
1.49 +}
1.50 +
1.51 +void ExternalPager::set_server(l4_cap_idx_t cap)
1.52 +{
1.53 + _server = cap;
1.54 +}
1.55 +
1.56 +void ExternalPager::set_gate(l4_cap_idx_t cap)
1.57 +{
1.58 + _ipc_gate = cap;
1.59 +}
1.60 +
1.61 +
1.62 +
1.63 /* Handle a general exception. */
1.64
1.65 long ExternalPager::exception(l4_exc_regs_t regs, l4_snd_fpage_t *region)
1.66 @@ -165,15 +208,45 @@
1.67 return err;
1.68 }
1.69
1.70 +
1.71 +
1.72 /* Receive signals from a task. */
1.73
1.74 long ExternalPager::signal(unsigned long sig, unsigned long val)
1.75 {
1.76 notify_all(NOTIFY_TASK_SIGNAL, (notify_values_t) {sig, val});
1.77
1.78 + /* Handle the termination event. */
1.79 +
1.80 + if (sig == 0)
1.81 + {
1.82 + /* Once the program exits, the IPC gate connecting the program with its
1.83 + internal pager can be released. */
1.84 +
1.85 + if (l4_is_valid_cap(_ipc_gate))
1.86 + {
1.87 + l4_task_unmap(L4RE_THIS_TASK_CAP, l4_obj_fpage(_ipc_gate, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
1.88 + _ipc_gate = L4_INVALID_CAP;
1.89 + }
1.90 +
1.91 + /* Upon exit of the program's internal pager, release the capabilities
1.92 + associated with this server. */
1.93 +
1.94 + else if (l4_is_valid_cap(_task))
1.95 + {
1.96 + /* NOTE: Capability indexes to be obtained from the process creation
1.97 + activity. */
1.98 +
1.99 + l4_task_unmap(_task, l4_obj_fpage(0x13UL << L4_CAP_SHIFT, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
1.100 + l4_task_unmap(_task, l4_obj_fpage(0x19UL << L4_CAP_SHIFT, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
1.101 + }
1.102 + }
1.103 +
1.104 return L4_EOK;
1.105 }
1.106
1.107 +
1.108 +
1.109 /* Subscribe to notifications. */
1.110
1.111 long ExternalPager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)