Skip to content

Commit c9bae12

Browse files
committed
Factor out the target_os = "wasi" check from the mm module.
1 parent 4db9ba9 commit c9bae12

File tree

5 files changed

+7
-24
lines changed

5 files changed

+7
-24
lines changed

src/imp/libc/mm/syscalls.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ use super::super::c;
44
#[cfg(any(target_os = "android", target_os = "linux"))]
55
use super::super::conv::syscall_ret_owned_fd;
66
use super::super::conv::{borrowed_fd, no_fd, ret};
7-
#[cfg(not(target_os = "wasi"))]
87
use super::super::offset::libc_mmap;
9-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
8+
#[cfg(not(target_os = "redox"))]
109
use super::types::Advice;
1110
#[cfg(target_os = "linux")]
1211
use super::types::MremapFlags;
13-
#[cfg(not(target_os = "wasi"))]
1412
use super::types::{MapFlags, MprotectFlags, MsyncFlags, ProtFlags};
1513
#[cfg(any(target_os = "android", target_os = "linux"))]
1614
use super::types::{MlockFlags, UserfaultfdFlags};
@@ -19,7 +17,7 @@ use crate::io;
1917
#[cfg(any(target_os = "android", target_os = "linux"))]
2018
use crate::io::OwnedFd;
2119

22-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
20+
#[cfg(not(target_os = "redox"))]
2321
pub(crate) fn madvise(addr: *mut c::c_void, len: usize, advice: Advice) -> io::Result<()> {
2422
// On Linux platforms, `MADV_DONTNEED` has the same value as
2523
// `POSIX_MADV_DONTNEED` but different behavior. We remap it to a different
@@ -53,7 +51,6 @@ pub(crate) fn madvise(addr: *mut c::c_void, len: usize, advice: Advice) -> io::R
5351
}
5452
}
5553

56-
#[cfg(not(target_os = "wasi"))]
5754
pub(crate) unsafe fn msync(addr: *mut c::c_void, len: usize, flags: MsyncFlags) -> io::Result<()> {
5855
let err = c::msync(addr, len, flags.bits());
5956

@@ -69,7 +66,6 @@ pub(crate) unsafe fn msync(addr: *mut c::c_void, len: usize, flags: MsyncFlags)
6966
///
7067
/// `mmap` is primarily unsafe due to the `addr` parameter, as anything working
7168
/// with memory pointed to by raw pointers is unsafe.
72-
#[cfg(not(target_os = "wasi"))]
7369
pub(crate) unsafe fn mmap(
7470
ptr: *mut c::c_void,
7571
len: usize,
@@ -97,7 +93,6 @@ pub(crate) unsafe fn mmap(
9793
///
9894
/// `mmap` is primarily unsafe due to the `addr` parameter, as anything working
9995
/// with memory pointed to by raw pointers is unsafe.
100-
#[cfg(not(target_os = "wasi"))]
10196
pub(crate) unsafe fn mmap_anonymous(
10297
ptr: *mut c::c_void,
10398
len: usize,
@@ -119,7 +114,6 @@ pub(crate) unsafe fn mmap_anonymous(
119114
}
120115
}
121116

122-
#[cfg(not(target_os = "wasi"))]
123117
pub(crate) unsafe fn mprotect(
124118
ptr: *mut c::c_void,
125119
len: usize,
@@ -128,7 +122,6 @@ pub(crate) unsafe fn mprotect(
128122
ret(c::mprotect(ptr, len, flags.bits()))
129123
}
130124

131-
#[cfg(not(target_os = "wasi"))]
132125
pub(crate) unsafe fn munmap(ptr: *mut c::c_void, len: usize) -> io::Result<()> {
133126
ret(c::munmap(ptr, len))
134127
}
@@ -183,7 +176,6 @@ pub(crate) unsafe fn mremap_fixed(
183176
///
184177
/// `mlock` operates on raw pointers and may round out to the nearest page
185178
/// boundaries.
186-
#[cfg(not(target_os = "wasi"))]
187179
#[inline]
188180
pub(crate) unsafe fn mlock(addr: *mut c::c_void, length: usize) -> io::Result<()> {
189181
ret(c::mlock(addr, length))
@@ -215,7 +207,6 @@ pub(crate) unsafe fn mlock_with(
215207
///
216208
/// `munlock` operates on raw pointers and may round out to the nearest page
217209
/// boundaries.
218-
#[cfg(not(target_os = "wasi"))]
219210
#[inline]
220211
pub(crate) unsafe fn munlock(addr: *mut c::c_void, length: usize) -> io::Result<()> {
221212
ret(c::munlock(addr, length))

src/imp/libc/mm/types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::super::c;
22
use bitflags::bitflags;
33

4-
#[cfg(not(target_os = "wasi"))]
54
bitflags! {
65
/// `PROT_*` flags for use with [`mmap`].
76
///
@@ -18,7 +17,6 @@ bitflags! {
1817
}
1918
}
2019

21-
#[cfg(not(target_os = "wasi"))]
2220
bitflags! {
2321
/// `PROT_*` flags for use with [`mprotect`].
2422
///
@@ -41,7 +39,6 @@ bitflags! {
4139
}
4240
}
4341

44-
#[cfg(not(target_os = "wasi"))]
4542
bitflags! {
4643
/// `MAP_*` flags for use with [`mmap`].
4744
///
@@ -228,7 +225,6 @@ bitflags! {
228225
}
229226
}
230227

231-
#[cfg(not(target_os = "wasi"))]
232228
bitflags! {
233229
/// `MS_*` flags for use with [`msync`].
234230
///
@@ -260,7 +256,7 @@ bitflags! {
260256
/// `POSIX_MADV_*` constants for use with [`madvise`].
261257
///
262258
/// [`madvise`]: crate::mm::madvise
263-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
259+
#[cfg(not(target_os = "redox"))]
264260
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
265261
#[repr(i32)]
266262
#[non_exhaustive]

src/imp/libc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) mod io;
6363
#[cfg(feature = "io_uring")]
6464
#[cfg_attr(doc_cfg, doc(cfg(feature = "io_uring")))]
6565
pub(crate) mod io_uring;
66-
#[cfg(not(windows))]
66+
#[cfg(not(any(windows, target_os = "wasi")))]
6767
#[cfg(any(feature = "mm", feature = "time", target_arch = "x86"))] // vdso.rs uses `madvise`
6868
pub(crate) mod mm;
6969
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub mod io;
165165
#[cfg(feature = "io_uring")]
166166
#[cfg_attr(doc_cfg, doc(cfg(feature = "io_uring")))]
167167
pub mod io_uring;
168-
#[cfg(not(windows))]
168+
#[cfg(not(any(windows, target_os = "wasi")))]
169169
#[cfg(feature = "mm")]
170170
#[cfg_attr(doc_cfg, doc(cfg(feature = "mm")))]
171171
pub mod mm;

src/mm/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
//! Memory map operations.
22
3-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
3+
#[cfg(not(target_os = "redox"))]
44
mod madvise;
5-
#[cfg(not(target_os = "wasi"))]
65
mod mmap;
7-
#[cfg(not(target_os = "wasi"))]
86
mod msync;
97
#[cfg(any(target_os = "android", target_os = "linux"))]
108
mod userfaultfd;
119

12-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
10+
#[cfg(not(target_os = "redox"))]
1311
pub use madvise::{madvise, Advice};
14-
#[cfg(not(target_os = "wasi"))]
1512
pub use mmap::{
1613
mlock, mmap, mmap_anonymous, mprotect, munlock, munmap, MapFlags, MprotectFlags, ProtFlags,
1714
};
1815
#[cfg(any(target_os = "android", target_os = "linux"))]
1916
pub use mmap::{mlock_with, MlockFlags};
2017
#[cfg(any(linux_raw, all(libc, target_os = "linux")))]
2118
pub use mmap::{mremap, mremap_fixed, MremapFlags};
22-
#[cfg(not(target_os = "wasi"))]
2319
pub use msync::{msync, MsyncFlags};
2420
#[cfg(any(target_os = "android", target_os = "linux"))]
2521
pub use userfaultfd::{userfaultfd, UserfaultfdFlags};

0 commit comments

Comments
 (0)