contur2
Loading...
Searching...
No Matches
kernel.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7
9
10namespace contur {
11
12 class IClock;
13 class IMemory;
14 class IMMU;
15 class IVirtualMemory;
16 class ICPU;
17 class IExecutionEngine;
18 class IScheduler;
19 class IDispatcher;
20 class IFileSystem;
23 class SyscallTable;
24 class IpcManager;
25
28 {
30 std::unique_ptr<IClock> clock;
31
33 std::unique_ptr<IMemory> memory;
34
36 std::unique_ptr<IMMU> mmu;
37
39 std::unique_ptr<IVirtualMemory> virtualMemory;
40
42 std::unique_ptr<ICPU> cpu;
43
45 std::unique_ptr<IExecutionEngine> executionEngine;
46
48 std::unique_ptr<IScheduler> scheduler;
49
51 std::unique_ptr<IDispatcher> dispatcher;
52
54 std::unique_ptr<IFileSystem> fileSystem;
55
57 std::unique_ptr<IpcManager> ipcManager;
58
60 std::unique_ptr<SyscallTable> syscallTable;
61
63 std::size_t defaultTickBudget = static_cast<std::size_t>(DEFAULT_TIME_SLICE);
64 };
65
67 class Kernel final : public IKernel
68 {
69 public:
70 explicit Kernel(KernelDependencies deps);
71 ~Kernel() override;
72
73 Kernel(const Kernel &) = delete;
74 Kernel &operator=(const Kernel &) = delete;
75 Kernel(Kernel &&) noexcept;
76 Kernel &operator=(Kernel &&) noexcept;
77
78 [[nodiscard]] Result<ProcessId> createProcess(const ProcessConfig &config) override;
79 [[nodiscard]] Result<void> terminateProcess(ProcessId pid) override;
80 [[nodiscard]] Result<void> tick(std::size_t tickBudget = 0) override;
81 [[nodiscard]] Result<void> runForTicks(std::size_t cycles, std::size_t tickBudget = 0) override;
82 [[nodiscard]] Result<RegisterValue>
83 syscall(ProcessId pid, SyscallId id, std::span<const RegisterValue> args) override;
84 [[nodiscard]] Result<void> registerSyscallHandler(SyscallId id, SyscallHandlerFn handler) override;
85 [[nodiscard]] Result<void>
86 registerSyncPrimitive(const std::string &name, std::unique_ptr<ISyncPrimitive> primitive) override;
87 [[nodiscard]] Result<void> enterCritical(ProcessId pid, std::string_view primitiveName) override;
88 [[nodiscard]] Result<void> leaveCritical(ProcessId pid, std::string_view primitiveName) override;
89 [[nodiscard]] KernelSnapshot snapshot() const override;
90 [[nodiscard]] Tick now() const noexcept override;
91 [[nodiscard]] bool hasProcess(ProcessId pid) const noexcept override;
92 [[nodiscard]] std::size_t processCount() const noexcept override;
93
94 private:
95 struct Impl;
96 std::unique_ptr<Impl> impl_;
97 };
98
99} // namespace contur
Abstract CPU interface.
Definition i_cpu.h:21
Abstract clock interface for simulation time.
Definition clock.h:21
Interface for process lifecycle dispatch orchestration.
Abstract execution engine interface.
Abstract file-system interface.
Top-level kernel facade.
Definition i_kernel.h:76
Abstract interface for the Memory Management Unit.
Definition i_mmu.h:22
Abstract interface for linear addressable memory.
Definition i_memory.h:19
Abstract interface for page replacement algorithms.
Scheduler abstraction managing process state queues.
Definition i_scheduler.h:23
Strategy interface for scheduling algorithms.
Common interface for synchronization primitives.
Abstract interface for virtual memory management.
Registry/mediator for named IPC channels.
Definition ipc_manager.h:18
Result< void > tick(std::size_t tickBudget=0) override
Executes one dispatch cycle.
Result< RegisterValue > syscall(ProcessId pid, SyscallId id, std::span< const RegisterValue > args) override
Dispatches a syscall on behalf of a process.
std::unique_ptr< Impl > impl_
Definition kernel.h:96
Tick now() const noexcept override
Returns current simulation time.
Result< void > terminateProcess(ProcessId pid) override
Terminates a process immediately.
Result< void > enterCritical(ProcessId pid, std::string_view primitiveName) override
Acquires a named synchronization primitive.
Kernel(Kernel &&) noexcept
Result< void > registerSyscallHandler(SyscallId id, SyscallHandlerFn handler) override
Registers or replaces syscall handler.
Result< void > runForTicks(std::size_t cycles, std::size_t tickBudget=0) override
Executes multiple dispatch cycles.
Result< void > leaveCritical(ProcessId pid, std::string_view primitiveName) override
Releases a named synchronization primitive.
Result< void > registerSyncPrimitive(const std::string &name, std::unique_ptr< ISyncPrimitive > primitive) override
Registers a named synchronization primitive.
Kernel(KernelDependencies deps)
Result< ProcessId > createProcess(const ProcessConfig &config) override
Creates and admits a process.
KernelSnapshot snapshot() const override
Returns a snapshot of current kernel state.
bool hasProcess(ProcessId pid) const noexcept override
Returns true when process exists in dispatcher.
Kernel(const Kernel &)=delete
std::size_t processCount() const noexcept override
Returns total managed process count.
~Kernel() override
Kernel & operator=(const Kernel &)=delete
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Dispatch table mapping SyscallId to handler functions.
IKernel facade interface for top-level kernel operations.
Definition block.h:15
std::function< Result< RegisterValue >(std::span< const RegisterValue > args, ProcessImage &caller)> SyscallHandlerFn
Function signature used for syscall registration.
Definition i_kernel.h:71
constexpr Tick DEFAULT_TIME_SLICE
Default time slice for Round Robin scheduling (in ticks).
Definition types.h:61
std::uint64_t Tick
Simulation clock tick counter.
Definition types.h:18
std::uint32_t ProcessId
Unique identifier for a process.
Definition types.h:12
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
Dependency bundle used to construct a Kernel.
Definition kernel.h:28
std::unique_ptr< ICPU > cpu
CPU implementation used by execution engines.
Definition kernel.h:42
std::unique_ptr< IMemory > memory
Physical memory backend.
Definition kernel.h:33
std::unique_ptr< IpcManager > ipcManager
IPC manager service.
Definition kernel.h:57
std::unique_ptr< IClock > clock
Simulation clock implementation.
Definition kernel.h:30
std::unique_ptr< IExecutionEngine > executionEngine
Execution engine (interpreter or native).
Definition kernel.h:45
std::unique_ptr< IDispatcher > dispatcher
Dispatcher orchestrating process lifecycle.
Definition kernel.h:51
std::unique_ptr< SyscallTable > syscallTable
Syscall dispatch table.
Definition kernel.h:60
std::unique_ptr< IMMU > mmu
Memory management unit implementation.
Definition kernel.h:36
std::size_t defaultTickBudget
Default per-dispatch tick budget used when caller passes 0.
Definition kernel.h:63
std::unique_ptr< IScheduler > scheduler
Scheduler implementation.
Definition kernel.h:48
std::unique_ptr< IFileSystem > fileSystem
File system service.
Definition kernel.h:54
std::unique_ptr< IVirtualMemory > virtualMemory
Virtual memory manager.
Definition kernel.h:39
Lightweight kernel state snapshot for UI and diagnostics.
Definition i_kernel.h:47
Configuration payload used to create a process.
Definition i_kernel.h:28