theory CSpaceInv_AI

lemma cap_insert_iflive:
  "\<lbrace>if_live_then_nonz_cap\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv. if_live_then_nonz_cap\<rbrace>" apply (simp add: cap_insert_def set_untyped_cap_as_full_def) apply (wp get_cap_wp set_cap_cte_wp_at | simp split del: if_split)+ apply (rule new_cap_iflive) apply (wp set_cap_iflive set_cap_cte_wp_at get_cap_wp)+ apply (clarsimp simp: is_cap_simps cte_wp_at_caps_of_state) done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. \<lbrace>if_live_then_nonz_cap\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv. if_live_then_nonz_cap\<rbrace> proof (prove)
goal (1 subgoal):
 1. \<lbrace>if_live_then_nonz_cap\<rbrace> do src_cap <- get_cap src;
old_cap <- get_cap dest;
y <- assert (old_cap = NullCap);
y <- if is_untyped_cap src_cap \<and> is_untyped_cap cap \<and> obj_ref_of src_cap = obj_ref_of cap \<and> cap_bits_untyped src_cap = cap_bits_untyped cap then set_cap (max_free_index_update src_cap) src else return ();
y <- set_cap cap dest;
is_original <- gets is_original_cap;
src_p <- gets (\<lambda>s. cdt s src);
dest_p <- gets (\<lambda>s. cdt s dest);
y <- update_cdt (\<lambda>cdt. cdt(dest := if should_be_parent_of src_cap (is_original src) cap (is_cap_revocable cap src_cap) then Some src else cdt src));
y <- do_extended_op (cap_insert_ext (should_be_parent_of src_cap (is_original src) cap (is_cap_revocable cap src_cap)) src dest src_p dest_p);
set_original dest (is_cap_revocable cap src_cap)
od \<lbrace>\<lambda>rv. if_live_then_nonz_cap\<rbrace> proof (prove)
goal (6 subgoals):
 1. \<And>src_cap x. \<lbrace>?B4 src_cap x () ()\<rbrace> set_cap cap dest \<lbrace>\<lambda>yb. if_live_then_nonz_cap\<rbrace>
 2. \<And>src_cap x y. \<lbrace>?B3 src_cap x y\<rbrace> if is_untyped_cap src_cap \<and> is_untyped_cap cap \<and> obj_ref_of src_cap = obj_ref_of cap \<and> cap_bits_untyped src_cap = cap_bits_untyped cap then set_cap (max_free_index_update src_cap) src else return () \<lbrace>?B4 src_cap x y\<rbrace>
 3. \<And>src_cap x. \<lbrace>?B2 src_cap x\<rbrace> assert (x = NullCap) \<lbrace>?B3 src_cap x\<rbrace>
 4. \<And>src_cap. \<lbrace>?B1 src_cap\<rbrace> get_cap dest \<lbrace>?B2 src_cap\<rbrace>
 5. \<lbrace>?Q\<rbrace> get_cap src \<lbrace>?B1\<rbrace>
 6. \<And>s. if_live_then_nonz_cap s \<Longrightarrow> ?Q s proof (prove)
goal (5 subgoals):
 1. \<And>src_cap x y. \<lbrace>?B3 src_cap x y\<rbrace> if is_untyped_cap src_cap \<and> is_untyped_cap cap \<and> obj_ref_of src_cap = obj_ref_of cap \<and> cap_bits_untyped src_cap = cap_bits_untyped cap then set_cap (max_free_index_update src_cap) src else return () \<lbrace>\<lambda>a. cte_wp_at ((=) NullCap) dest and if_live_then_nonz_cap\<rbrace>
 2. \<And>src_cap x. \<lbrace>?B2 src_cap x\<rbrace> assert (x = NullCap) \<lbrace>?B3 src_cap x\<rbrace>
 3. \<And>src_cap. \<lbrace>?B1 src_cap\<rbrace> get_cap dest \<lbrace>?B2 src_cap\<rbrace>
 4. \<lbrace>?Q\<rbrace> get_cap src \<lbrace>?B1\<rbrace>
 5. \<And>s. if_live_then_nonz_cap s \<Longrightarrow> ?Q s proof (prove)
goal (1 subgoal):
 1. \<And>s. if_live_then_nonz_cap s \<Longrightarrow> \<forall>capa. cte_wp_at ((=) capa) src s \<longrightarrow> (\<forall>capb. cte_wp_at ((=) capb) dest s \<longrightarrow> capb = NullCap \<longrightarrow> (is_untyped_cap capa \<and> is_untyped_cap cap \<and> obj_ref_of capa = obj_ref_of cap \<and> cap_bits_untyped capa = cap_bits_untyped cap \<longrightarrow> ((\<lambda>s. if dest = src then NullCap = max_free_index_update capa else cte_wp_at ((=) NullCap) dest s) and cte_wp_at (\<lambda>_. True) src) s \<and> cte_wp_at (\<lambda>cap'. \<forall>p'\<in>zobj_refs cap' - zobj_refs (max_free_index_update capa). obj_at (Not \<circ> live) p' s) src s \<and> if_live_then_nonz_cap s) \<and> (\<not> (is_untyped_cap capa \<and> is_untyped_cap cap \<and> obj_ref_of capa = obj_ref_of cap \<and> cap_bits_untyped capa = cap_bits_untyped cap) \<longrightarrow> cte_wp_at ((=) NullCap) dest s \<and> if_live_then_nonz_cap s)) proof (prove)
goal:
No subgoals!