paul@477 | 1 | /* |
paul@477 | 2 | * Support for executing code in new tasks and threads. |
paul@477 | 3 | * |
paul@477 | 4 | * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@477 | 5 | * |
paul@477 | 6 | * This program is free software; you can redistribute it and/or |
paul@477 | 7 | * modify it under the terms of the GNU General Public License as |
paul@477 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@477 | 9 | * the License, or (at your option) any later version. |
paul@477 | 10 | * |
paul@477 | 11 | * This program is distributed in the hope that it will be useful, |
paul@477 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@477 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@477 | 14 | * GNU General Public License for more details. |
paul@477 | 15 | * |
paul@477 | 16 | * You should have received a copy of the GNU General Public License |
paul@477 | 17 | * along with this program; if not, write to the Free Software |
paul@477 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@477 | 19 | * Boston, MA 02110-1301, USA |
paul@477 | 20 | */ |
paul@477 | 21 | |
paul@477 | 22 | #pragma once |
paul@477 | 23 | |
paul@477 | 24 | #include <exec/elf.h> |
paul@477 | 25 | #include <exec/external_pager.h> |
paul@477 | 26 | #include <exec/memory.h> |
paul@477 | 27 | #include <exec/process.h> |
paul@477 | 28 | #include <ipc/map.h> |
paul@477 | 29 | |
paul@477 | 30 | |
paul@477 | 31 | |
paul@483 | 32 | /* Process creator functionality. */ |
paul@477 | 33 | |
paul@483 | 34 | class ProcessCreating |
paul@477 | 35 | { |
paul@477 | 36 | protected: |
paul@477 | 37 | const char *_rm_filename; |
paul@477 | 38 | |
paul@477 | 39 | /* External pager configuration. */ |
paul@477 | 40 | |
paul@487 | 41 | ExternalPager *_exec_pager = NULL; |
paul@477 | 42 | |
paul@487 | 43 | /* Process construction. */ |
paul@487 | 44 | |
paul@477 | 45 | Process _process; |
paul@477 | 46 | |
paul@477 | 47 | /* Stack and payload descriptions. */ |
paul@477 | 48 | |
paul@477 | 49 | ExplicitSegment _rm_stack; |
paul@487 | 50 | Payload *_rm_payload = NULL; |
paul@477 | 51 | |
paul@477 | 52 | ExplicitSegment _program_stack; |
paul@487 | 53 | Payload *_program_payload = NULL; |
paul@477 | 54 | |
paul@477 | 55 | /* IPC gate for communication within the created task, plus allocated |
paul@477 | 56 | capability. */ |
paul@477 | 57 | |
paul@477 | 58 | l4_cap_idx_t _ipc_gate, _ipc_gate_cap; |
paul@477 | 59 | |
paul@477 | 60 | /* Utility methods. */ |
paul@477 | 61 | |
paul@477 | 62 | long start_pager(); |
paul@477 | 63 | |
paul@477 | 64 | long init_region_mapper(); |
paul@477 | 65 | |
paul@477 | 66 | long init_program(file_t *file); |
paul@477 | 67 | |
paul@489 | 68 | long init_external_pager(l4_cap_idx_t *pager); |
paul@477 | 69 | |
paul@489 | 70 | long configure_task(l4_cap_idx_t pager); |
paul@477 | 71 | |
paul@477 | 72 | long create_ipc_gate(); |
paul@477 | 73 | |
paul@477 | 74 | void init_region(struct exec_region *regions, |
paul@477 | 75 | struct ipc_mapped_cap *mapped_caps, |
paul@477 | 76 | struct exec_region &r, unsigned int &index); |
paul@477 | 77 | |
paul@489 | 78 | long start_region_mapper(l4_cap_idx_t pager); |
paul@477 | 79 | |
paul@477 | 80 | long start_program(int argc, const char *argv[]); |
paul@477 | 81 | |
paul@477 | 82 | public: |
paul@483 | 83 | explicit ProcessCreating(const char *rm_filename); |
paul@477 | 84 | |
paul@487 | 85 | virtual long start(file_t *file, int argc, const char *argv[], l4_cap_idx_t *process); |
paul@477 | 86 | }; |
paul@477 | 87 | |
paul@477 | 88 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@477 | 89 | */ |