src/kernel/mm/vmm/vmm.c
/**
 * @note copy the vm addr space from src to dest,
 *       pm will be alloc when copying.
 *       however,the physical memory need copy in
 *       src vmm pool must be in RAM.
 *       The data in desc will be covered.
 * @param dest
 * @param src
 * @param start
 * @param len
 */
@note copy the vm addr space from src to dest,
pm will be alloc when copying.
however,the physical memory need copy in
src vmm pool must be in RAM.
The data in desc will be covered.
@note copy the vm addr space from src to dest pm will be alloc when copying . however the physical memory need copy in src vmm pool must be in RAM . The data in desc will be covered .
bool vmm_copy_user_space(vmm_t * dest , vmm_t * src , addr_t start , size_t len){
    start = PAGE_ALIGN(start);
    addr_t end = CEILING(start + len, PAGE_SIZE);
    if(end>CONFIG_USER_ADDR_END){
        end = CONFIG_USER_ADDR_END;
    }
    pte_t * pte;
    addr_t paddr;
    bool ret;
    base_t level_src = intrLock_lock(&src->spinlock);
    base_t level_dest = intrLock_lock(&dest->spinlock);
    for(;start<end;start+=PAGE_SIZE){
        pte = walk(src, start, false);
        if(pte!=NULL){
            if(*pte&VMM_PTE_V){
                paddr = _pte2paddr(*pte);
                if (!pmm_valid(paddr)) {
                    continue;
                }
                addr_t new_vm = valloc_no_lock(dest,start,1,*pte&VMM_PTE_RW_MASK);
                if(new_vm == NULL){
                    ret = false;
                    goto out;
                }
                addr_t new_pm = _pte2paddr(*walk(dest, start, false));
                if(new_pm == NULL){
                    ret = false;
                    goto out;
                }
                memcpy(new_pm,paddr,PAGE_SIZE);
            }
        }
    }
    ret = true;
    out:
    intrLock_unlock(&dest->spinlock,level_dest);
    intrLock_unlock(&src->spinlock,level_src);
    return ret;
}
bool vmm_copy_user_space ( vmm_t * dest , vmm_t * src , addr_t start , size_t len ) { start = PAGE_ALIGN ( start ) ; addr_t end = CEILING ( start + len , PAGE_SIZE ) ; if ( end > CONFIG_USER_ADDR_END ) { end = CONFIG_USER_ADDR_END ; } pte_t * pte ; addr_t paddr ; bool ret ; base_t level_src = intrLock_lock ( & src -> spinlock ) ; base_t level_dest = intrLock_lock ( & dest -> spinlock ) ; for ( ; start < end ; start += PAGE_SIZE ) { pte = walk ( src , start , false ) ; if ( pte != NULL ) { if ( * pte & VMM_PTE_V ) { paddr = _pte2paddr ( * pte ) ; if ( ! pmm_valid ( paddr ) ) { continue ; } addr_t new_vm = valloc_no_lock ( dest , start , 1 , * pte & VMM_PTE_RW_MASK ) ; if ( new_vm == NULL ) { ret = false ; goto out ; } addr_t new_pm = _pte2paddr ( * walk ( dest , start , false ) ) ; if ( new_pm == NULL ) { ret = false ; goto out ; } memcpy ( new_pm , paddr , PAGE_SIZE ) ; } } } ret = true ; out : intrLock_unlock ( & dest -> spinlock , level_dest ) ; intrLock_unlock ( & src -> spinlock , level_src ) ; return ret ; }
@note copy the vm addr space from src to dest,
       pm will be alloc when copying.
@note copy the vm addr space from src to dest pm will be alloc when copying .
//need copy physical page. //check paddr in ram // if this physical page is // not in RAM, this page will // be skipped.