Use `throw_unsup_format` instead of returning `ENOTSUP` in the mmap shim · rust-lang/rust@37a37f6

2 files changed

lines changed

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
Original file line numberDiff line numberDiff line change

@@ -69,36 +69,6 @@ fn test_mmap<Offset: Default>(

6969

assert_eq!(ptr, libc::MAP_FAILED);

7070

assert_eq!(Error::last_os_error().raw_os_error().unwrap(), libc::EINVAL);

7171
72-

let ptr = unsafe {

73-

mmap(

74-

ptr::without_provenance_mut(page_size * 64),

75-

page_size,

76-

libc::PROT_READ | libc::PROT_WRITE,

77-

// We don't support MAP_FIXED

78-

libc::MAP_PRIVATE | libc::MAP_ANONYMOUS | libc::MAP_FIXED,

79-

-1,

80-

Default::default(),

81-

)

82-

};

83-

assert_eq!(ptr, libc::MAP_FAILED);

84-

assert_eq!(Error::last_os_error().raw_os_error().unwrap(), libc::ENOTSUP);

85-
86-

// We don't support protections other than read+write

87-

for prot in [libc::PROT_NONE, libc::PROT_EXEC, libc::PROT_READ, libc::PROT_WRITE] {

88-

let ptr = unsafe {

89-

mmap(

90-

ptr::null_mut(),

91-

page_size,

92-

prot,

93-

libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,

94-

-1,

95-

Default::default(),

96-

)

97-

};

98-

assert_eq!(ptr, libc::MAP_FAILED);

99-

assert_eq!(Error::last_os_error().raw_os_error().unwrap(), libc::ENOTSUP);

100-

}

101-
10272

// We report an error for mappings whose length cannot be rounded up to a multiple of

10373

// the page size.

10474

let ptr = unsafe {