summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/mm
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/mm')
-rw-r--r--vendor/rustix/src/mm/madvise.rs6
-rw-r--r--vendor/rustix/src/mm/mmap.rs93
-rw-r--r--vendor/rustix/src/mm/msync.rs6
3 files changed, 99 insertions, 6 deletions
diff --git a/vendor/rustix/src/mm/madvise.rs b/vendor/rustix/src/mm/madvise.rs
index 868a31a5e..4015d1284 100644
--- a/vendor/rustix/src/mm/madvise.rs
+++ b/vendor/rustix/src/mm/madvise.rs
@@ -16,9 +16,9 @@ pub use backend::mm::types::Advice;
///
/// # Safety
///
-/// `addr` must be a valid pointer to memory that is appropriate to
-/// call `posix_madvise` on. Some forms of `advice` may mutate the memory
-/// or evoke a variety of side-effects on the mapping and/or the file.
+/// `addr` must be a valid pointer to memory that is appropriate to call
+/// `posix_madvise` on. Some forms of `advice` may mutate the memory or evoke a
+/// variety of side-effects on the mapping and/or the file.
///
/// # References
/// - [POSIX]
diff --git a/vendor/rustix/src/mm/mmap.rs b/vendor/rustix/src/mm/mmap.rs
index 02badb9fd..22137a930 100644
--- a/vendor/rustix/src/mm/mmap.rs
+++ b/vendor/rustix/src/mm/mmap.rs
@@ -10,12 +10,40 @@ use crate::{backend, io};
use backend::fd::AsFd;
use core::ffi::c_void;
+#[cfg(any(linux_kernel, freebsdlike, netbsdlike))]
+pub use backend::mm::types::MlockAllFlags;
#[cfg(linux_kernel)]
pub use backend::mm::types::MlockFlags;
#[cfg(any(target_os = "emscripten", target_os = "linux"))]
pub use backend::mm::types::MremapFlags;
pub use backend::mm::types::{MapFlags, MprotectFlags, ProtFlags};
+impl MapFlags {
+ /// Create `MAP_HUGETLB` with provided size of huge page.
+ ///
+ /// Under the hood it computes
+ /// `MAP_HUGETLB | (huge_page_size_log2 << MAP_HUGE_SHIFT)`.
+ /// `huge_page_size_log2` denotes logarithm of huge page size to use and
+ /// should be between 16 and 63 (inclusive).
+ ///
+ /// ```
+ /// use rustix::mm::MapFlags;
+ ///
+ /// let f = MapFlags::hugetlb_with_size_log2(30).unwrap();
+ /// assert_eq!(f, MapFlags::HUGETLB | MapFlags::HUGE_1GB);
+ /// ```
+ #[cfg(linux_kernel)]
+ pub const fn hugetlb_with_size_log2(huge_page_size_log2: u32) -> Option<Self> {
+ use linux_raw_sys::general::{MAP_HUGETLB, MAP_HUGE_SHIFT};
+ if 16 <= huge_page_size_log2 && huge_page_size_log2 <= 63 {
+ let bits = MAP_HUGETLB | (huge_page_size_log2 << MAP_HUGE_SHIFT);
+ Self::from_bits(bits)
+ } else {
+ None
+ }
+ }
+}
+
/// `mmap(ptr, len, prot, flags, fd, offset)`—Create a file-backed memory
/// mapping.
///
@@ -314,3 +342,68 @@ pub unsafe fn mlock_with(ptr: *mut c_void, len: usize, flags: MlockFlags) -> io:
pub unsafe fn munlock(ptr: *mut c_void, len: usize) -> io::Result<()> {
backend::mm::syscalls::munlock(ptr, len)
}
+
+/// Locks all pages mapped into the address space of the calling process.
+///
+/// This includes the pages of the code, data, and stack segment, as well as
+/// shared libraries, user space kernel data, shared memory, and memory-mapped
+/// files. All mapped pages are guaranteed to be resident in RAM when the call
+/// returns successfully; the pages are guaranteed to stay in RAM until later
+/// unlocked.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+/// - [FreeBSD]
+/// - [NetBSD]
+/// - [OpenBSD]
+/// - [DragonFly BSD]
+/// - [illumos]
+/// - [glibc]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mlockall.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/mlockall.2.html
+/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=mlockall&sektion=2
+/// [NetBSD]: https://man.netbsd.org/mlockall.2
+/// [OpenBSD]: https://man.openbsd.org/mlockall.2
+/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=mlockall&section=2
+/// [illumos]: https://illumos.org/man/3C/mlockall
+/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Page-Lock-Functions.html#index-mlockall
+#[cfg(any(linux_kernel, freebsdlike, netbsdlike))]
+#[inline]
+pub fn mlockall(flags: MlockAllFlags) -> io::Result<()> {
+ backend::mm::syscalls::mlockall(flags)
+}
+
+/// Unlocks all pages mapped into the address space of the calling process.
+///
+/// # Warnings
+///
+/// This function is aware of all the memory pages in the process, as if it
+/// were a debugger. It unlocks all the pages, which could potentially
+/// compromise security assumptions made by code about memory it has
+/// encapsulated.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+/// - [FreeBSD]
+/// - [NetBSD]
+/// - [OpenBSD]
+/// - [DragonFly BSD]
+/// - [illumos]
+/// - [glibc]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/munlockall.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/munlockall.2.html
+/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=munlockall&sektion=2
+/// [NetBSD]: https://man.netbsd.org/munlockall.2
+/// [OpenBSD]: https://man.openbsd.org/munlockall.2
+/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=munlockall&section=2
+/// [illumos]: https://illumos.org/man/3C/munlockall
+/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Page-Lock-Functions.html#index-munlockall
+#[cfg(any(linux_kernel, freebsdlike, netbsdlike))]
+#[inline]
+pub fn munlockall() -> io::Result<()> {
+ backend::mm::syscalls::munlockall()
+}
diff --git a/vendor/rustix/src/mm/msync.rs b/vendor/rustix/src/mm/msync.rs
index 0306e36b9..c61d7c379 100644
--- a/vendor/rustix/src/mm/msync.rs
+++ b/vendor/rustix/src/mm/msync.rs
@@ -16,9 +16,9 @@ pub use backend::mm::types::MsyncFlags;
///
/// # Safety
///
-/// `addr` must be a valid pointer to memory that is appropriate to
-/// call `msync` on. Some forms of `msync` may mutate the memory
-/// or evoke a variety of side-effects on the mapping and/or the file.
+/// `addr` must be a valid pointer to memory that is appropriate to call
+/// `msync` on. Some forms of `msync` may mutate the memory or evoke a variety
+/// of side-effects on the mapping and/or the file.
///
/// # References
/// - [POSIX]