From dcadb8308869740a5c1d89181522533a4f670d37 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sun, 18 Oct 2026 01:30:23 +0200 Subject: [PATCH] feat: add Platform::map_shared and wire memory delegation to page mapping --- crates/kernel/src/syscall/capability.rs | 18 +++++++++++++++--- crates/kernel/src/tests/mock_platform.rs | 12 +++++++++++- crates/platform/src/lib.rs | 11 ++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/crates/kernel/src/syscall/capability.rs b/crates/kernel/src/syscall/capability.rs index 3a7e9cd..0db8596 100644 --- a/crates/kernel/src/syscall/capability.rs +++ b/crates/kernel/src/syscall/capability.rs @@ -39,10 +39,22 @@ impl Kernel

{ Err(e) => return SyscallOutcome::Complete(SyscallResult::Error(e)), }; - match self.grant_cap(target_pid, resource, restricted) { - Ok(_) => SyscallOutcome::Complete(SyscallResult::Ok), - Err(e) => SyscallOutcome::Complete(SyscallResult::Error(e)), + if let Err(e) = self.grant_cap(target_pid, resource.clone(), restricted) { + return SyscallOutcome::Complete(SyscallResult::Error(e)); } + + if let domain::resource::Resource::Memory(region_id) = &resource { + if let Some(region) = self.regions.get(*region_id) { + self.platform.map_shared( + target_pid, + region.base(), + region.size(), + restricted, + ); + } + } + + SyscallOutcome::Complete(SyscallResult::Ok) } pub(crate) fn handle_revoke( diff --git a/crates/kernel/src/tests/mock_platform.rs b/crates/kernel/src/tests/mock_platform.rs index 8ef02d9..d92bd4d 100644 --- a/crates/kernel/src/tests/mock_platform.rs +++ b/crates/kernel/src/tests/mock_platform.rs @@ -2,8 +2,10 @@ use domain::memory::MemoryRegion; use domain::thread::SavedContext; use platform::Platform; use types::{ - address::{EntryPoint, StackPointer}, + address::{EntryPoint, PhysicalAddress, StackPointer}, + bounded::PageCount, id::{CoreId, IrqId, ProcessId}, + permission::PermissionSet, time::{Ticks, TimerDuration}, }; @@ -46,4 +48,12 @@ impl Platform for MockPlatform { fn num_cores(&self) -> u8 { self.cores } + fn map_shared( + &mut self, + _process: ProcessId, + _base: PhysicalAddress, + _size: PageCount, + _permissions: PermissionSet, + ) { + } } diff --git a/crates/platform/src/lib.rs b/crates/platform/src/lib.rs index 61f0091..bf65a0c 100644 --- a/crates/platform/src/lib.rs +++ b/crates/platform/src/lib.rs @@ -2,8 +2,10 @@ use domain::{memory::MemoryRegion, thread::SavedContext}; use types::{ - address::{EntryPoint, StackPointer}, + address::{EntryPoint, PhysicalAddress, StackPointer}, + bounded::PageCount, id::{CoreId, IrqId, ProcessId}, + permission::PermissionSet, time::{Ticks, TimerDuration}, }; @@ -20,4 +22,11 @@ pub trait Platform { fn send_ipi(&mut self, target: CoreId); fn core_id(&self) -> CoreId; fn num_cores(&self) -> u8; + fn map_shared( + &mut self, + process: ProcessId, + base: PhysicalAddress, + size: PageCount, + permissions: PermissionSet, + ); }