From ed5725269f162e36b4510618ea061781f83de352 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 19 Apr 2023 01:49:23 +0800 Subject: [PATCH] Removed the old "ownership"-based code from BinaryPackage --- lib/wasi/src/bin_factory/binary_package.rs | 72 ++-------------------- lib/wasi/src/wapm/mod.rs | 1 - 2 files changed, 5 insertions(+), 68 deletions(-) diff --git a/lib/wasi/src/bin_factory/binary_package.rs b/lib/wasi/src/bin_factory/binary_package.rs index 283e8a80e25..831d4330bd4 100644 --- a/lib/wasi/src/bin_factory/binary_package.rs +++ b/lib/wasi/src/bin_factory/binary_package.rs @@ -1,17 +1,11 @@ -use std::{ - any::Any, - borrow::Cow, - sync::{Arc, Mutex, RwLock}, -}; +use std::sync::{Arc, Mutex, RwLock}; use derivative::*; use once_cell::sync::OnceCell; use virtual_fs::FileSystem; -use wasmer_wasix_types::wasi::Snapshot0Clockid; use webc::compat::SharedBytes; use super::hash_of_binary; -use crate::syscalls::platform_clock_time_get; #[derive(Derivative, Clone)] #[derivative(Debug)] @@ -31,23 +25,6 @@ impl BinaryPackageCommand { } } - /// Hold on to some arbitrary data for the lifetime of this binary pacakge. - /// - /// # Safety - /// - /// Must ensure that the atom data will be safe to use as long as the provided - /// ownership handle stays alive. - pub unsafe fn new_with_ownership<'a, T>( - name: String, - atom: Cow<'a, [u8]>, - _ownership: Arc, - ) -> Self - where - T: 'static, - { - Self::new(name, atom.to_vec().into()) - } - pub fn name(&self) -> &str { &self.name } @@ -61,12 +38,15 @@ impl BinaryPackageCommand { } } +/// A WebAssembly package that has been loaded into memory. +/// +/// You can crate a [`BinaryPackage`] using [`crate::bin_factory::ModuleCache`] +/// or [`crate::wapm::parse_static_webc()`]. #[derive(Derivative, Clone)] #[derivative(Debug)] pub struct BinaryPackage { pub package_name: String, pub when_cached: Option, - pub ownership: Option>, #[derivative(Debug = "ignore")] pub entry: Option, pub hash: Arc>>, @@ -79,48 +59,6 @@ pub struct BinaryPackage { } impl BinaryPackage { - pub fn new(package_name: &str, entry: Option) -> Self { - let now = platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000).unwrap() as u128; - let (package_name, version) = match package_name.split_once('@') { - Some((a, b)) => (a.to_string(), b.to_string()), - None => (package_name.to_string(), "1.0.0".to_string()), - }; - let module_memory_footprint = entry.as_ref().map(|a| a.len()).unwrap_or_default() as u64; - Self { - package_name, - when_cached: Some(now), - ownership: None, - entry, - hash: Arc::new(Mutex::new(None)), - webc_fs: None, - commands: Arc::new(RwLock::new(Vec::new())), - uses: Vec::new(), - version, - module_memory_footprint, - file_system_memory_footprint: 0, - } - } - - /// Hold on to some arbitrary data for the lifetime of this binary pacakge. - /// - /// # Safety - /// - /// Must ensure that the entry data will be safe to use as long as the provided - /// ownership handle stays alive. - pub unsafe fn new_with_ownership<'a, T>( - package_name: &str, - entry: Option, - ownership: Arc, - ) -> Self - where - T: 'static, - { - let ownership: Arc = ownership; - let mut ret = Self::new(package_name, entry); - ret.ownership = Some(std::mem::transmute(ownership)); - ret - } - pub fn hash(&self) -> String { let mut hash = self.hash.lock().unwrap(); if hash.is_none() { diff --git a/lib/wasi/src/wapm/mod.rs b/lib/wasi/src/wapm/mod.rs index 2a938d3dfaf..026fa29c75f 100644 --- a/lib/wasi/src/wapm/mod.rs +++ b/lib/wasi/src/wapm/mod.rs @@ -305,7 +305,6 @@ fn parse_webc_v2(webc: &Container) -> Result { crate::syscalls::platform_clock_time_get(Snapshot0Clockid::Monotonic, 1_000_000) .unwrap() as u128, ), - ownership: None, entry: entry.map(Into::into), hash: Arc::new(Mutex::new(None)), webc_fs: Some(Arc::new(webc_fs)),