Skip to main content

ostd/mm/frame/
linked_list.rs

1// SPDX-License-Identifier: MPL-2.0
2//! Enabling linked lists of frames without heap allocation.
3//!
4//! This module leverages the customizability of the metadata system (see
5//! [super::meta]) to allow any type of frame to be used in a linked list.
6use vstd::{prelude::*, seq_lib::*, simple_pptr::PPtr};
7use vstd_extra::{cast_ptr::*, ownership::*};
8
9use crate::specs::{
10    arch::*,
11    mm::embedding::list_store::list_registry_ok,
12    mm::frame::{
13        linked_list::linked_list_owners::*, mapping::*, meta_owners::*,
14        meta_region_owners::MetaRegionOwners, unique::UniqueFrameOwner,
15    },
16};
17
18use crate::mm::{
19    frame::meta::{
20        META_SLOT_SIZE, REF_COUNT_UNIQUE,
21        mapping::{frame_to_meta, meta_to_frame},
22    },
23    kspace::FRAME_METADATA_RANGE,
24};
25
26use core::{
27    ops::{Deref, DerefMut},
28    ptr::NonNull,
29    sync::atomic::{AtomicU64, Ordering},
30};
31
32use super::{
33    MetaSlot, mapping,
34    meta::{AnyFrameMeta, get_slot},
35    unique::UniqueFrame,
36};
37use crate::{
38    arch::mm::PagingConsts,
39    mm::{Paddr, Vaddr},
40    //panic::abort,
41};
42
43verus! {
44
45/// A linked list of frames.
46///
47/// Two key features that [`LinkedList`] is different from
48/// [`alloc::collections::LinkedList`] is that:
49///  1. It is intrusive, meaning that the links are part of the frame metadata.
50///     This allows the linked list to be used without heap allocation. But it
51///     disallows a frame to be in multiple linked lists at the same time.
52///  2. The linked list exclusively own the frames, meaning that it takes
53///     unique pointers [`UniqueFrame`]. And other bodies cannot
54///     [`from_in_use`] a frame that is inside a linked list.
55///  3. We also allow creating cursors at a specific frame, allowing $O(1)$
56///     removal without iterating through the list at a cost of some checks.
57///
58/// # Example
59///
60/// To create metadata types that allows linked list links, wrap the metadata
61/// type in [`Link`]:
62///
63/// ```rust
64/// use ostd::{
65///     mm::{frame::{linked_list::{Link, LinkedList}, Frame}, FrameAllocOptions},
66///     impl_untyped_frame_meta_for,
67/// };
68///
69/// #[derive(Debug)]
70/// struct MyMeta { mark: usize }
71///
72/// type MyFrame = Frame<Link<MyMeta>>;
73///
74/// impl_untyped_frame_meta_for!(MyMeta);
75///
76/// let alloc_options = FrameAllocOptions::new();
77/// let frame1 = alloc_options.alloc_frame_with(Link::new(MyMeta { mark: 1 })).unwrap();
78/// let frame2 = alloc_options.alloc_frame_with(Link::new(MyMeta { mark: 2 })).unwrap();
79///
80/// let mut list = LinkedList::new();
81/// list.push_front(frame1.try_into().unwrap());
82/// list.push_front(frame2.try_into().unwrap());
83///
84/// let mut cursor = list.cursor_front_mut();
85/// assert_eq!(cursor.current_meta().unwrap().mark, 2);
86/// cursor.move_next();
87/// assert_eq!(cursor.current_meta().unwrap().mark, 1);
88/// ```
89///
90/// [`from_in_use`]: super::Frame::from_in_use
91///
92/// # Verified Properties
93/// ## Verification Design
94/// The linked list is abstractly represented by a [`LinkedListOwner`]:
95/// ```rust
96/// tracked struct LinkedListOwner<M: AnyFrameMeta + Repr<MetaSlotStorage>> {
97///     pub list: Seq<LinkOwner>,
98///     pub list_id: u64,
99/// }
100/// ```
101/// The raw slot permissions for each link are parked in [`MetaRegionOwners`],
102/// while [`LinkedListOwner`] owns the exclusive metadata permissions. Cursor
103/// accessors borrow these components together when projecting a `Link<M>`.
104/// ## Invariant
105/// The linked list uniquely owns the raw frames that it contains, so they cannot be used by other
106/// data structures. The frame metadata field `in_list` is equal to `list_id` for all links in the list.
107/// The per-link well-formedness against the region (pointer/permission wiring,
108/// `next`/`prev` pointer chain) is captured by
109/// [`LinkedListOwner::relate_region`] (opaque, with per-position
110/// [`LinkedListOwner::relate_region_at`]). The cursor exposes this via
111/// [`CursorOwner::wf_with_region`] and [`CursorMut::wf_region`].
112/// ## Safety
113/// A given linked list can only have one cursor at a time, so there are no data races.
114/// The `prev` and `next` fields of the metadata for each link always points to valid
115/// links in the list, so the structure is memory safe (will not read or write invalid memory).
116pub struct LinkedList<M: AnyFrameMeta + Repr<MetaSlotSmall>> {
117    pub front: Option<ReprPtr<MetaSlotStorage, Link<M>>>,
118    pub back: Option<ReprPtr<MetaSlotStorage, Link<M>>>,
119    /// The number of frames in the list.
120    pub size: usize,
121    /// A lazily initialized ID, used to check whether a frame is in the list.
122    /// 0 means uninitialized.
123    pub list_id: u64,
124}
125
126/// A cursor that can mutate the linked list links.
127///
128/// The cursor points to either a frame or the "ghost" non-element. It points
129/// to the "ghost" non-element when the cursor surpasses the back of the list.
130pub struct CursorMut<'a, M: AnyFrameMeta + Repr<MetaSlotSmall>> {
131    pub list: &'a mut LinkedList<M>,
132    pub current: Option<ReprPtr<MetaSlotStorage, Link<M>>>,
133}
134
135#[verifier::spinoff_prover]
136proof fn lemma_meta_region_inv_at(regions: MetaRegionOwners, i: int)
137    requires
138        regions.inv(),
139        regions.contains(i),
140    ensures
141        regions.slot_owners[i].inv(),
142        regions.slots[i].is_init(),
143        regions.slots[i].addr() == index_to_meta(i),
144        regions.slots[i].value().wf(regions.slot_owners[i]),
145        regions.slot_owners[i].slot_vaddr == regions.slots[i].addr(),
146{
147}
148
149/// Localizes the "no existing slot aliases the inserted frame" universal fact
150/// into its own prover query, so the `MetaRegionOwners::inv` and map-insert
151/// quantifiers do not get over-instantiated inside `insert_before`'s body.
152#[verifier::spinoff_prover]
153proof fn lemma_insert_before_slot_distinct<M: AnyFrameMeta + Repr<MetaSlotSmall>>(
154    owner0: LinkedListOwner<M>,
155    regions0: MetaRegionOwners,
156    frame_idx: int,
157    nn: int,
158)
159    requires
160        owner0.relate_region(regions0),
161        regions0.inv(),
162        regions0.contains(frame_idx),
163        regions0.slot_owners[frame_idx].in_list_perm.value() == 0,
164        0 <= nn <= owner0.list.len() as int,
165    ensures
166        forall|p: int|
167            #![trigger regions0.slot_owners[meta_to_index(owner0.list[p].slot_vaddr)]]
168            (0 <= p < owner0.list.len() as int) ==> frame_idx != meta_to_index(
169                owner0.list[p].slot_vaddr,
170            ),
171{
172    owner0.lemma_relate_region_shape(regions0);
173    assert forall|p: int|
174        #![trigger regions0.slot_owners[meta_to_index(owner0.list[p].slot_vaddr)]]
175        0 <= p < owner0.list.len() as int implies frame_idx != meta_to_index(
176        owner0.list[p].slot_vaddr,
177    ) by {
178        owner0.lemma_relate_region_at_index(regions0, p);
179        owner0.lemma_relate_region_at_facts(regions0, p);
180        if frame_idx == meta_to_index(owner0.list[p].slot_vaddr) {
181            assert(regions0.slot_owners[meta_to_index(
182                owner0.list[p].slot_vaddr,
183            )].in_list_perm.value() == owner0.list_id);
184        }
185    }
186}
187
188impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> LinkedList<M> {
189    /// Creates a new linked list.
190    pub const fn new() -> Self {
191        Self { front: None, back: None, size: 0, list_id: 0 }
192    }
193}
194
195impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> Default for LinkedList<M> {
196    fn default() -> Self {
197        Self::new()
198    }
199}
200
201#[verus_verify]
202impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> LinkedList<M> {
203    /// Gets the number of frames in the linked list.
204    #[verus_spec(s =>
205        with
206            Tracked(owner): Tracked<LinkedListOwner<M>>,
207        requires
208            self.wf(owner),
209            owner.inv(),
210        ensures
211            s == owner@.list.len(),
212    )]
213    pub fn size(&self) -> usize {
214        self.size
215    }
216
217    /// Tells if the linked list is empty.
218    #[verus_spec(b =>
219        with
220            Tracked(owner): Tracked<LinkedListOwner<M>>,
221        requires
222            self.wf(owner),
223            owner.inv(),
224        ensures
225            b ==> self.size == 0 && self.front is None && self.back is None,
226            !b ==> self.size > 0 && self.front is Some && self.back is Some,
227    )]
228    pub fn is_empty(&self) -> bool {
229        let is_empty = self.size == 0;
230        is_empty
231    }
232
233    /// Pushes a frame to the front of the linked list.
234    /// # Verified Properties
235    /// ## Preconditions
236    /// The list must be well-formed, with the pointers to its links' metadata slots
237    /// matching the tracked permission objects. The new frame must be active, so that it is
238    /// valid to call `into_raw` on it inside of `insert_before`.
239    /// ## Postconditions
240    /// The new frame is inserted at the front of the list.
241    /// The list invariants are preserved.
242    /// ## Safety
243    /// See [`insert_before`] for the safety guarantees.
244    #[verus_spec(
245        with
246            Tracked(regions): Tracked<&mut MetaRegionOwners>,
247            Tracked(owner): Tracked<&mut LinkedListOwner<M>>,
248            Tracked(frame_own): Tracked<&mut UniqueFrameOwner<Link<M>>>,
249        requires
250            old(self).wf_region(*old(owner), *old(regions)),
251            old(owner).relate_region(*old(regions)),
252            frame.inv(),
253            old(frame_own).inv(),
254            frame.wf_with_region(*old(frame_own), *old(regions)),
255            frame.frame_link_inv(*old(frame_own), *old(regions)),
256            old(regions).inv(),
257        ensures
258            final(self).wf_region(*final(owner), *final(regions)),
259            final(owner).inv(),
260            final(owner).relate_region(*final(regions)),
261            final(regions).inv(),
262            final(owner).list == old(owner).list.insert(0, final(frame_own).meta_own),
263            old(owner).list_id != 0 ==> final(owner).list_id == old(owner).list_id,
264            final(owner).list_id != 0,
265            final(frame_own).meta_own.slot_vaddr == old(frame_own).meta_own.slot_vaddr,
266            final(frame_own).meta_own.in_list == final(owner).list_id,
267    )]
268    pub fn push_front(&mut self, frame: UniqueFrame<Link<M>>) {
269        let current = self.front;
270        let tracked owner0 = LinkedListOwner::tracked_take(owner);
271        let tracked mut cursor_own = CursorOwner::tracked_front_owner(owner0);
272        let mut cursor = CursorMut { list: self, current };
273
274        #[verus_spec(with Tracked(regions), Tracked(&mut cursor_own), Tracked(frame_own))]
275        cursor.insert_before(frame);
276
277        proof {
278            *owner = cursor_own.list_own;
279            owner.lemma_relate_region_implies_inv(*regions);
280        }
281    }
282
283    /// Pops a frame from the front of the linked list.
284    /// # Verified Properties
285    /// ## Preconditions
286    /// The list must be well-formed, with the pointers to its links' metadata slots
287    /// matching the tracked permission objects.
288    /// ## Postconditions
289    /// - The list invariants are preserved.
290    /// - Returns the front frame and its owner, or `None` if the list is empty.
291    /// ## Safety
292    /// See [`take_current`] for the safety guarantees.
293    #[verus_spec(r =>
294        with
295            Tracked(regions): Tracked<&mut MetaRegionOwners>,
296            Tracked(owner): Tracked<&mut LinkedListOwner<M>>,
297            -> frame_owner: Tracked<Option<UniqueFrameOwner<Link<M>>>>,
298        requires
299            old(regions).inv(),
300            old(self).wf_region(*old(owner), *old(regions)),
301            old(owner).relate_region(*old(regions)),
302        ensures
303            final(regions).inv(),
304            final(owner).inv(),
305            final(owner).relate_region(*final(regions)),
306            final(self).wf_region(*final(owner), *final(regions)),
307            final(owner).list_id == old(owner).list_id,
308            r is Some == (old(owner).list.len() > 0),
309            r is Some == frame_owner@ is Some,
310            r matches Some(frame) ==> (frame_owner@ matches Some(fo) ==> {
311                &&& final(owner).list == old(owner).list.remove(0)
312                &&& fo.meta_own@ == old(owner).list[0]@
313                &&& frame.inv()
314                &&& fo.inv()
315                &&& frame.wf(fo)
316                &&& frame.wf_with_region(fo, *final(regions))
317                &&& frame.frame_link_inv(fo, *final(regions))
318            }),
319            r is None ==> *final(owner) == *old(owner)
320                && *final(self) == *old(self) && *final(regions) == *old(regions),
321    )]
322    pub fn pop_front(&mut self) -> Option<UniqueFrame<Link<M>>> {
323        let tracked owner0 = LinkedListOwner::tracked_take(owner);
324        let tracked mut cursor_own = CursorOwner::tracked_front_owner(owner0);
325        let tracked mut returned_owner: Option<UniqueFrameOwner<Link<M>>>;
326
327        /* Restore the tracked list owner after the cursor call.
328         * Origin Rust: self.cursor_front_mut().take_current()
329         */
330        #[verus_spec(with Tracked(regions), Tracked(&mut cursor_own) => Tracked(returned_owner))]
331        let frame = self.cursor_front_mut().take_current();
332        proof! {
333            *owner = cursor_own.list_own;
334            owner.lemma_relate_region_implies_inv(*regions);
335        }
336        proof_with!(|= Tracked(returned_owner));
337        frame
338    }
339
340    /// Pushes a frame to the back of the linked list.
341    /// # Verified Properties
342    /// ## Preconditions
343    /// The list must be well-formed, with the pointers to its links' metadata slots
344    /// matching the tracked permission objects. The new frame must be active, so that it is
345    /// valid to call `into_raw` on it inside of `insert_before`.
346    /// ## Postconditions
347    /// - The new frame is inserted at the back of the list.
348    /// - The list invariants are preserved.
349    /// ## Safety
350    /// See [`insert_before`] for the safety guarantees.
351    #[verus_spec(
352        with
353            Tracked(regions): Tracked<&mut MetaRegionOwners>,
354            Tracked(owner): Tracked<&mut LinkedListOwner<M>>,
355            Tracked(frame_own): Tracked<&mut UniqueFrameOwner<Link<M>>>,
356        requires
357            old(self).wf_region(*old(owner), *old(regions)),
358            old(owner).relate_region(*old(regions)),
359            frame.inv(),
360            old(frame_own).inv(),
361            frame.wf_with_region(*old(frame_own), *old(regions)),
362            frame.frame_link_inv(*old(frame_own), *old(regions)),
363            old(regions).inv(),
364        ensures
365            final(self).wf_region(*final(owner), *final(regions)),
366            final(owner).inv(),
367            final(owner).relate_region(*final(regions)),
368            final(regions).inv(),
369            final(owner).list == old(owner).list.insert(
370                old(owner).list.len() as int, final(frame_own).meta_own),
371            // Id preserved when already minted; a fresh (empty) list adopts a
372            // non-zero id.
373            old(owner).list_id != 0 ==> final(owner).list_id == old(owner).list_id,
374            final(owner).list_id != 0,
375            final(frame_own).meta_own.slot_vaddr == old(frame_own).meta_own.slot_vaddr,
376            final(frame_own).meta_own.in_list == final(owner).list_id,
377    )]
378    pub fn push_back(&mut self, frame: UniqueFrame<Link<M>>) {
379        let tracked owner0 = LinkedListOwner::tracked_take(owner);
380        let tracked mut cursor_own = CursorOwner::tracked_cursor_mut_at_owner(
381            owner0,
382            owner0.list.len() as int,
383        );
384
385        #[verus_spec(with Tracked(regions), Tracked(&mut cursor_own), Tracked(frame_own))]
386        self.cursor_at_ghost_mut().insert_before(frame);
387
388        proof {
389            *owner = cursor_own.list_own;
390            owner.lemma_relate_region_implies_inv(*regions);
391            assert(self.wf_region(*owner, *regions));
392        }
393    }
394
395    /// Pops a frame from the back of the linked list.
396    /// # Verified Properties
397    /// ## Preconditions
398    /// - The list must be well-formed, with the pointers to its links' metadata slots
399    /// matching the tracked permission objects.
400    /// ## Postconditions
401    /// - Returns the back frame and its owner, or `None` if the list is empty.
402    /// - The list invariants are preserved.
403    /// ## Safety
404    /// See [`take_current`] for the safety guarantees.
405    #[verus_spec(r =>
406        with
407            Tracked(regions): Tracked<&mut MetaRegionOwners>,
408            Tracked(owner): Tracked<&mut LinkedListOwner<M>>,
409            -> frame_owner: Tracked<Option<UniqueFrameOwner<Link<M>>>>,
410        requires
411            old(regions).inv(),
412            old(self).wf_region(*old(owner), *old(regions)),
413            old(owner).relate_region(*old(regions)),
414        ensures
415            final(regions).inv(),
416            final(owner).inv(),
417            final(owner).relate_region(*final(regions)),
418            final(self).wf_region(*final(owner), *final(regions)),
419            final(owner).list_id == old(owner).list_id,
420            (r is Some) == (old(owner).list.len() > 0),
421            (r is Some) == (frame_owner@ is Some),
422            r matches Some(frame) ==> (frame_owner@ matches Some(fo) ==> {
423                &&& final(owner).list == old(owner).list.remove(old(owner).list.len() - 1)
424                &&& fo.meta_own@ == old(owner).list[old(owner).list.len() - 1]@
425                &&& frame.inv()
426                &&& fo.inv()
427                &&& frame.wf(fo)
428                &&& frame.wf_with_region(fo, *final(regions))
429                &&& frame.frame_link_inv(fo, *final(regions))
430            }),
431            r is None ==> *final(owner) == *old(owner)
432                && *final(self) == *old(self) && *final(regions) == *old(regions),
433    )]
434    pub fn pop_back(&mut self) -> Option<UniqueFrame<Link<M>>> {
435        let tracked owner0 = LinkedListOwner::tracked_take(owner);
436        let tracked mut cursor_own = CursorOwner::tracked_back_owner(owner0);
437        let tracked mut returned_owner: Option<UniqueFrameOwner<Link<M>>>;
438
439        /* Restore the tracked list owner after the cursor call.
440         * Origin Rust: self.cursor_back_mut().take_current()
441         */
442        #[verus_spec(with Tracked(regions), Tracked(&mut cursor_own) => Tracked(returned_owner))]
443        let frame = self.cursor_back_mut().take_current();
444        proof! {
445            *owner = cursor_own.list_own;
446            owner.lemma_relate_region_implies_inv(*regions);
447        }
448        proof_with!(|= Tracked(returned_owner));
449        frame
450    }
451
452    /// Tells if a frame is in the list.
453    /// # Verified Properties
454    /// ## Preconditions
455    /// - The list must be well-formed, with the pointers to its links' metadata slots
456    /// matching the tracked permission objects.
457    /// - The list owner must relate its links to the region permissions.
458    /// ## Postconditions
459    /// - The result is `true` exactly when the frame address is valid and its
460    /// region-owned `in_list` tag equals the list's ID after lazy initialization.
461    /// - A valid frame in the owner's list always returns `true`.
462    /// ## Safety
463    /// - `lazy_get_id` uses atomic memory accesses, so there are no data races.
464    /// - We assume that the ID allocator has an available ID if the list previously didn't have one,
465    /// but the consequence if that is not the case is a failsafe panic.
466    /// - Everything else conforms to the safe interface.
467    #[verus_spec(r =>
468        with
469            Tracked(regions): Tracked<&MetaRegionOwners>,
470            Tracked(owner): Tracked<&LinkedListOwner<M>>,
471        requires
472            regions.inv(),
473            old(self).wf(*owner),
474            owner.relate_region(*regions),
475        ensures
476            (valid_frame_paddr(frame) && exists|i: int| 0 <= i < owner.list.len()
477                && #[trigger] meta_to_index(owner.list[i].slot_vaddr) == frame_to_index(frame))
478                ==> r,
479        returns
480            valid_frame_paddr(frame)
481                && regions.slot_owners[frame_to_index(frame)].in_list_perm.value()
482                    == final(self).list_id,
483    )]
484    pub fn contains(&mut self, frame: Paddr) -> bool {
485        proof_decl! {
486        let ghost idx = frame_to_index(frame);
487            if valid_frame_paddr(frame) {
488                regions.lemma_contains_valid_frame_paddr(frame);
489                if exists|i: int| 0 <= i < owner.list.len()
490                    && #[trigger] meta_to_index(owner.list[i].slot_vaddr) == idx {
491                    let i = choose|i: int| 0 <= i < owner.list.len()
492                        && #[trigger] meta_to_index(owner.list[i].slot_vaddr) == idx;
493                    owner.lemma_relate_region_shape(*regions);
494                    owner.lemma_relate_region_at_index(*regions, i);
495                    owner.lemma_relate_region_at_facts(*regions, i);
496                }
497            }
498        let tracked slot_perm = if valid_frame_paddr(frame) {
499            Some(*regions.slots.tracked_borrow(idx))
500        } else {
501            None
502        };
503        }
504        let Ok(slot) = (#[verus_spec(with Tracked(slot_perm))]
505        crate::mm::frame::meta::get_slot(frame)) else {
506            return false;
507        };
508
509        let tracked slot_own = regions.slot_owners.tracked_borrow(idx);
510
511        slot.in_list.load(Tracked(&slot_own.in_list_perm)) == #[verus_spec(with Tracked(owner))]
512        self.lazy_get_id()
513    }
514
515    /// Gets a cursor at the specified frame if the frame is in the list.
516    ///
517    /// This method fails if the frame is not in the list.
518    /// # Verified Properties
519    /// ## Preconditions
520    /// - The list must be well-formed, with the pointers to its links' metadata slots
521    /// matching the tracked permission objects.
522    /// - The list owner must match the list and region permissions, and its
523    /// membership registry must be consistent with the region's `in_list` tags.
524    /// - The list must already have a non-zero ID: `lazy_get_id` does not yet
525    /// model freshness against the region's `in_list` tags for a fresh list.
526    /// ## Postconditions
527    /// - A cursor is returned exactly when the valid frame belongs to the list.
528    /// Its owner has an in-range index matching the frame, and the cursor is
529    /// well-formed with the region permissions.
530    /// - The returned cursor and its tracked owner are either both present or both absent.
531    /// ## Safety
532    /// - `lazy_get_id` uses atomic memory accesses, so there are no data races.
533    #[verus_spec(r =>
534        with
535            Tracked(regions): Tracked<&MetaRegionOwners>,
536            Tracked(owner): Tracked<&mut LinkedListOwner<M>>,
537            -> cursor_owner: Tracked<Option<CursorOwner<M>>>,
538        requires
539            regions.inv(),
540            old(self).wf_region(*old(owner), *regions),
541            old(owner).relate_region(*regions),
542            list_registry_ok(*regions, *old(owner)),
543            old(owner).list_id != 0,
544        ensures
545            !valid_frame_paddr(frame) ==> r is None,
546            r is Some == cursor_owner@ is Some,
547            (r is Some) == (valid_frame_paddr(frame)
548                && exists|i: int| 0 <= i < old(owner).list.len()
549                    && #[trigger] meta_to_index(old(owner).list[i].slot_vaddr) == frame_to_index(frame)),
550            r is None ==> {
551                &&& *final(owner) == *old(owner)
552                &&& *final(self) == *old(self)
553                &&& final(self).wf_region(*final(owner), *regions)
554                &&& final(owner).inv()
555            },
556            r matches Some(cursor) ==> (cursor_owner@ matches Some(co) ==> {
557                &&& co.list_own == *old(owner)
558                &&& 0 <= co.index < co.list_own.list.len()
559                &&& meta_to_index(co.list_own.list[co.index].slot_vaddr) == frame_to_index(frame)
560                &&& cursor.wf_region(co, *regions)
561                &&& co.wf_with_region(*regions)
562                &&& cursor.wf(co)
563                &&& co.inv()
564                &&& *cursor.list == *old(self)
565                &&& *final(self) == *final(cursor.list)
566            }),
567    )]
568    pub fn cursor_mut_at(&mut self, frame: Paddr) -> Option<CursorMut<'_, M>> {
569        proof_decl! {
570            owner.lemma_relate_region_implies_inv(*regions);
571            let ghost idx = frame_to_index(frame);
572            if valid_frame_paddr(frame) {
573                regions.lemma_contains_valid_frame_paddr(frame);
574            }
575
576            let tracked slot_perm = if valid_frame_paddr(frame) {
577                Some(*regions.slots.tracked_borrow(idx))
578            } else {
579                None
580            };
581        }
582        let Ok(slot) = (#[verus_spec(with Tracked(slot_perm))]
583        crate::mm::frame::meta::get_slot(frame)) else {
584            return {
585                proof_with!(|= Tracked(None));
586                None
587            };
588        };
589
590        let tracked slot_own = regions.slot_owners.tracked_borrow(idx);
591
592        let contains = slot.in_list.load(Tracked(&slot_own.in_list_perm))
593            == #[verus_spec(with Tracked(&*owner))]
594        self.lazy_get_id();
595
596        if contains {
597            proof_decl!{
598                let ghost index = choose|i: int| 0 <= i < owner.list.len()
599                    && #[trigger] meta_to_index(owner.list[i].slot_vaddr) == frame_to_index(frame);
600                owner.lemma_relate_region_at_index(*regions, index);
601                owner.lemma_relate_region_at_facts(*regions, index);
602                lemma_meta_region_inv_at(*regions, idx);
603                let tracked list_owner = LinkedListOwner::tracked_take(owner);
604                let tracked cursor_owner = CursorOwner::tracked_cursor_mut_at_owner(list_owner, index);
605            }
606
607            let meta_ptr = ReprPtr::<MetaSlotStorage, Link<M>>::from_pptr(
608                PPtr::<MetaSlotStorage>::from_addr(frame_to_meta(frame)),
609            );
610            proof_with!(|= Tracked(Some(cursor_owner)));
611            Some(CursorMut { list: self, current: Some(meta_ptr) })
612        } else {
613            proof_with!(|= Tracked(None));
614            None
615        }
616    }
617
618    /// Gets a cursor at the front that can mutate the linked list links.
619    ///
620    /// If the list is empty, the cursor points to the "ghost" non-element.
621    /// # Verified Properties
622    /// ## Safety
623    /// This function is written in safe Rust and there is no undefined behavior.
624    #[verus_spec(r =>
625        ensures
626            r.current == old(self).front,
627            *r.list == *old(self),
628            *final(self) == *final(r.list),
629    )]
630    pub fn cursor_front_mut(&mut self) -> CursorMut<'_, M> {
631        let current = self.front;
632        CursorMut { list: self, current }
633    }
634
635    /// Gets a cursor at the back that can mutate the linked list links.
636    ///
637    /// If the list is empty, the cursor points to the "ghost" non-element.
638    /// # Verified Properties
639    /// ## Safety
640    /// This function is written in safe Rust and there is no undefined behavior.
641    #[verus_spec(r =>
642        ensures
643            r.current == old(self).back,
644            *r.list == *old(self),
645            *final(self) == *final(r.list),
646    )]
647    pub fn cursor_back_mut(&mut self) -> CursorMut<'_, M> {
648        let current = self.back;
649        CursorMut { list: self, current }
650    }
651
652    /// Gets a cursor at the "ghost" non-element that can mutate the linked list links.
653    /// # Verified Properties
654    /// ## Safety
655    /// This function is written in safe Rust and there is no undefined behavior.
656    #[verus_spec(r =>
657        ensures
658            r.current.is_none(),
659            *r.list == *old(self),
660            *final(self) == *final(r.list),
661    )]
662    fn cursor_at_ghost_mut(&mut self) -> CursorMut<'_, M> {
663        CursorMut { list: self, current: None }
664    }
665
666    /// # Verification Assumption
667    /// We assume that there is an available ID for `lazy_get_id` to return.
668    /// This is safe because it will panic if the ID allocator is exhausted.
669    #[verifier::external_body]
670    #[verus_spec(
671        with Tracked(owner): Tracked<& LinkedListOwner<M>>
672    )]
673    fn lazy_get_id(&mut self) -> (id: u64)
674        ensures
675            owner.list_id != 0 ==> id == owner.list_id,
676            final(self).size == old(self).size,
677            final(self).front == old(self).front,
678            final(self).back == old(self).back,
679            old(self).list_id != 0 ==> final(self).list_id == old(self).list_id,
680            id != 0,
681            final(self).list_id == id,
682    {
683        unimplemented!()/*        // FIXME: Self-incrementing IDs may overflow, while `core::pin::Pin`
684        // is not compatible with locks. Think about a better solution.
685        static LIST_ID_ALLOCATOR: AtomicU64 = AtomicU64::new(1);
686        const MAX_LIST_ID: u64 = i64::MAX as u64;
687
688        if self.list_id == 0 {
689            let id = LIST_ID_ALLOCATOR.fetch_add(1, Ordering::Relaxed);
690            if id >= MAX_LIST_ID {
691//                log::error!("The frame list ID allocator has exhausted.");
692//                abort();
693                unimplemented!()
694            }
695            self.list_id = id;
696            id
697        } else {
698            self.list_id
699        }*/
700
701    }
702}
703
704impl<'a, M: AnyFrameMeta + Repr<MetaSlotSmall>> CursorMut<'a, M> {
705    /// Moves the cursor to the next frame towards the back.
706    ///
707    /// If the cursor is pointing to the "ghost" non-element then this will
708    /// move it to the first element of the [`LinkedList`]. If it is pointing
709    /// to the last element of the LinkedList then this will move it to the
710    /// "ghost" non-element.
711    #[verus_spec(
712        with Tracked(owner): Tracked<CursorOwner<M>>,
713            Tracked(regions): Tracked<&MetaRegionOwners>,
714    )]
715    pub fn move_next(&mut self)
716        requires
717            owner.wf_with_region(*regions),
718            old(self).wf_region(owner, *regions),
719        ensures
720            owner.move_next_owner_spec()@ == owner@.move_next_spec(),
721            owner.move_next_owner_spec().wf_with_region(*regions),
722            final(self).wf_region(owner.move_next_owner_spec(), *regions),
723    {
724        proof {
725            owner.list_own.lemma_relate_region_shape(*regions);
726            if self.current is Some {
727                owner.list_own.lemma_relate_region_at_index(*regions, owner.index);
728                owner.list_own.lemma_relate_region_at_facts(*regions, owner.index);
729            }
730            if owner.index < owner.length() - 1 {
731                owner.list_own.lemma_relate_region_at_index(*regions, owner.index + 1);
732                owner.list_own.lemma_relate_region_at_facts(*regions, owner.index + 1);
733            }
734        }
735
736        self.current = match self.current {
737            // SAFETY: The cursor is pointing to a valid element.
738            Some(current) => {
739                proof_decl!{
740                    let ghost idx = meta_to_index(current.addr());
741                    let tracked points_to = regions.slots.tracked_borrow(idx);
742                    let tracked metadata_perms =
743                        owner.list_own.metadata_perms.tracked_borrow(owner.index);
744                }
745                proof {
746                    assert(regions.contains(idx));
747                }
748                let link = borrow_meta(current, Tracked(points_to), Tracked(metadata_perms));
749                link.next
750            },
751            None => self.list.front,
752        };
753
754        proof {
755            assert(owner.move_next_owner_spec()@.fore == owner@.move_next_spec().fore);
756            assert(owner.move_next_owner_spec()@.rear == owner@.move_next_spec().rear);
757        }
758    }
759
760    /// Moves the cursor to the previous frame towards the front.
761    ///
762    /// If the cursor is pointing to the "ghost" non-element then this will
763    /// move it to the last element of the [`LinkedList`]. If it is pointing
764    /// to the first element of the LinkedList then this will move it to the
765    /// "ghost" non-element.
766    #[verus_spec(
767        with Tracked(owner): Tracked<CursorOwner<M>>,
768            Tracked(regions): Tracked<&MetaRegionOwners>,
769    )]
770    pub fn move_prev(&mut self)
771        requires
772            owner.wf_with_region(*regions),
773            old(self).wf_region(owner, *regions),
774        ensures
775            owner.move_prev_owner_spec()@ == owner@.move_prev_spec(),
776            owner.move_prev_owner_spec().wf_with_region(*regions),
777            final(self).wf_region(owner.move_prev_owner_spec(), *regions),
778    {
779        proof {
780            owner.list_own.lemma_relate_region_shape(*regions);
781            if self.current is Some {
782                owner.list_own.lemma_relate_region_at_index(*regions, owner.index);
783                owner.list_own.lemma_relate_region_at_facts(*regions, owner.index);
784            }
785            if 0 < owner.index {
786                owner.list_own.lemma_relate_region_at_index(*regions, owner.index - 1);
787                owner.list_own.lemma_relate_region_at_facts(*regions, owner.index - 1);
788            }
789        }
790
791        self.current = match self.current {
792            // SAFETY: The cursor is pointing to a valid element.
793            Some(current) => {
794                proof_decl!{
795                    let ghost idx = meta_to_index(current.addr());
796                    let tracked points_to = regions.slots.tracked_borrow(idx);
797                    let tracked metadata_perms =
798                        owner.list_own.metadata_perms.tracked_borrow(owner.index);
799                }
800                proof {
801                    assert(regions.contains(idx));
802                }
803
804                let link = borrow_meta(current, Tracked(points_to), Tracked(metadata_perms));
805                link.prev
806            },
807            None => self.list.back,
808        };
809
810        proof {
811            if owner@.list_model.list.len() > 0 {
812                if owner@.fore.len() > 0 {
813                    assert(owner.move_prev_owner_spec()@.fore == owner@.move_prev_spec().fore);
814                    assert(owner.move_prev_owner_spec()@.rear == owner@.move_prev_spec().rear);
815                    if owner@.rear.len() > 0 {
816                        owner.list_own.lemma_relate_region_at_index(*regions, owner.index);
817                        owner.list_own.lemma_relate_region_at_facts(*regions, owner.index);
818                    }
819                } else {
820                    owner.list_own.lemma_relate_region_at_index(*regions, owner.index);
821                    owner.list_own.lemma_relate_region_at_facts(*regions, owner.index);
822                    assert(owner.move_prev_owner_spec()@.rear == owner@.move_prev_spec().rear);
823                    assert(owner@.rear == owner@.list_model.list);
824                }
825            }
826        }
827    }
828
829    /// Gets the mutable reference to the current frame's metadata.
830    ///
831    /// # Verified Properties
832    /// ## Preconditions
833    /// The cursor must be well-formed with respect to the tracked `CursorOwner`.
834    /// ## Postconditions
835    /// If the cursor is on an element, returns `Some(&mut meta)` borrowing the
836    /// current link's metadata. The cursor state and list shape are otherwise
837    /// unchanged; the current metadata permission remains borrowed while the
838    /// returned reference is live.
839    /// ## Safety
840    /// The `&mut self` guarantees exclusive access to the cursor; the tracked
841    /// `CursorOwner` guarantees the perm for the current link is live.
842    #[verus_spec(
843        with Tracked(owner): Tracked<&'b mut CursorOwner<M>>,
844            Tracked(regions): Tracked<&'b mut MetaRegionOwners>,
845    )]
846    pub fn current_meta<'b>(&'b mut self) -> (res: Option<&'b mut M>)
847        requires
848            old(self).wf_region(*old(owner), *old(regions)),
849            old(owner).wf_with_region(*old(regions)),
850            old(regions).inv(),
851        ensures
852            final(owner).index == old(owner).index,
853            final(owner).list_own.list == old(owner).list_own.list,
854            final(owner).list_own.list_id == old(owner).list_own.list_id,
855            *final(self) == *old(self),
856            res.is_some() == (0 <= final(owner).index < final(owner).length()),
857            final(regions).slots.dom() == old(regions).slots.dom(),
858            final(regions).slot_owners.dom() == old(regions).slot_owners.dom(),
859    {
860        // Verus does not support option.map very well.
861        // self.current.map(|current| {
862        //     let link_mut = unsafe { &mut *(current.ptr.addr() as *mut Link<M>) };
863        //     &mut link_mut.meta
864        // })
865        match self.current {
866            Some(current) => {
867                proof {
868                    owner.list_own.lemma_relate_region_shape(*regions);
869                    owner.list_own.lemma_relate_region_at_index(*regions, owner.index);
870                    owner.list_own.lemma_relate_region_at_facts(*regions, owner.index);
871                }
872                let ghost idx = meta_to_index(current.addr());
873                proof {
874                    assert(regions.contains(idx));
875                }
876                let tracked points_to = regions.slots.tracked_borrow(idx);
877                let tracked metadata_perms = owner.list_own.metadata_perms.tracked_borrow_mut(
878                    owner.index,
879                );
880                Some(
881                    &mut borrow_meta_mut(current, Tracked(points_to), Tracked(metadata_perms)).meta,
882                )
883            },
884            None => None,
885        }
886    }
887
888    /// Takes the current pointing frame out of the linked list.
889    ///
890    /// If successful, the frame is returned and the cursor is moved to the
891    /// next frame. If the cursor is pointing to the back of the list then it
892    /// is moved to the "ghost" non-element.
893    /// # Verified Properties
894    /// ## Preconditions
895    /// The cursor must be well-formed, with the pointers to its links' metadata slots
896    /// matching the tracked permission objects.
897    /// ## Postconditions
898    /// At an element, returns the frame, transfers its owner through the tracked output,
899    /// and moves the cursor to the next frame. At the ghost non-element, returns `None`
900    /// without changing the cursor, list owner, or region permissions.
901    /// ## Safety
902    /// This function calls `from_raw` on the frame, but we guarantee that the frame is forgotten
903    /// if it is in the list. So, double-free will not occur. All loads and stores are through track
904    /// tracked permissions, so there are no illegal memory accesses. No data races are possible.
905    #[verus_spec(res =>
906        with
907            Tracked(regions): Tracked<&mut MetaRegionOwners>,
908            Tracked(owner): Tracked<&mut CursorOwner<M>>,
909            -> returned_owner: Tracked<Option<UniqueFrameOwner<Link<M>>>>,
910
911        requires
912            old(self).wf_region(*old(owner), *old(regions)),
913            old(owner).wf_with_region(*old(regions)),
914            old(regions).inv(),
915        ensures
916            (res is Some) == (returned_owner@ is Some),
917            old(owner).length() == 0 ==> res.is_none(),
918            old(self).current.is_some() ==> res.is_some(),
919            final(owner).wf_with_region(*final(regions)),
920            final(self).wf_region(*final(owner), *final(regions)),
921            *final(final(self).list) == *final(old(self).list),
922            final(regions).inv(),
923            final(owner).list_own.list_id == old(owner).list_own.list_id,
924            res is None ==> {
925                &&& *final(self) == *old(self)
926                &&& *final(owner) == *old(owner)
927                &&& *final(regions) == *old(regions)
928            },
929            res matches Some(unique) ==> {
930                let paddr = meta_to_frame(old(self).current->0.addr());
931                let idx = frame_to_index(paddr);
932                let metadata_perm = unique.tracked_metadata_perm@->0;
933                &&& final(owner)@ == old(owner)@.remove()
934                &&& final(owner).index == old(owner).index
935                &&& final(owner).list_own.list == old(owner).list_own.list.remove(old(owner).index)
936                &&& final(regions).slots.dom() == old(regions).slots.dom()
937                &&& final(regions).ref_count(idx) == REF_COUNT_UNIQUE
938                &&& final(regions).slot_owners[idx].in_list_perm.value() == 0
939                &&& metadata_perm.storage_perm.is_init()
940                &&& metadata_perm.vtable_ptr_perm.is_init()
941                &&& final(regions).slot_owners[idx].slot_vaddr == index_to_meta(idx)
942                &&& final(regions).slot_owners[idx].paths_in_pt == old(regions).slot_owners[idx].paths_in_pt
943                &&& *final(regions) == old(regions).insert_slot_owner(
944                    paddr, final(regions).slot_owners[idx],
945                )
946                &&& unique.inv()
947                &&& unique.ptr.addr() == old(self).current->0.addr()
948                &&& returned_owner@ matches Some(unique_owner) ==> {
949                    &&& unique_owner.meta_own@ == old(owner).list_own.list[old(owner).index]@
950                    &&& unique.frame_link_inv(unique_owner, *final(regions))
951                    &&& unique.wf(unique_owner)
952                    &&& unique_owner.inv()
953                    &&& unique.wf_with_region(unique_owner, *final(regions))
954                    &&& unique_owner.slot_index == idx
955                }
956            },
957    )]
958    #[verifier::spinoff_prover]
959    #[verifier::rlimit(250)]
960    pub fn take_current(&mut self) -> Option<UniqueFrame<Link<M>>> {
961        hide(typed_meta_wf);
962        hide(MetaSlotOwner::storage_perm);
963        hide(MetaSlotOwner::vtable_ptr_perm);
964        hide(<MetaRegionOwners as Inv>::inv);
965        let ghost owner0 = *owner;
966        let ghost regions0 = *regions;
967
968        /* Ghost returns need an explicit owner on the early-return path.
969         * Origin Rust: let current = self.current?;
970         */
971        let current = match self.current {
972            Some(current) => current,
973            None => return {
974                proof_with!(|= Tracked(None));
975                None
976            },
977        };
978
979        proof {
980            owner.list_own.lemma_relate_region_shape(*regions);
981            owner.list_own.lemma_relate_region_at_index(*regions, owner.index);
982            owner.list_own.lemma_relate_region_at_facts(*regions, owner.index);
983            if owner.index > 0 {
984                owner.list_own.lemma_relate_region_at_index(*regions, owner.index - 1);
985                owner.list_own.lemma_relate_region_at_facts(*regions, owner.index - 1);
986            }
987            if owner.index < owner.list_own.list.len() - 1 {
988                owner.list_own.lemma_relate_region_at_index(*regions, owner.index + 1);
989                owner.list_own.lemma_relate_region_at_facts(*regions, owner.index + 1);
990            }
991        }
992
993        let meta_ptr = current.addr();
994        let paddr = meta_to_frame(meta_ptr);
995        let ghost idx = frame_to_index(paddr);
996
997        proof {
998            lemma_meta_region_inv_at(regions0, idx);
999        }
1000
1001        let tracked mut cur_own = owner.list_own.list.tracked_remove(owner.index);
1002        let tracked cur_metadata_perm = owner.list_own.metadata_perms.tracked_remove(owner.index);
1003
1004        proof_decl! {
1005            let tracked mut frame_own: UniqueFrameOwner<Link<M>>;
1006        }
1007        assert(MetaSlot::perms_related(*regions.slots[idx], cur_metadata_perm)) by {
1008            reveal(typed_meta_wf);
1009        };
1010        let mut frame = unsafe {
1011            // SAFETY: The frame was forgotten when inserted into the linked list.
1012            #[verus_spec(with
1013                Tracked(regions.tracked_borrow_slot(paddr)),
1014                Tracked(cur_own),
1015
1016                Tracked(cur_metadata_perm) => Tracked(frame_own)
1017            )]
1018            UniqueFrame::<Link<M>>::from_raw(paddr)
1019        };
1020
1021        proof {
1022            assert(regions.slots.dom() == regions0.slots.dom());
1023        }
1024
1025        let next_ptr = (#[verus_spec(with Tracked(&frame_own))]
1026        frame.meta()).next;
1027        let prev_ptr = (#[verus_spec(with Tracked(&frame_own))]
1028        frame.meta()).prev;
1029
1030        if let Some(prev) = prev_ptr {
1031            let ghost prev_idx = meta_to_index(owner.list_own.list[owner.index - 1].slot_vaddr);
1032            proof {
1033                lemma_meta_region_inv_at(*regions, prev_idx);
1034            }
1035            let tracked prev_points_to = regions.slots.tracked_borrow(prev_idx);
1036            let tracked prev_metadata_perm = owner.list_own.metadata_perms.tracked_borrow_mut(
1037                owner.index - 1,
1038            );
1039            let prev_meta = borrow_meta_mut(
1040                prev,
1041                Tracked(prev_points_to),
1042                Tracked(prev_metadata_perm),
1043            );
1044            prev_meta.next = next_ptr;
1045
1046        } else {
1047            self.list.front = next_ptr;
1048        }
1049
1050        if let Some(next) = next_ptr {
1051            let ghost next_idx = meta_to_index(owner.list_own.list[owner.index].slot_vaddr);
1052            proof {
1053                lemma_meta_region_inv_at(*regions, next_idx);
1054            }
1055            let tracked next_points_to = regions.slots.tracked_borrow(next_idx);
1056            let tracked next_metadata_perm = owner.list_own.metadata_perms.tracked_borrow_mut(
1057                owner.index,
1058            );
1059            let next_meta = borrow_meta_mut(
1060                next,
1061                Tracked(next_points_to),
1062                Tracked(next_metadata_perm),
1063            );
1064            next_meta.prev = prev_ptr;
1065
1066            self.current = Some(next);
1067        } else {
1068            self.list.back = prev_ptr;
1069
1070            self.current = None;
1071        }
1072
1073        (#[verus_spec(with Tracked(&mut frame_own))]
1074        frame.meta_mut()).next = None;
1075        (#[verus_spec(with Tracked(&mut frame_own))]
1076        frame.meta_mut()).prev = None;
1077
1078        let tracked mut frame_so = regions.slot_owners.tracked_borrow_mut(idx);
1079        let tracked mut fip = &mut frame_so;
1080        let slot = frame.slot();
1081        slot.in_list.store(Tracked(&mut fip.in_list_perm), 0);
1082        proof {
1083            assert(regions.inv()) by {
1084                reveal(MetaSlotOwner::storage_perm);
1085                reveal(MetaSlotOwner::vtable_ptr_perm);
1086                reveal(<MetaRegionOwners as Inv>::inv);
1087            };
1088            assert(regions.slots.dom() == regions0.slots.dom());
1089        }
1090
1091        self.list.size -= 1;
1092
1093        proof {
1094            assert(owner.list_own.relate_region(*regions)) by {
1095                let ghost oldl = owner0.list_own;
1096                let ghost nn = owner0.index as int;
1097                assert forall|p: int|
1098                    #![trigger meta_to_index(oldl.list[p].slot_vaddr)]
1099                    (0 <= p < oldl.list.len() && p != nn) implies ({
1100                    let i = meta_to_index(oldl.list[p].slot_vaddr);
1101                    let np = if p < nn {
1102                        p
1103                    } else {
1104                        p - 1
1105                    };
1106                    let fp = owner.list_own.meta_value_at(*regions, np);
1107                    &&& regions.contains(i)
1108                    &&& regions.slots[i].addr() == oldl.list[p].slot_vaddr
1109                    &&& regions.slots[i].ptr() == regions0.slots[i].ptr()
1110                    &&& regions.ref_count(i) == REF_COUNT_UNIQUE
1111                    &&& regions.slot_owners[i].metadata_perm.is_resource_vacant()
1112                    &&& owner.list_own.metadata_perms[np].storage_perm.id()
1113                        == regions.slots[i].value().storage.id()
1114                    &&& owner.list_own.metadata_perms[np].vtable_ptr_perm.pptr()
1115                        == regions.slots[i].value().vtable_ptr
1116                    &&& owner.list_own.metadata_perms[np].vtable_ptr_perm.is_init()
1117                    &&& regions.slot_owners[i].usage is Frame
1118                    &&& regions.slot_owners[i].in_list_perm.value() == owner.list_own.list_id
1119                    &&& owner.list_own.meta_wf_at(*regions, np)
1120                    &&& regions.slots[i].addr() % META_SLOT_SIZE == 0
1121                    &&& FRAME_METADATA_RANGE.start <= regions.slots[i].addr()
1122                        < FRAME_METADATA_RANGE.start + MAX_NR_PAGES * META_SLOT_SIZE
1123                    &&& (p == nn - 1 ==> fp.next == oldl.meta_value_at(regions0, nn).next)
1124                    &&& (p != nn - 1 ==> fp.next == oldl.meta_value_at(regions0, p).next)
1125                    &&& (p == nn + 1 ==> fp.prev == oldl.meta_value_at(regions0, nn).prev)
1126                    &&& (p != nn + 1 ==> fp.prev == oldl.meta_value_at(regions0, p).prev)
1127                }) by {
1128                    reveal(typed_meta_wf);
1129                    let i = meta_to_index(oldl.list[p].slot_vaddr);
1130                    let np = if p < nn {
1131                        p
1132                    } else {
1133                        p - 1
1134                    };
1135                    let fp = owner.list_own.meta_value_at(*regions, np);
1136                    oldl.lemma_relate_region_at_index(regions0, p);
1137                    oldl.lemma_relate_region_at_index(regions0, nn);
1138                    oldl.lemma_relate_region_indices_distinct(regions0, p, nn);
1139                    oldl.lemma_relate_region_at_facts(regions0, p);
1140                    oldl.lemma_relate_region_at_facts(regions0, nn);
1141                    assert(regions.contains(i));
1142                }
1143                LinkedListOwner::lemma_pop_preserves_relate_region(
1144                    oldl,
1145                    regions0,
1146                    owner.list_own,
1147                    *regions,
1148                    nn,
1149                );
1150            };
1151            assert(frame.wf_with_region(frame_own, *regions)) by {
1152                reveal(typed_meta_wf);
1153            };
1154            owner0.remove_owner_spec_implies_model_spec(*owner);
1155        }
1156        proof_with!(|= Tracked(Some(frame_own)));
1157        Some(frame)
1158    }
1159
1160    /// Inserts a frame before the current frame.
1161    ///
1162    /// If the cursor is pointing at the "ghost" non-element then the new
1163    /// element is inserted at the back of the [`LinkedList`].
1164    /// # Verified Properties
1165    /// ## Preconditions
1166    /// The cursor must be well-formed, with the pointers to its links' metadata slots matching the tracked permission objects.
1167    /// - The new frame must be active, so that it is valid to call `into_raw` on it.
1168    /// ## Postconditions
1169    /// - The new frame is inserted into the list, immediately before the current index.
1170    /// - The list invariants are preserved.
1171    /// ## Safety
1172    /// - This function calls `into_raw` on the frame, so the caller must ensure that the frame is active and
1173    /// has not been forgotten already to avoid a memory leak. If the caller attempts to insert a forgotten frame,
1174    /// the invariant around `into_raw` and `from_raw` will be violated. But, it is the safe failure case in that
1175    /// it will not cause a double-free. (Note: we should be able to move this requirement into the `UniqueFrame` invariants.)
1176    #[verus_spec(
1177        with Tracked(regions): Tracked<&mut MetaRegionOwners>,
1178            Tracked(owner): Tracked<&mut CursorOwner<M>>,
1179            Tracked(frame_own): Tracked<&mut UniqueFrameOwner<Link<M>>>
1180    )]
1181    #[verifier::spinoff_prover]
1182    #[verifier::rlimit(200)]
1183    pub fn insert_before(&mut self, mut frame: UniqueFrame<Link<M>>)
1184        requires
1185            old(self).wf_region(*old(owner), *old(regions)),
1186            old(owner).wf_with_region(*old(regions)),
1187            old(regions).inv(),
1188            frame.inv(),
1189            old(frame_own).inv(),
1190            frame.wf_with_region(*old(frame_own), *old(regions)),
1191            frame.frame_link_inv(*old(frame_own), *old(regions)),
1192        ensures
1193            final(owner).wf_with_region(*final(regions)),
1194            final(self).wf_region(*final(owner), *final(regions)),
1195            *final(final(self).list) == *final(old(self).list),
1196            final(regions).inv(),
1197            final(owner).list_own.list == old(owner).list_own.list.insert(
1198                old(owner).index,
1199                final(frame_own).meta_own,
1200            ),
1201            // The id is preserved when it was already minted; a `list_id == 0`
1202            // (necessarily empty) list adopts a freshly-minted non-zero id.
1203            old(owner).list_own.list_id != 0 ==> final(owner).list_own.list_id == old(
1204                owner,
1205            ).list_own.list_id,
1206            final(owner).list_own.list_id != 0,
1207            final(owner).index == old(owner).index + 1,
1208            final(frame_own).meta_own.slot_vaddr == old(frame_own).meta_own.slot_vaddr,
1209            final(frame_own).meta_own.in_list == final(owner).list_own.list_id,
1210            final(owner)@ == old(owner)@.insert(final(frame_own).meta_own@),
1211    {
1212        hide(MetaSlotOwner::storage_perm);
1213        hide(MetaSlotOwner::vtable_ptr_perm);
1214        hide(<MetaRegionOwners as Inv>::inv);
1215        let ghost owner0 = *owner;
1216        let ghost regions0 = *regions;
1217        let ghost nn = owner.index as int;
1218
1219        proof {
1220            assert(owner0.list_own.metadata_perms.len() == owner0.list_own.list.len()) by {
1221                reveal(LinkedListOwner::relate_region);
1222            };
1223            assert(owner0.list_own.list.len() > 0 ==> owner0.list_own.list_id != 0) by {
1224                reveal(LinkedListOwner::relate_region);
1225            };
1226            lemma_meta_region_inv_at(regions0, frame_own.slot_index);
1227            owner0.list_own.lemma_length_lt_usize_max(regions0);
1228            if nn > 0 {
1229                assert(owner0.list_own.relate_region_at(regions0, nn - 1)) by {
1230                    reveal(LinkedListOwner::relate_region);
1231                };
1232                owner.list_own.lemma_relate_region_at_facts(*regions, nn - 1);
1233                lemma_meta_region_inv_at(
1234                    regions0,
1235                    meta_to_index(owner0.list_own.list[nn - 1].slot_vaddr),
1236                );
1237            }
1238            if nn < owner.list_own.list.len() {
1239                assert(owner0.list_own.relate_region_at(regions0, nn)) by {
1240                    reveal(LinkedListOwner::relate_region);
1241                };
1242                owner.list_own.lemma_relate_region_at_facts(*regions, nn);
1243                lemma_meta_region_inv_at(
1244                    regions0,
1245                    meta_to_index(owner0.list_own.list[nn].slot_vaddr),
1246                );
1247            }
1248            assert forall|p: int|
1249                #![trigger
1250                    regions0.slot_owners[meta_to_index(owner0.list_own.list[p].slot_vaddr)]]
1251                0 <= p < owner0.list_own.list.len() implies frame_own.slot_index != meta_to_index(
1252                owner0.list_own.list[p].slot_vaddr,
1253            ) by {
1254                lemma_insert_before_slot_distinct(
1255                    owner0.list_own,
1256                    regions0,
1257                    frame_own.slot_index,
1258                    nn,
1259                );
1260            }
1261        }
1262
1263        let frame_ptr = ReprPtr::<MetaSlotStorage, Link<M>>::from_pptr(
1264            PPtr::<MetaSlotStorage>::from_addr(frame.ptr.addr()),
1265        );
1266
1267        if let Some(current) = self.current {
1268            proof_decl!{
1269                let ghost idx = meta_to_index(current.addr());
1270                let tracked points_to = regions.slots.tracked_borrow(idx);
1271                let tracked metadata_perms =
1272                    owner.list_own.metadata_perms.tracked_borrow(owner.index);
1273            }
1274
1275            // Read current's prev pointer.
1276            let opt_prev_link: Option<ReprPtr<MetaSlotStorage, Link<M>>> = borrow_meta(
1277                current,
1278                Tracked(points_to),
1279                Tracked(metadata_perms),
1280            ).prev;
1281
1282            if let Some(prev_link) = opt_prev_link {
1283                let prev = prev_link;
1284
1285                (#[verus_spec(with Tracked(frame_own))]
1286                frame.meta_mut()).prev = Some(prev_link);
1287                (#[verus_spec(with Tracked(frame_own))]
1288                frame.meta_mut()).next = Some(current);
1289
1290                let ghost prev_idx = meta_to_index(owner.list_own.list[nn - 1].slot_vaddr);
1291                proof {
1292                    assert(prev_idx != idx) by {
1293                        reveal(LinkedListOwner::relate_region);
1294                    };
1295                }
1296                let tracked prev_points_to = regions.slots.tracked_borrow(prev_idx);
1297                let tracked prev_metadata_perm = owner.list_own.metadata_perms.tracked_borrow_mut(
1298                    nn - 1,
1299                );
1300                let prev_meta = borrow_meta_mut(
1301                    prev,
1302                    Tracked(prev_points_to),
1303                    Tracked(prev_metadata_perm),
1304                );
1305                prev_meta.next = Some(frame_ptr);
1306
1307                let ghost current_idx = meta_to_index(owner.list_own.list[nn].slot_vaddr);
1308                let tracked current_points_to = regions.slots.tracked_borrow(current_idx);
1309                let tracked current_metadata_perm =
1310                    owner.list_own.metadata_perms.tracked_borrow_mut(nn);
1311                let current_meta = borrow_meta_mut(
1312                    current,
1313                    Tracked(current_points_to),
1314                    Tracked(current_metadata_perm),
1315                );
1316                current_meta.prev = Some(frame_ptr);
1317            } else {
1318                (#[verus_spec(with Tracked(frame_own))]
1319                frame.meta_mut()).next = Some(current);
1320
1321                let ghost current_idx = meta_to_index(owner.list_own.list[nn].slot_vaddr);
1322                let tracked current_points_to = regions.slots.tracked_borrow(current_idx);
1323                let tracked current_metadata_perm =
1324                    owner.list_own.metadata_perms.tracked_borrow_mut(nn);
1325                let current_meta = borrow_meta_mut(
1326                    current,
1327                    Tracked(current_points_to),
1328                    Tracked(current_metadata_perm),
1329                );
1330                current_meta.prev = Some(frame_ptr);
1331                self.list.front = Some(frame_ptr);
1332            }
1333        } else {
1334            if let Some(back) = self.list.back {
1335                (#[verus_spec(with Tracked(frame_own))]
1336                frame.meta_mut()).prev = Some(back);
1337
1338                let ghost back_idx = meta_to_index(owner.list_own.list[nn - 1].slot_vaddr);
1339
1340                let tracked back_points_to = regions.slots.tracked_borrow(back_idx);
1341                let tracked back_metadata_perm = owner.list_own.metadata_perms.tracked_borrow_mut(
1342                    nn - 1,
1343                );
1344                let back_meta = borrow_meta_mut(
1345                    back,
1346                    Tracked(back_points_to),
1347                    Tracked(back_metadata_perm),
1348                );
1349                back_meta.next = Some(frame_ptr);
1350                self.list.back = Some(frame_ptr);
1351            } else {
1352                // EMPTY list: just point both ends at the inserted frame.
1353                self.list.front = Some(frame_ptr);
1354                self.list.back = Some(frame_ptr);
1355            }
1356        }
1357
1358        #[verus_spec(with Tracked(&owner.list_own))]
1359        let list_id = self.list.lazy_get_id();
1360
1361        proof {
1362            assert(owner0.list_own.list.len() > 0 ==> list_id == owner0.list_own.list_id);
1363        }
1364        let tracked mut frame_so = regions.slot_owners.tracked_borrow_mut(frame_own.slot_index);
1365        let tracked mut fip = &mut frame_so;
1366        let slot = frame.slot();
1367        slot.in_list.store(Tracked(&mut fip.in_list_perm), list_id);
1368        proof {
1369            assert(regions.inv()) by {
1370                reveal(MetaSlotOwner::storage_perm);
1371                reveal(MetaSlotOwner::vtable_ptr_perm);
1372                reveal(<MetaRegionOwners as Inv>::inv);
1373            };
1374            assert(frame.wf_with_region(*frame_own, *regions));
1375        }
1376
1377        #[verus_spec(with
1378            => Tracked(frame_metadata_perm)
1379        )]
1380        let _ = frame.into_raw();
1381
1382        self.list.size += 1;
1383
1384        proof {
1385            let ghost insert_index = owner.index;
1386            let ghost slot_vaddr = frame_own.meta_own.slot_vaddr;
1387            let tracked list_entry = LinkOwner { slot_vaddr, in_list: list_id };
1388            owner.list_own.list.tracked_insert(insert_index, list_entry);
1389            owner.list_own.metadata_perms.tracked_insert(insert_index, frame_metadata_perm);
1390            owner.list_own.list_id = list_id;
1391            owner.index = insert_index + 1;
1392            frame_own.meta_own = LinkOwner { slot_vaddr, in_list: list_id };
1393            let oldl = owner0.list_own;
1394            let nn = owner0.index as int;
1395            let flink = frame_own.meta_own;
1396            let ins = frame_own.slot_index;
1397
1398            assert(owner.list_own.relate_region(*regions)) by {
1399                assert forall|p: int|
1400                    #![trigger
1401                        owner.list_own.insert_old_slot_post_at(
1402                            *regions,
1403                            oldl,
1404                            regions0,
1405                            nn,
1406                            flink,
1407                            p,
1408                        )]
1409                    (0 <= p < oldl.list.len()) implies owner.list_own.insert_old_slot_post_at(
1410                    *regions,
1411                    oldl,
1412                    regions0,
1413                    nn,
1414                    flink,
1415                    p,
1416                ) by {
1417                    reveal(LinkedListOwner::insert_old_slot_post_at);
1418                    assert(oldl.relate_region_at(regions0, p)) by {
1419                        reveal(LinkedListOwner::relate_region);
1420                    };
1421                    oldl.lemma_relate_region_at_facts(regions0, p);
1422                    if nn - 1 >= 0 && nn - 1 < oldl.list.len() && p != nn - 1 {
1423                        assert(meta_to_index(oldl.list[p].slot_vaddr) != meta_to_index(
1424                            oldl.list[nn - 1].slot_vaddr,
1425                        )) by {
1426                            reveal(LinkedListOwner::relate_region);
1427                        };
1428                    }
1429                    if nn >= 0 && nn < oldl.list.len() && p != nn {
1430                        assert(meta_to_index(oldl.list[p].slot_vaddr) != meta_to_index(
1431                            oldl.list[nn].slot_vaddr,
1432                        )) by {
1433                            reveal(LinkedListOwner::relate_region);
1434                        };
1435                    }
1436                }
1437
1438                LinkedListOwner::lemma_insert_preserves_relate_region(
1439                    oldl,
1440                    regions0,
1441                    owner.list_own,
1442                    *regions,
1443                    nn,
1444                    flink,
1445                );
1446            };
1447
1448            owner0.insert_owner_spec_implies_model_spec(flink, *owner);
1449        }
1450    }
1451
1452    /// Provides a reference to the linked list.
1453    pub fn as_list(&self) -> &LinkedList<M> {
1454        self.list
1455    }
1456}
1457
1458impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> LinkedList<M> {
1459    /// Releases every frame owned by the list.
1460    ///
1461    /// # Verified Properties
1462    /// Requires matching list ownership and region permissions, with every list
1463    /// frame uniquely owned and absent from page tables.
1464    /// Empties the list owner, preserves the region invariant, and leaves unrelated
1465    /// frames' usage, metadata addresses, and page-table ownership unchanged.
1466    #[verifier::spinoff_prover]
1467    pub fn drop(
1468        mut self,
1469        Tracked(owner): Tracked<&mut LinkedListOwner<M>>,
1470        Tracked(regions): Tracked<&mut MetaRegionOwners>,
1471    )
1472        requires
1473            self.wf(*old(owner)),
1474            old(owner).inv(),
1475            old(regions).inv(),
1476            forall|i: int|
1477                #![trigger old(owner).list[i]]
1478                0 <= i < old(owner).list.len() ==> {
1479                    let idx = meta_to_index(old(owner).list[i].slot_vaddr);
1480                    &&& old(regions).contains(idx)
1481                    &&& old(regions).ref_count(idx) == REF_COUNT_UNIQUE
1482                    &&& old(regions).slot_owners[idx].paths_in_pt.is_empty()
1483                },
1484            forall|i: int, j: int|
1485                #![trigger old(owner).list[i], old(owner).list[j]]
1486                0 <= i < j < old(owner).list.len() ==> meta_to_index(old(owner).list[i].slot_vaddr)
1487                    != meta_to_index(old(owner).list[j].slot_vaddr),
1488            old(owner).relate_region(*old(regions)),
1489        ensures
1490            final(owner).list.len() == 0,
1491            forall|idx: int|
1492                #![trigger final(regions).slot_owners[idx]]
1493                (forall|i: int|
1494                    #![trigger old(owner).list[i]]
1495                    0 <= i < old(owner).list.len() ==> idx != meta_to_index(
1496                        old(owner).list[i].slot_vaddr,
1497                    )) ==> {
1498                    &&& final(regions).slot_owners[idx].usage == old(regions).slot_owners[idx].usage
1499                    &&& final(regions).slot_owners[idx].slot_vaddr == old(
1500                        regions,
1501                    ).slot_owners[idx].slot_vaddr
1502                    &&& final(regions).slot_owners[idx].paths_in_pt == old(
1503                        regions,
1504                    ).slot_owners[idx].paths_in_pt
1505                },
1506            final(regions).slots.dom() =~= old(regions).slots.dom(),
1507            final(regions).inv(),
1508    {
1509        proof_decl! {
1510            let tracked mut list_own: LinkedListOwner<M>;
1511        }
1512        let ghost original_list = owner.list;
1513        let ghost original_list_id = owner.list_id;
1514        let ghost n = original_list.len();
1515        let ghost original_regions = *regions;
1516        proof {
1517            list_own = LinkedListOwner::<M>::tracked_take(owner);
1518        }
1519
1520        let tracked mut cursor_own = CursorOwner::tracked_front_owner(list_own);
1521        let mut cursor = self.cursor_front_mut();
1522
1523        proof {
1524            if n > 0 {
1525                cursor_own.list_own.lemma_relate_region_at_index(*regions, 0);
1526                cursor_own.list_own.lemma_relate_region_at_index(*regions, n - 1);
1527                cursor_own.list_own.lemma_relate_region_at_facts(*regions, 0);
1528                cursor_own.list_own.lemma_relate_region_at_facts(*regions, n - 1);
1529            }
1530        }
1531
1532        let ghost mut k: int = 0;
1533
1534        loop
1535            invariant_except_break
1536                cursor.wf_region(cursor_own, *regions),
1537                cursor.current.is_some() <==> k < n,
1538            invariant
1539                cursor_own.wf_with_region(*regions),
1540                cursor_own.list_own.list_id == original_list_id,
1541                cursor_own.index == 0,
1542                regions.inv(),
1543                cursor_own.list_own.list.len() == n - k,
1544                0 <= k <= n,
1545                // The remaining list is a suffix of the original
1546                forall|j: int|
1547                    #![trigger cursor_own.list_own.list[j]]
1548                    0 <= j < n - k ==> cursor_own.list_own.list[j] == original_list[j + k],
1549                // slots values inside the original_list.
1550                forall|idx: int|
1551                    #![trigger regions.slot_owners[idx]]
1552                    (forall|j: int|
1553                        #![trigger original_list[j]]
1554                        0 <= j < n ==> idx != meta_to_index(original_list[j].slot_vaddr)) ==> {
1555                        &&& regions.slot_owners[idx].usage
1556                            == original_regions.slot_owners[idx].usage
1557                        &&& regions.slot_owners[idx].slot_vaddr
1558                            == original_regions.slot_owners[idx].slot_vaddr
1559                        &&& regions.slot_owners[idx].paths_in_pt
1560                            == original_regions.slot_owners[idx].paths_in_pt
1561                    },
1562                regions.slots.dom() == original_regions.slots.dom(),
1563                forall|j: int|
1564                    #![trigger original_list[j]]
1565                    k <= j < n ==> {
1566                        let idx = meta_to_index(original_list[j].slot_vaddr);
1567                        &&& regions.slot_owners[idx].paths_in_pt
1568                            == original_regions.slot_owners[idx].paths_in_pt
1569                    },
1570                // Each remaining element's slot is in slot_owners
1571                forall|j: int|
1572                    #![trigger original_list[j]]
1573                    k <= j < n ==> regions.contains(meta_to_index(original_list[j].slot_vaddr)),
1574                forall|i: int, j: int|
1575                    #![trigger original_list[i], original_list[j]]
1576                    0 <= i < j < n ==> meta_to_index(original_list[i].slot_vaddr) != meta_to_index(
1577                        original_list[j].slot_vaddr,
1578                    ),
1579                forall|j: int|
1580                    #![trigger original_list[j]]
1581                    0 <= j < n ==> {
1582                        let idx = meta_to_index(original_list[j].slot_vaddr);
1583                        &&& original_regions.contains(idx)
1584                        &&& original_regions.slot_owners[idx].paths_in_pt.is_empty()
1585                        &&& original_regions.ref_count(idx) == REF_COUNT_UNIQUE
1586                    },
1587            ensures
1588                k == n,
1589                cursor_own.list_own.list.len() == 0,
1590            decreases n - k,
1591        {
1592            #[verus_spec(with Tracked(regions), Tracked(&mut cursor_own) => Tracked(returned_owner))]
1593            let entry = cursor.take_current();
1594
1595            if let Some(current) = entry {
1596                let mut frame = current;
1597                let tracked frame_own = returned_owner.tracked_unwrap();
1598                let ghost regions_pre_drop = *regions;
1599
1600                // Drop the frame, returning its slot to regions
1601                #[verus_spec(with Tracked(frame_own), Tracked(regions))]
1602                frame.drop();
1603
1604                proof {
1605                    assert forall|i: int|
1606                        #![trigger cursor_own.list_own.list[i]]
1607                        0 <= i < cursor_own.list_own.list.len() implies ({
1608                        let idx = meta_to_index(cursor_own.list_own.list[i].slot_vaddr);
1609                        &&& regions.contains(idx)
1610                        &&& regions.slot_owners[idx] == regions_pre_drop.slot_owners[idx]
1611                    }) by {
1612                        let idx = meta_to_index(cursor_own.list_own.list[i].slot_vaddr);
1613                        assert(cursor_own.list_own.list[i] == original_list[i + k + 1]);
1614
1615                        cursor_own.list_own.lemma_relate_region_at_index(regions_pre_drop, i);
1616                        cursor_own.list_own.lemma_relate_region_at_facts(regions_pre_drop, i);
1617                    };
1618                    cursor_own.list_own.lemma_relate_region_preserved_external_change(
1619                        regions_pre_drop,
1620                        *regions,
1621                    );
1622
1623                    assert forall|j: int|
1624                        #![trigger cursor_own.list_own.list[j]]
1625                        0 <= j < n - k - 1 implies cursor_own.list_own.list[j] == original_list[j
1626                        + k + 1] by {};
1627
1628                    k = k + 1;
1629                }
1630            } else {
1631                break;
1632            }
1633        }
1634
1635        // Restore the list owner from the cursor's final (empty) list.
1636        proof {
1637            let tracked mut final_list_own = cursor_own.list_own;
1638            vstd::modes::tracked_swap(owner, &mut final_list_own);
1639            final_list_own.tracked_destroy_empty();
1640        }
1641    }
1642}
1643
1644// SAFETY: `Link<M>` is `Send` and `Sync` if `M` is `Send` and `Sync` because
1645// we only access these unsafe cells when the frame is not shared. This is
1646// enforced by `UniqueFrame`.
1647// #[verifier::external]
1648// unsafe impl<M> Send for LinkedList<M> where Link<M>: AnyFrameMeta {}
1649// #[verifier::external]
1650// unsafe impl<M> Sync for LinkedList<M> where Link<M>: AnyFrameMeta {}
1651/// A link in the linked list.
1652pub struct Link<M: AnyFrameMeta + Repr<MetaSlotSmall>> {
1653    pub next: Option<ReprPtr<MetaSlotStorage, Link<M>>>,
1654    pub prev: Option<ReprPtr<MetaSlotStorage, Link<M>>>,
1655    pub meta: M,
1656}
1657
1658impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> Deref for Link<M> {
1659    type Target = M;
1660
1661    fn deref(&self) -> &Self::Target {
1662        &self.meta
1663    }
1664}
1665
1666impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> DerefMut for Link<M> {
1667    fn deref_mut(&mut self) -> &mut Self::Target {
1668        &mut self.meta
1669    }
1670}
1671
1672impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> Link<M> {
1673    /// Creates a new linked list metadata.
1674    pub const fn new(meta: M) -> Self {
1675        Self { next: None, prev: None, meta }
1676    }
1677}
1678
1679// SAFETY: If `M::on_drop` reads the page using the provided `VmReader`,
1680// the safety is upheld by the one who implements `AnyFrameMeta` for `M`.
1681unsafe impl<M: AnyFrameMeta + Repr<MetaSlotSmall>> AnyFrameMeta for Link<M> {
1682    open spec fn on_drop_pre(
1683        &self,
1684        reader: crate::mm::VmReader<'_, crate::mm::Infallible>,
1685        regions: MetaRegionOwners,
1686        vm_io_owner: crate::specs::mm::io::VmIoOwner,
1687    ) -> bool {
1688        self.meta.on_drop_pre(reader, regions, vm_io_owner)
1689    }
1690
1691    fn on_drop(
1692        &mut self,
1693        reader: &mut crate::mm::VmReader<crate::mm::Infallible>,
1694        regions: Tracked<&mut MetaRegionOwners>,
1695        vm_io_owner: Tracked<&mut crate::specs::mm::io::VmIoOwner>,
1696    ) {
1697        self.meta.on_drop(reader, regions, vm_io_owner);
1698    }
1699
1700    fn is_untyped(&self) -> bool {
1701        self.meta.is_untyped()
1702    }
1703
1704    uninterp spec fn vtable_ptr(&self) -> usize;
1705}
1706
1707} // verus!