feat(runtime): implement shared transactional memcard with async saves
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
This commit is contained in:
@@ -6,12 +6,25 @@ use crate::asset::{
|
||||
use crate::cartridge::AssetsPayloadSource;
|
||||
|
||||
pub trait AssetBridge {
|
||||
/// Bind before cartridge preload/loading. Hosts supporting memcard must use
|
||||
/// this same lane for assets; an unsupported bridge refuses the fast profile.
|
||||
fn bind_background_work(
|
||||
&mut self,
|
||||
_lane: std::sync::Arc<dyn crate::background_work::BackgroundWork>,
|
||||
) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn initialize_for_cartridge(
|
||||
&self,
|
||||
assets: Vec<AssetEntry>,
|
||||
preload: Vec<PreloadEntry>,
|
||||
assets_data: AssetsPayloadSource,
|
||||
);
|
||||
/// Admission waits until all preloads are installed. Failure blocks guest boot.
|
||||
fn preloads_ready(&self) -> Result<bool, AssetLoadError> {
|
||||
Ok(true)
|
||||
}
|
||||
fn load(&self, asset_id: AssetId, slot_index: usize) -> Result<HandleId, AssetLoadError>;
|
||||
fn status(&self, handle: HandleId) -> LoadStatus;
|
||||
fn commit(&self, handle: HandleId) -> AssetOpStatus;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//! Portable submission seam for host-owned cooperative IO execution.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum WorkStep {
|
||||
Yield,
|
||||
Complete,
|
||||
Failed,
|
||||
}
|
||||
pub type AssetWork = Box<dyn FnMut(bool) -> WorkStep + Send + 'static>;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct WorkUnavailable;
|
||||
pub trait BackgroundWork: Send + Sync {
|
||||
fn submit_asset(&self, work: AssetWork) -> Result<(), WorkUnavailable>;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use crate::asset::{AssetEntry, PreloadEntry};
|
||||
use crate::syscalls::CapFlags;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::File;
|
||||
use std::io::{self, Cursor, Read, Seek, SeekFrom};
|
||||
use std::io::{self, Read, Seek, SeekFrom};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -18,6 +18,7 @@ pub struct Cartridge {
|
||||
pub app_version: String,
|
||||
pub app_mode: AppMode,
|
||||
pub capabilities: CapFlags,
|
||||
pub memcard_slots: Option<u8>,
|
||||
pub program: Vec<u8>,
|
||||
pub assets: AssetsPayloadSource,
|
||||
pub asset_table: Vec<AssetEntry>,
|
||||
@@ -31,6 +32,7 @@ pub struct CartridgeDTO {
|
||||
pub app_version: String,
|
||||
pub app_mode: AppMode,
|
||||
pub capabilities: CapFlags,
|
||||
pub memcard_slots: Option<u8>,
|
||||
pub program: Vec<u8>,
|
||||
pub assets: AssetsPayloadSource,
|
||||
pub asset_table: Vec<AssetEntry>,
|
||||
@@ -45,6 +47,7 @@ impl From<CartridgeDTO> for Cartridge {
|
||||
app_version: dto.app_version,
|
||||
app_mode: dto.app_mode,
|
||||
capabilities: dto.capabilities,
|
||||
memcard_slots: dto.memcard_slots,
|
||||
program: dto.program,
|
||||
assets: dto.assets,
|
||||
asset_table: dto.asset_table,
|
||||
@@ -125,8 +128,12 @@ impl AssetsPayloadSlice {
|
||||
pub fn open_reader(&self) -> io::Result<AssetsPayloadReader> {
|
||||
match self {
|
||||
Self::Memory { bytes, start, len } => {
|
||||
let data = Arc::<[u8]>::from(bytes[*start..*start + *len].to_vec());
|
||||
Ok(AssetsPayloadReader::Memory(Cursor::new(data)))
|
||||
Ok(AssetsPayloadReader::Memory(MemorySliceReader {
|
||||
bytes: Arc::clone(bytes),
|
||||
start: *start,
|
||||
len: *len,
|
||||
position: 0,
|
||||
}))
|
||||
}
|
||||
Self::File { source, offset, size } => {
|
||||
let mut file = File::open(&source.path)?;
|
||||
@@ -151,7 +158,7 @@ impl AssetsPayloadSlice {
|
||||
}
|
||||
|
||||
pub enum AssetsPayloadReader {
|
||||
Memory(Cursor<Arc<[u8]>>),
|
||||
Memory(MemorySliceReader),
|
||||
File(FileSliceReader),
|
||||
}
|
||||
|
||||
@@ -173,6 +180,37 @@ impl Seek for AssetsPayloadReader {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MemorySliceReader {
|
||||
bytes: Arc<[u8]>,
|
||||
start: usize,
|
||||
len: usize,
|
||||
position: usize,
|
||||
}
|
||||
impl Read for MemorySliceReader {
|
||||
fn read(&mut self, target: &mut [u8]) -> io::Result<usize> {
|
||||
let n = target.len().min(self.len.saturating_sub(self.position));
|
||||
target[..n].copy_from_slice(
|
||||
&self.bytes[self.start + self.position..self.start + self.position + n],
|
||||
);
|
||||
self.position += n;
|
||||
Ok(n)
|
||||
}
|
||||
}
|
||||
impl Seek for MemorySliceReader {
|
||||
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
||||
let next = match pos {
|
||||
SeekFrom::Start(n) => n as i128,
|
||||
SeekFrom::Current(n) => self.position as i128 + n as i128,
|
||||
SeekFrom::End(n) => self.len as i128 + n as i128,
|
||||
};
|
||||
if next < 0 || next > self.len as i128 {
|
||||
return Err(invalid_input("slice seek out of bounds"));
|
||||
}
|
||||
self.position = next as usize;
|
||||
Ok(self.position as u64)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FileSliceReader {
|
||||
file: File,
|
||||
start: u64,
|
||||
@@ -292,6 +330,7 @@ pub enum Capability {
|
||||
Gfxui,
|
||||
Audio,
|
||||
Fs,
|
||||
Memcard,
|
||||
Log,
|
||||
Asset,
|
||||
Bank,
|
||||
@@ -308,4 +347,6 @@ pub struct CartridgeManifest {
|
||||
pub app_mode: AppMode,
|
||||
#[serde(default)]
|
||||
pub capabilities: Vec<Capability>,
|
||||
#[serde(default)]
|
||||
pub memcard_slots: Option<u8>,
|
||||
}
|
||||
|
||||
@@ -55,6 +55,11 @@ impl DirectoryCartridgeLoader {
|
||||
}
|
||||
|
||||
let capabilities = normalize_capabilities(&manifest.capabilities)?;
|
||||
if ((capabilities & caps::MEMCARD) != 0) != manifest.memcard_slots.is_some()
|
||||
|| manifest.memcard_slots.is_some_and(|n| !(1..=64).contains(&n))
|
||||
{
|
||||
return Err(CartridgeError::InvalidManifest);
|
||||
}
|
||||
|
||||
let program_path = path.join("program.pbx");
|
||||
if !program_path.exists() {
|
||||
@@ -91,6 +96,7 @@ impl DirectoryCartridgeLoader {
|
||||
app_version: manifest.app_version,
|
||||
app_mode: manifest.app_mode,
|
||||
capabilities,
|
||||
memcard_slots: manifest.memcard_slots,
|
||||
program,
|
||||
assets,
|
||||
asset_table,
|
||||
@@ -180,6 +186,7 @@ fn normalize_capabilities(capabilities: &[Capability]) -> Result<CapFlags, Cartr
|
||||
Capability::Gfxui => caps::GFXUI,
|
||||
Capability::Audio => caps::AUDIO,
|
||||
Capability::Fs => caps::FS,
|
||||
Capability::Memcard => caps::MEMCARD,
|
||||
Capability::Log => caps::LOG,
|
||||
Capability::Asset => caps::ASSET,
|
||||
Capability::Bank => caps::BANK,
|
||||
@@ -447,7 +454,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn load_with_all_capability_normalizes_to_all_flags() {
|
||||
let dir = TestCartridgeDir::new(manifest_with_capabilities(Some(vec!["all"])));
|
||||
let mut manifest = manifest_with_capabilities(Some(vec!["all"]));
|
||||
manifest["memcard_slots"] = serde_json::json!(1);
|
||||
let dir = TestCartridgeDir::new(manifest);
|
||||
dir.write_assets_pa(vec![], vec![], &[]);
|
||||
|
||||
let cartridge = DirectoryCartridgeLoader::load(dir.path()).expect("cartridge must load");
|
||||
|
||||
@@ -13,6 +13,14 @@ pub trait GuestStringAllocator {
|
||||
) -> Result<Arc<str>, VmFault>;
|
||||
}
|
||||
|
||||
/// A bounded, call-scoped Array<Int32> byte carrier. Implementations validate
|
||||
/// concrete array type, every value and all bounds before exposing mutations.
|
||||
pub trait GuestByteArrays {
|
||||
fn validate(&mut self, handle: HeapRef, offset: usize, count: usize) -> Result<(), VmFault>;
|
||||
fn read(&mut self, handle: HeapRef, offset: usize, target: &mut [u8]) -> Result<(), VmFault>;
|
||||
fn write(&mut self, handle: HeapRef, offset: usize, bytes: &[u8]) -> Result<(), VmFault>;
|
||||
}
|
||||
|
||||
/// Writes only into result slots reserved by the VM. A native handler cannot
|
||||
/// grow the operand buffer or exceed its declared result count.
|
||||
pub struct HostReturn<'a> {
|
||||
@@ -21,6 +29,7 @@ pub struct HostReturn<'a> {
|
||||
overflowed: bool,
|
||||
strings: &'a mut dyn GuestStringAllocator,
|
||||
failure: Option<VmFault>,
|
||||
arrays: Option<&'a mut dyn GuestByteArrays>,
|
||||
}
|
||||
|
||||
impl<'a> HostReturn<'a> {
|
||||
@@ -39,7 +48,21 @@ impl<'a> HostReturn<'a> {
|
||||
result_slots: usize,
|
||||
strings: &'a mut dyn GuestStringAllocator,
|
||||
) -> Self {
|
||||
Self { stack, remaining: result_slots, overflowed: false, strings, failure: None }
|
||||
Self {
|
||||
stack,
|
||||
remaining: result_slots,
|
||||
overflowed: false,
|
||||
strings,
|
||||
failure: None,
|
||||
arrays: None,
|
||||
}
|
||||
}
|
||||
pub fn with_arrays(mut self, arrays: &'a mut dyn GuestByteArrays) -> Self {
|
||||
self.arrays = Some(arrays);
|
||||
self
|
||||
}
|
||||
pub fn byte_arrays(&mut self) -> Result<&mut (dyn GuestByteArrays + 'a), VmFault> {
|
||||
self.arrays.as_deref_mut().ok_or(VmFault::Unavailable)
|
||||
}
|
||||
pub fn failure(&self) -> Option<&VmFault> {
|
||||
self.failure.as_ref()
|
||||
|
||||
@@ -2,6 +2,7 @@ pub mod app_mode;
|
||||
pub mod asset;
|
||||
pub mod asset_bridge;
|
||||
pub mod audio_bridge;
|
||||
pub mod background_work;
|
||||
pub mod button;
|
||||
pub mod cartridge;
|
||||
pub mod cartridge_loader;
|
||||
@@ -15,6 +16,7 @@ pub mod host_context;
|
||||
pub mod host_return;
|
||||
pub mod input_signals;
|
||||
pub mod log;
|
||||
pub mod memcard;
|
||||
pub mod native_helpers;
|
||||
pub mod native_interface;
|
||||
pub mod owned_frame;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//! Host region IO. Logical mapping, checksums and publication belong to the runtime.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum MemcardIoError {
|
||||
Unavailable,
|
||||
ReadOnly,
|
||||
InvalidRange,
|
||||
NoSpace,
|
||||
Unsupported,
|
||||
IoError,
|
||||
}
|
||||
|
||||
/// Implementations return success only for a complete transfer. Errors may have
|
||||
/// partial effects. Instances stay owned by their worker until all IO has ceased.
|
||||
pub trait MemcardStorage: Send {
|
||||
fn len(&self) -> Result<u64, MemcardIoError>;
|
||||
fn is_empty(&self) -> Result<bool, MemcardIoError> {
|
||||
self.len().map(|length| length == 0)
|
||||
}
|
||||
fn read_at(&mut self, offset: u64, target: &mut [u8]) -> Result<(), MemcardIoError>;
|
||||
fn write_at(&mut self, offset: u64, source: &[u8]) -> Result<(), MemcardIoError>;
|
||||
fn sync(&mut self) -> Result<(), MemcardIoError>;
|
||||
fn read_only(&self) -> bool;
|
||||
}
|
||||
@@ -62,12 +62,20 @@ pub enum Syscall {
|
||||
FsListDir = 0x4005,
|
||||
FsExists = 0x4006,
|
||||
FsDelete = 0x4007,
|
||||
MemBootstrap = 0x4200,
|
||||
MemSlotCount = 0x4201,
|
||||
MemSlotStat = 0x4202,
|
||||
MemSlotRead = 0x4203,
|
||||
MemSlotWrite = 0x4204,
|
||||
MemSlotCommit = 0x4205,
|
||||
MemSlotClear = 0x4206,
|
||||
MemQuery = 0x4207,
|
||||
MemRelease = 0x4208,
|
||||
MemInfo = 0x4209,
|
||||
MemMetadata = 0x420A,
|
||||
MemPresentation = 0x420B,
|
||||
MemDiagnostic = 0x420C,
|
||||
MemPublishPresentation = 0x420D,
|
||||
LogWrite = 0x5001,
|
||||
LogWriteTag = 0x5002,
|
||||
AssetLoad = 0x6001,
|
||||
|
||||
@@ -10,5 +10,7 @@ pub const ASSET: CapFlags = 1 << 5;
|
||||
pub const BANK: CapFlags = 1 << 6;
|
||||
pub const GFX2D: CapFlags = 1 << 7;
|
||||
pub const GFXUI: CapFlags = 1 << 8;
|
||||
pub const MEMCARD: CapFlags = 1 << 9;
|
||||
pub const GFX: CapFlags = COMPOSER | GFX2D;
|
||||
pub const ALL: CapFlags = SYSTEM | COMPOSER | AUDIO | FS | LOG | ASSET | BANK | GFX2D | GFXUI;
|
||||
pub const ALL: CapFlags =
|
||||
SYSTEM | COMPOSER | AUDIO | FS | LOG | ASSET | BANK | GFX2D | GFXUI | MEMCARD;
|
||||
|
||||
@@ -32,37 +32,4 @@ pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
.caps(caps::FS)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotCount, "mem", "slot_count")
|
||||
.rets(2)
|
||||
.caps(caps::FS),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotStat, "mem", "slot_stat")
|
||||
.args(1)
|
||||
.rets(5)
|
||||
.caps(caps::FS)
|
||||
.non_deterministic()
|
||||
.cost(5),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotRead, "mem", "slot_read")
|
||||
.args(3)
|
||||
.rets(3)
|
||||
.caps(caps::FS)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotWrite, "mem", "slot_write")
|
||||
.args(3)
|
||||
.rets(2)
|
||||
.caps(caps::FS)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotCommit, "mem", "slot_commit")
|
||||
.args(1)
|
||||
.rets(1)
|
||||
.caps(caps::FS)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotClear, "mem", "slot_clear")
|
||||
.args(1)
|
||||
.rets(1)
|
||||
.caps(caps::FS)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
];
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
use crate::syscalls::{Syscall, SyscallRegistryEntry, caps};
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
SyscallRegistryEntry::builder(Syscall::MemBootstrap, "mem", "bootstrap")
|
||||
.args(0)
|
||||
.rets(1)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotCount, "mem", "slot_count")
|
||||
.args(1)
|
||||
.rets(2)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotStat, "mem", "slot_stat")
|
||||
.args(2)
|
||||
.rets(7)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotRead, "mem", "slot_read")
|
||||
.args(6)
|
||||
.rets(2)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotWrite, "mem", "slot_write")
|
||||
.args(6)
|
||||
.rets(2)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotCommit, "mem", "slot_commit")
|
||||
.args(2)
|
||||
.rets(2)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemSlotClear, "mem", "slot_clear")
|
||||
.args(2)
|
||||
.rets(1)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemQuery, "mem", "query")
|
||||
.args(2)
|
||||
.rets(3)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemRelease, "mem", "release")
|
||||
.args(2)
|
||||
.rets(1)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemInfo, "mem", "info")
|
||||
.args(1)
|
||||
.rets(6)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemMetadata, "mem", "metadata")
|
||||
.args(1)
|
||||
.rets(4)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemPresentation, "mem", "presentation")
|
||||
.args(8)
|
||||
.rets(1)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemDiagnostic, "mem", "diagnostic")
|
||||
.args(2)
|
||||
.rets(1)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
SyscallRegistryEntry::builder(Syscall::MemPublishPresentation, "mem", "publish_presentation")
|
||||
.args(1)
|
||||
.rets(2)
|
||||
.caps(caps::MEMCARD)
|
||||
.non_deterministic()
|
||||
.cost(20),
|
||||
];
|
||||
@@ -18,7 +18,10 @@ pub(crate) fn all_entries() -> impl Iterator<Item = &'static SyscallRegistryEntr
|
||||
.chain(composer::ENTRIES.iter())
|
||||
.chain(audio::ENTRIES.iter())
|
||||
.chain(fs::ENTRIES.iter())
|
||||
.chain(memcard::ENTRIES.iter())
|
||||
.chain(log::ENTRIES.iter())
|
||||
.chain(asset::ENTRIES.iter())
|
||||
.chain(bank::ENTRIES.iter())
|
||||
}
|
||||
|
||||
mod memcard;
|
||||
|
||||
@@ -40,6 +40,14 @@ impl Syscall {
|
||||
0x4005 => Some(Self::FsListDir),
|
||||
0x4006 => Some(Self::FsExists),
|
||||
0x4007 => Some(Self::FsDelete),
|
||||
0x4200 => Some(Self::MemBootstrap),
|
||||
0x4207 => Some(Self::MemQuery),
|
||||
0x4208 => Some(Self::MemRelease),
|
||||
0x4209 => Some(Self::MemInfo),
|
||||
0x420A => Some(Self::MemMetadata),
|
||||
0x420B => Some(Self::MemPresentation),
|
||||
0x420C => Some(Self::MemDiagnostic),
|
||||
0x420D => Some(Self::MemPublishPresentation),
|
||||
0x4201 => Some(Self::MemSlotCount),
|
||||
0x4202 => Some(Self::MemSlotStat),
|
||||
0x4203 => Some(Self::MemSlotRead),
|
||||
@@ -101,6 +109,14 @@ impl Syscall {
|
||||
Self::FsListDir => "FsListDir",
|
||||
Self::FsExists => "FsExists",
|
||||
Self::FsDelete => "FsDelete",
|
||||
Self::MemBootstrap => "MemBootstrap",
|
||||
Self::MemQuery => "MemQuery",
|
||||
Self::MemRelease => "MemRelease",
|
||||
Self::MemInfo => "MemInfo",
|
||||
Self::MemMetadata => "MemMetadata",
|
||||
Self::MemPresentation => "MemPresentation",
|
||||
Self::MemDiagnostic => "MemDiagnostic",
|
||||
Self::MemPublishPresentation => "MemPublishPresentation",
|
||||
Self::MemSlotCount => "MemSlotCount",
|
||||
Self::MemSlotStat => "MemSlotStat",
|
||||
Self::MemSlotRead => "MemSlotRead",
|
||||
|
||||
@@ -460,29 +460,39 @@ fn declared_resolver_accepts_mixed_status_first_surface_as_a_single_module() {
|
||||
|
||||
#[test]
|
||||
fn memcard_syscall_signatures_are_pinned() {
|
||||
let slot_count = meta_for(Syscall::MemSlotCount);
|
||||
assert_eq!(slot_count.module, "mem");
|
||||
assert_eq!(slot_count.name, "slot_count");
|
||||
assert_eq!(slot_count.arg_slots, 0);
|
||||
assert_eq!(slot_count.ret_slots, 2);
|
||||
|
||||
let slot_stat = meta_for(Syscall::MemSlotStat);
|
||||
assert_eq!(slot_stat.arg_slots, 1);
|
||||
assert_eq!(slot_stat.ret_slots, 5);
|
||||
|
||||
let slot_read = meta_for(Syscall::MemSlotRead);
|
||||
assert_eq!(slot_read.arg_slots, 3);
|
||||
assert_eq!(slot_read.ret_slots, 3);
|
||||
|
||||
let slot_write = meta_for(Syscall::MemSlotWrite);
|
||||
assert_eq!(slot_write.arg_slots, 3);
|
||||
assert_eq!(slot_write.ret_slots, 2);
|
||||
|
||||
let slot_commit = meta_for(Syscall::MemSlotCommit);
|
||||
assert_eq!(slot_commit.arg_slots, 1);
|
||||
assert_eq!(slot_commit.ret_slots, 1);
|
||||
|
||||
let slot_clear = meta_for(Syscall::MemSlotClear);
|
||||
assert_eq!(slot_clear.arg_slots, 1);
|
||||
assert_eq!(slot_clear.ret_slots, 1);
|
||||
for (call, args, results) in [
|
||||
(Syscall::MemBootstrap, 0, 1),
|
||||
(Syscall::MemSlotCount, 1, 2),
|
||||
(Syscall::MemSlotStat, 2, 7),
|
||||
(Syscall::MemSlotRead, 6, 2),
|
||||
(Syscall::MemSlotWrite, 6, 2),
|
||||
(Syscall::MemSlotCommit, 2, 2),
|
||||
(Syscall::MemSlotClear, 2, 1),
|
||||
(Syscall::MemQuery, 2, 3),
|
||||
(Syscall::MemRelease, 2, 1),
|
||||
(Syscall::MemInfo, 1, 6),
|
||||
(Syscall::MemMetadata, 1, 4),
|
||||
(Syscall::MemPresentation, 8, 1),
|
||||
(Syscall::MemDiagnostic, 2, 1),
|
||||
(Syscall::MemPublishPresentation, 1, 2),
|
||||
] {
|
||||
let meta = meta_for(call);
|
||||
assert_eq!(meta.module, "mem");
|
||||
assert_eq!(meta.arg_slots, args);
|
||||
assert_eq!(meta.ret_slots, results);
|
||||
assert!(
|
||||
resolve_program_syscalls(
|
||||
&[SyscallIdentity { module: "mem", name: meta.name, version: 1 }],
|
||||
caps::FS
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
resolve_program_syscalls(
|
||||
&[SyscallIdentity { module: "mem", name: meta.name, version: 1 }],
|
||||
caps::MEMCARD
|
||||
)
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user