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

Function num_bytes_mapped

examples/mpk.rs:230–256  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228/// We parse the start and end addresses: <start>-<end> [ignore the rest].
229#[cfg(target_os = "linux")]
230fn num_bytes_mapped() -> Result<usize> {
231 use std::fs::File;
232 use std::io::{BufRead, BufReader};
233
234 let file = File::open("/proc/self/maps")?;
235 let reader = BufReader::new(file);
236 let mut total = 0;
237 for line in reader.lines() {
238 let line = line?;
239 let range = line
240 .split_whitespace()
241 .next()
242 .ok_or(format_err!("parse failure: expected whitespace"))?;
243 let mut addresses = range.split("-");
244 let start = addresses.next().ok_or(format_err!(
245 "parse failure: expected dash-separated address"
246 ))?;
247 let start = usize::from_str_radix(start, 16)?;
248 let end = addresses.next().ok_or(format_err!(
249 "parse failure: expected dash-separated address"
250 ))?;
251 let end = usize::from_str_radix(end, 16)?;
252
253 total += end - start;
254 }
255 Ok(total)
256}
257
258#[cfg(not(target_os = "linux"))]
259fn num_bytes_mapped() -> Result<usize> {

Callers 1

build_engineFunction · 0.85

Calls 4

OkFunction · 0.85
splitMethod · 0.80
newFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected