feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
//! Phase 88: Ring0Context - OS API 抽象化レイヤー
|
|
|
|
|
//!
|
|
|
|
|
//! Ring0 は Box を知らない、Nyash を知らない純粋な OS API 層。
|
|
|
|
|
|
|
|
|
|
mod errors;
|
|
|
|
|
mod std_impls;
|
|
|
|
|
mod traits;
|
|
|
|
|
|
|
|
|
|
pub use errors::{IoError, TimeError};
|
2025-12-11 20:54:33 +09:00
|
|
|
pub use std_impls::{NoFsApi, NoopMem, StdFs, StdIo, StdLog, StdMem, StdThread, StdTime};
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
pub use traits::{
|
|
|
|
|
FsApi, FsMetadata, IoApi, LogApi, LogLevel, MemApi, MemStats, ThreadApi, TimeApi,
|
|
|
|
|
};
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
|
2025-12-03 22:19:24 +09:00
|
|
|
use crate::runtime::runtime_profile::RuntimeProfile;
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
use std::sync::{Arc, OnceLock};
|
|
|
|
|
|
|
|
|
|
/// Phase 88: Ring0 コンテキスト
|
|
|
|
|
///
|
|
|
|
|
/// OS API レイヤーを trait で抽象化し、1つの構造体に束ねる。
|
|
|
|
|
pub struct Ring0Context {
|
|
|
|
|
pub mem: Arc<dyn MemApi>,
|
|
|
|
|
pub io: Arc<dyn IoApi>,
|
|
|
|
|
pub time: Arc<dyn TimeApi>,
|
|
|
|
|
pub log: Arc<dyn LogApi>,
|
2025-12-11 20:54:33 +09:00
|
|
|
pub fs: Arc<dyn FsApi>, // Phase 90-A
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
pub thread: Arc<dyn ThreadApi>, // Phase 90-D
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Ring0Context {
|
|
|
|
|
/// 新規 Ring0Context を作成
|
|
|
|
|
pub fn new(
|
|
|
|
|
mem: Arc<dyn MemApi>,
|
|
|
|
|
io: Arc<dyn IoApi>,
|
|
|
|
|
time: Arc<dyn TimeApi>,
|
|
|
|
|
log: Arc<dyn LogApi>,
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
fs: Arc<dyn FsApi>,
|
|
|
|
|
thread: Arc<dyn ThreadApi>,
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
) -> Self {
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
Self {
|
|
|
|
|
mem,
|
|
|
|
|
io,
|
|
|
|
|
time,
|
|
|
|
|
log,
|
|
|
|
|
fs,
|
|
|
|
|
thread,
|
|
|
|
|
}
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl std::fmt::Debug for Ring0Context {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
f.debug_struct("Ring0Context")
|
|
|
|
|
.field("mem", &"<dyn MemApi>")
|
|
|
|
|
.field("io", &"<dyn IoApi>")
|
|
|
|
|
.field("time", &"<dyn TimeApi>")
|
|
|
|
|
.field("log", &"<dyn LogApi>")
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
.field("fs", &"<dyn FsApi>")
|
|
|
|
|
.field("thread", &"<dyn ThreadApi>")
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 22:19:24 +09:00
|
|
|
/// Phase 112: Ring0 service registry
|
|
|
|
|
///
|
|
|
|
|
/// profile ごとに適切な FsApi 実装(等)を選択して Ring0Context を構築する factory。
|
|
|
|
|
pub struct Ring0Registry;
|
|
|
|
|
|
|
|
|
|
impl Ring0Registry {
|
|
|
|
|
/// Ring0Context を profile に応じて構築
|
|
|
|
|
pub fn build(profile: RuntimeProfile) -> Ring0Context {
|
|
|
|
|
match profile {
|
2025-12-04 03:18:49 +09:00
|
|
|
RuntimeProfile::Default => Self::build_with_fs(Arc::new(StdFs)),
|
|
|
|
|
RuntimeProfile::NoFs => Self::build_with_fs(Arc::new(NoFsApi)),
|
2025-12-03 22:19:24 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-04 03:18:49 +09:00
|
|
|
fn build_with_fs(fs: Arc<dyn FsApi>) -> Ring0Context {
|
2025-12-03 22:19:24 +09:00
|
|
|
Ring0Context {
|
|
|
|
|
mem: Arc::new(StdMem::new()),
|
|
|
|
|
io: Arc::new(StdIo),
|
|
|
|
|
time: Arc::new(StdTime),
|
|
|
|
|
log: Arc::new(StdLog),
|
2025-12-04 03:18:49 +09:00
|
|
|
fs,
|
2025-12-03 22:19:24 +09:00
|
|
|
thread: Arc::new(StdThread),
|
|
|
|
|
}
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 22:19:24 +09:00
|
|
|
/// Phase 88: デフォルト Ring0Context を作成
|
|
|
|
|
///
|
|
|
|
|
/// Phase 112 以降は、initialize_runtime() を通じて
|
|
|
|
|
/// Ring0Registry::build(profile) 経由で初期化されることが推奨。
|
|
|
|
|
///
|
|
|
|
|
/// この関数は直接呼び出しに対する互換性レイヤーとして保持。
|
|
|
|
|
pub fn default_ring0() -> Ring0Context {
|
|
|
|
|
Ring0Registry::build(RuntimeProfile::Default)
|
|
|
|
|
}
|
|
|
|
|
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
// ===== グローバル Ring0Context =====
|
|
|
|
|
|
|
|
|
|
pub static GLOBAL_RING0: OnceLock<Arc<Ring0Context>> = OnceLock::new();
|
|
|
|
|
|
|
|
|
|
/// グローバル Ring0Context を初期化
|
|
|
|
|
pub fn init_global_ring0(ctx: Ring0Context) {
|
|
|
|
|
GLOBAL_RING0
|
|
|
|
|
.set(Arc::new(ctx))
|
|
|
|
|
.expect("[Phase 88] Ring0Context already initialized");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// グローバル Ring0Context を取得
|
|
|
|
|
pub fn get_global_ring0() -> Arc<Ring0Context> {
|
|
|
|
|
GLOBAL_RING0
|
|
|
|
|
.get()
|
|
|
|
|
.expect("[Phase 88] Ring0Context not initialized")
|
|
|
|
|
.clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===== テスト =====
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
2025-12-04 03:18:49 +09:00
|
|
|
fn unsafe_dealloc(ptr: *mut u8, size: usize) {
|
2025-12-11 20:54:33 +09:00
|
|
|
unsafe { std::alloc::dealloc(ptr, std::alloc::Layout::from_size_align_unchecked(size, 1)) }
|
2025-12-04 03:18:49 +09:00
|
|
|
}
|
|
|
|
|
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
#[test]
|
|
|
|
|
fn test_ring0_context_creation() {
|
|
|
|
|
let ring0 = default_ring0();
|
|
|
|
|
ring0.log.info("test message");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_io_api() {
|
|
|
|
|
let ring0 = default_ring0();
|
|
|
|
|
let result = ring0.io.stdout_write(b"test\n");
|
|
|
|
|
assert!(result.is_ok());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_time_api() {
|
|
|
|
|
let ring0 = default_ring0();
|
|
|
|
|
let now = ring0.time.now();
|
|
|
|
|
assert!(now.is_ok());
|
|
|
|
|
|
|
|
|
|
let instant = ring0.time.monotonic_now();
|
|
|
|
|
assert!(instant.is_ok());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_log_levels() {
|
|
|
|
|
let ring0 = default_ring0();
|
|
|
|
|
ring0.log.debug("debug message");
|
|
|
|
|
ring0.log.info("info message");
|
|
|
|
|
ring0.log.warn("warn message");
|
|
|
|
|
ring0.log.error("error message");
|
|
|
|
|
}
|
2025-12-03 13:42:05 +09:00
|
|
|
|
|
|
|
|
#[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
|
2025-12-04 03:18:49 +09:00
|
|
|
unsafe_dealloc(ptr, 512);
|
2025-12-03 13:42:05 +09:00
|
|
|
}
|
2025-12-03 22:19:24 +09:00
|
|
|
|
|
|
|
|
// Phase 112: Ring0Registry tests
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ring0_registry_default_profile() {
|
|
|
|
|
let ctx = Ring0Registry::build(RuntimeProfile::Default);
|
|
|
|
|
|
|
|
|
|
// Verify basic operations work
|
|
|
|
|
ctx.log.info("Test message from Default profile");
|
|
|
|
|
assert!(ctx.time.now().is_ok());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ring0_registry_nofs_profile() {
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
let ctx = Ring0Registry::build(RuntimeProfile::NoFs);
|
|
|
|
|
|
|
|
|
|
// Verify NoFsApi returns errors
|
|
|
|
|
let result = ctx.fs.read_to_string(Path::new("/tmp/test.txt"));
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
|
|
|
|
|
// Verify exists returns false
|
|
|
|
|
assert!(!ctx.fs.exists(Path::new("/tmp/test.txt")));
|
|
|
|
|
|
|
|
|
|
// Other services should still work
|
|
|
|
|
ctx.log.info("Test message from NoFs profile");
|
|
|
|
|
assert!(ctx.time.now().is_ok());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_default_ring0_uses_registry() {
|
|
|
|
|
let ctx = default_ring0();
|
|
|
|
|
|
|
|
|
|
// Should behave same as Default profile
|
|
|
|
|
ctx.log.info("Test from default_ring0()");
|
|
|
|
|
assert!(ctx.time.now().is_ok());
|
|
|
|
|
}
|
2025-12-04 03:18:49 +09:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_read_to_string() {
|
|
|
|
|
let api = NoFsApi;
|
|
|
|
|
let result = api.read_to_string(std::path::Path::new("/tmp/test.txt"));
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
assert!(result.unwrap_err().to_string().contains("disabled"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_read() {
|
|
|
|
|
let api = NoFsApi;
|
|
|
|
|
assert!(api.read(std::path::Path::new("/tmp/test.txt")).is_err());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_write_all() {
|
|
|
|
|
let api = NoFsApi;
|
2025-12-11 20:54:33 +09:00
|
|
|
assert!(api
|
|
|
|
|
.write_all(std::path::Path::new("/tmp/test.txt"), b"data")
|
|
|
|
|
.is_err());
|
2025-12-04 03:18:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_append_all() {
|
|
|
|
|
let api = NoFsApi;
|
2025-12-11 20:54:33 +09:00
|
|
|
assert!(api
|
|
|
|
|
.append_all(std::path::Path::new("/tmp/test.txt"), b"data")
|
|
|
|
|
.is_err());
|
2025-12-04 03:18:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_exists() {
|
|
|
|
|
let api = NoFsApi;
|
|
|
|
|
assert!(!api.exists(std::path::Path::new("/tmp/test.txt")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_metadata() {
|
|
|
|
|
let api = NoFsApi;
|
|
|
|
|
assert!(api.metadata(std::path::Path::new("/tmp/test.txt")).is_err());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_nofs_api_canonicalize() {
|
|
|
|
|
let api = NoFsApi;
|
2025-12-11 20:54:33 +09:00
|
|
|
assert!(api
|
|
|
|
|
.canonicalize(std::path::Path::new("/tmp/test.txt"))
|
|
|
|
|
.is_err());
|
2025-12-04 03:18:49 +09:00
|
|
|
}
|
feat(phase88): Ring0Context Skeleton implementation
Phase 88: OS API abstraction layer implementation
**Implementation**:
- Ring0Context module added (4 files)
- mod.rs: Public API, global initialization (OnceLock)
- traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
- std_impls.rs: std-based default implementations
- errors.rs: IoError, TimeError type definitions
**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction
**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)
**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)
**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)
**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)
**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)
Phase 88 complete. Ready for Phase 89 (gradual migration).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
}
|