/* modify the property of existed varea by shrink its size. Mem_obj is notified to released the resource.  */
static rt_err_t _shrink_varea(rt_varea_t varea, void *new_va, rt_size_t size)
/* modify the property of existed varea by shrink its size. Mem_obj is notified to released the resource.  */
static rt_err_t _shrink_varea(rt_varea_t varea, void *new_va, rt_size_t size)
{
    rt_err_t error;
    rt_aspace_t aspace;
    void *old_va;
    if (varea->mem_obj && varea->mem_obj->on_varea_shrink)
        error = varea->mem_obj->on_varea_shrink(varea, new_va, size);
    else
        error = -RT_EPERM;
    if (error == RT_EOK)
    {
        aspace = varea->aspace;
        old_va = varea->start;
        varea->size = size;
        if (old_va != new_va)
        {
            varea->start = new_va;
            varea->offset += ((long)new_va - (long)old_va) >> MM_PAGE_SHIFT;
            _aspace_bst_remove(aspace, varea);
            _aspace_bst_insert(aspace, varea);
        }
    }
    return error;
}