# HG changeset patch # User Paul Boddie # Date 1705277921 -3600 # Node ID abb6e29facd69f4fb64808083fafb6863e9e0d69 # Parent f7b76a66eb29c77fca5c4573c8867a4fe9530cd5 Added initial support for running programs within fsaccess. Note that the filesystem server page allocation needs to be increased to provide adequate performance; otherwise, thousands of page faults occur trying to service the memory accesses involved in running a test payload. diff -r f7b76a66eb29 -r abb6e29facd6 conf/dstest_fsaccess.cfg --- a/conf/dstest_fsaccess.cfg Mon Jan 15 00:05:01 2024 +0100 +++ b/conf/dstest_fsaccess.cfg Mon Jan 15 01:18:41 2024 +0100 @@ -37,16 +37,30 @@ }, log = { "ext2svr", "y" }, }, - "rom/ext2_server", "blockserver", "rom/e2test.fs", "10", "fsserver"); + "rom/ext2_server", "blockserver", "rom/e2test.fs", "20", "fsserver"); -- Obtain user filesystems with umask 0022 (18). local open_for_user = 6; local ext2server_paulb = L4.cast(L4.Proto.Factory, ext2server):create(open_for_user, 1000, 1000, 18); +local process_server = l:new_channel(); + l:startv({ caps = { fsserver = ext2server_paulb, + prserver = process_server:svr(), + jdb = L4.Env.jdb, -- to set the server name + }, + log = { "process", "y" }, + }, + "rom/process_server", "home/paulb/exec_region_mapper"); + +l:startv({ + caps = { + fsserver = ext2server_paulb, + pipeserver = pipe_server, + prserver = process_server, }, log = { "client", "g" }, }, diff -r f7b76a66eb29 -r abb6e29facd6 conf/dstest_fsaccess.list --- a/conf/dstest_fsaccess.list Mon Jan 15 00:05:01 2024 +0100 +++ b/conf/dstest_fsaccess.list Mon Jan 15 01:18:41 2024 +0100 @@ -9,6 +9,7 @@ module ext2_server module block_server module pipe_server +module process_server module lib4re-c.so module lib4re-c-util.so module lib4re.so diff -r f7b76a66eb29 -r abb6e29facd6 conf/dstest_fsaccess_stdin.cfg --- a/conf/dstest_fsaccess_stdin.cfg Mon Jan 15 00:05:01 2024 +0100 +++ b/conf/dstest_fsaccess_stdin.cfg Mon Jan 15 01:18:41 2024 +0100 @@ -37,19 +37,32 @@ }, log = { "ext2svr", "y" }, }, - "rom/ext2_server", "blockserver", "rom/e2test.fs", "10", "fsserver"); + "rom/ext2_server", "blockserver", "rom/e2test.fs", "20", "fsserver"); -- Obtain user filesystems with umask 0022 (18). local open_for_user = 6; local ext2server_paulb = L4.cast(L4.Proto.Factory, ext2server):create(open_for_user, 1000, 1000, 18); +local process_server = l:new_channel(); + +l:startv({ + caps = { + fsserver = ext2server_paulb, + prserver = process_server:svr(), + jdb = L4.Env.jdb, -- to set the server name + }, + log = { "process", "y" }, + }, + "rom/process_server", "home/paulb/exec_region_mapper"); + l:startv({ log = L4.Env.log, caps = { fsserver = ext2server_paulb, + pipeserver = pipe_server, + prserver = process_server, }, - -- log = { "client", "g" }, }, -- program, options, operation involving a script file "rom/fsaccess", "-m", "0022", "script", "-"); diff -r f7b76a66eb29 -r abb6e29facd6 conf/dstest_fsaccess_stdin.list --- a/conf/dstest_fsaccess_stdin.list Mon Jan 15 00:05:01 2024 +0100 +++ b/conf/dstest_fsaccess_stdin.list Mon Jan 15 01:18:41 2024 +0100 @@ -9,6 +9,7 @@ module ext2_server module block_server module pipe_server +module process_server module lib4re-c.so module lib4re-c-util.so module lib4re.so diff -r f7b76a66eb29 -r abb6e29facd6 fsaccess/Control --- a/fsaccess/Control Mon Jan 15 00:05:01 2024 +0100 +++ b/fsaccess/Control Mon Jan 15 01:18:41 2024 +0100 @@ -1,3 +1,3 @@ -requires: libc libipc libfsclient libmem libext2fs libext2fs_blockserver libe2access_blockserver +requires: libc libipc libfsclient libmem libext2fs libext2fs_blockserver libe2access_blockserver fsservers provides: fsaccess maintainer: paul@boddie.org.uk diff -r f7b76a66eb29 -r abb6e29facd6 fsaccess/Makefile --- a/fsaccess/Makefile Mon Jan 15 00:05:01 2024 +0100 +++ b/fsaccess/Makefile Mon Jan 15 01:18:41 2024 +0100 @@ -8,7 +8,7 @@ SRC_C = \ file.c fsaccess.c input.c session.c ops.c \ op_copy_in.c op_list_objects.c op_make_dirs.c op_remove.c \ - op_script.c op_stat_objects.c + op_run.c op_script.c op_stat_objects.c REQUIRES_LIBS = l4re_c-util libfsclient libmem libipc libsystypes libe2access libe2access_blockserver diff -r f7b76a66eb29 -r abb6e29facd6 fsaccess/fsaccess.c --- a/fsaccess/fsaccess.c Mon Jan 15 00:05:01 2024 +0100 +++ b/fsaccess/fsaccess.c Mon Jan 15 01:18:41 2024 +0100 @@ -51,6 +51,9 @@ Script operations:\n\ \n\ script Read operations from a script file (or stdin)\n\ +Execution operations:\n\ +\n\ + run Run a program from the filesystem\n\ "; /* Operations exposed by the program. */ @@ -61,6 +64,7 @@ {"mkdir", make_dirs}, {"rm", remove_non_dirs}, {"rmdir", remove_dirs}, + {"run", run_program}, {"script", run_script}, {"stat", stat_objects}, {NULL, NULL}, diff -r f7b76a66eb29 -r abb6e29facd6 fsaccess/op_run.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fsaccess/op_run.c Mon Jan 15 01:18:41 2024 +0100 @@ -0,0 +1,105 @@ +/* + * Run a program residing in the filesystem. + * + * Copyright (C) 2022, 2023, 2024 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 + +#include "ops.h" + + + +/* Transfer size for communication. */ + +static const offset_t TO_TRANSFER = 1024; + + + +/* Run the given program. */ + +int run_program(int argc, char *argv[]) +{ + char buffer[TO_TRANSFER]; + process_t *process; + file_t *reader, *writer; + notify_flags_t flags; + notify_values_t values; + long err; + + /* Create a pipe for process output. */ + + err = client_pipe(&reader, &writer, 0); + + if (err) + { + printf("Could not obtain pipe: %s\n", l4sys_errtostr(err)); + return 1; + } + + /* Start the process. */ + + err = process_spawn(argc, (const char **) argv, writer, &process); + + if (err) + { + printf("Could not start process: %s\n", l4sys_errtostr(err)); + return 1; + } + + printf("Finished program initiation.\n"); + + /* Release the writing end of the pipe. */ + + client_close(writer); + + /* Read until the pipe yields no more data. */ + + while (1) + { + offset_t nread = client_read(reader, buffer, TO_TRANSFER); + + if (nread) + fwrite(buffer, sizeof(char), nread, stdout); + else + break; + } + + /* Close the pipe and obtain the process state. */ + + client_close(reader); + + err = process_wait(process, &flags, &values); + + printf("End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", flags, values.sig, values.val); + + if (err) + return 1; + + return 0; +} + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/ diff -r f7b76a66eb29 -r abb6e29facd6 fsaccess/op_script.c --- a/fsaccess/op_script.c Mon Jan 15 00:05:01 2024 +0100 +++ b/fsaccess/op_script.c Mon Jan 15 01:18:41 2024 +0100 @@ -33,7 +33,7 @@ /* Maximum number of arguments in scripts. */ -const int MAX_ARGS = 32; +static const int MAX_ARGS = 32; diff -r f7b76a66eb29 -r abb6e29facd6 fsaccess/ops.h --- a/fsaccess/ops.h Mon Jan 15 00:05:01 2024 +0100 +++ b/fsaccess/ops.h Mon Jan 15 01:18:41 2024 +0100 @@ -1,7 +1,7 @@ /* * Operations and their invocation. * - * Copyright (C) 2022 Paul Boddie + * Copyright (C) 2022, 2024 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 @@ -49,6 +49,7 @@ int make_dirs(int argc, char *argv[]); int remove_dirs(int argc, char *argv[]); int remove_non_dirs(int argc, char *argv[]); +int run_program(int argc, char *argv[]); int run_script(int argc, char *argv[]); int stat_objects(int argc, char *argv[]);