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 public: 41 /* Allocated memory. */ 42 43 char *buf; 44 l4re_ds_t ds; 45 46 /* Segment base and corresponding region base. */ 47 48 l4_addr_t base, region_base; 49 50 /* Segment size and corresponding region size. */ 51 52 offset_t size, region_size; 53 54 /* Offset of segment content within the region. */ 55 56 offset_t region_offset; 57 58 /* Access flags. */ 59 60 l4re_rm_flags_t flags; 61 62 /* File access details. */ 63 64 offset_t file_offset, file_contents; 65 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 long allocate(); 70 71 long fill(file_t *file); 72 73 MappedRegion ®ion(); 74 75 l4_addr_t region_address(char *address); 76 77 l4_addr_t region_address(l4_addr_t address); 78 }; 79 80 /* vim: tabstop=2 expandtab shiftwidth=2 81 */