Skip to content

Commit

Permalink
Removed the old "ownership"-based code from BinaryPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Apr 18, 2023
1 parent 58de1a3 commit 0f930c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 68 deletions.
72 changes: 5 additions & 67 deletions lib/wasi/src/bin_factory/binary_package.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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<T>,
) -> Self
where
T: 'static,
{
Self::new(name, atom.to_vec().into())
}

pub fn name(&self) -> &str {
&self.name
}
Expand All @@ -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<u128>,
pub ownership: Option<Arc<dyn Any + Send + Sync + 'static>>,
#[derivative(Debug = "ignore")]
pub entry: Option<SharedBytes>,
pub hash: Arc<Mutex<Option<String>>>,
Expand All @@ -79,48 +59,6 @@ pub struct BinaryPackage {
}

impl BinaryPackage {
pub fn new(package_name: &str, entry: Option<SharedBytes>) -> 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<SharedBytes>,
ownership: Arc<T>,
) -> Self
where
T: 'static,
{
let ownership: Arc<dyn Any> = 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() {
Expand Down
1 change: 0 additions & 1 deletion lib/wasi/src/wapm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ fn parse_webc_v2(webc: &Container) -> Result<BinaryPackage, anyhow::Error> {
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)),
Expand Down

0 comments on commit 0f930c6

Please sign in to comment.