# HG changeset patch # User Paul Boddie # Date 1678146232 -3600 # Node ID 26baf4c23b927d8cb2ee173e37acabffce906a68 # Parent 35dad174d0bbcf7df19e3c4c9463625a839d5363 Moved program file opening to the general process creation functionality. diff -r 35dad174d0bb -r 26baf4c23b92 libexec/include/exec/process_creating.h --- a/libexec/include/exec/process_creating.h Mon Mar 06 19:12:48 2023 +0100 +++ b/libexec/include/exec/process_creating.h Tue Mar 07 00:43:52 2023 +0100 @@ -82,7 +82,7 @@ public: explicit ProcessCreating(const char *rm_filename); - virtual long start(file_t *file, int argc, const char *argv[], l4_cap_idx_t *process); + virtual long start(int argc, const char *argv[], l4_cap_idx_t *process); }; /* vim: tabstop=2 expandtab shiftwidth=2 diff -r 35dad174d0bb -r 26baf4c23b92 libexec/lib/src/process_creating.cc --- a/libexec/lib/src/process_creating.cc Mon Mar 06 19:12:48 2023 +0100 +++ b/libexec/lib/src/process_creating.cc Tue Mar 07 00:43:52 2023 +0100 @@ -21,9 +21,11 @@ #include +#include #include #include #include +#include #include @@ -306,13 +308,29 @@ return L4_EOK; } -/* Start a new process for the given payload, providing the indicated program - arguments, returning a reference to the pager. */ +/* Start a new process for the payload indicated by the first of the given + program arguments, returning a reference to the pager as an object for + interacting with the process. */ + +long ProcessCreating::start(int argc, const char *argv[], l4_cap_idx_t *process) +{ + file_t *file = client_open(argv[0], O_RDONLY); + long err; + + /* Open the program file, handling any error conditions. If successfully + opened, it will be closed when the process terminates. */ -long ProcessCreating::start(file_t *file, int argc, const char *argv[], - l4_cap_idx_t *process) -{ - long err; + if (file == NULL) + return -L4_EIO; + + if (!client_opened(file)) + { + err = file->error; + client_close(file); + return err; + } + + /* Initialise the different elements of the process. */ err = init_region_mapper(); if (err) @@ -344,7 +362,8 @@ /* Discard instances created to initialise the process. The region mapper relies on resources associated with its payload and stack and so these - cannot be deleted immediately. + cannot be deleted immediately. Instead, they are released when the pager is + deallocated. NOTE: The region mapper payload could be retained instead of being reconstructed each time. */ diff -r 35dad174d0bb -r 26baf4c23b92 libexec/lib/src/process_creator_resource.cc --- a/libexec/lib/src/process_creator_resource.cc Mon Mar 06 19:12:48 2023 +0100 +++ b/libexec/lib/src/process_creator_resource.cc Tue Mar 07 00:43:52 2023 +0100 @@ -20,7 +20,6 @@ */ #include -#include #include "opener_server.h" #include "process_creating.h" @@ -49,17 +48,19 @@ /* ProcessCreator interface methods. */ +/* Start the new process, obtaining a reference to it. */ + long ProcessCreatorResource::start(int argc, const char *argv[], l4_cap_idx_t *process) { - file_t *program_file = client_open(argv[0], O_RDONLY); - - /* Start the new process, obtaining a reference to it. */ - - return _creating.start(program_file, argc, argv, process); + return _creating.start(argc, argv, process); } + + /* Opener interface methods. */ +/* Return a context, through which program arguments must be communicated. */ + long ProcessCreatorResource::context(l4_cap_idx_t *context) { ProcessCreatorContextResource *resource = new ProcessCreatorContextResource(this);