memory.rs.html -- source
Description: Source to the Rust file `src/libcore/../stdsimd/coresimd/wasm32/memory.rs`.
Keywords: rust, rustlang, rust-lang

     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

    #[cfg(test)]
    use stdsimd_test::assert_instr;
    #[cfg(test)]
    use wasm_bindgen_test::wasm_bindgen_test;

    extern "C" {
        #[link_name = "llvm.wasm.memory.grow.i32"]
        fn llvm_memory_grow(mem: i32, pages: i32) -> i32;
        #[link_name = "llvm.wasm.memory.size.i32"]
        fn llvm_memory_size(mem: i32) -> i32;
    }

    /// Corresponding intrinsic to wasm's [`memory.size` instruction][instr]
    ///
    /// This function, when called, will return the current memory size in units of
    /// pages.
    ///
    /// The argument `mem` is the numerical index of which memory to return the
    /// size of. Note that currently wasm only supports one memory, so specifying
    /// a nonzero value will likely result in a runtime validation error of the
    /// wasm module.
    ///
    /// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
    #[inline]
    #[cfg_attr(test, assert_instr("memory.size", mem = 0))]
    #[rustc_args_required_const(0)]
    pub unsafe fn size(mem: i32) -> i32 {
        if mem != 0 {
            ::intrinsics::abort();
        }
        llvm_memory_size(0)
    }

    /// Corresponding intrinsic to wasm's [`memory.grow` instruction][instr]
    ///
    /// This function, when called, will attempt to grow the default linear memory
    /// by the specified `delta` of pages. If memory is successfully grown then the
    /// previous size of memory, in pages, is returned. If memory cannot be grown
    /// then -1 is returned.
    ///
    /// The argument `mem` is the numerical index of which memory to return the
    /// size of. Note that currently wasm only supports one memory, so specifying
    /// a nonzero value will likely result in a runtime validation error of the
    /// wasm module.
    ///
    /// [instr]: https://github.com/WebAssembly/design/blob/master/Semantics.md#resizing
    #[inline]
    #[cfg_attr(test, assert_instr("memory.grow", mem = 0))]
    #[rustc_args_required_const(0)]
    pub unsafe fn grow(mem: i32, delta: i32) -> i32 {
        if mem != 0 {
            ::intrinsics::abort();
        }
        llvm_memory_grow(0, delta)
    }

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)