contur2
Loading...
Searching...
No Matches
i_virtual_memory.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <cstddef>
7#include <vector>
8
9#include "contur/core/error.h"
10#include "contur/core/types.h"
11
12#include "contur/arch/block.h"
13
14namespace contur {
15
26 {
27 public:
28 virtual ~IVirtualMemory() = default;
29
34 [[nodiscard]] virtual Result<MemoryAddress> allocateSlot(ProcessId processId, std::size_t size) = 0;
35
39 [[nodiscard]] virtual Result<void> freeSlot(ProcessId processId) = 0;
40
45 [[nodiscard]] virtual Result<void> loadSegment(ProcessId processId, const std::vector<Block> &data) = 0;
46
50 [[nodiscard]] virtual Result<std::vector<Block>> readSegment(ProcessId processId) const = 0;
51
53 [[nodiscard]] virtual std::size_t totalSlots() const noexcept = 0;
54
56 [[nodiscard]] virtual std::size_t freeSlots() const noexcept = 0;
57
59 [[nodiscard]] virtual bool hasSlot(ProcessId processId) const noexcept = 0;
60
62 [[nodiscard]] virtual std::size_t slotSize(ProcessId processId) const noexcept = 0;
63 };
64
65} // namespace contur
Block — the fundamental unit of simulated memory.
Abstract interface for virtual memory management.
virtual Result< void > loadSegment(ProcessId processId, const std::vector< Block > &data)=0
Loads a code/data segment into a process's virtual address space.
virtual bool hasSlot(ProcessId processId) const noexcept=0
Checks whether a process has an allocated slot.
virtual std::size_t freeSlots() const noexcept=0
Returns the number of free (unallocated) slots.
virtual Result< std::vector< Block > > readSegment(ProcessId processId) const =0
Reads the entire code/data segment from a process's virtual memory.
virtual Result< MemoryAddress > allocateSlot(ProcessId processId, std::size_t size)=0
Allocates a virtual memory slot for a process.
virtual ~IVirtualMemory()=default
virtual Result< void > freeSlot(ProcessId processId)=0
Frees a previously allocated slot.
virtual std::size_t slotSize(ProcessId processId) const noexcept=0
Returns the slot size (number of blocks) for a process, or 0 if no slot.
virtual std::size_t totalSlots() const noexcept=0
Returns the number of total slots available.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Error codes and Result<T> type for fallible operations.
Definition block.h:15
std::uint32_t ProcessId
Unique identifier for a process.
Definition types.h:12
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...