| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <functional> |
| 6 | #include <map> |
| 7 | #include <functional> |
| 8 | #include <stdio.h> |
| 9 | #include <asm/types.h> |
| 10 | #include <errno.h> |
| 11 | #include "common.h" |
| 12 | #include "util.h" |
| 13 | #include <linux/seccomp.h> |
| 14 | |
| 15 | class SecCompDispatcher |
| 16 | { |
| 17 | public: |
| 18 | SecCompDispatcher(int SecCompFd); |
| 19 | ~SecCompDispatcher(); |
| 20 | |
| 21 | SecCompDispatcher(const SecCompDispatcher&) = delete; |
| 22 | SecCompDispatcher(SecCompDispatcher&&) = delete; |
| 23 | SecCompDispatcher& operator=(const SecCompDispatcher&) = delete; |
| 24 | SecCompDispatcher& operator=(SecCompDispatcher&&) = delete; |
| 25 | |
| 26 | void RegisterHandler(int SysCallNr, const std::function<int(seccomp_notif*)>& Handler); |
| 27 | void UnregisterHandler(int SysCallNr); |
| 28 | |
| 29 | bool ValidateCookie(uint64_t id) noexcept; |
| 30 | |
| 31 | std::optional<std::vector<gsl::byte>> ReadProcessMemory(uint64_t cookie, pid_t pid, size_t address, size_t length) noexcept; |
| 32 | |
| 33 | private: |
| 34 | void Run(); |
| 35 | |
| 36 | seccomp_notif_sizes m_notificationSizes; |
| 37 | std::map<int, std::function<int(seccomp_notif*)>> m_handlers; |
| 38 | wil::unique_fd m_notifyFd; |
| 39 | wil::unique_fd m_shutdown; |
| 40 | std::thread m_worker; |
| 41 | }; |