1 /* 2 * A system pager implementation residing in a separate task. 3 * 4 * Copyright (C) 2022, 2023, 2024 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 <set> 25 26 #include <exec/elf.h> 27 #include <exec/pager.h> 28 #include <exec/process_monitor.h> 29 #include <exec/segment.h> 30 #include <resource/resource.h> 31 32 #include "parent_pager_object_interface.h" 33 34 35 36 /* Collection definitions. */ 37 38 typedef std::set<l4_cap_idx_t> Capabilities; 39 40 41 42 /* A simple system pager also acting as a region mapper. */ 43 44 class ExternalPager : public ExecPager, public ParentPagerObject, 45 public Resource 46 { 47 protected: 48 /* Dataspace capabilities associated with regions. */ 49 50 Capabilities _dataspaces; 51 52 /* Resources associated with the created process. */ 53 54 l4_cap_idx_t _task = L4_INVALID_CAP, _mapped_task = L4_INVALID_CAP, 55 _thread = L4_INVALID_CAP, _mapped_thread = L4_INVALID_CAP, 56 _parent = L4_INVALID_CAP, _mapped_parent = L4_INVALID_CAP, 57 _pager = L4_INVALID_CAP, _mapped_pager = L4_INVALID_CAP; 58 59 ProcessMonitor *_monitor = NULL; 60 61 /* Resources supporting the internal pager. */ 62 63 ExplicitSegment *_rm_stack = NULL; 64 Payload *_rm_payload = NULL; 65 66 public: 67 explicit ExternalPager(address_t start = 0, address_t end = 0); 68 69 /* Server details. */ 70 71 virtual ipc_server_default_config_type config(); 72 73 virtual void *interface() 74 { return static_cast<ParentPagerObject *>(this); } 75 76 /* Capability management. */ 77 78 virtual void set_pager(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 79 virtual void set_parent(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 80 virtual void set_task(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 81 virtual void set_thread(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 82 83 /* Lifecycle management. */ 84 85 virtual void set_monitor(ProcessMonitor *monitor); 86 87 /* Internal pager resource management. */ 88 89 virtual void set_payload(Payload *payload); 90 virtual void set_stack(ExplicitSegment *stack); 91 92 /* Resource methods. */ 93 94 virtual void close(); 95 96 /* Notification methods, implementing PagerObject. */ 97 98 virtual long exception(l4_exc_regs_t regs, 99 l4_snd_fpage_t *region); 100 101 virtual long page_fault(l4_umword_t pfa, l4_umword_t pc, 102 l4_snd_fpage_t *region); 103 104 /* Region manager/mapper methods. */ 105 106 virtual long attach(address_t *start, address_t size, rm_flags_t flags, 107 l4_cap_idx_t ds, rm_offset_t offset, unsigned char align); 108 109 /* Parent methods. */ 110 111 virtual long signal(unsigned long sig, unsigned long val); 112 }; 113 114 /* vim: tabstop=2 expandtab shiftwidth=2 115 */