paul@93 | 1 | /* |
paul@93 | 2 | * Generic pager functionality. |
paul@93 | 3 | * |
paul@332 | 4 | * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@6 | 22 | #pragma once |
paul@6 | 23 | |
paul@30 | 24 | #include <systypes/base.h> |
paul@30 | 25 | |
paul@94 | 26 | #include <fsserver/page_mapper.h> |
paul@94 | 27 | #include <fsserver/resource.h> |
paul@332 | 28 | #include <mem/memory_incremental.h> |
paul@6 | 29 | |
paul@6 | 30 | |
paul@6 | 31 | |
paul@6 | 32 | /* A pager exposing a dataspace. */ |
paul@6 | 33 | |
paul@7 | 34 | class Pager : public Resource |
paul@6 | 35 | { |
paul@6 | 36 | protected: |
paul@6 | 37 | offset_t _start, _size; |
paul@6 | 38 | PageMapper *_mapper; |
paul@121 | 39 | map_flags_t _flags; |
paul@6 | 40 | |
paul@332 | 41 | /* Masked region support. */ |
paul@332 | 42 | |
paul@332 | 43 | bool _is_masked; |
paul@332 | 44 | offset_t _start_visible, _end_visible; |
paul@332 | 45 | Flexpage _start_flexpage, _end_flexpage, _zero_flexpage; |
paul@332 | 46 | MemoryIncremental _memory; |
paul@332 | 47 | |
paul@332 | 48 | Flexpage *get_masked_flexpage(Flexpage *flexpage); |
paul@332 | 49 | |
paul@332 | 50 | void allocate_region(Flexpage *flexpage, Flexpage &masked); |
paul@332 | 51 | |
paul@332 | 52 | void populate_region(Flexpage *flexpage, Flexpage &masked, |
paul@332 | 53 | bool has_start, bool has_end); |
paul@332 | 54 | |
paul@6 | 55 | public: |
paul@121 | 56 | explicit Pager(PageMapper *mapper, map_flags_t flags); |
paul@6 | 57 | |
paul@24 | 58 | virtual void close(); |
paul@6 | 59 | |
paul@6 | 60 | /* Paging methods. */ |
paul@6 | 61 | |
paul@121 | 62 | virtual long map(offset_t offset, address_t hot_spot, map_flags_t flags, |
paul@90 | 63 | l4_snd_fpage_t *region); |
paul@6 | 64 | |
paul@6 | 65 | /* Limit methods. */ |
paul@6 | 66 | |
paul@6 | 67 | offset_t get_data_size(); |
paul@6 | 68 | |
paul@53 | 69 | /* File methods. */ |
paul@53 | 70 | |
paul@53 | 71 | virtual long flush(offset_t populated_size, offset_t *size); |
paul@53 | 72 | |
paul@55 | 73 | virtual long resize(offset_t *size); |
paul@55 | 74 | |
paul@7 | 75 | /* Mapped file methods. */ |
paul@7 | 76 | |
paul@332 | 77 | virtual long mmap(offset_t position, offset_t length, int masked, |
paul@332 | 78 | offset_t *start_pos, offset_t *end_pos, offset_t *size); |
paul@6 | 79 | }; |
paul@6 | 80 | |
paul@6 | 81 | // vim: tabstop=4 expandtab shiftwidth=4 |