# HG changeset patch # User Paul Boddie # Date 1678115144 -3600 # Node ID e4341cbc7e2a4dd0eeb297e0055418f32faf07c7 # Parent f1c4592015e304fb98cec211d969964cd8681eff Propagated the created task's own capability details to the pager so that it may be unmapped, thus destroying the created task. diff -r f1c4592015e3 -r e4341cbc7e2a libexec/include/exec/external_pager.h --- a/libexec/include/exec/external_pager.h Mon Mar 06 16:04:23 2023 +0100 +++ b/libexec/include/exec/external_pager.h Mon Mar 06 16:05:44 2023 +0100 @@ -38,7 +38,7 @@ public NotificationSupport, public Resource { protected: - l4_cap_idx_t _task, _ipc_gate, _parent, _rparent, _pager, _rpager; + l4_cap_idx_t _task, _rtask, _parent, _rparent, _pager, _rpager, _ipc_gate; std::vector _threads, _rthreads; public: @@ -57,7 +57,7 @@ virtual void set_gate(l4_cap_idx_t cap); virtual void set_pager(l4_cap_idx_t cap, l4_cap_idx_t rcap); virtual void set_parent(l4_cap_idx_t cap, l4_cap_idx_t rcap); - virtual void set_task(l4_cap_idx_t cap); + virtual void set_task(l4_cap_idx_t cap, l4_cap_idx_t rcap); /* Resource methods. */ diff -r f1c4592015e3 -r e4341cbc7e2a libexec/include/exec/process.h --- a/libexec/include/exec/process.h Mon Mar 06 16:04:23 2023 +0100 +++ b/libexec/include/exec/process.h Mon Mar 06 16:05:44 2023 +0100 @@ -91,12 +91,10 @@ l4_cap_idx_t allocate_cap(); - long configure_task(unsigned int threads = 2); + long configure_task(l4_cap_idx_t *task, l4_cap_idx_t *rtask, unsigned int threads = 2); long configure_thread(l4_cap_idx_t server, l4_cap_idx_t *mapped_cap = NULL); - l4_cap_idx_t get_task(); - long set_parent(l4_cap_idx_t parent, l4_cap_idx_t *rparent); long map_capabilities(struct ipc_mapped_cap mapped_caps[], diff -r f1c4592015e3 -r e4341cbc7e2a libexec/lib/src/external_pager.cc --- a/libexec/lib/src/external_pager.cc Mon Mar 06 16:04:23 2023 +0100 +++ b/libexec/lib/src/external_pager.cc Mon Mar 06 16:05:44 2023 +0100 @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -68,12 +69,14 @@ MappedRegion &r = it->second; ipc_detach_dataspace((void *) r.ds_start); - printf("Free %lx\n", r.ds); ipc_cap_free_um(r.ds); } + /* Remove the created task. */ + if (l4_is_valid_cap(_task)) { + ipc_unmap_capability(_task, _rtask); ipc_cap_free_um(_task); _task = L4_INVALID_CAP; } @@ -106,9 +109,10 @@ _rparent = rcap; } -void ExternalPager::set_task(l4_cap_idx_t cap) +void ExternalPager::set_task(l4_cap_idx_t cap, l4_cap_idx_t rcap) { _task = cap; + _rtask = rcap; } @@ -253,7 +257,7 @@ if (l4_is_valid_cap(_ipc_gate)) { - l4_task_unmap(L4RE_THIS_TASK_CAP, l4_obj_fpage(_ipc_gate, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); + ipc_cap_free_um(_ipc_gate); _ipc_gate = L4_INVALID_CAP; } @@ -262,17 +266,10 @@ else if (l4_is_valid_cap(_task)) { - /* NOTE: Capability indexes to be obtained from the process creation - activity. */ - - /* Log. */ - - l4_task_unmap(_task, l4_obj_fpage(0x05UL << L4_CAP_SHIFT, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); - /* Parent and pager/region mapper. */ - l4_task_unmap(_task, l4_obj_fpage(_rparent, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); - l4_task_unmap(_task, l4_obj_fpage(_rpager, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); + ipc_unmap_capability(_task, _rparent); + ipc_unmap_capability(_task, _rpager); /* Threads. For some reason, these cannot be released by the process, so they are also unmapped on its behalf. */ @@ -283,7 +280,7 @@ ipc_cap_free_um(*it); for (it = _rthreads.begin(); it != _rthreads.end(); it++) - l4_task_unmap(_task, l4_obj_fpage(*it, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); + ipc_unmap_capability(_task, *it); } } diff -r f1c4592015e3 -r e4341cbc7e2a libexec/lib/src/process.cc --- a/libexec/lib/src/process.cc Mon Mar 06 16:04:23 2023 +0100 +++ b/libexec/lib/src/process.cc Mon Mar 06 16:05:44 2023 +0100 @@ -107,16 +107,9 @@ return l4_error(l4_factory_create_thread(l4re_env()->factory, *thread)); } -/* Task access. */ - -l4_cap_idx_t Process::get_task() -{ - return _task; -} - /* Configure the task environment. */ -long Process::configure_task(unsigned int threads) +long Process::configure_task(l4_cap_idx_t *task, l4_cap_idx_t *rtask, unsigned int threads) { long err = create_task(threads); @@ -145,6 +138,11 @@ {0, L4_INVALID_CAP, 0, 0}, }; + /* Return the capability details for the task. */ + + *task = _task; + *rtask = L4_BASE_TASK_CAP; + return map_capabilities(mapped_caps, false); } diff -r f1c4592015e3 -r e4341cbc7e2a libexec/lib/src/process_creating.cc --- a/libexec/lib/src/process_creating.cc Mon Mar 06 16:04:23 2023 +0100 +++ b/libexec/lib/src/process_creating.cc Mon Mar 06 16:05:44 2023 +0100 @@ -109,12 +109,16 @@ long ProcessCreating::configure_task(l4_cap_idx_t pager) { - l4_cap_idx_t rparent; - long err = _process.configure_task(); + l4_cap_idx_t task, rtask; + long err = _process.configure_task(&task, &rtask); if (err) return err; + _exec_pager->set_task(task, rtask); + + l4_cap_idx_t rparent; + err = _process.set_parent(pager, &rparent); if (err) @@ -135,6 +139,7 @@ if (l4_is_invalid_cap(_ipc_gate)) return -L4_ENOMEM; + _exec_pager->set_gate(_ipc_gate); return l4_error(l4_factory_create_gate(l4re_env()->factory, _ipc_gate, L4_INVALID_CAP, 0)); } @@ -323,11 +328,6 @@ if (err) return err; - /* Note the task and IPC gate on the pager object. */ - - _exec_pager->set_task(_process.get_task()); - _exec_pager->set_gate(_ipc_gate); - /* Discard instances created to initialise the process. The region mapper relies on resources associated with its payload and stack and so these cannot be deleted immediately.