# HG changeset patch # User Paul Boddie # Date 1677505573 -3600 # Node ID 7f5b80fdea592ca42cb6bd456089e6bfbc8d8d73 # Parent d9de8ecdaf6038c8d2d6a31d021a520ac588e143 Made the external pager a resource so that it can be managed more conveniently. diff -r d9de8ecdaf60 -r 7f5b80fdea59 libexec/include/exec/external_pager.h --- a/libexec/include/exec/external_pager.h Sun Feb 26 22:19:31 2023 +0100 +++ b/libexec/include/exec/external_pager.h Mon Feb 27 14:46:13 2023 +0100 @@ -23,6 +23,7 @@ #include #include +#include #include "notifier_interface.h" #include "parent_pager_object_interface.h" @@ -32,11 +33,18 @@ /* A simple system pager also acting as a region mapper. */ class ExternalPager : public ExecPager, public ParentPagerObject, - public NotificationSupport + public NotificationSupport, public Resource { public: explicit ExternalPager(address_t start = 0, address_t end = 0); + /* Server details. */ + + virtual ipc_server_default_config_type config(); + + virtual void *interface() + { return static_cast(this); } + /* Notification methods, implementing PagerObject. */ virtual long exception(l4_exc_regs_t regs, diff -r d9de8ecdaf60 -r 7f5b80fdea59 libexec/include/exec/process_creating.h --- a/libexec/include/exec/process_creating.h Sun Feb 26 22:19:31 2023 +0100 +++ b/libexec/include/exec/process_creating.h Mon Feb 27 14:46:13 2023 +0100 @@ -26,7 +26,6 @@ #include #include #include -#include @@ -40,7 +39,6 @@ /* External pager configuration. */ ExternalPager *_exec_pager = NULL; - ipc_server_config_type _config; /* Process construction. */ @@ -67,9 +65,9 @@ long init_program(file_t *file); - long init_external_pager(); + long init_external_pager(l4_cap_idx_t *pager); - long configure_task(); + long configure_task(l4_cap_idx_t pager); long create_ipc_gate(); @@ -77,7 +75,7 @@ struct ipc_mapped_cap *mapped_caps, struct exec_region &r, unsigned int &index); - long start_region_mapper(); + long start_region_mapper(l4_cap_idx_t pager); long start_program(int argc, const char *argv[]); diff -r d9de8ecdaf60 -r 7f5b80fdea59 libexec/lib/src/external_pager.cc --- a/libexec/lib/src/external_pager.cc Sun Feb 26 22:19:31 2023 +0100 +++ b/libexec/lib/src/external_pager.cc Mon Feb 27 14:46:13 2023 +0100 @@ -29,6 +29,7 @@ #include #include "external_pager.h" +#include "parent_pager_object_server.h" @@ -43,6 +44,11 @@ { } +ipc_server_default_config_type ExternalPager::config() +{ + return config_ParentPagerObject; +} + /* Handle a general exception. */ long ExternalPager::exception(l4_exc_regs_t regs, l4_snd_fpage_t *region) diff -r d9de8ecdaf60 -r 7f5b80fdea59 libexec/lib/src/process_creating.cc --- a/libexec/lib/src/process_creating.cc Sun Feb 26 22:19:31 2023 +0100 +++ b/libexec/lib/src/process_creating.cc Mon Feb 27 14:46:13 2023 +0100 @@ -21,15 +21,12 @@ #include +#include #include #include #include -#include -#include - -#include "parent_pager_object_server.h" #include "process_creating.h" @@ -49,26 +46,6 @@ { } -/* Start the system pager in a separate thread. */ - -long ProcessCreating::start_pager() -{ - pthread_t pager_thread; - pthread_attr_t attr; - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - ipc_server_init_for(&_config, ParentPagerObject, _exec_pager); - - long err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &_config); - - if (err) - return err; - - return ipc_server_start_config_thread(&_config, pthread_l4_cap(pager_thread)); -} - /* Initialise the memory segments of the region mapper. These are mapped into this task so that we may access them, allowing the external pager in this task to use them. */ @@ -102,7 +79,7 @@ constrained to an area of memory that must not overlap with the area reserved for the program being run. */ -long ProcessCreating::init_external_pager() +long ProcessCreating::init_external_pager(l4_cap_idx_t *pager) { _exec_pager = new ExternalPager(0, 10 * L4_PAGESIZE); @@ -120,19 +97,19 @@ /* Start the pager in a separate thread. */ - return start_pager(); + return ResourceServer(_exec_pager).start_thread(pager); } /* Configure the environment for the task. */ -long ProcessCreating::configure_task() +long ProcessCreating::configure_task(l4_cap_idx_t pager) { long err = _process.configure_task(); if (err) return err; - return _process.set_parent(_config.server); + return _process.set_parent(pager); } /* Create an unbound IPC gate for the region mapper and allocate it in the @@ -171,7 +148,7 @@ and of the associated capabilities, configure the region mapper thread, populate its stack, and start the thread. */ -long ProcessCreating::start_region_mapper() +long ProcessCreating::start_region_mapper(l4_cap_idx_t pager) { /* Define regions employing dataspaces to provide program segments. */ @@ -230,7 +207,7 @@ /* Configure the environment for the thread, specifying the pager (and exception handler plus region mapper). */ - long err = _process.configure_thread(_config.server); + long err = _process.configure_thread(pager); if (err) return err; @@ -296,11 +273,11 @@ if (err) return err; - err = init_external_pager(); + err = init_external_pager(process); if (err) return err; - err = configure_task(); + err = configure_task(*process); if (err) return err; @@ -308,7 +285,7 @@ if (err) return err; - err = start_region_mapper(); + err = start_region_mapper(*process); if (err) return err; @@ -316,8 +293,6 @@ if (err) return err; - *process = _config.server; - /* Discard instances created to initialise the process. NOTE: The region mapper payload could be retained instead of being reconstructed each time. */