1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Shims for MemFdSlot when the memfd allocator is not
//! included. Enables unconditional use of the type and its methods
//! throughout higher-level code.

use crate::InstantiationError;
use anyhow::Result;
use std::sync::Arc;
use wasmtime_environ::{DefinedMemoryIndex, Module};

/// A shim for the memfd image container when memfd support is not
/// included.
pub enum ModuleMemFds {}

/// A shim for an individual memory image.
#[allow(dead_code)]
pub enum MemoryMemFd {}

impl ModuleMemFds {
    /// Construct a new set of memfd images. This variant is used
    /// when memfd support is not included; it always returns no
    /// images.
    pub fn new(_: &Module, _: &[u8]) -> Result<Option<Arc<ModuleMemFds>>> {
        Ok(None)
    }

    /// Get the memfd image for a particular memory.
    pub(crate) fn get_memory_image(&self, _: DefinedMemoryIndex) -> Option<&Arc<MemoryMemFd>> {
        // Should be unreachable because the `Self` type is
        // uninhabitable.
        match *self {}
    }
}

/// A placeholder for MemFdSlot when we have not included the pooling
/// allocator.
///
/// To allow MemFdSlot to be unconditionally passed around in various
/// places (e.g. a `Memory`), we define a zero-sized type when memfd is
/// not included in the build.
#[derive(Debug)]
pub enum MemFdSlot {}

#[allow(dead_code)]
impl MemFdSlot {
    pub(crate) fn create(_: *mut libc::c_void, _: usize, _: usize) -> Self {
        panic!("create() on invalid MemFdSlot");
    }

    pub(crate) fn instantiate(
        &mut self,
        _: usize,
        _: Option<&Arc<MemoryMemFd>>,
    ) -> Result<Self, InstantiationError> {
        match *self {}
    }

    pub(crate) fn no_clear_on_drop(&mut self) {
        match *self {}
    }

    pub(crate) fn clear_and_remain_ready(&mut self) -> Result<()> {
        match *self {}
    }

    pub(crate) fn has_image(&self) -> bool {
        match *self {}
    }

    pub(crate) fn is_dirty(&self) -> bool {
        match *self {}
    }

    pub(crate) fn set_heap_limit(&mut self, _: usize) -> Result<()> {
        match *self {}
    }
}