[vm] Refine VMA created with inherits_file_from
This commit is contained in:
parent
b0989b6d46
commit
56f7ab02a5
@ -46,6 +46,7 @@ impl VMArea {
|
||||
new_perms: VMPerms,
|
||||
access: VMAccess,
|
||||
) -> Self {
|
||||
debug_assert!(vma.is_superset_of(&new_range));
|
||||
let new_backed_file = vma.file_backed.as_ref().map(|file| {
|
||||
let mut new_file = file.clone();
|
||||
let file_offset = file.offset();
|
||||
|
@ -324,9 +324,6 @@ impl ChunkManager {
|
||||
let old_end = containing_vma.end();
|
||||
let protect_end = protect_range.end();
|
||||
|
||||
// Shrinked old VMA
|
||||
containing_vma.set_end(protect_range.start());
|
||||
|
||||
// New VMA
|
||||
let new_vma = VMArea::inherits_file_from(
|
||||
&containing_vma,
|
||||
@ -349,6 +346,9 @@ impl ChunkManager {
|
||||
VMAObj::new_vma_obj(new_vma)
|
||||
};
|
||||
|
||||
// Shrinked old VMA
|
||||
containing_vma.set_end(protect_range.start());
|
||||
|
||||
containing_vmas.replace_with(VMAObj::new_vma_obj(containing_vma));
|
||||
containing_vmas.insert(new_vma);
|
||||
containing_vmas.insert(new_vma2);
|
||||
@ -357,6 +357,15 @@ impl ChunkManager {
|
||||
}
|
||||
1 => {
|
||||
let remain_vma = remain_vmas.pop().unwrap();
|
||||
|
||||
let new_vma = VMArea::inherits_file_from(
|
||||
&containing_vma,
|
||||
intersection_vma.range().clone(),
|
||||
new_perms,
|
||||
VMAccess::Private(current_pid),
|
||||
);
|
||||
VMPerms::apply_perms(&new_vma, new_vma.perms());
|
||||
|
||||
if remain_vma.start() == containing_vma.start() {
|
||||
// mprotect right side of the vma
|
||||
containing_vma.set_end(remain_vma.end());
|
||||
@ -365,13 +374,6 @@ impl ChunkManager {
|
||||
debug_assert!(remain_vma.end() == containing_vma.end());
|
||||
containing_vma.set_start(remain_vma.start());
|
||||
}
|
||||
let new_vma = VMArea::inherits_file_from(
|
||||
&containing_vma,
|
||||
intersection_vma.range().clone(),
|
||||
new_perms,
|
||||
VMAccess::Private(current_pid),
|
||||
);
|
||||
VMPerms::apply_perms(&new_vma, new_vma.perms());
|
||||
|
||||
containing_vmas.replace_with(VMAObj::new_vma_obj(containing_vma));
|
||||
containing_vmas.insert(VMAObj::new_vma_obj(new_vma));
|
||||
|
@ -867,8 +867,6 @@ impl InternalVMManager {
|
||||
let old_end = containing_vma.end();
|
||||
let old_perms = containing_vma.perms();
|
||||
|
||||
containing_vma.set_end(protect_range.start());
|
||||
|
||||
let new_vma = VMArea::inherits_file_from(
|
||||
&containing_vma,
|
||||
protect_range,
|
||||
@ -887,19 +885,13 @@ impl InternalVMManager {
|
||||
)
|
||||
};
|
||||
|
||||
containing_vma.set_end(protect_range.start());
|
||||
|
||||
// Put containing_vma at last to be updated first.
|
||||
let updated_vmas = vec![new_vma, remaining_old_vma, containing_vma.clone()];
|
||||
updated_vmas
|
||||
}
|
||||
_ => {
|
||||
if same_start {
|
||||
// Protect range is at left side of the cotaining vma
|
||||
containing_vma.set_start(protect_range.end());
|
||||
} else {
|
||||
// Protect range is at right side of the cotaining vma
|
||||
containing_vma.set_end(protect_range.start());
|
||||
}
|
||||
|
||||
let new_vma = VMArea::inherits_file_from(
|
||||
&containing_vma,
|
||||
protect_range,
|
||||
@ -908,6 +900,14 @@ impl InternalVMManager {
|
||||
);
|
||||
VMPerms::apply_perms(&new_vma, new_vma.perms());
|
||||
|
||||
if same_start {
|
||||
// Protect range is at left side of the cotaining vma
|
||||
containing_vma.set_start(protect_range.end());
|
||||
} else {
|
||||
// Protect range is at right side of the cotaining vma
|
||||
containing_vma.set_end(protect_range.start());
|
||||
}
|
||||
|
||||
// Put containing_vma at last to be updated first.
|
||||
let updated_vmas = vec![new_vma, containing_vma.clone()];
|
||||
updated_vmas
|
||||
|
Loading…
Reference in New Issue
Block a user