1+ //! Memory management declarations.
2+
13use crate :: Result ;
24#[ cfg( not( target_os = "android" ) ) ]
35use crate :: NixPath ;
@@ -30,7 +32,7 @@ libc_bitflags!{
3032}
3133
3234libc_bitflags ! {
33- /// Additional parameters for `mmap()` .
35+ /// Additional parameters for [ `mmap`] .
3436 pub struct MapFlags : c_int {
3537 /// Compatibility flag. Ignored.
3638 MAP_FILE ;
@@ -151,7 +153,7 @@ libc_bitflags!{
151153
152154#[ cfg( any( target_os = "linux" , target_os = "netbsd" ) ) ]
153155libc_bitflags ! {
154- /// Options for `mremap()` .
156+ /// Options for [ `mremap`] .
155157 pub struct MRemapFlags : c_int {
156158 /// Permit the kernel to relocate the mapping to a new virtual address, if necessary.
157159 #[ cfg( target_os = "linux" ) ]
@@ -171,7 +173,7 @@ libc_bitflags!{
171173libc_enum ! {
172174 /// Usage information for a range of memory to allow for performance optimizations by the kernel.
173175 ///
174- /// Used by [`madvise`](./fn.madvise.html) .
176+ /// Used by [`madvise`].
175177 #[ repr( i32 ) ]
176178 #[ non_exhaustive]
177179 pub enum MmapAdvise {
@@ -264,7 +266,7 @@ libc_enum!{
264266}
265267
266268libc_bitflags ! {
267- /// Configuration flags for `msync`.
269+ /// Configuration flags for [ `msync`] .
268270 pub struct MsFlags : c_int {
269271 /// Schedule an update but return immediately.
270272 MS_ASYNC ;
@@ -282,7 +284,7 @@ libc_bitflags!{
282284}
283285
284286libc_bitflags ! {
285- /// Flags for `mlockall`.
287+ /// Flags for [ `mlockall`] .
286288 pub struct MlockAllFlags : c_int {
287289 /// Lock pages that are currently mapped into the address space of the process.
288290 MCL_CURRENT ;
@@ -298,7 +300,9 @@ libc_bitflags!{
298300///
299301/// # Safety
300302///
301- /// `addr` must meet all the requirements described in the `mlock(2)` man page.
303+ /// `addr` must meet all the requirements described in the [`mlock(2)`] man page.
304+ ///
305+ /// [`mlock(2)`]: https://man7.org/linux/man-pages/man2/mlock.2.html
302306pub unsafe fn mlock ( addr : * const c_void , length : size_t ) -> Result < ( ) > {
303307 Errno :: result ( libc:: mlock ( addr, length) ) . map ( drop)
304308}
@@ -308,25 +312,28 @@ pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> {
308312///
309313/// # Safety
310314///
311- /// `addr` must meet all the requirements described in the `munlock(2)` man
315+ /// `addr` must meet all the requirements described in the [ `munlock(2)`] man
312316/// page.
317+ ///
318+ /// [`munlock(2)`]: https://man7.org/linux/man-pages/man2/munlock.2.html
313319pub unsafe fn munlock ( addr : * const c_void , length : size_t ) -> Result < ( ) > {
314320 Errno :: result ( libc:: munlock ( addr, length) ) . map ( drop)
315321}
316322
317323/// Locks all memory pages mapped into this process' address space.
318324///
319- /// Locked pages never move to the swap area.
325+ /// Locked pages never move to the swap area. For more information, see [`mlockall(2)`].
320326///
321- /// # Safety
322- ///
323- /// `addr` must meet all the requirements described in the `mlockall(2)` man
324- /// page.
327+ /// [`mlockall(2)`]: https://man7.org/linux/man-pages/man2/mlockall.2.html
325328pub fn mlockall ( flags : MlockAllFlags ) -> Result < ( ) > {
326329 unsafe { Errno :: result ( libc:: mlockall ( flags. bits ( ) ) ) } . map ( drop)
327330}
328331
329332/// Unlocks all memory pages mapped into this process' address space.
333+ ///
334+ /// For more information, see [`munlockall(2)`].
335+ ///
336+ /// [`munlockall(2)`]: https://man7.org/linux/man-pages/man2/munlockall.2.html
330337pub fn munlockall ( ) -> Result < ( ) > {
331338 unsafe { Errno :: result ( libc:: munlockall ( ) ) } . map ( drop)
332339}
@@ -335,7 +342,9 @@ pub fn munlockall() -> Result<()> {
335342///
336343/// # Safety
337344///
338- /// See the `mmap(2)` man page for detailed requirements.
345+ /// See the [`mmap(2)`] man page for detailed requirements.
346+ ///
347+ /// [`mmap(2)`]: https://man7.org/linux/man-pages/man2/mmap.2.html
339348pub unsafe fn mmap ( addr : * mut c_void , length : size_t , prot : ProtFlags , flags : MapFlags , fd : RawFd , offset : off_t ) -> Result < * mut c_void > {
340349 let ret = libc:: mmap ( addr, length, prot. bits ( ) , flags. bits ( ) , fd, offset) ;
341350
@@ -383,8 +392,10 @@ pub unsafe fn mremap(
383392///
384393/// # Safety
385394///
386- /// `addr` must meet all the requirements described in the `munmap(2)` man
395+ /// `addr` must meet all the requirements described in the [ `munmap(2)`] man
387396/// page.
397+ ///
398+ /// [`munmap(2)`]: https://man7.org/linux/man-pages/man2/munmap.2.html
388399pub unsafe fn munmap ( addr : * mut c_void , len : size_t ) -> Result < ( ) > {
389400 Errno :: result ( libc:: munmap ( addr, len) ) . map ( drop)
390401}
@@ -393,8 +404,10 @@ pub unsafe fn munmap(addr: *mut c_void, len: size_t) -> Result<()> {
393404///
394405/// # Safety
395406///
396- /// See the `madvise(2)` man page. Take special care when using
397- /// `MmapAdvise::MADV_FREE`.
407+ /// See the [`madvise(2)`] man page. Take special care when using
408+ /// [`MmapAdvise::MADV_FREE`].
409+ ///
410+ /// [`madvise(2)`]: https://man7.org/linux/man-pages/man2/madvise.2.html
398411pub unsafe fn madvise ( addr : * mut c_void , length : size_t , advise : MmapAdvise ) -> Result < ( ) > {
399412 Errno :: result ( libc:: madvise ( addr, length, advise as i32 ) ) . map ( drop)
400413}
@@ -432,12 +445,19 @@ pub unsafe fn mprotect(addr: *mut c_void, length: size_t, prot: ProtFlags) -> Re
432445///
433446/// # Safety
434447///
435- /// `addr` must meet all the requirements described in the `msync(2)` man
448+ /// `addr` must meet all the requirements described in the [ `msync(2)`] man
436449/// page.
450+ ///
451+ /// [`msync(2)`]: https://man7.org/linux/man-pages/man2/msync.2.html
437452pub unsafe fn msync ( addr : * mut c_void , length : size_t , flags : MsFlags ) -> Result < ( ) > {
438453 Errno :: result ( libc:: msync ( addr, length, flags. bits ( ) ) ) . map ( drop)
439454}
440455
456+ /// Creates and opens a new, or opens an existing, POSIX shared memory object.
457+ ///
458+ /// For more information, see [`shm_open(3)`].
459+ ///
460+ /// [`shm_open(3)`]: https://man7.org/linux/man-pages/man3/shm_open.3.html
441461#[ cfg( not( target_os = "android" ) ) ]
442462pub fn shm_open < P : ?Sized + NixPath > ( name : & P , flag : OFlag , mode : Mode ) -> Result < RawFd > {
443463 let ret = name. with_nix_path ( |cstr| {
@@ -454,6 +474,11 @@ pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Resul
454474 Errno :: result ( ret)
455475}
456476
477+ /// Performs the converse of [`shm_open`], removing an object previously created.
478+ ///
479+ /// For more information, see [`shm_unlink(3)`].
480+ ///
481+ /// [`shm_unlink(3)`]: https://man7.org/linux/man-pages/man3/shm_unlink.3.html
457482#[ cfg( not( target_os = "android" ) ) ]
458483pub fn shm_unlink < P : ?Sized + NixPath > ( name : & P ) -> Result < ( ) > {
459484 let ret = name. with_nix_path ( |cstr| {
0 commit comments