MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / mmap

Function mmap

src/backend/linux_raw/mm/syscalls.rs:44–79  ·  view source on GitHub ↗
(
    addr: *mut c_void,
    length: usize,
    prot: ProtFlags,
    flags: MapFlags,
    fd: BorrowedFd<'_>,
    offset: u64,
)

Source from the content-addressed store, hash-verified

42/// with memory pointed to by raw pointers is unsafe.
43#[inline]
44pub(crate) unsafe fn mmap(
45 addr: *mut c_void,
46 length: usize,
47 prot: ProtFlags,
48 flags: MapFlags,
49 fd: BorrowedFd<'_>,
50 offset: u64,
51) -> io::Result<*mut c_void> {
52 #[cfg(target_pointer_width = "32")]
53 {
54 ret_void_star(syscall!(
55 __NR_mmap2,
56 addr,
57 pass_usize(length),
58 prot,
59 flags,
60 fd,
61 (offset / 4096)
62 .try_into()
63 .map(pass_usize)
64 .map_err(|_| io::Errno::INVAL)?
65 ))
66 }
67 #[cfg(target_pointer_width = "64")]
68 {
69 ret_void_star(syscall!(
70 __NR_mmap,
71 addr,
72 pass_usize(length),
73 prot,
74 flags,
75 fd,
76 loff_t_from_u64(offset)
77 ))
78 }
79}
80
81/// # Safety
82///

Callers

nothing calls this directly

Calls 1

ret_void_starFunction · 0.85

Tested by

no test coverage detected