Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
virtual_memory.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7
9
10namespace contur {
11
12 // Forward declarations
13 class IMMU;
14
20 class VirtualMemory final : public IVirtualMemory
21 {
22 public:
26 explicit VirtualMemory(IMMU &mmu, std::size_t maxSlots);
27
29 ~VirtualMemory() override;
30
31 // Non-copyable, movable
32 VirtualMemory(const VirtualMemory &) = delete;
36
38 VirtualMemory &operator=(VirtualMemory &&) noexcept;
39
40 // IVirtualMemory interface
42 [[nodiscard]] Result<MemoryAddress> allocateSlot(ProcessId processId, std::size_t size) override;
43
45 [[nodiscard]] Result<void> freeSlot(ProcessId processId) override;
46
48 [[nodiscard]] Result<void> loadSegment(ProcessId processId, const std::vector<Block> &data) override;
49
51 [[nodiscard]] Result<std::vector<Block>> readSegment(ProcessId processId) const override;
52
54 [[nodiscard]] std::size_t totalSlots() const noexcept override;
55
57 [[nodiscard]] std::size_t freeSlots() const noexcept override;
58
60 [[nodiscard]] bool hasSlot(ProcessId processId) const noexcept override;
61
63 [[nodiscard]] std::size_t slotSize(ProcessId processId) const noexcept override;
64
65 private:
66 struct Impl;
67 std::unique_ptr<Impl> impl_;
68 };
69
70} // namespace contur
Abstract interface for the Memory Management Unit.
Definition i_mmu.h:22
Abstract interface for virtual memory management.
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Result< MemoryAddress > allocateSlot(ProcessId processId, std::size_t size) override
Allocates a virtual memory slot for a process.
std::unique_ptr< Impl > impl_
bool hasSlot(ProcessId processId) const noexcept override
Checks whether a process has an allocated slot.
~VirtualMemory() override
Destroys virtual memory manager.
Result< void > freeSlot(ProcessId processId) override
Frees a previously allocated slot.
Result< void > loadSegment(ProcessId processId, const std::vector< Block > &data) override
Loads a code/data segment into a process's virtual address space.
std::size_t totalSlots() const noexcept override
Returns the number of total slots available.
VirtualMemory & operator=(const VirtualMemory &)=delete
std::size_t slotSize(ProcessId processId) const noexcept override
Returns the slot size (number of blocks) for a process, or 0 if no slot.
VirtualMemory(const VirtualMemory &)=delete
VirtualMemory(VirtualMemory &&) noexcept
Move-constructs virtual memory manager state.
Result< std::vector< Block > > readSegment(ProcessId processId) const override
Reads the entire code/data segment from a process's virtual memory.
VirtualMemory(IMMU &mmu, std::size_t maxSlots)
Constructs virtual memory backed by the given MMU.
std::size_t freeSlots() const noexcept override
Returns the number of free (unallocated) slots.
IVirtualMemory interface — virtual address space management.
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