MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_mmap2

Function sys_mmap2

components/lwp/lwp_syscall.c:2006–2039  ·  view source on GitHub ↗

* @brief Maps a file or device into memory. * * This system call implements the `mmap2` system call, which maps a file or device into memory. * It provides a way for processes to access file contents directly in memory, bypassing * the need for explicit read or write operations. This function supports advanced memory * mapping options such as shared or private mappings, specific protection fl

Source from the content-addressed store, hash-verified

2004 * @see mmap(), munmap(), msync()
2005 */
2006void *sys_mmap2(void *addr, size_t length, int prot,
2007 int flags, int fd, size_t pgoffset)
2008{
2009 sysret_t rc = 0;
2010 long offset = 0;
2011
2012 /* aligned for user addr */
2013 if ((rt_base_t)addr & ARCH_PAGE_MASK)
2014 {
2015 if (flags & MAP_FIXED)
2016 rc = -EINVAL;
2017 else
2018 {
2019 offset = (char *)addr - (char *)RT_ALIGN_DOWN((rt_base_t)addr, ARCH_PAGE_SIZE);
2020 length += offset;
2021 addr = (void *)RT_ALIGN_DOWN((rt_base_t)addr, ARCH_PAGE_SIZE);
2022 }
2023 }
2024
2025 if (rc == 0)
2026 {
2027 /* fix parameter passing (both along have same effect) */
2028 if (fd == -1 || flags & MAP_ANONYMOUS)
2029 {
2030 fd = -1;
2031 /* MAP_SHARED has no effect and treated as nothing */
2032 flags &= ~MAP_SHARED;
2033 flags |= MAP_PRIVATE | MAP_ANONYMOUS;
2034 }
2035 rc = (sysret_t)lwp_mmap2(lwp_self(), addr, length, prot, flags, fd, pgoffset);
2036 }
2037
2038 return rc < 0 ? (char *)rc : (char *)rc + offset;
2039}
2040
2041/**
2042 * @brief Unmaps a memory region previously mapped with mmap or mmap2.

Callers

nothing calls this directly

Calls 2

lwp_mmap2Function · 0.85
lwp_selfFunction · 0.85

Tested by

no test coverage detected