summaryrefslogtreecommitdiff
path: root/src/sys/mman.rs
diff options
context:
space:
mode:
authorAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:27:08 -0800
committerAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:39:09 -0800
commit17833268cb3269d83766bcdb4d9cbe0e25ebd38e (patch)
treeb86885991e1d8b6f9c610747c2e8c3a3370960cd /src/sys/mman.rs
parent20df092bd067908fba23e49120eed7ad62f29108 (diff)
downloadnix-17833268cb3269d83766bcdb4d9cbe0e25ebd38e.zip
Reformat everything
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Diffstat (limited to 'src/sys/mman.rs')
-rw-r--r--src/sys/mman.rs62
1 files changed, 43 insertions, 19 deletions
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 700e231c..869f44c4 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -1,16 +1,16 @@
//! Memory management declarations.
-use crate::Result;
+use crate::errno::Errno;
#[cfg(not(target_os = "android"))]
use crate::NixPath;
-use crate::errno::Errno;
+use crate::Result;
#[cfg(not(target_os = "android"))]
#[cfg(feature = "fs")]
use crate::{fcntl::OFlag, sys::stat::Mode};
-use libc::{self, c_int, c_void, size_t, off_t};
+use libc::{self, c_int, c_void, off_t, size_t};
use std::os::unix::io::RawFd;
-libc_bitflags!{
+libc_bitflags! {
/// Desired memory protection of a memory mapping.
pub struct ProtFlags: c_int {
/// Pages cannot be accessed.
@@ -32,7 +32,7 @@ libc_bitflags!{
}
}
-libc_bitflags!{
+libc_bitflags! {
/// Additional parameters for [`mmap`].
pub struct MapFlags: c_int {
/// Compatibility flag. Ignored.
@@ -188,7 +188,7 @@ libc_bitflags!{
}
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
-libc_bitflags!{
+libc_bitflags! {
/// Options for [`mremap`].
pub struct MRemapFlags: c_int {
/// Permit the kernel to relocate the mapping to a new virtual address, if necessary.
@@ -210,7 +210,7 @@ libc_bitflags!{
}
}
-libc_enum!{
+libc_enum! {
/// Usage information for a range of memory to allow for performance optimizations by the kernel.
///
/// Used by [`madvise`].
@@ -331,7 +331,7 @@ libc_enum!{
}
}
-libc_bitflags!{
+libc_bitflags! {
/// Configuration flags for [`msync`].
pub struct MsFlags: c_int {
/// Schedule an update but return immediately.
@@ -352,7 +352,7 @@ libc_bitflags!{
}
#[cfg(not(target_os = "haiku"))]
-libc_bitflags!{
+libc_bitflags! {
/// Flags for [`mlockall`].
pub struct MlockAllFlags: c_int {
/// Lock pages that are currently mapped into the address space of the process.
@@ -416,7 +416,14 @@ pub fn munlockall() -> Result<()> {
/// See the [`mmap(2)`] man page for detailed requirements.
///
/// [`mmap(2)`]: https://man7.org/linux/man-pages/man2/mmap.2.html
-pub unsafe fn mmap(addr: *mut c_void, length: size_t, prot: ProtFlags, flags: MapFlags, fd: RawFd, offset: off_t) -> Result<*mut c_void> {
+pub unsafe fn mmap(
+ addr: *mut c_void,
+ length: size_t,
+ prot: ProtFlags,
+ flags: MapFlags,
+ fd: RawFd,
+ offset: off_t,
+) -> Result<*mut c_void> {
let ret = libc::mmap(addr, length, prot.bits(), flags.bits(), fd, offset);
if ret == libc::MAP_FAILED {
@@ -439,10 +446,16 @@ pub unsafe fn mremap(
old_size: size_t,
new_size: size_t,
flags: MRemapFlags,
- new_address: Option<* mut c_void>,
+ new_address: Option<*mut c_void>,
) -> Result<*mut c_void> {
#[cfg(target_os = "linux")]
- let ret = libc::mremap(addr, old_size, new_size, flags.bits(), new_address.unwrap_or(std::ptr::null_mut()));
+ let ret = libc::mremap(
+ addr,
+ old_size,
+ new_size,
+ flags.bits(),
+ new_address.unwrap_or(std::ptr::null_mut()),
+ );
#[cfg(target_os = "netbsd")]
let ret = libc::mremap(
addr,
@@ -450,7 +463,7 @@ pub unsafe fn mremap(
new_address.unwrap_or(std::ptr::null_mut()),
new_size,
flags.bits(),
- );
+ );
if ret == libc::MAP_FAILED {
Err(Errno::last())
@@ -479,7 +492,11 @@ pub unsafe fn munmap(addr: *mut c_void, len: size_t) -> Result<()> {
/// [`MmapAdvise::MADV_FREE`].
///
/// [`madvise(2)`]: https://man7.org/linux/man-pages/man2/madvise.2.html
-pub unsafe fn madvise(addr: *mut c_void, length: size_t, advise: MmapAdvise) -> Result<()> {
+pub unsafe fn madvise(
+ addr: *mut c_void,
+ length: size_t,
+ advise: MmapAdvise,
+) -> Result<()> {
Errno::result(libc::madvise(addr, length, advise as i32)).map(drop)
}
@@ -508,7 +525,11 @@ pub unsafe fn madvise(addr: *mut c_void, length: size_t, advise: MmapAdvise) ->
/// slice[0] = 0xFF;
/// assert_eq!(slice[0], 0xFF);
/// ```
-pub unsafe fn mprotect(addr: *mut c_void, length: size_t, prot: ProtFlags) -> Result<()> {
+pub unsafe fn mprotect(
+ addr: *mut c_void,
+ length: size_t,
+ prot: ProtFlags,
+) -> Result<()> {
Errno::result(libc::mprotect(addr, length, prot.bits())).map(drop)
}
@@ -520,7 +541,11 @@ pub unsafe fn mprotect(addr: *mut c_void, length: size_t, prot: ProtFlags) -> Re
/// page.
///
/// [`msync(2)`]: https://man7.org/linux/man-pages/man2/msync.2.html
-pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result<()> {
+pub unsafe fn msync(
+ addr: *mut c_void,
+ length: size_t,
+ flags: MsFlags,
+) -> Result<()> {
Errno::result(libc::msync(addr, length, flags.bits())).map(drop)
}
@@ -561,9 +586,8 @@ pub fn shm_open<P>(
/// [`shm_unlink(3)`]: https://man7.org/linux/man-pages/man3/shm_unlink.3.html
#[cfg(not(target_os = "android"))]
pub fn shm_unlink<P: ?Sized + NixPath>(name: &P) -> Result<()> {
- let ret = name.with_nix_path(|cstr| {
- unsafe { libc::shm_unlink(cstr.as_ptr()) }
- })?;
+ let ret =
+ name.with_nix_path(|cstr| unsafe { libc::shm_unlink(cstr.as_ptr()) })?;
Errno::result(ret).map(drop)
}