1.1 --- a/conf/dstest_exec.cfg Fri Jun 17 23:36:03 2022 +0200
1.2 +++ b/conf/dstest_exec.cfg Fri Jun 17 23:54:54 2022 +0200
1.3 @@ -34,7 +34,7 @@
1.4 },
1.5 log = { "ext2svr", "y" },
1.6 },
1.7 - "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr");
1.8 + "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "20", "ext2svr");
1.9
1.10 -- Obtain user filesystems with umask 0022 (18).
1.11
1.12 @@ -47,4 +47,4 @@
1.13 },
1.14 log = { "client", "g" },
1.15 },
1.16 - "rom/dstest_exec", "home/paulb/dstest_region_mapper", "home/paulb/dstest_exec_payload", "hello", "world");
1.17 + "rom/dstest_exec", "home/paulb/exec_region_mapper", "home/paulb/dstest_exec_payload", "hello", "world");
2.1 --- a/libexec/Makefile Fri Jun 17 23:36:03 2022 +0200
2.2 +++ b/libexec/Makefile Fri Jun 17 23:54:54 2022 +0200
2.3 @@ -1,4 +1,10 @@
2.4 PKGDIR ?= .
2.5 L4DIR ?= $(PKGDIR)/../../..
2.6
2.7 +TARGET = include lib rm
2.8 +
2.9 include $(L4DIR)/mk/subdir.mk
2.10 +
2.11 +# Internal dependencies.
2.12 +
2.13 +rm: lib
3.1 --- a/libexec/include/exec/process.h Fri Jun 17 23:36:03 2022 +0200
3.2 +++ b/libexec/include/exec/process.h Fri Jun 17 23:54:54 2022 +0200
3.3 @@ -95,7 +95,7 @@
3.4
3.5 long configure_task();
3.6
3.7 - long configure_thread(l4_cap_idx_t server);
3.8 + long configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap = L4_INVALID_CAP);
3.9
3.10 long map_capabilities(struct ipc_mapped_cap mapped_caps[],
3.11 bool to_count = true);
4.1 --- a/libexec/lib/src/external_pager.cc Fri Jun 17 23:36:03 2022 +0200
4.2 +++ b/libexec/lib/src/external_pager.cc Fri Jun 17 23:54:54 2022 +0200
4.3 @@ -75,6 +75,9 @@
4.4 printf("fs_base = %lx\n", regs.fs_base);
4.5 printf("gs_base = %lx\n", regs.gs_base);
4.6
4.7 + while (1)
4.8 + l4_sleep_forever();
4.9 +
4.10 return L4_EOK;
4.11 }
4.12
4.13 @@ -105,17 +108,22 @@
4.14 if ((addr >= r.map_start) && (addr < r.map_start + r.size))
4.15 {
4.16 l4_addr_t page_addr = trunc(addr, L4_PAGESIZE);
4.17 + 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);
4.18
4.19 - region->fpage = l4_fpage(r.start + (page_addr - r.map_start), L4_PAGESHIFT, r.flags);
4.20 + if (!map_flags)
4.21 + map_flags = L4RE_DS_F_R;
4.22 +
4.23 + region->fpage = l4_fpage(r.start + (page_addr - r.map_start), L4_PAGESHIFT, map_flags & r.flags);
4.24 region->snd_base = page_addr;
4.25
4.26 #if DEBUG
4.27 - printf("%lx...%lx from %lx...%lx offset %lx size %d rights %x\n",
4.28 + printf("%lx...%lx from %lx...%lx offset %lx size %d rights %x ds %lx\n",
4.29 r.map_start, region->snd_base,
4.30 r.start, l4_fpage_memaddr(region->fpage),
4.31 addr - r.map_start,
4.32 l4_fpage_size(region->fpage),
4.33 - l4_fpage_rights(region->fpage));
4.34 + l4_fpage_rights(region->fpage),
4.35 + r.ds);
4.36
4.37 printf("%lx -> ", addr);
4.38
4.39 @@ -228,10 +236,10 @@
4.40 l4_touch_rw((const void *) ds_start, size);
4.41
4.42 #if DEBUG
4.43 - printf("-> added region for %lx size %ld (%d)\n", region_start, region_size, page_order(region_size));
4.44 + printf("-> added region at %lx size %ld (%d) from %lx ds %lx\n", region_start, region_size, page_order(region_size), ds_start, ds);
4.45 #endif
4.46
4.47 - MappedRegion r(ds_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, region_start);
4.48 + MappedRegion r(ds_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, region_start, ds);
4.49
4.50 add(r);
4.51
5.1 --- a/libexec/lib/src/internal_pager.cc Fri Jun 17 23:36:03 2022 +0200
5.2 +++ b/libexec/lib/src/internal_pager.cc Fri Jun 17 23:54:54 2022 +0200
5.3 @@ -76,6 +76,9 @@
5.4 printf("fs_base = %lx\n", regs.fs_base);
5.5 printf("gs_base = %lx\n", regs.gs_base);
5.6
5.7 + while (1)
5.8 + l4_sleep_forever();
5.9 +
5.10 return L4_EOK;
5.11 }
5.12
5.13 @@ -105,19 +108,36 @@
5.14
5.15 if ((addr >= r.start) && (addr < r.start + r.size))
5.16 {
5.17 - l4_addr_t page_addr = trunc(addr, L4_PAGESIZE);
5.18 + offset_t window_size = L4_PAGESIZE;
5.19 + address_t window_base = trunc(addr, window_size);
5.20 + offset_t offset = addr - r.start;
5.21 + address_t page_addr = trunc(addr, L4_PAGESIZE);
5.22 + address_t hot_spot = page_addr - window_base;
5.23
5.24 /* Interact with the region's dataspace, specifying a receive window for a
5.25 map operation. Here, a single page is specified. */
5.26
5.27 client_Dataspace dataspace(r.ds);
5.28 - l4_snd_fpage_t region = {0, l4_fpage(page_addr, L4_PAGESHIFT, 0)};
5.29 + l4_snd_fpage_t rw_region = {0, l4_fpage(window_base, L4_PAGESHIFT, 0)};
5.30 + 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);
5.31 +
5.32 + if (!map_flags)
5.33 + map_flags = L4RE_DS_F_R;
5.34
5.35 #if DEBUG
5.36 - printf("region = {%lx, {%lx, %d}}\n", region.snd_base, l4_fpage_memaddr(region.fpage), l4_fpage_size(region.fpage));
5.37 + printf("window_base = %lx; window_size = %lx\n", window_base, window_size);
5.38 + printf("region = {%lx, {%lx, %d}}\n", rw_region.snd_base, l4_fpage_memaddr(rw_region.fpage), l4_fpage_size(rw_region.fpage));
5.39 + printf("map(%lx, %lx, %lx) -> %lx\n", offset, hot_spot, map_flags, r.ds);
5.40 #endif
5.41
5.42 - return dataspace.map(0, 0, L4_FPAGE_RO, ®ion);
5.43 + long err = dataspace.map(offset, hot_spot, map_flags & r.flags, &rw_region);
5.44 +
5.45 + /* Indicate an unspecified result, since the mapping should have taken
5.46 + place. */
5.47 +
5.48 + *region = {0, l4_fpage_invalid()};
5.49 +
5.50 + return err;
5.51 }
5.52
5.53 #if DEBUG
5.54 @@ -201,7 +221,7 @@
5.55 }
5.56
5.57 #if DEBUG
5.58 - printf("-> added region for %lx size %ld (%d)\n", region_start, region_size, page_order(region_size));
5.59 + printf("-> added region at %lx size %ld (%d) ds %lx\n", region_start, region_size, page_order(region_size), ds);
5.60 #endif
5.61
5.62 ExecRegion r = (ExecRegion) {region_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, ds};
6.1 --- a/libexec/lib/src/process.cc Fri Jun 17 23:36:03 2022 +0200
6.2 +++ b/libexec/lib/src/process.cc Fri Jun 17 23:54:54 2022 +0200
6.3 @@ -132,12 +132,12 @@
6.4 /* Define capability mappings for the new task. */
6.5
6.6 struct ipc_mapped_cap mapped_caps[] = {
6.7 - {L4_BASE_TASK_CAP, _task, L4_CAP_FPAGE_RWS},
6.8 - {_env.factory, l4re_env()->factory, L4_CAP_FPAGE_RWS},
6.9 - {_env.log, l4re_env()->log, L4_CAP_FPAGE_RWS},
6.10 - {_env.scheduler, l4re_env()->scheduler, L4_CAP_FPAGE_RWS},
6.11 - {_env.mem_alloc, l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS},
6.12 - {0, L4_INVALID_CAP, 0},
6.13 + {L4_BASE_TASK_CAP, _task, L4_CAP_FPAGE_RWS, 0},
6.14 + {_env.factory, l4re_env()->factory, L4_CAP_FPAGE_RWS, 0},
6.15 + {_env.log, l4re_env()->log, L4_CAP_FPAGE_RWS, 0},
6.16 + {_env.scheduler, l4re_env()->scheduler, L4_CAP_FPAGE_RWS, 0},
6.17 + {_env.mem_alloc, l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS, 0},
6.18 + {0, L4_INVALID_CAP, 0, 0},
6.19 };
6.20
6.21 return map_capabilities(mapped_caps, false);
6.22 @@ -145,19 +145,21 @@
6.23
6.24 /* Configure the thread environment. */
6.25
6.26 -long Process::configure_thread(l4_cap_idx_t server)
6.27 +long Process::configure_thread(l4_cap_idx_t server, l4_cap_idx_t mapped_cap)
6.28 {
6.29 /* Employ a distinct region mapper for each thread's environment, this acting
6.30 as pager. */
6.31
6.32 - _env.rm = allocate_cap();
6.33 -
6.34 - struct ipc_mapped_cap mapped_caps[] = {
6.35 - {_env.rm, server, L4_CAP_FPAGE_RWS},
6.36 - {0, L4_INVALID_CAP, 0},
6.37 - };
6.38 -
6.39 - return map_capabilities(mapped_caps, false);
6.40 + if (l4_is_valid_cap(mapped_cap))
6.41 + {
6.42 + _env.rm = mapped_cap;
6.43 + return L4_EOK;
6.44 + }
6.45 + else
6.46 + {
6.47 + _env.rm = allocate_cap();
6.48 + return ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.rm, server, L4_CAP_FPAGE_RWS, 0});
6.49 + }
6.50 }
6.51
6.52 /* Map capabilities into the task, counting them if indicated. */
6.53 @@ -205,13 +207,20 @@
6.54
6.55 _env.main_thread = allocate_cap();
6.56
6.57 - ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS});
6.58 + ipc_map_capability(_task, (struct ipc_mapped_cap) {_env.main_thread, thread, L4_CAP_FPAGE_RWS, 0});
6.59
6.60 /* Populate the initial environment in the thread. */
6.61
6.62 st.set_l4re_aux(&_aux);
6.63 st.set_l4re_env(&_env);
6.64
6.65 + /* Reserve some extra space for capabilities used by this thread.
6.66 + NOTE: Surely the capability allocator should be able to avoid conflicts,
6.67 + but concurrency issues have been observed before, leading to various
6.68 + measures in libipc. */
6.69 +
6.70 + _env.first_free_cap += 0x20;
6.71 +
6.72 /* Set the start details. */
6.73
6.74 err = l4_error(l4_thread_ex_regs(thread, program_start, st.start_address(), 0));
7.1 --- a/libexec/lib/src/segment.cc Fri Jun 17 23:36:03 2022 +0200
7.2 +++ b/libexec/lib/src/segment.cc Fri Jun 17 23:54:54 2022 +0200
7.3 @@ -121,7 +121,7 @@
7.4
7.5 MappedRegion &Segment::region()
7.6 {
7.7 - _region = MappedRegion((l4_addr_t) _buf, _region_allocated_size, region_flags(), _region_base);
7.8 + _region = MappedRegion((l4_addr_t) _buf, _region_allocated_size, region_flags(), _region_base, _ds);
7.9 return _region;
7.10 }
7.11
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/libexec/rm/Makefile Fri Jun 17 23:54:54 2022 +0200
8.3 @@ -0,0 +1,52 @@
8.4 +PKGDIR ?= ..
8.5 +L4DIR ?= $(PKGDIR)/../../..
8.6 +
8.7 +TARGET = exec_region_mapper
8.8 +
8.9 +MODE = static
8.10 +
8.11 +# Relocate the binary to avoid conflicting with actual payloads.
8.12 +
8.13 +DEFAULT_RELOC_x86 := 0xb0000000
8.14 +DEFAULT_RELOC_arm := 0xb0000000
8.15 +DEFAULT_RELOC_arm64 := 0xc0000000
8.16 +DEFAULT_RELOC_ppc32 := 0xb0000000
8.17 +DEFAULT_RELOC_amd64 := 0x70000000
8.18 +DEFAULT_RELOC_mips := 0x70000000
8.19 +
8.20 +# Locations for interface input and generated output.
8.21 +
8.22 +IDL_DIR = $(PKGDIR)/../libsystypes/idl
8.23 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
8.24 +IDL_BUILD_DIR = .
8.25 +IDL_EXPORT_DIR = .
8.26 +
8.27 +include $(IDL_MK_DIR)/idl.mk
8.28 +
8.29 +# Compound interfaces.
8.30 +
8.31 +pager_object_NAME = PagerObject
8.32 +pager_object_INTERFACES = region_mapper system_pager
8.33 +
8.34 +COMP_INTERFACES_CC = pager_object
8.35 +
8.36 +# Individual interfaces.
8.37 +
8.38 +SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC))
8.39 +
8.40 +# Generated and plain source files.
8.41 +
8.42 +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC))
8.43 +
8.44 +# Normal source files.
8.45 +
8.46 +PLAIN_SRC_CC = region_mapper.cc
8.47 +SRC_CC = $(PLAIN_SRC_CC) $(SERVER_INTERFACES_SRC_CC)
8.48 +
8.49 +REQUIRES_LIBS = libc libstdc++ libexec libipc
8.50 +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
8.51 +
8.52 +include $(L4DIR)/mk/prog.mk
8.53 +include $(IDL_MK_DIR)/interface_rules.mk
8.54 +
8.55 +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC)
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/libexec/rm/region_mapper.cc Fri Jun 17 23:54:54 2022 +0200
9.3 @@ -0,0 +1,75 @@
9.4 +/*
9.5 + * A region mapper for deployment in a new task.
9.6 + *
9.7 + * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
9.8 + *
9.9 + * This program is free software; you can redistribute it and/or
9.10 + * modify it under the terms of the GNU General Public License as
9.11 + * published by the Free Software Foundation; either version 2 of
9.12 + * the License, or (at your option) any later version.
9.13 + *
9.14 + * This program is distributed in the hope that it will be useful,
9.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.17 + * GNU General Public License for more details.
9.18 + *
9.19 + * You should have received a copy of the GNU General Public License
9.20 + * along with this program; if not, write to the Free Software
9.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
9.22 + * Boston, MA 02110-1301, USA
9.23 + */
9.24 +
9.25 +#include <l4/re/env.h>
9.26 +
9.27 +#include <exec/common.h>
9.28 +#include <exec/internal_pager.h>
9.29 +#include <exec/stack.h>
9.30 +#include <ipc/server.h>
9.31 +
9.32 +#include "pager_object_server.h"
9.33 +
9.34 +
9.35 +
9.36 +static InternalPager exec_pager;
9.37 +
9.38 +
9.39 +
9.40 +int main(int argc, char *argv[])
9.41 +{
9.42 + /* Initialise pager regions from region descriptions obtained via the
9.43 + auxiliary data. */
9.44 +
9.45 + l4re_aux_t *l4re_aux = exec_get_l4re_aux(argc, argv);
9.46 +
9.47 + printf("aux = {%s, %lx, %lx, %lx}\n", l4re_aux->binary, l4re_aux->kip_ds, l4re_aux->dbg_lvl, l4re_aux->ldr_flags);
9.48 +
9.49 + /* Skip past the auxiliary structure itself. */
9.50 +
9.51 + struct exec_region *region = (struct exec_region *) *((l4_addr_t *) (l4re_aux + 1));
9.52 +
9.53 + if (!region)
9.54 + {
9.55 + printf("Could not find regions.\n");
9.56 + return 1;
9.57 + }
9.58 +
9.59 + for (; region && (region->ds != L4_INVALID_CAP); region++)
9.60 + {
9.61 + printf("Adding region: {%lx, %lx, %lx, %lx}\n", region->start, region->size, region->flags, region->ds);
9.62 + exec_pager.add(*region);
9.63 + }
9.64 +
9.65 + /* Start the pager. */
9.66 +
9.67 + printf("Starting pager...\n");
9.68 + printf("Pager capability: %lx\n", l4re_env_get_cap("server"));
9.69 + printf("Main thread: %lx\n", l4re_env()->main_thread);
9.70 +
9.71 + ipc_server_loop_for(PagerObject, &exec_pager, "server");
9.72 +
9.73 + printf("Ending pager...\n");
9.74 + return 0;
9.75 +}
9.76 +
9.77 +/* vim: tabstop=2 expandtab shiftwidth=2
9.78 +*/
10.1 --- a/libipc/include/ipc/map.h Fri Jun 17 23:36:03 2022 +0200
10.2 +++ b/libipc/include/ipc/map.h Fri Jun 17 23:54:54 2022 +0200
10.3 @@ -27,9 +27,10 @@
10.4
10.5 struct ipc_mapped_cap
10.6 {
10.7 - l4_umword_t index;
10.8 + l4_cap_idx_t mapped_cap;
10.9 l4_cap_idx_t cap;
10.10 unsigned char rights;
10.11 + l4_umword_t obj_rights;
10.12 };
10.13
10.14 long ipc_map_capability(l4_cap_idx_t task, struct ipc_mapped_cap mapped_cap);
11.1 --- a/libipc/lib/src/map.c Fri Jun 17 23:36:03 2022 +0200
11.2 +++ b/libipc/lib/src/map.c Fri Jun 17 23:54:54 2022 +0200
11.3 @@ -34,7 +34,8 @@
11.4 {
11.5 return l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP,
11.6 l4_obj_fpage(mapped_cap.cap, 0, mapped_cap.rights),
11.7 - l4_map_obj_control(mapped_cap.index, L4_MAP_ITEM_MAP)));
11.8 + l4_map_obj_control(mapped_cap.mapped_cap, L4_MAP_ITEM_MAP) |
11.9 + mapped_cap.obj_rights));
11.10 }
11.11
11.12 /* Map several capabilities to another task. */
12.1 --- a/test_files/Makefile Fri Jun 17 23:36:03 2022 +0200
12.2 +++ b/test_files/Makefile Fri Jun 17 23:54:54 2022 +0200
12.3 @@ -4,18 +4,26 @@
12.4 E2ACCESS_DIR = $(PKGDIR)/../libe2access/host
12.5 TARGET = $(PKGDIR)/../conf/e2test.fs
12.6
12.7 +REQUIRES_LIBS = libc libstdc++ libexec libipc
12.8 +
12.9 include $(L4DIR)/mk/Makeconf
12.10 include $(OBJ_BASE)/l4defs.mk.inc
12.11
12.12 PROGRAMS_DIR = $(PKGDIR_OBJ)/programs/OBJ-$(L4_SYSTEM)-l4f
12.13
12.14 +LIBEXEC_DIR = $(PKGDIR)/../libexec
12.15 +RM_PROGRAM_DIR = $(call absfilename,$(OBJ_DIR)/$(LIBEXEC_DIR))/rm/OBJ-$(L4_SYSTEM)-l4f
12.16 +RM_PROGRAM = $(RM_PROGRAM_DIR)/exec_region_mapper
12.17 +
12.18 # Special rules to build the test filesystem.
12.19
12.20 all:: $(TARGET) $(PROGRAMS_DIR)
12.21
12.22 -$(TARGET): $(PROGRAMS_DIR)
12.23 +$(TARGET): $(PROGRAMS_DIR) $(RM_PROGRAM)
12.24 $(MAKE) -C $(E2ACCESS_DIR) && \
12.25 - $(PKGDIR)/mk_e2test.sh -q $(PKGDIR) $(PROGRAMS_DIR) $(E2ACCESS_DIR) $@
12.26 + $(PKGDIR)/mk_e2test.sh -q $(PKGDIR) $(E2ACCESS_DIR) $@ \
12.27 + $(PROGRAMS_DIR)/dstest_* \
12.28 + $(RM_PROGRAM)
12.29
12.30 $(PROGRAMS_DIR): $(PKGDIR)/programs/*.c*
12.31 $(MAKE) -C $(PKGDIR)/programs $(MKFLAGS) && \
13.1 --- a/test_files/mk_e2test.sh Fri Jun 17 23:36:03 2022 +0200
13.2 +++ b/test_files/mk_e2test.sh Fri Jun 17 23:54:54 2022 +0200
13.3 @@ -31,18 +31,19 @@
13.4 fi
13.5
13.6 PKGDIR=$(realpath "$1")
13.7 -PROGRAMS_DIR=$(realpath "$2")
13.8 -E2ACCESS_DIR=$(realpath "$3")
13.9 -TARGET=$(realpath "$4")
13.10 +E2ACCESS_DIR=$(realpath "$2")
13.11 +TARGET=$(realpath "$3")
13.12
13.13 -if [ ! -e "$PKGDIR" ] || [ ! -e "$PROGRAMS_DIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then
13.14 +shift 3
13.15 +
13.16 +if [ ! -e "$PKGDIR" ] || [ ! -e "$E2ACCESS_DIR" ] || [ ! "$TARGET" ] ; then
13.17 cat 1>&2 <<EOF
13.18 -Usage: $PROGNAME [ -q ] <package directory> <programs directory> <e2access directory> <target>
13.19 +Usage: $PROGNAME [ -q ] <package directory> <e2access directory> <target> [ <program> ... ]
13.20
13.21 Package directory: $PKGDIR
13.22 -Programs directory: $PROGRAMS_DIR
13.23 e2access directory: $E2ACCESS_DIR
13.24 Target filesystem: $TARGET
13.25 +Programs: $*
13.26 EOF
13.27 exit 1
13.28 fi
13.29 @@ -110,7 +111,9 @@
13.30
13.31 # Put some programs in the same place.
13.32
13.33 -cp "$PROGRAMS_DIR/dstest_"* .
13.34 +for PROGRAM in $* ; do
13.35 + cp $(realpath "$PROGRAM") .
13.36 +done
13.37
13.38 # Leave the filesystem root.
13.39
14.1 --- a/test_files/programs/Makefile Fri Jun 17 23:36:03 2022 +0200
14.2 +++ b/test_files/programs/Makefile Fri Jun 17 23:54:54 2022 +0200
14.3 @@ -1,47 +1,12 @@
14.4 PKGDIR ?= ..
14.5 L4DIR ?= $(PKGDIR)/../../..
14.6
14.7 -TARGET = dstest_exec_payload dstest_region_mapper
14.8 +TARGET = dstest_exec_payload
14.9
14.10 MODE = static
14.11
14.12 -# Locations for interface input and generated output.
14.13 -
14.14 -IDL_DIR = $(PKGDIR)/../libsystypes/idl
14.15 -IDL_MK_DIR = $(L4DIR)/idl4re/mk
14.16 -IDL_BUILD_DIR = .
14.17 -IDL_EXPORT_DIR = .
14.18 -
14.19 -include $(IDL_MK_DIR)/idl.mk
14.20 -
14.21 -# Compound interfaces.
14.22 -
14.23 -pager_object_NAME = PagerObject
14.24 -pager_object_INTERFACES = region_mapper system_pager
14.25 -
14.26 -COMP_INTERFACES_CC = pager_object
14.27 -
14.28 -# Individual interfaces.
14.29 +SRC_C_dstest_exec_payload = exec_payload.c
14.30
14.31 -SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC))
14.32 -
14.33 -# Generated and plain source files.
14.34 -
14.35 -SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC))
14.36 -
14.37 -# Normal source files.
14.38 -
14.39 -SRC_C_dstest_exec_payload = exec_payload.c
14.40 -
14.41 -PLAIN_SRC_CC_dstest_region_mapper = region_mapper.cc
14.42 -SRC_CC_dstest_region_mapper = \
14.43 - $(PLAIN_SRC_CC_dstest_region_mapper) \
14.44 - $(SERVER_INTERFACES_SRC_CC)
14.45 -
14.46 -REQUIRES_LIBS = libc libstdc++ libexec libipc
14.47 -PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
14.48 +REQUIRES_LIBS = libc
14.49
14.50 include $(L4DIR)/mk/prog.mk
14.51 -include $(IDL_MK_DIR)/interface_rules.mk
14.52 -
14.53 -$(PLAIN_SRC_CC_dstest_region_mapper): $(SERVER_INTERFACES_SRC_CC)
15.1 --- a/test_files/programs/region_mapper.cc Fri Jun 17 23:36:03 2022 +0200
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,71 +0,0 @@
15.4 -/*
15.5 - * A region mapper for deployment in a new task.
15.6 - *
15.7 - * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
15.8 - *
15.9 - * This program is free software; you can redistribute it and/or
15.10 - * modify it under the terms of the GNU General Public License as
15.11 - * published by the Free Software Foundation; either version 2 of
15.12 - * the License, or (at your option) any later version.
15.13 - *
15.14 - * This program is distributed in the hope that it will be useful,
15.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
15.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15.17 - * GNU General Public License for more details.
15.18 - *
15.19 - * You should have received a copy of the GNU General Public License
15.20 - * along with this program; if not, write to the Free Software
15.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
15.22 - * Boston, MA 02110-1301, USA
15.23 - */
15.24 -
15.25 -#include <l4/re/env.h>
15.26 -
15.27 -#include <exec/common.h>
15.28 -#include <exec/internal_pager.h>
15.29 -#include <exec/stack.h>
15.30 -#include <ipc/server.h>
15.31 -
15.32 -#include "pager_object_server.h"
15.33 -
15.34 -
15.35 -
15.36 -static InternalPager exec_pager;
15.37 -
15.38 -
15.39 -
15.40 -int main(int argc, char *argv[])
15.41 -{
15.42 - /* Initialise pager regions from region descriptions obtained via the
15.43 - auxiliary data. */
15.44 -
15.45 - l4re_aux_t *l4re_aux = exec_get_l4re_aux(argc, argv);
15.46 -
15.47 - printf("aux = {%s, %lx, %lx, %lx}\n", l4re_aux->binary, l4re_aux->kip_ds, l4re_aux->dbg_lvl, l4re_aux->ldr_flags);
15.48 -
15.49 - /* Skip past the auxiliary structure itself. */
15.50 -
15.51 - struct exec_region *region = (struct exec_region *) *((l4_addr_t *) (l4re_aux + 1));
15.52 -
15.53 - if (!region)
15.54 - {
15.55 - printf("Could not find regions.\n");
15.56 - return 1;
15.57 - }
15.58 -
15.59 - for (; region && (region->ds != L4_INVALID_CAP); region++)
15.60 - {
15.61 - printf("Adding region: %lx\n", region->start);
15.62 - exec_pager.add(*region);
15.63 - }
15.64 -
15.65 - /* Start the pager. */
15.66 -
15.67 - printf("Starting pager...\n");
15.68 - ipc_server_loop_for(PagerObject, &exec_pager, "server");
15.69 -
15.70 - return 0;
15.71 -}
15.72 -
15.73 -/* vim: tabstop=2 expandtab shiftwidth=2
15.74 -*/
16.1 --- a/tests/dstest_exec.cc Fri Jun 17 23:36:03 2022 +0200
16.2 +++ b/tests/dstest_exec.cc Fri Jun 17 23:54:54 2022 +0200
16.3 @@ -40,6 +40,8 @@
16.4
16.5
16.6
16.7 +/* External system-level pager for the region mapper in a created task. */
16.8 +
16.9 static ExternalPager exec_pager;
16.10
16.11 static const offset_t initial_stack_size = 16 * L4_PAGESIZE;
16.12 @@ -197,24 +199,29 @@
16.13
16.14 struct exec_region rm_regions[rm_payload->segments() + 2];
16.15 struct ipc_mapped_cap rm_mapped_caps[rm_payload->segments() + 3];
16.16 + l4_cap_idx_t mapped_cap;
16.17 unsigned int rm_index = 0;
16.18
16.19 - for (unsigned int i = 0; i < rm_payload->segments(); i++)
16.20 + for (unsigned int i = 0; i < program_payload->segments(); i++)
16.21 {
16.22 - Segment *s = rm_payload->segment(i);
16.23 + Segment *s = program_payload->segment(i);
16.24
16.25 if (s->loadable())
16.26 {
16.27 + mapped_cap = process.allocate_cap();
16.28 rm_regions[rm_index] = s->exec_region();
16.29 - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {process.allocate_cap(), rm_regions[rm_index].ds, L4_CAP_FPAGE_RWS};
16.30 + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {mapped_cap, rm_regions[rm_index].ds, L4_CAP_FPAGE_RWS, 0};
16.31 + rm_regions[rm_index].ds = mapped_cap;
16.32 rm_index++;
16.33 }
16.34 }
16.35
16.36 /* Introduce the stack region and capability. */
16.37
16.38 + mapped_cap = process.allocate_cap();
16.39 rm_regions[rm_index] = program_stack.exec_region();
16.40 - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {process.allocate_cap(), program_stack.exec_region().ds, L4_CAP_FPAGE_RWS};
16.41 + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {mapped_cap, program_stack.exec_region().ds, L4_CAP_FPAGE_RWS, 0};
16.42 + rm_regions[rm_index].ds = mapped_cap;
16.43 rm_index++;
16.44
16.45 /* Terminate the region array. */
16.46 @@ -225,18 +232,20 @@
16.47
16.48 l4_cap_idx_t ipc_gate_cap = process.allocate_cap();
16.49
16.50 - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {ipc_gate_cap, ipc_gate, L4_CAP_FPAGE_RWS};
16.51 + printf("Mapping %lx to %lx in task.\n", ipc_gate, ipc_gate_cap);
16.52 +
16.53 + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {ipc_gate_cap, ipc_gate, L4_CAP_FPAGE_RWS, L4_FPAGE_C_OBJ_RIGHTS};
16.54 rm_index++;
16.55
16.56 /* Terminate the capability array. */
16.57
16.58 - rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {0, L4_INVALID_CAP, 0};
16.59 + rm_mapped_caps[rm_index] = (struct ipc_mapped_cap) {0, L4_INVALID_CAP, 0, 0};
16.60
16.61 /* Map these additional capabilities. */
16.62
16.63 printf("Map additional capabilities...\n");
16.64
16.65 - process.map_capabilities(rm_mapped_caps);
16.66 + process.map_capabilities(rm_mapped_caps, false);
16.67
16.68 /* Define the IPC gate as an initial capability to be acquired by the region
16.69 mapper via the l4re_env API. The capability index is assigned above when
16.70 @@ -277,7 +286,7 @@
16.71 /* Configure the environment for the thread, specifying the pager (and
16.72 exception handler plus region mapper). */
16.73
16.74 - err = process.configure_thread(ipc_gate);
16.75 + err = process.configure_thread(ipc_gate, ipc_gate_cap);
16.76
16.77 if (err)
16.78 {
16.79 @@ -308,6 +317,7 @@
16.80 }
16.81
16.82 printf("Finished.\n");
16.83 +
16.84 while (1)
16.85 l4_sleep_forever();
16.86