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