1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libexec/include/exec/process_creator_context_resource.h Tue Feb 28 22:40:02 2023 +0100
1.3 @@ -0,0 +1,72 @@
1.4 +/*
1.5 + * Support for creating a new process.
1.6 + *
1.7 + * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#pragma once
1.26 +
1.27 +#include <fsserver/simple_pager.h>
1.28 +
1.29 +#include "process_creator_context_object_interface.h"
1.30 +
1.31 +
1.32 +
1.33 +/* Forward declaration. */
1.34 +
1.35 +class ProcessCreatorResource;
1.36 +
1.37 +
1.38 +
1.39 +/* A process creating context employing a simple pager to transfer process
1.40 + details. */
1.41 +
1.42 +class ProcessCreatorContextResource : public SimplePager,
1.43 + public ProcessCreatorContextObject
1.44 +{
1.45 +protected:
1.46 + ProcessCreatorResource *_creator;
1.47 +
1.48 +public:
1.49 + explicit ProcessCreatorContextResource(ProcessCreatorResource *creator);
1.50 +
1.51 + virtual ~ProcessCreatorContextResource();
1.52 +
1.53 + /* Server details. */
1.54 +
1.55 + ipc_server_default_config_type config();
1.56 +
1.57 + void *interface()
1.58 + { return static_cast<ProcessCreatorContextObject *>(this); }
1.59 +
1.60 + /* Process creator context interface methods. */
1.61 +
1.62 + virtual long start(int argc, l4_cap_idx_t *process);
1.63 +
1.64 + /* Pager/dataspace methods. */
1.65 +
1.66 + long map(offset_t offset, map_address_t hot_spot, map_flags_t flags,
1.67 + l4_snd_fpage_t *region)
1.68 + { return SimplePager::map(offset, hot_spot, flags, region); }
1.69 +
1.70 + long info(offset_t *size, map_flags_t *flags)
1.71 + { return SimplePager::info(size, flags); }
1.72 +};
1.73 +
1.74 +/* vim: tabstop=2 expandtab shiftwidth=2
1.75 +*/
2.1 --- a/libexec/include/exec/process_creator_resource.h Tue Feb 28 22:35:25 2023 +0100
2.2 +++ b/libexec/include/exec/process_creator_resource.h Tue Feb 28 22:40:02 2023 +0100
2.3 @@ -24,13 +24,13 @@
2.4 #include <exec/process_creating.h>
2.5 #include <fsserver/resource.h>
2.6
2.7 -#include "process_creator_interface.h"
2.8 +#include "opener_interface.h"
2.9
2.10
2.11
2.12 /* Process creator. */
2.13
2.14 -class ProcessCreatorResource : public Resource, public ProcessCreator
2.15 +class ProcessCreatorResource : public Opener, public Resource
2.16 {
2.17 protected:
2.18 ProcessCreating _creating;
2.19 @@ -45,11 +45,15 @@
2.20 ipc_server_default_config_type config();
2.21
2.22 void *interface()
2.23 - { return static_cast<ProcessCreator *>(this); }
2.24 + { return static_cast<Opener *>(this); }
2.25
2.26 /* Process creator interface methods. */
2.27
2.28 - virtual long start(l4_cap_idx_t program, l4_cap_idx_t *process);
2.29 + virtual long start(int argc, const char *argv[], l4_cap_idx_t *process);
2.30 +
2.31 + /* Opener interface methods. */
2.32 +
2.33 + virtual long context(l4_cap_idx_t *context);
2.34 };
2.35
2.36 /* vim: tabstop=2 expandtab shiftwidth=2
3.1 --- a/libexec/lib/src/Makefile Tue Feb 28 22:35:25 2023 +0100
3.2 +++ b/libexec/lib/src/Makefile Tue Feb 28 22:40:02 2023 +0100
3.3 @@ -17,7 +17,7 @@
3.4
3.5 CLIENT_INTERFACES_CC = dataspace mapped_file notifier
3.6
3.7 -SERVER_INTERFACES_CC = pager_object parent_pager_object process_creator
3.8 +SERVER_INTERFACES_CC = opener pager_object parent_pager_object process_creator_context_object
3.9
3.10 # Generated and plain source files.
3.11
3.12 @@ -31,6 +31,7 @@
3.13 common.cc elf.cc external_pager.cc \
3.14 internal_pager.cc memory.cc pager.cc \
3.15 process.cc process_creating.cc \
3.16 + process_creator_context_resource.cc \
3.17 process_creator_resource.cc \
3.18 segment.cc stack.cc
3.19
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/libexec/lib/src/process_creator_context_resource.cc Tue Feb 28 22:40:02 2023 +0100
4.3 @@ -0,0 +1,76 @@
4.4 +/*
4.5 + * A resource offering support for creating processes.
4.6 + *
4.7 + * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include <systypes/fcntl.h>
4.26 +
4.27 +#include "process_creator_resource.h"
4.28 +#include "process_creator_context_resource.h"
4.29 +#include "process_creator_context_object_server.h"
4.30 +
4.31 +#include <string.h>
4.32 +#include <stdio.h>
4.33 +
4.34 +
4.35 +
4.36 +/* Support for creating processes. */
4.37 +
4.38 +ProcessCreatorContextResource::ProcessCreatorContextResource(ProcessCreatorResource *creator)
4.39 +: SimplePager(), _creator(creator)
4.40 +{
4.41 +}
4.42 +
4.43 +ProcessCreatorContextResource::~ProcessCreatorContextResource()
4.44 +{
4.45 +}
4.46 +
4.47 +ipc_server_default_config_type ProcessCreatorContextResource::config()
4.48 +{
4.49 + return config_ProcessCreatorContextObject;
4.50 +}
4.51 +
4.52 +
4.53 +
4.54 +/* ProcessCreatorContext interface methods. */
4.55 +
4.56 +long ProcessCreatorContextResource::start(int argc, l4_cap_idx_t *process)
4.57 +{
4.58 + /* Obtain the arguments by reading from the shared memory. */
4.59 +
4.60 + const char *argv[argc];
4.61 + offset_t pos = 0;
4.62 +
4.63 + for (int i = 0; i < argc; i++)
4.64 + {
4.65 + argv[i] = get_string(pos);
4.66 +
4.67 + if (argv[i] != NULL)
4.68 + pos += strlen(argv[i]) + 1;
4.69 +
4.70 + printf("argv[%d] = %s\n", i, argv[i]);
4.71 + }
4.72 +
4.73 + /* Start the new process, obtaining a reference to it. */
4.74 +
4.75 + return _creator->start(argc, argv, process);
4.76 +}
4.77 +
4.78 +/* vim: tabstop=4 expandtab shiftwidth=4
4.79 +*/
5.1 --- a/libexec/lib/src/process_creator_resource.cc Tue Feb 28 22:35:25 2023 +0100
5.2 +++ b/libexec/lib/src/process_creator_resource.cc Tue Feb 28 22:40:02 2023 +0100
5.3 @@ -19,14 +19,14 @@
5.4 * Boston, MA 02110-1301, USA
5.5 */
5.6
5.7 +#include <fsserver/resource_server.h>
5.8 #include <systypes/fcntl.h>
5.9
5.10 +#include "opener_server.h"
5.11 #include "process_creating.h"
5.12 +#include "process_creator_context_resource.h"
5.13 #include "process_creator_resource.h"
5.14
5.15 -#include "notifier_client.h"
5.16 -#include "process_creator_server.h"
5.17 -
5.18
5.19
5.20 /* Support for creating processes. */
5.21 @@ -42,32 +42,32 @@
5.22
5.23 ipc_server_default_config_type ProcessCreatorResource::config()
5.24 {
5.25 - return config_ProcessCreator;
5.26 + return config_Opener;
5.27 }
5.28
5.29
5.30
5.31 /* ProcessCreator interface methods. */
5.32
5.33 -long ProcessCreatorResource::start(l4_cap_idx_t program, l4_cap_idx_t *process)
5.34 +long ProcessCreatorResource::start(int argc, const char *argv[], l4_cap_idx_t *process)
5.35 {
5.36 - file_t file;
5.37 -
5.38 - file_init(&file);
5.39 - file.ref = program;
5.40 -
5.41 - /* Obtain a distinct and usable file object. */
5.42 -
5.43 - file_t *program_file = client_reopen(&file, O_RDONLY);
5.44 -
5.45 - /* NOTE: To be replaced with the actual arguments, perhaps involving a
5.46 - context object. */
5.47 -
5.48 - const char *argv[] = {"<program>"};
5.49 + file_t *program_file = client_open(argv[0], O_RDONLY);
5.50
5.51 /* Start the new process, obtaining a reference to it. */
5.52
5.53 - return _creating.start(program_file, 1, argv, process);
5.54 + return _creating.start(program_file, argc, argv, process);
5.55 +}
5.56 +
5.57 +/* Opener interface methods. */
5.58 +
5.59 +long ProcessCreatorResource::context(l4_cap_idx_t *context)
5.60 +{
5.61 + ProcessCreatorContextResource *resource = new ProcessCreatorContextResource(this);
5.62 +
5.63 + /* Complete the initialisation and start a server in a new thread.
5.64 + If the thread does not start, the resource will be finalised. */
5.65 +
5.66 + return ResourceServer(resource).start_thread(context);
5.67 }
5.68
5.69 // vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/libfsclient/include/fsclient/process.h Tue Feb 28 22:35:25 2023 +0100
6.2 +++ b/libfsclient/include/fsclient/process.h Tue Feb 28 22:40:02 2023 +0100
6.3 @@ -58,7 +58,7 @@
6.4
6.5 process_t *process_new();
6.6 void process_init(process_t *process);
6.7 -long process_start(process_t *process, file_t *file);
6.8 +long process_start(process_t *process, int argc, char *argv[]);
6.9
6.10 /* Notification support. */
6.11
7.1 --- a/libfsclient/lib/src/Makefile Tue Feb 28 22:35:25 2023 +0100
7.2 +++ b/libfsclient/lib/src/Makefile Tue Feb 28 22:40:02 2023 +0100
7.3 @@ -17,7 +17,7 @@
7.4
7.5 CLIENT_INTERFACES_CC = dataspace directory file filesystem flush \
7.6 mapped_file notifier notification opener \
7.7 - opener_context pipe pipe_opener process_creator
7.8 + opener_context pipe pipe_opener process_creator_context
7.9
7.10 # Generated and plain source files.
7.11
8.1 --- a/libfsclient/lib/src/process.cc Tue Feb 28 22:35:25 2023 +0100
8.2 +++ b/libfsclient/lib/src/process.cc Tue Feb 28 22:40:02 2023 +0100
8.3 @@ -25,7 +25,7 @@
8.4 #include <stdio.h>
8.5 #include <stdlib.h>
8.6
8.7 -#include "process_creator_client.h"
8.8 +#include "process_creator_context_client.h"
8.9
8.10 #include "file.h"
8.11 #include "process.h"
8.12 @@ -58,24 +58,47 @@
8.13 process->notifiable.base = (notifiable_base_t *) process;
8.14 }
8.15
8.16 -/* Start a process using the given file as payload.
8.17 - NOTE: This does not yet communicate arguments or obtain input/output
8.18 - pipes. */
8.19 +/* Start a process using the given arguments.
8.20 + NOTE: This does not yet obtain input/output pipes. */
8.21
8.22 -long process_start(process_t *process, file_t *file)
8.23 +long process_start(process_t *process, int argc, char *argv[])
8.24 {
8.25 l4_cap_idx_t server = l4re_env_get_cap("pserver");
8.26
8.27 if (l4_is_invalid_cap(server))
8.28 return -L4_ENOMEM;
8.29
8.30 - /* Obtain a client for the process creator. */
8.31 + /* Obtain a context for process creation. */
8.32 +
8.33 + file_t context;
8.34 + long err = file_context(&context, server);
8.35 +
8.36 + if (err)
8.37 + return err;
8.38 +
8.39 + offset_t pos = 0, written;
8.40
8.41 - client_ProcessCreator creator(server);
8.42 + for (int i = 0; i < argc; i++)
8.43 + {
8.44 + if (!file_string_set(&context, argv[i], pos, &written))
8.45 + return -L4_ENOMEM;
8.46 +
8.47 + pos += written + 1;
8.48 + }
8.49 +
8.50 + /* Obtain a client for the process creator context. */
8.51 +
8.52 + client_ProcessCreatorContext creator(context.ref);
8.53
8.54 /* Start the process, obtaining a reference to it. */
8.55
8.56 - return creator.start(file->ref, &process->ref);
8.57 + err = creator.start(argc, &process->ref);
8.58 +
8.59 + /* Close the context, although a separate mechanism could permit contexts to
8.60 + open several processes. */
8.61 +
8.62 + file_close(&context);
8.63 + return err;
8.64 }
8.65
8.66
9.1 --- a/libsystypes/idl/opener.idl Tue Feb 28 22:35:25 2023 +0100
9.2 +++ b/libsystypes/idl/opener.idl Tue Feb 28 22:40:02 2023 +0100
9.3 @@ -1,5 +1,3 @@
9.4 -#include <sys/types.h> /* size_t */
9.5 -
9.6 /* An interface providing a way of opening filesystem objects. */
9.7
9.8 interface Opener
10.1 --- a/libsystypes/idl/process_creator.idl Tue Feb 28 22:35:25 2023 +0100
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,6 +0,0 @@
10.4 -interface ProcessCreator
10.5 -{
10.6 - /* Start a process, using the given file reference as the payload. */
10.7 -
10.8 - [opcode(30)] void start(in cap program, out cap process);
10.9 -};
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/libsystypes/idl/process_creator_context.idl Tue Feb 28 22:40:02 2023 +0100
11.3 @@ -0,0 +1,10 @@
11.4 +/* An interface providing a way of creating processes, relying on a dataspace to
11.5 + transfer arguments to initialise each new process. */
11.6 +
11.7 +interface ProcessCreatorContext
11.8 +{
11.9 + /* Start a process, using the given argument count to refer to the process
11.10 + arguments supplied via the dataspace, including the program itself. */
11.11 +
11.12 + [opcode(30)] void start(in int argc, out cap process);
11.13 +};
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/libsystypes/idl/process_creator_context_object.idl Tue Feb 28 22:40:02 2023 +0100
12.3 @@ -0,0 +1,4 @@
12.4 +import "dataspace.idl";
12.5 +import "process_creator_context.idl";
12.6 +
12.7 +interface ProcessCreatorContextObject composes Dataspace, ProcessCreatorContext;
13.1 --- a/tests/dstest_exec.cc Tue Feb 28 22:35:25 2023 +0100
13.2 +++ b/tests/dstest_exec.cc Tue Feb 28 22:40:02 2023 +0100
13.3 @@ -23,9 +23,7 @@
13.4 #include <l4/sys/err.h>
13.5 #include <l4/util/util.h>
13.6
13.7 -#include <fsclient/client.h>
13.8 #include <fsclient/process.h>
13.9 -#include <systypes/fcntl.h>
13.10 #include <systypes/format.h>
13.11
13.12 #include <stdio.h>
13.13 @@ -42,26 +40,13 @@
13.14 return 1;
13.15 }
13.16
13.17 - char *program_filename = argv[1];
13.18 -
13.19 - file_t *program_file = client_open(program_filename, O_RDONLY);
13.20 -
13.21 - if (!client_opened(program_file))
13.22 - {
13.23 - printf("Could not open program file.\n");
13.24 - return 1;
13.25 - }
13.26 -
13.27 /* Create a new process structure. */
13.28
13.29 process_t *process = process_new();
13.30
13.31 /* Start a process for the given program. */
13.32
13.33 - err = process_start(process, program_file);
13.34 -
13.35 - /* NOTE: Need to be able to send arguments, which would be sent via a context,
13.36 - although capabilities could be sent via arguments. */
13.37 + err = process_start(process, argc - 1, argv + 1);
13.38
13.39 if (err)
13.40 {