Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 12 additions & 4 deletions DESIGN.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ guest's hardware writes included, so the runtime's executions from `w0` /
`w1` are serializable (`w0_serializable_impl`, `w1_serializable_impl`),
from four memory-model and IPI premises. `cargo xtask gate` checks the x86_64
extraction; the AArch64 one is extracted and checked on its own
(`lake build Fl4ProofsA64`). AArch64 P3 Stages 3 and 4 prove the syscall
kernel-entry top (`kernelEntry_recGA`) over the CNode, VSpace (incl. the Stage-2 and high-window maps and the T2 unmap shrink),
SchedContext, TCB (installs, SetSpace, Configure, SetSchedParams, SetTimer, Read-, Write- and CopyRegisters), IPC, IRQ, Domain, VCPU and Untyped (Retype, TCB creation and the non-preempting reset) groups,
(`lake build Fl4ProofsA64`). AArch64 P3 Stages 3–5 prove the syscall
kernel-entry top (`kernelEntry_recGA`) over the CNode, VSpace (incl. the Stage-2 and high-window maps, the T2 unmap shrink and the stale-ASID unmap, ASIDControl MakePool and DeriveSubframe),
SchedContext, TCB (installs, SetSpace, Configure, SetSchedParams, SetTimer, Read-, Write- and CopyRegisters), IPC, IRQ, Domain, VCPU and Untyped (Retype, TCB creation and reset, preempted or not) groups,
the receive family and combined syscalls, the preempted exit, the interrupt entry (`kernelEntryIrq_recGA`) and the VM-exit entries `runExit` / `runVppi`;
the preempting Untyped reset, a device Untyped, DeriveSubframe, ASIDControl MakePool, the Stage-1 / high-window shrink, the guest-resume `finish` and the other guest entries are declared limits,
a device Untyped, the Stage-1 / high-window shrink, the guest-resume `finish` and the other guest entries are declared limits,
`ArchSwFA` is single-core (the SMP stage restates it per core), and
the premises of every top are shown jointly satisfiable (`wit_send_nonvacuous`, `wit_recv_nonvacuous`, `wit_comb_nonvacuous`, `wit_runexit_nonvacuous` / `wit_runvppi_nonvacuous` (a VCPU-less exit), `wit_irq_nonvacuous`, under the witness-world hypotheses `OpaqueWA` and the IRQ-oracle fact of each; the Untyped arm has a premise-level witness) (DESIGN.md §9). P3 also covers the x86_64 VCPU/EPT
the premises of every top are shown jointly satisfiable (`wit_send_nonvacuous`, `wit_ut_nonvacuous` (an Untyped Retype into the root CNode), `wit_recv_nonvacuous`, `wit_comb_nonvacuous`, `wit_runexit_nonvacuous` / `wit_runvppi_nonvacuous` (a VCPU-less exit), `wit_irq_nonvacuous`, under the witness-world hypotheses `OpaqueWA` and the IRQ-oracle fact of each) (DESIGN.md §9); the Stage-5 arms (MakePool, DeriveSubframe, the Stage-2 / high-window VSpace arms) have premise-level witnesses at most, not end-to-end ones (the Untyped chunk-loop resets are premise-level only; `ptUnmapT2Stale` has no arm witness). P3 also covers the x86_64 VCPU/EPT
extension on a joint VM state (`VmEptState`): retype and untyped, the EPT
syscalls through the dispatcher, the VCPU report and detach, the IO-port
cap's owner, revoke and delete, capability delete of every cap
Expand Down
69 changes: 69 additions & 0 deletions proofs/Fl4ProofsA64.lean
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ import Fl4ProofsA64.P1.MdbTreeF
import Fl4ProofsA64.P1.MdbTreeR
import Fl4ProofsA64.P1.MdbTreeL
import Fl4ProofsA64.P1.MdbTreeD
import Fl4ProofsA64.P1.MdbRoot
import Fl4ProofsA64.P1.MdbTreeS
import Fl4ProofsA64.P1.MdbTreeK
import Fl4ProofsA64.P1.MdbTreeU
Expand Down Expand Up @@ -909,6 +910,18 @@ import Fl4ProofsA64.P3.InsertA
import Fl4ProofsA64.P3.JEntW0A
import Fl4ProofsA64.P3.JBootW1A
import Fl4ProofsA64.P3.JBootW1SA
import Fl4ProofsA64.P3.VsUniqShrinkA
import Fl4ProofsA64.P3.VsUniqLinkA
import Fl4ProofsA64.P3.VsUniqGrowA
import Fl4ProofsA64.P3.VsWalkHiA
import Fl4ProofsA64.P3.VsWalkS2A
import Fl4ProofsA64.P3.VsUniqLinkS2A
import Fl4ProofsA64.P3.VsS2MapVsuA
import Fl4ProofsA64.P3.VsS2ArmVsuA
import Fl4ProofsA64.P3.VsHiMapVsuA
import Fl4ProofsA64.P3.VsWalkSlotA
import Fl4ProofsA64.P3.VsPtMapVsuA
import Fl4ProofsA64.P3.VsW1A
import Fl4ProofsA64.P3.JEntW1A
import Fl4ProofsA64.P3.InsDisA
import Fl4ProofsA64.P3.LookupA
Expand Down Expand Up @@ -1194,6 +1207,8 @@ import Fl4ProofsA64.P3.VsMakePoolA
import Fl4ProofsA64.P3.PtCapBootA
import Fl4ProofsA64.P3.ExtVsPerfA
import Fl4ProofsA64.P3.ExtVsDefA
import Fl4ProofsA64.P3.VsUClosedA
import Fl4ProofsA64.P3.VsUniqA
import Fl4ProofsA64.P3.ScRelA
import Fl4ProofsA64.P3.ScSpecA
import Fl4ProofsA64.P3.ScRefillA
Expand Down Expand Up @@ -1736,6 +1751,17 @@ import Fl4ProofsA64.P1.S1aCReplyTl
import Fl4ProofsA64.P1.S1aCReplyM
import Fl4ProofsA64.P1.S1aCReplyA
import Fl4ProofsA64.P1.S1aCAll
import Fl4ProofsA64.P1.S1aSubTree
import Fl4ProofsA64.P1.S1aSubIns
import Fl4ProofsA64.P1.S1aSubDest
import Fl4ProofsA64.P1.S1aSubRun
import Fl4ProofsA64.P1.S1aSubLoop
import Fl4ProofsA64.P1.S1aSubGeo
import Fl4ProofsA64.P1.S1aSubArm
import Fl4ProofsA64.P1.S1aSubTop
import Fl4ProofsA64.P1.S1aSubFin
import Fl4ProofsA64.P1.MdbSubFrA
import Fl4ProofsA64.P1.MdbInvSubA
import Fl4ProofsA64.P1.S1aBootDel0
import Fl4ProofsA64.P1.S1aBootDel1
import Fl4ProofsA64.P1.S1aCStepD
Expand All @@ -1760,6 +1786,12 @@ import Fl4ProofsA64.P3.Stage3ArmCnMoveA
import Fl4ProofsA64.P3.Stage3ArmCnRotA
import Fl4ProofsA64.P3.Stage3ArmCnSwapA
import Fl4ProofsA64.P3.Stage3CnInsA
import Fl4ProofsA64.P3.Stage3CnInsSubA
import Fl4ProofsA64.P3.FrSubframeJ5A
import Fl4ProofsA64.P3.CapInsSpecQA
import Fl4ProofsA64.P3.Stage3CapDerivCnA
import Fl4ProofsA64.P3.Stage3ArmSubframeA
import Fl4ProofsA64.P3.Stage3T3ArmSubA
import Fl4ProofsA64.P3.Stage3ArmCnCopyA
import Fl4ProofsA64.P3.Stage3Rec5A
import Fl4ProofsA64.P3.Stage3SchedValidA
Expand Down Expand Up @@ -2018,6 +2050,14 @@ import Fl4ProofsA64.P3.UtRec6KeepA
import Fl4ProofsA64.P3.UtVcInitA
import Fl4ProofsA64.P3.UtApRec6A
import Fl4ProofsA64.P3.UtVcTrA
import Fl4ProofsA64.P3.UtPreCarryA
import Fl4ProofsA64.P3.UtPreDecA
import Fl4ProofsA64.P3.UtPreExitA
import Fl4ProofsA64.P3.Stage3UtPreArmA
import Fl4ProofsA64.P3.Stage3DispUtPreA
import Fl4ProofsA64.P3.UtBigCarryA
import Fl4ProofsA64.P3.UtBigDecA
import Fl4ProofsA64.P3.Stage3UtBigArmA
import Fl4ProofsA64.P3.Stage3IpcGlueA
import Fl4ProofsA64.P3.Stage3SignalIdleA
import Fl4ProofsA64.P3.Stage3TcbWordsA
Expand Down Expand Up @@ -2384,11 +2424,16 @@ import Fl4ProofsA64.P3.A64Wit2bNatA
import Fl4ProofsA64.P3.A64Wit2bBodyA
import Fl4ProofsA64.P3.A64Wit2PlatA
import Fl4ProofsA64.P3.A64WitW1A
import Fl4ProofsA64.P3.A64WitMsgA
import Fl4ProofsA64.P3.A64WitStA
import Fl4ProofsA64.P3.A64WitJA
import Fl4ProofsA64.P3.A64WitRecA
import Fl4ProofsA64.P3.A64WitSyscA
import Fl4ProofsA64.P3.A64WitReadA
import Fl4ProofsA64.P3.A64WitCopyA
import Fl4ProofsA64.P3.A64WitUtMsgA
import Fl4ProofsA64.P3.A64WitUtScopeA
import Fl4ProofsA64.P3.A64WitUtTopA
import Fl4ProofsA64.P3.A64WitTopA
import Fl4ProofsA64.P3.A64Wit2BudgetA
import Fl4ProofsA64.P3.A64Wit2EntryA
Expand All @@ -2412,6 +2457,13 @@ import Fl4ProofsA64.P3.A64ArchSwH
import Fl4ProofsA64.P3.Stage3KEntryIrqBodyA
import Fl4ProofsA64.P3.Stage3KEntryIrqTopA
import Fl4ProofsA64.P3.A64WitIrqA
import Fl4ProofsA64.P3.A64WitVsLayA
import Fl4ProofsA64.P3.A64WitVsArchA
import Fl4ProofsA64.P3.A64WitVsStA
import Fl4ProofsA64.P3.A64WitVsExtA
import Fl4ProofsA64.P3.A64WitVsPremA
import Fl4ProofsA64.P3.A64WitVsArmsA
import Fl4ProofsA64.P3.A64WitSubA
import Fl4ProofsA64.P3.Stage3TcbReadRegsA
import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsA
import Fl4ProofsA64.P3.TcbInvokeReadCallFineA
Expand All @@ -2420,3 +2472,20 @@ import Fl4ProofsA64.P3.Stage3TcbReadCallA
import Fl4ProofsA64.P3.Stage3SuspOffQA
import Fl4ProofsA64.P3.Stage3TcbReadRegsSuspA
import Fl4ProofsA64.P3.Stage3TcbReadCallSuspA
import Fl4ProofsA64.P3.Stage3PoolCapsA
import Fl4ProofsA64.P3.Stage3PoolHeapA
import Fl4ProofsA64.P3.Stage3PoolSysA
import Fl4ProofsA64.P3.Stage3PoolSpecA
import Fl4ProofsA64.P3.Stage3PoolIpcA
import Fl4ProofsA64.P3.Stage3PoolCoreA
import Fl4ProofsA64.P3.Stage3PoolShapeA
import Fl4ProofsA64.P3.Stage3PoolMemA
import Fl4ProofsA64.P3.Stage3PoolJ7A
import Fl4ProofsA64.P3.Stage3PoolSysEndA
import Fl4ProofsA64.P3.Stage3PoolRecA
import Fl4ProofsA64.P3.Stage3PoolTopA
import Fl4ProofsA64.P3.Stage3ArmPoolA
import Fl4ProofsA64.P3.Stage3PoolEndA
import Fl4ProofsA64.P3.Stage3PoolFinA
import Fl4ProofsA64.P3.Stage3PoolJ5A
import Fl4ProofsA64.P3.Stage3T3PoolA
10 changes: 8 additions & 2 deletions proofs/Fl4ProofsA64/P1/BootW1Items.lean
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,17 @@ section caps
variable (P : BootLay1 kb ib nc)
include P

/-- **The exact objects of the `w1` frames** (boot: every frame is exactly its heap object). -/
theorem w1_frameObj {y : U64} (hy : y ∈ OS1) {ptr : U64} {size : capability.FrameSize} {rights : U64} {x1 x2 : Bool} {x3 x4 : U64}
(hc : capA bst S1 y = .Frame ptr size rights false x1 x2 x3 x4) {bits : U64} (hb : size.bits = ok bits) :
H1 ptr = some (.other bits.val) := by
obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc
rw [small_bits hb]; exact frPg_obj hF

/-- **`FrameOK` at `w1`.** -/
theorem w1_frameOK : FrameOK bst H1 OS1 S1 := by
intro y hy ptr size rights x1 x2 x3 x4 hc bits hb
obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc
rw [small_bits hb]; exact frPg_obj hF
exact FrAt.ofObj (w1_frameObj P hy hc hb)

/-- **`UserOffFr` at `w1`**: the frame words are off the RAM untyped. -/
theorem w1_userOffFr : UserOffFr bst OS1 S1 := by
Expand Down
2 changes: 1 addition & 1 deletion proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ theorem RunBuf.frUb {Ub' : Set U64} {s : S} {y : U64} (hH : HeapOK H) (hF : Fram
subst hdev
have hcap0 : capA st s (sbWordA y) = .Frame ptr size rights false x1 x2 x3 x4 :=
okinj ((capA_eq s _).symm.trans hcap)
have hp : H ptr = some (.other bits.val) := hF _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits
have hp : FrAt H ptr bits := hF _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits
intro i hi
obtain ⟨hal, hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi
exact ⟨hU i hi, hf _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal hin.1 hin.2⟩
Expand Down
2 changes: 1 addition & 1 deletion proofs/Fl4ProofsA64/P1/MdbDropR.lean
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ theorem SysL.dropR {s s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {x p s
· rcases hO.disj y hy.1 x P.src hyx with g | g <;> omega
have hf : RstF st (OffR p.val (p.val + 2 ^ sb.val) OS) x s s' :=
⟨w.1, w.2.1, kc, fun y hy => ⟨lk y hy _ (Or.inl rfl), lk y hy _ (Or.inr rfl)⟩⟩
obtain ⟨h1, h2, h3⟩ := RstF.bn hO B.sys.stz B.sys.fr B.sys.cz P.src hcx hnd hf hcx' hi hUZ
obtain ⟨h1, h2, h3⟩ := RstF.bn hO B.sys.stz B.sys.fr B.sys.cz P.src hcx hnd (R.ur.rin R.src R.cap) hf hcx' hi hUZ
(not_islN_region q hnode)
have hR1 : UtRV st (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) (OffR p.val (p.val + 2 ^ sb.val) OS) s' := by
refine UtRV.mono (H := H) (fun y hy => ?_) fun q k hq => (Heap.drop_eq_some.1 hq).2
Expand Down
18 changes: 8 additions & 10 deletions proofs/Fl4ProofsA64/P1/MdbFpuL.lean
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ theorem frame_word (hH : HeapOK H) {ptr : U64} {z : Nat} (hp : H ptr = some (.ot

/-- **The 65 words from `ptr + offset` of a frame object** (module docstring): words of `Ω \ Sg` inside
`[ptr, ptr + 2^bits)`. -/
theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : H ptr = some (.other bits.val))
theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : FrAt H ptr bits)
(h12 : 12 ≤ bits.val) (ho : offset.val % 64 = 0) (hob : offset.val + 520 ≤ 2 ^ bits.val) :
Aligned (wa ptr offset) ∧ (wa ptr offset).val + 8 * (65#u64 : U64).val ≤ 2 ^ 64 ∧
∀ b, CWW (wa ptr offset) 65#u64 b → (ptr.val ≤ b.val ∧ b.val < ptr.val + 2 ^ bits.val) ∧
b ∈ H.omega ∧ b ∉ H.frame := by
have hf := hH.fits ptr _ hp
have hal := hH.align ptr _ hp
simp only [HKind.bits] at hf hal
have hf := hp.fits hH
have hal := hp.al hH
have h8 : 8 ∣ 2 ^ bits.val := by
have : 2 ^ bits.val = 2 ^ 3 * 2 ^ (bits.val - 3) := by rw [← Nat.pow_add]; congr 1; omega
rw [this]; exact Dvd.dvd.mul_right (by norm_num) _
Expand All @@ -98,12 +97,12 @@ theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : H ptr = some (
rw [h65] at hk
rw [hfv] at e
have hin : ptr.val ≤ b.val ∧ b.val < ptr.val + 2 ^ bits.val := by omega
exact ⟨hin, frame_word hH hp (by unfold Aligned; omega) hin⟩
exact ⟨hin, hp.word hH (by unfold Aligned; omega) hin⟩

/-- (A64-S1A gen 29) **The 128 words at a checked offset of a frame object** (the common part of MdbRunQ's
`runBuf_of`, MdbVcStQ's `frU_of` and MdbDelVsZ's `RunBuf.frUb`): each aligned and inside the object. -/
theorem frame_off_words (hH : HeapOK H) {ptr bits sz off : U64} {size : capability.FrameSize}
(hp : H ptr = some (.other bits.val)) (hbits : capability.FrameSize.bits size = ok bits)
(hp : FrAt H ptr bits) (hbits : capability.FrameSize.bits size = ok bits)
(hsz : (1#u64 <<< (bits &&& 63#u64) : Result U64) = ok sz)
(h63 : (off &&& 63#u64) = 0#u64) (hlt : off.val < sz.val) (hge : 1024 ≤ sz.val - off.val)
{i : U64} (hi : i.val < 128) :
Expand All @@ -122,8 +121,7 @@ theorem frame_off_words (hH : HeapOK H) {ptr bits sz off : U64} {size : capabili
simpa using e
rw [hszv] at hlt hge
obtain ⟨hal, -, -⟩ := frame_words hH hp hb64.2 ho (by omega)
have hf := hH.fits ptr _ hp
simp only [HKind.bits] at hf
have hf := hp.fits hH
have hpo : (wa ptr off).val = ptr.val + off.val := by
simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega
have hv : (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val = ptr.val + off.val + 8 * i.val := by
Expand Down Expand Up @@ -289,7 +287,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le
have hcap0 : capA st s x = .Frame ptr sz r false m ep asid va := by rw [← k1.capA hxO]; exact hcp
have h12 : 12 ≤ bits.val := by
cases sz <;> simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> simp
have hH : H ptr = some (.other bits.val) := B.sys.fr x hxO ptr sz r m ep asid va hcap0 bits hb
have hH : FrAt H ptr bits := B.sys.fr x hxO ptr sz r m ep asid va hcap0 bits hb
have hFo := (B.fo x hxO ptr sz r m ep asid va hcap0 bits hb).1
obtain ⟨hfa, hff, hW⟩ := frame_words P.heap hH h12 ho hob
-- the restart
Expand Down Expand Up @@ -322,7 +320,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le
refine WP.spec_bind (tcb.copy_words_loop.w s2 _ _ _ 0#u64 hfa hff) fun s3 w3 => ?_
have hBo : ∀ b, CWW (wa ptr off) 65#u64 b → FrBw H OS b ∧ FrCw st OS s b := fun b hw' => by
have hin := (hW b hw').1
refine ⟨⟨(hW b hw').2, ⟨ptr, bits.val, hH, h12, hin⟩, fun y hy g => ?_⟩,
refine ⟨⟨(hW b hw').2, hH.frBw h12 hin, fun y hy g => ?_⟩,
x, hxO, ptr, sz, r, m, ep, asid, va, bits, hcap0, hb, hin⟩
rcases hFo y hy with g' | g' <;> omega
have X3 := SysL.cwO P2 h2.bxi run2 w3 (fun b hb => (hW b hb).2)
Expand Down
72 changes: 52 additions & 20 deletions proofs/Fl4ProofsA64/P1/MdbFrC.lean
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,35 @@ theorem frame_range {ptr r x3 x4 bits : U64} {size : capability.FrameSize} {x1 x
· rw [Nat.mod_eq_of_lt hw]; omega
· rw [Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by omega)] at hr; omega

/-- **l4v `valid_untyped`** (Untyped_AI): every heap object meeting the region `[lo, hi)` lies inside it. -/
def RegionIn (H : Heap) (lo hi : Nat) : Prop :=
∀ q k, H q = some k → MeetsR lo hi q.val (q.val + 2 ^ k.bits) → lo ≤ q.val ∧ q.val + 2 ^ k.bits ≤ hi

/-- A frame range survives the drop of a region if every `.other` object containing it is kept. -/
theorem FrAt.drop {H : Heap} {ptr bits : U64} {R : U64 → Prop} (h : FrAt H ptr bits)
(hD : ∀ b k, H b = some (.other k) → b.val ≤ ptr.val → ptr.val + 2 ^ bits.val ≤ b.val + 2 ^ k → ¬ R b) :
FrAt (H.drop R) ptr bits := by
obtain ⟨b, k, hb, h1, h2, h3⟩ := FrAt.def.1 h
exact FrAt.def.2 ⟨b, k, Heap.drop_eq_some.2 ⟨hD b k hb h1 h2, hb⟩, h1, h2, h3⟩

/-- The converse: a frame range in the dropped heap lies in a kept object, so it is off the region. -/
theorem FrAt.undrop {H : Heap} {ptr bits : U64} {lo hi : Nat} (h : FrAt (H.drop (RegionD H lo hi)) ptr bits) :
FrAt H ptr bits ∧ ¬ MeetsR lo hi ptr.val (ptr.val + 2 ^ bits.val) := by
obtain ⟨b, k, hb, h1, h2, h3⟩ := FrAt.def.1 h
obtain ⟨hn, hb'⟩ := Heap.drop_eq_some.1 hb
refine ⟨FrAt.def.2 ⟨b, k, hb', h1, h2, h3⟩, fun hm => hn ?_⟩
unfold RegionD
rw [hb']
simp only [Option.elim, HKind.bits]
unfold MeetsR at hm ⊢
omega

/-- **`FrameOK` over the dropped heap after the reset** (module docstring): the kept slots other than `u` keep their
caps, `u` holds an `Untyped`, `u` has no MDB children. -/
caps, `u` holds an `Untyped`, `u` has no MDB children; `hRin` (l4v `valid_untyped`, `UtRV.rin`): every heap object
meeting the region lies in it, so the object containing a kept frame is kept. -/
theorem FrameOK.reset {s s' : S} (hF : FrameOK st H OS s) {par : U64 → Option U64} (hU : UtInvA st OS par s)
{u p b i : U64} {d : Bool} (hu : u ∈ OS) (hcu : capA st s u = .Untyped p b i d) (hnd : ∀ y, ¬ Mdb.Desc par y u)
(hRin : RegionIn H p.val (p.val + 2 ^ b.val))
{OS' : Set U64} (hs : OS' ⊆ OS) {i' : U64} (hcu' : capA st s' u = .Untyped p b i' d)
(hk : ∀ y ∈ OS', y ≠ u → capA st s' y = capA st s y) :
FrameOK st (H.drop (RegionD H p.val (p.val + 2 ^ b.val))) OS' s' := by
Expand All @@ -147,32 +172,39 @@ theorem FrameOK.reset {s s' : S} (hF : FrameOK st H OS s) {par : U64 → Option
· rw [e, hcu'] at hc; cases hc
rw [hk y hy e] at hc
have hq := hF y (hs hy) ptr size rights x1 x2 x3 x4 hc bits hbits
refine Heap.drop_eq_some.2 ⟨fun hD => ?_, hq⟩
unfold RegionD MeetsR at hD
rw [hq] at hD
simp only [Option.elim, show (HKind.other bits.val).bits = bits.val from rfl] at hD
have hp : physA (capA st s y) = true := by
have h := physA_eq (.Frame ptr size rights false x1 x2 x3 x4)
simp only [objects.cap_is_physical] at h
rw [hc]; exact (okinj h).symm
obtain ⟨rb, rt, -⟩ := ut_rangeA (capA_ut_b hcu) (by
have := hU.reg u hu (by rw [hcu]; exact physA_ut _ _ _ _); rwa [hcu] at this)
obtain ⟨fb, ft⟩ := frame_range hbits (by have := hU.reg y (hs hy) hp; rwa [hc] at this)
have hb1 : 1 ≤ 2 ^ b.val := Nat.one_le_two_pow
have hf1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow
have hDj : ¬ DisjA (capA st s y) (capA st s u) := by unfold DisjA; rw [hcu, hc, rb, rt, fb, ft]; omega
rcases hU.drange u hu p b i d hcu y (hs hy) e hp hDj with g | g
· exact hnd y g
· have := hU.anc y u g (by rw [hcu]; rfl)
rw [hc] at this; simp [isUtA] at this
have hoff : ptr.val + 2 ^ bits.val ≤ p.val ∨ p.val + 2 ^ b.val ≤ ptr.val := by
by_contra hmeet
have hp : physA (capA st s y) = true := by
have h := physA_eq (.Frame ptr size rights false x1 x2 x3 x4)
simp only [objects.cap_is_physical] at h
rw [hc]; exact (okinj h).symm
obtain ⟨rb, rt, -⟩ := ut_rangeA (capA_ut_b hcu) (by
have := hU.reg u hu (by rw [hcu]; exact physA_ut _ _ _ _); rwa [hcu] at this)
obtain ⟨fb, ft⟩ := frame_range hbits (by have := hU.reg y (hs hy) hp; rwa [hc] at this)
have hb1 : 1 ≤ 2 ^ b.val := Nat.one_le_two_pow
have hDj : ¬ DisjA (capA st s y) (capA st s u) := by unfold DisjA; rw [hcu, hc, rb, rt, fb, ft]; omega
rcases hU.drange u hu p b i d hcu y (hs hy) e hp hDj with g | g
· exact hnd y g
· have := hU.anc y u g (by rw [hcu]; rfl)
rw [hc] at this; simp [isUtA] at this
refine FrAt.drop hq fun b0 k0 hb0 h1 h2 hD => ?_
have hm : MeetsR p.val (p.val + 2 ^ b.val) b0.val (b0.val + 2 ^ k0) := by
unfold RegionD at hD
rw [hb0] at hD
simpa [Option.elim, HKind.bits] using hD
have hin := hRin b0 _ hb0 (by simpa [HKind.bits] using hm)
simp only [HKind.bits] at hin
omega

/-- **`FrameOK` over the dropped heap and `OffR` at the reset's start** (MdbVUS's `reset_start` form). -/
theorem FrameOK.reset_start {s : S} (hS : MdbST st OS s) (hF : FrameOK st H OS s) {u p b i : U64} {d : Bool}
(hu : u ∈ OS) (hcu : capA st s u = .Untyped p b i d)
(hnd : ∀ G par, TreeA st OS G par s → ∀ y, ¬ Mdb.Desc par y u) :
(hnd : ∀ G par, TreeA st OS G par s → ∀ y, ¬ Mdb.Desc par y u)
(hRin : RegionIn H p.val (p.val + 2 ^ b.val)) :
FrameOK st (H.drop (RegionD H p.val (p.val + 2 ^ b.val))) (OffR p.val (p.val + 2 ^ b.val) OS) s := by
obtain ⟨G, par, hM, -, -, -, -, hTr, hU⟩ := id hS
exact hF.reset hU hu hcu (hnd G par ⟨hM, hTr, hU⟩) OffR.sub hcu fun _ _ _ => rfl
exact hF.reset hU hu hcu (hnd G par ⟨hM, hTr, hU⟩) hRin OffR.sub hcu fun _ _ _ => rfl

end ST
end R
Expand Down
Loading