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