Skip to content

Commit 501e59f

Browse files
committed
Convert MS_ flags to bitflags! type.
1 parent 85482ab commit 501e59f

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

src/sys/mman.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ mod consts {
6262
pub const MADV_DODUMP : MmapAdvise = 17; /* Clear the MADV_DONTDUMP flag. */
6363
pub const MADV_HWPOISON : MmapAdvise = 100; /* Poison a page for testing. */
6464

65-
pub type MmapSync = c_int;
6665

67-
pub const MS_ASYNC : MmapSync = 1;
68-
pub const MS_SYNC : MmapSync = 4;
69-
pub const MS_INVALIDATE : MmapSync = 2;
66+
bitflags!{
67+
flags SyncFlags: c_int {
68+
const MS_ASYNC = libc::MS_ASYNC,
69+
const MS_INVALIDATE = libc::MS_INVALIDATE,
70+
const MS_SYNC = libc::MS_SYNC,
71+
}
72+
}
7073

7174
pub const MAP_FAILED: isize = -1;
7275
}
@@ -101,13 +104,15 @@ mod consts {
101104
pub const MADV_FREE_REUSE : MmapAdvise = 8; /* caller wants to reuse those pages */
102105
pub const MADV_CAN_REUSE : MmapAdvise = 9;
103106

104-
pub type MmapSync = c_int;
105-
106-
pub const MS_ASYNC : MmapSync = 0x0001; /* [MF|SIO] return immediately */
107-
pub const MS_INVALIDATE : MmapSync = 0x0002; /* [MF|SIO] invalidate all cached data */
108-
pub const MS_SYNC : MmapSync = 0x0010; /* [MF|SIO] msync synchronously */
109-
pub const MS_KILLPAGES : MmapSync = 0x0004; /* invalidate pages, leave mapped */
110-
pub const MS_DEACTIVATE : MmapSync = 0x0008; /* deactivate pages, leave mapped */
107+
bitflags!{
108+
flags SyncFlags: c_int {
109+
const MS_ASYNC = libc::MS_ASYNC, /* [MF|SIO] return immediately */
110+
const MS_INVALIDATE = libc::MS_INVALIDATE, /* [MF|SIO] invalidate all cached data */
111+
const MS_KILLPAGES = libc::MS_KILLPAGES, /* invalidate pages, leave mapped */
112+
const MS_DEACTIVATE = libc::MS_DEACTIVATE, /* deactivate pages, leave mapped */
113+
const MS_SYNC = libc::MS_SYNC, /* [MF|SIO] msync synchronously */
114+
}
115+
}
111116

112117
pub const MAP_FAILED: isize = -1;
113118
}
@@ -154,21 +159,21 @@ mod consts {
154159
#[cfg(target_os = "dragonfly")]
155160
pub const MADV_SETMAP : MmapAdvise = 11; /* set page table directory page for map */
156161

157-
pub type MmapSync = c_int;
158-
159-
pub const MS_ASYNC : MmapSync = 0x0001; /* [MF|SIO] return immediately */
160-
pub const MS_INVALIDATE : MmapSync = 0x0002; /* [MF|SIO] invalidate all cached data */
161-
#[cfg(not(target_os = "dragonfly"))]
162-
pub const MS_SYNC : MmapSync = 0x0010; /* [MF|SIO] msync synchronously */
163-
#[cfg(target_os = "dragonfly")]
164-
pub const MS_SYNC : MmapSync = 0x0000; /* [MF|SIO] msync synchronously */
165-
#[cfg(not(target_os = "dragonfly"))]
166-
pub const MS_KILLPAGES : MmapSync = 0x0004; /* invalidate pages, leave mapped */
167-
#[cfg(not(target_os = "dragonfly"))]
168-
pub const MS_DEACTIVATE : MmapSync = 0x0008; /* deactivate pages, leave mapped */
162+
bitflags!{
163+
flags SyncFlags: c_int {
164+
const MS_ASYNC = libc::MS_ASYNC, /* [MF|SIO] return immediately */
165+
const MS_INVALIDATE = libc::MS_INVALIDATE, /* [MF|SIO] invalidate all cached data */
166+
#[cfg(not(target_os = "dragonfly"))]
167+
const MS_KILLPAGES = 0x0004, /* invalidate pages, leave mapped */
168+
#[cfg(not(target_os = "dragonfly"))]
169+
const MS_DEACTIVATE = 0x0004, /* deactivate pages, leave mapped */
170+
const MS_SYNC = libc::MS_SYNC, /* [MF|SIO] msync synchronously */
171+
}
172+
}
169173

170174
pub const MAP_FAILED: isize = -1;
171175
}
176+
172177
mod ffi {
173178
use libc::{c_void, size_t, c_int, c_char, mode_t};
174179

@@ -213,8 +218,8 @@ pub fn madvise(addr: *const c_void, length: size_t, advise: MmapAdvise) -> Resul
213218
Errno::result(unsafe { ffi::madvise(addr, length, advise) }).map(drop)
214219
}
215220

216-
pub fn msync(addr: *const c_void, length: size_t, flags: MmapSync) -> Result<()> {
217-
Errno::result(unsafe { ffi::msync(addr, length, flags) }).map(drop)
221+
pub fn msync(addr: *const c_void, length: size_t, flags: SyncFlags) -> Result<()> {
222+
Errno::result(unsafe { ffi::msync(addr, length, flags.bits()) }).map(drop)
218223
}
219224

220225
pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<RawFd> {

0 commit comments

Comments
 (0)