contur2
Loading...
Searching...
No Matches
i_mmu.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <cstddef>
7
8#include "contur/core/error.h"
9#include "contur/core/types.h"
10
11#include "contur/arch/block.h"
12
13namespace contur {
14
21 class IMMU
22 {
23 public:
24 virtual ~IMMU() = default;
25
30 [[nodiscard]] virtual Result<Block> read(ProcessId processId, MemoryAddress virtualAddress) const = 0;
31
37 [[nodiscard]] virtual Result<void>
38 write(ProcessId processId, MemoryAddress virtualAddress, const Block &block) = 0;
39
44 [[nodiscard]] virtual Result<MemoryAddress> allocate(ProcessId processId, std::size_t pageCount) = 0;
45
49 [[nodiscard]] virtual Result<void> deallocate(ProcessId processId) = 0;
50
55 [[nodiscard]] virtual Result<void> swapIn(ProcessId processId, MemoryAddress virtualAddress) = 0;
56
61 [[nodiscard]] virtual Result<void> swapOut(ProcessId processId, MemoryAddress virtualAddress) = 0;
62
64 [[nodiscard]] virtual std::size_t totalFrames() const noexcept = 0;
65
67 [[nodiscard]] virtual std::size_t freeFrames() const noexcept = 0;
68 };
69
70} // namespace contur
Block — the fundamental unit of simulated memory.
Abstract interface for the Memory Management Unit.
Definition i_mmu.h:22
virtual Result< MemoryAddress > allocate(ProcessId processId, std::size_t pageCount)=0
Allocates a range of frames for a process.
virtual ~IMMU()=default
virtual Result< void > deallocate(ProcessId processId)=0
Deallocates all frames owned by a process.
virtual Result< Block > read(ProcessId processId, MemoryAddress virtualAddress) const =0
Reads a Block from a virtual address in a given process's address space.
virtual Result< void > swapIn(ProcessId processId, MemoryAddress virtualAddress)=0
Swaps a page into physical memory.
virtual std::size_t totalFrames() const noexcept=0
Returns the total number of physical frames managed.
virtual Result< void > swapOut(ProcessId processId, MemoryAddress virtualAddress)=0
Swaps a page out of physical memory (to simulated disk).
virtual Result< void > write(ProcessId processId, MemoryAddress virtualAddress, const Block &block)=0
Writes a Block to a virtual address in a given process's address space.
virtual std::size_t freeFrames() const noexcept=0
Returns the number of free (unallocated) physical frames.
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
std::uint32_t MemoryAddress
Represents a memory address (physical or virtual).
Definition types.h:15
A single memory cell in the simulated architecture.
Definition block.h:26
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...