theory Ipc_AC

lemma send_fault_ipc_pas_refined:
  "\<lbrace>pas_refined aag and invs and is_subject aag \<circ> cur_thread
                    and K (valid_fault fault) and K (is_subject aag thread)\<rbrace>
   send_fault_ipc thread fault
   \<lbrace>\<lambda>_. pas_refined aag\<rbrace>" apply (rule hoare_gen_asm)+ apply (simp add: send_fault_ipc_def Let_def lookup_cap_def split_def) apply (wpsimp wp: send_ipc_pas_refined thread_set_fault_pas_refined thread_set_tcb_fault_set_invs
                    thread_set_refs_trivial thread_set_obj_at_impossible get_cap_wp
                    thread_set_valid_objs'' hoare_vcg_conj_lift hoare_vcg_ex_lift hoare_vcg_all_lift
              simp: split_def) apply (rule_tac Q'="\<lambda>rv s. pas_refined aag s \<and> is_subject aag (cur_thread s) \<and>
                               invs s \<and> valid_fault fault \<and> is_subject aag (fst (fst rv))"
                 in hoare_post_imp_R[rotated]) apply (fastforce dest!: cap_auth_caps_of_state
                       simp: invs_valid_objs invs_sym_refs cte_wp_at_caps_of_state aag_cap_auth_def
                             cap_auth_conferred_def cap_rights_to_auth_def AllowSend_def) apply (wp get_cap_auth_wp[where aag=aag] lookup_slot_for_thread_authorised
           | simp add: lookup_cap_def split_def)+ done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. \<lbrace>pas_refined aag and invs and is_subject aag \<circ> cur_thread and K (valid_fault fault) and K (is_subject aag thread)\<rbrace> send_fault_ipc thread fault \<lbrace>\<lambda>_. pas_refined aag\<rbrace> proof (prove)
goal (1 subgoal):
 1. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>pas_refined aag and invs and is_subject aag \<circ> cur_thread\<rbrace> send_fault_ipc thread fault \<lbrace>\<lambda>_. pas_refined aag\<rbrace> proof (prove)
goal (1 subgoal):
 1. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>pas_refined aag and invs and is_subject aag \<circ> cur_thread\<rbrace> doE handler_cptr <- liftE (thread_get tcb_fault_handler thread);
handler_cap <- cap_fault_on_failure (of_bl handler_cptr) False (doE p <- lookup_slot_for_thread thread handler_cptr;
liftE (get_cap (fst p))
odE);
case handler_cap of EndpointCap ref badge rights \<Rightarrow> if AllowSend \<in> rights \<and> (AllowGrant \<in> rights \<or> AllowGrantReply \<in> rights) then liftE $ do thread_set (tcb_fault_update (\<lambda>_. Some fault)) thread;
send_ipc True True (cap_ep_badge handler_cap) (AllowGrant \<in> rights) True thread (cap_ep_ptr handler_cap)
od else throwError (CapFault (of_bl handler_cptr) False (MissingCapability 0)) | _ \<Rightarrow> throwError (CapFault (of_bl handler_cptr) False (MissingCapability 0))
odE \<lbrace>\<lambda>_. pas_refined aag\<rbrace> proof (prove)
goal (3 subgoals):
 1. \<And>handler_cptr. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>?P'185 handler_cptr\<rbrace> lookup_slot_for_thread thread handler_cptr \<lbrace>\<lambda>p s. \<forall>cap. cte_wp_at ((=) cap) (fst p) s \<longrightarrow> (cap = NullCap \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb xc. cap = UntypedCap x xa xb xc) \<longrightarrow> pas_refined aag s) \<and> (\<forall>x xa xb. cap = EndpointCap x xa xb \<longrightarrow> (AllowSend \<in> xb \<and> (AllowGrant \<in> xb \<or> AllowGrantReply \<in> xb) \<longrightarrow> pas_refined aag s \<and> pspace_aligned s \<and> valid_vspace_objs s \<and> valid_arch_state s \<and> invs s \<and> (pasSubject aag, SyncSend, pasObjectAbs aag x) \<in> pasPolicy aag \<and> (pasSubject aag, Call, pasObjectAbs aag x) \<in> pasPolicy aag \<and> (AllowGrant \<in> xb \<longrightarrow> (pasSubject aag, Grant, pasObjectAbs aag x) \<in> pasPolicy aag \<and> (pasSubject aag, Call, pasObjectAbs aag x) \<in> pasPolicy aag)) \<and> ((AllowSend \<in> xb \<longrightarrow> AllowGrant \<notin> xb \<and> AllowGrantReply \<notin> xb) \<longrightarrow> pas_refined aag s)) \<and> ((\<exists>x xa xb. cap = NotificationCap x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb. cap = ReplyCap x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb. cap = CNodeCap x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x. cap = ThreadCap x) \<longrightarrow> pas_refined aag s) \<and> (cap = DomainCap \<longrightarrow> pas_refined aag s) \<and> (cap = IRQControlCap \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x. cap = IRQHandlerCap x) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb. cap = Zombie x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x. cap = ArchObjectCap x) \<longrightarrow> pas_refined aag s)\<rbrace>, -
 2. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>?Q5\<rbrace> liftE (thread_get tcb_fault_handler thread) \<lbrace>\<lambda>handler_cptr s. pas_refined aag s \<and> ?P'185 handler_cptr s\<rbrace>, \<lbrace>\<lambda>_. pas_refined aag\<rbrace>
 3. \<And>s. \<lbrakk>is_subject aag thread; valid_fault fault; (pas_refined aag and invs and is_subject aag \<circ> cur_thread) s\<rbrakk> \<Longrightarrow> ?Q5 s proof (prove)
goal (4 subgoals):
 1. \<And>handler_cptr rv s. \<lbrakk>is_subject aag thread; valid_fault fault; pas_refined aag s \<and> is_subject aag (cur_thread s) \<and> invs s \<and> valid_fault fault \<and> is_subject aag (fst (fst rv))\<rbrakk> \<Longrightarrow> \<forall>cap. cte_wp_at ((=) cap) (fst rv) s \<longrightarrow> (cap = NullCap \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb xc. cap = UntypedCap x xa xb xc) \<longrightarrow> pas_refined aag s) \<and> (\<forall>x xa xb. cap = EndpointCap x xa xb \<longrightarrow> (AllowSend \<in> xb \<and> (AllowGrant \<in> xb \<or> AllowGrantReply \<in> xb) \<longrightarrow> pas_refined aag s \<and> pspace_aligned s \<and> valid_vspace_objs s \<and> valid_arch_state s \<and> invs s \<and> (pasSubject aag, SyncSend, pasObjectAbs aag x) \<in> pasPolicy aag \<and> (pasSubject aag, Call, pasObjectAbs aag x) \<in> pasPolicy aag \<and> (AllowGrant \<in> xb \<longrightarrow> (pasSubject aag, Grant, pasObjectAbs aag x) \<in> pasPolicy aag \<and> (pasSubject aag, Call, pasObjectAbs aag x) \<in> pasPolicy aag)) \<and> ((AllowSend \<in> xb \<longrightarrow> AllowGrant \<notin> xb \<and> AllowGrantReply \<notin> xb) \<longrightarrow> pas_refined aag s)) \<and> ((\<exists>x xa xb. cap = NotificationCap x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb. cap = ReplyCap x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb. cap = CNodeCap x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x. cap = ThreadCap x) \<longrightarrow> pas_refined aag s) \<and> (cap = DomainCap \<longrightarrow> pas_refined aag s) \<and> (cap = IRQControlCap \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x. cap = IRQHandlerCap x) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x xa xb. cap = Zombie x xa xb) \<longrightarrow> pas_refined aag s) \<and> ((\<exists>x. cap = ArchObjectCap x) \<longrightarrow> pas_refined aag s)
 2. \<And>handler_cptr. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>?P'185 handler_cptr\<rbrace> lookup_slot_for_thread thread handler_cptr \<lbrace>\<lambda>rv s. pas_refined aag s \<and> is_subject aag (cur_thread s) \<and> invs s \<and> valid_fault fault \<and> is_subject aag (fst (fst rv))\<rbrace>, -
 3. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>?Q5\<rbrace> liftE (thread_get tcb_fault_handler thread) \<lbrace>\<lambda>handler_cptr s. pas_refined aag s \<and> ?P'185 handler_cptr s\<rbrace>, \<lbrace>\<lambda>_. pas_refined aag\<rbrace>
 4. \<And>s. \<lbrakk>is_subject aag thread; valid_fault fault; (pas_refined aag and invs and is_subject aag \<circ> cur_thread) s\<rbrakk> \<Longrightarrow> ?Q5 s proof (prove)
goal (3 subgoals):
 1. \<And>handler_cptr. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>?P'185 handler_cptr\<rbrace> lookup_slot_for_thread thread handler_cptr \<lbrace>\<lambda>rv s. pas_refined aag s \<and> is_subject aag (cur_thread s) \<and> invs s \<and> valid_fault fault \<and> is_subject aag (fst (fst rv))\<rbrace>, -
 2. \<lbrakk>is_subject aag thread; valid_fault fault\<rbrakk> \<Longrightarrow> \<lbrace>?Q5\<rbrace> liftE (thread_get tcb_fault_handler thread) \<lbrace>\<lambda>handler_cptr s. pas_refined aag s \<and> ?P'185 handler_cptr s\<rbrace>, \<lbrace>\<lambda>_. pas_refined aag\<rbrace>
 3. \<And>s. \<lbrakk>is_subject aag thread; valid_fault fault; (pas_refined aag and invs and is_subject aag \<circ> cur_thread) s\<rbrakk> \<Longrightarrow> ?Q5 s proof (prove)
goal:
No subgoals!