Skip to content

Commit 1f94fb3

Browse files
committed
Use MAP_SHARED for shared memory creation again
Previously, in 7ca0a78, MAP_SHARED was replaced with MAP_PRIVATE, primarily to bring the Miri and non-Miri code paths closer together, since it did not appear to have any detrimental effect. However, this seems to cause issues with the scratch mapping on mshv on Linux. It is not entirely clear what mshv is doing here; possibly something like "mapping a page which has never been written to" causes the problem. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 8916cad commit 1f94fb3

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/hyperlight_host/src/mem/shared_mem.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,11 @@ impl ExclusiveSharedMemory {
314314
#[cfg(target_os = "linux")]
315315
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
316316
pub fn new(min_size_bytes: usize) -> Result<Self> {
317-
use libc::{
318-
MAP_ANONYMOUS, MAP_FAILED, MAP_PRIVATE, PROT_READ, PROT_WRITE, c_int, mmap, off_t,
319-
size_t,
320-
};
317+
#[cfg(miri)]
318+
use libc::MAP_PRIVATE;
319+
use libc::{MAP_ANONYMOUS, MAP_FAILED, PROT_READ, PROT_WRITE, c_int, mmap, off_t, size_t};
321320
#[cfg(not(miri))]
322-
use libc::{MAP_NORESERVE, PROT_NONE, mprotect};
321+
use libc::{MAP_NORESERVE, MAP_SHARED, PROT_NONE, mprotect};
323322

324323
if min_size_bytes == 0 {
325324
return Err(new_error!("Cannot create shared memory with size 0"));
@@ -347,7 +346,7 @@ impl ExclusiveSharedMemory {
347346

348347
// allocate the memory
349348
#[cfg(not(miri))]
350-
let flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;
349+
let flags = MAP_ANONYMOUS | MAP_SHARED | MAP_NORESERVE;
351350
#[cfg(miri)]
352351
let flags = MAP_ANONYMOUS | MAP_PRIVATE;
353352

0 commit comments

Comments
 (0)