Index string provenance with metered image and session tables

This commit is contained in:
2026-10-14 13:55:16 +01:00
parent bb6f212779
commit 3f9d235546
16 changed files with 848 additions and 15 deletions
@@ -385,6 +385,10 @@ impl<T> BudgetVec<T> {
let bytes = b.bytes::<T>(capacity, q)?;
let mut extra = b.reserve(q, bytes - self.charge.amount)?;
let temporary = b.reserve(RuntimeResource::TemporaryBytes, self.charge.amount)?;
#[cfg(test)]
if FAIL_NEXT_VEC_ALLOCATION.with(|fail| fail.replace(false)) {
return Err(b.failure(q, ResourceReason::AllocationFailed, bytes));
}
let mut candidate = Vec::new();
candidate
.try_reserve_exact(capacity)
@@ -405,6 +409,21 @@ impl<T> BudgetVec<T> {
self.charge.absorb(growth.extra);
}
}
/// Rebuild a table with all fallible capacity/coexistence admission completed
/// before moving any old entry. The relocation callback must not allocate.
pub(crate) fn rebuild_with(
&mut self,
len: usize,
vacant: impl FnMut() -> T,
relocate: impl FnOnce(&mut [T], &mut [T]),
) -> Result<(), ResourceFailure> {
let mut growth = self.prepare_capacity(len.max(self.data.capacity()))?;
growth.candidate.resize_with(len, vacant);
relocate(&mut self.data, &mut growth.candidate);
self.data = growth.candidate;
self.charge.absorb(growth.extra);
Ok(())
}
pub fn reserve(&mut self, additional: usize) -> Result<(), ResourceFailure> {
let growth = self.prepare_growth(additional)?;
self.commit_growth(growth);
@@ -445,9 +464,6 @@ impl<T> BudgetVec<T> {
pub fn clear(&mut self) {
self.data.clear();
}
pub(crate) fn retain(&mut self, keep: impl FnMut(&T) -> bool) {
self.data.retain(keep);
}
pub(crate) fn extend_from_slice(&mut self, values: &[T]) -> Result<(), ResourceFailure>
where
T: Clone,
@@ -509,3 +525,8 @@ pub(crate) struct VecGrowth<T> {
_temporary: Reservation,
old_capacity: usize,
}
#[cfg(test)]
thread_local! {
pub(crate) static FAIL_NEXT_VEC_ALLOCATION: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
}