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

Function rt_varea_fix_private_locked

components/mm/mm_anon.c:555–629  ·  view source on GitHub ↗

* replace an existing mapping to a private one, this is identical to: * => aspace_unmap(ex_varea, ) * => aspace_map() */

Source from the content-addressed store, hash-verified

553 * => aspace_map()
554 */
555int rt_varea_fix_private_locked(rt_varea_t ex_varea, void *pa,
556 struct rt_aspace_fault_msg *msg,
557 rt_bool_t dont_copy)
558{
559 /**
560 * todo: READ -> WRITE lock here
561 */
562 void *page;
563 void *fault_vaddr;
564 rt_aspace_t aspace;
565 rt_mem_obj_t ex_obj;
566 int rc = MM_FAULT_FIXABLE_FALSE;
567 ex_obj = ex_varea->mem_obj;
568
569 if (ex_obj)
570 {
571 fault_vaddr = msg->fault_vaddr;
572 aspace = ex_varea->aspace;
573 RT_ASSERT(!!aspace);
574
575 /**
576 * todo: what if multiple pages are required?
577 */
578 if (aspace->private_object == ex_obj)
579 {
580 RT_ASSERT(0 && "recursion");
581 }
582 else if (ex_obj->page_read)
583 {
584 page = rt_pages_alloc_tagged(0, RT_PAGE_PICK_AFFID(fault_vaddr), PAGE_ANY_AVAILABLE);
585 if (page)
586 {
587 /** setup message & fetch the data from source object */
588 if (!dont_copy)
589 {
590 struct rt_aspace_io_msg io_msg;
591 rt_mm_io_msg_init(&io_msg, msg->off, msg->fault_vaddr, page);
592 ex_obj->page_read(ex_varea, &io_msg);
593 /**
594 * Note: if ex_obj have mapped into varea, it's still okay since
595 * we will override it latter
596 */
597 if (io_msg.response.status != MM_FAULT_STATUS_UNRECOVERABLE)
598 {
599 rc = _override_map(ex_varea, aspace, fault_vaddr, msg, page);
600 }
601 else
602 {
603 rt_pages_free(page, 0);
604 LOG_I("%s: page read(va=%p) fault from %s(start=%p,size=%p)", __func__,
605 msg->fault_vaddr, VAREA_NAME(ex_varea), ex_varea->start, ex_varea->size);
606 }
607 }
608 else
609 {
610 rc = _override_map(ex_varea, aspace, fault_vaddr, msg, page);
611 }
612 }

Callers 2

_write_faultFunction · 0.85
rt_aspace_page_putFunction · 0.85

Calls 4

rt_pages_alloc_taggedFunction · 0.85
rt_mm_io_msg_initFunction · 0.85
_override_mapFunction · 0.85
rt_pages_freeFunction · 0.85

Tested by

no test coverage detected