@@ -10,6 +10,8 @@ use crate::{backend, io};
1010use backend:: fd:: AsFd ;
1111use core:: ffi:: c_void;
1212
13+ #[ cfg( any( linux_kernel, freebsdlike, netbsdlike) ) ]
14+ pub use backend:: mm:: types:: MlockAllFlags ;
1315#[ cfg( linux_kernel) ]
1416pub use backend:: mm:: types:: MlockFlags ;
1517#[ cfg( any( target_os = "emscripten" , target_os = "linux" ) ) ]
@@ -340,3 +342,60 @@ pub unsafe fn mlock_with(ptr: *mut c_void, len: usize, flags: MlockFlags) -> io:
340342pub unsafe fn munlock ( ptr : * mut c_void , len : usize ) -> io:: Result < ( ) > {
341343 backend:: mm:: syscalls:: munlock ( ptr, len)
342344}
345+
346+ /// Locks all pages mapped into the address space of the calling process.
347+ ///
348+ /// This includes the pages of the code, data and stack segment, as well as shared libraries,
349+ /// user space kernel data, shared memory, and memory-mapped files. All mapped pages are
350+ /// guaranteed to be resident in RAM when the call returns successfully;
351+ /// the pages are guaranteed to stay in RAM until later unlocked.
352+ ///
353+ /// # References
354+ /// - [POSIX]
355+ /// - [Linux]
356+ /// - [FreeBSD]
357+ /// - [NetBSD]
358+ /// - [OpenBSD]
359+ /// - [DragonFly BSD]
360+ /// - [illumos]
361+ /// - [glibc]
362+ ///
363+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mlockall.html
364+ /// [Linux]: https://man7.org/linux/man-pages/man2/mlockall.2.html
365+ /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=mlockall&sektion=2
366+ /// [NetBSD]: https://man.netbsd.org/mlockall.2
367+ /// [OpenBSD]: https://man.openbsd.org/mlockall.2
368+ /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=mlockall§ion=2
369+ /// [illumos]: https://illumos.org/man/3C/mlockall
370+ /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Page-Lock-Functions.html#index-mlockall
371+ #[ cfg( any( linux_kernel, freebsdlike, netbsdlike) ) ]
372+ #[ inline]
373+ pub fn mlockall ( flags : MlockAllFlags ) -> io:: Result < ( ) > {
374+ backend:: mm:: syscalls:: mlockall ( flags)
375+ }
376+
377+ /// Unlocks all pages mapped into the address space of the calling process.
378+ ///
379+ /// # References
380+ /// - [POSIX]
381+ /// - [Linux]
382+ /// - [FreeBSD]
383+ /// - [NetBSD]
384+ /// - [OpenBSD]
385+ /// - [DragonFly BSD]
386+ /// - [illumos]
387+ /// - [glibc]
388+ ///
389+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/munlockall.html
390+ /// [Linux]: https://man7.org/linux/man-pages/man2/munlockall.2.html
391+ /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=munlockall&sektion=2
392+ /// [NetBSD]: https://man.netbsd.org/munlockall.2
393+ /// [OpenBSD]: https://man.openbsd.org/munlockall.2
394+ /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=munlockall§ion=2
395+ /// [illumos]: https://illumos.org/man/3C/munlockall
396+ /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Page-Lock-Functions.html#index-munlockall
397+ #[ cfg( any( linux_kernel, freebsdlike, netbsdlike) ) ]
398+ #[ inline]
399+ pub fn munlockall ( ) -> io:: Result < ( ) > {
400+ backend:: mm:: syscalls:: munlockall ( )
401+ }
0 commit comments