-/*
- * Try to merge a vma with the previous flag, return 1 if successful or 0 if it
- * was impossible.
- */
-static int
-mprotect_attempt_merge(struct vm_area_struct *vma, struct vm_area_struct *prev,
- unsigned long end, int newflags)
-{
- struct mm_struct * mm;
-
- if (!prev || !vma)
- return 0;
- mm = vma->vm_mm;
- if (prev->vm_end != vma->vm_start)
- return 0;
- if (!can_vma_merge(prev, newflags))
- return 0;
- if (vma->vm_file || (vma->vm_flags & VM_SHARED))
- return 0;
-
- /*
- * If the whole area changes to the protection of the previous one
- * we can just get rid of it.
- */
- if (end == vma->vm_end) {
- spin_lock(&mm->page_table_lock);
- prev->vm_end = end;
- __vma_unlink(mm, vma, prev);
- spin_unlock(&mm->page_table_lock);
-
- kmem_cache_free(vm_area_cachep, vma);
- mm->map_count--;
- return 1;
- }
-
- /*
- * Otherwise extend it.
- */
- spin_lock(&mm->page_table_lock);
- prev->vm_end = end;
- vma->vm_start = end;
- spin_unlock(&mm->page_table_lock);
- return 1;
-}