1 /* 2 * Support for executing code in new tasks and threads. 3 * 4 * Copyright (C) 2022, 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 #pragma once 23 24 #include <mutex> 25 26 #include <exec/elf.h> 27 #include <exec/external_pager.h> 28 #include <exec/memory.h> 29 #include <exec/process.h> 30 #include <ipc/map.h> 31 32 33 34 /* Process creator functionality. */ 35 36 class ProcessCreating 37 { 38 protected: 39 std::mutex _lock; 40 41 /* Region mapper program file. */ 42 43 const char *_rm_filename; 44 file_t *_rm_file; 45 46 /* External pager configuration. */ 47 48 ExternalPager *_exec_pager = NULL; 49 50 /* Process construction. */ 51 52 Process _process; 53 54 /* Stack and payload descriptions. */ 55 56 ExplicitSegment *_rm_stack = NULL; 57 Payload *_rm_payload = NULL; 58 59 ExplicitSegment *_program_stack = NULL; 60 Payload *_program_payload = NULL; 61 62 /* IPC gate for communication within the created task, plus allocated 63 capability. */ 64 65 l4_cap_idx_t _ipc_gate, _ipc_gate_cap; 66 67 /* Utility methods. */ 68 69 long start_pager(); 70 71 long init_region_mapper(); 72 73 long init_program(file_t *file); 74 75 long init_external_pager(l4_cap_idx_t *pager); 76 77 long configure_task(l4_cap_idx_t pager); 78 79 long create_ipc_gate(); 80 81 void init_region(struct exec_region *regions, 82 struct ipc_mapped_cap *mapped_caps, 83 struct exec_region &r, unsigned int &index); 84 85 long start_region_mapper(l4_cap_idx_t pager); 86 87 long start_program(int argc, const char *argv[]); 88 89 public: 90 explicit ProcessCreating(const char *rm_filename, file_t *rm_file); 91 92 virtual long start(int argc, const char *argv[], l4_cap_idx_t *process); 93 }; 94 95 /* vim: tabstop=2 expandtab shiftwidth=2 96 */