paul@366 | 1 | /* |
paul@366 | 2 | * A system pager implementation residing in a separate task. |
paul@366 | 3 | * |
paul@480 | 4 | * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@366 | 5 | * |
paul@366 | 6 | * This program is free software; you can redistribute it and/or |
paul@366 | 7 | * modify it under the terms of the GNU General Public License as |
paul@366 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@366 | 9 | * the License, or (at your option) any later version. |
paul@366 | 10 | * |
paul@366 | 11 | * This program is distributed in the hope that it will be useful, |
paul@366 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@366 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@366 | 14 | * GNU General Public License for more details. |
paul@366 | 15 | * |
paul@366 | 16 | * You should have received a copy of the GNU General Public License |
paul@366 | 17 | * along with this program; if not, write to the Free Software |
paul@366 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@366 | 19 | * Boston, MA 02110-1301, USA |
paul@366 | 20 | */ |
paul@366 | 21 | |
paul@366 | 22 | #pragma once |
paul@366 | 23 | |
paul@499 | 24 | #include <vector> |
paul@499 | 25 | |
paul@504 | 26 | #include <exec/elf.h> |
paul@366 | 27 | #include <exec/pager.h> |
paul@504 | 28 | #include <exec/segment.h> |
paul@484 | 29 | #include <fsserver/notification.h> |
paul@489 | 30 | #include <fsserver/resource.h> |
paul@366 | 31 | |
paul@469 | 32 | #include "parent_pager_object_interface.h" |
paul@469 | 33 | |
paul@366 | 34 | |
paul@366 | 35 | |
paul@366 | 36 | /* A simple system pager also acting as a region mapper. */ |
paul@366 | 37 | |
paul@484 | 38 | class ExternalPager : public ExecPager, public ParentPagerObject, |
paul@489 | 39 | public NotificationSupport, public Resource |
paul@366 | 40 | { |
paul@492 | 41 | protected: |
paul@504 | 42 | |
paul@504 | 43 | /* Resources associated with the created process. */ |
paul@504 | 44 | |
paul@504 | 45 | l4_cap_idx_t _task = L4_INVALID_CAP, _mapped_task = L4_INVALID_CAP, |
paul@504 | 46 | _parent = L4_INVALID_CAP, _mapped_parent = L4_INVALID_CAP, |
paul@504 | 47 | _pager = L4_INVALID_CAP, _mapped_pager = L4_INVALID_CAP, |
paul@504 | 48 | _ipc_gate = L4_INVALID_CAP; |
paul@503 | 49 | std::vector<l4_cap_idx_t> _threads, _mapped_threads; |
paul@492 | 50 | |
paul@504 | 51 | /* Resources supporting the internal pager. */ |
paul@504 | 52 | |
paul@504 | 53 | ExplicitSegment *_rm_stack = NULL; |
paul@504 | 54 | Payload *_rm_payload = NULL; |
paul@504 | 55 | |
paul@366 | 56 | public: |
paul@431 | 57 | explicit ExternalPager(address_t start = 0, address_t end = 0); |
paul@366 | 58 | |
paul@489 | 59 | /* Server details. */ |
paul@489 | 60 | |
paul@489 | 61 | virtual ipc_server_default_config_type config(); |
paul@489 | 62 | |
paul@489 | 63 | virtual void *interface() |
paul@489 | 64 | { return static_cast<ParentPagerObject *>(this); } |
paul@489 | 65 | |
paul@492 | 66 | /* Task and thread management. */ |
paul@492 | 67 | |
paul@503 | 68 | virtual void add_thread(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); |
paul@499 | 69 | virtual void set_gate(l4_cap_idx_t cap); |
paul@503 | 70 | virtual void set_pager(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); |
paul@503 | 71 | virtual void set_parent(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); |
paul@503 | 72 | virtual void set_task(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); |
paul@492 | 73 | |
paul@504 | 74 | /* Internal pager resource management. */ |
paul@504 | 75 | |
paul@504 | 76 | virtual void set_payload(Payload *payload); |
paul@504 | 77 | virtual void set_stack(ExplicitSegment *stack); |
paul@504 | 78 | |
paul@492 | 79 | /* Resource methods. */ |
paul@492 | 80 | |
paul@492 | 81 | virtual void close(); |
paul@492 | 82 | |
paul@366 | 83 | /* Notification methods, implementing PagerObject. */ |
paul@366 | 84 | |
paul@366 | 85 | virtual long exception(l4_exc_regs_t regs, |
paul@366 | 86 | l4_snd_fpage_t *region); |
paul@366 | 87 | |
paul@366 | 88 | virtual long page_fault(l4_umword_t pfa, l4_umword_t pc, |
paul@366 | 89 | l4_snd_fpage_t *region); |
paul@366 | 90 | |
paul@366 | 91 | /* Region manager/mapper methods. */ |
paul@366 | 92 | |
paul@419 | 93 | virtual long attach(address_t *start, address_t size, map_flags_t flags, |
paul@366 | 94 | l4_cap_idx_t ds, address_t offset, unsigned char align); |
paul@469 | 95 | |
paul@469 | 96 | /* Parent methods. */ |
paul@469 | 97 | |
paul@469 | 98 | virtual long signal(unsigned long sig, unsigned long val); |
paul@480 | 99 | |
paul@480 | 100 | /* Notification methods. */ |
paul@480 | 101 | |
paul@485 | 102 | virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); |
paul@484 | 103 | |
paul@488 | 104 | virtual long unsubscribe(l4_cap_idx_t notifier); |
paul@366 | 105 | }; |
paul@366 | 106 | |
paul@366 | 107 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@366 | 108 | */ |