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 filename. */ 42 43 const char *_rm_filename; 44 45 /* External pager configuration. */ 46 47 ExternalPager *_exec_pager = NULL; 48 49 /* Process construction. */ 50 51 Process _process; 52 53 /* Stack and payload descriptions. */ 54 55 ExplicitSegment *_rm_stack = NULL; 56 Payload *_rm_payload = NULL; 57 58 ExplicitSegment *_program_stack = NULL; 59 Payload *_program_payload = NULL; 60 61 /* IPC gate for communication within the created task, plus allocated 62 capability. */ 63 64 l4_cap_idx_t _ipc_gate, _ipc_gate_cap; 65 66 /* Utility methods. */ 67 68 long start_pager(); 69 70 long init_region_mapper(); 71 72 long init_program(file_t *file); 73 74 long init_external_pager(l4_cap_idx_t *pager); 75 76 long configure_task(l4_cap_idx_t pager); 77 78 long create_ipc_gate(); 79 80 void init_region(struct exec_region *regions, 81 struct ipc_mapped_cap *mapped_caps, 82 struct exec_region &r, unsigned int &index); 83 84 long start_region_mapper(l4_cap_idx_t pager); 85 86 long start_program(int argc, const char *argv[]); 87 88 public: 89 explicit ProcessCreating(const char *rm_filename); 90 91 virtual long start(int argc, const char *argv[], l4_cap_idx_t *process); 92 }; 93 94 /* vim: tabstop=2 expandtab shiftwidth=2 95 */