L4Re/departure

Changeset

501:e4341cbc7e2a
2023-03-06 Paul Boddie raw files shortlog changelog graph Propagated the created task's own capability details to the pager so that it may be unmapped, thus destroying the created task.
libexec/include/exec/external_pager.h (file) libexec/include/exec/process.h (file) libexec/lib/src/external_pager.cc (file) libexec/lib/src/process.cc (file) libexec/lib/src/process_creating.cc (file)
     1.1 --- a/libexec/include/exec/external_pager.h	Mon Mar 06 16:04:23 2023 +0100
     1.2 +++ b/libexec/include/exec/external_pager.h	Mon Mar 06 16:05:44 2023 +0100
     1.3 @@ -38,7 +38,7 @@
     1.4                        public NotificationSupport, public Resource
     1.5  {
     1.6  protected:
     1.7 -  l4_cap_idx_t _task, _ipc_gate, _parent, _rparent, _pager, _rpager;
     1.8 +  l4_cap_idx_t _task, _rtask, _parent, _rparent, _pager, _rpager, _ipc_gate;
     1.9    std::vector<l4_cap_idx_t> _threads, _rthreads;
    1.10  
    1.11  public:
    1.12 @@ -57,7 +57,7 @@
    1.13    virtual void set_gate(l4_cap_idx_t cap);
    1.14    virtual void set_pager(l4_cap_idx_t cap, l4_cap_idx_t rcap);
    1.15    virtual void set_parent(l4_cap_idx_t cap, l4_cap_idx_t rcap);
    1.16 -  virtual void set_task(l4_cap_idx_t cap);
    1.17 +  virtual void set_task(l4_cap_idx_t cap, l4_cap_idx_t rcap);
    1.18  
    1.19    /* Resource methods. */
    1.20  
     2.1 --- a/libexec/include/exec/process.h	Mon Mar 06 16:04:23 2023 +0100
     2.2 +++ b/libexec/include/exec/process.h	Mon Mar 06 16:05:44 2023 +0100
     2.3 @@ -91,12 +91,10 @@
     2.4  
     2.5    l4_cap_idx_t allocate_cap();
     2.6  
     2.7 -  long configure_task(unsigned int threads = 2);
     2.8 +  long configure_task(l4_cap_idx_t *task, l4_cap_idx_t *rtask, unsigned int threads = 2);
     2.9  
    2.10    long configure_thread(l4_cap_idx_t server, l4_cap_idx_t *mapped_cap = NULL);
    2.11  
    2.12 -  l4_cap_idx_t get_task();
    2.13 -
    2.14    long set_parent(l4_cap_idx_t parent, l4_cap_idx_t *rparent);
    2.15  
    2.16    long map_capabilities(struct ipc_mapped_cap mapped_caps[],
     3.1 --- a/libexec/lib/src/external_pager.cc	Mon Mar 06 16:04:23 2023 +0100
     3.2 +++ b/libexec/lib/src/external_pager.cc	Mon Mar 06 16:05:44 2023 +0100
     3.3 @@ -24,6 +24,7 @@
     3.4  #include <l4/util/util.h>
     3.5  
     3.6  #include <ipc/cap_alloc.h>
     3.7 +#include <ipc/map.h>
     3.8  #include <ipc/mem_ipc.h>
     3.9  #include <mem/memory_utils.h>
    3.10  #include <systypes/base.h>
    3.11 @@ -68,12 +69,14 @@
    3.12      MappedRegion &r = it->second;
    3.13  
    3.14      ipc_detach_dataspace((void *) r.ds_start);
    3.15 -    printf("Free %lx\n", r.ds);
    3.16      ipc_cap_free_um(r.ds);
    3.17    }
    3.18  
    3.19 +  /* Remove the created task. */
    3.20 +
    3.21    if (l4_is_valid_cap(_task))
    3.22    {
    3.23 +    ipc_unmap_capability(_task, _rtask);
    3.24      ipc_cap_free_um(_task);
    3.25      _task = L4_INVALID_CAP;
    3.26    }
    3.27 @@ -106,9 +109,10 @@
    3.28    _rparent = rcap;
    3.29  }
    3.30  
    3.31 -void ExternalPager::set_task(l4_cap_idx_t cap)
    3.32 +void ExternalPager::set_task(l4_cap_idx_t cap, l4_cap_idx_t rcap)
    3.33  {
    3.34    _task = cap;
    3.35 +  _rtask = rcap;
    3.36  }
    3.37  
    3.38  
    3.39 @@ -253,7 +257,7 @@
    3.40  
    3.41      if (l4_is_valid_cap(_ipc_gate))
    3.42      {
    3.43 -      l4_task_unmap(L4RE_THIS_TASK_CAP, l4_obj_fpage(_ipc_gate, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
    3.44 +      ipc_cap_free_um(_ipc_gate);
    3.45        _ipc_gate = L4_INVALID_CAP;
    3.46      }
    3.47  
    3.48 @@ -262,17 +266,10 @@
    3.49  
    3.50      else if (l4_is_valid_cap(_task))
    3.51      {
    3.52 -      /* NOTE: Capability indexes to be obtained from the process creation
    3.53 -               activity. */
    3.54 -
    3.55 -      /* Log. */
    3.56 -
    3.57 -      l4_task_unmap(_task, l4_obj_fpage(0x05UL << L4_CAP_SHIFT, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
    3.58 -
    3.59        /* Parent and pager/region mapper. */
    3.60  
    3.61 -      l4_task_unmap(_task, l4_obj_fpage(_rparent, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
    3.62 -      l4_task_unmap(_task, l4_obj_fpage(_rpager, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
    3.63 +      ipc_unmap_capability(_task, _rparent);
    3.64 +      ipc_unmap_capability(_task, _rpager);
    3.65  
    3.66        /* Threads. For some reason, these cannot be released by the process, so
    3.67           they are also unmapped on its behalf. */
    3.68 @@ -283,7 +280,7 @@
    3.69          ipc_cap_free_um(*it);
    3.70  
    3.71        for (it = _rthreads.begin(); it != _rthreads.end(); it++)
    3.72 -        l4_task_unmap(_task, l4_obj_fpage(*it, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES);
    3.73 +        ipc_unmap_capability(_task, *it);
    3.74      }
    3.75    }
    3.76  
     4.1 --- a/libexec/lib/src/process.cc	Mon Mar 06 16:04:23 2023 +0100
     4.2 +++ b/libexec/lib/src/process.cc	Mon Mar 06 16:05:44 2023 +0100
     4.3 @@ -107,16 +107,9 @@
     4.4    return l4_error(l4_factory_create_thread(l4re_env()->factory, *thread));
     4.5  }
     4.6  
     4.7 -/* Task access. */
     4.8 -
     4.9 -l4_cap_idx_t Process::get_task()
    4.10 -{
    4.11 -  return _task;
    4.12 -}
    4.13 -
    4.14  /* Configure the task environment. */
    4.15  
    4.16 -long Process::configure_task(unsigned int threads)
    4.17 +long Process::configure_task(l4_cap_idx_t *task, l4_cap_idx_t *rtask, unsigned int threads)
    4.18  {
    4.19    long err = create_task(threads);
    4.20  
    4.21 @@ -145,6 +138,11 @@
    4.22      {0,                 L4_INVALID_CAP,         0,                0},
    4.23      };
    4.24  
    4.25 +  /* Return the capability details for the task. */
    4.26 +
    4.27 +  *task = _task;
    4.28 +  *rtask = L4_BASE_TASK_CAP;
    4.29 +
    4.30    return map_capabilities(mapped_caps, false);
    4.31  }
    4.32  
     5.1 --- a/libexec/lib/src/process_creating.cc	Mon Mar 06 16:04:23 2023 +0100
     5.2 +++ b/libexec/lib/src/process_creating.cc	Mon Mar 06 16:05:44 2023 +0100
     5.3 @@ -109,12 +109,16 @@
     5.4  
     5.5  long ProcessCreating::configure_task(l4_cap_idx_t pager)
     5.6  {
     5.7 -  l4_cap_idx_t rparent;
     5.8 -  long err = _process.configure_task();
     5.9 +  l4_cap_idx_t task, rtask;
    5.10 +  long err = _process.configure_task(&task, &rtask);
    5.11  
    5.12    if (err)
    5.13      return err;
    5.14  
    5.15 +  _exec_pager->set_task(task, rtask);
    5.16 +
    5.17 +  l4_cap_idx_t rparent;
    5.18 +
    5.19    err = _process.set_parent(pager, &rparent);
    5.20  
    5.21    if (err)
    5.22 @@ -135,6 +139,7 @@
    5.23    if (l4_is_invalid_cap(_ipc_gate))
    5.24      return -L4_ENOMEM;
    5.25  
    5.26 +  _exec_pager->set_gate(_ipc_gate);
    5.27    return l4_error(l4_factory_create_gate(l4re_env()->factory, _ipc_gate, L4_INVALID_CAP, 0));
    5.28  }
    5.29  
    5.30 @@ -323,11 +328,6 @@
    5.31    if (err)
    5.32      return err;
    5.33  
    5.34 -  /* Note the task and IPC gate on the pager object. */
    5.35 -
    5.36 -  _exec_pager->set_task(_process.get_task());
    5.37 -  _exec_pager->set_gate(_ipc_gate);
    5.38 -
    5.39    /* Discard instances created to initialise the process. The region mapper
    5.40       relies on resources associated with its payload and stack and so these
    5.41       cannot be deleted immediately.