theory CSpaceInv_AI

lemma cap_insert_ex_cap:
  "\<lbrace>ex_nonz_cap_to p\<rbrace>
     cap_insert cap src dest
   \<lbrace>\<lambda>rv. ex_nonz_cap_to p\<rbrace>" apply (simp add: cap_insert_def) apply (wp|simp split del: if_split)+ apply (wp set_cap_cap_to get_cap_wp set_cap_cte_wp_at set_untyped_cap_as_full_cte_wp_at)+ apply (clarsimp simp: set_untyped_cap_as_full_def split del: if_split) apply (wp set_cap_cap_to get_cap_wp)+ apply (clarsimp elim!: cte_wp_at_weakenE simp: is_cap_simps cte_wp_at_caps_of_state) apply (simp add: masked_as_full_def) done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. \<lbrace>ex_nonz_cap_to p\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv. ex_nonz_cap_to p\<rbrace> proof (prove)
goal (1 subgoal):
 1. \<lbrace>ex_nonz_cap_to p\<rbrace> do src_cap <- get_cap src;
old_cap <- get_cap dest;
y <- assert (old_cap = NullCap);
y <- set_untyped_cap_as_full src_cap cap src;
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. ex_nonz_cap_to p\<rbrace> proof (prove)
goal (6 subgoals):
 1. \<And>src_cap x. \<lbrace>?B4 src_cap x () ()\<rbrace> set_cap cap dest \<lbrace>\<lambda>yb. ex_nonz_cap_to p\<rbrace>
 2. \<And>src_cap x y. \<lbrace>?B3 src_cap x y\<rbrace> set_untyped_cap_as_full src_cap cap src \<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. ex_nonz_cap_to p s \<Longrightarrow> ?Q s proof (prove)
goal (5 subgoals):
 1. \<And>src_cap x y. \<lbrace>?P'32 src_cap x y\<rbrace> set_untyped_cap_as_full src_cap cap src \<lbrace>\<lambda>rv. ex_nonz_cap_to p\<rbrace>
 2. \<And>src_cap x. \<lbrace>?B2 src_cap x\<rbrace> assert (x = NullCap) \<lbrace>\<lambda>y s. ((dest \<noteq> src \<and> cte_wp_at (\<lambda>cap'. p \<notin> zobj_refs cap' - zobj_refs cap) dest s \<or> dest = src \<and> cte_wp_at (\<lambda>a. p \<notin> zobj_refs (masked_as_full a cap) - zobj_refs cap) src s) \<and> cte_wp_at ((=) src_cap) src s) \<and> ?P'32 src_cap x y s\<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. ex_nonz_cap_to p s \<Longrightarrow> ?Q s proof (prove)
goal (5 subgoals):
 1. \<And>src_cap x. \<lbrace>?P'32 src_cap x ()\<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>rv. ex_nonz_cap_to p\<rbrace>
 2. \<And>src_cap x. \<lbrace>?B2 src_cap x\<rbrace> assert (x = NullCap) \<lbrace>\<lambda>y s. ((dest \<noteq> src \<and> cte_wp_at (\<lambda>cap'. p \<notin> zobj_refs cap' - zobj_refs cap) dest s \<or> dest = src \<and> cte_wp_at (\<lambda>a. p \<notin> zobj_refs (masked_as_full a cap) - zobj_refs cap) src s) \<and> cte_wp_at ((=) src_cap) src s) \<and> ?P'32 src_cap x y s\<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. ex_nonz_cap_to p s \<Longrightarrow> ?Q s proof (prove)
goal (1 subgoal):
 1. \<And>s. ex_nonz_cap_to p s \<Longrightarrow> \<forall>capa. cte_wp_at ((=) capa) src s \<longrightarrow> (\<forall>capb. cte_wp_at ((=) capb) dest s \<longrightarrow> capb = NullCap \<longrightarrow> ((dest \<noteq> src \<and> cte_wp_at (\<lambda>cap'. p \<notin> zobj_refs cap' - zobj_refs cap) dest s \<or> dest = src \<and> cte_wp_at (\<lambda>a. p \<notin> zobj_refs (masked_as_full a cap) - zobj_refs cap) src s) \<and> cte_wp_at ((=) capa) src s) \<and> (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 (\<lambda>cap'. p \<notin> zobj_refs cap' - zobj_refs (max_free_index_update capa)) src s \<and> ex_nonz_cap_to p 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> ex_nonz_cap_to p s)) proof (prove)
goal (1 subgoal):
 1. \<And>s. \<lbrakk>ex_nonz_cap_to p s; caps_of_state s src = Some NullCap; dest = src; p \<in> zobj_refs (masked_as_full NullCap cap)\<rbrakk> \<Longrightarrow> p \<in> zobj_refs cap proof (prove)
goal:
No subgoals!