# HG changeset patch # User Paul Boddie # Date 1677868173 -3600 # Node ID 360bebaf5edd3a4827c3bd066da1e376bf49bde1 # Parent dbed58b9eb942e31f6fff4e1ffbb691720d7814f Support same-thread resource finalisation, making InternalPager a resource. diff -r dbed58b9eb94 -r 360bebaf5edd libexec/include/exec/internal_pager.h --- a/libexec/include/exec/internal_pager.h Fri Mar 03 18:15:38 2023 +0100 +++ b/libexec/include/exec/internal_pager.h Fri Mar 03 19:29:33 2023 +0100 @@ -1,7 +1,7 @@ /* * A system pager implementation residing in the same task as a program. * - * Copyright (C) 2022 Paul Boddie + * Copyright (C) 2022, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -22,6 +22,7 @@ #pragma once #include +#include #include "pager_object_interface.h" @@ -29,11 +30,18 @@ /* A simple system pager also acting as a region mapper. */ -class InternalPager : public ExecPager, public PagerObject +class InternalPager : public ExecPager, public PagerObject, public Resource { public: explicit InternalPager(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 dbed58b9eb94 -r 360bebaf5edd libexec/lib/src/external_pager.cc --- a/libexec/lib/src/external_pager.cc Fri Mar 03 18:15:38 2023 +0100 +++ b/libexec/lib/src/external_pager.cc Fri Mar 03 19:29:33 2023 +0100 @@ -237,6 +237,8 @@ /* NOTE: Capability indexes to be obtained from the process creation activity. */ + /* Parent and pager/region mapper. */ + l4_task_unmap(_task, l4_obj_fpage(0x13UL << L4_CAP_SHIFT, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); l4_task_unmap(_task, l4_obj_fpage(0x19UL << L4_CAP_SHIFT, 0, L4_CAP_FPAGE_RWSD), L4_FP_ALL_SPACES); } diff -r dbed58b9eb94 -r 360bebaf5edd libexec/lib/src/internal_pager.cc --- a/libexec/lib/src/internal_pager.cc Fri Mar 03 18:15:38 2023 +0100 +++ b/libexec/lib/src/internal_pager.cc Fri Mar 03 19:29:33 2023 +0100 @@ -30,6 +30,7 @@ #include "dataspace_client.h" #include "internal_pager.h" +#include "pager_object_server.h" @@ -44,6 +45,13 @@ { } +ipc_server_default_config_type InternalPager::config() +{ + return config_PagerObject; +} + + + /* Handle a general exception. */ long InternalPager::exception(l4_exc_regs_t regs, l4_snd_fpage_t *region) diff -r dbed58b9eb94 -r 360bebaf5edd libexec/rm/region_mapper.cc --- a/libexec/rm/region_mapper.cc Fri Mar 03 18:15:38 2023 +0100 +++ b/libexec/rm/region_mapper.cc Fri Mar 03 19:29:33 2023 +0100 @@ -20,13 +20,12 @@ */ #include +#include #include #include #include -#include - -#include "pager_object_server.h" +#include @@ -65,20 +64,23 @@ /* Start the pager. */ - printf("Starting pager...\n"); + printf("Initialising pager...\n"); printf("Pager capability: %lx\n", l4re_env_get_cap("server")); printf("Main thread: %lx\n", l4re_env()->main_thread); /* Initialise the server, enabling notifications. */ - ipc_server_config_type config; - ipc_server_init_for(&config, PagerObject, &exec_pager); - config.notifications = 1; + ResourceServer server(&exec_pager); + long err = server.bind("server"); - /* Bind to the named capability and serve until the IPC gate is released. */ + if (err) + { + printf("Could not bind server: %s\n", l4sys_errtostr(err)); + return 1; + } - ipc_server_bind("server", (l4_umword_t) &config, &config.server); - ipc_server_start_config(&config); + printf("Starting pager...\n"); + server.start(true); printf("Ending pager...\n"); return 0; diff -r dbed58b9eb94 -r 360bebaf5edd libfsserver/include/fsserver/resource_server.h --- a/libfsserver/include/fsserver/resource_server.h Fri Mar 03 18:15:38 2023 +0100 +++ b/libfsserver/include/fsserver/resource_server.h Fri Mar 03 19:29:33 2023 +0100 @@ -1,7 +1,7 @@ /* * Common resource server functions. * - * Copyright (C) 2018, 2019, 2020, 2021 Paul Boddie + * Copyright (C) 2018, 2019, 2020, 2021, 2023 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -53,7 +53,7 @@ /* Server initiation. */ - long start(); + long start(bool finalisation = false); long start_thread(); @@ -75,6 +75,8 @@ /* Server finalisation. */ +void resource_same_thread_finaliser(ipc_server_config_type *config); + void resource_thread_finaliser(ipc_server_config_type *config); // vim: tabstop=2 expandtab shiftwidth=2 diff -r dbed58b9eb94 -r 360bebaf5edd libfsserver/lib/generic/resource_server.cc --- a/libfsserver/lib/generic/resource_server.cc Fri Mar 03 18:15:38 2023 +0100 +++ b/libfsserver/lib/generic/resource_server.cc Fri Mar 03 19:29:33 2023 +0100 @@ -37,12 +37,20 @@ return ipc_server_bind(name, (l4_umword_t) _config, &_config->server); } -/* Start in the same thread with no deletion notifications or finalisation. */ +/* Start in the same thread indicating whether deletion notifications and + finalisation are to be used. */ -long ResourceServer::start() +long ResourceServer::start(bool finalisation) { resource_init_config(_config, _resource); _config->thread = pthread_l4_cap(pthread_self()); + + if (finalisation) + { + _config->finaliser = resource_same_thread_finaliser; + _config->notifications = 1; + } + return resource_start_config(_config, _resource); } @@ -126,7 +134,24 @@ -/* A finaliser for exposed resources. */ +/* A finaliser for exposed resources in the same thread. */ + +void resource_same_thread_finaliser(ipc_server_config_type *config) +{ + Resource *resource = reinterpret_cast(config->finaliser_obj); + + /* Close but do not delete the resource since it is assumed that it is being + managed by the thread. */ + + resource->close(); + + /* Release the capabilities. */ + + ipc_server_finalise_config(config); + delete config; +} + +/* A finaliser for exposed resources in a different thread. */ void resource_thread_finaliser(ipc_server_config_type *config) {