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 abstraction. */ 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 base and corresponding region base. */ 46 47 l4_addr_t _base, _region_base; 48 49 /* Segment size and corresponding region size. */ 50 51 offset_t _size, _region_size; 52 53 /* Offset of segment content within the region. */ 54 55 offset_t _region_offset; 56 57 /* Access flags. */ 58 59 l4re_rm_flags_t _flags; 60 61 /* File access details. */ 62 63 offset_t _file_offset, _file_contents; 64 65 public: 66 explicit Segment(l4_addr_t base, offset_t size, l4re_rm_flags_t flags, 67 offset_t file_offset = 0, offset_t file_contents = 0); 68 69 char *address(); 70 71 offset_t size(); 72 73 /* Segment population methods. */ 74 75 long allocate(); 76 77 long fill(file_t *file); 78 79 /* Mapped region methods. */ 80 81 MappedRegion ®ion(); 82 83 l4_addr_t region_address(char *address); 84 85 l4_addr_t region_address(l4_addr_t address); 86 87 /* Generic property access. */ 88 89 offset_t file_contents(); 90 91 l4re_rm_flags_t region_flags(); 92 }; 93 94 /* vim: tabstop=2 expandtab shiftwidth=2 95 */