MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / new_rounded_up

Method new_rounded_up

crates/wasmtime/src/runtime/vm/byte_count.rs:48–55  ·  view source on GitHub ↗

Creates a new `HostAlignedByteCount`, rounding up to the nearest page. Returns an error if `bytes + page_size - 1` overflows.

(bytes: usize)

Source from the content-addressed store, hash-verified

46 ///
47 /// Returns an error if `bytes + page_size - 1` overflows.
48 pub fn new_rounded_up(bytes: usize) -> Result<Self, ByteCountOutOfBounds> {
49 let page_size = host_page_size();
50 debug_assert!(page_size.is_power_of_two());
51 match bytes.checked_add(page_size - 1) {
52 Some(v) => Ok(Self(v & !(page_size - 1))),
53 None => Err(ByteCountOutOfBounds(ByteCountOutOfBoundsKind::RoundUp)),
54 }
55 }
56
57 /// Creates a new `HostAlignedByteCount` from a `u64`, rounding up to the nearest page.
58 ///

Callers

nothing calls this directly

Calls 4

OkFunction · 0.85
host_page_sizeFunction · 0.50
checked_addMethod · 0.45

Tested by

no test coverage detected