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

Function lwp_mmap2

components/lwp/lwp_user_mm.c:551–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

549}
550
551void *lwp_mmap2(struct rt_lwp *lwp, void *addr, size_t length, int prot,
552 int flags, int fd, off_t pgoffset)
553{
554 rt_err_t rc;
555 rt_size_t k_attr, k_flags, k_offset, aligned_size = 0;
556 rt_size_t min_align_size = 1 << MM_PAGE_SHIFT;
557 rt_aspace_t uspace;
558 rt_mem_obj_t mem_obj;
559 void *ret = 0;
560 LOG_D("%s(addr=0x%lx,length=0x%lx,fd=%d,pgoff=0x%lx)", __func__, addr, length, fd, pgoffset);
561
562 /* alignment for affinity page block */
563 if (flags & MAP_FIXED)
564 {
565 if (fd != -1)
566 {
567 /* requested mapping address */
568 rt_base_t va_affid = RT_PAGE_PICK_AFFID(addr);
569 rt_base_t pgoff_affid = RT_PAGE_PICK_AFFID(pgoffset << MM_PAGE_SHIFT);
570
571 /* filter illegal align address */
572 if (va_affid != pgoff_affid)
573 {
574 LOG_W("Unaligned mapping address %p(pgoff=0x%lx) from fd=%d",
575 addr, pgoffset, fd);
576 }
577 }
578 else
579 {
580 /* anonymous mapping can always aligned */
581 }
582 }
583 else
584 {
585 /* weak address selection */
586 aligned_size = _aligned_for_weak_mapping(&pgoffset, &length, &min_align_size);
587 }
588
589 if (fd == -1)
590 {
591 #ifdef RT_DEBUGGING_PAGE_THRESHOLD
592 if (!_memory_threshold_ok())
593 return (void *)-ENOMEM;
594 #endif /* RT_DEBUGGING_PAGE_THRESHOLD */
595
596 k_offset = MM_PA_TO_OFF(addr);
597 k_flags = MMF_CREATE(lwp_user_mm_flag_to_kernel(flags) | MMF_MAP_PRIVATE,
598 min_align_size);
599 k_attr = lwp_user_mm_attr_to_kernel(prot);
600
601 uspace = lwp->aspace;
602 length = RT_ALIGN(length, ARCH_PAGE_SIZE);
603 mem_obj = _get_mmap_obj(lwp);
604
605 rc = rt_aspace_map(uspace, &addr, length, k_attr, k_flags, mem_obj, k_offset);
606 if (rc == RT_EOK)
607 {
608 ret = addr;

Callers 10

lwp_argscopyFunction · 0.85
file_mmapFunction · 0.85
elf_aux_fillFunction · 0.85
sys_mmap2Function · 0.85
test_mmap_fdFunction · 0.85
test_mmap_fix_privateFunction · 0.85
test_mmap_fd_fixedFunction · 0.85
test_map_fixedFunction · 0.85
test_mmap_fd_fixedFunction · 0.85
test_mmap_expandFunction · 0.85

Calls 9

_memory_threshold_okFunction · 0.85
_get_mmap_objFunction · 0.85
rt_aspace_mapFunction · 0.85
lwp_errno_to_posixFunction · 0.85
fd_getFunction · 0.50
dfs_file_mmap2Function · 0.50

Tested by 6

test_mmap_fdFunction · 0.68
test_mmap_fix_privateFunction · 0.68
test_mmap_fd_fixedFunction · 0.68
test_map_fixedFunction · 0.68
test_mmap_fd_fixedFunction · 0.68
test_mmap_expandFunction · 0.68