1 /* 2 * A process monitor abstraction. 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 <fsserver/notification.h> 25 #include <resource/resource.h> 26 27 #include "parent_notification_object_interface.h" 28 29 30 31 /* A process monitor receiving signals from a task. */ 32 33 class ProcessMonitor : public ParentNotificationObject, public NotificationSupport, 34 public Resource 35 { 36 protected: 37 bool _debug; 38 39 /* Resources associated with the created process. */ 40 41 l4_cap_idx_t _pager = L4_INVALID_CAP, _mapped_pager = L4_INVALID_CAP, 42 _parent = L4_INVALID_CAP, _mapped_parent = L4_INVALID_CAP, 43 _task = L4_INVALID_CAP, _mapped_task = L4_INVALID_CAP, 44 _thread = L4_INVALID_CAP, _mapped_thread = L4_INVALID_CAP; 45 46 /* Notification support. */ 47 48 l4_cap_idx_t _notifier = L4_INVALID_CAP; 49 50 public: 51 explicit ProcessMonitor(bool debug = false); 52 53 /* Server details. */ 54 55 virtual ipc_server_default_config_type config(); 56 57 virtual void *interface() 58 { return static_cast<ParentNotificationObject *>(this); } 59 60 /* Capability management. */ 61 62 virtual void set_pager(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 63 virtual void set_parent(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 64 virtual void set_task(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 65 virtual void set_thread(l4_cap_idx_t cap, l4_cap_idx_t mapped_cap); 66 67 /* Lifecycle management. */ 68 69 virtual void pager_ended(); 70 71 /* Resource methods. */ 72 73 virtual void close(); 74 75 /* Parent methods. */ 76 77 virtual long signal(unsigned long sig, unsigned long val); 78 79 /* Notification methods. */ 80 81 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags); 82 83 virtual long unsubscribe(); 84 }; 85 86 /* vim: tabstop=2 expandtab shiftwidth=2 87 */