~james/split

feat(snapshot): preserve source frames across valid edit traces

commit
c0ba93474c40cb7f3a384ca03d2d11b6ad5133b4 browse tree
parent
86650c76e96e3766ec12a32d552f12520965f9c2
author
james <j@cpl0.zip>
signature
Verified ~james signed with a key registered by ~james
date
2026-06-21 15:43 UTC

2 files changed, +74 −0

ROOT modified

@@ -5,3 +5,4 @@ session Split = HOL +
55 Isolation
66 Execution
77 Protocol
8+ Snapshot

Snapshot.thy added

@@ -0,0 +1,73 @@
1+theory Snapshot
2+ imports Protocol
3+begin
4+
5+definition private_frames :: "nat \<Rightarrow> nat \<Rightarrow> pager \<Rightarrow> bool" where
6+ "private_frames pages slots s \<longleftrightarrow> pages \<le> frontier s \<and>
7+ (\<forall>k<slots. writable s k \<longrightarrow> pages \<le> ptable s k)"
8+
9+lemma initial_private: "private_frames pages slots (initial pages contents)"
10+ by (simp add: private_frames_def)
11+
12+lemma prepare_private:
13+ "private_frames pages slots s \<Longrightarrow> private_frames pages slots (prepare s k)"
14+ by (auto simp: private_frames_def prepare_def split: if_splits)
15+
16+lemma prepared_frame_private:
17+ "private_frames pages slots s \<Longrightarrow> k < slots \<Longrightarrow>
18+ pages \<le> ptable (prepare s k) k"
19+ by (auto simp: private_frames_def prepare_def)
20+
21+lemma store_private:
22+ "private_frames pages slots s \<Longrightarrow> private_frames pages slots (store s k offset byte)"
23+ using prepare_private[of pages slots s k]
24+ by (simp add: private_frames_def)
25+
26+lemma prepare_original:
27+ "private_frames pages slots s \<Longrightarrow> f < pages \<Longrightarrow>
28+ physical (prepare s k) f = physical s f"
29+ by (auto simp: private_frames_def prepare_def detach_def)
30+
31+theorem store_original:
32+ assumes owned: "private_frames pages slots s" and valid: "k < slots" and original: "f < pages"
33+ shows "physical (store s k offset byte) f = physical s f"
34+proof -
35+ have distinct: "f \<noteq> ptable (prepare s k) k"
36+ using prepared_frame_private[OF owned valid] original by arith
37+ have preserved: "physical (prepare s k) f = physical s f"
38+ using prepare_original[OF owned original] .
39+ show ?thesis
40+ using distinct preserved by (simp add: store_def Let_def)
41+qed
42+
43+lemma advance_private:
44+ "private_frames pages slots s \<Longrightarrow> private_frames pages slots (advance s a)"
45+ by (cases a; simp add: store_private)
46+
47+lemma advance_original:
48+ "private_frames pages slots s \<Longrightarrow> valid slots bytes a \<Longrightarrow> f < pages \<Longrightarrow>
49+ physical (advance s a) f = physical s f"
50+ by (cases a; auto intro: store_original)
51+
52+theorem execute_original:
53+ "private_frames pages slots s \<Longrightarrow> list_all (valid slots bytes) actions \<Longrightarrow>
54+ f < pages \<Longrightarrow> physical (execute s actions) f = physical s f"
55+proof (induction actions arbitrary: s)
56+ case Nil
57+ then show ?case by simp
58+next
59+ case (Cons a actions)
60+ have state: "private_frames pages slots (advance s a)"
61+ using Cons.prems by (simp add: advance_private)
62+ have tail: "physical (execute (advance s a) actions) f = physical (advance s a) f"
63+ using Cons.IH[OF state] Cons.prems by simp
64+ show ?case
65+ using tail advance_original Cons.prems by auto
66+qed
67+
68+corollary original_preserved:
69+ "list_all (valid slots bytes) actions \<Longrightarrow> f < pages \<Longrightarrow>
70+ physical (execute (initial pages contents) actions) f = contents f"
71+ using execute_original[OF initial_private] by simp
72+
73+end