# HG changeset patch # User Paul Boddie # Date 1655502894 -7200 # Node ID df0cdda397075bbe2e554daaaf34dd97478c3f32 # Parent e0fef4c35263d7564c22244afa9dde4ba8132de9 Introduced a region mapper thread alongside the actual program to be run in a new task, with the region mapper being moved from the test files into libexec. The region mapper needs to reside in a different area of memory, with a special Makefile definition being employed to indicate this. Various adjustments to the task and thread initialisation mechanisms were required, along with fixes to the program regions provided to the region mapper thread (these having been erroneously specified using the region mapper's own segments). A more flexible method of allocating capability slots to the threads in the new task was introduced, and the mapped IPC gate capability (used by the region mapper to provide its service to the program) also needed a special control right, necessitating the expansion of the mapped capability structure. For performance, more pages are allocated to the ext2 filesystem server. One troublesome issue arose with regard to the first free capability setting and possible capability slot conflicts, necessitating a special adjustment of this setting so that the region mapper and actual program may start without the apparent loss of capabilities, this having been seen to affect the external pager. diff -r e0fef4c35263 -r df0cdda39707 conf/dstest_exec.cfg --- a/conf/dstest_exec.cfg Fri Jun 17 23:36:03 2022 +0200 +++ b/conf/dstest_exec.cfg Fri Jun 17 23:54:54 2022 +0200 @@ -34,7 +34,7 @@ }, log = { "ext2svr", "y" }, }, - "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr"); + "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "20", "ext2svr"); -- Obtain user filesystems with umask 0022 (18). @@ -47,4 +47,4 @@ }, log = { "client", "g" }, }, - "rom/dstest_exec", "home/paulb/dstest_region_mapper", "home/paulb/dstest_exec_payload", "hello", "world"); + "rom/dstest_exec", "home/paulb/exec_region_mapper", "home/paulb/dstest_exec_payload", "hello", "world"); diff -r e0fef4c35263 -r df0cdda39707 libexec/Makefile --- a/libexec/Makefile Fri Jun 17 23:36:03 2022 +0200 +++ b/libexec/Makefile Fri Jun 17 23:54:54 2022 +0200 @@ -1,4 +1,10 @@ PKGDIR ?= . L4DIR ?= $(PKGDIR)/../../.. +TARGET = include lib rm + include $(L4DIR)/mk/subdir.mk + +# Internal dependencies. + +rm: lib diff -r e0fef4c35263 -r df0cdda39707 libexec/include/exec/process.h --- a/libexec/include/exec/process.h Fri Jun 17 23:36:03 2022 +0200 +++ b/libexec/include/exec/process.h Fri Jun 17 23:54:54 2022 +0200 @@ -95,7 +95,7 @@ long configure_task(); - long configure_thread(l4_cap_idx_t server); + long configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap = L4_INVALID_CAP); long map_capabilities(struct ipc_mapped_cap mapped_caps[], bool to_count = true); diff -r e0fef4c35263 -r df0cdda39707 libexec/lib/src/external_pager.cc --- a/libexec/lib/src/external_pager.cc Fri Jun 17 23:36:03 2022 +0200 +++ b/libexec/lib/src/external_pager.cc Fri Jun 17 23:54:54 2022 +0200 @@ -75,6 +75,9 @@ printf("fs_base = %lx\n", regs.fs_base); printf("gs_base = %lx\n", regs.gs_base); + while (1) + l4_sleep_forever(); + return L4_EOK; } @@ -105,17 +108,22 @@ if ((addr >= r.map_start) && (addr < r.map_start + r.size)) { l4_addr_t page_addr = trunc(addr, L4_PAGESIZE); + map_flags_t map_flags = (flags & 4 ? L4RE_DS_F_RX : 0) | (flags & 2 ? L4RE_DS_F_W : 0) | (flags & 1 ? L4RE_DS_F_R : 0); - region->fpage = l4_fpage(r.start + (page_addr - r.map_start), L4_PAGESHIFT, r.flags); + if (!map_flags) + map_flags = L4RE_DS_F_R; + + region->fpage = l4_fpage(r.start + (page_addr - r.map_start), L4_PAGESHIFT, map_flags & r.flags); region->snd_base = page_addr; #if DEBUG - printf("%lx...%lx from %lx...%lx offset %lx size %d rights %x\n", + printf("%lx...%lx from %lx...%lx offset %lx size %d rights %x ds %lx\n", r.map_start, region->snd_base, r.start, l4_fpage_memaddr(region->fpage), addr - r.map_start, l4_fpage_size(region->fpage), - l4_fpage_rights(region->fpage)); + l4_fpage_rights(region->fpage), + r.ds); printf("%lx -> ", addr); @@ -228,10 +236,10 @@ l4_touch_rw((const void *) ds_start, size); #if DEBUG - printf("-> added region for %lx size %ld (%d)\n", region_start, region_size, page_order(region_size)); + printf("-> added region at %lx size %ld (%d) from %lx ds %lx\n", region_start, region_size, page_order(region_size), ds_start, ds); #endif - MappedRegion r(ds_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, region_start); + MappedRegion r(ds_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, region_start, ds); add(r); diff -r e0fef4c35263 -r df0cdda39707 libexec/lib/src/internal_pager.cc --- a/libexec/lib/src/internal_pager.cc Fri Jun 17 23:36:03 2022 +0200 +++ b/libexec/lib/src/internal_pager.cc Fri Jun 17 23:54:54 2022 +0200 @@ -76,6 +76,9 @@ printf("fs_base = %lx\n", regs.fs_base); printf("gs_base = %lx\n", regs.gs_base); + while (1) + l4_sleep_forever(); + return L4_EOK; } @@ -105,19 +108,36 @@ if ((addr >= r.start) && (addr < r.start + r.size)) { - l4_addr_t page_addr = trunc(addr, L4_PAGESIZE); + offset_t window_size = L4_PAGESIZE; + address_t window_base = trunc(addr, window_size); + offset_t offset = addr - r.start; + address_t page_addr = trunc(addr, L4_PAGESIZE); + address_t hot_spot = page_addr - window_base; /* Interact with the region's dataspace, specifying a receive window for a map operation. Here, a single page is specified. */ client_Dataspace dataspace(r.ds); - l4_snd_fpage_t region = {0, l4_fpage(page_addr, L4_PAGESHIFT, 0)}; + l4_snd_fpage_t rw_region = {0, l4_fpage(window_base, L4_PAGESHIFT, 0)}; + map_flags_t map_flags = (flags & 4 ? L4RE_DS_F_RX : 0) | (flags & 2 ? L4RE_DS_F_W : 0) | (flags & 1 ? L4RE_DS_F_R : 0); + + if (!map_flags) + map_flags = L4RE_DS_F_R; #if DEBUG - printf("region = {%lx, {%lx, %d}}\n", region.snd_base, l4_fpage_memaddr(region.fpage), l4_fpage_size(region.fpage)); + printf("window_base = %lx; window_size = %lx\n", window_base, window_size); + printf("region = {%lx, {%lx, %d}}\n", rw_region.snd_base, l4_fpage_memaddr(rw_region.fpage), l4_fpage_size(rw_region.fpage)); + printf("map(%lx, %lx, %lx) -> %lx\n", offset, hot_spot, map_flags, r.ds); #endif - return dataspace.map(0, 0, L4_FPAGE_RO, ®ion); + long err = dataspace.map(offset, hot_spot, map_flags & r.flags, &rw_region); + + /* Indicate an unspecified result, since the mapping should have taken + place. */ + + *region = {0, l4_fpage_invalid()}; + + return err; } #if DEBUG @@ -201,7 +221,7 @@ } #if DEBUG - printf("-> added region for %lx size %ld (%d)\n", region_start, region_size, page_order(region_size)); + printf("-> added region at %lx size %ld (%d) ds %lx\n", region_start, region_size, page_order(region_size), ds); #endif ExecRegion r = (ExecRegion) {region_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, ds}; diff -r e0fef4c35263 -r df0cdda39707 libexec/lib/src/process.cc --- a/libexec/lib/src/process.cc Fri Jun 17 23:36:03 2022 +0200 +++ b/libexec/lib/src/process.cc Fri Jun 17 23:54:54 2022 +0200 @@ -132,12 +132,12 @@ /* Define capability mappings for the new task. */ struct ipc_mapped_cap mapped_caps[] = { - {L4_BASE_TASK_CAP, _task, L4_CAP_FPAGE_RWS}, - {_env.factory, l4re_env()->factory, L4_CAP_FPAGE_RWS}, - {_env.log, l4re_env()->log, L4_CAP_FPAGE_RWS}, - {_env.scheduler, l4re_env()->scheduler, L4_CAP_FPAGE_RWS}, - {_env.mem_alloc, l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS}, - {0, L4_INVALID_CAP, 0}, + {L4_BASE_TASK_CAP, _task, L4_CAP_FPAGE_RWS, 0}, + {_env.factory, l4re_env()->factory, L4_CAP_FPAGE_RWS, 0}, + {_env.log, l4re_env()->log, L4_CAP_FPAGE_RWS, 0}, + {_env.scheduler, l4re_env()->scheduler, L4_CAP_FPAGE_RWS, 0}, + {_env.mem_alloc, l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS, 0}, + {0, L4_INVALID_CAP, 0, 0}, }; return map_capabilities(mapped_caps, false); @@ -145,19 +145,21 @@ /* Configure the thread environment. */ -long Process::configure_thread(l4_cap_idx_t server) +long Process::configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap) { /* Employ a distinct region mapper for each thread's environment, this acting as pager. */ - _env.rm = allocate_cap(); - - struct ipc_mapped_cap mapped_caps[] = { - {_env.rm, server, L4_CAP_FPAGE_RWS}, - {0, L4_INVALID_CAP, 0}, - }; - - return map_capabilities(mapped_caps, false); + if (l4_is_valid_cap(mapped_cap)) + { + _env.rm = mapped_cap; + return L4_EOK; + } + else + { + _env.rm = allocate_cap(); + return ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.rm, server, L4_CAP_FPAGE_RWS, 0}); + } } /* Map capabilities into the task, counting them if indicated. */ @@ -205,13 +207,20 @@ _env.main_thread = allocate_cap(); - ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS}); + ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS, 0}); /* Populate the initial environment in the thread. */ st.set_l4re_aux(&_aux); st.set_l4re_env(&_env); + /* Reserve some extra space for capabilities used by this thread. + NOTE: Surely the capability allocator should be able to avoid conflicts, + but concurrency issues have been observed before, leading to various + measures in libipc. */ + + _env.first_free_cap += 0x20; + /* Set the start details. */ err = l4_error(l4_thread_ex_regs(thread, program_start, st.start_address(), 0)); diff -r e0fef4c35263 -r df0cdda39707 libexec/lib/src/segment.cc --- a/libexec/lib/src/segment.cc Fri Jun 17 23:36:03 2022 +0200 +++ b/libexec/lib/src/segment.cc Fri Jun 17 23:54:54 2022 +0200 @@ -121,7 +121,7 @@ MappedRegion &Segment::region() { - _region = MappedRegion((l4_addr_t) _buf, _region_allocated_size, region_flags(), _region_base); + _region = MappedRegion((l4_addr_t) _buf, _region_allocated_size, region_flags(), _region_base, _ds); return _region; } diff -r e0fef4c35263 -r df0cdda39707 libexec/rm/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libexec/rm/Makefile Fri Jun 17 23:54:54 2022 +0200 @@ -0,0 +1,52 @@ +PKGDIR ?= .. +L4DIR ?= $(PKGDIR)/../../.. + +TARGET = exec_region_mapper + +MODE = static + +# Relocate the binary to avoid conflicting with actual payloads. + +DEFAULT_RELOC_x86 := 0xb0000000 +DEFAULT_RELOC_arm := 0xb0000000 +DEFAULT_RELOC_arm64 := 0xc0000000 +DEFAULT_RELOC_ppc32 := 0xb0000000 +DEFAULT_RELOC_amd64 := 0x70000000 +DEFAULT_RELOC_mips := 0x70000000 + +# Locations for interface input and generated output. + +IDL_DIR = $(PKGDIR)/../libsystypes/idl +IDL_MK_DIR = $(L4DIR)/idl4re/mk +IDL_BUILD_DIR = . +IDL_EXPORT_DIR = . + +include $(IDL_MK_DIR)/idl.mk + +# Compound interfaces. + +pager_object_NAME = PagerObject +pager_object_INTERFACES = region_mapper system_pager + +COMP_INTERFACES_CC = pager_object + +# Individual interfaces. + +SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC)) + +# Generated and plain source files. + +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC)) + +# Normal source files. + +PLAIN_SRC_CC = region_mapper.cc +SRC_CC = $(PLAIN_SRC_CC) $(SERVER_INTERFACES_SRC_CC) + +REQUIRES_LIBS = libc libstdc++ libexec libipc +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) + +include $(L4DIR)/mk/prog.mk +include $(IDL_MK_DIR)/interface_rules.mk + +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC) diff -r e0fef4c35263 -r df0cdda39707 libexec/rm/region_mapper.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libexec/rm/region_mapper.cc Fri Jun 17 23:54:54 2022 +0200 @@ -0,0 +1,75 @@ +/* + * A region mapper for deployment in a new task. + * + * Copyright (C) 2022 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 + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include + +#include +#include +#include +#include + +#include "pager_object_server.h" + + + +static InternalPager exec_pager; + + + +int main(int argc, char *argv[]) +{ + /* Initialise pager regions from region descriptions obtained via the + auxiliary data. */ + + l4re_aux_t *l4re_aux = exec_get_l4re_aux(argc, argv); + + printf("aux = {%s, %lx, %lx, %lx}\n", l4re_aux->binary, l4re_aux->kip_ds, l4re_aux->dbg_lvl, l4re_aux->ldr_flags); + + /* Skip past the auxiliary structure itself. */ + + struct exec_region *region = (struct exec_region *) *((l4_addr_t *) (l4re_aux + 1)); + + if (!region) + { + printf("Could not find regions.\n"); + return 1; + } + + for (; region && (region->ds != L4_INVALID_CAP); region++) + { + printf("Adding region: {%lx, %lx, %lx, %lx}\n", region->start, region->size, region->flags, region->ds); + exec_pager.add(*region); + } + + /* Start the pager. */ + + printf("Starting pager...\n"); + printf("Pager capability: %lx\n", l4re_env_get_cap("server")); + printf("Main thread: %lx\n", l4re_env()->main_thread); + + ipc_server_loop_for(PagerObject, &exec_pager, "server"); + + printf("Ending pager...\n"); + return 0; +} + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/ diff -r e0fef4c35263 -r df0cdda39707 libipc/include/ipc/map.h --- a/libipc/include/ipc/map.h Fri Jun 17 23:36:03 2022 +0200 +++ b/libipc/include/ipc/map.h Fri Jun 17 23:54:54 2022 +0200 @@ -27,9 +27,10 @@ struct ipc_mapped_cap { - l4_umword_t index; + l4_cap_idx_t mapped_cap; l4_cap_idx_t cap; unsigned char rights; + l4_umword_t obj_rights; }; long ipc_map_capability(l4_cap_idx_t task, struct ipc_mapped_cap mapped_cap); diff -r e0fef4c35263 -r df0cdda39707 libipc/lib/src/map.c --- a/libipc/lib/src/map.c Fri Jun 17 23:36:03 2022 +0200 +++ b/libipc/lib/src/map.c Fri Jun 17 23:54:54 2022 +0200 @@ -34,7 +34,8 @@ { return l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP, l4_obj_fpage(mapped_cap.cap, 0, mapped_cap.rights), - l4_map_obj_control(mapped_cap.index, L4_MAP_ITEM_MAP))); + l4_map_obj_control(mapped_cap.mapped_cap, L4_MAP_ITEM_MAP) | + mapped_cap.obj_rights)); } /* Map several capabilities to another task. */ diff -r e0fef4c35263 -r df0cdda39707 test_files/Makefile --- a/test_files/Makefile Fri Jun 17 23:36:03 2022 +0200 +++ b/test_files/Makefile Fri Jun 17 23:54:54 2022 +0200 @@ -4,18 +4,26 @@ E2ACCESS_DIR = $(PKGDIR)/../libe2access/host TARGET = $(PKGDIR)/../conf/e2test.fs +REQUIRES_LIBS = libc libstdc++ libexec libipc + include $(L4DIR)/mk/Makeconf include $(OBJ_BASE)/l4defs.mk.inc PROGRAMS_DIR = $(PKGDIR_OBJ)/programs/OBJ-$(L4_SYSTEM)-l4f +LIBEXEC_DIR = $(PKGDIR)/../libexec +RM_PROGRAM_DIR = $(call absfilename,$(OBJ_DIR)/$(LIBEXEC_DIR))/rm/OBJ-$(L4_SYSTEM)-l4f +RM_PROGRAM = $(RM_PROGRAM_DIR)/exec_region_mapper + # Special rules to build the test filesystem. all:: $(TARGET) $(PROGRAMS_DIR) -$(TARGET): $(PROGRAMS_DIR) +$(TARGET): $(PROGRAMS_DIR) $(RM_PROGRAM) $(MAKE) -C $(E2ACCESS_DIR) && \ - $(PKGDIR)/mk_e2test.sh -q $(PKGDIR) $(PROGRAMS_DIR) $(E2ACCESS_DIR) $@ + $(PKGDIR)/mk_e2test.sh -q $(PKGDIR) $(E2ACCESS_DIR) $@ \ + $(PROGRAMS_DIR)/dstest_* \ + $(RM_PROGRAM) $(PROGRAMS_DIR): $(PKGDIR)/programs/*.c* $(MAKE) -C $(PKGDIR)/programs $(MKFLAGS) && \ diff -r e0fef4c35263 -r df0cdda39707 test_files/mk_e2test.sh --- a/test_files/mk_e2test.sh Fri Jun 17 23:36:03 2022 +0200 +++ b/test_files/mk_e2test.sh Fri Jun 17 23:54:54 2022 +0200 @@ -31,18 +31,19 @@ fi PKGDIR=$(realpath "$1") -PROGRAMS_DIR=$(realpath "$2") -E2ACCESS_DIR=$(realpath "$3") -TARGET=$(realpath "$4") +E2ACCESS_DIR=$(realpath "$2") +TARGET=$(realpath "$3") -if [ ! -e "$PKGDIR" ] || [ ! -e "$PROGRAMS_DIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then +shift 3 + +if [ ! -e "$PKGDIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then cat 1>&2 < +Usage: $PROGNAME [ -q ] [ ... ] Package directory: $PKGDIR -Programs directory: $PROGRAMS_DIR e2access directory: $E2ACCESS_DIR Target filesystem: $TARGET +Programs: $* EOF exit 1 fi @@ -110,7 +111,9 @@ # Put some programs in the same place. -cp "$PROGRAMS_DIR/dstest_"* . +for PROGRAM in $* ; do + cp $(realpath "$PROGRAM") . +done # Leave the filesystem root. diff -r e0fef4c35263 -r df0cdda39707 test_files/programs/Makefile --- a/test_files/programs/Makefile Fri Jun 17 23:36:03 2022 +0200 +++ b/test_files/programs/Makefile Fri Jun 17 23:54:54 2022 +0200 @@ -1,47 +1,12 @@ PKGDIR ?= .. L4DIR ?= $(PKGDIR)/../../.. -TARGET = dstest_exec_payload dstest_region_mapper +TARGET = dstest_exec_payload MODE = static -# Locations for interface input and generated output. - -IDL_DIR = $(PKGDIR)/../libsystypes/idl -IDL_MK_DIR = $(L4DIR)/idl4re/mk -IDL_BUILD_DIR = . -IDL_EXPORT_DIR = . - -include $(IDL_MK_DIR)/idl.mk - -# Compound interfaces. - -pager_object_NAME = PagerObject -pager_object_INTERFACES = region_mapper system_pager - -COMP_INTERFACES_CC = pager_object - -# Individual interfaces. +SRC_C_dstest_exec_payload = exec_payload.c -SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC)) - -# Generated and plain source files. - -SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC)) - -# Normal source files. - -SRC_C_dstest_exec_payload = exec_payload.c - -PLAIN_SRC_CC_dstest_region_mapper = region_mapper.cc -SRC_CC_dstest_region_mapper = \ - $(PLAIN_SRC_CC_dstest_region_mapper) \ - $(SERVER_INTERFACES_SRC_CC) - -REQUIRES_LIBS = libc libstdc++ libexec libipc -PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) +REQUIRES_LIBS = libc include $(L4DIR)/mk/prog.mk -include $(IDL_MK_DIR)/interface_rules.mk - -$(PLAIN_SRC_CC_dstest_region_mapper): $(SERVER_INTERFACES_SRC_CC) diff -r e0fef4c35263 -r df0cdda39707 test_files/programs/region_mapper.cc --- a/test_files/programs/region_mapper.cc Fri Jun 17 23:36:03 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * A region mapper for deployment in a new task. - * - * Copyright (C) 2022 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 - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#include - -#include -#include -#include -#include - -#include "pager_object_server.h" - - - -static InternalPager exec_pager; - - - -int main(int argc, char *argv[]) -{ - /* Initialise pager regions from region descriptions obtained via the - auxiliary data. */ - - l4re_aux_t *l4re_aux = exec_get_l4re_aux(argc, argv); - - printf("aux = {%s, %lx, %lx, %lx}\n", l4re_aux->binary, l4re_aux->kip_ds, l4re_aux->dbg_lvl, l4re_aux->ldr_flags); - - /* Skip past the auxiliary structure itself. */ - - struct exec_region *region = (struct exec_region *) *((l4_addr_t *) (l4re_aux + 1)); - - if (!region) - { - printf("Could not find regions.\n"); - return 1; - } - - for (; region && (region->ds != L4_INVALID_CAP); region++) - { - printf("Adding region: %lx\n", region->start); - exec_pager.add(*region); - } - - /* Start the pager. */ - - printf("Starting pager...\n"); - ipc_server_loop_for(PagerObject, &exec_pager, "server"); - - return 0; -} - -/* vim: tabstop=2 expandtab shiftwidth=2 -*/ diff -r e0fef4c35263 -r df0cdda39707 tests/dstest_exec.cc --- a/tests/dstest_exec.cc Fri Jun 17 23:36:03 2022 +0200 +++ b/tests/dstest_exec.cc Fri Jun 17 23:54:54 2022 +0200 @@ -40,6 +40,8 @@ +/* External system-level pager for the region mapper in a created task. */ + static ExternalPager exec_pager; static const offset_t initial_stack_size = 16 * L4_PAGESIZE; @@ -197,24 +199,29 @@ struct exec_region rm_regions[rm_payload->segments() + 2]; struct ipc_mapped_cap rm_mapped_caps[rm_payload->segments() + 3]; + l4_cap_idx_t mapped_cap; unsigned int rm_index = 0; - for (unsigned int i = 0; i < rm_payload->segments(); i++) + for (unsigned int i = 0; i < program_payload->segments(); i++) { - Segment *s = rm_payload->segment(i); + Segment *s = program_payload->segment(i); if (s->loadable()) { + mapped_cap = process.allocate_cap(); rm_regions[rm_index] = s->exec_region(); - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {process.allocate_cap(), rm_regions[rm_index].ds, L4_CAP_FPAGE_RWS}; + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {mapped_cap, rm_regions[rm_index].ds, L4_CAP_FPAGE_RWS, 0}; + rm_regions[rm_index].ds = mapped_cap; rm_index++; } } /* Introduce the stack region and capability. */ + mapped_cap = process.allocate_cap(); rm_regions[rm_index] = program_stack.exec_region(); - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {process.allocate_cap(), program_stack.exec_region().ds, L4_CAP_FPAGE_RWS}; + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {mapped_cap, program_stack.exec_region().ds, L4_CAP_FPAGE_RWS, 0}; + rm_regions[rm_index].ds = mapped_cap; rm_index++; /* Terminate the region array. */ @@ -225,18 +232,20 @@ l4_cap_idx_t ipc_gate_cap = process.allocate_cap(); - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {ipc_gate_cap, ipc_gate, L4_CAP_FPAGE_RWS}; + printf("Mapping %lx to %lx in task.\n", ipc_gate, ipc_gate_cap); + + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {ipc_gate_cap, ipc_gate, L4_CAP_FPAGE_RWS, L4_FPAGE_C_OBJ_RIGHTS}; rm_index++; /* Terminate the capability array. */ - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {0, L4_INVALID_CAP, 0}; + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {0, L4_INVALID_CAP, 0, 0}; /* Map these additional capabilities. */ printf("Map additional capabilities...\n"); - process.map_capabilities(rm_mapped_caps); + process.map_capabilities(rm_mapped_caps, false); /* Define the IPC gate as an initial capability to be acquired by the region mapper via the l4re_env API. The capability index is assigned above when @@ -277,7 +286,7 @@ /* Configure the environment for the thread, specifying the pager (and exception handler plus region mapper). */ - err = process.configure_thread(ipc_gate); + err = process.configure_thread(ipc_gate, ipc_gate_cap); if (err) { @@ -308,6 +317,7 @@ } printf("Finished.\n"); + while (1) l4_sleep_forever();