# HG changeset patch # User Paul Boddie # Date 1670947551 -3600 # Node ID 89b9c10db829a778393c3a1c3e403114d3b973a8 # Parent e9a1fb8dc4a1d48119e832334ead4ae9d33ece76 Added experimental support for program termination handling. diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/include/exec/external_pager.h --- a/libexec/include/exec/external_pager.h Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/include/exec/external_pager.h Tue Dec 13 17:05:51 2022 +0100 @@ -23,11 +23,13 @@ #include +#include "parent_pager_object_interface.h" + /* A simple system pager also acting as a region mapper. */ -class ExternalPager : public ExecPager +class ExternalPager : public ExecPager, public ParentPagerObject { public: explicit ExternalPager(address_t start = 0, address_t end = 0); @@ -44,6 +46,10 @@ virtual long attach(address_t *start, address_t size, map_flags_t flags, l4_cap_idx_t ds, address_t offset, unsigned char align); + + /* Parent methods. */ + + virtual long signal(unsigned long sig, unsigned long val); }; /* vim: tabstop=2 expandtab shiftwidth=2 diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/include/exec/internal_pager.h --- a/libexec/include/exec/internal_pager.h Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/include/exec/internal_pager.h Tue Dec 13 17:05:51 2022 +0100 @@ -23,11 +23,13 @@ #include +#include "pager_object_interface.h" + /* A simple system pager also acting as a region mapper. */ -class InternalPager : public ExecPager +class InternalPager : public ExecPager, public PagerObject { public: explicit InternalPager(address_t start = 0, address_t end = 0); diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/include/exec/pager.h --- a/libexec/include/exec/pager.h Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/include/exec/pager.h Tue Dec 13 17:05:51 2022 +0100 @@ -25,8 +25,6 @@ #include -#include "pager_object_interface.h" - /* Collection types. */ @@ -37,7 +35,7 @@ /* A simple system pager also acting as a region mapper. */ -class ExecPager : public PagerObject +class ExecPager { protected: address_t _start, _end; diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/include/exec/process.h --- a/libexec/include/exec/process.h Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/include/exec/process.h Tue Dec 13 17:05:51 2022 +0100 @@ -50,10 +50,11 @@ enum exec_task_caps { - L4_EXEC_PAGER_CAP = 0x10UL << L4_CAP_SHIFT, - L4_EXEC_RM_CAP = 0x11UL << L4_CAP_SHIFT, - L4_EXEC_MA_CAP = 0x12UL << L4_CAP_SHIFT, - L4_EXEC_KIP_CAP = 0x14UL << L4_CAP_SHIFT, + L4_EXEC_PAGER_CAP = 0x10UL << L4_CAP_SHIFT, + L4_EXEC_RM_CAP = 0x11UL << L4_CAP_SHIFT, + L4_EXEC_MA_CAP = 0x12UL << L4_CAP_SHIFT, + L4_EXEC_PARENT_CAP = 0x13UL << L4_CAP_SHIFT, + L4_EXEC_KIP_CAP = 0x14UL << L4_CAP_SHIFT, }; /* The default first free capability index must follow those above. Any @@ -94,6 +95,8 @@ long configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap = L4_INVALID_CAP); + long set_parent(l4_cap_idx_t server); + long map_capabilities(struct ipc_mapped_cap mapped_caps[], bool to_count = true); diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/lib/src/Makefile --- a/libexec/lib/src/Makefile Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/lib/src/Makefile Tue Dec 13 17:05:51 2022 +0100 @@ -17,7 +17,7 @@ CLIENT_INTERFACES_CC = dataspace mapped_file -SERVER_INTERFACES_CC = pager_object +SERVER_INTERFACES_CC = pager_object parent_pager_object # Generated and plain source files. diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/lib/src/external_pager.cc --- a/libexec/lib/src/external_pager.cc Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/lib/src/external_pager.cc Tue Dec 13 17:05:51 2022 +0100 @@ -131,7 +131,7 @@ l4_cap_idx_t ds, address_t offset, unsigned char align) { - long err = find(start, &size, flags, offset, align); + long err = ExecPager::find(start, &size, flags, offset, align); if (!err) { @@ -155,5 +155,13 @@ return err; } +/* Receive signals from a task. */ + +long ExternalPager::signal(unsigned long sig, unsigned long val) +{ + printf("Signal %ld with value %ld received.\n", sig, val); + return L4_EOK; +} + /* vim: tabstop=2 expandtab shiftwidth=2 */ diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/lib/src/internal_pager.cc --- a/libexec/lib/src/internal_pager.cc Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/lib/src/internal_pager.cc Tue Dec 13 17:05:51 2022 +0100 @@ -21,6 +21,7 @@ #include #include +#include #include @@ -131,7 +132,7 @@ l4_cap_idx_t ds, address_t offset, unsigned char align) { - long err = find(start, &size, flags, offset, align); + long err = ExecPager::find(start, &size, flags, offset, align); if (!err) { diff -r e9a1fb8dc4a1 -r 89b9c10db829 libexec/lib/src/process.cc --- a/libexec/lib/src/process.cc Sun Dec 11 01:23:05 2022 +0100 +++ b/libexec/lib/src/process.cc Tue Dec 13 17:05:51 2022 +0100 @@ -62,8 +62,10 @@ _env.log = L4_BASE_LOG_CAP; _env.scheduler = L4_BASE_SCHEDULER_CAP; _env.mem_alloc = L4_EXEC_MA_CAP; + _env.parent = L4_EXEC_PARENT_CAP; - /* Capability details that are updated for each thread. */ + /* Capability details that are updated for each thread. Note that the region + mapper is redefined, but it would traditionally employ the given index. */ _env.main_thread = L4_BASE_THREAD_CAP; _env.rm = L4_EXEC_RM_CAP; @@ -139,7 +141,8 @@ return map_capabilities(mapped_caps, false); } -/* Configure the thread environment. */ +/* Configure the thread environment, employing the given server as the region + mapper. */ long Process::configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap) { @@ -158,6 +161,13 @@ } } +/* Set the parent of the new thread. */ + +long Process::set_parent(l4_cap_idx_t server) +{ + return ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.parent, server, L4_CAP_FPAGE_RWS, 0}); +} + /* Map capabilities into the task, counting them if indicated. */ long Process::map_capabilities(struct ipc_mapped_cap mapped_caps[], diff -r e9a1fb8dc4a1 -r 89b9c10db829 libsystypes/idl/parent.idl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsystypes/idl/parent.idl Tue Dec 13 17:05:51 2022 +0100 @@ -0,0 +1,9 @@ +#include /* L4RE_PROTO_PARENT */ + +[protocol(L4RE_PROTO_PARENT)] +interface Parent +{ + /* Receive a signal from a task. */ + + [opcode(0)] void signal(in unsigned long sig, in unsigned long val); +}; diff -r e9a1fb8dc4a1 -r 89b9c10db829 libsystypes/idl/parent_pager_object.idl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsystypes/idl/parent_pager_object.idl Tue Dec 13 17:05:51 2022 +0100 @@ -0,0 +1,4 @@ +import "pager_object.idl"; +import "parent.idl"; + +interface ParentPagerObject composes Parent, PagerObject; diff -r e9a1fb8dc4a1 -r 89b9c10db829 tests/Makefile --- a/tests/Makefile Sun Dec 11 01:23:05 2022 +0100 +++ b/tests/Makefile Tue Dec 13 17:05:51 2022 +0100 @@ -34,7 +34,7 @@ CLIENT_INTERFACES_CC = dataspace -SERVER_INTERFACES_CC = pager_object +SERVER_INTERFACES_CC = pager_object parent_pager_object # Generated and plain source files. diff -r e9a1fb8dc4a1 -r 89b9c10db829 tests/dstest_exec.cc --- a/tests/dstest_exec.cc Sun Dec 11 01:23:05 2022 +0100 +++ b/tests/dstest_exec.cc Tue Dec 13 17:05:51 2022 +0100 @@ -36,7 +36,7 @@ #include #include -#include "pager_object_server.h" +#include "parent_pager_object_server.h" @@ -61,7 +61,7 @@ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - ipc_server_init_for(&config, PagerObject, &exec_pager); + ipc_server_init_for(&config, ParentPagerObject, &exec_pager); long err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config); @@ -172,6 +172,14 @@ return 1; } + err = process.set_parent(config.server); + + if (err) + { + printf("Could not map parent to task for internal pager.\n"); + return 1; + } + /* Create an unbound IPC gate for the region mapper. */ l4_cap_idx_t ipc_gate = ipc_cap_alloc(); @@ -297,6 +305,14 @@ return 1; } + err = process.set_parent(config.server); + + if (err) + { + printf("Could not map parent to task for payload.\n"); + return 1; + } + /* Populate a thread stack with argument and environment details for the actual program. The server capability should be assigned to the region mapper capability slot already. */