simple_selinux/Co2sobj_prop.thy
changeset 74 271e9818b6f6
child 75 99af1986e1e0
equal deleted inserted replaced
73:924ab7a4e7fa 74:271e9818b6f6
       
     1 (*<*)
       
     2 theory Co2sobj_prop
       
     3 imports Main Flask Flask_type Static Static_type Sectxt_prop Init_prop Current_files_prop Current_sockets_prop Delete_prop Proc_fd_of_file_prop Tainted_prop Valid_prop Init_prop Alive_prop
       
     4 begin
       
     5 (*<*)
       
     6 
       
     7 ML {*
       
     8 fun print_ss ss =
       
     9 let
       
    10 val {simps, congs, procs, ...} = Raw_Simplifier.dest_ss ss
       
    11 in
       
    12 simps
       
    13 end
       
    14 *}
       
    15 
       
    16 
       
    17 context tainting_s begin
       
    18 
       
    19 (********************* cm2smsg simpset ***********************)
       
    20 
       
    21 lemma cm2smsg_other: 
       
    22   "\<lbrakk>valid (e # s); \<forall> p q m. e \<noteq> SendMsg p q m; \<forall> p q m. e \<noteq> RecvMsg p q m; \<forall> p q. e \<noteq> RemoveMsgq p q\<rbrakk> 
       
    23    \<Longrightarrow> cm2smsg (e # s) = cm2smsg s"
       
    24 apply (frule vt_grant_os, frule vd_cons, rule ext, rule ext)
       
    25 unfolding cm2smsg_def
       
    26 apply (case_tac e)
       
    27 apply (auto simp:sectxt_of_obj_simps tainted_eq_Tainted 
       
    28            split:t_object.splits option.splits if_splits 
       
    29             dest:not_deleted_init_msg  dest!:current_has_sec')
       
    30 done
       
    31 
       
    32 lemma cm2smsg_sendmsg:
       
    33   "valid (SendMsg p q m # s) \<Longrightarrow> cm2smsg (SendMsg p q m # s) = (\<lambda> q' m'. 
       
    34      if (q' = q \<and> m' = m)
       
    35      then (case (sectxt_of_obj (SendMsg p q m # s) (O_msg q m)) of
       
    36              Some sec \<Rightarrow> Some (Created, sec, O_msg q m \<in> tainted (SendMsg p q m # s))
       
    37            | _ \<Rightarrow> None)
       
    38      else cm2smsg s q' m') "
       
    39 apply (frule vd_cons, frule vt_grant_os, rule ext, rule ext)
       
    40 apply (auto simp:cm2smsg_def tainted_eq_Tainted sectxt_of_obj_simps 
       
    41   split:if_splits option.splits
       
    42   dest:not_deleted_init_msg  dest!:current_has_sec')
       
    43 done
       
    44 
       
    45 lemma cm2smsg_recvmsg1:
       
    46   "\<lbrakk>q' \<noteq> q; valid (RecvMsg p q m # s)\<rbrakk> \<Longrightarrow> cm2smsg (RecvMsg p q m # s) q' = cm2smsg s q'"
       
    47 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
    48 apply (auto simp:cm2smsg_def tainted_eq_Tainted sectxt_of_obj_simps 
       
    49   split:if_splits option.splits)
       
    50 done
       
    51 
       
    52 lemma cm2smsg_recvmsg2:
       
    53   "\<lbrakk>m' \<noteq> m; valid (RecvMsg p q m # s)\<rbrakk> \<Longrightarrow> cm2smsg (RecvMsg p q m # s) q m' = cm2smsg s q m'"
       
    54 apply (frule vd_cons, frule vt_grant_os)
       
    55 apply (auto simp:cm2smsg_def tainted_eq_Tainted sectxt_of_obj_simps 
       
    56   split:if_splits option.splits)
       
    57 done
       
    58 
       
    59 lemma cm2smsg_recvmsg1':
       
    60   "\<lbrakk>valid (RecvMsg p q m # s); q' \<noteq> q\<rbrakk> \<Longrightarrow> cm2smsg (RecvMsg p q m # s) q' = cm2smsg s q'"
       
    61 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
    62 apply (auto simp:cm2smsg_def tainted_eq_Tainted sectxt_of_obj_simps 
       
    63   split:if_splits option.splits)
       
    64 done
       
    65 
       
    66 lemma cm2smsg_recvmsg2':
       
    67   "\<lbrakk>valid (RecvMsg p q m # s); m' \<noteq> m\<rbrakk> \<Longrightarrow> cm2smsg (RecvMsg p q m # s) q m' = cm2smsg s q m'"
       
    68 apply (frule vd_cons, frule vt_grant_os)
       
    69 apply (auto simp:cm2smsg_def tainted_eq_Tainted sectxt_of_obj_simps 
       
    70   split:if_splits option.splits)
       
    71 done
       
    72 
       
    73 lemma cm2smsg_removemsgq:
       
    74   "\<lbrakk>q' \<noteq> q; valid (RemoveMsgq p q # s)\<rbrakk> \<Longrightarrow> cm2smsg (RemoveMsgq p q # s) q' = cm2smsg s q'"
       
    75 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
    76 apply (auto simp:cm2smsg_def tainted_eq_Tainted sectxt_of_obj_simps 
       
    77   split:if_splits option.splits)
       
    78 done
       
    79 
       
    80 lemmas cm2smsg_simps = cm2smsg_nil_prop cm2smsg_sendmsg cm2smsg_recvmsg1' cm2smsg_recvmsg2'
       
    81   cm2smsg_removemsgq cm2smsg_other
       
    82 
       
    83 lemma init_cm2smsg_has_smsg:
       
    84   "\<lbrakk>m \<in> set (init_msgs_of_queue q); q \<in> init_msgqs\<rbrakk> \<Longrightarrow> \<exists> sm. init_cm2smsg q m = Some sm"
       
    85 by (auto simp:init_cm2smsg_def split:option.splits dest:init_msg_has_ctxt)
       
    86 
       
    87 lemma hd_set_prop1:
       
    88   "hd l \<notin> set l \<Longrightarrow> l = []"
       
    89 by (case_tac l, auto)
       
    90 
       
    91 lemma tl_set_prop1:
       
    92   "a \<in> set (tl l) \<Longrightarrow> a \<in> set l"
       
    93 by (case_tac l, auto)
       
    94 
       
    95 lemma current_has_smsg:
       
    96   "\<lbrakk>m \<in> set (msgs_of_queue s q); q \<in> current_msgqs s; valid s\<rbrakk> \<Longrightarrow> \<exists> sm. cm2smsg s q m = Some sm"
       
    97 apply (induct s)
       
    98 apply (simp only:cm2smsg_nil_prop msgs_of_queue.simps current_msgqs.simps init_cm2smsg_has_smsg)
       
    99 
       
   100 apply (frule vt_grant_os, frule vd_cons, case_tac a)
       
   101 apply (auto simp:cm2smsg_def sectxt_of_obj_simps split:if_splits option.splits
       
   102   dest!:current_has_sec' hd_set_prop1 dest:not_deleted_init_msg tl_set_prop1)
       
   103 done 
       
   104 
       
   105 lemma current_has_smsg':
       
   106   "\<lbrakk>cm2smsg s q m = None; q \<in> current_msgqs s; valid s\<rbrakk> \<Longrightarrow> m \<notin> set (msgs_of_queue s q)"
       
   107 by (auto dest:current_has_smsg)
       
   108 
       
   109 lemma cqm2sms_has_sms_aux:
       
   110   "\<forall> m \<in> set ms. sectxt_of_obj s (O_msg q m) \<noteq> None \<Longrightarrow> (\<exists> sms. cqm2sms s q ms = Some sms)"
       
   111 by (induct ms, auto split:option.splits simp:cm2smsg_def)
       
   112 
       
   113 lemma current_has_sms:
       
   114   "\<lbrakk>q \<in> current_msgqs s; valid s\<rbrakk> \<Longrightarrow> \<exists> sms. cqm2sms s q (msgs_of_queue s q) = Some sms"
       
   115 apply (rule cqm2sms_has_sms_aux)
       
   116 apply (auto dest:current_msg_has_sec)
       
   117 done
       
   118 
       
   119 lemma current_has_sms':
       
   120   "\<lbrakk>cqm2sms s q (msgs_of_queue s q) = None; valid s\<rbrakk> \<Longrightarrow> q \<notin> current_msgqs s"
       
   121 by (auto dest:current_has_sms)
       
   122 
       
   123 (********************* cqm2sms simpset ***********************) 
       
   124 
       
   125 lemma cqm2sms_other:
       
   126   "\<lbrakk>valid (e # s); \<forall> p m. e \<noteq> CreateMsgq p q; \<forall> p q m. e \<noteq> SendMsg p q m; 
       
   127     \<forall> p q m. e \<noteq> RecvMsg p q m; \<forall> p q. e \<noteq> RemoveMsgq p q\<rbrakk> 
       
   128    \<Longrightarrow> cqm2sms (e # s) = cqm2sms s"
       
   129 apply (rule ext, rule ext)
       
   130 apply (induct_tac xa, simp)
       
   131 apply (frule vt_grant_os, frule vd_cons, case_tac e)
       
   132 apply (auto split:option.splits dest:cm2smsg_other) 
       
   133 done
       
   134 
       
   135 lemma cqm2sms_createmsgq:
       
   136   "valid (CreateMsgq p q # s) \<Longrightarrow> cqm2sms (CreateMsgq p q # s) = (\<lambda> q' ms'. 
       
   137      if (q' = q \<and> ms' = []) then Some []
       
   138      else cqm2sms s q' ms')"
       
   139 apply (rule ext, rule ext)
       
   140 apply (frule vt_grant_os, frule vd_cons, induct_tac ms')
       
   141 apply (auto split:if_splits option.splits dest:cm2smsg_other)
       
   142 done
       
   143 
       
   144 lemma cqm2sms_2:
       
   145   "cqm2sms s q (ms @ [m]) = 
       
   146      (case (cqm2sms s q ms, cm2smsg s q m) of 
       
   147        (Some sms, Some sm) \<Rightarrow> Some (sms @ [sm]) 
       
   148      | _ \<Rightarrow> None)"
       
   149 apply (induct ms, simp split:option.splits)
       
   150 by (auto split:option.splits)
       
   151 
       
   152 lemmas cqm2sms_simps2 = cqm2sms.simps(1) cqm2sms_2
       
   153 
       
   154 declare cqm2sms.simps [simp del]
       
   155 
       
   156 lemma cqm2sms_prop1:
       
   157   "cqm2sms s q ms = None \<Longrightarrow> \<exists> m \<in> set ms. cm2smsg s q m = None"
       
   158 by (induct ms, auto simp:cqm2sms.simps split:option.splits)
       
   159 
       
   160 lemma cqm2sms_sendmsg1:
       
   161   "\<lbrakk>valid (SendMsg p q m # s); m \<notin> set ms\<rbrakk>
       
   162    \<Longrightarrow> cqm2sms (SendMsg p q m # s) q' ms = cqm2sms s q' ms"
       
   163 apply (frule vt_grant_os, frule vd_cons)
       
   164 apply (frule cm2smsg_sendmsg)
       
   165 apply (induct ms rule:rev_induct)
       
   166 apply (auto split:if_splits option.splits  simp:cqm2sms_simps2)
       
   167 done
       
   168 
       
   169 lemma cqm2sms_sendmsg2:
       
   170   "\<lbrakk>valid (SendMsg p q m # s); q' \<noteq> q\<rbrakk>
       
   171    \<Longrightarrow> cqm2sms (SendMsg p q m # s) q' ms = cqm2sms s q' ms"
       
   172 apply (frule vt_grant_os, frule vd_cons)
       
   173 apply (frule cm2smsg_sendmsg)
       
   174 apply (induct ms rule:rev_induct)
       
   175 apply (auto split:if_splits option.splits  simp:cqm2sms_simps2)
       
   176 done
       
   177 
       
   178 lemma cqm2sms_sendmsg3:
       
   179   "\<lbrakk>valid (SendMsg p q m # s); ms' = msgs_of_queue (SendMsg p q m # s) q\<rbrakk>
       
   180    \<Longrightarrow> cqm2sms (SendMsg p q m # s) q ms' = 
       
   181      (case (cqm2sms s q (msgs_of_queue s q), sectxt_of_obj (SendMsg p q m # s) (O_msg q m)) of
       
   182        (Some sms, Some sec) \<Rightarrow> Some (sms @ [(Created, sec, O_msg q m \<in> tainted (SendMsg p q m # s))])
       
   183      | _ \<Rightarrow> None)"
       
   184 apply (frule vt_grant_os, frule vd_cons)
       
   185 apply (frule cm2smsg_sendmsg)
       
   186 apply (auto split:if_splits option.splits  simp:cqm2sms_simps2 cqm2sms_sendmsg1)
       
   187 done
       
   188 
       
   189 lemma cqm2sms_sendmsg:
       
   190   "\<lbrakk>valid (SendMsg p q m # s); ms' = msgs_of_queue (SendMsg p q m # s) q'\<rbrakk> 
       
   191    \<Longrightarrow> cqm2sms (SendMsg p q m # s) q' ms' = (
       
   192      if (q' = q) 
       
   193      then (case (cqm2sms s q (msgs_of_queue s q), sectxt_of_obj (SendMsg p q m # s) (O_msg q m)) of
       
   194              (Some sms, Some sec) \<Rightarrow> Some (sms @ [(Created, sec, O_msg q m \<in> tainted (SendMsg p q m # s))])
       
   195            | _ \<Rightarrow> None)
       
   196      else cqm2sms s q' ms' )"
       
   197 apply (simp split:if_splits add:cqm2sms_sendmsg2 cqm2sms_sendmsg3)
       
   198 done
       
   199 
       
   200 lemma cqm2sms_recvmsg1:
       
   201   "\<lbrakk>valid (RecvMsg p q m # s); m \<notin> set ms\<rbrakk> 
       
   202    \<Longrightarrow> cqm2sms (RecvMsg p q m # s) q ms = cqm2sms s q ms"
       
   203 apply (frule vt_grant_os, frule vd_cons)
       
   204 apply (induct ms rule:rev_induct)
       
   205 apply (auto split:if_splits option.splits simp:cqm2sms_simps2 cm2smsg_recvmsg2')
       
   206 done
       
   207 
       
   208 lemma cqm2sms_recvmsg2:
       
   209   "\<lbrakk>valid (RecvMsg p q m # s); q' \<noteq> q\<rbrakk>
       
   210    \<Longrightarrow> cqm2sms (RecvMsg p q m # s) q' ms = cqm2sms s q' ms"
       
   211 apply (frule vt_grant_os, frule vd_cons)
       
   212 apply (induct ms rule:rev_induct)
       
   213 apply (auto split:if_splits option.splits simp:cqm2sms_simps2 cm2smsg_recvmsg1')
       
   214 done
       
   215 
       
   216 lemma cqm2sms_recvmsg:
       
   217   "\<lbrakk>valid (RecvMsg p q m # s); ms = msgs_of_queue (RecvMsg p q m # s) q'\<rbrakk>
       
   218    \<Longrightarrow> cqm2sms (RecvMsg p q m # s) q' ms = (
       
   219      if (q' = q) 
       
   220      then (case (cqm2sms s q (msgs_of_queue s q)) of
       
   221              Some sms \<Rightarrow> Some (tl sms)
       
   222            | _ \<Rightarrow> None)
       
   223      else cqm2sms s q' ms)"
       
   224 apply (frule vt_grant_os, frule vd_cons)
       
   225 apply (auto split:if_splits option.splits simp:cqm2sms_recvmsg1 cqm2sms_recvmsg2 
       
   226      dest!:current_has_sms')
       
   227 apply (case_tac "msgs_of_queue s q", simp)
       
   228 apply (frule_tac ms = "tl (msgs_of_queue s q)" in cqm2sms_recvmsg1)
       
   229 apply (drule_tac q = q in distinct_queue_msgs, simp+)
       
   230 apply (case_tac a, auto simp:cqm2sms.simps split:option.splits if_splits)
       
   231 done
       
   232 
       
   233 lemma cqm2sms_removemsgq:
       
   234   "\<lbrakk>valid (RemoveMsgq p q # s); q' \<noteq> q; q' \<in> current_msgqs s\<rbrakk> 
       
   235    \<Longrightarrow> cqm2sms (RemoveMsgq p q # s) q' ms = cqm2sms s q' ms"
       
   236 apply (frule vt_grant_os, frule vd_cons)
       
   237 apply (induct ms rule:rev_induct)
       
   238 apply (auto simp:cqm2sms_simps2 cm2smsg_removemsgq split:option.splits if_splits)
       
   239 done
       
   240   
       
   241 lemmas cqm2sms_simps = cqm2sms_other cqm2sms_createmsgq cqm2sms_sendmsg cqm2sms_recvmsg cqm2sms_removemsgq
       
   242 
       
   243 (********************* cq2smsgq simpset ***********************) 
       
   244  
       
   245 lemma cq2smsgq_other: 
       
   246   "\<lbrakk>valid (e # s); \<forall> p q. e \<noteq> CreateMsgq p q; \<forall> p q m. e \<noteq> SendMsg p q m; 
       
   247     \<forall> p q m. e \<noteq> RecvMsg p q m; \<forall> p q. e \<noteq> RemoveMsgq p q\<rbrakk> 
       
   248    \<Longrightarrow> cq2smsgq (e # s) = cq2smsgq s" 
       
   249 apply (frule cqm2sms_other, simp+)
       
   250 apply (frule vd_cons, frule vt_grant_os, rule ext, case_tac e) 
       
   251 apply (auto simp:cq2smsgq_def sectxt_of_obj_simps 
       
   252            split:t_object.splits option.splits if_splits 
       
   253             dest:not_deleted_init_msg) 
       
   254 done
       
   255 
       
   256 lemma cq2smsg_createmsgq:
       
   257   "valid (CreateMsgq p q # s)
       
   258    \<Longrightarrow> cq2smsgq (CreateMsgq p q # s) = (cq2smsgq s) (q := 
       
   259      case (sectxt_of_obj s (O_proc p)) of
       
   260        Some psec \<Rightarrow> Some (Created, (fst psec, R_object, (snd o snd) psec), [])
       
   261      | None     \<Rightarrow> None)"
       
   262 apply (frule vd_cons, frule vt_grant_os)
       
   263 apply (frule cqm2sms_createmsgq)
       
   264 apply (rule ext, auto simp:cq2smsgq_def sec_createmsgq 
       
   265   split:option.splits if_splits dest:not_deleted_init_msgq)
       
   266 done
       
   267 
       
   268 lemma cq2smsg_sendmsg:
       
   269   "valid (SendMsg p q m # s) 
       
   270    \<Longrightarrow> cq2smsgq (SendMsg p q m # s) = (cq2smsgq s) (q := 
       
   271      case (cq2smsgq s q, sectxt_of_obj (SendMsg p q m # s) (O_msg q m)) of 
       
   272        (Some (qi, sec, sms), Some msec) \<Rightarrow> 
       
   273           Some (qi, sec, sms @ [(Created, msec, O_msg q m \<in> tainted (SendMsg p q m # s))])
       
   274      | _ \<Rightarrow> None)"
       
   275 apply (frule vd_cons, frule vt_grant_os)
       
   276 apply (rule ext)
       
   277 apply (frule_tac q' = x in cqm2sms_sendmsg, simp)
       
   278 apply (auto simp:cq2smsgq_def sectxt_of_obj_simps  split:option.splits if_splits
       
   279   dest!:current_has_sms' current_has_sec')
       
   280 done
       
   281 
       
   282 lemma current_has_smsgq:
       
   283   "\<lbrakk>q \<in> current_msgqs s; valid s\<rbrakk> \<Longrightarrow> \<exists> sq. cq2smsgq s q = Some sq"
       
   284 by (auto simp:cq2smsgq_def split:option.splits dest!:current_has_sec' current_has_sms')
       
   285 
       
   286 lemma current_has_smsgq':
       
   287   "\<lbrakk>cq2smsgq s q = None; valid s\<rbrakk> \<Longrightarrow> q \<notin> current_msgqs s"
       
   288 by (auto dest:current_has_smsgq)
       
   289 
       
   290 lemma cq2smsg_recvmsg:
       
   291   "valid (RecvMsg p q m # s) 
       
   292    \<Longrightarrow> cq2smsgq (RecvMsg p q m # s) = (cq2smsgq s) (q := 
       
   293     case (cq2smsgq s q) of
       
   294       Some (qi, sec, sms) \<Rightarrow> Some (qi, sec, tl sms)
       
   295     | _ \<Rightarrow> None)"
       
   296 apply (frule vd_cons, frule vt_grant_os)
       
   297 apply (rule ext, frule_tac q' = x in cqm2sms_recvmsg, simp)
       
   298 apply (auto simp add:cq2smsgq_def sectxt_of_obj_simps split:option.splits if_splits 
       
   299   dest!:current_has_sec' current_has_sms' current_has_smsgq')
       
   300 done
       
   301 
       
   302 lemma cq2smsg_removemsgq:
       
   303   "\<lbrakk>valid (RemoveMsgq p q # s); q' \<noteq> q; q' \<in> current_msgqs s\<rbrakk>
       
   304    \<Longrightarrow> cq2smsgq (RemoveMsgq p q # s) q' = cq2smsgq s q'"
       
   305 apply (frule vd_cons, frule vt_grant_os)
       
   306 apply (auto simp:cq2smsgq_def sectxt_of_obj_simps cqm2sms_removemsgq split:if_splits option.splits 
       
   307   dest!:current_has_sec' current_has_sms' current_has_smsgq')
       
   308 done
       
   309 
       
   310 lemmas cq2smsgq_simps = cq2smsgq_other cq2smsg_sendmsg cq2smsg_recvmsg cq2smsg_removemsgq
       
   311 
       
   312 lemma sm_in_sqsms_init_aux:
       
   313   "\<lbrakk>m \<in> set ms; init_cm2smsg q m = Some sm; q \<in> init_msgqs; 
       
   314     init_cqm2sms q ms = Some sms\<rbrakk> \<Longrightarrow> sm \<in> set sms"
       
   315 apply (induct ms arbitrary:m sm sms)
       
   316 by (auto split:if_splits option.splits)
       
   317 
       
   318 lemma sm_in_sqsms_init:
       
   319   "\<lbrakk>m \<in> set (init_msgs_of_queue q); init_cm2smsg q m = Some sm; q \<in> init_msgqs; 
       
   320     init_cqm2sms q (init_msgs_of_queue q) = Some sms\<rbrakk> \<Longrightarrow> sm \<in> set sms"
       
   321 by (simp add:sm_in_sqsms_init_aux)
       
   322 
       
   323 lemma cqm2sms_prop0:
       
   324   "\<lbrakk>m \<in> set ms; cm2smsg s q m = Some sm; cqm2sms s q ms = Some sms\<rbrakk> \<Longrightarrow> sm \<in> set sms"
       
   325 apply (induct ms arbitrary:m sm sms)
       
   326 apply (auto simp:cqm2sms.simps split:option.splits)
       
   327 done
       
   328 
       
   329 lemma sm_in_sqsms:
       
   330   "\<lbrakk>m \<in> set (msgs_of_queue s q); q \<in> current_msgqs s; valid s; cq2smsgq s q = Some (qi, qsec, sms);
       
   331     cm2smsg s q m = Some sm\<rbrakk> \<Longrightarrow> sm \<in> set sms"
       
   332 proof (induct s arbitrary:m q qi qsec sms sm)
       
   333   case Nil
       
   334   thus ?case 
       
   335     by (simp add:cq2smsga_nil_prop cm2smsg_nil_prop init_cq2smsgq_def sm_in_sqsms_init 
       
   336            split:option.splits)
       
   337 next
       
   338   case (Cons e s)
       
   339   hence p1:"\<And> m q qi qsec sms sm. \<lbrakk>m \<in> set (msgs_of_queue s q); q \<in> current_msgqs s; valid s; 
       
   340     cq2smsgq s q = Some (qi, qsec, sms); cm2smsg s q m = Some sm\<rbrakk>
       
   341     \<Longrightarrow> sm \<in> set sms" and p2: "m \<in> set (msgs_of_queue (e # s) q)" 
       
   342     and p3: "q \<in> current_msgqs (e # s)" and p4: "valid (e # s)"
       
   343     and p5: "cq2smsgq (e # s) q = Some (qi, qsec, sms)"
       
   344     and p6: "cm2smsg (e # s) q m = Some sm" by auto
       
   345   from p4 have os: "os_grant s e" and vd: "valid s" by (auto dest:vd_cons vt_grant_os)
       
   346 (*
       
   347   from p1 have p1':
       
   348     "\<And> m q qi qsec sms sm ms. \<lbrakk>m \<in> set ms; set ms \<subseteq> set (msgs_of_queue s q); q \<in> current_msgqs s;
       
   349     valid s; cq2smsgq s q = Some (qi, qsec, sms); cm2smsg s q m = Some sm\<rbrakk>
       
   350     \<Longrightarrow> sm \<in> set "
       
   351 *)
       
   352   show ?case using p2 p3 p4 p5 p6 vd os
       
   353     apply (case_tac e)
       
   354     apply (auto simp:cq2smsgq_simps cm2smsg_simps split:if_splits option.splits intro:p1)
       
   355 
       
   356     apply (rule_tac m = m and q = q and qi = qi and qsec = qsec in p1, simp+)
       
   357     apply (case_tac "q = nat2", simp)
       
   358     apply (drule cq2smsg_createmsgq, simp, simp)
       
   359 
       
   360     apply (drule_tac m = m and q = q and qi = qi and qsec = "(aa,ab,b)" in p1, simp+)
       
   361 
       
   362     apply (simp add:cq2smsgq_def split:option.splits)
       
   363     apply (rule_tac m = m and sm = sm in cqm2sms_prop0, simp+)
       
   364     apply (simp add:cqm2sms_recvmsg)
       
   365     done
       
   366 qed
       
   367 
       
   368 (****************** cf2sfile path simpset ***************)
       
   369 
       
   370 lemma sroot_only:
       
   371   "cf2sfile s [] = Some sroot"
       
   372 by (simp add:cf2sfile_def)
       
   373 
       
   374 lemma not_file_is_dir:
       
   375   "\<lbrakk>\<not> is_file s f; f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> is_dir s f"
       
   376 by (auto simp:is_file_def current_files_def is_dir_def 
       
   377          dest:finum_has_itag finum_has_ftag' split:t_inode_tag.splits option.splits)
       
   378 
       
   379 lemma not_dir_is_file:
       
   380   "\<lbrakk>\<not> is_dir s f; f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> is_file s f"
       
   381 by (auto simp:is_file_def current_files_def is_dir_def 
       
   382          dest:finum_has_itag finum_has_ftag' split:t_inode_tag.splits option.splits)
       
   383 
       
   384 lemma is_file_or_dir:
       
   385   "\<lbrakk>f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> is_file s f \<or> is_dir s f"
       
   386 by (auto dest:not_dir_is_file)
       
   387 
       
   388 lemma current_file_has_sfile:
       
   389   "\<lbrakk>f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> \<exists> sf. cf2sfile s f = Some sf"
       
   390 apply (induct f)
       
   391 apply (rule_tac x = "sroot" in exI, simp add:sroot_only)
       
   392 apply (frule parentf_in_current', simp, clarsimp)
       
   393 apply (frule parentf_is_dir'', simp)
       
   394 apply (frule is_file_or_dir, simp)
       
   395 apply (auto dest!:current_has_sec'
       
   396             simp:cf2sfile_def split:option.splits if_splits dest!:get_pfs_secs_prop')
       
   397 done
       
   398 
       
   399 definition sectxt_of_pf :: "t_state \<Rightarrow> t_file \<Rightarrow> security_context_t option"
       
   400 where
       
   401   "sectxt_of_pf s f = (case f of [] \<Rightarrow> None | (a # pf) \<Rightarrow> sectxt_of_obj s (O_dir pf))"
       
   402 
       
   403 definition get_parentfs_ctxts' :: "t_state \<Rightarrow> t_file \<Rightarrow> (security_context_t list) option"
       
   404 where
       
   405   "get_parentfs_ctxts' s f = (case f of [] \<Rightarrow> None | (a # pf) \<Rightarrow> get_parentfs_ctxts s pf)"
       
   406 
       
   407 lemma is_file_has_sfile:
       
   408   "\<lbrakk>is_file s f; valid s\<rbrakk> \<Longrightarrow> \<exists> sec psec asecs. cf2sfile s f = Some 
       
   409       (if (\<not> deleted (O_file f) s \<and> is_init_file f) then Init f else Created,
       
   410        sec, Some psec, set asecs) \<and> (sectxt_of_obj s (O_file f) = Some sec) \<and>
       
   411        (sectxt_of_pf s f = Some psec) \<and> (get_parentfs_ctxts' s f = Some asecs)"
       
   412 apply (case_tac f, simp, drule root_is_dir', simp, simp)
       
   413 apply (frule is_file_in_current)
       
   414 apply (drule current_file_has_sfile, simp)
       
   415 apply (auto simp:cf2sfile_def sectxt_of_pf_def get_parentfs_ctxts'_def split:if_splits option.splits)
       
   416 done
       
   417 
       
   418 lemma is_file_has_sfile':
       
   419   "\<lbrakk>is_file s f; valid s\<rbrakk> \<Longrightarrow> \<exists> sf. cf2sfile s f = Some sf"
       
   420 by (drule is_file_has_sfile, auto)
       
   421 
       
   422 lemma is_dir_has_sfile:
       
   423   "\<lbrakk>is_dir s f; valid s\<rbrakk> \<Longrightarrow> (case f of
       
   424       [] \<Rightarrow> cf2sfile s f = Some sroot
       
   425     | a # pf \<Rightarrow> (\<exists> sec psec asecs. cf2sfile s f = Some 
       
   426       (if (\<not> deleted (O_dir f) s \<and> is_init_dir f) then Init f else Created,
       
   427        sec, Some psec, set asecs) \<and> (sectxt_of_obj s (O_dir f) = Some sec) \<and>
       
   428        (sectxt_of_obj s (O_dir pf) = Some psec) \<and> (get_parentfs_ctxts s pf = Some asecs)))"
       
   429 apply (case_tac f, simp add:sroot_only)
       
   430 apply (frule is_dir_in_current, frule is_dir_not_file)
       
   431 apply (drule current_file_has_sfile, simp)
       
   432 apply (auto simp:cf2sfile_def split:if_splits option.splits)
       
   433 done
       
   434 
       
   435 lemma is_dir_has_sdir':
       
   436   "\<lbrakk>is_dir s f; valid s\<rbrakk> \<Longrightarrow> \<exists> sf. cf2sfile s f = Some sf"
       
   437 apply (case_tac f)
       
   438 apply (rule_tac x = sroot in exI)
       
   439 apply (simp add:sroot_only)
       
   440 apply (drule is_dir_has_sfile, auto)
       
   441 done
       
   442 
       
   443 lemma sroot_set:
       
   444   "valid s \<Longrightarrow> \<exists> sec. sroot = (Init [], sec, None, {}) \<and> sectxt_of_obj s (O_dir []) = Some sec"
       
   445 apply (frule root_is_dir)
       
   446 apply (drule is_dir_has_sec, simp)
       
   447 apply (auto simp:sroot_def sec_of_root_def sectxt_of_obj_def type_of_obj.simps 
       
   448                  root_type_remains root_user_remains
       
   449            dest!:root_has_type' root_has_user' root_has_init_type' root_has_init_user'
       
   450            split:option.splits)
       
   451 done
       
   452 
       
   453 lemma cf2sfile_path_file:
       
   454   "\<lbrakk>is_file s (f # pf); valid s\<rbrakk>
       
   455    \<Longrightarrow> cf2sfile s (f # pf) = (
       
   456      case (cf2sfile s pf) of
       
   457        Some (pfi, pfsec, psec, asecs) \<Rightarrow> 
       
   458           (case (sectxt_of_obj s (O_file (f # pf))) of
       
   459               Some fsec \<Rightarrow> Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
       
   460                                 else Created, fsec, Some pfsec, asecs \<union> {pfsec})
       
   461            | None \<Rightarrow> None)
       
   462      | _ \<Rightarrow> None)"
       
   463 apply (frule is_file_in_current, drule parentf_is_dir'', simp)
       
   464 apply (frule is_dir_has_sfile, simp, frule is_file_has_sfile, simp)
       
   465 apply (frule sroot_set)
       
   466 apply (case_tac pf, (clarsimp simp:get_parentfs_ctxts'_def sectxt_of_pf_def)+) 
       
   467 done
       
   468 
       
   469 lemma cf2sfile_path_dir:
       
   470   "\<lbrakk>is_dir s (f # pf); valid s\<rbrakk>
       
   471    \<Longrightarrow> cf2sfile s (f # pf) = (
       
   472      case (cf2sfile s pf) of
       
   473        Some (pfi, pfsec, psec, asecs) \<Rightarrow> 
       
   474           (case (sectxt_of_obj s (O_dir (f # pf))) of
       
   475               Some fsec \<Rightarrow> Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
       
   476                                 else Created, fsec, Some pfsec, asecs \<union> {pfsec})
       
   477            | None \<Rightarrow> None)
       
   478      | _ \<Rightarrow> None)"
       
   479 apply (frule is_dir_in_current, drule parentf_is_dir'', simp)
       
   480 apply (frule_tac f = "f # pf" in is_dir_has_sfile, simp)
       
   481 apply (frule_tac f = "pf" in is_dir_has_sfile, simp)
       
   482 apply (frule sroot_set)
       
   483 apply (case_tac pf, (clarsimp simp:get_parentfs_ctxts'_def sectxt_of_pf_def)+) 
       
   484 done  
       
   485 
       
   486 lemma cf2sfile_path:
       
   487   "\<lbrakk>f # pf \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> cf2sfile s (f # pf) = (
       
   488      case (cf2sfile s pf) of
       
   489        Some (pfi, pfsec, psec, asecs) \<Rightarrow> (if (is_file s (f # pf))
       
   490          then (case (sectxt_of_obj s (O_file (f # pf))) of
       
   491                  Some fsec \<Rightarrow> Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
       
   492                                    else Created, fsec, Some pfsec, asecs \<union> {pfsec})
       
   493                | None \<Rightarrow> None)
       
   494          else (case (sectxt_of_obj s (O_dir (f # pf))) of
       
   495                  Some fsec \<Rightarrow> Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
       
   496                                    else Created, fsec, Some pfsec, asecs \<union> {pfsec})
       
   497                | None \<Rightarrow> None)           )
       
   498      | None \<Rightarrow> None)"
       
   499 apply (drule is_file_or_dir, simp)
       
   500 apply (erule disjE)
       
   501 apply (frule cf2sfile_path_file, simp) defer
       
   502 apply (frule cf2sfile_path_dir, simp, drule is_dir_not_file)
       
   503 apply (auto split:option.splits)
       
   504 done
       
   505 
       
   506 lemma cf2sfile_path_file_prop1:
       
   507   "\<lbrakk>is_file s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); valid s\<rbrakk>
       
   508    \<Longrightarrow> \<exists> fsec. cf2sfile s (f # pf) = 
       
   509                  Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
       
   510                        else Created, fsec, Some pfsec, asecs \<union> {pfsec}) \<and> 
       
   511                sectxt_of_obj s (O_file (f # pf)) = Some fsec"
       
   512 apply (frule is_file_has_sfile, simp)
       
   513 by (auto simp:cf2sfile_path_file)
       
   514 
       
   515 lemma cf2sfile_path_file_prop2:
       
   516   "\<lbrakk>is_file s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); 
       
   517     sectxt_of_obj s (O_file (f # pf)) = Some fsec; valid s\<rbrakk> \<Longrightarrow> cf2sfile s (f # pf) = 
       
   518       Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
       
   519             else Created, fsec, Some pfsec, asecs \<union> {pfsec})"
       
   520 by (drule cf2sfile_path_file_prop1, auto)
       
   521 
       
   522 lemma cf2sfile_path_dir_prop1:
       
   523   "\<lbrakk>is_dir s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); valid s\<rbrakk>
       
   524    \<Longrightarrow> \<exists> fsec. cf2sfile s (f # pf) = 
       
   525                  Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
       
   526                        else Created, fsec, Some pfsec, asecs \<union> {pfsec}) \<and> 
       
   527                sectxt_of_obj s (O_dir (f # pf)) = Some fsec"
       
   528 apply (frule is_dir_has_sfile, simp)
       
   529 by (auto simp:cf2sfile_path_dir)
       
   530 
       
   531 lemma cf2sfile_path_dir_prop2:
       
   532   "\<lbrakk>is_dir s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); 
       
   533     sectxt_of_obj s (O_dir (f # pf)) = Some fsec; valid s\<rbrakk> \<Longrightarrow> cf2sfile s (f # pf) = 
       
   534       Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
       
   535             else Created, fsec, Some pfsec, asecs \<union> {pfsec})"
       
   536 by (drule cf2sfile_path_dir_prop1, auto)
       
   537 
       
   538 (**************** cf2sfile event list simpset ****************)
       
   539 
       
   540 lemma cf2sfile_open_none':
       
   541   "valid (Open p f flag fd None # s) \<Longrightarrow> cf2sfile (Open p f flag fd None # s) f'= cf2sfile s f'"
       
   542 apply (frule vd_cons, frule vt_grant_os)
       
   543 apply (induct f', simp add:cf2sfile_def)
       
   544 apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   545                get_parentfs_ctxts_simps)
       
   546 done
       
   547 
       
   548 lemma cf2sfile_open_none:
       
   549   "valid (Open p f flag fd None # s) \<Longrightarrow> cf2sfile (Open p f flag fd None # s) = cf2sfile s"
       
   550 apply (rule ext)
       
   551 by (simp add:cf2sfile_open_none')
       
   552 
       
   553 lemma cf2sfile_open_some1:
       
   554   "\<lbrakk>valid (Open p f flag fd (Some inum) # s); f' \<in> current_files s\<rbrakk>
       
   555    \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f' = cf2sfile s f'"
       
   556 apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
       
   557 apply (case_tac "f = f'", simp)
       
   558 apply (induct f', simp add:sroot_only, simp)
       
   559 apply (frule parentf_in_current', simp+)
       
   560 apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   561                get_parentfs_ctxts_simps)
       
   562 done
       
   563 
       
   564 lemma cf2sfile_open_some2:
       
   565   "\<lbrakk>valid (Open p f flag fd (Some inum) # s); is_file s f'\<rbrakk>
       
   566    \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f' = cf2sfile s f'"
       
   567 apply (frule vd_cons, drule is_file_in_current)
       
   568 by (simp add:cf2sfile_open_some1)
       
   569 
       
   570 lemma cf2sfile_open_some3:
       
   571   "\<lbrakk>valid (Open p f flag fd (Some inum) # s); is_dir s f'\<rbrakk>
       
   572    \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f' = cf2sfile s f'"
       
   573 apply (frule vd_cons, drule is_dir_in_current)
       
   574 by (simp add:cf2sfile_open_some1)
       
   575 
       
   576 lemma cf2sfile_open_some4:
       
   577   "valid (Open p f flag fd (Some inum) # s) \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f = (
       
   578      case (parent f) of
       
   579        Some pf \<Rightarrow> (case (sectxt_of_obj (Open p f flag fd (Some inum) # s) (O_file f), sectxt_of_obj s (O_dir pf), 
       
   580                          get_parentfs_ctxts s pf) of
       
   581                     (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
       
   582                   | _ \<Rightarrow> None)
       
   583      | None \<Rightarrow> None)"
       
   584 apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
       
   585 apply (case_tac f, simp)
       
   586 apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   587                get_parentfs_ctxts_simps)
       
   588 apply (rule impI, (erule conjE)+)
       
   589 apply (drule not_deleted_init_file, simp+)
       
   590 apply (simp add:is_file_in_current)
       
   591 done
       
   592 
       
   593 lemma cf2sfile_open:
       
   594   "\<lbrakk>valid (Open p f flag fd opt # s); f' \<in> current_files (Open p f flag fd opt # s)\<rbrakk>
       
   595    \<Longrightarrow> cf2sfile (Open p f flag fd opt # s) f' = (
       
   596      if (opt = None) then cf2sfile s f'
       
   597      else if (f' = f) 
       
   598      then (case (parent f) of
       
   599              Some pf \<Rightarrow> (case (sectxt_of_obj (Open p f flag fd opt # s) (O_file f), sectxt_of_obj s (O_dir pf), 
       
   600                  get_parentfs_ctxts s pf) of
       
   601                           (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
       
   602                         | _ \<Rightarrow> None)
       
   603            | None \<Rightarrow> None)
       
   604      else cf2sfile s f')"
       
   605 apply (case_tac opt)
       
   606 apply (simp add:cf2sfile_open_none)
       
   607 apply (case_tac "f = f'")
       
   608 apply (simp add:cf2sfile_open_some4 split:option.splits)
       
   609 apply (simp add:cf2sfile_open_some1 current_files_simps)
       
   610 done
       
   611 
       
   612 lemma cf2sfile_mkdir1:
       
   613   "\<lbrakk>valid (Mkdir p f i # s); f' \<in> current_files s\<rbrakk>
       
   614    \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = cf2sfile s f'"
       
   615 apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
       
   616 apply (case_tac "f = f'", simp)
       
   617 apply (induct f', simp add:sroot_only, simp)
       
   618 apply (frule parentf_in_current', simp+)
       
   619 apply (case_tac "f = f'", simp)
       
   620 apply (simp add:cf2sfile_path is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   621                get_parentfs_ctxts_simps split:if_splits option.splits)
       
   622 done
       
   623 
       
   624 lemma cf2sfile_mkdir2:
       
   625   "\<lbrakk>valid (Mkdir p f i # s); is_file s f'\<rbrakk>
       
   626    \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = cf2sfile s f'"
       
   627 apply (frule vd_cons, drule is_file_in_current)
       
   628 by (simp add:cf2sfile_mkdir1)
       
   629 
       
   630 lemma cf2sfile_mkdir3:
       
   631   "\<lbrakk>valid (Mkdir p f i # s); is_dir s f'\<rbrakk>
       
   632    \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = cf2sfile s f'"
       
   633 apply (frule vd_cons, drule is_dir_in_current)
       
   634 by (simp add:cf2sfile_mkdir1)
       
   635 
       
   636 lemma cf2sfile_mkdir4:
       
   637   "valid (Mkdir p f i # s)
       
   638   \<Longrightarrow> cf2sfile (Mkdir p f i # s) f = (case (parent f) of
       
   639          Some pf \<Rightarrow> (case (sectxt_of_obj (Mkdir p f i # s) (O_dir f), sectxt_of_obj s (O_dir pf), 
       
   640                            get_parentfs_ctxts s pf) of
       
   641                       (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
       
   642                     | _ \<Rightarrow> None)
       
   643        | None \<Rightarrow> None)"
       
   644 apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
       
   645 apply (case_tac f, simp)
       
   646 apply (clarsimp simp:os_grant.simps)
       
   647 apply (simp add:sectxt_of_obj_simps)
       
   648 apply (frule current_proc_has_sec, simp)
       
   649 apply (frule is_dir_has_sec, simp)
       
   650 apply (frule get_pfs_secs_prop, simp)
       
   651 apply (frule is_dir_not_file)
       
   652 apply (auto simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   653                get_parentfs_ctxts_simps split:option.splits if_splits 
       
   654             dest:not_deleted_init_dir is_dir_in_current not_deleted_init_file is_file_in_current)
       
   655 done
       
   656 
       
   657 lemma cf2sfile_mkdir:
       
   658   "\<lbrakk>valid (Mkdir p f i # s); f' \<in> current_files (Mkdir p f i # s)\<rbrakk>
       
   659   \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = (
       
   660     if (f' = f) 
       
   661     then (case (parent f) of
       
   662              Some pf \<Rightarrow> (case (sectxt_of_obj (Mkdir p f i # s) (O_dir f), sectxt_of_obj s (O_dir pf), 
       
   663                  get_parentfs_ctxts s pf) of
       
   664                           (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
       
   665                         | _ \<Rightarrow> None)
       
   666            | None \<Rightarrow> None)
       
   667      else cf2sfile s f')"
       
   668 apply (case_tac "f = f'")
       
   669 apply (simp add:cf2sfile_mkdir4 split:option.splits)
       
   670 apply (simp add:cf2sfile_mkdir1 current_files_simps)
       
   671 done
       
   672 
       
   673 lemma cf2sfile_linkhard1:
       
   674   "\<lbrakk>valid (LinkHard p oldf f # s); f' \<in> current_files s\<rbrakk>
       
   675    \<Longrightarrow> cf2sfile (LinkHard p oldf f# s) f' = cf2sfile s f'"
       
   676 apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
       
   677 apply (case_tac "f = f'", simp)
       
   678 apply (induct f', simp add:sroot_only, simp)
       
   679 apply (frule parentf_in_current', simp+)
       
   680 apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   681                get_parentfs_ctxts_simps split:if_splits option.splits)
       
   682 done
       
   683 
       
   684 lemma cf2sfile_linkhard2:
       
   685   "\<lbrakk>valid (LinkHard p oldf f # s); is_file s f'\<rbrakk>
       
   686    \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f' = cf2sfile s f'"
       
   687 apply (frule vd_cons, drule is_file_in_current)
       
   688 by (simp add:cf2sfile_linkhard1)
       
   689 
       
   690 lemma cf2sfile_linkhard3:
       
   691   "\<lbrakk>valid (LinkHard p oldf f # s); is_dir s f'\<rbrakk>
       
   692    \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f' = cf2sfile s f'"
       
   693 apply (frule vd_cons, drule is_dir_in_current)
       
   694 by (simp add:cf2sfile_linkhard1)
       
   695 
       
   696 lemma cf2sfile_linkhard4:
       
   697   "valid (LinkHard p oldf f # s)
       
   698   \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f = (case (parent f) of
       
   699          Some pf \<Rightarrow> (case (sectxt_of_obj (LinkHard p oldf f # s) (O_file f), sectxt_of_obj s (O_dir pf), 
       
   700                            get_parentfs_ctxts s pf) of
       
   701                       (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
       
   702                     | _ \<Rightarrow> None)
       
   703        | None \<Rightarrow> None)"
       
   704 apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
       
   705 apply (case_tac f, simp)
       
   706 apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
       
   707                get_parentfs_ctxts_simps)
       
   708 apply (rule impI, (erule conjE)+)
       
   709 apply (drule not_deleted_init_file, simp+)
       
   710 apply (simp add:is_file_in_current)
       
   711 done
       
   712 
       
   713 lemma cf2sfile_linkhard:
       
   714   "\<lbrakk>valid (LinkHard p oldf f # s); f' \<in> current_files (LinkHard p oldf f # s)\<rbrakk>
       
   715   \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f' = (
       
   716     if (f' = f) 
       
   717     then (case (parent f) of
       
   718              Some pf \<Rightarrow> (case (sectxt_of_obj (LinkHard p oldf f # s) (O_file f), sectxt_of_obj s (O_dir pf), 
       
   719                  get_parentfs_ctxts s pf) of
       
   720                           (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
       
   721                         | _ \<Rightarrow> None)
       
   722            | None \<Rightarrow> None)
       
   723      else cf2sfile s f')"
       
   724 apply (case_tac "f = f'")
       
   725 apply (simp add:cf2sfile_linkhard4 split:option.splits)
       
   726 apply (simp add:cf2sfile_linkhard1 current_files_simps)
       
   727 done
       
   728 
       
   729 lemma cf2sfile_other:
       
   730   "\<lbrakk>ff \<in> current_files s;
       
   731     \<forall> p f flag fd opt. e \<noteq> Open p f flag fd opt;
       
   732     \<forall> p fd. e \<noteq> CloseFd p fd;
       
   733     \<forall> p f. e \<noteq> UnLink p f;
       
   734     \<forall> p f. e \<noteq> Rmdir p f;
       
   735     \<forall> p f i. e \<noteq> Mkdir p f i;
       
   736     \<forall> p f f'. e \<noteq> LinkHard p f f'; 
       
   737     valid (e # s)\<rbrakk> \<Longrightarrow> cf2sfile (e # s) ff = cf2sfile s ff"
       
   738 apply (frule vd_cons, frule vt_grant_os)
       
   739 apply (induct ff, simp add:sroot_only)
       
   740 apply (frule parentf_in_current', simp+, case_tac e)
       
   741 apply (auto simp:current_files_simps is_file_simps is_dir_simps sectxt_of_obj_simps cf2sfile_path 
       
   742            split:if_splits option.splits)                     
       
   743 done     
       
   744 
       
   745 lemma cf2sfile_other':
       
   746   "\<lbrakk>valid (e # s); 
       
   747     \<forall> p f flag fd opt. e \<noteq> Open p f flag fd opt;
       
   748     \<forall> p fd. e \<noteq> CloseFd p fd;
       
   749     \<forall> p f. e \<noteq> UnLink p f;
       
   750     \<forall> p f. e \<noteq> Rmdir p f;
       
   751     \<forall> p f i. e \<noteq> Mkdir p f i;
       
   752     \<forall> p f f'. e \<noteq> LinkHard p f f'; 
       
   753     ff \<in> current_files s\<rbrakk> \<Longrightarrow> cf2sfile (e # s) ff = cf2sfile s ff"
       
   754 by (auto intro!:cf2sfile_other)
       
   755   
       
   756 lemma cf2sfile_unlink:
       
   757   "\<lbrakk>valid (UnLink p f # s); f' \<in> current_files (UnLink p f # s)\<rbrakk>
       
   758    \<Longrightarrow> cf2sfile (UnLink p f # s) f' = cf2sfile s f'"
       
   759 apply (frule vd_cons, frule vt_grant_os)
       
   760 apply (simp add:current_files_simps split:if_splits)
       
   761 apply (auto simp:cf2sfile_def sectxt_of_obj_simps get_parentfs_ctxts_simps is_file_simps is_dir_simps
       
   762            split:if_splits option.splits)
       
   763 done
       
   764 
       
   765 lemma cf2sfile_rmdir:
       
   766   "\<lbrakk>valid (Rmdir p f # s); f' \<in> current_files (Rmdir p f # s)\<rbrakk>
       
   767    \<Longrightarrow> cf2sfile (Rmdir p f # s) f' = cf2sfile s f'"
       
   768 apply (frule vd_cons, frule vt_grant_os)
       
   769 apply (simp add:current_files_simps split:if_splits)
       
   770 apply (auto simp:cf2sfile_def sectxt_of_obj_simps get_parentfs_ctxts_simps is_file_simps is_dir_simps
       
   771            split:if_splits option.splits)
       
   772 done
       
   773 
       
   774 lemma pfdof_simp5: "\<lbrakk>proc_fd_of_file s f = {(p, fd)}; file_of_proc_fd s p fd = None\<rbrakk> \<Longrightarrow> False"
       
   775 apply (subgoal_tac "(p, fd) \<in> proc_fd_of_file s f")
       
   776 by (simp add:pfdof_simp2, simp)
       
   777 
       
   778 lemma pfdof_simp6: "proc_fd_of_file s f = {(p, fd)} \<Longrightarrow> file_of_proc_fd s p fd = Some f"
       
   779 apply (subgoal_tac "(p, fd) \<in> proc_fd_of_file s f")
       
   780 by (simp add:pfdof_simp2, simp)
       
   781 
       
   782 lemma cf2sfile_closefd:
       
   783   "\<lbrakk>valid (CloseFd p fd # s); f \<in> current_files (CloseFd p fd # s)\<rbrakk>
       
   784    \<Longrightarrow> cf2sfile (CloseFd p fd # s) f = cf2sfile s f"
       
   785 apply (frule vd_cons, frule vt_grant_os)
       
   786 apply (simp add:current_files_simps split:if_splits option.splits) 
       
   787 (* costs too much time, but solved *)
       
   788 
       
   789 apply (auto simp:cf2sfile_def sectxt_of_obj_simps get_parentfs_ctxts_simps is_file_simps is_dir_simps 
       
   790            split:if_splits option.splits  
       
   791             dest:init_file_dir_conflict pfdof_simp5 pfdof_simp6 file_of_pfd_is_file
       
   792                  not_deleted_init_file not_deleted_init_dir is_file_not_dir is_dir_not_file
       
   793             dest!:current_has_sec')
       
   794 done
       
   795 
       
   796 lemmas cf2sfile_simps = cf2sfile_open cf2sfile_mkdir cf2sfile_linkhard cf2sfile_other
       
   797   cf2sfile_unlink cf2sfile_rmdir cf2sfile_closefd
       
   798   
       
   799 (*********** cfd2sfd simpset *********)
       
   800 
       
   801 lemma cfd2sfd_open1:
       
   802   "valid (Open p f flags fd opt # s)
       
   803    \<Longrightarrow> cfd2sfd (Open p f flags fd opt # s) p fd = 
       
   804      (case (sectxt_of_obj (Open p f flags fd opt # s) (O_fd p fd), cf2sfile (Open p f flags fd opt # s) f) of
       
   805         (Some sec, Some sf) \<Rightarrow> Some (sec, flags, sf)
       
   806       | _ \<Rightarrow> None)"
       
   807 by (simp add:cfd2sfd_def sectxt_of_obj_simps split:if_splits)
       
   808 
       
   809 lemma cfd2sfd_open_some2:
       
   810   "\<lbrakk>valid (Open p f flags fd (Some inum) # s); file_of_proc_fd s p' fd' = Some f'\<rbrakk>
       
   811   \<Longrightarrow> cfd2sfd (Open p f flags fd (Some inum) # s) p' fd' = cfd2sfd s p' fd'"
       
   812 apply (frule vd_cons, frule vt_grant_os)
       
   813 apply (frule proc_fd_in_fds, simp)
       
   814 apply (frule file_of_proc_fd_in_curf, simp)
       
   815 apply (case_tac "f = f'", simp)
       
   816 apply (simp add:cfd2sfd_def sectxt_of_obj_simps cf2sfile_open_some1)
       
   817 apply (case_tac "p = p'", simp)
       
   818 apply (rule conjI, rule impI, simp)
       
   819 apply (drule cf2sfile_open_some1, simp)
       
   820 apply (auto split:option.splits)[1]
       
   821 apply simp
       
   822 apply (drule cf2sfile_open_some1, simp)
       
   823 apply (auto split:option.splits)[1]
       
   824 done
       
   825 
       
   826 lemma cfd2sfd_open_none2:
       
   827   "\<lbrakk>valid (Open p f flags fd None # s); file_of_proc_fd s p' fd' = Some f'\<rbrakk>
       
   828   \<Longrightarrow> cfd2sfd (Open p f flags fd None # s) p' fd' = cfd2sfd s p' fd'"
       
   829 apply (frule vd_cons, frule vt_grant_os)
       
   830 apply (frule proc_fd_in_fds, simp)
       
   831 apply (frule file_of_proc_fd_in_curf, simp)
       
   832 apply (simp add:cfd2sfd_def sectxt_of_obj_simps cf2sfile_open_none)
       
   833 apply (case_tac "p = p'", simp)
       
   834 apply (rule conjI, rule impI, simp)
       
   835 apply (drule cf2sfile_open_none)
       
   836 apply (auto split:option.splits)[1]
       
   837 apply simp
       
   838 apply (drule cf2sfile_open_none)
       
   839 apply (auto split:option.splits)[1]
       
   840 done
       
   841   
       
   842 lemma cfd2sfd_open2:
       
   843   "\<lbrakk>valid (Open p f flags fd opt # s); file_of_proc_fd s p' fd' = Some f'\<rbrakk>
       
   844   \<Longrightarrow> cfd2sfd (Open p f flags fd opt # s) p' fd' = cfd2sfd s p' fd'"
       
   845 apply (case_tac opt)
       
   846 apply (simp add:cfd2sfd_open_none2)
       
   847 apply (simp add:cfd2sfd_open_some2)
       
   848 done
       
   849 
       
   850 lemma cfd2sfd_open:
       
   851   "\<lbrakk>valid (Open p f flags fd opt # s); file_of_proc_fd (Open p f flags fd opt # s) p' fd' = Some f'\<rbrakk>
       
   852    \<Longrightarrow> cfd2sfd (Open p f flags fd opt # s) p' fd' = (if (p' = p \<and> fd' = fd) then 
       
   853      (case (sectxt_of_obj (Open p f flags fd opt # s) (O_fd p fd), cf2sfile (Open p f flags fd opt # s) f) of
       
   854         (Some sec, Some sf) \<Rightarrow> Some (sec, flags, sf)
       
   855       | _ \<Rightarrow> None)         else cfd2sfd s p' fd')"
       
   856 apply (simp split:if_splits)
       
   857 apply (simp add:cfd2sfd_open1 split:option.splits)
       
   858 apply (simp add:cfd2sfd_open2)
       
   859 apply (rule impI, simp)
       
   860 done
       
   861 
       
   862 lemma cfd2sfd_closefd:
       
   863   "\<lbrakk>valid (CloseFd p fd # s); file_of_proc_fd (CloseFd p fd # s) p' fd' = Some f\<rbrakk>
       
   864    \<Longrightarrow> cfd2sfd (CloseFd p fd # s) p' fd' = cfd2sfd  s p' fd'"
       
   865 apply (frule vd_cons, frule vt_grant_os)
       
   866 apply (frule proc_fd_in_fds, simp)
       
   867 apply (frule file_of_proc_fd_in_curf, simp)
       
   868 apply (frule cf2sfile_closefd, simp)
       
   869 apply (simp add:cfd2sfd_def sectxt_of_obj_simps)
       
   870 apply (auto split:option.splits if_splits)
       
   871 done
       
   872 
       
   873 lemma cfd2sfd_clone:
       
   874   "\<lbrakk>valid (Clone p p' fds shms # s); file_of_proc_fd (Clone p p' fds shms # s) p'' fd' = Some f\<rbrakk>
       
   875    \<Longrightarrow> cfd2sfd (Clone p p' fds shms # s) p'' fd' = (
       
   876      if (p'' = p') then cfd2sfd s p fd'
       
   877      else cfd2sfd s p'' fd')"
       
   878 apply (frule vd_cons, frule vt_grant_os)
       
   879 apply (frule proc_fd_in_fds, simp)
       
   880 apply (frule file_of_proc_fd_in_curf, simp, simp add:current_files_simps)
       
   881 apply (frule_tac cf2sfile_other', simp+)
       
   882 apply (simp add:cfd2sfd_def sectxt_of_obj_simps)
       
   883 apply (case_tac "p'' = p'", simp)
       
   884 apply (auto split:option.splits if_splits)[1]
       
   885 apply (simp)
       
   886 apply (auto split:option.splits if_splits)[1]
       
   887 done
       
   888 
       
   889 lemma cfd2sfd_execve:
       
   890   "\<lbrakk>valid (Execve p f fds # s); file_of_proc_fd (Execve p f fds # s) p' fd' = Some f'\<rbrakk>
       
   891    \<Longrightarrow> cfd2sfd (Execve p f fds # s) p' fd' = cfd2sfd s p' fd'"
       
   892 apply (frule vd_cons, frule vt_grant_os)
       
   893 apply (frule proc_fd_in_fds, simp)
       
   894 apply (frule file_of_proc_fd_in_curf, simp, simp add:current_files_simps)
       
   895 apply (frule_tac cf2sfile_other', simp+)
       
   896 apply (simp add:cfd2sfd_def sectxt_of_obj_simps)
       
   897 apply (case_tac "p' = p", simp)
       
   898 apply (auto split:option.splits if_splits)[1]
       
   899 apply (simp)
       
   900 apply (auto split:option.splits if_splits)[1]
       
   901 done
       
   902 
       
   903 lemma cfd2sfd_kill:
       
   904   "\<lbrakk>valid (Kill p p'' # s); file_of_proc_fd (Kill p p'' # s) p' fd' = Some f'\<rbrakk>
       
   905    \<Longrightarrow> cfd2sfd (Kill p p'' # s) p' fd' = cfd2sfd s p' fd'"
       
   906 apply (frule vd_cons, frule vt_grant_os)
       
   907 apply (frule proc_fd_in_fds, simp)
       
   908 apply (frule proc_fd_in_procs, simp)
       
   909 apply (frule file_of_proc_fd_in_curf, simp, simp add:current_files_simps)
       
   910 apply (frule_tac cf2sfile_other', simp+)
       
   911 apply (simp add:cfd2sfd_def sectxt_of_obj_simps)
       
   912 apply (auto split:option.splits if_splits)
       
   913 done
       
   914 
       
   915 lemma cfd2sfd_exit:
       
   916   "\<lbrakk>valid (Exit p # s); file_of_proc_fd (Exit p # s) p' fd' = Some f'\<rbrakk>
       
   917    \<Longrightarrow> cfd2sfd (Exit p # s) p' fd' = cfd2sfd s p' fd'"
       
   918 apply (frule vd_cons, frule vt_grant_os)
       
   919 apply (frule proc_fd_in_fds, simp)
       
   920 apply (frule proc_fd_in_procs, simp)
       
   921 apply (frule file_of_proc_fd_in_curf, simp, simp add:current_files_simps)
       
   922 apply (frule_tac cf2sfile_other', simp+)
       
   923 apply (simp add:cfd2sfd_def sectxt_of_obj_simps)
       
   924 apply (auto split:option.splits if_splits)
       
   925 done
       
   926 
       
   927 lemma cfd2sfd_other:
       
   928   "\<lbrakk>valid (e # s); file_of_proc_fd (e # s) p' fd' = Some f';
       
   929     \<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
       
   930     \<forall> p p'' fds shms. e \<noteq> Clone p p'' fds shms\<rbrakk>
       
   931    \<Longrightarrow> cfd2sfd (e # s) p' fd' = cfd2sfd s p' fd'"
       
   932 apply (frule vd_cons, frule vt_grant_os)
       
   933 apply (frule proc_fd_in_fds, simp)
       
   934 apply (frule proc_fd_in_procs, simp)
       
   935 apply (frule file_of_proc_fd_in_curf, simp)
       
   936 apply (case_tac e)
       
   937 apply (auto intro!:cfd2sfd_execve cfd2sfd_closefd cfd2sfd_kill cfd2sfd_exit)
       
   938 apply (auto simp:cfd2sfd_def sectxt_of_obj_simps current_files_simps cf2sfile_simps split:option.splits)
       
   939 apply (auto dest!:current_has_sec' dest:file_of_proc_fd_in_curf proc_fd_in_fds)
       
   940 done
       
   941 
       
   942 lemmas cfd2sfd_simps = cfd2sfd_open cfd2sfd_clone cfd2sfd_other
       
   943 
       
   944 (********** cpfd2sfds simpset **********)
       
   945 
       
   946 lemma current_filefd_has_flags:
       
   947   "\<lbrakk>file_of_proc_fd s p fd = Some f; valid s\<rbrakk> \<Longrightarrow> \<exists> flags. flags_of_proc_fd s p fd = Some flags"
       
   948 apply (induct s arbitrary:p)
       
   949 apply (simp only:flags_of_proc_fd.simps file_of_proc_fd.simps init_filefd_prop4)
       
   950 apply (frule vd_cons, frule vt_grant_os, case_tac a)
       
   951 apply (auto split:if_splits option.splits dest:proc_fd_in_fds)
       
   952 done
       
   953 
       
   954 lemma current_filefd_has_flags':
       
   955   "\<lbrakk>flags_of_proc_fd s p fd = None; valid s\<rbrakk> \<Longrightarrow> file_of_proc_fd s p fd = None"
       
   956 apply (case_tac "file_of_proc_fd s p fd")
       
   957 apply (simp, drule current_filefd_has_flags, simp+)
       
   958 done
       
   959 
       
   960 lemma current_file_has_sfile':
       
   961   "\<lbrakk>cf2sfile s f = None; valid s\<rbrakk> \<Longrightarrow> f \<notin> current_files s"
       
   962 by (rule notI, drule current_file_has_sfile, simp+)
       
   963 
       
   964 lemma current_filefd_has_sfd:
       
   965   "\<lbrakk>file_of_proc_fd s p fd = Some f; valid s\<rbrakk> \<Longrightarrow> \<exists>sfd. cfd2sfd s p fd = Some sfd"
       
   966 by (auto simp:cfd2sfd_def split:option.splits dest!:current_has_sec' current_file_has_sfile' 
       
   967          dest:file_of_proc_fd_in_curf proc_fd_in_fds current_filefd_has_flags)
       
   968 
       
   969 lemma current_filefd_has_sfd':
       
   970   "\<lbrakk>cfd2sfd s p fd = None; valid s\<rbrakk> \<Longrightarrow> file_of_proc_fd s p fd = None"
       
   971 by (case_tac "file_of_proc_fd s p fd", auto dest:current_filefd_has_sfd)
       
   972 
       
   973 lemma cpfd2sfds_open1:
       
   974   "valid (Open p f flags fd opt # s) \<Longrightarrow>
       
   975    cpfd2sfds (Open p f flags fd opt # s) p = (
       
   976     case (cfd2sfd (Open p f flags fd opt # s) p fd) of
       
   977         Some sfd \<Rightarrow> (cpfd2sfds s p) \<union> {sfd}
       
   978       | _ \<Rightarrow> cpfd2sfds s p)"
       
   979 apply (frule vd_cons, frule vt_grant_os)
       
   980 apply (split option.splits)
       
   981 apply (rule conjI, rule impI, drule current_filefd_has_sfd', simp, simp)
       
   982 apply (rule allI, rule impI)
       
   983 apply (rule set_eqI, rule iffI)
       
   984 apply (case_tac "x = a", simp)
       
   985 unfolding cpfd2sfds_def
       
   986 apply (erule CollectE, (erule conjE|erule bexE)+)
       
   987 apply (simp add:proc_file_fds_def split:if_splits)
       
   988 apply (erule exE, rule_tac x = fda in exI)
       
   989 apply (simp add:cfd2sfd_open2)
       
   990 apply (case_tac "x = a", simp add:proc_file_fds_def)
       
   991 apply (rule_tac x = fd in exI, simp+)
       
   992 apply (erule conjE|erule bexE)+
       
   993 apply (rule_tac x = fda in bexI)
       
   994 apply (simp add:proc_file_fds_def, erule exE)
       
   995 apply (simp add:cfd2sfd_open2)
       
   996 apply (simp add:proc_file_fds_def)
       
   997 done
       
   998 
       
   999 lemma cpfd2sfds_open1':
       
  1000   "valid (Open p f flags fd opt # s) \<Longrightarrow>
       
  1001    cpfd2sfds (Open p f flags fd opt # s) p = (
       
  1002     case (sectxt_of_obj (Open p f flags fd opt # s) (O_fd p fd), cf2sfile (Open p f flags fd opt # s) f) of
       
  1003         (Some sec, Some sf) \<Rightarrow> (cpfd2sfds s p) \<union> {(sec, flags, sf)}
       
  1004       | _ \<Rightarrow> cpfd2sfds s p)"
       
  1005 apply (frule cfd2sfd_open1)
       
  1006 apply (auto dest:cpfd2sfds_open1 split:option.splits)
       
  1007 done
       
  1008 
       
  1009 lemma cpfd2sfds_open2:
       
  1010   "\<lbrakk>valid (Open p f flags fd opt # s); p' \<noteq> p\<rbrakk> \<Longrightarrow> cpfd2sfds (Open p f flags fd opt # s) p' = cpfd2sfds s p'"
       
  1011 apply (frule vt_grant_os, frule vd_cons)
       
  1012 unfolding cpfd2sfds_def
       
  1013 apply (rule set_eqI, rule iffI)
       
  1014 apply (simp add:proc_file_fds_def)
       
  1015 apply (erule exE|erule conjE)+
       
  1016 apply (simp only:file_of_proc_fd.simps cfd2sfd_open2 split:if_splits)
       
  1017 apply (rule_tac x = fda in exI, simp)
       
  1018 apply (simp add:proc_file_fds_def)
       
  1019 apply (erule exE|erule conjE)+
       
  1020 apply (rule_tac x = fda in exI, simp add:cfd2sfd_open2)
       
  1021 done
       
  1022 
       
  1023 lemma cpfd2sfds_open:
       
  1024   "valid (Open p f flags fd opt # s)
       
  1025    \<Longrightarrow> cpfd2sfds (Open p f flags fd opt # s) = (cpfd2sfds s) (p := (
       
  1026     case (sectxt_of_obj (Open p f flags fd opt # s) (O_fd p fd), cf2sfile (Open p f flags fd opt # s) f) of
       
  1027         (Some sec, Some sf) \<Rightarrow> (cpfd2sfds s p) \<union> {(sec, flags, sf)}
       
  1028       | _ \<Rightarrow> cpfd2sfds s p))"
       
  1029 apply (rule ext)
       
  1030 apply (case_tac "x \<noteq> p")
       
  1031 apply (simp add:cpfd2sfds_open2)
       
  1032 apply (simp add:cpfd2sfds_open1')
       
  1033 done
       
  1034 
       
  1035 lemma cpfd2sfds_execve:
       
  1036   "valid (Execve p f fds # s) 
       
  1037    \<Longrightarrow> cpfd2sfds (Execve p f fds # s) = (cpfd2sfds s) (p := {sfd. \<exists> fd \<in> fds. \<exists> f. file_of_proc_fd s p fd = Some f \<and> cfd2sfd s p fd = Some sfd})"
       
  1038 apply (frule vd_cons, frule vt_grant_os)
       
  1039 apply (rule ext)
       
  1040 apply (rule set_eqI, rule iffI)
       
  1041 unfolding cpfd2sfds_def proc_file_fds_def
       
  1042 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1043 apply (simp split:if_splits)
       
  1044 apply (frule_tac p' = p and fd' = fd in cfd2sfd_other, simp+)
       
  1045 apply (rule_tac x = fd in bexI, simp+)
       
  1046 apply (simp add:cpfd2sfds_def proc_file_fds_def)
       
  1047 apply (frule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1048 apply (rule_tac x = fd in exI, simp)
       
  1049 apply (simp split:if_splits)
       
  1050 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1051 apply (rule_tac x = fd in exI, simp)
       
  1052 apply (frule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1053 apply (simp add:cpfd2sfds_def proc_file_fds_def)
       
  1054 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1055 apply (rule_tac x = fd in exI, simp)
       
  1056 apply (frule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1057 done
       
  1058 
       
  1059 lemma cpfd2sfds_clone:
       
  1060   "valid (Clone p p' fds shms # s) 
       
  1061    \<Longrightarrow> cpfd2sfds (Clone p p' fds shms # s) = (cpfd2sfds s) (p' := {sfd. \<exists> fd \<in> fds. \<exists> f. file_of_proc_fd s p fd = Some f \<and> cfd2sfd s p fd = Some sfd})"
       
  1062 apply (frule vd_cons, frule vt_grant_os)
       
  1063 apply (rule ext)
       
  1064 apply (rule set_eqI, rule iffI)
       
  1065 unfolding cpfd2sfds_def proc_file_fds_def
       
  1066 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1067 apply (simp split:if_splits)
       
  1068 apply (frule_tac p'' = p' and fd' = fd in cfd2sfd_clone, simp+)
       
  1069 apply (rule_tac x = fd in bexI, simp+)
       
  1070 apply (simp add:cpfd2sfds_def proc_file_fds_def)
       
  1071 apply (frule_tac p'' = x and fd' = fd in cfd2sfd_clone, simp+)
       
  1072 apply (rule_tac x = fd in exI, simp)
       
  1073 apply (simp split:if_splits)
       
  1074 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1075 apply (rule_tac x = fd in exI, simp)
       
  1076 apply (frule_tac p'' = p' and fd' = fd in cfd2sfd_clone, simp+)
       
  1077 apply (simp add:cpfd2sfds_def proc_file_fds_def)
       
  1078 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1079 apply (rule_tac x = fd in exI, simp)
       
  1080 apply (frule_tac p'' = x and fd' = fd in cfd2sfd_clone, simp+)
       
  1081 done
       
  1082 
       
  1083 lemma cpfd2sfds_other:
       
  1084   "\<lbrakk>valid (e # s);
       
  1085     \<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
       
  1086     \<forall> p f fds. e \<noteq> Execve p f fds;
       
  1087     \<forall> p p'. e \<noteq> Kill p p';
       
  1088     \<forall> p. e \<noteq> Exit p;
       
  1089     \<forall> p fd. e \<noteq> CloseFd p fd;
       
  1090     \<forall> p p' fds shms. e \<noteq> Clone p p' fds shms\<rbrakk> \<Longrightarrow> cpfd2sfds (e # s) = cpfd2sfds s"
       
  1091 apply (frule vd_cons, frule vt_grant_os)
       
  1092 apply (rule ext)
       
  1093 unfolding cpfd2sfds_def proc_file_fds_def
       
  1094 apply (case_tac e)
       
  1095 using cfd2sfd_other
       
  1096 by auto
       
  1097 
       
  1098 lemma cpfd2sfds_kill:
       
  1099   "valid (Kill p p' # s) \<Longrightarrow> cpfd2sfds (Kill p p' # s) = (cpfd2sfds s) (p' := {})"
       
  1100 apply (frule vd_cons, frule vt_grant_os)
       
  1101 apply (rule ext, rule set_eqI)
       
  1102 unfolding cpfd2sfds_def proc_file_fds_def
       
  1103 apply (rule iffI)
       
  1104 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1105 apply (simp split:if_splits add: cpfd2sfds_def proc_file_fds_def)
       
  1106 apply (rule_tac x = fd in exI, simp)
       
  1107 apply (drule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1108 apply (simp split:if_splits add: cpfd2sfds_def proc_file_fds_def)
       
  1109 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1110 apply (rule_tac x = fd in exI, simp)
       
  1111 apply (drule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1112 done
       
  1113 
       
  1114 lemma cpfd2sfds_exit:
       
  1115   "valid (Exit p # s) \<Longrightarrow> cpfd2sfds (Exit p # s) = (cpfd2sfds s) (p := {})"
       
  1116 apply (frule vd_cons, frule vt_grant_os)
       
  1117 apply (rule ext, rule set_eqI)
       
  1118 unfolding cpfd2sfds_def proc_file_fds_def
       
  1119 apply (rule iffI)
       
  1120 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1121 apply (simp split:if_splits add: cpfd2sfds_def proc_file_fds_def)
       
  1122 apply (rule_tac x = fd in exI, simp)
       
  1123 apply (drule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1124 apply (simp split:if_splits add: cpfd2sfds_def proc_file_fds_def)
       
  1125 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1126 apply (rule_tac x = fd in exI, simp)
       
  1127 apply (drule_tac p' = x and fd' = fd in cfd2sfd_other, simp+)
       
  1128 done
       
  1129 
       
  1130 lemma cpfd2sfds_closefd:
       
  1131   "valid (CloseFd p fd # s) \<Longrightarrow> cpfd2sfds (CloseFd p fd # s) = (cpfd2sfds s) (p := 
       
  1132      if (fd \<in> proc_file_fds s p)
       
  1133      then (case (cfd2sfd s p fd) of 
       
  1134              Some sfd \<Rightarrow> (if (\<exists> fd' f'. fd' \<noteq> fd \<and> file_of_proc_fd s p fd' = Some f' \<and> cfd2sfd s p fd' = Some sfd)
       
  1135                           then cpfd2sfds s p else cpfd2sfds s p - {sfd})
       
  1136            | _        \<Rightarrow> cpfd2sfds s p)
       
  1137      else cpfd2sfds s p)"
       
  1138 apply (frule vd_cons)
       
  1139 apply (rule ext, rule set_eqI, rule iffI)
       
  1140 unfolding cpfd2sfds_def proc_file_fds_def
       
  1141 apply (erule CollectE| erule bexE| erule conjE| erule exE| rule conjI)+
       
  1142 apply (simp split:if_splits)
       
  1143 apply (rule conjI, rule impI, rule conjI, rule impI, erule exE)
       
  1144 apply (frule_tac p = p and fd = fd in current_filefd_has_sfd, simp)
       
  1145 apply (erule exE, simp)
       
  1146 apply (rule conjI, rule impI, (erule exE|erule conjE)+)
       
  1147 apply (rule_tac x = fda in exI, simp, simp add:cfd2sfd_closefd)
       
  1148 
       
  1149 apply (rule impI, rule conjI)
       
  1150 apply (rule_tac x = fda in exI, simp, simp add:cfd2sfd_closefd)
       
  1151 apply (rule notI, simp)
       
  1152 apply (erule_tac x = fda in allE, simp add:cfd2sfd_closefd)
       
  1153 
       
  1154 apply (rule impI, simp add:cpfd2sfds_def proc_file_fds_def)
       
  1155 apply (erule exE, rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1156 
       
  1157 apply (rule impI| rule conjI)+
       
  1158 apply (rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1159 
       
  1160 apply (rule impI, simp add:cpfd2sfds_def proc_file_fds_def)
       
  1161 apply (rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1162 
       
  1163 apply (simp split:if_splits)
       
  1164 apply (frule_tac p = p and fd = fd in current_filefd_has_sfd, simp)
       
  1165 apply (erule exE, simp)
       
  1166 apply (case_tac "\<exists>fd'. fd' \<noteq> fd \<and> (\<exists>f'. file_of_proc_fd s p fd' = Some f') \<and> cfd2sfd s p fd' = Some sfd")
       
  1167 apply simp
       
  1168 apply (case_tac "xa = sfd")
       
  1169 apply (erule exE|erule conjE)+
       
  1170 apply (rule_tac x = fd' in exI, simp add:cfd2sfd_closefd)
       
  1171 apply (erule exE|erule conjE)+
       
  1172 apply (rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1173 apply (rule notI, simp)
       
  1174 apply (simp, (erule exE|erule conjE)+)
       
  1175 apply (rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1176 apply (rule notI, simp)
       
  1177 apply (erule exE|erule conjE)+
       
  1178 apply (rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1179 apply (rule notI, simp)
       
  1180 apply (simp add:cpfd2sfds_def proc_file_fds_def)
       
  1181 apply (erule exE|erule conjE)+
       
  1182 apply (rule_tac x = fda in exI, simp add:cfd2sfd_closefd)
       
  1183 done
       
  1184 
       
  1185 lemmas cpfd2sfds_simps = cpfd2sfds_open cpfd2sfds_execve cpfd2sfds_clone cpfd2sfds_kill cpfd2sfds_exit
       
  1186   cpfd2sfds_closefd cpfd2sfds_other
       
  1187 
       
  1188 (********* ch2sshm simpset ********)
       
  1189 
       
  1190 lemma ch2sshm_createshm:
       
  1191   "valid (CreateShM p h # s) 
       
  1192    \<Longrightarrow> ch2sshm (CreateShM p h # s) = (ch2sshm s) (h := 
       
  1193      (case (sectxt_of_obj (CreateShM p h # s) (O_shm h)) of
       
  1194                     Some sec \<Rightarrow> 
       
  1195  Some (if (\<not> deleted (O_shm h) s \<and> h \<in> init_shms) then Init h else Created, sec)
       
  1196                   | _ \<Rightarrow> None))"
       
  1197 apply (frule vd_cons, frule vt_grant_os)
       
  1198 apply (auto simp:ch2sshm_def sectxt_of_obj_simps dest!:current_has_sec' split:option.splits if_splits)
       
  1199 done
       
  1200 
       
  1201 lemma ch2sshm_other:
       
  1202   "\<lbrakk>valid (e # s); 
       
  1203     \<forall> p h. e \<noteq> CreateShM p h; 
       
  1204     h' \<in> current_shms (e # s)\<rbrakk> \<Longrightarrow> ch2sshm (e # s) h' = ch2sshm s h'"
       
  1205 apply (frule vd_cons, frule vt_grant_os)
       
  1206 apply (case_tac e)
       
  1207 apply (auto simp:ch2sshm_def sectxt_of_obj_simps dest!:current_has_sec' split:option.splits if_splits)
       
  1208 done
       
  1209 
       
  1210 lemmas ch2sshm_simps = ch2sshm_createshm ch2sshm_other
       
  1211 
       
  1212 lemma current_shm_has_sh:
       
  1213   "\<lbrakk>h \<in> current_shms s; valid s\<rbrakk> \<Longrightarrow> \<exists> sh. ch2sshm s h = Some sh"
       
  1214 by (auto simp:ch2sshm_def split:option.splits dest!:current_has_sec')
       
  1215 
       
  1216 lemma current_shm_has_sh':
       
  1217   "\<lbrakk>ch2sshm s h = None; valid s\<rbrakk> \<Longrightarrow> h \<notin> current_shms s"
       
  1218 by (auto dest:current_shm_has_sh)
       
  1219 
       
  1220 (********** cph2spshs simpset **********)
       
  1221 
       
  1222 lemma cph2spshs_attach:
       
  1223   "valid (Attach p h flag # s) \<Longrightarrow> 
       
  1224    cph2spshs (Attach p h flag # s) = (cph2spshs s) (p := 
       
  1225      (case (ch2sshm s h) of 
       
  1226         Some sh \<Rightarrow> cph2spshs s p \<union> {(sh, flag)}
       
  1227       | _       \<Rightarrow> cph2spshs s p) )"
       
  1228 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1229 using ch2sshm_other[where e = "Attach p h flag" and s = s]
       
  1230 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1231 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 simp:cph2spshs_def)
       
  1232 apply (erule_tac x = ha in allE, frule procs_of_shm_prop1, simp, simp)
       
  1233 apply (erule_tac x = ha in allE, frule procs_of_shm_prop1, simp, simp)
       
  1234 apply (erule_tac x = ha in allE, frule procs_of_shm_prop1, simp, simp)
       
  1235 apply (erule_tac x = ha in allE, frule procs_of_shm_prop1, simp, simp)
       
  1236 apply (erule_tac x = ha in allE, frule procs_of_shm_prop1, simp, simp)
       
  1237 apply (case_tac "ha = h", simp, frule procs_of_shm_prop1, simp)
       
  1238 apply (rule_tac x = ha in exI, simp)
       
  1239 apply (rule_tac x = ha in exI, simp, drule procs_of_shm_prop1, simp, simp)
       
  1240 apply (rule_tac x = ha in exI, simp)
       
  1241 apply (frule procs_of_shm_prop1, simp, simp)
       
  1242 apply (rule impI, simp)
       
  1243 done
       
  1244 
       
  1245 lemma cph2spshs_detach: "valid (Detach p h # s) \<Longrightarrow> 
       
  1246   cph2spshs (Detach p h # s) = (cph2spshs s) (p := 
       
  1247     (case (ch2sshm s h, flag_of_proc_shm s p h) of 
       
  1248        (Some sh, Some flag) \<Rightarrow> if (\<exists> h'. h' \<noteq> h \<and> (p,flag) \<in> procs_of_shm s h' \<and> ch2sshm s h' = Some sh)
       
  1249                   then cph2spshs s p else cph2spshs s p - {(sh, flag)}
       
  1250      | _       \<Rightarrow> cph2spshs s p)             )"
       
  1251 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1252 apply (case_tac "x = p")  defer
       
  1253 using ch2sshm_other[where e = "Detach p h" and s = s] 
       
  1254 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1255 dest!:current_shm_has_sh' procs_of_shm_prop4' dest:procs_of_shm_prop1 procs_of_shm_prop3 simp:cph2spshs_def) [1]
       
  1256 apply (rule_tac x = ha in exI, frule_tac h = ha in procs_of_shm_prop1, simp, simp)
       
  1257 apply (rule_tac x = ha in exI, frule_tac h = ha in procs_of_shm_prop1, simp, simp)
       
  1258 apply (rule impI, simp)
       
  1259 
       
  1260 apply (clarsimp)
       
  1261 apply (frule current_shm_has_sh, simp, erule exE)
       
  1262 apply (frule procs_of_shm_prop4, simp, simp)
       
  1263 apply (rule allI | rule conjI| erule conjE | erule exE | rule impI)+
       
  1264 
       
  1265 apply (simp only:cph2spshs_def, rule set_eqI, rule iffI)
       
  1266 apply (erule CollectE | erule exE| erule conjE| rule CollectI)+
       
  1267 apply (case_tac "ha = h", simp)
       
  1268 apply (rule_tac x = sha in exI, rule_tac x = flaga in exI, rule_tac x = ha in exI, simp)
       
  1269 using ch2sshm_other[where e = "Detach p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1270 
       
  1271 apply (erule CollectE | erule exE| erule conjE| rule CollectI)+
       
  1272 apply (case_tac "ha = h", simp)
       
  1273 apply (rule_tac x = h' in exI, simp)
       
  1274 apply (frule_tac flag = flag and flag' = flaga in procs_of_shm_prop3, simp+)
       
  1275 apply (frule_tac flag = flaga in procs_of_shm_prop4, simp+)
       
  1276 using ch2sshm_other[where e = "Detach p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1277 apply (frule_tac h = h' in procs_of_shm_prop1, simp, simp)
       
  1278 apply (rule_tac x = ha in exI, simp, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1279 using ch2sshm_other[where e = "Detach p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1280 
       
  1281 apply (rule allI | rule conjI| erule conjE | erule exE | rule impI)+
       
  1282 apply (simp only:cph2spshs_def, rule set_eqI, rule iffI)
       
  1283 apply (erule CollectE | erule exE| erule conjE| rule DiffI |rule CollectI)+
       
  1284 apply (simp split:if_splits)
       
  1285 apply (rule_tac x = ha in exI, simp, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1286 using ch2sshm_other[where e = "Detach p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1287 apply (rule notI, simp split:if_splits)
       
  1288 apply (erule_tac x = ha in allE, simp, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1289 using ch2sshm_other[where e = "Detach p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1290 apply (erule CollectE | erule exE| erule conjE| erule DiffE |rule CollectI)+
       
  1291 apply (simp split:if_splits)
       
  1292 apply (erule_tac x = ha in allE, simp, rule_tac x = ha in exI, simp)
       
  1293 apply (case_tac "ha = h", simp add:procs_of_shm_prop3, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1294 using ch2sshm_other[where e = "Detach p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1295 done
       
  1296 
       
  1297 lemma cph2spshs_deleteshm:
       
  1298   "valid (DeleteShM p h # s) \<Longrightarrow>     
       
  1299    cph2spshs (DeleteShM p h # s) = (\<lambda> p'. 
       
  1300     (case (ch2sshm s h, flag_of_proc_shm s p' h) of 
       
  1301        (Some sh, Some flag) \<Rightarrow> if (\<exists> h'. h' \<noteq> h \<and> (p', flag) \<in> procs_of_shm s h' \<and> ch2sshm s h' = Some sh)
       
  1302                   then cph2spshs s p' else cph2spshs s p' - {(sh, flag)}
       
  1303      | _       \<Rightarrow> cph2spshs s p')   )"
       
  1304 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1305 
       
  1306 apply (clarsimp)
       
  1307 apply (frule current_shm_has_sh, simp, erule exE, simp, simp split:option.splits)
       
  1308 apply (rule conjI, rule impI)
       
  1309 using ch2sshm_other[where e = "DeleteShM p h" and s = s] 
       
  1310 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1311 dest!:current_shm_has_sh' procs_of_shm_prop4' dest:procs_of_shm_prop1 procs_of_shm_prop3 simp:cph2spshs_def) [1]
       
  1312 apply (rule_tac x = ha in exI, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1313 apply (rule_tac x = ha in exI, simp)
       
  1314 apply (case_tac "ha = h", simp+, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1315 
       
  1316 apply (rule allI | rule conjI| erule conjE | erule exE | rule impI)+
       
  1317 
       
  1318 apply (simp only:cph2spshs_def, rule set_eqI, rule iffI)
       
  1319 apply (erule CollectE | erule exE| erule conjE| rule CollectI)+
       
  1320 apply (case_tac "ha = h", simp)
       
  1321 apply (rule_tac x = sha in exI, rule_tac x = flag in exI, rule_tac x = ha in exI, simp)
       
  1322 using ch2sshm_other[where e = "DeleteShM p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1323 
       
  1324 apply (erule CollectE | erule exE| erule conjE| rule CollectI)+
       
  1325 apply (case_tac "ha = h", simp)
       
  1326 apply (rule_tac x = h' in exI, simp)
       
  1327 apply (frule_tac flag = flag in procs_of_shm_prop4, simp+)
       
  1328 using ch2sshm_other[where e = "DeleteShM p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1329 apply (frule_tac h = h' in procs_of_shm_prop1, simp, simp)
       
  1330 apply (rule_tac x = ha in exI, simp, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1331 using ch2sshm_other[where e = "DeleteShM p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1332 
       
  1333 apply (rule allI | rule conjI| erule conjE | erule exE | rule impI)+
       
  1334 apply (simp only:cph2spshs_def, rule set_eqI, rule iffI)
       
  1335 apply (erule CollectE | erule exE| erule conjE| rule DiffI |rule CollectI)+
       
  1336 apply (simp split:if_splits)
       
  1337 apply (rule_tac x = ha in exI, simp, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1338 using ch2sshm_other[where e = "DeleteShM p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1339 apply (rule notI, simp split:if_splits)
       
  1340 apply (erule_tac x = ha in allE, simp, frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1341 using ch2sshm_other[where e = "DeleteShM p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1342 apply (erule CollectE | erule exE| erule conjE| erule DiffE |rule CollectI)+
       
  1343 apply (simp split:if_splits)
       
  1344 apply (erule_tac x = ha in allE, simp, rule_tac x = ha in exI, simp)
       
  1345 apply (case_tac "ha = h", simp add:procs_of_shm_prop4)
       
  1346 apply (frule_tac h = ha in procs_of_shm_prop1, simp+)
       
  1347 using ch2sshm_other[where e = "DeleteShM p h" and s = s] apply (simp add:procs_of_shm_prop1)
       
  1348 done
       
  1349 
       
  1350 lemma flag_of_proc_shm_prop1:
       
  1351   "\<lbrakk>flag_of_proc_shm s p h = Some flag; valid s\<rbrakk> \<Longrightarrow> (p, flag) \<in> procs_of_shm s h"
       
  1352 apply (induct s arbitrary:p)
       
  1353 apply (simp add:init_shmflag_has_proc)
       
  1354 apply (frule vt_grant_os, frule vd_cons, case_tac a, auto split:if_splits option.splits)
       
  1355 done
       
  1356 
       
  1357 lemma cph2spshs_clone:
       
  1358   "valid (Clone p p' fds shms # s) \<Longrightarrow> 
       
  1359    cph2spshs (Clone p p' fds shms # s) = (cph2spshs s) (p' := 
       
  1360      {(sh, flag) | h sh flag. h \<in> shms \<and> ch2sshm s h = Some sh \<and> flag_of_proc_shm s p h = Some flag} )"
       
  1361 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1362 using ch2sshm_other[where e = "Clone p p' fds shms" and s = s]
       
  1363 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1364 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3 simp:cph2spshs_def)
       
  1365 apply (erule_tac x = h in allE, frule procs_of_shm_prop1, simp, simp add:procs_of_shm_prop4)
       
  1366 apply (rule_tac x = h in exI, simp, frule flag_of_proc_shm_prop1, simp+, simp add:procs_of_shm_prop1)
       
  1367 apply (rule_tac x = h in exI, simp, frule procs_of_shm_prop1, simp+)+
       
  1368 done
       
  1369 
       
  1370 lemma cph2spshs_execve:
       
  1371   "valid (Execve p f fds # s) \<Longrightarrow>
       
  1372   cph2spshs (Execve p f fds # s) = (cph2spshs s) (p := {})"
       
  1373 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1374 using ch2sshm_other[where e = "Execve p f fds" and s = s]
       
  1375 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1376 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3 simp:cph2spshs_def)
       
  1377 apply (rule_tac x = h in exI, simp add:procs_of_shm_prop1)+
       
  1378 done
       
  1379 
       
  1380 lemma cph2spshs_kill:
       
  1381   "valid (Kill p p' # s) \<Longrightarrow> cph2spshs (Kill p p' # s) = (cph2spshs s) (p' := {})"
       
  1382 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1383 using ch2sshm_other[where e = "Kill p p'" and s = s]
       
  1384 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1385 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3 simp:cph2spshs_def)
       
  1386 apply (rule_tac x = h in exI, simp add:procs_of_shm_prop1)+
       
  1387 done
       
  1388 
       
  1389 lemma cph2spshs_exit:
       
  1390   "valid (Exit p # s) \<Longrightarrow> cph2spshs (Exit p # s) = (cph2spshs s) (p := {})"
       
  1391 apply (frule vd_cons, frule vt_grant_os, rule ext)
       
  1392 using ch2sshm_other[where e = "Exit p" and s = s]
       
  1393 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1394 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3 simp:cph2spshs_def)
       
  1395 apply (rule_tac x = h in exI, simp add:procs_of_shm_prop1)+
       
  1396 done
       
  1397 
       
  1398 lemma cph2spshs_createshm:
       
  1399   "valid (CreateShM p h # s) \<Longrightarrow> cph2spshs (CreateShM p h # s) = cph2spshs s"
       
  1400 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1401 apply (auto simp:cph2spshs_def)
       
  1402 using ch2sshm_createshm
       
  1403 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1404 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3 simp:cph2spshs_def)
       
  1405 apply (rule_tac x = ha in exI, auto simp:procs_of_shm_prop1)
       
  1406 done
       
  1407 
       
  1408 lemma cph2spshs_other:
       
  1409   "\<lbrakk>valid (e # s); 
       
  1410     \<forall> p h flag. e \<noteq> Attach p h flag;
       
  1411     \<forall> p h. e \<noteq> Detach p h;
       
  1412     \<forall> p h. e \<noteq> DeleteShM p h;
       
  1413     \<forall> p p' fds shms. e \<noteq> Clone p p' fds shms;
       
  1414     \<forall> p f fds. e \<noteq> Execve p f fds;
       
  1415     \<forall> p p'. e \<noteq> Kill p p';
       
  1416     \<forall> p. e \<noteq> Exit p\<rbrakk> \<Longrightarrow> cph2spshs (e # s) = cph2spshs s"
       
  1417 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1418 unfolding cph2spshs_def 
       
  1419 apply (rule set_eqI, rule iffI)
       
  1420 apply (erule CollectE | erule conjE| erule exE| rule conjI| rule impI| rule CollectI)+
       
  1421 apply (frule procs_of_shm_prop1, simp, rule_tac x= sh in exI, rule_tac x = flag in exI, rule_tac x = h in exI)
       
  1422 apply (case_tac e)
       
  1423 using ch2sshm_other[where e = e and s = s] 
       
  1424 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1425 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3
       
  1426  simp:ch2sshm_createshm)
       
  1427 apply (rule_tac x = h in exI, case_tac e)
       
  1428 using ch2sshm_other[where e = e and s = s] 
       
  1429 apply (auto split del:t_open_must_flag.splits t_open_option_flag.splits split add:if_splits option.splits
       
  1430 dest!:current_shm_has_sh' dest: procs_of_shm_prop1 procs_of_shm_prop2 procs_of_shm_prop3 
       
  1431  simp:ch2sshm_createshm)
       
  1432 done
       
  1433 
       
  1434 lemmas cph2spshs_simps = cph2spshs_attach cph2spshs_detach cph2spshs_deleteshm cph2spshs_clone cph2spshs_execve
       
  1435   cph2spshs_exit cph2spshs_kill cph2spshs_other
       
  1436 
       
  1437 (******** cp2sproc simpset *********)
       
  1438 
       
  1439 lemma cp2sproc_clone:
       
  1440   "valid (Clone p p' fds shms # s) \<Longrightarrow> cp2sproc (Clone p p' fds shms # s) = (cp2sproc s) (p' := 
       
  1441      case (sectxt_of_obj s (O_proc p)) of 
       
  1442        Some sec \<Rightarrow> Some (Created, sec, 
       
  1443   {sfd. \<exists> fd \<in> fds. \<exists> f. file_of_proc_fd s p fd = Some f \<and> cfd2sfd s p fd = Some sfd},
       
  1444   {(sh, flag) | h sh flag. h \<in> shms \<and> ch2sshm s h = Some sh \<and> flag_of_proc_shm s p h = Some flag})
       
  1445      | _        \<Rightarrow> None)"
       
  1446 apply (frule cph2spshs_clone, frule cpfd2sfds_clone)
       
  1447 apply (frule vd_cons, frule vt_grant_os, simp only:os_grant.simps)
       
  1448 apply ((erule exE| erule conjE)+, frule not_init_intro_proc, simp, rule ext, case_tac "x = p'", simp)
       
  1449 apply (auto simp:cp2sproc_def sectxt_of_obj_simps dest!:current_has_sec' 
       
  1450             dest:current_proc_has_sec split:option.splits if_splits)
       
  1451 done
       
  1452 
       
  1453 lemma cp2sproc_other:
       
  1454   "\<lbrakk>valid (e # s); 
       
  1455     \<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
       
  1456     \<forall> p fd. e \<noteq> CloseFd p fd;
       
  1457     \<forall> p h flag. e \<noteq> Attach p h flag;
       
  1458     \<forall> p h. e \<noteq> Detach p h;
       
  1459     \<forall> p h. e \<noteq> DeleteShM p h;
       
  1460     \<forall> p p' fds shms. e \<noteq> Clone p p' fds shms;
       
  1461     \<forall> p f fds. e \<noteq> Execve p f fds;
       
  1462     \<forall> p p'. e \<noteq> Kill p p';
       
  1463     \<forall> p. e \<noteq> Exit p\<rbrakk> \<Longrightarrow> cp2sproc (e # s) = cp2sproc s"
       
  1464 apply (frule cph2spshs_other, simp+, frule cpfd2sfds_other, simp+)
       
  1465 apply (frule vt_grant_os, frule vd_cons, rule ext, case_tac e, simp_all) 
       
  1466 apply (auto simp:cp2sproc_def sectxt_of_obj_simps dest!:current_has_sec' 
       
  1467             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1468 done
       
  1469 
       
  1470 lemma cp2sproc_open:
       
  1471   "valid (Open p f flags fd opt # s) \<Longrightarrow> 
       
  1472    cp2sproc (Open p f flags fd opt # s) = (cp2sproc s) (p :=      
       
  1473      case (sectxt_of_obj s (O_proc p), sectxt_of_obj (Open p f flags fd opt # s) (O_fd p fd), 
       
  1474            cf2sfile (Open p f flags fd opt # s) f) of 
       
  1475        (Some sec, Some fdsec, Some sf) \<Rightarrow> Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) 
       
  1476                                                then Init p else Created, sec, 
       
  1477                                                 (cpfd2sfds s p) \<union> {(fdsec, flags, sf)}, cph2spshs s p)
       
  1478      | _        \<Rightarrow> None)"
       
  1479 apply (frule cph2spshs_other, simp, simp, simp, simp, simp, simp, simp)
       
  1480 apply (frule cpfd2sfds_open, frule vt_grant_os, frule vd_cons, rule ext)
       
  1481 apply (case_tac "x = p") 
       
  1482 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1483            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1484             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1485 done
       
  1486 
       
  1487 lemma cp2sproc_closefd:
       
  1488   "valid (CloseFd p fd # s) \<Longrightarrow> 
       
  1489    cp2sproc (CloseFd p fd # s) = (cp2sproc s) (p := 
       
  1490      if (fd \<in> proc_file_fds s p)
       
  1491      then (case (cfd2sfd s p fd) of 
       
  1492              Some sfd \<Rightarrow> (if (\<exists> fd' f'. fd' \<noteq> fd \<and> file_of_proc_fd s p fd' = Some f' \<and> cfd2sfd s p fd' = Some sfd)
       
  1493                           then cp2sproc s p 
       
  1494                           else (case (sectxt_of_obj s (O_proc p)) of
       
  1495                                   Some sec \<Rightarrow> Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) 
       
  1496                                                     then Init p else Created, 
       
  1497                                                     sec, cpfd2sfds s p - {sfd}, cph2spshs s p)
       
  1498                                 | _        \<Rightarrow> None))
       
  1499            | _        \<Rightarrow> cp2sproc s p)
       
  1500      else cp2sproc s p)"
       
  1501 apply (frule cpfd2sfds_closefd, frule cph2spshs_other, simp, simp, simp, simp, simp, simp, simp)
       
  1502 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1503 apply (case_tac "x = p") 
       
  1504 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1505            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1506             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1507 done
       
  1508 
       
  1509 lemma cp2sproc_attach:
       
  1510   "valid (Attach p h flag # s) \<Longrightarrow> 
       
  1511    cp2sproc (Attach p h flag # s) = (cp2sproc s) (p := 
       
  1512      (case (ch2sshm s h) of 
       
  1513         Some sh \<Rightarrow> (case (sectxt_of_obj s (O_proc p)) of
       
  1514                       Some sec \<Rightarrow> Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) 
       
  1515                                         then Init p else Created, 
       
  1516                                         sec, cpfd2sfds s p, cph2spshs s p \<union> {(sh, flag)})
       
  1517                     | _        \<Rightarrow> None)
       
  1518       | _       \<Rightarrow> cp2sproc s p) )"
       
  1519 apply (frule cph2spshs_attach, frule cpfd2sfds_other, simp, simp, simp, simp, simp, simp)
       
  1520 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1521 apply (case_tac "x = p") 
       
  1522 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1523            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1524             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1525 done
       
  1526 
       
  1527 lemma cp2sproc_detach:
       
  1528   "valid (Detach p h # s) \<Longrightarrow> 
       
  1529    cp2sproc (Detach p h # s) = (cp2sproc s) (p := 
       
  1530     (case (ch2sshm s h, flag_of_proc_shm s p h) of 
       
  1531        (Some sh, Some flag) \<Rightarrow> if (\<exists> h'. h' \<noteq> h \<and> (p,flag) \<in> procs_of_shm s h' \<and> ch2sshm s h' = Some sh)
       
  1532                               then cp2sproc s p 
       
  1533                               else (case (sectxt_of_obj s (O_proc p)) of
       
  1534                                       Some sec \<Rightarrow> Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) 
       
  1535                                                        then Init p else Created, sec,
       
  1536                                                        cpfd2sfds s p, cph2spshs s p - {(sh, flag)})
       
  1537                                     | None     \<Rightarrow> None)                   
       
  1538      | _       \<Rightarrow> cp2sproc s p)             )"
       
  1539 apply (frule cph2spshs_detach, frule cpfd2sfds_other, simp, simp, simp, simp, simp, simp)
       
  1540 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1541 apply (case_tac "x = p") 
       
  1542 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1543            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1544             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1545 done
       
  1546 
       
  1547 lemma cp2sproc_deleteshm:
       
  1548   "valid (DeleteShM p h # s) \<Longrightarrow> 
       
  1549    cp2sproc (DeleteShM p h # s) = (\<lambda> p'. 
       
  1550     (case (ch2sshm s h, flag_of_proc_shm s p' h) of 
       
  1551        (Some sh, Some flag) \<Rightarrow> if (\<exists> h'. h' \<noteq> h \<and> (p', flag) \<in> procs_of_shm s h' \<and> ch2sshm s h' = Some sh)
       
  1552                               then cp2sproc s p' 
       
  1553                               else (case (sectxt_of_obj s (O_proc p')) of
       
  1554                                       Some sec \<Rightarrow> Some (if (\<not> deleted (O_proc p') s \<and> p' \<in> init_procs) 
       
  1555                                                        then Init p' else Created, sec,
       
  1556                                                        cpfd2sfds s p', cph2spshs s p' - {(sh, flag)})
       
  1557                                     | None     \<Rightarrow> None)                   
       
  1558      | _       \<Rightarrow> cp2sproc s p')             )"
       
  1559 apply (frule cph2spshs_deleteshm, frule cpfd2sfds_other, simp, simp, simp, simp, simp, simp)
       
  1560 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1561 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1562            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1563             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1564 done
       
  1565 
       
  1566 lemma cp2sproc_execve:
       
  1567   "valid (Execve p f fds # s) \<Longrightarrow> 
       
  1568    cp2sproc (Execve p f fds # s) = (cp2sproc s) (p := 
       
  1569      (case (sectxt_of_obj (Execve p f fds # s) (O_proc p)) of
       
  1570         Some sec \<Rightarrow> Some (if (\<not> deleted (O_proc p) s \<and> p \<in> init_procs) then Init p else Created, sec, 
       
  1571                          {sfd. \<exists> fd \<in> fds. \<exists> f. file_of_proc_fd s p fd = Some f \<and> cfd2sfd s p fd = Some sfd}, {})
       
  1572       | _        \<Rightarrow> None)                        )"
       
  1573 apply (frule cph2spshs_execve, frule cpfd2sfds_execve)
       
  1574 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1575 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1576            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1577             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1578 done
       
  1579 
       
  1580 lemma cp2sproc_kill:
       
  1581   "\<lbrakk>valid (Kill p p' # s); p'' \<noteq> p'\<rbrakk> \<Longrightarrow> 
       
  1582    cp2sproc (Kill p p' # s) p'' = (cp2sproc s) p''"
       
  1583 apply (frule cph2spshs_kill, frule cpfd2sfds_kill)
       
  1584 apply (frule vt_grant_os, frule vd_cons)
       
  1585 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1586            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1587             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1588 done
       
  1589 
       
  1590 lemma cp2sproc_kill':
       
  1591   "\<lbrakk>valid (Kill p p' # s); p'' \<in> current_procs (Kill p p' # s)\<rbrakk> \<Longrightarrow> 
       
  1592    cp2sproc (Kill p p' # s) p'' = (cp2sproc s) p''"
       
  1593 by (drule_tac p'' = p'' in cp2sproc_kill, simp+)
       
  1594 
       
  1595 lemma cp2sproc_exit:
       
  1596   "\<lbrakk>valid (Exit p # s); p' \<noteq> p\<rbrakk> \<Longrightarrow> 
       
  1597    cp2sproc (Exit p # s) p' = (cp2sproc s) p'"
       
  1598 apply (frule cph2spshs_exit, frule cpfd2sfds_exit)
       
  1599 apply (frule vt_grant_os, frule vd_cons)
       
  1600 apply (auto simp:cp2sproc_def sectxt_of_obj_simps current_files_simps 
       
  1601            dest!:current_has_sec' dest!:current_file_has_sfile' dest:is_file_in_current is_dir_in_current
       
  1602             dest:current_proc_has_sec not_deleted_init_proc split:option.splits if_splits)
       
  1603 done
       
  1604 
       
  1605 lemma cp2sproc_exit':
       
  1606   "\<lbrakk>valid (Exit p # s); p' \<in> current_procs (Exit p # s)\<rbrakk> \<Longrightarrow> 
       
  1607    cp2sproc (Exit p # s) p' = (cp2sproc s) p'"
       
  1608 by (drule_tac p'= p' in cp2sproc_exit, simp+)
       
  1609 
       
  1610 lemmas cp2sproc_simps = cp2sproc_open cp2sproc_closefd cp2sproc_attach cp2sproc_detach cp2sproc_deleteshm
       
  1611   cp2sproc_clone cp2sproc_execve cp2sproc_kill cp2sproc_exit cp2sproc_other 
       
  1612 
       
  1613 lemma current_proc_has_sp:
       
  1614   "\<lbrakk>p \<in> current_procs s; valid s\<rbrakk> \<Longrightarrow> \<exists> sp. cp2sproc s p = Some sp"
       
  1615 by (auto simp:cp2sproc_def split:option.splits dest!:current_has_sec')
       
  1616 
       
  1617 lemma current_proc_has_sp':
       
  1618   "\<lbrakk>cp2sproc s p = None; valid s\<rbrakk> \<Longrightarrow> p \<notin> current_procs s"
       
  1619 by (auto dest:current_proc_has_sp)
       
  1620 
       
  1621 
       
  1622 
       
  1623 (* simpset for cf2sfiles *)
       
  1624 
       
  1625 lemma cf2sfiles_open:
       
  1626   "\<lbrakk>valid (Open p f flag fd opt # s); f' \<in> current_files (Open p f flag fd opt # s)\<rbrakk>
       
  1627    \<Longrightarrow> cf2sfiles (Open p f flag fd opt # s) f' = (
       
  1628      if (f' = f \<and> opt \<noteq> None) 
       
  1629      then (case cf2sfile (Open p f flag fd opt # s) f of 
       
  1630              Some sf \<Rightarrow> {sf}  
       
  1631            | _       \<Rightarrow> {} )
       
  1632      else cf2sfiles s f')"
       
  1633 apply (frule vt_grant_os, frule vd_cons)
       
  1634 apply (auto simp:cf2sfiles_def cf2sfile_open_none cf2sfile_simps same_inode_files_open
       
  1635   split:if_splits option.splits dest!:current_file_has_sfile' dest:cf2sfile_open)
       
  1636 apply (rule_tac x = "f'a" in bexI, drule same_inode_files_prop1, simp add:cf2sfile_open_some1, simp)+
       
  1637 done
       
  1638 
       
  1639 lemma cf2sfiles_other:
       
  1640   "\<lbrakk>valid (e # s);
       
  1641     \<forall> p f flag fd opt. e \<noteq> Open p f flag fd opt;
       
  1642     \<forall> p fd. e \<noteq> CloseFd p fd;
       
  1643     \<forall> p f. e \<noteq> UnLink p f;
       
  1644     \<forall> p f f'. e \<noteq> LinkHard p f f'\<rbrakk> \<Longrightarrow> cf2sfiles (e # s) = cf2sfiles s"
       
  1645 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1646 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI)
       
  1647 apply (drule Set.CollectD, erule bexE, rule CollectI)
       
  1648 apply (rule_tac x = f' in bexI, case_tac e)
       
  1649 apply (auto simp:cf2sfiles_def cf2sfile_simps same_inode_files_simps current_files_simps
       
  1650   split:if_splits option.splits dest!:current_file_has_sfile' dest:same_inode_files_prop1 cf2sfile_other')
       
  1651 apply (drule_tac f' = f' in cf2sfile_rmdir)
       
  1652 apply (simp add:current_files_simps same_inode_files_prop1 same_inode_files_prop3 dir_is_empty_def)+
       
  1653 
       
  1654 apply (rule_tac x = f' in bexI, case_tac e)
       
  1655 apply (auto simp:cf2sfiles_def cf2sfile_simps same_inode_files_simps current_files_simps
       
  1656   split:if_splits option.splits dest!:current_file_has_sfile' dest:same_inode_files_prop1 cf2sfile_other')
       
  1657 apply (drule_tac f' = f' in cf2sfile_rmdir)
       
  1658 apply (simp add:current_files_simps same_inode_files_prop1 same_inode_files_prop3 dir_is_empty_def)+
       
  1659 done
       
  1660 
       
  1661 lemma cf2sfile_linkhard1':
       
  1662   "\<lbrakk>valid (LinkHard p oldf f # s); f' \<in> same_inode_files s f''\<rbrakk>
       
  1663    \<Longrightarrow> cf2sfile (LinkHard p oldf f# s) f' = cf2sfile s f'"
       
  1664 apply (drule same_inode_files_prop1)
       
  1665 by (simp add:cf2sfile_linkhard1)
       
  1666 
       
  1667 lemma cf2sfiles_linkhard:
       
  1668   "valid (LinkHard p oldf f # s) \<Longrightarrow> cf2sfiles (LinkHard p oldf f # s) = (\<lambda> f'. 
       
  1669      if (f' = f \<or> f' \<in> same_inode_files s oldf)
       
  1670      then (case (cf2sfile (LinkHard p oldf f # s) f) of
       
  1671              Some sf \<Rightarrow> cf2sfiles s oldf \<union> {sf}
       
  1672            | _       \<Rightarrow> {})
       
  1673      else cf2sfiles s f')"
       
  1674 apply (frule vt_grant_os, frule vd_cons, rule ext)
       
  1675 apply (auto simp:cf2sfiles_def cf2sfile_linkhard1' same_inode_files_linkhard current_files_linkhard 
       
  1676   split:if_splits option.splits dest!:current_file_has_sfile' current_has_sec' dest:same_inode_files_prop1)
       
  1677 done
       
  1678 
       
  1679 lemma cf2sfile_unlink':
       
  1680   "\<lbrakk>valid (UnLink p f # s); f' \<in> same_inode_files (UnLink p f # s) f''\<rbrakk>
       
  1681    \<Longrightarrow> cf2sfile (UnLink p f # s) f' = cf2sfile s f'"
       
  1682 apply (drule same_inode_files_prop1)
       
  1683 by (simp add:cf2sfile_unlink)
       
  1684 
       
  1685 lemma cf2sfiles_unlink:
       
  1686   "\<lbrakk>valid (UnLink p f # s); f' \<in> current_files (UnLink p f # s)\<rbrakk> \<Longrightarrow> cf2sfiles (UnLink p f # s) f' = ( 
       
  1687      if (f' \<in> same_inode_files s f \<and> proc_fd_of_file s f = {} \<and> 
       
  1688          (\<forall> f'' \<in> same_inode_files s f. f'' \<noteq> f \<longrightarrow> cf2sfile s f'' \<noteq> cf2sfile s f)) then 
       
  1689         (case (cf2sfile s f) of 
       
  1690            Some sf \<Rightarrow> cf2sfiles s f' - {sf}
       
  1691          | _       \<Rightarrow> {})
       
  1692      else cf2sfiles s f')"
       
  1693 apply (frule vt_grant_os, frule vd_cons, simp add:current_files_simps split:if_splits)
       
  1694 apply (rule conjI, clarify, frule is_file_has_sfile', simp, erule exE, simp)
       
  1695 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1696 apply (erule bexE, frule_tac f' = f' in same_inode_files_unlink)
       
  1697 apply (simp add:current_files_unlink, simp, erule conjE)
       
  1698 apply (erule_tac x = f'a in ballE, frule_tac f' = "f'a" in cf2sfile_unlink)
       
  1699 apply (simp add:current_files_unlink same_inode_files_prop1, simp)
       
  1700 apply (rule_tac x = f'a in bexI, simp, simp)
       
  1701 apply (drule_tac f = f and f' = f' and f'' = f'a in same_inode_files_prop4, simp+)
       
  1702 apply (erule conjE|erule exE|erule bexE)+
       
  1703 apply (case_tac "f'a = f", simp)
       
  1704 apply (frule_tac f' = f' in same_inode_files_unlink, simp add:current_files_unlink)
       
  1705 apply (frule_tac f' = f'a in cf2sfile_unlink, simp add:current_files_unlink same_inode_files_prop1)
       
  1706 apply (rule_tac x = f'a in bexI, simp, simp)
       
  1707 
       
  1708 apply (rule impI)+
       
  1709 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1710 apply (erule bexE, frule_tac f' = f' in same_inode_files_unlink)
       
  1711 apply (simp add:current_files_unlink, simp, (erule conjE)+)
       
  1712 apply (rule_tac x = f'a in bexI, frule_tac f' = "f'a" in cf2sfile_unlink)
       
  1713 apply (simp add:current_files_unlink same_inode_files_prop1, simp, simp)
       
  1714 apply (drule CollectD, erule bexE, frule_tac f' = f' in same_inode_files_unlink)
       
  1715 apply (simp add:current_files_unlink, simp)
       
  1716 apply (case_tac "f'a = f", simp)
       
  1717 apply (frule_tac f = f' and f' = f in same_inode_files_prop5, simp)
       
  1718 apply (erule bexE, erule conjE)
       
  1719 apply (rule_tac x = f'' in bexI)
       
  1720 apply (drule_tac f' = f'' in cf2sfile_unlink, simp add:current_files_unlink same_inode_files_prop1)
       
  1721 apply (simp, simp, erule same_inode_files_prop4, simp)
       
  1722 apply (rule_tac x = f'a in bexI)
       
  1723 apply (drule_tac f' = f'a in cf2sfile_unlink, simp add:current_files_unlink same_inode_files_prop1)
       
  1724 apply (simp, simp)
       
  1725 
       
  1726 
       
  1727 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1728 apply (erule bexE, frule_tac f' = f' in same_inode_files_unlink)
       
  1729 apply (simp add:current_files_unlink, simp)
       
  1730 apply (rule_tac x = f'a in bexI)
       
  1731 apply (frule_tac f' = f'a in cf2sfile_unlink)
       
  1732 apply (simp add:same_inode_files_prop1 current_files_unlink, simp, simp)
       
  1733 apply (drule CollectD, erule bexE, frule_tac f' = f' in same_inode_files_unlink)
       
  1734 apply (simp add:current_files_unlink, simp)
       
  1735 apply (rule_tac x = f'a in bexI)
       
  1736 apply (frule_tac f' = f'a in cf2sfile_unlink)
       
  1737 apply (simp add:same_inode_files_prop1 current_files_unlink, simp, simp)
       
  1738 done
       
  1739 
       
  1740 lemma cf2sfiles_closefd:
       
  1741   "\<lbrakk>valid (CloseFd p fd # s); f' \<in> current_files (CloseFd p fd # s)\<rbrakk> \<Longrightarrow> cf2sfiles (CloseFd p fd # s) f' = (
       
  1742      case (file_of_proc_fd s p fd) of
       
  1743        Some f \<Rightarrow> if (f' \<in> same_inode_files s f \<and> proc_fd_of_file s f = {(p, fd)} \<and> f \<in> files_hung_by_del s \<and> 
       
  1744                     (\<forall> f'' \<in> same_inode_files s f. f'' \<noteq> f \<longrightarrow> cf2sfile s f'' \<noteq> cf2sfile s f)) 
       
  1745                  then (case (cf2sfile s f) of 
       
  1746                          Some sf \<Rightarrow> cf2sfiles s f' - {sf}
       
  1747                        | _       \<Rightarrow> {})
       
  1748                  else cf2sfiles s f'
       
  1749      | _       \<Rightarrow> cf2sfiles s f')"
       
  1750 
       
  1751 apply (frule vt_grant_os, frule vd_cons, case_tac "file_of_proc_fd s p fd")
       
  1752 apply (simp_all add:current_files_simps split:if_splits)
       
  1753 
       
  1754 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1755 apply (erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1756 apply (simp add:current_files_closefd, simp)
       
  1757 apply (rule_tac x = f'a in bexI)
       
  1758 apply (frule_tac f = f'a in cf2sfile_closefd)
       
  1759 apply (simp add:same_inode_files_prop1 current_files_closefd, simp, simp)
       
  1760 apply (drule CollectD, erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1761 apply (simp add:current_files_closefd, simp)
       
  1762 apply (rule_tac x = f'a in bexI)
       
  1763 apply (frule_tac f = f'a in cf2sfile_closefd)
       
  1764 apply (simp add:same_inode_files_prop1 current_files_closefd, simp, simp)
       
  1765 
       
  1766 apply (rule conjI, clarify, frule file_of_pfd_is_file, simp)
       
  1767 apply (frule is_file_has_sfile', simp, erule exE, simp)
       
  1768 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1769 apply (erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1770 apply (simp add:current_files_closefd, simp, erule conjE)
       
  1771 apply (erule_tac x = f'a in ballE, frule_tac f = "f'a" in cf2sfile_closefd)
       
  1772 apply (simp add:current_files_closefd same_inode_files_prop1, simp)
       
  1773 apply (rule_tac x = f'a in bexI, simp, simp)
       
  1774 apply (drule_tac f = a and f' = f' and f'' = f'a in same_inode_files_prop4, simp+)
       
  1775 apply (erule conjE|erule exE|erule bexE)+
       
  1776 apply (case_tac "f'a = a", simp)
       
  1777 apply (frule_tac f' = f' in same_inode_files_closefd, simp add:current_files_closefd, simp)
       
  1778 apply (frule_tac f = f'a in cf2sfile_closefd, simp add:current_files_closefd same_inode_files_prop1)
       
  1779 apply (rule_tac x = f'a in bexI, simp, simp)
       
  1780 
       
  1781 apply (rule impI)+
       
  1782 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1783 apply (erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1784 apply (simp add:current_files_closefd, simp, (erule conjE)+)
       
  1785 apply (rule_tac x = f'a in bexI, frule_tac f = f'a in cf2sfile_closefd)
       
  1786 apply (simp add:current_files_closefd same_inode_files_prop1, simp, simp)
       
  1787 apply (drule CollectD, erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1788 apply (simp add:current_files_closefd, simp)
       
  1789 apply (case_tac "f'a = a", simp)
       
  1790 apply (frule_tac f = f' and f' = a in same_inode_files_prop5, simp)
       
  1791 apply (erule bexE, erule conjE)
       
  1792 apply (rule_tac x = f'' in bexI)
       
  1793 apply (drule_tac f = f'' in cf2sfile_closefd, simp add:current_files_closefd same_inode_files_prop1)
       
  1794 apply (simp, simp, erule same_inode_files_prop4, simp)
       
  1795 apply (rule_tac x = f'a in bexI)
       
  1796 apply (drule_tac f = f'a in cf2sfile_closefd, simp add:current_files_closefd same_inode_files_prop1)
       
  1797 apply (simp, simp)
       
  1798 
       
  1799 apply (rule conjI, clarify)
       
  1800 
       
  1801 apply (rule impI)
       
  1802 apply (case_tac "a \<in> files_hung_by_del s", simp_all)
       
  1803 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1804 apply (erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1805 apply (simp add:current_files_closefd, simp)
       
  1806 apply (rule_tac x = f'a in bexI)
       
  1807 apply (frule_tac f = f'a in cf2sfile_closefd)
       
  1808 apply (simp add:same_inode_files_prop1 current_files_closefd, simp, simp)
       
  1809 apply (drule CollectD, erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1810 apply (simp add:current_files_closefd, simp)
       
  1811 apply (rule_tac x = f'a in bexI)
       
  1812 apply (frule_tac f = f'a in cf2sfile_closefd)
       
  1813 apply (simp add:same_inode_files_prop1 current_files_closefd, simp, simp)
       
  1814 apply (simp add:cf2sfiles_def, rule set_eqI, rule iffI, drule CollectD)
       
  1815 apply (erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1816 apply (simp add:current_files_closefd, simp)
       
  1817 apply (rule_tac x = f'a in bexI)
       
  1818 apply (frule_tac f = f'a in cf2sfile_closefd)
       
  1819 apply (simp add:same_inode_files_prop1 current_files_closefd, simp, simp)
       
  1820 apply (drule CollectD, erule bexE, frule_tac f' = f' in same_inode_files_closefd)
       
  1821 apply (simp add:current_files_closefd, simp)
       
  1822 apply (rule_tac x = f'a in bexI)
       
  1823 apply (frule_tac f = f'a in cf2sfile_closefd)
       
  1824 apply (simp add:same_inode_files_prop1 current_files_closefd, simp, simp)
       
  1825 done
       
  1826 
       
  1827 lemmas cf2sfiles_simps = cf2sfiles_open cf2sfiles_linkhard cf2sfiles_other
       
  1828   cf2sfiles_unlink cf2sfiles_closefd
       
  1829   
       
  1830 
       
  1831 (* simpset for co2sobj *)
       
  1832 
       
  1833 lemma co2sobj_execve:
       
  1834   "\<lbrakk>valid (Execve p f fds # s); alive (Execve p f fds # s) obj\<rbrakk> \<Longrightarrow> co2sobj (Execve p f fds # s) obj = (
       
  1835       if (obj = O_proc p)
       
  1836       then (case (cp2sproc (Execve p f fds # s) p) of
       
  1837               Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s \<or> O_file f \<in> Tainted s))
       
  1838             | _       \<Rightarrow> None) 
       
  1839       else co2sobj s obj )"
       
  1840 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1841 apply (simp_all add:current_files_simps cf2sfiles_other ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  1842 apply (case_tac "cp2sproc (Execve p f fds # s) p")
       
  1843 apply (drule current_proc_has_sp', simp, simp)
       
  1844 apply (simp (no_asm_simp) add:cp2sproc_execve tainted_eq_Tainted split:option.splits)
       
  1845 apply (simp add:is_dir_simps, frule_tac s = s in is_dir_has_sdir', simp, erule exE, simp)
       
  1846 apply (frule_tac ff = list in cf2sfile_other', simp_all)
       
  1847 apply (simp add:is_dir_in_current)
       
  1848 done
       
  1849 
       
  1850 lemma co2sobj_execve':
       
  1851   "\<lbrakk>valid (Execve p f fds # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (Execve p f fds # s) obj = (
       
  1852       if (obj = O_proc p)
       
  1853       then (case (cp2sproc (Execve p f fds # s) p) of
       
  1854               Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s \<or> O_file f \<in> Tainted s))
       
  1855             | _       \<Rightarrow> None) 
       
  1856       else co2sobj s obj )"
       
  1857 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1858 apply (simp_all add:current_files_simps cf2sfiles_other ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  1859 apply (case_tac "cp2sproc (Execve p f fds # s) p")
       
  1860 apply (drule current_proc_has_sp', simp, simp)
       
  1861 apply (simp (no_asm_simp) add:cp2sproc_execve tainted_eq_Tainted split:option.splits)
       
  1862 apply (frule_tac s = s in is_dir_has_sdir', simp, erule exE, simp)
       
  1863 apply (frule_tac ff = list in cf2sfile_other', simp_all)
       
  1864 apply (simp add:is_dir_in_current)
       
  1865 done
       
  1866 
       
  1867 lemma co2sobj_clone':
       
  1868   "\<lbrakk>valid (Clone p p' fds shms # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (Clone p p' fds shms # s) obj = (
       
  1869       if (obj = O_proc p')
       
  1870       then (case (cp2sproc (Clone p p' fds shms # s) p') of
       
  1871               Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s))
       
  1872             | _       \<Rightarrow> None)
       
  1873       else co2sobj s obj )"
       
  1874 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1875 apply (simp_all add:current_files_simps cf2sfiles_other ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  1876 apply (case_tac "cp2sproc (Clone p p' fds shms # s) p'")
       
  1877 apply (drule current_proc_has_sp', simp, simp)
       
  1878 apply ((erule conjE)+, frule_tac p = p in current_proc_has_sec, simp, erule exE, simp)
       
  1879 apply (rule conjI, rule impI, simp)
       
  1880 apply (simp (no_asm_simp) add:cp2sproc_clone tainted_eq_Tainted split:option.splits)
       
  1881 
       
  1882 apply (frule_tac s = s in is_dir_has_sdir', simp, erule exE, simp)
       
  1883 apply (frule_tac ff = list in cf2sfile_other', simp_all)
       
  1884 apply (simp add:is_dir_in_current)
       
  1885 done
       
  1886 
       
  1887 lemma co2sobj_clone:
       
  1888   "\<lbrakk>valid (Clone p p' fds shms # s); alive (Clone p p' fds shms # s) obj\<rbrakk> 
       
  1889    \<Longrightarrow> co2sobj (Clone p p' fds shms # s) obj = (
       
  1890       if (obj = O_proc p')
       
  1891       then (case (cp2sproc (Clone p p' fds shms # s) p') of
       
  1892               Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s))
       
  1893             | _       \<Rightarrow> None)
       
  1894       else co2sobj s obj )"
       
  1895 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1896 apply (simp_all add:current_files_simps cf2sfiles_other ch2sshm_other 
       
  1897   cq2smsgq_other tainted_eq_Tainted)
       
  1898 apply (rule conjI, rule impI, simp)
       
  1899 apply (case_tac "cp2sproc (Clone p p' fds shms # s) p'")
       
  1900 apply (drule current_proc_has_sp', simp, simp)
       
  1901 apply ((erule conjE)+, frule_tac p = p in current_proc_has_sec, simp, erule exE, simp)
       
  1902 apply (simp add:tainted_eq_Tainted, rule impI, rule notI)
       
  1903 apply (drule Tainted_in_current, simp+)
       
  1904 apply (rule impI, simp)
       
  1905 apply (drule current_proc_has_sp, simp, (erule exE|erule conjE)+)
       
  1906 apply (simp (no_asm_simp) add:cp2sproc_clone tainted_eq_Tainted Tainted_in_current split:option.splits)
       
  1907 
       
  1908 apply (simp add:is_dir_simps, frule_tac s = s in is_dir_has_sdir', simp, erule exE, simp)
       
  1909 apply (frule_tac ff = list in cf2sfile_other', simp_all)
       
  1910 apply (simp add:is_dir_in_current)
       
  1911 done
       
  1912 
       
  1913 lemma co2sobj_ptrace:
       
  1914   "\<lbrakk>valid (Ptrace p p' # s); alive s obj\<rbrakk>\<Longrightarrow> co2sobj (Ptrace p p' # s) obj = (
       
  1915      case obj of
       
  1916        O_proc p'' \<Rightarrow> if (info_flow_shm s p' p'') 
       
  1917                      then (case (cp2sproc s p'') of 
       
  1918                              Some sp \<Rightarrow> Some (S_proc sp (O_proc p'' \<in> Tainted s \<or> O_proc p \<in> Tainted s))
       
  1919                            | _       \<Rightarrow> None)
       
  1920                      else if (info_flow_shm s p p'')
       
  1921                           then (case (cp2sproc s p'') of 
       
  1922                                   Some sp \<Rightarrow> Some (S_proc sp (O_proc p'' \<in> Tainted s \<or> O_proc p' \<in> Tainted s))
       
  1923                                 | _       \<Rightarrow> None)
       
  1924                           else co2sobj s (O_proc p'')
       
  1925     | _          \<Rightarrow> co2sobj s obj)"
       
  1926 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1927 apply (simp_all add:current_files_simps ch2sshm_other cq2smsgq_other cf2sfiles_other tainted_eq_Tainted)
       
  1928 
       
  1929 apply (auto simp:cp2sproc_other tainted_eq_Tainted split:option.splits
       
  1930   dest!:current_proc_has_sec' current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  1931 
       
  1932 apply (frule_tac s = s in is_dir_has_sdir', simp, erule exE, simp)
       
  1933 apply (frule_tac ff = list in cf2sfile_other', simp_all)
       
  1934 apply (simp add:is_dir_in_current)
       
  1935 done
       
  1936 
       
  1937 lemma co2sobj_open:
       
  1938   "\<lbrakk>valid (Open p f flag fd opt # s); alive (Open p f flag fd opt # s) obj\<rbrakk> 
       
  1939    \<Longrightarrow> co2sobj (Open p f flag fd opt # s) obj = (case obj of 
       
  1940      O_file f' \<Rightarrow> if (f' = f \<and> opt \<noteq> None)
       
  1941                   then (case (cf2sfile (Open p f flag fd opt # s) f) of
       
  1942                           Some sf \<Rightarrow> Some (S_file {sf} (O_proc p \<in> Tainted s))
       
  1943                         | _       \<Rightarrow> None)
       
  1944                   else co2sobj s (O_file f')
       
  1945    | O_proc p' \<Rightarrow> if (p' = p) 
       
  1946                   then (case (cp2sproc (Open p f flag fd opt # s) p) of
       
  1947                           Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s))
       
  1948                         | _       \<Rightarrow> None)
       
  1949                   else co2sobj s (O_proc p')
       
  1950    | _         \<Rightarrow> co2sobj s obj )"
       
  1951 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1952 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits
       
  1953            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  1954 
       
  1955 apply (simp split:if_splits t_object.splits)
       
  1956 apply (rule conjI, rule impI, erule conjE, erule exE, simp, (erule exE|erule conjE)+)
       
  1957 apply (case_tac "cf2sfile (Open p f flag fd (Some y) # s) f")
       
  1958 apply (drule current_file_has_sfile', simp, simp add:current_files_simps, simp)
       
  1959 apply (frule_tac f' = f in cf2sfiles_open, simp add:current_files_simps)
       
  1960 apply (simp add:tainted_eq_Tainted)
       
  1961 apply (rule impI, rule notI, drule Tainted_in_current, simp, simp add:is_file_in_current)
       
  1962 apply (rule impI, simp add:tainted_eq_Tainted cf2sfiles_open is_file_in_current split:option.splits)
       
  1963 
       
  1964 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  1965 
       
  1966 apply (frule is_dir_in_current)
       
  1967 apply (frule_tac f' = list in cf2sfile_open)
       
  1968 apply (simp add:current_files_simps split:option.splits)
       
  1969 apply (simp split:if_splits option.splits)
       
  1970 done
       
  1971 
       
  1972 lemma co2sobj_readfile:
       
  1973   "\<lbrakk>valid (ReadFile p fd # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (ReadFile p fd # s) obj = (
       
  1974      case obj of
       
  1975        O_proc p' \<Rightarrow> (case (file_of_proc_fd s p fd) of
       
  1976                        Some f \<Rightarrow> (if (info_flow_shm s p p' \<and> O_file f \<in> Tainted s)
       
  1977                                   then (case (cp2sproc s p') of
       
  1978                                           Some sp \<Rightarrow> Some (S_proc sp True)
       
  1979                                         | _       \<Rightarrow> None)
       
  1980                                   else co2sobj s obj)
       
  1981                     | _       \<Rightarrow> None)
       
  1982      | _         \<Rightarrow> co2sobj s obj)"
       
  1983 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  1984 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits
       
  1985            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  1986 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  1987 
       
  1988 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' 
       
  1989              simp:current_files_simps cf2sfiles_simps cf2sfile_simps 
       
  1990              dest:is_file_in_current is_dir_in_current)
       
  1991 done
       
  1992 
       
  1993 lemma co2sobj_writefile:
       
  1994   "\<lbrakk>valid (WriteFile p fd # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (WriteFile p fd # s) obj = (
       
  1995      case obj of
       
  1996        O_file f' \<Rightarrow> (case (file_of_proc_fd s p fd) of
       
  1997                        Some f \<Rightarrow> (if (f \<in> same_inode_files s f') 
       
  1998                                   then Some (S_file (cf2sfiles s f') 
       
  1999                                                     (O_file f' \<in> Tainted s \<or> O_proc p \<in> Tainted s))
       
  2000                                   else co2sobj s obj)
       
  2001                     | _       \<Rightarrow> None)
       
  2002      | _         \<Rightarrow> co2sobj s obj)"
       
  2003 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2004 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2005 
       
  2006 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2007              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2008                   same_inode_files_prop6
       
  2009              dest:is_file_in_current is_dir_in_current)
       
  2010 
       
  2011 (* should delete has_same_inode !?!?*)
       
  2012 by (auto simp:same_inode_files_def is_file_def has_same_inode_def split:if_splits option.splits)
       
  2013 
       
  2014 lemma co2sobj_closefd:
       
  2015   "\<lbrakk>valid (CloseFd p fd # s); alive (CloseFd p fd # s) obj\<rbrakk> \<Longrightarrow> co2sobj (CloseFd p fd # s) obj = (
       
  2016       case obj of 
       
  2017         O_file f' \<Rightarrow> (case (file_of_proc_fd s p fd) of 
       
  2018                         Some f \<Rightarrow> (if (f' \<in> same_inode_files s f \<and> proc_fd_of_file s f = {(p, fd)} \<and>
       
  2019                                        f \<in> files_hung_by_del s \<and> (\<forall> f'' \<in> same_inode_files s f. 
       
  2020                                        f'' \<noteq> f \<longrightarrow> cf2sfile s f'' \<noteq> cf2sfile s f))
       
  2021                                    then (case (cf2sfile s f, co2sobj s (O_file f')) of
       
  2022                                            (Some sf, Some (S_file sfs b)) \<Rightarrow> Some (S_file (sfs - {sf}) b)
       
  2023                                          | _                              \<Rightarrow> None)
       
  2024                                    else co2sobj s obj)
       
  2025                      | _       \<Rightarrow> co2sobj s obj)
       
  2026       | O_proc p' \<Rightarrow> (if (p = p') 
       
  2027                       then (case (cp2sproc (CloseFd p fd # s) p) of
       
  2028                               Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s))
       
  2029                             | _       \<Rightarrow> None)
       
  2030                       else co2sobj s obj)
       
  2031       | _         \<Rightarrow> co2sobj s obj) "
       
  2032 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2033 apply (simp_all add:current_files_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2034 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits if_splits
       
  2035            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  2036 
       
  2037 apply (frule is_file_in_current)
       
  2038 apply (case_tac "file_of_proc_fd s p fd")
       
  2039 apply (simp add:tainted_eq_Tainted)
       
  2040 apply (drule_tac f' = list in cf2sfiles_closefd, simp add:current_files_closefd, simp)
       
  2041 apply (frule_tac f' = list in cf2sfiles_closefd, simp)
       
  2042 apply (simp add:is_file_simps current_files_simps)
       
  2043 apply (auto simp add:tainted_eq_Tainted cf2sfile_closefd split:if_splits option.splits
       
  2044   dest!:current_file_has_sfile' dest:hung_file_in_current)[1]
       
  2045 
       
  2046 apply (simp add:is_dir_simps, frule is_dir_in_current)
       
  2047 apply (frule_tac f = list in cf2sfile_closefd)
       
  2048 apply (clarsimp simp:current_files_closefd split:option.splits)
       
  2049 apply (drule file_of_pfd_is_file', simp+)
       
  2050 done
       
  2051 
       
  2052 lemma co2sobj_unlink:
       
  2053   "\<lbrakk>valid (UnLink p f # s); alive (UnLink p f # s) obj\<rbrakk> \<Longrightarrow> co2sobj (UnLink p f # s) obj = (
       
  2054       case obj of
       
  2055         O_file f' \<Rightarrow> if (f' \<in> same_inode_files s f \<and> proc_fd_of_file s f = {} \<and> 
       
  2056                         (\<forall> f'' \<in> same_inode_files s f. f'' \<noteq> f \<longrightarrow> cf2sfile s f'' \<noteq> cf2sfile s f))
       
  2057                      then (case (cf2sfile s f, co2sobj s (O_file f')) of
       
  2058                              (Some sf, Some (S_file sfs b)) \<Rightarrow> Some (S_file (sfs - {sf}) b)
       
  2059                            | _                              \<Rightarrow> None)
       
  2060                      else co2sobj s obj
       
  2061       | _         \<Rightarrow> co2sobj s obj)"
       
  2062 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2063 apply (simp_all add:current_files_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2064 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits if_splits
       
  2065            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  2066 apply (frule is_file_in_current)
       
  2067 apply (frule_tac f' = list in cf2sfile_unlink, simp)
       
  2068 apply (frule_tac f' = list in cf2sfiles_unlink, simp)
       
  2069 apply (simp add:is_file_simps current_files_simps)
       
  2070 apply (auto simp add:tainted_eq_Tainted is_file_in_current split:if_splits option.splits
       
  2071   dest!:current_file_has_sfile')[1]
       
  2072 
       
  2073 apply (simp add:is_dir_simps, frule is_dir_in_current)
       
  2074 apply (frule_tac f' = list in cf2sfile_unlink)
       
  2075 apply (clarsimp simp:current_files_unlink split:option.splits)
       
  2076 apply (drule file_dir_conflict, simp+)
       
  2077 done
       
  2078 
       
  2079 lemma co2sobj_rmdir:
       
  2080   "\<lbrakk>valid (Rmdir p f # s); alive (Rmdir p f # s) obj\<rbrakk> \<Longrightarrow> co2sobj (Rmdir p f # s) obj = co2sobj s obj"
       
  2081 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2082 apply (simp_all add:current_files_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2083 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits if_splits
       
  2084            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  2085 apply (simp add:is_file_simps dir_is_empty_def)
       
  2086 apply (case_tac "f = list", drule file_dir_conflict, simp, simp)
       
  2087 apply (simp add:cf2sfiles_other)
       
  2088 apply (auto simp:cf2sfile_simps dest:is_dir_in_current)
       
  2089 done
       
  2090 
       
  2091 lemma co2sobj_mkdir:
       
  2092   "\<lbrakk>valid (Mkdir p f i # s); alive (Mkdir p f i # s) obj\<rbrakk> \<Longrightarrow> co2sobj (Mkdir p f i # s) obj = (
       
  2093       if (obj = O_dir f) 
       
  2094       then (case (cf2sfile (Mkdir p f i # s) f) of 
       
  2095               Some sf \<Rightarrow> Some (S_dir sf)
       
  2096             | _       \<Rightarrow> None)
       
  2097       else co2sobj s obj)"
       
  2098 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2099 apply (simp_all add:current_files_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2100 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits if_splits
       
  2101            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  2102 apply (frule_tac cf2sfiles_other, simp+)
       
  2103 apply (frule is_dir_in_current, rule impI, simp add:current_files_mkdir)
       
  2104 apply (frule current_file_has_sfile, simp, erule exE, simp)
       
  2105 apply (drule cf2sfile_mkdir1, simp+)
       
  2106 done
       
  2107 
       
  2108 
       
  2109 lemma co2sobj_linkhard:
       
  2110   "\<lbrakk>valid (LinkHard p oldf f # s); alive (LinkHard p oldf f # s) obj\<rbrakk> 
       
  2111    \<Longrightarrow> co2sobj (LinkHard p oldf f # s) obj = (
       
  2112     case obj of
       
  2113       O_file f' \<Rightarrow> if (f' = f \<or> f' \<in> same_inode_files s oldf)
       
  2114                    then (case (cf2sfile (LinkHard p oldf f # s) f) of
       
  2115                            Some sf \<Rightarrow> Some (S_file (cf2sfiles s oldf \<union> {sf}) (O_file oldf \<in> Tainted s))
       
  2116                          | _       \<Rightarrow> None)
       
  2117                    else co2sobj s obj
       
  2118     | _         \<Rightarrow> co2sobj s obj)"
       
  2119 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2120 apply (simp_all add:current_files_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2121 apply (auto simp:cp2sproc_simps tainted_eq_Tainted split:option.splits if_splits
       
  2122            dest!:current_proc_has_sp' intro:info_flow_shm_Tainted)[1]
       
  2123 apply (frule_tac cf2sfiles_linkhard, simp+)
       
  2124 apply (frule_tac f' = f in cf2sfile_linkhard, simp add:current_files_linkhard)
       
  2125 apply (auto simp:is_file_simps sectxt_of_obj_simps current_files_simps is_file_in_current same_inodes_Tainted
       
  2126   split:option.splits if_splits dest:Tainted_in_current 
       
  2127   dest!:current_has_sec' current_file_has_sfile')[1]
       
  2128 
       
  2129 apply (frule is_dir_in_current, simp add:current_files_linkhard is_dir_simps is_dir_in_current)
       
  2130 apply (frule is_dir_in_current)
       
  2131 apply (frule current_file_has_sfile, simp)
       
  2132 apply (drule cf2sfile_linkhard1, simp+)
       
  2133 done
       
  2134 
       
  2135 lemma co2sobj_truncate:
       
  2136   "\<lbrakk>valid (Truncate p f len # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (Truncate p f len # s) obj = (
       
  2137       case obj of
       
  2138         O_file f' \<Rightarrow> if (f' \<in> same_inode_files s f \<and> len > 0)
       
  2139                      then Some (S_file (cf2sfiles s f') (O_file f' \<in> Tainted s \<or> O_proc p \<in> Tainted s))
       
  2140                      else co2sobj s obj
       
  2141       | _         \<Rightarrow> co2sobj s obj)"
       
  2142 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2143 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2144 
       
  2145 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2146              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2147                   same_inode_files_prop6
       
  2148              dest:is_file_in_current is_dir_in_current)
       
  2149 done
       
  2150 
       
  2151 lemma co2sobj_kill:
       
  2152   "\<lbrakk>valid (Kill p p' # s); alive (Kill p p' # s) obj\<rbrakk> \<Longrightarrow> co2sobj (Kill p p' # s) obj = co2sobj s obj"
       
  2153 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2154 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2155 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2156              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2157                   same_inode_files_prop6
       
  2158              dest:is_file_in_current is_dir_in_current)
       
  2159 done
       
  2160 
       
  2161 lemma co2sobj_exit:
       
  2162   "\<lbrakk>valid (Exit p # s); alive (Exit p # s) obj\<rbrakk> \<Longrightarrow> co2sobj (Exit p # s) obj = co2sobj s obj"
       
  2163 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2164 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2165 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2166              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2167                   same_inode_files_prop6
       
  2168              dest:is_file_in_current is_dir_in_current)
       
  2169 done
       
  2170 
       
  2171 lemma co2sobj_createmsgq:
       
  2172   "\<lbrakk>valid (CreateMsgq p q # s); alive (CreateMsgq p q # s) obj\<rbrakk> \<Longrightarrow> co2sobj (CreateMsgq p q # s) obj = (
       
  2173       case obj of
       
  2174         O_msgq q' \<Rightarrow> if (q' = q) then (case (cq2smsgq (CreateMsgq p q # s) q) of
       
  2175                                          Some sq \<Rightarrow> Some (S_msgq sq)
       
  2176                                        | _       \<Rightarrow> None)
       
  2177                      else co2sobj s obj
       
  2178       | _        \<Rightarrow> co2sobj s obj)"
       
  2179 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2180 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2181 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2182              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2183                   same_inode_files_prop6
       
  2184              dest!:current_has_smsgq'
       
  2185              dest:is_file_in_current is_dir_in_current cq2smsg_createmsgq)
       
  2186 done
       
  2187 
       
  2188 lemma co2sobj_sendmsg:
       
  2189   "\<lbrakk>valid (SendMsg p q m # s); alive (SendMsg p q m # s) obj\<rbrakk> \<Longrightarrow> co2sobj (SendMsg p q m # s) obj = (
       
  2190       case obj of
       
  2191         O_msgq q' \<Rightarrow> if (q' = q) then (case (cq2smsgq (SendMsg p q m # s) q) of
       
  2192                                          Some sq \<Rightarrow> Some (S_msgq sq)
       
  2193                                        | _       \<Rightarrow> None)
       
  2194                      else co2sobj s obj
       
  2195       | _        \<Rightarrow> co2sobj s obj)"
       
  2196 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2197 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2198 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2199              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2200                   same_inode_files_prop6
       
  2201              dest!:current_has_smsgq'
       
  2202              dest:is_file_in_current is_dir_in_current cq2smsg_sendmsg)
       
  2203 done
       
  2204 
       
  2205 lemma co2sobj_recvmsg:
       
  2206   "\<lbrakk>valid (RecvMsg p q m # s); alive (RecvMsg p q m # s) obj\<rbrakk> \<Longrightarrow> co2sobj (RecvMsg p q m # s) obj = (
       
  2207       case obj of
       
  2208         O_msgq q' \<Rightarrow> if (q' = q) then (case (cq2smsgq (RecvMsg p q m # s) q) of
       
  2209                                          Some sq \<Rightarrow> Some (S_msgq sq)
       
  2210                                        | _       \<Rightarrow> None)
       
  2211                      else co2sobj s obj
       
  2212       | O_proc p' \<Rightarrow> if (info_flow_shm s p p' \<and> O_msg q m \<in> Tainted s)
       
  2213                      then (case (cp2sproc s p') of
       
  2214                              Some sp \<Rightarrow> Some (S_proc sp True)
       
  2215                            | _       \<Rightarrow> None)
       
  2216                      else co2sobj s obj
       
  2217       | _         \<Rightarrow> co2sobj s obj)"
       
  2218 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2219 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2220 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2221              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2222                   same_inode_files_prop6
       
  2223              dest!:current_has_smsgq'
       
  2224              dest:is_file_in_current is_dir_in_current cq2smsg_recvmsg)
       
  2225 done
       
  2226 
       
  2227 lemma co2sobj_removemsgq:
       
  2228   "\<lbrakk>valid (RemoveMsgq p q # s); alive (RemoveMsgq p q # s) obj\<rbrakk> 
       
  2229    \<Longrightarrow> co2sobj (RemoveMsgq p q # s) obj = co2sobj s obj"
       
  2230 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2231 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2232 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2233              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2234                   same_inode_files_prop6
       
  2235              dest!:current_has_smsgq'
       
  2236              dest:is_file_in_current is_dir_in_current cq2smsg_removemsgq)
       
  2237 done
       
  2238 
       
  2239 lemma co2sobj_createshm:
       
  2240   "\<lbrakk>valid (CreateShM p h # s); alive (CreateShM p h # s) obj\<rbrakk> \<Longrightarrow> co2sobj (CreateShM p h # s) obj = (
       
  2241       case obj of 
       
  2242         O_shm h' \<Rightarrow> if (h' = h) then (case (ch2sshm (CreateShM p h # s) h) of
       
  2243                                         Some sh \<Rightarrow> Some (S_shm sh)
       
  2244                                       | _       \<Rightarrow> None)
       
  2245                     else co2sobj s obj
       
  2246       | _        \<Rightarrow> co2sobj s obj)"
       
  2247 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2248 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2249 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2250              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2251                   same_inode_files_prop6 ch2sshm_simps
       
  2252              dest!:current_shm_has_sh'
       
  2253              dest:is_file_in_current is_dir_in_current)
       
  2254 done
       
  2255 
       
  2256 lemma co2sobj_detach:
       
  2257   "\<lbrakk>valid (Detach p h # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (Detach p h # s) obj = (
       
  2258       case obj of
       
  2259         O_proc p' \<Rightarrow> if (p' = p) then (case (cp2sproc (Detach p h # s) p) of
       
  2260                                          Some sp \<Rightarrow> Some (S_proc sp (O_proc p \<in> Tainted s))
       
  2261                                        | _       \<Rightarrow> None)
       
  2262                      else co2sobj s obj
       
  2263       | _         \<Rightarrow> co2sobj s obj)"
       
  2264 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2265 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2266 
       
  2267 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2268              simp:current_files_simps cf2sfiles_simps cf2sfile_simps cp2sproc_simps tainted_eq_Tainted
       
  2269                   same_inode_files_prop6 ch2sshm_simps
       
  2270              dest!:current_shm_has_sh'
       
  2271              dest:is_file_in_current is_dir_in_current)
       
  2272 done
       
  2273 
       
  2274 lemma co2sobj_deleteshm:
       
  2275   "\<lbrakk>valid (DeleteShM p h # s); alive (DeleteShM p h # s) obj\<rbrakk> \<Longrightarrow> co2sobj (DeleteShM p h # s) obj = (
       
  2276       case obj of
       
  2277         O_proc p' \<Rightarrow> (case (cp2sproc (DeleteShM p h # s) p') of
       
  2278                         Some sp \<Rightarrow> Some (S_proc sp (O_proc p' \<in> Tainted s))
       
  2279                       | _       \<Rightarrow> None)
       
  2280       | _         \<Rightarrow> co2sobj s obj)"
       
  2281 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2282 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2283 
       
  2284 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' current_proc_has_sp'
       
  2285              simp:current_files_simps cf2sfiles_simps cf2sfile_simps tainted_eq_Tainted
       
  2286                   same_inode_files_prop6 ch2sshm_simps
       
  2287              dest!:current_shm_has_sh' 
       
  2288              dest:is_file_in_current is_dir_in_current)
       
  2289 done
       
  2290 
       
  2291 declare Product_Type.split_paired_Ex Product_Type.split_paired_All [simp del]
       
  2292 
       
  2293 lemma info_flow_shm_prop1:
       
  2294   "p \<in> current_procs s \<Longrightarrow> info_flow_shm s p p"
       
  2295 by (simp add:info_flow_shm_def)
       
  2296 
       
  2297 lemma co2sobj_attach:
       
  2298   "\<lbrakk>valid (Attach p h flag # s); alive s obj\<rbrakk> \<Longrightarrow> co2sobj (Attach p h flag # s) obj = (
       
  2299       case obj of
       
  2300         O_proc p' \<Rightarrow> if (info_flow_shm s p p')
       
  2301                      then (case (cp2sproc (Attach p h flag # s) p') of
       
  2302                              Some sp \<Rightarrow> Some (S_proc sp (O_proc p' \<in> Tainted s \<or> 
       
  2303               (\<exists> p''. O_proc p'' \<in> Tainted s \<and> (p'', SHM_RDWR) \<in> procs_of_shm s h)))
       
  2304                            | _       \<Rightarrow> None)
       
  2305                      else if (\<exists> p'' flag'. (p'', flag') \<in> procs_of_shm s h \<and> flag = SHM_RDWR \<and> O_proc p \<in> Tainted s \<and>
       
  2306   info_flow_shm s p'' p')
       
  2307                           then (case (cp2sproc s p') of 
       
  2308                                   Some sp \<Rightarrow> Some (S_proc sp True)
       
  2309                                 | _       \<Rightarrow> None)
       
  2310                           else co2sobj s obj
       
  2311       | _         \<Rightarrow> co2sobj s obj)"
       
  2312 apply (frule vt_grant_os, frule vd_cons, case_tac obj)
       
  2313 apply (simp_all add:current_files_simps is_dir_simps ch2sshm_other cq2smsgq_other tainted_eq_Tainted)
       
  2314 
       
  2315 apply (rule conjI|rule impI|erule exE)+
       
  2316 apply (simp split:option.splits del:split_paired_Ex)
       
  2317 apply (rule impI, frule current_proc_has_sp, simp)
       
  2318 apply ((erule exE)+, auto simp:tainted_eq_Tainted intro:info_flow_shm_Tainted)[1]
       
  2319 apply (rule impI, simp add:tainted_eq_Tainted split:option.splits del:split_paired_Ex)
       
  2320 apply (auto simp:info_flow_shm_prop1 cp2sproc_attach dest!:current_proc_has_sp')[1]
       
  2321 
       
  2322 apply (case_tac "cp2sproc (Attach p h flag # s) nat")
       
  2323 apply (drule current_proc_has_sp', simp+)
       
  2324 
       
  2325 apply (rule conjI|erule exE|erule conjE|rule impI)+
       
  2326 apply (simp add:tainted_eq_Tainted)
       
  2327 apply (auto simp:info_flow_shm_prop1 cp2sproc_attach intro:info_flow_shm_Tainted dest!:current_proc_has_sp')[1]
       
  2328 apply (auto simp:info_flow_shm_prop1 cp2sproc_attach tainted_eq_Tainted intro:info_flow_shm_Tainted dest!:current_proc_has_sp'
       
  2329 split:option.splits if_splits)[1]
       
  2330 
       
  2331 
       
  2332 apply (auto split:if_splits option.splits dest!:current_file_has_sfile' 
       
  2333              simp:current_files_simps cf2sfiles_simps cf2sfile_simps tainted_eq_Tainted
       
  2334                   same_inode_files_prop6 
       
  2335              dest:is_file_in_current is_dir_in_current)
       
  2336 done
       
  2337 
       
  2338 
       
  2339 lemma co2sobj_other:
       
  2340   "\<lbrakk>valid (e # s); alive (e # s) obj; 
       
  2341     \<forall> p f fds. e \<noteq> Execve p f fds;
       
  2342     \<forall> p p' fds shms. e \<noteq> Clone p p' fds shms;
       
  2343     \<forall> p p'. e \<noteq> Ptrace p p';
       
  2344     \<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
       
  2345     \<forall> p fd. e \<noteq> ReadFile p fd;
       
  2346     \<forall> p fd. e \<noteq> WriteFile p fd;
       
  2347     \<forall> p fd. e \<noteq> CloseFd p fd;
       
  2348     \<forall> p f. e \<noteq> UnLink p f;
       
  2349     \<forall> p f. e \<noteq> Rmdir p f;
       
  2350     \<forall> p f i. e \<noteq> Mkdir p f i;
       
  2351     \<forall> p f f'. e \<noteq> LinkHard p f f';
       
  2352     \<forall> p f len. e \<noteq> Truncate p f len;
       
  2353     \<forall> p q. e \<noteq> CreateMsgq p q;
       
  2354     \<forall> p q m. e \<noteq> SendMsg p q m;
       
  2355     \<forall> p q m. e \<noteq> RecvMsg p q m;
       
  2356     \<forall> p q. e \<noteq> RemoveMsgq p q;
       
  2357     \<forall> p h. e \<noteq> CreateShM p h;
       
  2358     \<forall> p h flag. e \<noteq> Attach p h flag;
       
  2359     \<forall> p h. e \<noteq> Detach p h;
       
  2360     \<forall> p h. e \<noteq> DeleteShM p h
       
  2361    \<rbrakk> \<Longrightarrow> co2sobj (e # s) obj = co2sobj s obj"
       
  2362 apply (frule vt_grant, case_tac e)
       
  2363 apply (auto intro:co2sobj_kill co2sobj_exit)
       
  2364 done
       
  2365 
       
  2366 lemmas co2sobj_simps = co2sobj_execve co2sobj_clone co2sobj_ptrace co2sobj_open co2sobj_readfile
       
  2367   co2sobj_writefile co2sobj_closefd co2sobj_unlink co2sobj_rmdir co2sobj_mkdir co2sobj_linkhard
       
  2368   co2sobj_truncate co2sobj_kill co2sobj_exit co2sobj_createmsgq co2sobj_sendmsg co2sobj_recvmsg
       
  2369   co2sobj_removemsgq co2sobj_attach co2sobj_detach co2sobj_createshm co2sobj_deleteshm
       
  2370 
       
  2371 
       
  2372 
       
  2373 end
       
  2374 
       
  2375 (*<*)
       
  2376 end
       
  2377 (*>*)