WIP: Add necessary interfaces for setuid/setgid.

This commit is contained in:
4lDO2
2022-06-16 14:51:23 +02:00
parent 37f9b292f1
commit 6e5015dcab
8 changed files with 229 additions and 119 deletions
+5 -5
View File
@@ -168,20 +168,20 @@ impl UserGrants {
}
}
}
fn unreserve(&mut self, grant: &Region) {
fn unreserve(holes: &mut BTreeMap<VirtualAddress, usize>, grant: &Region) {
// The size of any possible hole directly after the to-be-freed region.
let exactly_after_size = self.holes.remove(&grant.end_address());
let exactly_after_size = holes.remove(&grant.end_address());
// There was a range that began exactly prior to the to-be-freed region, so simply
// increment the size such that it occupies the grant too. If in additional there was a
// grant directly after the grant, include it too in the size.
if let Some((hole_offset, hole_size)) = self.holes.range_mut(..grant.start_address()).next_back().filter(|(offset, size)| offset.data() + **size == grant.start_address().data()) {
if let Some((hole_offset, hole_size)) = holes.range_mut(..grant.start_address()).next_back().filter(|(offset, size)| offset.data() + **size == grant.start_address().data()) {
*hole_size = grant.end_address().data() - hole_offset.data() + exactly_after_size.unwrap_or(0);
} else {
// There was no free region directly before the to-be-freed region, however will
// now unconditionally insert a new free region where the grant was, and add that extra
// size if there was something after it.
self.holes.insert(grant.start_address(), grant.size() + exactly_after_size.unwrap_or(0));
holes.insert(grant.start_address(), grant.size() + exactly_after_size.unwrap_or(0));
}
}
pub fn insert(&mut self, grant: Grant) {
@@ -193,7 +193,7 @@ impl UserGrants {
}
pub fn take(&mut self, region: &Region) -> Option<Grant> {
let grant = self.inner.take(region)?;
self.unreserve(region);
Self::unreserve(&mut self.holes, region);
Some(grant)
}
pub fn iter(&self) -> impl Iterator<Item = &Grant> + '_ {