1.1 --- a/Makefile Fri Feb 12 00:20:27 2021 +0100
1.2 +++ b/Makefile Fri Feb 12 00:21:03 2021 +0100
1.3 @@ -1,8 +1,11 @@
1.4 PKGDIR ?= .
1.5 L4DIR ?= $(PKGDIR)/../..
1.6
1.7 -TARGET = dstest_client dstest_server
1.8 -MODE = shared
1.9 +TARGET = \
1.10 + dstest_host_client dstest_test_client \
1.11 + dstest_host_server dstest_test_server
1.12 +
1.13 +MODE = static
1.14
1.15 # Locations for interface input and generated output.
1.16
1.17 @@ -37,28 +40,48 @@
1.18
1.19 COMMON_SRC_CC = memory_utils.cc
1.20
1.21 -PLAIN_SRC_CC_dstest_client = dstest_client.cc
1.22 +PLAIN_SRC_CC_dstest_host_client = dstest_host_client.cc
1.23 +
1.24 +PLAIN_SRC_CC_dstest_test_client = dstest_test_client.cc
1.25
1.26 -PLAIN_SRC_CC_dstest_server = \
1.27 +PLAIN_SRC_CC_dstest_host_server = \
1.28 access_map.cc accessing.cc accessor.cc \
1.29 - dstest_server.cc flexpage.cc file_pager.cc \
1.30 + dstest_host_server.cc flexpage.cc file_pager.cc \
1.31 + ipc.cc memory.cc \
1.32 + opener_resource.cc opener_context_resource.cc \
1.33 + page_mapper.cc page_queue.cc pager.cc pages.cc paging.cc \
1.34 + region.cc resource_server.cc simple_pager.cc \
1.35 + host_file_accessor.cc host_file_opener.cc
1.36 +
1.37 +PLAIN_SRC_CC_dstest_test_server = \
1.38 + access_map.cc accessing.cc accessor.cc \
1.39 + dstest_test_server.cc flexpage.cc file_pager.cc \
1.40 ipc.cc memory.cc \
1.41 opener_resource.cc opener_context_resource.cc \
1.42 page_mapper.cc page_queue.cc pager.cc pages.cc paging.cc \
1.43 region.cc resource_server.cc simple_pager.cc \
1.44 - host_file_accessor.cc host_file_opener.cc \
1.45 - test_file_accessor.cc test_file_opener.cc \
1.46 + test_file_accessor.cc test_file_opener.cc
1.47
1.48 # Normal definitions.
1.49
1.50 -SRC_CC_dstest_client = \
1.51 +SRC_CC_dstest_host_client = \
1.52 $(CLIENT_INTERFACES_SRC_CC) \
1.53 - $(PLAIN_SRC_CC_dstest_client) \
1.54 + $(PLAIN_SRC_CC_dstest_host_client) \
1.55 $(COMMON_SRC_CC)
1.56
1.57 -SRC_CC_dstest_server = \
1.58 +SRC_CC_dstest_test_client = \
1.59 + $(CLIENT_INTERFACES_SRC_CC) \
1.60 + $(PLAIN_SRC_CC_dstest_test_client) \
1.61 + $(COMMON_SRC_CC)
1.62 +
1.63 +SRC_CC_dstest_host_server = \
1.64 $(SERVER_INTERFACES_SRC_CC) \
1.65 - $(PLAIN_SRC_CC_dstest_server) \
1.66 + $(PLAIN_SRC_CC_dstest_host_server) \
1.67 + $(COMMON_SRC_CC)
1.68 +
1.69 +SRC_CC_dstest_test_server = \
1.70 + $(SERVER_INTERFACES_SRC_CC) \
1.71 + $(PLAIN_SRC_CC_dstest_test_server) \
1.72 $(COMMON_SRC_CC)
1.73
1.74 REQUIRES_LIBS = l4re_c-util libipc libstdc++
1.75 @@ -68,6 +91,10 @@
1.76 include $(L4DIR)/mk/prog.mk
1.77 include $(IDL_MK_DIR)/interface_rules.mk
1.78
1.79 -$(PLAIN_SRC_CC_dstest_client): $(CLIENT_INTERFACES_SRC_CC)
1.80 +$(PLAIN_SRC_CC_dstest_host_client): $(CLIENT_INTERFACES_SRC_CC)
1.81 +
1.82 +$(PLAIN_SRC_CC_dstest_test_client): $(CLIENT_INTERFACES_SRC_CC)
1.83
1.84 -$(PLAIN_SRC_CC_dstest_server): $(SERVER_INTERFACES_SRC_CC)
1.85 +$(PLAIN_SRC_CC_dstest_host_server): $(SERVER_INTERFACES_SRC_CC)
1.86 +
1.87 +$(PLAIN_SRC_CC_dstest_test_server): $(SERVER_INTERFACES_SRC_CC)
2.1 --- a/conf/dstest.cfg Fri Feb 12 00:20:27 2021 +0100
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,23 +0,0 @@
2.4 --- vim:set ft=lua:
2.5 -
2.6 -local L4 = require("L4");
2.7 -
2.8 -local l = L4.default_loader;
2.9 -
2.10 -local server = l:new_channel();
2.11 -
2.12 -l:start({
2.13 - caps = {
2.14 - server = server:svr(),
2.15 - },
2.16 - log = { "server", "r" },
2.17 - },
2.18 - "rom/dstest_server");
2.19 -
2.20 -l:start({
2.21 - caps = {
2.22 - server = server,
2.23 - },
2.24 - log = { "client", "g" },
2.25 - },
2.26 - "rom/dstest_client");
3.1 --- a/conf/dstest.list Fri Feb 12 00:20:27 2021 +0100
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,25 +0,0 @@
3.4 -entry dstest
3.5 -roottask moe rom/dstest.cfg
3.6 -module dstest.cfg
3.7 -module l4re
3.8 -module ned
3.9 -module dstest_client
3.10 -module dstest_server
3.11 -module lib4re-c.so
3.12 -module lib4re-c-util.so
3.13 -module lib4re.so
3.14 -module lib4re-util.so
3.15 -module libc_be_l4refile.so
3.16 -module libc_be_l4re.so
3.17 -module libc_be_socket_noop.so
3.18 -module libc_support_misc.so
3.19 -module libdl.so
3.20 -module libipc.so
3.21 -module libl4sys-direct.so
3.22 -module libl4sys.so
3.23 -module libl4util.so
3.24 -module libld-l4.so
3.25 -module libpthread.so
3.26 -module libstdc++.so
3.27 -module libsupc++.so
3.28 -module libuc_c.so
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/conf/dstest_host.cfg Fri Feb 12 00:21:03 2021 +0100
4.3 @@ -0,0 +1,23 @@
4.4 +-- vim:set ft=lua:
4.5 +
4.6 +local L4 = require("L4");
4.7 +
4.8 +local l = L4.default_loader;
4.9 +
4.10 +local server = l:new_channel();
4.11 +
4.12 +l:start({
4.13 + caps = {
4.14 + server = server:svr(),
4.15 + },
4.16 + log = { "server", "r" },
4.17 + },
4.18 + "rom/dstest_host_server");
4.19 +
4.20 +l:startv({
4.21 + caps = {
4.22 + server = server,
4.23 + },
4.24 + log = { "client", "g" },
4.25 + },
4.26 + "rom/dstest_host_client", "rom/dstest_host.cfg", 1024, 1024);
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/conf/dstest_host.list Fri Feb 12 00:21:03 2021 +0100
5.3 @@ -0,0 +1,25 @@
5.4 +entry dstest_host
5.5 +roottask moe rom/dstest_host.cfg
5.6 +module dstest_host.cfg
5.7 +module l4re
5.8 +module ned
5.9 +module dstest_host_client
5.10 +module dstest_host_server
5.11 +module lib4re-c.so
5.12 +module lib4re-c-util.so
5.13 +module lib4re.so
5.14 +module lib4re-util.so
5.15 +module libc_be_l4refile.so
5.16 +module libc_be_l4re.so
5.17 +module libc_be_socket_noop.so
5.18 +module libc_support_misc.so
5.19 +module libdl.so
5.20 +module libipc.so
5.21 +module libl4sys-direct.so
5.22 +module libl4sys.so
5.23 +module libl4util.so
5.24 +module libld-l4.so
5.25 +module libpthread.so
5.26 +module libstdc++.so
5.27 +module libsupc++.so
5.28 +module libuc_c.so
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/conf/dstest_test.cfg Fri Feb 12 00:21:03 2021 +0100
6.3 @@ -0,0 +1,23 @@
6.4 +-- vim:set ft=lua:
6.5 +
6.6 +local L4 = require("L4");
6.7 +
6.8 +local l = L4.default_loader;
6.9 +
6.10 +local server = l:new_channel();
6.11 +
6.12 +l:start({
6.13 + caps = {
6.14 + server = server:svr(),
6.15 + },
6.16 + log = { "server", "r" },
6.17 + },
6.18 + "rom/dstest_test_server");
6.19 +
6.20 +l:start({
6.21 + caps = {
6.22 + server = server,
6.23 + },
6.24 + log = { "client", "g" },
6.25 + },
6.26 + "rom/dstest_test_client");
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/conf/dstest_test.list Fri Feb 12 00:21:03 2021 +0100
7.3 @@ -0,0 +1,25 @@
7.4 +entry dstest_test
7.5 +roottask moe rom/dstest_test.cfg
7.6 +module dstest_test.cfg
7.7 +module l4re
7.8 +module ned
7.9 +module dstest_test_client
7.10 +module dstest_test_server
7.11 +module lib4re-c.so
7.12 +module lib4re-c-util.so
7.13 +module lib4re.so
7.14 +module lib4re-util.so
7.15 +module libc_be_l4refile.so
7.16 +module libc_be_l4re.so
7.17 +module libc_be_socket_noop.so
7.18 +module libc_support_misc.so
7.19 +module libdl.so
7.20 +module libipc.so
7.21 +module libl4sys-direct.so
7.22 +module libl4sys.so
7.23 +module libl4util.so
7.24 +module libld-l4.so
7.25 +module libpthread.so
7.26 +module libstdc++.so
7.27 +module libsupc++.so
7.28 +module libuc_c.so
8.1 --- a/dstest_client.cc Fri Feb 12 00:20:27 2021 +0100
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,163 +0,0 @@
8.4 -/*
8.5 - * Test dataspace operations.
8.6 - *
8.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
8.8 - *
8.9 - * This program is free software; you can redistribute it and/or
8.10 - * modify it under the terms of the GNU General Public License as
8.11 - * published by the Free Software Foundation; either version 2 of
8.12 - * the License, or (at your option) any later version.
8.13 - *
8.14 - * This program is distributed in the hope that it will be useful,
8.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.17 - * GNU General Public License for more details.
8.18 - *
8.19 - * You should have received a copy of the GNU General Public License
8.20 - * along with this program; if not, write to the Free Software
8.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
8.22 - * Boston, MA 02110-1301, USA
8.23 - */
8.24 -
8.25 -#include <l4/re/env.h>
8.26 -#include <l4/sys/err.h>
8.27 -
8.28 -#include <stdio.h>
8.29 -#include <string.h>
8.30 -#include <stdlib.h>
8.31 -
8.32 -#include <ipc/mem_ipc.h>
8.33 -
8.34 -#include "dataspace_client.h"
8.35 -#include "opener_client.h"
8.36 -#include "opener_context_client.h"
8.37 -#include "mapped_file_client.h"
8.38 -#include "memory_utils.h"
8.39 -
8.40 -
8.41 -
8.42 -int main(int argc, char *argv[])
8.43 -{
8.44 - if (argc < 4)
8.45 - {
8.46 - printf("Need filename, step and sample size.\n");
8.47 - return 1;
8.48 - }
8.49 -
8.50 - /* Obtain filename and access parameters. */
8.51 -
8.52 - char *filename = argv[1];
8.53 - unsigned long step = atoi(argv[2]);
8.54 - unsigned long sample = atoi(argv[3]);
8.55 -
8.56 - /* Allocate a buffer for sampling from the file. */
8.57 -
8.58 - char buf[sample + 1];
8.59 -
8.60 - /* Obtain access to the filesystem. */
8.61 -
8.62 - l4_cap_idx_t server = l4re_env_get_cap("server");
8.63 - l4_cap_idx_t context_ref;
8.64 - client_Opener opener(server);
8.65 -
8.66 - long err = opener.context(&context_ref);
8.67 -
8.68 - if (err)
8.69 - {
8.70 - printf("Could not obtain context: %s\n", l4sys_errtostr(err));
8.71 - return 1;
8.72 - }
8.73 -
8.74 - client_OpenerContext context(context_ref);
8.75 - client_Dataspace context_ds(context_ref);
8.76 - unsigned long size, flags;
8.77 -
8.78 - err = context_ds.info(&size, &flags);
8.79 -
8.80 - if (err)
8.81 - {
8.82 - printf("Could not obtain context info: %s\n", l4sys_errtostr(err));
8.83 - return 1;
8.84 - }
8.85 -
8.86 - /* Map context memory to write the filename. */
8.87 -
8.88 - char *memory;
8.89 -
8.90 - printf("Attach region of size %ld...\n", size);
8.91 -
8.92 - err = ipc_attach_dataspace(context_ref, size, (void **) &memory);
8.93 -
8.94 - if (err)
8.95 - {
8.96 - printf("Could not map memory: %s\n", l4sys_errtostr(err));
8.97 - return 1;
8.98 - }
8.99 -
8.100 - printf("Mapped memory at %p\n", memory);
8.101 -
8.102 - /* Write the filename. */
8.103 -
8.104 - strcpy(memory, filename);
8.105 -
8.106 - /* Invoke the open method to receive the file reference. */
8.107 -
8.108 - l4_cap_idx_t file;
8.109 -
8.110 - err = context.open(L4_FPAGE_RW, &size, &file);
8.111 -
8.112 - if (err)
8.113 - {
8.114 - printf("Could not obtain file: %s\n", l4sys_errtostr(err));
8.115 - return 1;
8.116 - }
8.117 -
8.118 - client_MappedFile obj(file);
8.119 -
8.120 - /* Some memory to be mapped. */
8.121 -
8.122 - size_t start_pos, end_pos, data_end;
8.123 -
8.124 - printf("Map region from %ld to %ld...\n", 0L, page(10));
8.125 -
8.126 - err = obj.mmap(0, page(10), &start_pos, &end_pos, &data_end);
8.127 -
8.128 - if (err)
8.129 - {
8.130 - printf("Could not map file region: %s\n", l4sys_errtostr(err));
8.131 - return 1;
8.132 - }
8.133 -
8.134 - printf("Mapped region from %ld to %ld with content %ld.\n",
8.135 - start_pos, end_pos, data_end);
8.136 -
8.137 - size = end_pos - start_pos;
8.138 -
8.139 - printf("Attach region of size %ld...\n", size);
8.140 -
8.141 - err = ipc_attach_dataspace(file, size, (void **) &memory);
8.142 -
8.143 - if (err)
8.144 - {
8.145 - printf("Could not map memory: %s\n", l4sys_errtostr(err));
8.146 - return 1;
8.147 - }
8.148 -
8.149 - printf("Mapped memory at %p\n", memory);
8.150 -
8.151 - if (data_end < size)
8.152 - size = data_end;
8.153 -
8.154 - for (unsigned long offset = 0; offset < size; offset += step)
8.155 - {
8.156 - unsigned long remaining = size - offset;
8.157 - unsigned long sample_remaining = remaining < sample ? remaining : sample;
8.158 -
8.159 - printf("%ld bytes from %p...\n", sample_remaining, (memory + offset));
8.160 - strncpy(buf, (memory + offset), sample_remaining);
8.161 - buf[sample_remaining] = '\0';
8.162 - printf("%s\n", buf);
8.163 - }
8.164 -
8.165 - return 0;
8.166 -}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/dstest_host_client.cc Fri Feb 12 00:21:03 2021 +0100
9.3 @@ -0,0 +1,163 @@
9.4 +/*
9.5 + * Test dataspace operations.
9.6 + *
9.7 + * Copyright (C) 2020, 2021 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 +#include <l4/sys/err.h>
9.27 +
9.28 +#include <stdio.h>
9.29 +#include <string.h>
9.30 +#include <stdlib.h>
9.31 +
9.32 +#include <ipc/mem_ipc.h>
9.33 +
9.34 +#include "dataspace_client.h"
9.35 +#include "opener_client.h"
9.36 +#include "opener_context_client.h"
9.37 +#include "mapped_file_client.h"
9.38 +#include "memory_utils.h"
9.39 +
9.40 +
9.41 +
9.42 +int main(int argc, char *argv[])
9.43 +{
9.44 + if (argc < 4)
9.45 + {
9.46 + printf("Need filename, step and sample size.\n");
9.47 + return 1;
9.48 + }
9.49 +
9.50 + /* Obtain filename and access parameters. */
9.51 +
9.52 + char *filename = argv[1];
9.53 + unsigned long step = atoi(argv[2]);
9.54 + unsigned long sample = atoi(argv[3]);
9.55 +
9.56 + /* Allocate a buffer for sampling from the file. */
9.57 +
9.58 + char buf[sample + 1];
9.59 +
9.60 + /* Obtain access to the filesystem. */
9.61 +
9.62 + l4_cap_idx_t server = l4re_env_get_cap("server");
9.63 + l4_cap_idx_t context_ref;
9.64 + client_Opener opener(server);
9.65 +
9.66 + long err = opener.context(&context_ref);
9.67 +
9.68 + if (err)
9.69 + {
9.70 + printf("Could not obtain context: %s\n", l4sys_errtostr(err));
9.71 + return 1;
9.72 + }
9.73 +
9.74 + client_OpenerContext context(context_ref);
9.75 + client_Dataspace context_ds(context_ref);
9.76 + unsigned long size, flags;
9.77 +
9.78 + err = context_ds.info(&size, &flags);
9.79 +
9.80 + if (err)
9.81 + {
9.82 + printf("Could not obtain context info: %s\n", l4sys_errtostr(err));
9.83 + return 1;
9.84 + }
9.85 +
9.86 + /* Map context memory to write the filename. */
9.87 +
9.88 + char *memory;
9.89 +
9.90 + printf("Attach region of size %ld...\n", size);
9.91 +
9.92 + err = ipc_attach_dataspace(context_ref, size, (void **) &memory);
9.93 +
9.94 + if (err)
9.95 + {
9.96 + printf("Could not map memory: %s\n", l4sys_errtostr(err));
9.97 + return 1;
9.98 + }
9.99 +
9.100 + printf("Mapped memory at %p\n", memory);
9.101 +
9.102 + /* Write the filename. */
9.103 +
9.104 + strcpy(memory, filename);
9.105 +
9.106 + /* Invoke the open method to receive the file reference. */
9.107 +
9.108 + l4_cap_idx_t file;
9.109 +
9.110 + err = context.open(L4_FPAGE_RW, &size, &file);
9.111 +
9.112 + if (err)
9.113 + {
9.114 + printf("Could not obtain file: %s\n", l4sys_errtostr(err));
9.115 + return 1;
9.116 + }
9.117 +
9.118 + client_MappedFile obj(file);
9.119 +
9.120 + /* Some memory to be mapped. */
9.121 +
9.122 + size_t start_pos, end_pos, data_end;
9.123 +
9.124 + printf("Map region from %ld to %ld...\n", 0L, page(10));
9.125 +
9.126 + err = obj.mmap(0, page(10), &start_pos, &end_pos, &data_end);
9.127 +
9.128 + if (err)
9.129 + {
9.130 + printf("Could not map file region: %s\n", l4sys_errtostr(err));
9.131 + return 1;
9.132 + }
9.133 +
9.134 + printf("Mapped region from %ld to %ld with content %ld.\n",
9.135 + start_pos, end_pos, data_end);
9.136 +
9.137 + size = end_pos - start_pos;
9.138 +
9.139 + printf("Attach region of size %ld...\n", size);
9.140 +
9.141 + err = ipc_attach_dataspace(file, size, (void **) &memory);
9.142 +
9.143 + if (err)
9.144 + {
9.145 + printf("Could not map memory: %s\n", l4sys_errtostr(err));
9.146 + return 1;
9.147 + }
9.148 +
9.149 + printf("Mapped memory at %p\n", memory);
9.150 +
9.151 + if (data_end < size)
9.152 + size = data_end;
9.153 +
9.154 + for (unsigned long offset = 0; offset < size; offset += step)
9.155 + {
9.156 + unsigned long remaining = size - offset;
9.157 + unsigned long sample_remaining = remaining < sample ? remaining : sample;
9.158 +
9.159 + printf("%ld bytes from %p...\n", sample_remaining, (memory + offset));
9.160 + strncpy(buf, (memory + offset), sample_remaining);
9.161 + buf[sample_remaining] = '\0';
9.162 + printf("%s\n", buf);
9.163 + }
9.164 +
9.165 + return 0;
9.166 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/dstest_host_server.cc Fri Feb 12 00:21:03 2021 +0100
10.3 @@ -0,0 +1,65 @@
10.4 +/*
10.5 + * Test dataspace operations.
10.6 + *
10.7 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
10.8 + *
10.9 + * This program is free software; you can redistribute it and/or
10.10 + * modify it under the terms of the GNU General Public License as
10.11 + * published by the Free Software Foundation; either version 2 of
10.12 + * the License, or (at your option) any later version.
10.13 + *
10.14 + * This program is distributed in the hope that it will be useful,
10.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.17 + * GNU General Public License for more details.
10.18 + *
10.19 + * You should have received a copy of the GNU General Public License
10.20 + * along with this program; if not, write to the Free Software
10.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
10.22 + * Boston, MA 02110-1301, USA
10.23 + */
10.24 +
10.25 +#include <l4/re/env.h>
10.26 +#include <l4/sys/err.h>
10.27 +
10.28 +#include <stdio.h>
10.29 +#include <string.h>
10.30 +#include <stdlib.h>
10.31 +
10.32 +#include "accessing.h"
10.33 +#include "memory.h"
10.34 +#include "memory_utils.h"
10.35 +#include "pages.h"
10.36 +#include "paging.h"
10.37 +#include "resource_server.h"
10.38 +#include "host_file_opener.h"
10.39 +
10.40 +
10.41 +
10.42 +const unsigned int MEMORY_PAGES = 10;
10.43 +
10.44 +int main(void)
10.45 +{
10.46 + /* Some memory plus infrastructure. */
10.47 +
10.48 + Memory mem(MEMORY_PAGES);
10.49 + Accessing accessing;
10.50 + Paging paging;
10.51 + Pages pages(&mem);
10.52 + HostFileOpener opener(&accessing, &paging, &pages);
10.53 +
10.54 + /* Register a server associating it with the given object. */
10.55 +
10.56 + ResourceServer server(&opener);
10.57 + long err = server.bind("server");
10.58 +
10.59 + if (err)
10.60 + {
10.61 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
10.62 + return 1;
10.63 + }
10.64 +
10.65 + printf("Starting server...\n");
10.66 + server.start();
10.67 + return 0;
10.68 +}
11.1 --- a/dstest_server.cc Fri Feb 12 00:20:27 2021 +0100
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,68 +0,0 @@
11.4 -/*
11.5 - * Test dataspace operations.
11.6 - *
11.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
11.8 - *
11.9 - * This program is free software; you can redistribute it and/or
11.10 - * modify it under the terms of the GNU General Public License as
11.11 - * published by the Free Software Foundation; either version 2 of
11.12 - * the License, or (at your option) any later version.
11.13 - *
11.14 - * This program is distributed in the hope that it will be useful,
11.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.17 - * GNU General Public License for more details.
11.18 - *
11.19 - * You should have received a copy of the GNU General Public License
11.20 - * along with this program; if not, write to the Free Software
11.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
11.22 - * Boston, MA 02110-1301, USA
11.23 - */
11.24 -
11.25 -#include <l4/re/env.h>
11.26 -#include <l4/sys/err.h>
11.27 -
11.28 -#include <stdio.h>
11.29 -#include <string.h>
11.30 -#include <stdlib.h>
11.31 -
11.32 -#include "accessing.h"
11.33 -#include "memory.h"
11.34 -#include "memory_utils.h"
11.35 -#include "pages.h"
11.36 -#include "paging.h"
11.37 -#include "resource_server.h"
11.38 -#include "host_file_opener.h"
11.39 -// #include "test_file_opener.h"
11.40 -
11.41 -
11.42 -
11.43 -const unsigned int MEMORY_PAGES = 10;
11.44 -const unsigned int FILE_PAGES = 20;
11.45 -
11.46 -int main(void)
11.47 -{
11.48 - /* Some memory plus infrastructure. */
11.49 -
11.50 - Memory mem(MEMORY_PAGES);
11.51 - Accessing accessing;
11.52 - Paging paging;
11.53 - Pages pages(&mem);
11.54 - HostFileOpener opener(&accessing, &paging, &pages);
11.55 - // TestFileOpener opener(&accessing, &paging, &pages, page(FILE_PAGES));
11.56 -
11.57 - /* Register a server associating it with the given object. */
11.58 -
11.59 - ResourceServer server(&opener);
11.60 - long err = server.bind("server");
11.61 -
11.62 - if (err)
11.63 - {
11.64 - printf("Could not bind server: %s\n", l4sys_errtostr(err));
11.65 - return 1;
11.66 - }
11.67 -
11.68 - printf("Starting server...\n");
11.69 - server.start();
11.70 - return 0;
11.71 -}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/dstest_test_client.cc Fri Feb 12 00:21:03 2021 +0100
12.3 @@ -0,0 +1,314 @@
12.4 +/*
12.5 + * Test dataspace operations.
12.6 + *
12.7 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
12.8 + *
12.9 + * This program is free software; you can redistribute it and/or
12.10 + * modify it under the terms of the GNU General Public License as
12.11 + * published by the Free Software Foundation; either version 2 of
12.12 + * the License, or (at your option) any later version.
12.13 + *
12.14 + * This program is distributed in the hope that it will be useful,
12.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12.17 + * GNU General Public License for more details.
12.18 + *
12.19 + * You should have received a copy of the GNU General Public License
12.20 + * along with this program; if not, write to the Free Software
12.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
12.22 + * Boston, MA 02110-1301, USA
12.23 + */
12.24 +
12.25 +#include <l4/re/env.h>
12.26 +#include <l4/sys/err.h>
12.27 +
12.28 +#include <stdio.h>
12.29 +#include <string.h>
12.30 +#include <stdlib.h>
12.31 +
12.32 +#include <mutex>
12.33 +#include <set>
12.34 +#include <thread>
12.35 +
12.36 +#include <ipc/cap_alloc.h>
12.37 +#include <ipc/mem_ipc.h>
12.38 +
12.39 +#include "dataspace_client.h"
12.40 +#include "opener_client.h"
12.41 +#include "opener_context_client.h"
12.42 +#include "mapped_file_client.h"
12.43 +#include "memory_utils.h"
12.44 +
12.45 +
12.46 +
12.47 +const unsigned int ACTIVITY_ITERATIONS = 100;
12.48 +const unsigned long NUMBER_OF_FILES = 10;
12.49 +const unsigned int START_LIMIT = 10;
12.50 +const unsigned int MAP_PAGES = 20;
12.51 +
12.52 +
12.53 +
12.54 +static std::mutex _lock;
12.55 +static std::set<void *> _memory;
12.56 +
12.57 +static long attach_dataspace(l4_cap_idx_t cap, unsigned long size, void **memory)
12.58 +{
12.59 + std::lock_guard<std::mutex> guard(_lock);
12.60 +
12.61 + long err = ipc_attach_dataspace(cap, size, memory);
12.62 +
12.63 + if (err)
12.64 + return err;
12.65 +
12.66 + if (_memory.find(*memory) != _memory.end())
12.67 + {
12.68 + printf("Memory assigned again: %p\n", *memory);
12.69 + return -L4_EINVAL;
12.70 + }
12.71 +
12.72 + _memory.insert(*memory);
12.73 + return L4_EOK;
12.74 +}
12.75 +
12.76 +static long detach_dataspace(void *memory)
12.77 +{
12.78 + std::lock_guard<std::mutex> guard(_lock);
12.79 +
12.80 + _memory.erase(memory);
12.81 + return ipc_detach_dataspace(memory);
12.82 +}
12.83 +
12.84 +
12.85 +
12.86 +static long activity(l4_cap_idx_t context_ref, unsigned long fileid, unsigned int start_page)
12.87 +{
12.88 + client_OpenerContext context(context_ref);
12.89 + unsigned long step = page(1);
12.90 + unsigned long sample = page(1);
12.91 +
12.92 + /* Allocate a buffer for sampling from the file. */
12.93 +
12.94 + char buf[sample + 1];
12.95 +
12.96 + /* Invoke the open method to receive the file reference. */
12.97 +
12.98 + unsigned long size;
12.99 + l4_cap_idx_t file_ref;
12.100 +
12.101 + long err = context.open(L4_FPAGE_RW, &size, &file_ref);
12.102 +
12.103 + if (err)
12.104 + {
12.105 + printf("Could not obtain file for %ld @ page %d: %s\n", fileid, start_page, l4sys_errtostr(err));
12.106 + return err;
12.107 + }
12.108 +
12.109 + client_MappedFile file(file_ref);
12.110 +
12.111 + /* Some memory to be mapped. */
12.112 +
12.113 + size_t start_pos, end_pos, data_end;
12.114 +
12.115 + err = file.mmap(page(start_page), page(MAP_PAGES), &start_pos, &end_pos, &data_end);
12.116 +
12.117 + if (err)
12.118 + {
12.119 + printf("Could not map file region for %ld @ page %d: %s\n", fileid, start_page, l4sys_errtostr(err));
12.120 + ipc_cap_free_um(file_ref);
12.121 + return err;
12.122 + }
12.123 +
12.124 + //printf("Mapped region from %ld to %ld with content %ld.\n",
12.125 + // start_pos, end_pos, data_end);
12.126 +
12.127 + size = end_pos - start_pos;
12.128 +
12.129 + //printf("Attach region of size %ld...\n", size);
12.130 +
12.131 + char *memory;
12.132 +
12.133 + err = attach_dataspace(file_ref, size, (void **) &memory);
12.134 +
12.135 + if (err)
12.136 + {
12.137 + printf("Could not map memory for %ld @ page %d: %s\n", fileid, start_page, l4sys_errtostr(err));
12.138 + ipc_cap_free_um(file_ref);
12.139 + return err;
12.140 + }
12.141 +
12.142 + //printf("Mapped memory from %lx / %ld at %p\n", file_ref, page(start_page), memory);
12.143 +
12.144 + if (data_end < size)
12.145 + size = data_end;
12.146 +
12.147 + for (unsigned long offset = 0; offset < size; offset += step)
12.148 + {
12.149 + unsigned long remaining = size - offset;
12.150 + unsigned long sample_remaining = remaining < sample ? remaining : sample;
12.151 +
12.152 + strncpy(buf, (memory + offset), sample_remaining);
12.153 + buf[sample_remaining] = '\0';
12.154 + //printf("%p: %s\n", (memory + offset), buf);
12.155 +
12.156 + /* Test the data obtained. */
12.157 +
12.158 + unsigned long filepos = start_pos + offset;
12.159 + unsigned long _fileid = 0, _filepos = 0;
12.160 + char *sep = strchr(buf, ':');
12.161 +
12.162 + if (sep != NULL)
12.163 + {
12.164 + *sep = '\0'; sep++;
12.165 + _fileid = atol(buf); _filepos = atol(sep);
12.166 + }
12.167 +
12.168 + if ((fileid != _fileid) || (filepos != _filepos))
12.169 + printf("! %ld:%ld is not %ld:%ld\n", _fileid, _filepos, fileid, filepos);
12.170 + }
12.171 +
12.172 + detach_dataspace(memory);
12.173 +
12.174 + //printf("Unmapped memory from %ld at %p\n", page(start_page), memory);
12.175 +
12.176 + ipc_cap_free_um(file_ref);
12.177 +
12.178 + return L4_EOK;
12.179 +}
12.180 +
12.181 +
12.182 +
12.183 +static long activity_iterate(l4_cap_idx_t context_ref, unsigned long fileid, unsigned int start_page)
12.184 +{
12.185 + long err;
12.186 +
12.187 + /* Open the file, read pages, close the file, over and over. */
12.188 +
12.189 + for (unsigned int iteration = 0; iteration < ACTIVITY_ITERATIONS; iteration++)
12.190 + {
12.191 + err = activity(context_ref, fileid, start_page);
12.192 + if (err)
12.193 + break;
12.194 + }
12.195 +
12.196 + //printf("Ending: %ld @ %d\n", fileid, start_page);
12.197 + return err;
12.198 +}
12.199 +
12.200 +
12.201 +
12.202 +static long context_for_file(unsigned long fileid, l4_cap_idx_t *context_ref, char **filename)
12.203 +{
12.204 + /* Obtain access to the filesystem. */
12.205 +
12.206 + l4_cap_idx_t server = l4re_env_get_cap("server");
12.207 + client_Opener opener(server);
12.208 +
12.209 + long err = opener.context(context_ref);
12.210 +
12.211 + if (err)
12.212 + {
12.213 + printf("Could not obtain context: %s\n", l4sys_errtostr(err));
12.214 + return err;
12.215 + }
12.216 +
12.217 + client_Dataspace context_ds(*context_ref);
12.218 + unsigned long size, flags;
12.219 +
12.220 + err = context_ds.info(&size, &flags);
12.221 +
12.222 + if (err)
12.223 + {
12.224 + printf("Could not obtain context info: %s\n", l4sys_errtostr(err));
12.225 + ipc_cap_free_um(*context_ref);
12.226 + return err;
12.227 + }
12.228 +
12.229 + /* Map context memory to write the filename. */
12.230 +
12.231 + err = attach_dataspace(*context_ref, size, (void **) filename);
12.232 +
12.233 + if (err)
12.234 + {
12.235 + printf("Could not map memory: %s\n", l4sys_errtostr(err));
12.236 + ipc_cap_free_um(*context_ref);
12.237 + return err;
12.238 + }
12.239 +
12.240 + /* Write the filename. */
12.241 +
12.242 + sprintf(*filename, "%ld", fileid);
12.243 +
12.244 + return L4_EOK;
12.245 +}
12.246 +
12.247 +
12.248 +
12.249 +static long activity_for_file(unsigned long fileid)
12.250 +{
12.251 + std::thread *activities[START_LIMIT];
12.252 +
12.253 + l4_cap_idx_t context_ref;
12.254 + char *filename;
12.255 + int current = 0;
12.256 +
12.257 + long err = context_for_file(fileid, &context_ref, &filename);
12.258 +
12.259 + if (err)
12.260 + return err;
12.261 +
12.262 + for (unsigned int start_page = 0; start_page < START_LIMIT; start_page++)
12.263 + activities[current++] = new std::thread(activity_iterate, context_ref, fileid, start_page);
12.264 +
12.265 + /* Wait for the threads. */
12.266 +
12.267 + int limit = current;
12.268 +
12.269 + printf("Waiting for %d threads for %ld...\n", limit, fileid);
12.270 +
12.271 + for (current = 0; current < limit; current++)
12.272 + {
12.273 + activities[current]->join();
12.274 + printf("End: %ld @ %d\n", fileid, current);
12.275 + }
12.276 +
12.277 + /* Discard the context. */
12.278 +
12.279 + detach_dataspace(filename);
12.280 + ipc_cap_free_um(context_ref);
12.281 +
12.282 + printf("End: %ld\n", fileid);
12.283 + return L4_EOK;
12.284 +}
12.285 +
12.286 +
12.287 +
12.288 +int main(void)
12.289 +{
12.290 + /* Introduce concurrency control. */
12.291 +
12.292 + ipc_cap_alloc_init();
12.293 +
12.294 + std::thread *activities[NUMBER_OF_FILES];
12.295 +
12.296 + unsigned long fileid;
12.297 + int current = 0;
12.298 +
12.299 + for (fileid = 0; fileid < NUMBER_OF_FILES; fileid++)
12.300 + activities[current++] = new std::thread(activity_for_file, fileid);
12.301 +
12.302 + /* Wait for the threads. */
12.303 +
12.304 + int limit = current;
12.305 +
12.306 + printf("Waiting for %d threads...\n", limit);
12.307 +
12.308 + for (current = 0; current < limit; current++)
12.309 + {
12.310 + activities[current]->join();
12.311 + printf("Ended: %d\n", current);
12.312 + }
12.313 +
12.314 + printf("Activities completed.\n");
12.315 +
12.316 + return 0;
12.317 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/dstest_test_server.cc Fri Feb 12 00:21:03 2021 +0100
13.3 @@ -0,0 +1,72 @@
13.4 +/*
13.5 + * Test dataspace operations.
13.6 + *
13.7 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
13.8 + *
13.9 + * This program is free software; you can redistribute it and/or
13.10 + * modify it under the terms of the GNU General Public License as
13.11 + * published by the Free Software Foundation; either version 2 of
13.12 + * the License, or (at your option) any later version.
13.13 + *
13.14 + * This program is distributed in the hope that it will be useful,
13.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13.17 + * GNU General Public License for more details.
13.18 + *
13.19 + * You should have received a copy of the GNU General Public License
13.20 + * along with this program; if not, write to the Free Software
13.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
13.22 + * Boston, MA 02110-1301, USA
13.23 + */
13.24 +
13.25 +#include <l4/re/env.h>
13.26 +#include <l4/sys/err.h>
13.27 +
13.28 +#include <ipc/cap_alloc.h>
13.29 +
13.30 +#include <stdio.h>
13.31 +#include <string.h>
13.32 +#include <stdlib.h>
13.33 +
13.34 +#include "accessing.h"
13.35 +#include "memory.h"
13.36 +#include "memory_utils.h"
13.37 +#include "pages.h"
13.38 +#include "paging.h"
13.39 +#include "resource_server.h"
13.40 +#include "test_file_opener.h"
13.41 +
13.42 +
13.43 +
13.44 +const unsigned int MEMORY_PAGES = 10;
13.45 +const unsigned int FILE_PAGES = 20;
13.46 +
13.47 +int main(void)
13.48 +{
13.49 + /* Introduce concurrency control. */
13.50 +
13.51 + ipc_cap_alloc_init();
13.52 +
13.53 + /* Some memory plus infrastructure. */
13.54 +
13.55 + Memory mem(MEMORY_PAGES);
13.56 + Accessing accessing;
13.57 + Paging paging;
13.58 + Pages pages(&mem);
13.59 + TestFileOpener opener(&accessing, &paging, &pages, page(FILE_PAGES));
13.60 +
13.61 + /* Register a server associating it with the given object. */
13.62 +
13.63 + ResourceServer server(&opener);
13.64 + long err = server.bind("server");
13.65 +
13.66 + if (err)
13.67 + {
13.68 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
13.69 + return 1;
13.70 + }
13.71 +
13.72 + printf("Starting server...\n");
13.73 + server.start();
13.74 + return 0;
13.75 +}