contur2
Loading...
Searching...
No Matches
syscall_table.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <functional>
7#include <memory>
8#include <span>
9
10#include "contur/core/error.h"
11#include "contur/core/types.h"
12
15
16namespace contur {
17
18 class ProcessImage;
19
22 {
23 public:
25 using HandlerFn = std::function<Result<RegisterValue>(std::span<const RegisterValue>, ProcessImage &)>;
26
29
30 SyscallTable(const SyscallTable &) = delete;
33 SyscallTable &operator=(SyscallTable &&) noexcept;
34
37 [[nodiscard]] Result<void> registerHandler(SyscallId id, HandlerFn handler);
38
42 [[nodiscard]] Result<void> registerHandler(SyscallId id, ISyscallHandler &handler);
43
46 [[nodiscard]] Result<void> unregisterHandler(SyscallId id);
47
50 [[nodiscard]] Result<RegisterValue>
51 dispatch(SyscallId id, std::span<const RegisterValue> args, ProcessImage &caller) const;
52
54 [[nodiscard]] bool hasHandler(SyscallId id) const noexcept;
55
57 [[nodiscard]] std::size_t handlerCount() const noexcept;
58
59 private:
60 struct Impl;
61 std::unique_ptr<Impl> impl_;
62 };
63
64} // namespace contur
Interface for syscall handling.
Full in-memory representation of a process.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Result< RegisterValue > dispatch(SyscallId id, std::span< const RegisterValue > args, ProcessImage &caller) const
Dispatches syscall to registered handler.
std::size_t handlerCount() const noexcept
Number of registered handlers.
std::unique_ptr< Impl > impl_
Result< void > unregisterHandler(SyscallId id)
Unregisters a handler for syscall id.
std::function< Result< RegisterValue >(std::span< const RegisterValue >, ProcessImage &)> HandlerFn
Function signature used for syscall handlers.
bool hasHandler(SyscallId id) const noexcept
Returns true when id has a registered handler.
SyscallTable(const SyscallTable &)=delete
Result< void > registerHandler(SyscallId id, HandlerFn handler)
Registers/replaces a function handler for syscall id.
SyscallTable(SyscallTable &&) noexcept
SyscallTable & operator=(const SyscallTable &)=delete
Error codes and Result<T> type for fallible operations.
Definition block.h:15
SyscallId
Numeric identifiers for system calls.
Definition syscall_ids.h:12
std::int32_t RegisterValue
Value stored in a CPU register.
Definition types.h:21
ISyscallHandler interface.
Syscall IDs for the user-kernel boundary.
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...