paul@324 | 1 | /* |
paul@324 | 2 | * Program memory segment support. |
paul@324 | 3 | * |
paul@324 | 4 | * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> |
paul@324 | 5 | * |
paul@324 | 6 | * This program is free software; you can redistribute it and/or |
paul@324 | 7 | * modify it under the terms of the GNU General Public License as |
paul@324 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@324 | 9 | * the License, or (at your option) any later version. |
paul@324 | 10 | * |
paul@324 | 11 | * This program is distributed in the hope that it will be useful, |
paul@324 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@324 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@324 | 14 | * GNU General Public License for more details. |
paul@324 | 15 | * |
paul@324 | 16 | * You should have received a copy of the GNU General Public License |
paul@324 | 17 | * along with this program; if not, write to the Free Software |
paul@324 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@324 | 19 | * Boston, MA 02110-1301, USA |
paul@324 | 20 | */ |
paul@324 | 21 | |
paul@324 | 22 | #pragma once |
paul@324 | 23 | |
paul@324 | 24 | #include <l4/re/c/dataspace.h> |
paul@324 | 25 | #include <l4/re/c/rm.h> |
paul@324 | 26 | |
paul@324 | 27 | #include <fsclient/client.h> |
paul@324 | 28 | |
paul@324 | 29 | #include <exec/mapped_region.h> |
paul@324 | 30 | |
paul@324 | 31 | |
paul@324 | 32 | |
paul@349 | 33 | /* Program segment abstractions. */ |
paul@324 | 34 | |
paul@324 | 35 | class Segment |
paul@324 | 36 | { |
paul@324 | 37 | protected: |
paul@324 | 38 | MappedRegion _region; |
paul@324 | 39 | |
paul@324 | 40 | /* Allocated memory. */ |
paul@324 | 41 | |
paul@326 | 42 | char *_buf; |
paul@326 | 43 | l4re_ds_t _ds; |
paul@324 | 44 | |
paul@349 | 45 | /* Segment region base. */ |
paul@324 | 46 | |
paul@349 | 47 | l4_addr_t _region_base; |
paul@324 | 48 | |
paul@349 | 49 | /* Segment region size. */ |
paul@324 | 50 | |
paul@349 | 51 | offset_t _region_allocated_size; |
paul@324 | 52 | |
paul@324 | 53 | /* Offset of segment content within the region. */ |
paul@324 | 54 | |
paul@349 | 55 | offset_t _region_content_offset; |
paul@324 | 56 | |
paul@349 | 57 | /* Common initialisation. */ |
paul@324 | 58 | |
paul@349 | 59 | void init(); |
paul@324 | 60 | |
paul@326 | 61 | public: |
paul@349 | 62 | virtual ~Segment(); |
paul@324 | 63 | |
paul@326 | 64 | char *address(); |
paul@326 | 65 | |
paul@326 | 66 | offset_t size(); |
paul@326 | 67 | |
paul@326 | 68 | /* Segment population methods. */ |
paul@326 | 69 | |
paul@324 | 70 | long allocate(); |
paul@324 | 71 | |
paul@324 | 72 | long fill(file_t *file); |
paul@324 | 73 | |
paul@326 | 74 | /* Mapped region methods. */ |
paul@326 | 75 | |
paul@324 | 76 | MappedRegion ®ion(); |
paul@324 | 77 | |
paul@324 | 78 | l4_addr_t region_address(char *address); |
paul@324 | 79 | |
paul@324 | 80 | l4_addr_t region_address(l4_addr_t address); |
paul@329 | 81 | |
paul@329 | 82 | /* Generic property access. */ |
paul@329 | 83 | |
paul@349 | 84 | virtual bool loadable() = 0; |
paul@349 | 85 | virtual offset_t file_contents() = 0; |
paul@349 | 86 | virtual offset_t file_offset() = 0; |
paul@349 | 87 | virtual l4_addr_t region_address() = 0; |
paul@349 | 88 | virtual offset_t region_size() = 0; |
paul@349 | 89 | virtual l4re_rm_flags_t region_flags() = 0; |
paul@349 | 90 | }; |
paul@349 | 91 | |
paul@349 | 92 | |
paul@349 | 93 | |
paul@349 | 94 | class ExplicitSegment : public Segment |
paul@349 | 95 | { |
paul@349 | 96 | protected: |
paul@349 | 97 | /* Segment base. */ |
paul@349 | 98 | |
paul@349 | 99 | l4_addr_t _base; |
paul@349 | 100 | |
paul@349 | 101 | /* Segment size. */ |
paul@349 | 102 | |
paul@349 | 103 | offset_t _size; |
paul@349 | 104 | |
paul@349 | 105 | /* Access flags. */ |
paul@349 | 106 | |
paul@349 | 107 | l4re_rm_flags_t _flags; |
paul@349 | 108 | |
paul@349 | 109 | /* File access details. */ |
paul@349 | 110 | |
paul@349 | 111 | offset_t _file_offset, _file_contents; |
paul@349 | 112 | |
paul@349 | 113 | public: |
paul@349 | 114 | explicit ExplicitSegment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags, |
paul@349 | 115 | offset_t file_offset = 0, offset_t file_contents = 0); |
paul@349 | 116 | |
paul@349 | 117 | /* Generic property access. */ |
paul@349 | 118 | |
paul@349 | 119 | bool loadable(); |
paul@329 | 120 | offset_t file_contents(); |
paul@349 | 121 | offset_t file_offset(); |
paul@349 | 122 | l4_addr_t region_address(); |
paul@349 | 123 | offset_t region_size(); |
paul@329 | 124 | l4re_rm_flags_t region_flags(); |
paul@324 | 125 | }; |
paul@324 | 126 | |
paul@324 | 127 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@324 | 128 | */ |