Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Cleanup: MemoryMapping (#286)
Browse files Browse the repository at this point in the history
* Adds a comment explaining gapped memory in MemoryMapping.

* Fixes memory mapping benchmarks.
  • Loading branch information
Lichtso authored Mar 18, 2022
1 parent 40df5e6 commit f4093e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion benches/memory_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn generate_memory_regions(

macro_rules! new_prng {
( ) => {
SmallRng::from_seed([0; 16])
SmallRng::from_seed([0; 32])
};
}

Expand Down
17 changes: 17 additions & 0 deletions src/memory_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ use crate::{
};
use std::fmt;

/* Explaination of the Gapped Memory
The MemoryMapping supports a special mapping mode which is used for the stack MemoryRegion.
In this mode the backing address space of the host is sliced in power-of-two aligned frames.
The exponent of this alignment is specified in vm_gap_shift. Then the virtual address space
of the guest is spread out in a way which leaves gapes, the same size as the frames, in
between the frames. This effectively doubles the size of the guests virtual address space.
But the acutual mapped memory stays the same, as the gaps are not mapped and accessing them
results in an AccessViolation.
Guest: frame 0 | gap 0 | frame 1 | gap 1 | frame 2 | gap 2 | ...
| / /
| *----* *------------*
| / /
Host: frame 0 | frame 1 | frame 2 | ...
*/

/// Memory region for bounds checking and address translation
#[derive(Clone, PartialEq, Eq, Default)]
#[repr(C, align(32))]
Expand Down

0 comments on commit f4093e7

Please sign in to comment.