1
+ //! Memory management declarations.
2
+
1
3
use crate :: Result ;
2
4
#[ cfg( not( target_os = "android" ) ) ]
3
5
use crate :: NixPath ;
@@ -30,7 +32,7 @@ libc_bitflags!{
30
32
}
31
33
32
34
libc_bitflags ! {
33
- /// Additional parameters for `mmap()` .
35
+ /// Additional parameters for [ `mmap`] .
34
36
pub struct MapFlags : c_int {
35
37
/// Compatibility flag. Ignored.
36
38
MAP_FILE ;
@@ -151,7 +153,7 @@ libc_bitflags!{
151
153
152
154
#[ cfg( any( target_os = "linux" , target_os = "netbsd" ) ) ]
153
155
libc_bitflags ! {
154
- /// Options for `mremap()` .
156
+ /// Options for [ `mremap`] .
155
157
pub struct MRemapFlags : c_int {
156
158
/// Permit the kernel to relocate the mapping to a new virtual address, if necessary.
157
159
#[ cfg( target_os = "linux" ) ]
@@ -171,7 +173,7 @@ libc_bitflags!{
171
173
libc_enum ! {
172
174
/// Usage information for a range of memory to allow for performance optimizations by the kernel.
173
175
///
174
- /// Used by [`madvise`](./fn.madvise.html) .
176
+ /// Used by [`madvise`].
175
177
#[ repr( i32 ) ]
176
178
#[ non_exhaustive]
177
179
pub enum MmapAdvise {
@@ -264,7 +266,7 @@ libc_enum!{
264
266
}
265
267
266
268
libc_bitflags ! {
267
- /// Configuration flags for `msync`.
269
+ /// Configuration flags for [ `msync`] .
268
270
pub struct MsFlags : c_int {
269
271
/// Schedule an update but return immediately.
270
272
MS_ASYNC ;
@@ -282,7 +284,7 @@ libc_bitflags!{
282
284
}
283
285
284
286
libc_bitflags ! {
285
- /// Flags for `mlockall`.
287
+ /// Flags for [ `mlockall`] .
286
288
pub struct MlockAllFlags : c_int {
287
289
/// Lock pages that are currently mapped into the address space of the process.
288
290
MCL_CURRENT ;
@@ -298,7 +300,9 @@ libc_bitflags!{
298
300
///
299
301
/// # Safety
300
302
///
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
302
306
pub unsafe fn mlock ( addr : * const c_void , length : size_t ) -> Result < ( ) > {
303
307
Errno :: result ( libc:: mlock ( addr, length) ) . map ( drop)
304
308
}
@@ -308,25 +312,28 @@ pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> {
308
312
///
309
313
/// # Safety
310
314
///
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
312
316
/// page.
317
+ ///
318
+ /// [`munlock(2)`]: https://man7.org/linux/man-pages/man2/munlock.2.html
313
319
pub unsafe fn munlock ( addr : * const c_void , length : size_t ) -> Result < ( ) > {
314
320
Errno :: result ( libc:: munlock ( addr, length) ) . map ( drop)
315
321
}
316
322
317
323
/// Locks all memory pages mapped into this process' address space.
318
324
///
319
- /// Locked pages never move to the swap area.
325
+ /// Locked pages never move to the swap area. For more information, see [`mlockall(2)`].
320
326
///
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
325
328
pub fn mlockall ( flags : MlockAllFlags ) -> Result < ( ) > {
326
329
unsafe { Errno :: result ( libc:: mlockall ( flags. bits ( ) ) ) } . map ( drop)
327
330
}
328
331
329
332
/// 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
330
337
pub fn munlockall ( ) -> Result < ( ) > {
331
338
unsafe { Errno :: result ( libc:: munlockall ( ) ) } . map ( drop)
332
339
}
@@ -335,7 +342,9 @@ pub fn munlockall() -> Result<()> {
335
342
///
336
343
/// # Safety
337
344
///
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
339
348
pub unsafe fn mmap ( addr : * mut c_void , length : size_t , prot : ProtFlags , flags : MapFlags , fd : RawFd , offset : off_t ) -> Result < * mut c_void > {
340
349
let ret = libc:: mmap ( addr, length, prot. bits ( ) , flags. bits ( ) , fd, offset) ;
341
350
@@ -383,8 +392,10 @@ pub unsafe fn mremap(
383
392
///
384
393
/// # Safety
385
394
///
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
387
396
/// page.
397
+ ///
398
+ /// [`munmap(2)`]: https://man7.org/linux/man-pages/man2/munmap.2.html
388
399
pub unsafe fn munmap ( addr : * mut c_void , len : size_t ) -> Result < ( ) > {
389
400
Errno :: result ( libc:: munmap ( addr, len) ) . map ( drop)
390
401
}
@@ -393,8 +404,10 @@ pub unsafe fn munmap(addr: *mut c_void, len: size_t) -> Result<()> {
393
404
///
394
405
/// # Safety
395
406
///
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
398
411
pub unsafe fn madvise ( addr : * mut c_void , length : size_t , advise : MmapAdvise ) -> Result < ( ) > {
399
412
Errno :: result ( libc:: madvise ( addr, length, advise as i32 ) ) . map ( drop)
400
413
}
@@ -432,12 +445,19 @@ pub unsafe fn mprotect(addr: *mut c_void, length: size_t, prot: ProtFlags) -> Re
432
445
///
433
446
/// # Safety
434
447
///
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
436
449
/// page.
450
+ ///
451
+ /// [`msync(2)`]: https://man7.org/linux/man-pages/man2/msync.2.html
437
452
pub unsafe fn msync ( addr : * mut c_void , length : size_t , flags : MsFlags ) -> Result < ( ) > {
438
453
Errno :: result ( libc:: msync ( addr, length, flags. bits ( ) ) ) . map ( drop)
439
454
}
440
455
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
441
461
#[ cfg( not( target_os = "android" ) ) ]
442
462
pub fn shm_open < P : ?Sized + NixPath > ( name : & P , flag : OFlag , mode : Mode ) -> Result < RawFd > {
443
463
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
454
474
Errno :: result ( ret)
455
475
}
456
476
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
457
482
#[ cfg( not( target_os = "android" ) ) ]
458
483
pub fn shm_unlink < P : ?Sized + NixPath > ( name : & P ) -> Result < ( ) > {
459
484
let ret = name. with_nix_path ( |cstr| {
0 commit comments