@@ -12,6 +12,15 @@ use core::ffi::c_void;
1212
1313#[ cfg( linux_kernel) ]
1414pub use backend:: mm:: types:: MlockFlags ;
15+ #[ cfg( any(
16+ linux_kernel,
17+ target_os = "freebsd" ,
18+ target_os = "netbsd" ,
19+ target_os = "openbsd" ,
20+ target_os = "dragonfly" ,
21+ target_os = "illumos" ,
22+ ) ) ]
23+ pub use backend:: mm:: types:: MlockallFlags ;
1524#[ cfg( any( target_os = "emscripten" , target_os = "linux" ) ) ]
1625pub use backend:: mm:: types:: MremapFlags ;
1726pub use backend:: mm:: types:: { MapFlags , MprotectFlags , ProtFlags } ;
@@ -340,3 +349,73 @@ pub unsafe fn mlock_with(ptr: *mut c_void, len: usize, flags: MlockFlags) -> io:
340349pub unsafe fn munlock ( ptr : * mut c_void , len : usize ) -> io:: Result < ( ) > {
341350 backend:: mm:: syscalls:: munlock ( ptr, len)
342351}
352+
353+ /// Locks all pages mapped into the address space of the calling process.
354+ ///
355+ /// This includes the pages of the code, data and stack segment, as well as shared libraries,
356+ /// user space kernel data, shared memory, and memory-mapped files. All mapped pages are
357+ /// guaranteed to be resident in RAM when the call returns successfully;
358+ /// the pages are guaranteed to stay in RAM until later unlocked.
359+ ///
360+ /// # References
361+ /// - [POSIX]
362+ /// - [Linux]
363+ /// - [FreeBSD]
364+ /// - [NetBSD]
365+ /// - [OpenBSD]
366+ /// - [DragonFly BSD]
367+ /// - [illumos]
368+ /// - [glibc]
369+ ///
370+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mlockall.html
371+ /// [Linux]: https://man7.org/linux/man-pages/man2/mlockall.2.html
372+ /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=mlockall&sektion=2
373+ /// [NetBSD]: https://man.netbsd.org/mlockall.2
374+ /// [OpenBSD]: https://man.openbsd.org/mlockall.2
375+ /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=mlockall§ion=2
376+ /// [illumos]: https://illumos.org/man/3C/mlockall
377+ /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Page-Lock-Functions.html#index-mlockall
378+ #[ cfg( any(
379+ linux_kernel,
380+ target_os = "freebsd" ,
381+ target_os = "netbsd" ,
382+ target_os = "openbsd" ,
383+ target_os = "dragonfly" ,
384+ target_os = "illumos" ,
385+ ) ) ]
386+ pub fn mlockall ( flags : MlockallFlags ) -> io:: Result < ( ) > {
387+ backend:: mm:: syscalls:: mlockall ( flags)
388+ }
389+
390+ /// Unlocks all pages mapped into the address space of the calling process.
391+ ///
392+ /// # References
393+ /// - [POSIX]
394+ /// - [Linux]
395+ /// - [FreeBSD]
396+ /// - [NetBSD]
397+ /// - [OpenBSD]
398+ /// - [DragonFly BSD]
399+ /// - [illumos]
400+ /// - [glibc]
401+ ///
402+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/munlockall.html
403+ /// [Linux]: https://man7.org/linux/man-pages/man2/munlockall.2.html
404+ /// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=munlockall&sektion=2
405+ /// [NetBSD]: https://man.netbsd.org/munlockall.2
406+ /// [OpenBSD]: https://man.openbsd.org/munlockall.2
407+ /// [DragonFly BSD]: https://man.dragonflybsd.org/?command=munlockall§ion=2
408+ /// [illumos]: https://illumos.org/man/3C/munlockall
409+ /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Page-Lock-Functions.html#index-munlockall
410+ #[ inline]
411+ #[ cfg( any(
412+ linux_kernel,
413+ target_os = "freebsd" ,
414+ target_os = "netbsd" ,
415+ target_os = "openbsd" ,
416+ target_os = "dragonfly" ,
417+ target_os = "illumos" ,
418+ ) ) ]
419+ pub fn munlockall ( ) -> io:: Result < ( ) > {
420+ backend:: mm:: syscalls:: munlockall ( )
421+ }
0 commit comments