feat(ring0): Phase 102 MemApi Bridge Skeleton - StdMem実装

- Add StdMem struct (stdlib alloc/free based)
- Update default_ring0() to use StdMem instead of NoopMem
- Keep NoopMem for compatibility and testing
- Add unit tests for StdMem allocation/stats
- Update docs (phase-85-ring0-runtime/README.md, ring0-inventory.md)

Note: This is a skeleton implementation. Full MemStats tracking
(including freed size) will be added in Phase 102B with hakmem bridge.

Files modified:
- src/runtime/ring0/std_impls.rs
- src/runtime/ring0/mod.rs
- docs/development/current/main/phase-85-ring0-runtime/README.md
- docs/development/current/main/ring0-inventory.md
This commit is contained in:
nyash-codex
2025-12-03 13:42:05 +09:00
parent 0c527dcd22
commit 262de28c6b
4 changed files with 249 additions and 3 deletions

View File

@ -7,7 +7,7 @@ mod std_impls;
mod traits;
pub use errors::{IoError, TimeError};
pub use std_impls::{NoopMem, StdFs, StdIo, StdLog, StdThread, StdTime};
pub use std_impls::{NoopMem, StdFs, StdIo, StdLog, StdMem, StdThread, StdTime};
pub use traits::{
FsApi, FsMetadata, IoApi, LogApi, LogLevel, MemApi, MemStats, ThreadApi, TimeApi,
};
@ -63,7 +63,7 @@ impl std::fmt::Debug for Ring0Context {
/// デフォルト Ring0Context を作成std ベース)
pub fn default_ring0() -> Ring0Context {
Ring0Context {
mem: Arc::new(NoopMem),
mem: Arc::new(StdMem::new()),
io: Arc::new(StdIo),
time: Arc::new(StdTime),
log: Arc::new(StdLog),
@ -128,4 +128,20 @@ mod tests {
ring0.log.warn("warn message");
ring0.log.error("error message");
}
#[test]
fn test_default_ring0_uses_stdmem() {
let ring0 = default_ring0();
let ptr = ring0.mem.alloc(512);
assert!(!ptr.is_null(), "default_ring0 should use StdMem");
ring0.mem.free(ptr);
// Clean up
unsafe {
std::alloc::dealloc(
ptr,
std::alloc::Layout::from_size_align_unchecked(512, 1),
)
};
}
}