1.1 --- a/libexec/include/exec/external_pager.h Sun Feb 26 22:19:31 2023 +0100
1.2 +++ b/libexec/include/exec/external_pager.h Mon Feb 27 14:46:13 2023 +0100
1.3 @@ -23,6 +23,7 @@
1.4
1.5 #include <exec/pager.h>
1.6 #include <fsserver/notification.h>
1.7 +#include <fsserver/resource.h>
1.8
1.9 #include "notifier_interface.h"
1.10 #include "parent_pager_object_interface.h"
1.11 @@ -32,11 +33,18 @@
1.12 /* A simple system pager also acting as a region mapper. */
1.13
1.14 class ExternalPager : public ExecPager, public ParentPagerObject,
1.15 - public NotificationSupport
1.16 + public NotificationSupport, public Resource
1.17 {
1.18 public:
1.19 explicit ExternalPager(address_t start = 0, address_t end = 0);
1.20
1.21 + /* Server details. */
1.22 +
1.23 + virtual ipc_server_default_config_type config();
1.24 +
1.25 + virtual void *interface()
1.26 + { return static_cast<ParentPagerObject *>(this); }
1.27 +
1.28 /* Notification methods, implementing PagerObject. */
1.29
1.30 virtual long exception(l4_exc_regs_t regs,
2.1 --- a/libexec/include/exec/process_creating.h Sun Feb 26 22:19:31 2023 +0100
2.2 +++ b/libexec/include/exec/process_creating.h Mon Feb 27 14:46:13 2023 +0100
2.3 @@ -26,7 +26,6 @@
2.4 #include <exec/memory.h>
2.5 #include <exec/process.h>
2.6 #include <ipc/map.h>
2.7 -#include <ipc/server.h>
2.8
2.9
2.10
2.11 @@ -40,7 +39,6 @@
2.12 /* External pager configuration. */
2.13
2.14 ExternalPager *_exec_pager = NULL;
2.15 - ipc_server_config_type _config;
2.16
2.17 /* Process construction. */
2.18
2.19 @@ -67,9 +65,9 @@
2.20
2.21 long init_program(file_t *file);
2.22
2.23 - long init_external_pager();
2.24 + long init_external_pager(l4_cap_idx_t *pager);
2.25
2.26 - long configure_task();
2.27 + long configure_task(l4_cap_idx_t pager);
2.28
2.29 long create_ipc_gate();
2.30
2.31 @@ -77,7 +75,7 @@
2.32 struct ipc_mapped_cap *mapped_caps,
2.33 struct exec_region &r, unsigned int &index);
2.34
2.35 - long start_region_mapper();
2.36 + long start_region_mapper(l4_cap_idx_t pager);
2.37
2.38 long start_program(int argc, const char *argv[]);
2.39
3.1 --- a/libexec/lib/src/external_pager.cc Sun Feb 26 22:19:31 2023 +0100
3.2 +++ b/libexec/lib/src/external_pager.cc Mon Feb 27 14:46:13 2023 +0100
3.3 @@ -29,6 +29,7 @@
3.4 #include <stdio.h>
3.5
3.6 #include "external_pager.h"
3.7 +#include "parent_pager_object_server.h"
3.8
3.9
3.10
3.11 @@ -43,6 +44,11 @@
3.12 {
3.13 }
3.14
3.15 +ipc_server_default_config_type ExternalPager::config()
3.16 +{
3.17 + return config_ParentPagerObject;
3.18 +}
3.19 +
3.20 /* Handle a general exception. */
3.21
3.22 long ExternalPager::exception(l4_exc_regs_t regs, l4_snd_fpage_t *region)
4.1 --- a/libexec/lib/src/process_creating.cc Sun Feb 26 22:19:31 2023 +0100
4.2 +++ b/libexec/lib/src/process_creating.cc Mon Feb 27 14:46:13 2023 +0100
4.3 @@ -21,15 +21,12 @@
4.4
4.5 #include <l4/re/env.h>
4.6
4.7 +#include <fsserver/resource_server.h>
4.8 #include <ipc/cap_alloc.h>
4.9 #include <ipc/map.h>
4.10
4.11 #include <stdio.h>
4.12
4.13 -#include <pthread-l4.h>
4.14 -#include <pthread.h>
4.15 -
4.16 -#include "parent_pager_object_server.h"
4.17 #include "process_creating.h"
4.18
4.19
4.20 @@ -49,26 +46,6 @@
4.21 {
4.22 }
4.23
4.24 -/* Start the system pager in a separate thread. */
4.25 -
4.26 -long ProcessCreating::start_pager()
4.27 -{
4.28 - pthread_t pager_thread;
4.29 - pthread_attr_t attr;
4.30 -
4.31 - pthread_attr_init(&attr);
4.32 - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
4.33 -
4.34 - ipc_server_init_for(&_config, ParentPagerObject, _exec_pager);
4.35 -
4.36 - long err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &_config);
4.37 -
4.38 - if (err)
4.39 - return err;
4.40 -
4.41 - return ipc_server_start_config_thread(&_config, pthread_l4_cap(pager_thread));
4.42 -}
4.43 -
4.44 /* Initialise the memory segments of the region mapper. These are mapped into
4.45 this task so that we may access them, allowing the external pager in this
4.46 task to use them. */
4.47 @@ -102,7 +79,7 @@
4.48 constrained to an area of memory that must not overlap with the area reserved
4.49 for the program being run. */
4.50
4.51 -long ProcessCreating::init_external_pager()
4.52 +long ProcessCreating::init_external_pager(l4_cap_idx_t *pager)
4.53 {
4.54 _exec_pager = new ExternalPager(0, 10 * L4_PAGESIZE);
4.55
4.56 @@ -120,19 +97,19 @@
4.57
4.58 /* Start the pager in a separate thread. */
4.59
4.60 - return start_pager();
4.61 + return ResourceServer(_exec_pager).start_thread(pager);
4.62 }
4.63
4.64 /* Configure the environment for the task. */
4.65
4.66 -long ProcessCreating::configure_task()
4.67 +long ProcessCreating::configure_task(l4_cap_idx_t pager)
4.68 {
4.69 long err = _process.configure_task();
4.70
4.71 if (err)
4.72 return err;
4.73
4.74 - return _process.set_parent(_config.server);
4.75 + return _process.set_parent(pager);
4.76 }
4.77
4.78 /* Create an unbound IPC gate for the region mapper and allocate it in the
4.79 @@ -171,7 +148,7 @@
4.80 and of the associated capabilities, configure the region mapper thread,
4.81 populate its stack, and start the thread. */
4.82
4.83 -long ProcessCreating::start_region_mapper()
4.84 +long ProcessCreating::start_region_mapper(l4_cap_idx_t pager)
4.85 {
4.86 /* Define regions employing dataspaces to provide program segments. */
4.87
4.88 @@ -230,7 +207,7 @@
4.89 /* Configure the environment for the thread, specifying the pager (and
4.90 exception handler plus region mapper). */
4.91
4.92 - long err = _process.configure_thread(_config.server);
4.93 + long err = _process.configure_thread(pager);
4.94
4.95 if (err)
4.96 return err;
4.97 @@ -296,11 +273,11 @@
4.98 if (err)
4.99 return err;
4.100
4.101 - err = init_external_pager();
4.102 + err = init_external_pager(process);
4.103 if (err)
4.104 return err;
4.105
4.106 - err = configure_task();
4.107 + err = configure_task(*process);
4.108 if (err)
4.109 return err;
4.110
4.111 @@ -308,7 +285,7 @@
4.112 if (err)
4.113 return err;
4.114
4.115 - err = start_region_mapper();
4.116 + err = start_region_mapper(*process);
4.117 if (err)
4.118 return err;
4.119
4.120 @@ -316,8 +293,6 @@
4.121 if (err)
4.122 return err;
4.123
4.124 - *process = _config.server;
4.125 -
4.126 /* Discard instances created to initialise the process.
4.127 NOTE: The region mapper payload could be retained instead of being
4.128 reconstructed each time. */