paul@491 | 1 | /* |
paul@491 | 2 | * A resource offering support for creating processes. |
paul@491 | 3 | * |
paul@491 | 4 | * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk> |
paul@491 | 5 | * |
paul@491 | 6 | * This program is free software; you can redistribute it and/or |
paul@491 | 7 | * modify it under the terms of the GNU General Public License as |
paul@491 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@491 | 9 | * the License, or (at your option) any later version. |
paul@491 | 10 | * |
paul@491 | 11 | * This program is distributed in the hope that it will be useful, |
paul@491 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@491 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@491 | 14 | * GNU General Public License for more details. |
paul@491 | 15 | * |
paul@491 | 16 | * You should have received a copy of the GNU General Public License |
paul@491 | 17 | * along with this program; if not, write to the Free Software |
paul@491 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@491 | 19 | * Boston, MA 02110-1301, USA |
paul@491 | 20 | */ |
paul@491 | 21 | |
paul@491 | 22 | #include <systypes/fcntl.h> |
paul@491 | 23 | |
paul@491 | 24 | #include "process_creator_resource.h" |
paul@491 | 25 | #include "process_creator_context_resource.h" |
paul@491 | 26 | #include "process_creator_context_object_server.h" |
paul@491 | 27 | |
paul@491 | 28 | #include <string.h> |
paul@491 | 29 | #include <stdio.h> |
paul@491 | 30 | |
paul@491 | 31 | |
paul@491 | 32 | |
paul@491 | 33 | /* Support for creating processes. */ |
paul@491 | 34 | |
paul@491 | 35 | ProcessCreatorContextResource::ProcessCreatorContextResource(ProcessCreatorResource *creator) |
paul@491 | 36 | : SimplePager(), _creator(creator) |
paul@491 | 37 | { |
paul@491 | 38 | } |
paul@491 | 39 | |
paul@491 | 40 | ProcessCreatorContextResource::~ProcessCreatorContextResource() |
paul@491 | 41 | { |
paul@491 | 42 | } |
paul@491 | 43 | |
paul@491 | 44 | ipc_server_default_config_type ProcessCreatorContextResource::config() |
paul@491 | 45 | { |
paul@491 | 46 | return config_ProcessCreatorContextObject; |
paul@491 | 47 | } |
paul@491 | 48 | |
paul@491 | 49 | |
paul@491 | 50 | |
paul@491 | 51 | /* ProcessCreatorContext interface methods. */ |
paul@491 | 52 | |
paul@491 | 53 | long ProcessCreatorContextResource::start(int argc, l4_cap_idx_t *process) |
paul@491 | 54 | { |
paul@491 | 55 | /* Obtain the arguments by reading from the shared memory. */ |
paul@491 | 56 | |
paul@491 | 57 | const char *argv[argc]; |
paul@491 | 58 | offset_t pos = 0; |
paul@491 | 59 | |
paul@491 | 60 | for (int i = 0; i < argc; i++) |
paul@491 | 61 | { |
paul@491 | 62 | argv[i] = get_string(pos); |
paul@491 | 63 | |
paul@491 | 64 | if (argv[i] != NULL) |
paul@491 | 65 | pos += strlen(argv[i]) + 1; |
paul@491 | 66 | |
paul@491 | 67 | printf("argv[%d] = %s\n", i, argv[i]); |
paul@491 | 68 | } |
paul@491 | 69 | |
paul@491 | 70 | /* Start the new process, obtaining a reference to it. */ |
paul@491 | 71 | |
paul@491 | 72 | return _creator->start(argc, argv, process); |
paul@491 | 73 | } |
paul@491 | 74 | |
paul@491 | 75 | /* vim: tabstop=4 expandtab shiftwidth=4 |
paul@491 | 76 | */ |