Use throw_unsup_format
instead of returning ENOTSUP
in the mmap shim · rust-lang/rust@37a37f6 (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -71,24 +71,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { | |||
71 | 71 | throw_unsup_format!("Miri does not support file-backed memory mappings"); | |
72 | 72 | } | |
73 | 73 | ||
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 | |
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 | +); | ||
85 | 87 | } | |
86 | 88 | ||
87 | 89 | // Miri does not support shared mappings, or any of the other extensions that for example | |
88 | 90 | // Linux has added to the flags arguments. | |
89 | 91 | if flags != map_private | map_anonymous { | |
90 | 92 | 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", | ||
92 | 95 | ); | |
93 | 96 | } | |
94 | 97 |
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -69,36 +69,6 @@ fn test_mmap<Offset: Default>( | |||
69 | 69 | assert_eq!(ptr, libc::MAP_FAILED); | |
70 | 70 | assert_eq!(Error::last_os_error().raw_os_error().unwrap(), libc::EINVAL); | |
71 | 71 | ||
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 | - | ||
102 | 72 | // We report an error for mappings whose length cannot be rounded up to a multiple of | |
103 | 73 | // the page size. | |
104 | 74 | let ptr = unsafe { |