1 /* 2 * Generic pager functionality. 3 * 4 * Copyright (C) 2021, 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 <systypes/base.h> 25 26 #include <fsserver/page_mapper.h> 27 #include <fsserver/resource.h> 28 #include <mem/memory_incremental.h> 29 30 31 32 /* A pager exposing a dataspace. */ 33 34 class Pager : public Resource 35 { 36 protected: 37 offset_t _start, _size; 38 PageMapper *_mapper; 39 map_flags_t _flags; 40 41 /* Masked region support. */ 42 43 bool _is_masked; 44 offset_t _start_visible, _end_visible; 45 Flexpage _start_flexpage, _end_flexpage, _zero_flexpage; 46 MemoryIncremental _memory; 47 48 Flexpage *get_masked_flexpage(Flexpage *flexpage); 49 50 void allocate_region(Flexpage *flexpage, Flexpage &masked); 51 52 void populate_region(Flexpage *flexpage, Flexpage &masked, 53 bool has_start, bool has_end); 54 55 public: 56 explicit Pager(PageMapper *mapper, map_flags_t flags); 57 58 virtual void close(); 59 60 /* Paging methods. */ 61 62 virtual long map(offset_t offset, address_t hot_spot, map_flags_t flags, 63 l4_snd_fpage_t *region); 64 65 /* Limit methods. */ 66 67 offset_t get_data_size(); 68 69 /* File methods. */ 70 71 virtual long flush(offset_t populated_size, offset_t *size); 72 73 virtual long resize(offset_t *size); 74 75 /* Mapped file methods. */ 76 77 virtual long mmap(offset_t position, offset_t length, 78 offset_t start_visible, offset_t end_visible, 79 offset_t *start_pos, offset_t *end_pos, offset_t *size); 80 }; 81 82 // vim: tabstop=4 expandtab shiftwidth=4