Skip to content

Commit 1953292

Browse files
committed
Use throw_unsup_format! instead of returning ENOTSUP in the mmap shim
1 parent 9b5daa8 commit 1953292

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/shims/unix/mem.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7171
throw_unsup_format!("Miri does not support file-backed memory mappings");
7272
}
7373

74-
// POSIX says:
75-
// [ENOTSUP]
76-
// * MAP_FIXED or MAP_PRIVATE was specified in the flags argument and the implementation
77-
// does not support this functionality.
78-
// * The implementation does not support the combination of accesses requested in the
79-
// prot argument.
80-
//
81-
// Miri doesn't support MAP_FIXED or any any protections other than PROT_READ|PROT_WRITE.
82-
if flags & map_fixed != 0 || prot != prot_read | prot_write {
83-
this.set_last_error(this.eval_libc("ENOTSUP"))?;
84-
return Ok(this.eval_libc("MAP_FAILED"));
74+
// Miri doesn't support MAP_FIXED.
75+
if flags & map_fixed != 0 {
76+
throw_unsup_format!(
77+
"Miri does not support calls to mmap with MAP_FIXED as part of the flags argument",
78+
);
79+
}
80+
81+
// Miri doesn't support protections other than PROT_READ|PROT_WRITE.
82+
if prot != prot_read | prot_write {
83+
throw_unsup_format!(
84+
"Miri does not support calls to mmap with protections other than \
85+
PROT_READ|PROT_WRITE",
86+
);
8587
}
8688

8789
// Miri does not support shared mappings, or any of the other extensions that for example
8890
// Linux has added to the flags arguments.
8991
if flags != map_private | map_anonymous {
9092
throw_unsup_format!(
91-
"Miri only supports calls to mmap which set the flags argument to MAP_PRIVATE|MAP_ANONYMOUS"
93+
"Miri only supports calls to mmap which set the flags argument to \
94+
MAP_PRIVATE|MAP_ANONYMOUS",
9295
);
9396
}
9497

0 commit comments

Comments
 (0)