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