1 /* 2 * Program memory segment support. 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 <l4/re/c/dataspace.h> 25 #include <l4/re/c/rm.h> 26 27 #include <fsclient/client.h> 28 29 #include <exec/common.h> 30 #include <exec/mapped_region.h> 31 32 33 34 /* Program segment abstractions. */ 35 36 class Segment 37 { 38 protected: 39 MappedRegion _region; 40 struct exec_region _exec_region; 41 42 /* Allocated memory. */ 43 44 char *_buf; 45 l4re_ds_t _ds; 46 file_t *_file; 47 bool _allocated = false, _attached = false; 48 49 /* Segment region base. */ 50 51 l4_addr_t _region_base; 52 53 /* Segment region size. */ 54 55 offset_t _region_allocated_size; 56 57 /* Offset of segment content within the region. */ 58 59 offset_t _region_content_offset; 60 61 /* Common initialisation. */ 62 63 void init(); 64 65 public: 66 virtual ~Segment(); 67 68 l4_cap_idx_t cap(); 69 70 char *address(); 71 72 offset_t size(); 73 74 /* Segment population methods. */ 75 76 long allocate(bool attach); 77 78 long fill(file_t *file, bool attach); 79 80 /* Mapped region methods. */ 81 82 MappedRegion ®ion(); 83 84 l4_addr_t region_address(char *address); 85 86 l4_addr_t region_address(l4_addr_t address); 87 88 /* Generic property access. */ 89 90 struct exec_region &exec_region(); 91 92 virtual bool loadable() = 0; 93 virtual offset_t file_contents() = 0; 94 virtual offset_t file_offset() = 0; 95 virtual l4_addr_t region_address() = 0; 96 virtual offset_t region_size() = 0; 97 virtual l4re_rm_flags_t region_flags() = 0; 98 }; 99 100 101 102 class ExplicitSegment : public Segment 103 { 104 protected: 105 /* Segment base. */ 106 107 l4_addr_t _base; 108 109 /* Segment size. */ 110 111 offset_t _size; 112 113 /* Access flags. */ 114 115 l4re_rm_flags_t _flags; 116 117 /* File access details. */ 118 119 offset_t _file_offset, _file_contents; 120 121 public: 122 explicit ExplicitSegment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags, 123 offset_t file_offset = 0, offset_t file_contents = 0); 124 125 /* Generic property access. */ 126 127 bool loadable(); 128 offset_t file_contents(); 129 offset_t file_offset(); 130 l4_addr_t region_address(); 131 offset_t region_size(); 132 l4re_rm_flags_t region_flags(); 133 }; 134 135 /* vim: tabstop=2 expandtab shiftwidth=2 136 */