no_shm_selinux/Enrich.thy
author chunhan
Wed, 18 Dec 2013 10:44:36 +0800
changeset 78 030643fab8a1
parent 77 6f7b9039715f
child 79 c09fcbcdb871
permissions -rw-r--r--
Enrich
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77
chunhan
parents:
diff changeset
     1
theory Enrich
chunhan
parents:
diff changeset
     2
imports Main Flask Static Init_prop Valid_prop Tainted_prop Delete_prop Co2sobj_prop S2ss_prop S2ss_prop2
chunhan
parents:
diff changeset
     3
 Temp
chunhan
parents:
diff changeset
     4
begin
chunhan
parents:
diff changeset
     5
78
chunhan
parents: 77
diff changeset
     6
datatype t_enrich_obj = 
chunhan
parents: 77
diff changeset
     7
  E_proc "t_process"
chunhan
parents: 77
diff changeset
     8
| E_file "t_file"
chunhan
parents: 77
diff changeset
     9
| E_fd   "t_process" "t_fd"
chunhan
parents: 77
diff changeset
    10
| E_inum "nat"
chunhan
parents: 77
diff changeset
    11
| E_msgq "t_msgq"
chunhan
parents: 77
diff changeset
    12
| E_msg  "t_msgq"    "t_msg"
chunhan
parents: 77
diff changeset
    13
77
chunhan
parents:
diff changeset
    14
context tainting_s begin
chunhan
parents:
diff changeset
    15
chunhan
parents:
diff changeset
    16
(* enrich s target_proc duplicated_pro *)
chunhan
parents:
diff changeset
    17
fun enrich_proc :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> t_state"
chunhan
parents:
diff changeset
    18
where 
chunhan
parents:
diff changeset
    19
  "enrich_proc [] tp dp = []"
chunhan
parents:
diff changeset
    20
| "enrich_proc (Execve p f fds # s) tp dp = (
chunhan
parents:
diff changeset
    21
     if (tp = p) 
chunhan
parents:
diff changeset
    22
     then Execve dp f (fds \<inter> proc_file_fds s p) # Execve p f fds # (enrich_proc s tp dp)
chunhan
parents:
diff changeset
    23
     else Execve p f fds # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    24
| "enrich_proc (Clone p p' fds # s) tp dp = (
chunhan
parents:
diff changeset
    25
     if (tp = p') 
chunhan
parents:
diff changeset
    26
     then Clone p dp (fds \<inter> proc_file_fds s p) # Clone p p' fds # s
chunhan
parents:
diff changeset
    27
     else Clone p p' fds # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    28
| "enrich_proc (Open p f flags fd opt # s) tp dp = (
chunhan
parents:
diff changeset
    29
     if (tp = p)
chunhan
parents:
diff changeset
    30
     then Open dp f (remove_create_flag flags) fd opt # Open p f flags fd opt # (enrich_proc s tp dp)
chunhan
parents:
diff changeset
    31
     else Open p f flags fd opt # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    32
| "enrich_proc (CloseFd p fd # s) tp dp = (
chunhan
parents:
diff changeset
    33
     if (tp = p)
chunhan
parents:
diff changeset
    34
     then CloseFd dp fd # CloseFd p fd # (enrich_proc s tp dp)
chunhan
parents:
diff changeset
    35
     else CloseFd p fd # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    36
(*
chunhan
parents:
diff changeset
    37
| "enrich_proc (Attach p h flag # s) tp dp = (
chunhan
parents:
diff changeset
    38
     if (tp = p)
chunhan
parents:
diff changeset
    39
     then Attach dp h flag # Attach p h flag # (enrich_proc s tp dp)
chunhan
parents:
diff changeset
    40
     else Attach p h flag # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    41
| "enrich_proc (Detach p h # s) tp dp = (
chunhan
parents:
diff changeset
    42
     if (tp = p) 
chunhan
parents:
diff changeset
    43
     then Detach dp h # Detach p h # (enrich_proc s tp dp)
chunhan
parents:
diff changeset
    44
     else Detach p h # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    45
*)
chunhan
parents:
diff changeset
    46
| "enrich_proc (Kill p p' # s) tp dp = (
chunhan
parents:
diff changeset
    47
     if (tp = p) then Kill p p' # s
chunhan
parents:
diff changeset
    48
     else Kill p p' # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    49
| "enrich_proc (Exit p # s) tp dp = (
chunhan
parents:
diff changeset
    50
     if (tp = p) then Exit p # s
chunhan
parents:
diff changeset
    51
     else Exit p # (enrich_proc s tp dp))"
chunhan
parents:
diff changeset
    52
| "enrich_proc (e # s) tp dp = e # (enrich_proc s tp dp)"
chunhan
parents:
diff changeset
    53
chunhan
parents:
diff changeset
    54
definition is_created_proc:: "t_state \<Rightarrow> t_process \<Rightarrow> bool"
chunhan
parents:
diff changeset
    55
where
chunhan
parents:
diff changeset
    56
  "is_created_proc s p \<equiv> p \<in> init_procs \<longrightarrow> died (O_proc p) s"
chunhan
parents:
diff changeset
    57
chunhan
parents:
diff changeset
    58
lemma enrich_search_check:
chunhan
parents:
diff changeset
    59
  assumes grant: "search_check s (up, rp, tp) f"
chunhan
parents:
diff changeset
    60
  and cf2sf: "\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile s' f = cf2sfile s f"
chunhan
parents:
diff changeset
    61
  and vd: "valid s" and f_in: "is_file s f"  and f_in': "is_file s' f"
chunhan
parents:
diff changeset
    62
  and sec: "sectxt_of_obj s' (O_file f) = sectxt_of_obj s (O_file f)"
chunhan
parents:
diff changeset
    63
  shows "search_check s' (up, rp, tp) f"
chunhan
parents:
diff changeset
    64
proof (cases f)
chunhan
parents:
diff changeset
    65
  case Nil
chunhan
parents:
diff changeset
    66
  with f_in vd have "False" 
chunhan
parents:
diff changeset
    67
    by (auto dest:root_is_dir') 
chunhan
parents:
diff changeset
    68
  thus ?thesis by simp
chunhan
parents:
diff changeset
    69
next
chunhan
parents:
diff changeset
    70
  case (Cons n pf)
chunhan
parents:
diff changeset
    71
  from vd f_in obtain sf where sf: "cf2sfile s f = Some sf"
chunhan
parents:
diff changeset
    72
    apply (drule_tac is_file_in_current, drule_tac current_file_has_sfile, simp)
chunhan
parents:
diff changeset
    73
    apply (erule exE, simp)
chunhan
parents:
diff changeset
    74
    done
chunhan
parents:
diff changeset
    75
  then obtain psfs where psfs: "get_parentfs_ctxts s pf = Some psfs" using Cons
chunhan
parents:
diff changeset
    76
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents:
diff changeset
    77
  from sf cf2sf f_in have sf': "cf2sfile s' f = Some sf" by (auto dest:is_file_in_current)
chunhan
parents:
diff changeset
    78
  then obtain psfs' where psfs': "get_parentfs_ctxts s' pf = Some psfs'"using Cons
chunhan
parents:
diff changeset
    79
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents:
diff changeset
    80
  with sf sf' psfs have psfs_eq: "set psfs' = set psfs" using Cons f_in f_in'
chunhan
parents:
diff changeset
    81
    apply (simp add:cf2sfile_def split:option.splits)
chunhan
parents:
diff changeset
    82
    apply (case_tac sf, simp)
chunhan
parents:
diff changeset
    83
    done
chunhan
parents:
diff changeset
    84
  show ?thesis using grant f_in f_in' psfs psfs' psfs_eq sec
chunhan
parents:
diff changeset
    85
    apply (simp add:Cons split:option.splits)
chunhan
parents:
diff changeset
    86
    by (case_tac a, simp)
chunhan
parents:
diff changeset
    87
qed
chunhan
parents:
diff changeset
    88
78
chunhan
parents: 77
diff changeset
    89
lemma enrich_search_check':
chunhan
parents: 77
diff changeset
    90
  assumes grant: "search_check s (up, rp, tp) f"
chunhan
parents: 77
diff changeset
    91
  and cf2sf: "\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile s' f = cf2sfile s f"
chunhan
parents: 77
diff changeset
    92
  and vd: "valid s" and vd': "valid s'" and f_in: "is_dir s f"  and f_in': "is_dir s' f"
chunhan
parents: 77
diff changeset
    93
  and sec: "sectxt_of_obj s' (O_dir f) = sectxt_of_obj s (O_dir f)"
chunhan
parents: 77
diff changeset
    94
  shows "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
    95
proof (cases f)
chunhan
parents: 77
diff changeset
    96
  case Nil
chunhan
parents: 77
diff changeset
    97
  have "sectxt_of_obj s' (O_dir []) = sectxt_of_obj s (O_dir [])"
chunhan
parents: 77
diff changeset
    98
    using cf2sf 
chunhan
parents: 77
diff changeset
    99
    apply (erule_tac x = "[]" in allE)
chunhan
parents: 77
diff changeset
   100
    by (auto simp:cf2sfile_def root_sec_remains vd vd')
chunhan
parents: 77
diff changeset
   101
  thus ?thesis using grant Nil 
chunhan
parents: 77
diff changeset
   102
    by auto
chunhan
parents: 77
diff changeset
   103
next
chunhan
parents: 77
diff changeset
   104
  case (Cons n pf)
chunhan
parents: 77
diff changeset
   105
  from vd f_in obtain sf where sf: "cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   106
    apply (drule_tac is_dir_in_current, drule_tac current_file_has_sfile, simp)
chunhan
parents: 77
diff changeset
   107
    apply (erule exE, simp)
chunhan
parents: 77
diff changeset
   108
    done
chunhan
parents: 77
diff changeset
   109
  then obtain psfs where psfs: "get_parentfs_ctxts s pf = Some psfs" using Cons
chunhan
parents: 77
diff changeset
   110
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents: 77
diff changeset
   111
  from sf cf2sf f_in have sf': "cf2sfile s' f = Some sf" by (auto dest:is_dir_in_current)
chunhan
parents: 77
diff changeset
   112
  then obtain psfs' where psfs': "get_parentfs_ctxts s' pf = Some psfs'"using Cons
chunhan
parents: 77
diff changeset
   113
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents: 77
diff changeset
   114
  with sf sf' psfs have psfs_eq: "set psfs' = set psfs" using Cons f_in f_in'
chunhan
parents: 77
diff changeset
   115
    apply (drule_tac is_dir_not_file)
chunhan
parents: 77
diff changeset
   116
    apply (drule is_dir_not_file)    
chunhan
parents: 77
diff changeset
   117
    apply (simp add:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   118
    apply (case_tac sf, simp)
chunhan
parents: 77
diff changeset
   119
    done
chunhan
parents: 77
diff changeset
   120
  show ?thesis using grant f_in f_in' psfs psfs' psfs_eq sec
chunhan
parents: 77
diff changeset
   121
    apply (drule_tac is_dir_not_file)
chunhan
parents: 77
diff changeset
   122
    apply (drule_tac is_dir_not_file)
chunhan
parents: 77
diff changeset
   123
    apply (simp add:Cons split:option.splits)
chunhan
parents: 77
diff changeset
   124
    by (case_tac a, simp)
chunhan
parents: 77
diff changeset
   125
qed
chunhan
parents: 77
diff changeset
   126
77
chunhan
parents:
diff changeset
   127
lemma proc_filefd_has_sfd: "\<lbrakk>fd \<in> proc_file_fds s p; valid s\<rbrakk> \<Longrightarrow> \<exists> sfd. cfd2sfd s p fd = Some sfd"
chunhan
parents:
diff changeset
   128
apply (simp add:proc_file_fds_def)
chunhan
parents:
diff changeset
   129
apply (auto dest: current_filefd_has_sfd)
chunhan
parents:
diff changeset
   130
done
chunhan
parents:
diff changeset
   131
chunhan
parents:
diff changeset
   132
lemma enrich_inherit_fds_check:
chunhan
parents:
diff changeset
   133
  assumes grant: "inherit_fds_check s (up, nr, nt) p fds"  and vd: "valid s"
chunhan
parents:
diff changeset
   134
  and cfd2sfd: "\<forall> p fd. fd \<in> proc_file_fds s p\<longrightarrow> cfd2sfd s' p fd = cfd2sfd s p fd"
chunhan
parents:
diff changeset
   135
  and fd_in: "fds \<subseteq> proc_file_fds s p" and fd_in': "fds \<subseteq> proc_file_fds s' p"
chunhan
parents:
diff changeset
   136
  shows "inherit_fds_check s' (up, nr, nt) p fds"
chunhan
parents:
diff changeset
   137
proof-
chunhan
parents:
diff changeset
   138
  have "\<And> fd. fd \<in> fds \<Longrightarrow> sectxt_of_obj s' (O_fd p fd) = sectxt_of_obj s (O_fd p fd)"
chunhan
parents:
diff changeset
   139
  proof-
chunhan
parents:
diff changeset
   140
    fix fd
chunhan
parents:
diff changeset
   141
    assume fd_in_fds: "fd \<in> fds"
chunhan
parents:
diff changeset
   142
    hence fd_in_cfds: "fd \<in> proc_file_fds s p" 
chunhan
parents:
diff changeset
   143
      and fd_in_cfds': "fd \<in> proc_file_fds s' p" 
chunhan
parents:
diff changeset
   144
      using fd_in fd_in' by auto
chunhan
parents:
diff changeset
   145
    with cfd2sfd
chunhan
parents:
diff changeset
   146
    have cfd_eq: "cfd2sfd s' p fd = cfd2sfd s p fd" by auto
chunhan
parents:
diff changeset
   147
    from fd_in_cfds obtain f where ffd: "file_of_proc_fd s p fd = Some f"
chunhan
parents:
diff changeset
   148
      by (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   149
    moreover have "flags_of_proc_fd s p fd \<noteq> None"
chunhan
parents:
diff changeset
   150
      using ffd vd by (auto dest:current_filefd_has_flags)
chunhan
parents:
diff changeset
   151
    moreover have "sectxt_of_obj s (O_fd p fd) \<noteq> None"
chunhan
parents:
diff changeset
   152
      using fd_in_cfds vd
chunhan
parents:
diff changeset
   153
      apply (rule_tac notI)
chunhan
parents:
diff changeset
   154
      by (auto dest!:current_has_sec' file_fds_subset_pfds[where p = p] intro:vd)
chunhan
parents:
diff changeset
   155
    moreover have "cf2sfile s f \<noteq> None"
chunhan
parents:
diff changeset
   156
      apply (rule notI)
chunhan
parents:
diff changeset
   157
      apply (drule current_file_has_sfile')
chunhan
parents:
diff changeset
   158
      using ffd
chunhan
parents:
diff changeset
   159
      by (auto simp:vd is_file_in_current dest:file_of_pfd_is_file)
chunhan
parents:
diff changeset
   160
    ultimately show "sectxt_of_obj s' (O_fd p fd) = sectxt_of_obj s (O_fd p fd)"
chunhan
parents:
diff changeset
   161
      using cfd_eq
chunhan
parents:
diff changeset
   162
      by (auto simp:cfd2sfd_def split:option.splits)
chunhan
parents:
diff changeset
   163
  qed
chunhan
parents:
diff changeset
   164
  hence "sectxts_of_fds s' p fds = sectxts_of_fds s p fds"
chunhan
parents:
diff changeset
   165
    by (simp add:sectxts_of_fds_def)
chunhan
parents:
diff changeset
   166
  thus ?thesis using grant
chunhan
parents:
diff changeset
   167
    by (simp add:inherit_fds_check_def)
chunhan
parents:
diff changeset
   168
qed
chunhan
parents:
diff changeset
   169
chunhan
parents:
diff changeset
   170
lemma not_all_procs_cons:
chunhan
parents:
diff changeset
   171
  "p \<notin> all_procs (e # s) \<Longrightarrow> p \<notin> all_procs s"
chunhan
parents:
diff changeset
   172
by (case_tac e, auto)
chunhan
parents:
diff changeset
   173
chunhan
parents:
diff changeset
   174
lemma not_all_procs_prop:
chunhan
parents:
diff changeset
   175
  "\<lbrakk>p' \<notin> all_procs s; p \<in> current_procs s; valid s\<rbrakk> \<Longrightarrow> p' \<noteq> p"
chunhan
parents:
diff changeset
   176
apply (induct s, rule notI, simp)
chunhan
parents:
diff changeset
   177
apply (frule vt_grant_os, frule vd_cons, frule not_all_procs_cons, simp, rule notI)
chunhan
parents:
diff changeset
   178
apply (case_tac a, auto)
chunhan
parents:
diff changeset
   179
done
chunhan
parents:
diff changeset
   180
78
chunhan
parents: 77
diff changeset
   181
fun enrich_not_alive :: "t_state \<Rightarrow> t_enrich_obj \<Rightarrow> bool"
77
chunhan
parents:
diff changeset
   182
where
78
chunhan
parents: 77
diff changeset
   183
  "enrich_not_alive s (E_file f) = (f \<notin> current_files s)"
chunhan
parents: 77
diff changeset
   184
| "enrich_not_alive s (E_proc p) = (p \<notin> current_procs s)"
chunhan
parents: 77
diff changeset
   185
| "enrich_not_alive s (E_fd p fd) = (p \<in> current_procs s \<longrightarrow> fd \<notin> current_proc_fds s p)"
chunhan
parents: 77
diff changeset
   186
| "enrich_not_alive s (E_msgq q) = (q \<notin> current_msgqs s)"
chunhan
parents: 77
diff changeset
   187
| "enrich_not_alive s (E_inum i) = (i \<notin> current_inode_nums s)"
chunhan
parents: 77
diff changeset
   188
| "enrich_not_alive s (E_msg q m) = (q \<in> current_msgqs s \<longrightarrow> m \<notin> set (msgs_of_queue s q))"
chunhan
parents: 77
diff changeset
   189
chunhan
parents: 77
diff changeset
   190
lemma file_has_parent: "\<lbrakk>is_file s f; valid s\<rbrakk> \<Longrightarrow> \<exists> pf. is_dir s pf \<and> parent f = Some pf"
chunhan
parents: 77
diff changeset
   191
apply (case_tac f)
chunhan
parents: 77
diff changeset
   192
apply (simp, drule root_is_dir', simp+)
chunhan
parents: 77
diff changeset
   193
apply (simp add:parentf_is_dir_prop2)
chunhan
parents: 77
diff changeset
   194
done
77
chunhan
parents:
diff changeset
   195
chunhan
parents:
diff changeset
   196
lemma enrich_valid_intro_cons:
chunhan
parents:
diff changeset
   197
  assumes vs': "valid s'"
chunhan
parents:
diff changeset
   198
    and os: "os_grant s e" and grant: "grant s e" and vd: "valid s"
chunhan
parents:
diff changeset
   199
    and alive: "\<forall> obj. alive s obj \<longrightarrow> alive s' obj"
chunhan
parents:
diff changeset
   200
    and alive': "\<forall> obj. enrich_not_alive s obj \<longrightarrow> enrich_not_alive s' obj"
78
chunhan
parents: 77
diff changeset
   201
    and hungs: "files_hung_by_del s' = files_hung_by_del s"
77
chunhan
parents:
diff changeset
   202
    and cp2sp: "\<forall> p. p \<in> current_procs s \<longrightarrow> cp2sproc s' p = cp2sproc s p"
chunhan
parents:
diff changeset
   203
    and cf2sf: "\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile s' f = cf2sfile s f"
78
chunhan
parents: 77
diff changeset
   204
    and cq2sq: "\<forall> q. q \<in> current_msgqs s \<longrightarrow> cq2smsgq s' q = cq2smsgq s q"
77
chunhan
parents:
diff changeset
   205
    and ffd_remain: "\<forall> p fd f. file_of_proc_fd s p fd = Some f \<longrightarrow> file_of_proc_fd s' p fd = Some f"
78
chunhan
parents: 77
diff changeset
   206
    and fflags_remain: "\<forall> p fd flags. flags_of_proc_fd s p fd = Some flags \<longrightarrow> flags_of_proc_fd s' p fd = Some flags"
chunhan
parents: 77
diff changeset
   207
    and sms_remain: "\<forall> q. msgs_of_queue s' q = msgs_of_queue s q"
chunhan
parents: 77
diff changeset
   208
   (* and empty_remain: "\<forall> f. dir_is_empty s f \<longrightarrow> dir_is_empty s' f" *)
77
chunhan
parents:
diff changeset
   209
    and cfd2sfd: "\<forall> p fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd s' p fd = cfd2sfd s p fd"
chunhan
parents:
diff changeset
   210
  shows "valid (e # s')"
chunhan
parents:
diff changeset
   211
proof (cases e)
chunhan
parents:
diff changeset
   212
  case (Execve p f fds)
chunhan
parents:
diff changeset
   213
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents:
diff changeset
   214
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents:
diff changeset
   215
    by (auto simp:Execve)
chunhan
parents:
diff changeset
   216
  have f_in: "is_file s' f" using os alive
chunhan
parents:
diff changeset
   217
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents:
diff changeset
   218
    by (auto simp:Execve)
chunhan
parents:
diff changeset
   219
  have fd_in: "fds \<subseteq> proc_file_fds s' p" using os alive ffd_remain
chunhan
parents:
diff changeset
   220
    by (auto simp:Execve proc_file_fds_def)
chunhan
parents:
diff changeset
   221
  have "os_grant s' e" using p_in f_in fd_in by (simp add:Execve)
chunhan
parents:
diff changeset
   222
  moreover have "grant s' e"
chunhan
parents:
diff changeset
   223
  proof-
chunhan
parents:
diff changeset
   224
    from grant obtain up rp tp uf rf tf 
chunhan
parents:
diff changeset
   225
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   226
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents:
diff changeset
   227
      by (simp add:Execve split:option.splits, blast)
chunhan
parents:
diff changeset
   228
    with grant obtain pu nr nt where p3: "npctxt_execve (up, rp, tp) (uf, rf, tf) = Some (pu, nr, nt)"
chunhan
parents:
diff changeset
   229
      by (simp add:Execve split:option.splits del:npctxt_execve.simps, blast)
chunhan
parents:
diff changeset
   230
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   231
      using os cp2sp
chunhan
parents:
diff changeset
   232
      apply (erule_tac x = p in allE)
chunhan
parents:
diff changeset
   233
      by (auto simp:Execve co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   234
    from os have f_in': "is_file s f" by (simp add:Execve)
chunhan
parents:
diff changeset
   235
    from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents:
diff changeset
   236
      by (auto dest!:is_file_in_current current_file_has_sfile simp:Execve)
chunhan
parents:
diff changeset
   237
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" using f_in f_in' p2 cf2sf
chunhan
parents:
diff changeset
   238
      apply (erule_tac x = f in allE)
chunhan
parents:
diff changeset
   239
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents:
diff changeset
   240
      apply (case_tac f, simp)
chunhan
parents:
diff changeset
   241
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents:
diff changeset
   242
      done
chunhan
parents:
diff changeset
   243
    have "inherit_fds_check s' (pu, nr, nt) p fds"
chunhan
parents:
diff changeset
   244
    proof-
chunhan
parents:
diff changeset
   245
      have "fds \<subseteq> proc_file_fds s' p" using os ffd_remain Execve
chunhan
parents:
diff changeset
   246
        by (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   247
      thus ?thesis using Execve grant vd cfd2sfd p1 p2 p3 os
chunhan
parents:
diff changeset
   248
        apply (rule_tac s = s in enrich_inherit_fds_check)
chunhan
parents:
diff changeset
   249
        by (simp_all split:option.splits)
chunhan
parents:
diff changeset
   250
    qed
chunhan
parents:
diff changeset
   251
    moreover have "search_check s' (pu, rp, tp) f"
chunhan
parents:
diff changeset
   252
      using p1 p2 p2' vd cf2sf f_in' grant Execve p3 f_in
chunhan
parents:
diff changeset
   253
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents:
diff changeset
   254
      by (simp_all split:option.splits)
chunhan
parents:
diff changeset
   255
    ultimately show ?thesis using p1' p2' p3
chunhan
parents:
diff changeset
   256
      apply (simp add:Execve split:option.splits) 
chunhan
parents:
diff changeset
   257
      using grant Execve p1 p2
chunhan
parents:
diff changeset
   258
      by (simp add:Execve grant p1 p2)
chunhan
parents:
diff changeset
   259
  qed
chunhan
parents:
diff changeset
   260
  ultimately show ?thesis using vs'
chunhan
parents:
diff changeset
   261
    by (erule_tac valid.intros(2), simp+)
chunhan
parents:
diff changeset
   262
next
chunhan
parents:
diff changeset
   263
  case (Clone p p' fds)
chunhan
parents:
diff changeset
   264
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents:
diff changeset
   265
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents:
diff changeset
   266
    by (auto simp:Clone)
chunhan
parents:
diff changeset
   267
  have p'_not_in: "p' \<notin> current_procs s'" using os alive'
78
chunhan
parents: 77
diff changeset
   268
    apply (erule_tac x = "E_proc p'" in allE)
77
chunhan
parents:
diff changeset
   269
    by (auto simp:Clone)
chunhan
parents:
diff changeset
   270
  have fd_in: "fds \<subseteq> proc_file_fds s' p" using os alive ffd_remain
chunhan
parents:
diff changeset
   271
    by (auto simp:Clone proc_file_fds_def)
chunhan
parents:
diff changeset
   272
  have "os_grant s' e" using p_in p'_not_in fd_in by (simp add:Clone)
chunhan
parents:
diff changeset
   273
  moreover have "grant s' e" 
chunhan
parents:
diff changeset
   274
  proof-
chunhan
parents:
diff changeset
   275
    from grant obtain up rp tp 
chunhan
parents:
diff changeset
   276
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   277
      apply (simp add:Clone split:option.splits)
chunhan
parents:
diff changeset
   278
      by (case_tac a, auto)
chunhan
parents:
diff changeset
   279
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   280
      using os cp2sp
chunhan
parents:
diff changeset
   281
      apply (erule_tac x = p in allE)
chunhan
parents:
diff changeset
   282
      by (auto simp:Clone co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   283
    have p2: "inherit_fds_check s' (up, rp, tp) p fds"
chunhan
parents:
diff changeset
   284
    proof-
chunhan
parents:
diff changeset
   285
      have "fds \<subseteq> proc_file_fds s' p" using os ffd_remain Clone
chunhan
parents:
diff changeset
   286
        by (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   287
      thus ?thesis using Clone grant vd cfd2sfd p1 os
chunhan
parents:
diff changeset
   288
        apply (rule_tac s = s in enrich_inherit_fds_check)
chunhan
parents:
diff changeset
   289
        by (simp_all split:option.splits)
chunhan
parents:
diff changeset
   290
    qed
chunhan
parents:
diff changeset
   291
    show ?thesis using p1 p2 p1' grant
chunhan
parents:
diff changeset
   292
      by (simp add:Clone)
chunhan
parents:
diff changeset
   293
  qed
chunhan
parents:
diff changeset
   294
  ultimately show ?thesis using vs'
chunhan
parents:
diff changeset
   295
    by (erule_tac valid.intros(2), simp+)
chunhan
parents:
diff changeset
   296
next
78
chunhan
parents: 77
diff changeset
   297
  case (Kill p p')
chunhan
parents: 77
diff changeset
   298
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   299
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   300
    by (auto simp:Kill)
chunhan
parents: 77
diff changeset
   301
  have p'_in: "p' \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   302
    apply (erule_tac x = "O_proc p'" in allE)
chunhan
parents: 77
diff changeset
   303
    by (auto simp:Kill)
chunhan
parents: 77
diff changeset
   304
  have "os_grant s' e" using p_in p'_in by (simp add:Kill)
chunhan
parents: 77
diff changeset
   305
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   306
  proof-
chunhan
parents: 77
diff changeset
   307
    from grant obtain up rp tp up' rp' tp'
chunhan
parents: 77
diff changeset
   308
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   309
      and p'1: "sectxt_of_obj s (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   310
      apply (simp add:Kill split:option.splits)
chunhan
parents: 77
diff changeset
   311
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   312
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   313
      using os cp2sp
chunhan
parents: 77
diff changeset
   314
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   315
      by (auto simp:Kill co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   316
    from p'1 have p'1': "sectxt_of_obj s' (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   317
      using os cp2sp
chunhan
parents: 77
diff changeset
   318
      apply (erule_tac x = p' in allE)
chunhan
parents: 77
diff changeset
   319
      by (auto simp:Kill co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   320
    show ?thesis using p1 p'1 p1' p'1' grant
chunhan
parents: 77
diff changeset
   321
      by (simp add:Kill)
chunhan
parents: 77
diff changeset
   322
  qed
chunhan
parents: 77
diff changeset
   323
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   324
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   325
next
chunhan
parents: 77
diff changeset
   326
  case (Ptrace p p')
chunhan
parents: 77
diff changeset
   327
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   328
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   329
    by (auto simp:Ptrace)
chunhan
parents: 77
diff changeset
   330
  have p'_in: "p' \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   331
    apply (erule_tac x = "O_proc p'" in allE)
chunhan
parents: 77
diff changeset
   332
    by (auto simp:Ptrace)
chunhan
parents: 77
diff changeset
   333
  have "os_grant s' e" using p_in p'_in by (simp add:Ptrace)
chunhan
parents: 77
diff changeset
   334
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   335
  proof-
chunhan
parents: 77
diff changeset
   336
    from grant obtain up rp tp up' rp' tp'
chunhan
parents: 77
diff changeset
   337
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   338
      and p'1: "sectxt_of_obj s (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   339
      apply (simp add:Ptrace split:option.splits)
chunhan
parents: 77
diff changeset
   340
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   341
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   342
      using os cp2sp
chunhan
parents: 77
diff changeset
   343
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   344
      by (auto simp:Ptrace co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   345
    from p'1 have p'1': "sectxt_of_obj s' (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   346
      using os cp2sp
chunhan
parents: 77
diff changeset
   347
      apply (erule_tac x = p' in allE)
chunhan
parents: 77
diff changeset
   348
      by (auto simp:Ptrace co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   349
    show ?thesis using p1 p'1 p1' p'1' grant
chunhan
parents: 77
diff changeset
   350
      by (simp add:Ptrace)
chunhan
parents: 77
diff changeset
   351
  qed
chunhan
parents: 77
diff changeset
   352
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   353
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   354
next
chunhan
parents: 77
diff changeset
   355
  case (Exit p)
chunhan
parents: 77
diff changeset
   356
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   357
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   358
    by (auto simp:Exit)
chunhan
parents: 77
diff changeset
   359
  have "os_grant s' e" using p_in by (simp add:Exit)
chunhan
parents: 77
diff changeset
   360
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   361
    by (simp add:Exit)
chunhan
parents: 77
diff changeset
   362
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   363
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   364
next
chunhan
parents: 77
diff changeset
   365
  case (Open p f flags fd opt)
chunhan
parents: 77
diff changeset
   366
  show ?thesis
chunhan
parents: 77
diff changeset
   367
  proof (cases opt)
chunhan
parents: 77
diff changeset
   368
    case None
chunhan
parents: 77
diff changeset
   369
    have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   370
      apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   371
      by (auto simp:Open None)
chunhan
parents: 77
diff changeset
   372
    have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   373
      apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   374
      by (auto simp:Open None)
chunhan
parents: 77
diff changeset
   375
    have fd_not_in: "fd \<notin> current_proc_fds s' p"
chunhan
parents: 77
diff changeset
   376
      using os alive' p_in
chunhan
parents: 77
diff changeset
   377
      apply (erule_tac x = "E_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   378
      by (simp add:Open None)
chunhan
parents: 77
diff changeset
   379
    have "os_grant s' e" using p_in f_in fd_not_in os
chunhan
parents: 77
diff changeset
   380
      by (simp add:Open None)
chunhan
parents: 77
diff changeset
   381
    moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   382
    proof-
chunhan
parents: 77
diff changeset
   383
      from grant obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   384
        where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   385
        and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   386
        apply (simp add:Open None split:option.splits)
chunhan
parents: 77
diff changeset
   387
        by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   388
      from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   389
        using os cp2sp
chunhan
parents: 77
diff changeset
   390
        apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   391
        by (auto simp:Open None co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   392
      from os have f_in': "is_file s f" by (simp add:Open None)
chunhan
parents: 77
diff changeset
   393
      from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   394
        by (auto dest!:is_file_in_current current_file_has_sfile simp:Open None)
chunhan
parents: 77
diff changeset
   395
      hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" using f_in f_in' p2 cf2sf
chunhan
parents: 77
diff changeset
   396
        apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   397
        apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   398
        apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   399
        apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   400
        done
chunhan
parents: 77
diff changeset
   401
      have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   402
        using p1 p2 p2' vd cf2sf f_in' grant Open None f_in
chunhan
parents: 77
diff changeset
   403
        apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   404
        by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   405
      thus ?thesis using p1' p2' 
chunhan
parents: 77
diff changeset
   406
        apply (simp add:Open None split:option.splits) 
chunhan
parents: 77
diff changeset
   407
        using grant Open None p1 p2 
chunhan
parents: 77
diff changeset
   408
        by simp
chunhan
parents: 77
diff changeset
   409
    qed
chunhan
parents: 77
diff changeset
   410
    ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   411
      by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   412
  next
chunhan
parents: 77
diff changeset
   413
    case (Some inum)
chunhan
parents: 77
diff changeset
   414
    from os obtain pf where pf_in_s: "is_dir s pf" and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   415
      by (auto simp:Open Some)
chunhan
parents: 77
diff changeset
   416
    have pf_in: "is_dir s' pf" using pf_in_s alive
chunhan
parents: 77
diff changeset
   417
      apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   418
      by simp
chunhan
parents: 77
diff changeset
   419
    have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   420
      apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   421
      by (auto simp:Open Some)
chunhan
parents: 77
diff changeset
   422
    have f_not_in: "f \<notin> current_files s'" using os alive'
chunhan
parents: 77
diff changeset
   423
      apply (erule_tac x = "E_file f" in allE)
chunhan
parents: 77
diff changeset
   424
      by (auto simp:Open Some)
chunhan
parents: 77
diff changeset
   425
    have fd_not_in: "fd \<notin> current_proc_fds s' p"
chunhan
parents: 77
diff changeset
   426
      using os alive' p_in
chunhan
parents: 77
diff changeset
   427
      apply (erule_tac x = "E_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   428
      by (simp add:Open Some)
chunhan
parents: 77
diff changeset
   429
    have inum_not_in: "inum \<notin> current_inode_nums s'"
chunhan
parents: 77
diff changeset
   430
      using os alive' 
chunhan
parents: 77
diff changeset
   431
      apply (erule_tac x = "E_inum inum" in allE)
chunhan
parents: 77
diff changeset
   432
      by (simp add:Open Some)
chunhan
parents: 77
diff changeset
   433
    have "os_grant s' e" using p_in pf_in parent f_not_in fd_not_in inum_not_in os
chunhan
parents: 77
diff changeset
   434
      by (simp add:Open Some hungs)
chunhan
parents: 77
diff changeset
   435
    moreover have "grant s' e"  
chunhan
parents: 77
diff changeset
   436
    proof-
chunhan
parents: 77
diff changeset
   437
      from grant parent obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   438
        where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   439
        and p2: "sectxt_of_obj s (O_dir pf) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   440
        apply (simp add:Open Some split:option.splits)
chunhan
parents: 77
diff changeset
   441
        by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   442
      from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   443
        using os cp2sp
chunhan
parents: 77
diff changeset
   444
        apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   445
        by (auto simp:Open Some co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   446
      from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   447
        by (auto dest!:is_dir_in_current current_file_has_sfile simp:Open Some)
chunhan
parents: 77
diff changeset
   448
      hence p2': "sectxt_of_obj s' (O_dir pf) = Some (uf, rf, tf)" using p2 cf2sf pf_in pf_in_s
chunhan
parents: 77
diff changeset
   449
        apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   450
        apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   451
        apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   452
        apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   453
        apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   454
        by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   455
      have "search_check s' (up, rp, tp) pf"
chunhan
parents: 77
diff changeset
   456
        using p1 p2 p2' vd cf2sf pf_in grant Open Some pf_in_s parent vs'
chunhan
parents: 77
diff changeset
   457
        apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   458
        by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   459
      thus ?thesis using p1' p2' parent 
chunhan
parents: 77
diff changeset
   460
        apply (simp add:Open Some split:option.splits) 
chunhan
parents: 77
diff changeset
   461
        using grant Open Some p1 p2 
chunhan
parents: 77
diff changeset
   462
        by simp
chunhan
parents: 77
diff changeset
   463
    qed
chunhan
parents: 77
diff changeset
   464
    ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   465
      by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   466
  qed
chunhan
parents: 77
diff changeset
   467
next
chunhan
parents: 77
diff changeset
   468
  case (ReadFile p fd)
chunhan
parents: 77
diff changeset
   469
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   470
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   471
    by (auto simp:ReadFile)
chunhan
parents: 77
diff changeset
   472
  have fd_in: "fd \<in> current_proc_fds s' p" using os alive
chunhan
parents: 77
diff changeset
   473
    apply (erule_tac x = "O_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   474
    by (auto simp:ReadFile)
chunhan
parents: 77
diff changeset
   475
  obtain f where ffd: "file_of_proc_fd s p fd = Some f"
chunhan
parents: 77
diff changeset
   476
    using os ReadFile by auto
chunhan
parents: 77
diff changeset
   477
  hence f_in_s: "is_file s f" using vd
chunhan
parents: 77
diff changeset
   478
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   479
  obtain flags where fflag: "flags_of_proc_fd s p fd = Some flags"
chunhan
parents: 77
diff changeset
   480
    using os ReadFile by auto
chunhan
parents: 77
diff changeset
   481
  have ffd_in: "file_of_proc_fd s' p fd = Some f"
chunhan
parents: 77
diff changeset
   482
    using ffd_remain ffd by auto
chunhan
parents: 77
diff changeset
   483
  hence f_in: "is_file s' f" using vs'
chunhan
parents: 77
diff changeset
   484
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   485
  have flags_in: "flags_of_proc_fd s' p fd = Some flags"
chunhan
parents: 77
diff changeset
   486
    using fflags_remain fflag by auto
chunhan
parents: 77
diff changeset
   487
  have "os_grant s' e" using p_in fd_in ffd_in flags_in fflag os f_in 
chunhan
parents: 77
diff changeset
   488
    by (auto simp add:ReadFile is_file_in_current)
chunhan
parents: 77
diff changeset
   489
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   490
  proof-
chunhan
parents: 77
diff changeset
   491
    from grant ffd obtain up rp tp uf rf tf ufd rfd tfd
chunhan
parents: 77
diff changeset
   492
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   493
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)"
chunhan
parents: 77
diff changeset
   494
      and p3: "sectxt_of_obj s (O_fd p fd) = Some (ufd, rfd, tfd)"
chunhan
parents: 77
diff changeset
   495
      apply (simp add:ReadFile split:option.splits)
chunhan
parents: 77
diff changeset
   496
      by (case_tac a, case_tac aa, case_tac ab, blast)
chunhan
parents: 77
diff changeset
   497
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   498
      using os cp2sp
chunhan
parents: 77
diff changeset
   499
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   500
      by (auto simp:ReadFile co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   501
    from vd f_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   502
      by (auto dest!:is_file_in_current current_file_has_sfile)
chunhan
parents: 77
diff changeset
   503
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" using f_in f_in_s p2 cf2sf
chunhan
parents: 77
diff changeset
   504
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   505
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   506
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   507
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   508
      done
chunhan
parents: 77
diff changeset
   509
    have p3': "sectxt_of_obj s' (O_fd p fd) = Some (ufd, rfd, tfd)" 
chunhan
parents: 77
diff changeset
   510
      using cfd2sfd ffd_in ffd p3 f_in f_in_s vd
chunhan
parents: 77
diff changeset
   511
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   512
      apply (erule_tac x = fd in allE)
chunhan
parents: 77
diff changeset
   513
      apply (simp add:proc_file_fds_def)
chunhan
parents: 77
diff changeset
   514
      apply (auto simp:cfd2sfd_def fflag flags_in p3 split:option.splits
chunhan
parents: 77
diff changeset
   515
        dest!:current_file_has_sfile' simp:is_file_in_current)
chunhan
parents: 77
diff changeset
   516
      done
chunhan
parents: 77
diff changeset
   517
    show ?thesis using p1' p2' p3' ffd_in ffd
chunhan
parents: 77
diff changeset
   518
      apply (simp add:ReadFile split:option.splits) 
chunhan
parents: 77
diff changeset
   519
      using grant p1 p2 p3 ReadFile
chunhan
parents: 77
diff changeset
   520
      by simp
chunhan
parents: 77
diff changeset
   521
  qed
chunhan
parents: 77
diff changeset
   522
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   523
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   524
next
chunhan
parents: 77
diff changeset
   525
  case (WriteFile p fd)
chunhan
parents: 77
diff changeset
   526
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   527
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   528
    by (auto simp:WriteFile)
chunhan
parents: 77
diff changeset
   529
  have fd_in: "fd \<in> current_proc_fds s' p" using os alive
chunhan
parents: 77
diff changeset
   530
    apply (erule_tac x = "O_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   531
    by (auto simp:WriteFile)
chunhan
parents: 77
diff changeset
   532
  obtain f where ffd: "file_of_proc_fd s p fd = Some f"
chunhan
parents: 77
diff changeset
   533
    using os WriteFile by auto
chunhan
parents: 77
diff changeset
   534
  hence f_in_s: "is_file s f" using vd
chunhan
parents: 77
diff changeset
   535
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   536
  obtain flags where fflag: "flags_of_proc_fd s p fd = Some flags"
chunhan
parents: 77
diff changeset
   537
    using os WriteFile by auto
chunhan
parents: 77
diff changeset
   538
  have ffd_in: "file_of_proc_fd s' p fd = Some f"
chunhan
parents: 77
diff changeset
   539
    using ffd_remain ffd by auto
chunhan
parents: 77
diff changeset
   540
  hence f_in: "is_file s' f" using vs'
chunhan
parents: 77
diff changeset
   541
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   542
  have flags_in: "flags_of_proc_fd s' p fd = Some flags"
chunhan
parents: 77
diff changeset
   543
    using fflags_remain fflag by auto
chunhan
parents: 77
diff changeset
   544
  have "os_grant s' e" using p_in fd_in ffd_in flags_in fflag os f_in 
chunhan
parents: 77
diff changeset
   545
    by (auto simp add:WriteFile is_file_in_current)
chunhan
parents: 77
diff changeset
   546
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   547
  proof-
chunhan
parents: 77
diff changeset
   548
    from grant ffd obtain up rp tp uf rf tf ufd rfd tfd
chunhan
parents: 77
diff changeset
   549
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   550
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)"
chunhan
parents: 77
diff changeset
   551
      and p3: "sectxt_of_obj s (O_fd p fd) = Some (ufd, rfd, tfd)"
chunhan
parents: 77
diff changeset
   552
      apply (simp add:WriteFile split:option.splits)
chunhan
parents: 77
diff changeset
   553
      by (case_tac a, case_tac aa, case_tac ab, blast)
chunhan
parents: 77
diff changeset
   554
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   555
      using os cp2sp
chunhan
parents: 77
diff changeset
   556
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   557
      by (auto simp:WriteFile co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   558
    from vd f_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   559
      by (auto dest!:is_file_in_current current_file_has_sfile)
chunhan
parents: 77
diff changeset
   560
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" using f_in f_in_s p2 cf2sf
chunhan
parents: 77
diff changeset
   561
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   562
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   563
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   564
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   565
      done
chunhan
parents: 77
diff changeset
   566
    have p3': "sectxt_of_obj s' (O_fd p fd) = Some (ufd, rfd, tfd)" 
chunhan
parents: 77
diff changeset
   567
      using cfd2sfd ffd_in ffd p3 f_in f_in_s vd
chunhan
parents: 77
diff changeset
   568
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   569
      apply (erule_tac x = fd in allE)
chunhan
parents: 77
diff changeset
   570
      apply (simp add:proc_file_fds_def)
chunhan
parents: 77
diff changeset
   571
      apply (auto simp:cfd2sfd_def fflag flags_in p3 split:option.splits
chunhan
parents: 77
diff changeset
   572
        dest!:current_file_has_sfile' simp:is_file_in_current)
chunhan
parents: 77
diff changeset
   573
      done
chunhan
parents: 77
diff changeset
   574
    show ?thesis using p1' p2' p3' ffd_in ffd
chunhan
parents: 77
diff changeset
   575
      apply (simp add:WriteFile split:option.splits) 
chunhan
parents: 77
diff changeset
   576
      using grant p1 p2 p3 WriteFile
chunhan
parents: 77
diff changeset
   577
      by simp
chunhan
parents: 77
diff changeset
   578
  qed
chunhan
parents: 77
diff changeset
   579
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   580
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   581
next
chunhan
parents: 77
diff changeset
   582
  case (CloseFd p fd)
chunhan
parents: 77
diff changeset
   583
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   584
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   585
    by (auto simp:CloseFd)
chunhan
parents: 77
diff changeset
   586
  have fd_in: "fd \<in> current_proc_fds s' p" using os alive
chunhan
parents: 77
diff changeset
   587
    apply (erule_tac x = "O_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   588
    by (auto simp:CloseFd)
chunhan
parents: 77
diff changeset
   589
  have "os_grant s' e" using p_in fd_in 
chunhan
parents: 77
diff changeset
   590
    by (auto simp add:CloseFd)
chunhan
parents: 77
diff changeset
   591
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   592
    by(simp add:CloseFd)
chunhan
parents: 77
diff changeset
   593
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   594
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   595
next
chunhan
parents: 77
diff changeset
   596
  case (UnLink p f)
chunhan
parents: 77
diff changeset
   597
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   598
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   599
    by (auto simp:UnLink)
chunhan
parents: 77
diff changeset
   600
  have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   601
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   602
    by (auto simp:UnLink)
chunhan
parents: 77
diff changeset
   603
  from os vd obtain pf where pf_in_s: "is_dir s pf"
chunhan
parents: 77
diff changeset
   604
    and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   605
    by (auto simp:UnLink dest!:file_has_parent)
chunhan
parents: 77
diff changeset
   606
  from pf_in_s alive have pf_in: "is_dir s' pf"
chunhan
parents: 77
diff changeset
   607
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   608
    by (auto simp:UnLink)
chunhan
parents: 77
diff changeset
   609
  have "os_grant s' e" using p_in f_in os
chunhan
parents: 77
diff changeset
   610
    by (simp add:UnLink hungs)
chunhan
parents: 77
diff changeset
   611
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   612
  proof-    
chunhan
parents: 77
diff changeset
   613
    from grant parent obtain up rp tp uf rf tf upf rpf tpf
chunhan
parents: 77
diff changeset
   614
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   615
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   616
      and p3: "sectxt_of_obj s (O_dir pf) = Some (upf, rpf, tpf)" 
chunhan
parents: 77
diff changeset
   617
      apply (simp add:UnLink split:option.splits)
chunhan
parents: 77
diff changeset
   618
      by (case_tac a, case_tac aa, case_tac ab, blast) 
chunhan
parents: 77
diff changeset
   619
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   620
      using os cp2sp
chunhan
parents: 77
diff changeset
   621
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   622
      by (auto simp:UnLink co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   623
    from vd os pf_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   624
      by (auto dest!:is_file_in_current current_file_has_sfile simp:UnLink)
chunhan
parents: 77
diff changeset
   625
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   626
      using p2 cf2sf f_in os parent 
chunhan
parents: 77
diff changeset
   627
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   628
      apply (erule exE, clarsimp simp:UnLink)
chunhan
parents: 77
diff changeset
   629
      apply (frule_tac s = s in is_file_in_current, simp)
chunhan
parents: 77
diff changeset
   630
      by (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   631
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   632
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:UnLink)
chunhan
parents: 77
diff changeset
   633
    hence p3': "sectxt_of_obj s' (O_dir pf) = Some (upf, rpf, tpf)" using p3 cf2sf pf_in pf_in_s
chunhan
parents: 77
diff changeset
   634
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   635
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   636
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   637
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   638
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   639
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   640
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   641
      using p1 p2 p2' vd cf2sf f_in grant UnLink os parent vs'
chunhan
parents: 77
diff changeset
   642
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   643
      by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   644
    thus ?thesis using p1' p2' p3' parent 
chunhan
parents: 77
diff changeset
   645
      apply (simp add:UnLink split:option.splits) 
chunhan
parents: 77
diff changeset
   646
      using grant UnLink p1 p2 p3
chunhan
parents: 77
diff changeset
   647
      by simp
chunhan
parents: 77
diff changeset
   648
  qed
chunhan
parents: 77
diff changeset
   649
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   650
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   651
next
chunhan
parents: 77
diff changeset
   652
  case (Rmdir p f)
chunhan
parents: 77
diff changeset
   653
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   654
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   655
    by (auto simp:Rmdir)
chunhan
parents: 77
diff changeset
   656
  have f_in: "is_dir s' f" using os alive
chunhan
parents: 77
diff changeset
   657
    apply (erule_tac x = "O_dir f" in allE)
chunhan
parents: 77
diff changeset
   658
    by (auto simp:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   659
  have not_root: "f \<noteq> []" using os 
chunhan
parents: 77
diff changeset
   660
    by (auto simp:Rmdir)
chunhan
parents: 77
diff changeset
   661
  from os vd obtain pf where pf_in_s: "is_dir s pf"
chunhan
parents: 77
diff changeset
   662
    and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   663
    apply (auto simp:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   664
    apply (case_tac f, simp+)
chunhan
parents: 77
diff changeset
   665
    apply (drule parentf_is_dir_prop1, auto)
chunhan
parents: 77
diff changeset
   666
    done
chunhan
parents: 77
diff changeset
   667
  from pf_in_s alive have pf_in: "is_dir s' pf"
chunhan
parents: 77
diff changeset
   668
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   669
    by (auto simp:Rmdir)
chunhan
parents: 77
diff changeset
   670
  have empty_in: "dir_is_empty s' f" using os
chunhan
parents: 77
diff changeset
   671
    apply (simp add:dir_is_empty_def f_in)
chunhan
parents: 77
diff changeset
   672
    apply auto using alive'
chunhan
parents: 77
diff changeset
   673
    apply (erule_tac x = "E_file f'" in allE)
chunhan
parents: 77
diff changeset
   674
    by (simp add:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   675
  have "os_grant s' e" using p_in f_in os empty_in
chunhan
parents: 77
diff changeset
   676
    by (simp add:Rmdir hungs)
chunhan
parents: 77
diff changeset
   677
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   678
  proof-
chunhan
parents: 77
diff changeset
   679
    from grant parent obtain up rp tp uf rf tf upf rpf tpf
chunhan
parents: 77
diff changeset
   680
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   681
      and p2: "sectxt_of_obj s (O_dir f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   682
      and p3: "sectxt_of_obj s (O_dir pf) = Some (upf, rpf, tpf)" 
chunhan
parents: 77
diff changeset
   683
      apply (simp add:Rmdir split:option.splits)
chunhan
parents: 77
diff changeset
   684
      by (case_tac a, case_tac aa, case_tac ab, blast) 
chunhan
parents: 77
diff changeset
   685
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   686
      using os cp2sp
chunhan
parents: 77
diff changeset
   687
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   688
      by (auto simp:Rmdir co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   689
    from vd os pf_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   690
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:dir_is_empty_def Rmdir)
chunhan
parents: 77
diff changeset
   691
    hence p2': "sectxt_of_obj s' (O_dir f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   692
      using p2 cf2sf f_in os parent 
chunhan
parents: 77
diff changeset
   693
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   694
      apply (erule exE, clarsimp simp:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   695
      apply (frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   696
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   697
      by (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   698
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   699
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:Rmdir)
chunhan
parents: 77
diff changeset
   700
    hence p3': "sectxt_of_obj s' (O_dir pf) = Some (upf, rpf, tpf)" using p3 cf2sf pf_in pf_in_s
chunhan
parents: 77
diff changeset
   701
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   702
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   703
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   704
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   705
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   706
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   707
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   708
      using p1 p2 p2' vd cf2sf f_in grant Rmdir os parent vs'
chunhan
parents: 77
diff changeset
   709
      apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   710
      by (simp_all add:dir_is_empty_def split:option.splits)
chunhan
parents: 77
diff changeset
   711
    thus ?thesis using p1' p2' p3' parent 
chunhan
parents: 77
diff changeset
   712
      apply (simp add:Rmdir split:option.splits) 
chunhan
parents: 77
diff changeset
   713
      using grant Rmdir p1 p2 p3
chunhan
parents: 77
diff changeset
   714
      by simp
chunhan
parents: 77
diff changeset
   715
  qed
chunhan
parents: 77
diff changeset
   716
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   717
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   718
next
chunhan
parents: 77
diff changeset
   719
  case (Mkdir p f inum)
chunhan
parents: 77
diff changeset
   720
  from os obtain pf where pf_in_s: "is_dir s pf" and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   721
    by (auto simp:Mkdir)
chunhan
parents: 77
diff changeset
   722
  have pf_in: "is_dir s' pf" using pf_in_s alive
chunhan
parents: 77
diff changeset
   723
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   724
    by simp
chunhan
parents: 77
diff changeset
   725
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   726
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   727
    by (auto simp:Mkdir)
chunhan
parents: 77
diff changeset
   728
  have f_not_in: "f \<notin> current_files s'" using os alive'
chunhan
parents: 77
diff changeset
   729
    apply (erule_tac x = "E_file f" in allE)
chunhan
parents: 77
diff changeset
   730
    by (auto simp:Mkdir)
chunhan
parents: 77
diff changeset
   731
  have inum_not_in: "inum \<notin> current_inode_nums s'"
chunhan
parents: 77
diff changeset
   732
    using os alive' 
chunhan
parents: 77
diff changeset
   733
    apply (erule_tac x = "E_inum inum" in allE)
chunhan
parents: 77
diff changeset
   734
    by (simp add:Mkdir)
chunhan
parents: 77
diff changeset
   735
  have "os_grant s' e" using p_in pf_in parent f_not_in os inum_not_in
chunhan
parents: 77
diff changeset
   736
    by (simp add:Mkdir hungs)
chunhan
parents: 77
diff changeset
   737
  moreover have "grant s' e"  
chunhan
parents: 77
diff changeset
   738
  proof-
chunhan
parents: 77
diff changeset
   739
    from grant parent obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   740
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   741
      and p2: "sectxt_of_obj s (O_dir pf) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   742
      apply (simp add:Mkdir split:option.splits)
chunhan
parents: 77
diff changeset
   743
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   744
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   745
      using os cp2sp
chunhan
parents: 77
diff changeset
   746
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   747
      by (auto simp:Mkdir co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   748
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   749
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:Mkdir)
chunhan
parents: 77
diff changeset
   750
    hence p2': "sectxt_of_obj s' (O_dir pf) = Some (uf, rf, tf)" using p2 cf2sf pf_in pf_in_s
chunhan
parents: 77
diff changeset
   751
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   752
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   753
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   754
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   755
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   756
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   757
    have "search_check s' (up, rp, tp) pf"
chunhan
parents: 77
diff changeset
   758
      using p1 p2 p2' vd cf2sf pf_in grant Mkdir pf_in_s parent vs'
chunhan
parents: 77
diff changeset
   759
      apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   760
      apply (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   761
      done
chunhan
parents: 77
diff changeset
   762
    thus ?thesis using p1' p2' parent 
chunhan
parents: 77
diff changeset
   763
      apply (simp add:Mkdir split:option.splits) 
chunhan
parents: 77
diff changeset
   764
      using grant Mkdir p1 p2 
chunhan
parents: 77
diff changeset
   765
      apply simp 
chunhan
parents: 77
diff changeset
   766
      done
chunhan
parents: 77
diff changeset
   767
  qed
chunhan
parents: 77
diff changeset
   768
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   769
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   770
next
chunhan
parents: 77
diff changeset
   771
  case (LinkHard p f f')
chunhan
parents: 77
diff changeset
   772
  from os obtain pf where pf_in_s: "is_dir s pf" and parent: "parent f' = Some pf"
chunhan
parents: 77
diff changeset
   773
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   774
  have pf_in: "is_dir s' pf" using pf_in_s alive
chunhan
parents: 77
diff changeset
   775
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   776
    by simp
chunhan
parents: 77
diff changeset
   777
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   778
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   779
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   780
  have f'_not_in: "f' \<notin> current_files s'" using os alive'
chunhan
parents: 77
diff changeset
   781
    apply (erule_tac x = "E_file f'" in allE)
chunhan
parents: 77
diff changeset
   782
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   783
  have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   784
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   785
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   786
  have "os_grant s' e" using p_in pf_in parent os f_in f'_not_in
chunhan
parents: 77
diff changeset
   787
    by (simp add:LinkHard hungs)
chunhan
parents: 77
diff changeset
   788
  moreover have "grant s' e"
chunhan
parents: 77
diff changeset
   789
  proof-
chunhan
parents: 77
diff changeset
   790
    from grant parent obtain up rp tp uf rf tf upf rpf tpf
chunhan
parents: 77
diff changeset
   791
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   792
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   793
      and p3: "sectxt_of_obj s (O_dir pf) = Some (upf, rpf, tpf)" 
chunhan
parents: 77
diff changeset
   794
      apply (simp add:LinkHard split:option.splits)
chunhan
parents: 77
diff changeset
   795
      by (case_tac a, case_tac aa, case_tac ab, blast) 
chunhan
parents: 77
diff changeset
   796
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   797
      using os cp2sp
chunhan
parents: 77
diff changeset
   798
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   799
      by (auto simp:LinkHard co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   800
    from vd os pf_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   801
      by (auto dest!:is_file_in_current current_file_has_sfile simp:LinkHard)
chunhan
parents: 77
diff changeset
   802
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   803
      using p2 cf2sf f_in os parent 
chunhan
parents: 77
diff changeset
   804
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   805
      apply (erule exE, clarsimp simp:LinkHard)
chunhan
parents: 77
diff changeset
   806
      apply (frule_tac s = s in is_file_in_current, simp)
chunhan
parents: 77
diff changeset
   807
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   808
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   809
      by (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   810
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   811
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:LinkHard)
chunhan
parents: 77
diff changeset
   812
    hence p3': "sectxt_of_obj s' (O_dir pf) = Some (upf, rpf, tpf)" using p3 cf2sf pf_in pf_in_s
chunhan
parents: 77
diff changeset
   813
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   814
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   815
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   816
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   817
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   818
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   819
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   820
      using p1 p2 p2' vd cf2sf f_in grant LinkHard os parent vs'
chunhan
parents: 77
diff changeset
   821
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   822
      by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   823
    moreover have "search_check s' (up, rp, tp) pf"
chunhan
parents: 77
diff changeset
   824
      using p1 p3 p3' vd cf2sf pf_in grant LinkHard os parent vs'
chunhan
parents: 77
diff changeset
   825
      apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   826
      apply (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   827
      done
chunhan
parents: 77
diff changeset
   828
    ultimately show ?thesis using p1' p2' p3' parent 
chunhan
parents: 77
diff changeset
   829
      apply (simp add:LinkHard split:option.splits) 
chunhan
parents: 77
diff changeset
   830
      using grant LinkHard p1 p2 p3
chunhan
parents: 77
diff changeset
   831
      apply simp 
chunhan
parents: 77
diff changeset
   832
      done
chunhan
parents: 77
diff changeset
   833
  qed
chunhan
parents: 77
diff changeset
   834
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   835
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   836
next
chunhan
parents: 77
diff changeset
   837
  case (Truncate p f len)
chunhan
parents: 77
diff changeset
   838
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   839
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   840
    by (auto simp:Truncate)
chunhan
parents: 77
diff changeset
   841
  have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   842
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   843
    by (auto simp:Truncate)
chunhan
parents: 77
diff changeset
   844
  have "os_grant s' e" using p_in f_in by (simp add:Truncate)
chunhan
parents: 77
diff changeset
   845
  moreover have "grant s' e"
chunhan
parents: 77
diff changeset
   846
  proof-
chunhan
parents: 77
diff changeset
   847
    from grant obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   848
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   849
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   850
      apply (simp add:Truncate split:option.splits)
chunhan
parents: 77
diff changeset
   851
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   852
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   853
      using os cp2sp
chunhan
parents: 77
diff changeset
   854
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   855
      by (auto simp:Truncate co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   856
    from os have f_in': "is_file s f" by (simp add:Truncate)
chunhan
parents: 77
diff changeset
   857
    from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   858
      by (auto dest!:is_file_in_current current_file_has_sfile simp:Truncate)
chunhan
parents: 77
diff changeset
   859
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" using f_in f_in' p2 cf2sf
chunhan
parents: 77
diff changeset
   860
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   861
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   862
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   863
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   864
      done
chunhan
parents: 77
diff changeset
   865
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   866
      using p1 p2 p2' vd cf2sf f_in' grant Truncate f_in
chunhan
parents: 77
diff changeset
   867
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   868
      by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   869
    thus ?thesis using p1' p2' 
chunhan
parents: 77
diff changeset
   870
      apply (simp add:Truncate split:option.splits) 
chunhan
parents: 77
diff changeset
   871
      using grant Truncate p1 p2
chunhan
parents: 77
diff changeset
   872
      by (simp add:Truncate grant p1 p2)
chunhan
parents: 77
diff changeset
   873
  qed
chunhan
parents: 77
diff changeset
   874
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   875
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   876
next
chunhan
parents: 77
diff changeset
   877
  case (CreateMsgq p q)
chunhan
parents: 77
diff changeset
   878
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   879
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   880
    by (auto simp:CreateMsgq)
chunhan
parents: 77
diff changeset
   881
  have q_not_in: "q \<notin> current_msgqs s'" using os alive'
chunhan
parents: 77
diff changeset
   882
    apply (erule_tac x = "E_msgq q" in allE)
chunhan
parents: 77
diff changeset
   883
    by (simp add:CreateMsgq)
chunhan
parents: 77
diff changeset
   884
  have "os_grant s' e" using p_in q_not_in by (simp add:CreateMsgq)
chunhan
parents: 77
diff changeset
   885
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   886
  proof-
chunhan
parents: 77
diff changeset
   887
    from grant obtain up rp tp 
chunhan
parents: 77
diff changeset
   888
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   889
      apply (simp add:CreateMsgq split:option.splits)
chunhan
parents: 77
diff changeset
   890
      by (case_tac a, blast)
chunhan
parents: 77
diff changeset
   891
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   892
      using os cp2sp
chunhan
parents: 77
diff changeset
   893
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   894
      by (auto simp:CreateMsgq co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   895
    show ?thesis using p1' 
chunhan
parents: 77
diff changeset
   896
      apply (simp add:CreateMsgq split:option.splits) 
chunhan
parents: 77
diff changeset
   897
      using grant CreateMsgq p1
chunhan
parents: 77
diff changeset
   898
      by simp
chunhan
parents: 77
diff changeset
   899
  qed
chunhan
parents: 77
diff changeset
   900
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   901
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   902
next
chunhan
parents: 77
diff changeset
   903
  case (RemoveMsgq p q)
chunhan
parents: 77
diff changeset
   904
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   905
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   906
    by (auto simp:RemoveMsgq)
chunhan
parents: 77
diff changeset
   907
  have q_in: "q \<in> current_msgqs s'" using os alive
chunhan
parents: 77
diff changeset
   908
    apply (erule_tac x = "O_msgq q" in allE)
chunhan
parents: 77
diff changeset
   909
    by (simp add:RemoveMsgq)
chunhan
parents: 77
diff changeset
   910
  have "os_grant s' e" using p_in q_in by (simp add:RemoveMsgq)
chunhan
parents: 77
diff changeset
   911
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   912
  proof-
chunhan
parents: 77
diff changeset
   913
    from grant obtain up rp tp uq rq tq
chunhan
parents: 77
diff changeset
   914
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   915
      and p2: "sectxt_of_obj s (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   916
      apply (simp add:RemoveMsgq split:option.splits)
chunhan
parents: 77
diff changeset
   917
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   918
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   919
      using os cp2sp
chunhan
parents: 77
diff changeset
   920
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   921
      by (auto simp:RemoveMsgq co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   922
    from p2 have p2': "sectxt_of_obj s' (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   923
      using os cq2sq vd
chunhan
parents: 77
diff changeset
   924
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
   925
      by (auto simp:RemoveMsgq co2sobj.simps cq2smsgq_def dest!:current_has_sms' split:option.splits)
chunhan
parents: 77
diff changeset
   926
    show ?thesis using p1' p2' grant p1 p2
chunhan
parents: 77
diff changeset
   927
      by (simp add:RemoveMsgq)
chunhan
parents: 77
diff changeset
   928
  qed
chunhan
parents: 77
diff changeset
   929
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   930
    by (erule_tac valid.intros(2), simp+)  
chunhan
parents: 77
diff changeset
   931
next
chunhan
parents: 77
diff changeset
   932
  case (SendMsg p q m)
chunhan
parents: 77
diff changeset
   933
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   934
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   935
    by (auto simp:SendMsg)
chunhan
parents: 77
diff changeset
   936
  have q_in: "q \<in> current_msgqs s'" using os alive
chunhan
parents: 77
diff changeset
   937
    apply (erule_tac x = "O_msgq q" in allE)
chunhan
parents: 77
diff changeset
   938
    by (simp add:SendMsg)
chunhan
parents: 77
diff changeset
   939
  have m_not_in: "m \<notin> set (msgs_of_queue s' q)" using os alive'
chunhan
parents: 77
diff changeset
   940
    apply (erule_tac x = "E_msg q m" in allE)
chunhan
parents: 77
diff changeset
   941
    by (simp add:SendMsg q_in)
chunhan
parents: 77
diff changeset
   942
  have "os_grant s' e" using p_in q_in m_not_in
chunhan
parents: 77
diff changeset
   943
    by (simp add:SendMsg)
chunhan
parents: 77
diff changeset
   944
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   945
  proof-
chunhan
parents: 77
diff changeset
   946
    from grant obtain up rp tp uq rq tq
chunhan
parents: 77
diff changeset
   947
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   948
      and p2: "sectxt_of_obj s (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   949
      apply (simp add:SendMsg split:option.splits)
chunhan
parents: 77
diff changeset
   950
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   951
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   952
      using os cp2sp
chunhan
parents: 77
diff changeset
   953
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   954
      by (auto simp:SendMsg co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   955
    from p2 have p2': "sectxt_of_obj s' (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   956
      using os cq2sq vd
chunhan
parents: 77
diff changeset
   957
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
   958
      by (auto simp:SendMsg co2sobj.simps cq2smsgq_def dest!:current_has_sms' split:option.splits)
chunhan
parents: 77
diff changeset
   959
    show ?thesis using p1' p2' grant p1 p2
chunhan
parents: 77
diff changeset
   960
      by (simp add:SendMsg)
chunhan
parents: 77
diff changeset
   961
  qed
chunhan
parents: 77
diff changeset
   962
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   963
    by (erule_tac valid.intros(2), simp+)  
chunhan
parents: 77
diff changeset
   964
next
chunhan
parents: 77
diff changeset
   965
  case (RecvMsg p q m)
chunhan
parents: 77
diff changeset
   966
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   967
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   968
    by (auto simp:RecvMsg)
chunhan
parents: 77
diff changeset
   969
  have q_in: "q \<in> current_msgqs s'" using os alive
chunhan
parents: 77
diff changeset
   970
    apply (erule_tac x = "O_msgq q" in allE)
chunhan
parents: 77
diff changeset
   971
    by (simp add:RecvMsg) 
chunhan
parents: 77
diff changeset
   972
  have m_in: "m = hd (msgs_of_queue s' q)" 
chunhan
parents: 77
diff changeset
   973
    and sms_not_empty: "msgs_of_queue s' q \<noteq> []"
chunhan
parents: 77
diff changeset
   974
    using os sms_remain
chunhan
parents: 77
diff changeset
   975
    by (auto simp:RecvMsg)
chunhan
parents: 77
diff changeset
   976
  have "os_grant s' e" using p_in q_in m_in sms_not_empty os
chunhan
parents: 77
diff changeset
   977
    by (simp add:RecvMsg)
chunhan
parents: 77
diff changeset
   978
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   979
  proof-
chunhan
parents: 77
diff changeset
   980
    from grant obtain up rp tp uq rq tq um rm tm
chunhan
parents: 77
diff changeset
   981
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   982
      and p2: "sectxt_of_obj s (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   983
      and p3: "sectxt_of_obj s (O_msg q m) = Some (um, rm, tm)"
chunhan
parents: 77
diff changeset
   984
      apply (simp add:RecvMsg split:option.splits)
chunhan
parents: 77
diff changeset
   985
      by (case_tac a, case_tac aa, case_tac ab, blast)
chunhan
parents: 77
diff changeset
   986
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   987
      using os cp2sp
chunhan
parents: 77
diff changeset
   988
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   989
      by (auto simp:RecvMsg co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   990
    from p2 have p2': "sectxt_of_obj s' (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   991
      using os cq2sq vd
chunhan
parents: 77
diff changeset
   992
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
   993
      by (auto simp:RecvMsg co2sobj.simps cq2smsgq_def dest!:current_has_sms' split:option.splits)
chunhan
parents: 77
diff changeset
   994
    from p3 have p3': "sectxt_of_obj s' (O_msg q m) = Some (um, rm, tm)"
chunhan
parents: 77
diff changeset
   995
      using sms_remain cq2sq vd os p2 p2' p3 
chunhan
parents: 77
diff changeset
   996
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
   997
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
   998
      apply (clarsimp simp:RecvMsg)
chunhan
parents: 77
diff changeset
   999
      apply (simp add:cq2smsgq_def split:option.splits if_splits)
chunhan
parents: 77
diff changeset
  1000
      apply (drule current_has_sms', simp, simp)
chunhan
parents: 77
diff changeset
  1001
      apply (case_tac "msgs_of_queue s q", simp)
chunhan
parents: 77
diff changeset
  1002
      apply (simp add:cqm2sms.simps split:option.splits)
chunhan
parents: 77
diff changeset
  1003
      apply (auto simp add:cm2smsg_def split:option.splits if_splits)[1]
chunhan
parents: 77
diff changeset
  1004
      apply (case_tac "msgs_of_queue s q", simp)
chunhan
parents: 77
diff changeset
  1005
      apply (simp add:cqm2sms.simps split:option.splits)
chunhan
parents: 77
diff changeset
  1006
      apply (auto simp add:cm2smsg_def split:option.splits if_splits)[1]
chunhan
parents: 77
diff changeset
  1007
      done
chunhan
parents: 77
diff changeset
  1008
    show ?thesis using p1' p2' p3' grant p1 p2 p3
chunhan
parents: 77
diff changeset
  1009
      by (simp add:RecvMsg)
chunhan
parents: 77
diff changeset
  1010
  qed
chunhan
parents: 77
diff changeset
  1011
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
  1012
    by (erule_tac valid.intros(2), simp+)  
chunhan
parents: 77
diff changeset
  1013
next
chunhan
parents: 77
diff changeset
  1014
  case (CreateSock p af st fd inum)
chunhan
parents: 77
diff changeset
  1015
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1016
    by (simp add:CreateSock)
chunhan
parents: 77
diff changeset
  1017
next
chunhan
parents: 77
diff changeset
  1018
  case (Bind p fd addr)
chunhan
parents: 77
diff changeset
  1019
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1020
    by (simp add:Bind)
chunhan
parents: 77
diff changeset
  1021
next
chunhan
parents: 77
diff changeset
  1022
  case (Connect p fd addr)
chunhan
parents: 77
diff changeset
  1023
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1024
    by (simp add:Connect)
chunhan
parents: 77
diff changeset
  1025
next
chunhan
parents: 77
diff changeset
  1026
  case (Listen p fd)
chunhan
parents: 77
diff changeset
  1027
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1028
    by (simp add:Listen)
chunhan
parents: 77
diff changeset
  1029
next
chunhan
parents: 77
diff changeset
  1030
  case (Accept p fd addr port fd' inum)
chunhan
parents: 77
diff changeset
  1031
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1032
    by (simp add:Accept)
chunhan
parents: 77
diff changeset
  1033
next
chunhan
parents: 77
diff changeset
  1034
  case (SendSock p fd)
chunhan
parents: 77
diff changeset
  1035
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1036
    by (simp add:SendSock)
chunhan
parents: 77
diff changeset
  1037
next
chunhan
parents: 77
diff changeset
  1038
  case (RecvSock p fd)
chunhan
parents: 77
diff changeset
  1039
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1040
    by (simp add:RecvSock)
chunhan
parents: 77
diff changeset
  1041
next
chunhan
parents: 77
diff changeset
  1042
  case (Shutdown p fd how)
chunhan
parents: 77
diff changeset
  1043
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1044
    by (simp add:Shutdown)
chunhan
parents: 77
diff changeset
  1045
qed  
77
chunhan
parents:
diff changeset
  1046
  
78
chunhan
parents: 77
diff changeset
  1047
  
chunhan
parents: 77
diff changeset
  1048
  
chunhan
parents: 77
diff changeset
  1049
  
chunhan
parents: 77
diff changeset
  1050
  
chunhan
parents: 77
diff changeset
  1051
  
chunhan
parents: 77
diff changeset
  1052
  
chunhan
parents: 77
diff changeset
  1053
  
chunhan
parents: 77
diff changeset
  1054
    
77
chunhan
parents:
diff changeset
  1055
chunhan
parents:
diff changeset
  1056
chunhan
parents:
diff changeset
  1057
chunhan
parents:
diff changeset
  1058
chunhan
parents:
diff changeset
  1059
    
chunhan
parents:
diff changeset
  1060
chunhan
parents:
diff changeset
  1061
lemma enrich_proc_prop:
chunhan
parents:
diff changeset
  1062
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
  1063
   \<Longrightarrow> valid (enrich_proc s p p') \<and> 
chunhan
parents:
diff changeset
  1064
       (p \<in> current_procs s \<longrightarrow> co2sobj (enrich_proc s p p') (O_proc p') = co2sobj (enrich_proc s p p') (O_proc p)) \<and>
chunhan
parents:
diff changeset
  1065
       (\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p')  obj) \<and> 
chunhan
parents:
diff changeset
  1066
       (\<forall> p'. p' \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') p' = cp2sproc s p) \<and>
chunhan
parents:
diff changeset
  1067
       (\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') f = cf2sfile s f) \<and>
chunhan
parents:
diff changeset
  1068
       (Tainted (enrich_proc s p p') = (Tainted s \<union> (if (O_proc p \<in> Tainted s) then {O_proc p'} else {})))"
chunhan
parents:
diff changeset
  1069
proof (induct s)
chunhan
parents:
diff changeset
  1070
  case Nil
chunhan
parents:
diff changeset
  1071
  thus ?case by (auto simp:is_created_proc_def)
chunhan
parents:
diff changeset
  1072
next
chunhan
parents:
diff changeset
  1073
  case (Cons e s)
chunhan
parents:
diff changeset
  1074
  hence p1: "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
  1075
  \<Longrightarrow> valid (enrich_proc s p p') \<and>
chunhan
parents:
diff changeset
  1076
     (p \<in> current_procs s \<longrightarrow> co2sobj (enrich_proc s p p') (O_proc p') = co2sobj (enrich_proc s p p') (O_proc p)) \<and>
chunhan
parents:
diff changeset
  1077
     (alive s obj \<longrightarrow> alive (enrich_proc s p p') obj \<and> co2sobj (enrich_proc s p p') obj = co2sobj s obj)"
chunhan
parents:
diff changeset
  1078
    and p2: "valid (e # s)" and p3: "is_created_proc (e # s) p" and p4: "p' \<notin> all_procs (e # s)"
chunhan
parents:
diff changeset
  1079
    by auto
chunhan
parents:
diff changeset
  1080
  from p2 have vd: "valid s" and os: "os_grant s e" and grant: "grant s e"
chunhan
parents:
diff changeset
  1081
    by (auto dest:vd_cons vt_grant vt_grant_os)
chunhan
parents:
diff changeset
  1082
  from p4 have p4': "p' \<notin> all_procs s" by (case_tac e, auto)
chunhan
parents:
diff changeset
  1083
  from p1 p4' have a1: "is_created_proc s p \<Longrightarrow> valid (enrich_proc s p p')" by (auto simp:vd)
chunhan
parents:
diff changeset
  1084
  have c1: "valid (enrich_proc (e # s) p p')"
chunhan
parents:
diff changeset
  1085
    apply (case_tac e)
chunhan
parents:
diff changeset
  1086
    using a1 os p3
chunhan
parents:
diff changeset
  1087
    apply (auto simp:is_created_proc_def)
chunhan
parents:
diff changeset
  1088
    sorry
chunhan
parents:
diff changeset
  1089
  moreover have c2: "p' \<in> current_procs (enrich_proc (e # s) p p')"
chunhan
parents:
diff changeset
  1090
    sorry
chunhan
parents:
diff changeset
  1091
  moreover have c3: "co2sobj (enrich_proc (e # s) p p') (O_proc p') = co2sobj (enrich_proc (e # s) p p') (O_proc p)"
chunhan
parents:
diff changeset
  1092
    sorry
chunhan
parents:
diff changeset
  1093
  moreover have c4: "alive (e # s) obj \<longrightarrow>
chunhan
parents:
diff changeset
  1094
     alive (enrich_proc (e # s) p p') obj \<and> co2sobj (enrich_proc (e # s) p p') obj = co2sobj (e # s) obj"
chunhan
parents:
diff changeset
  1095
    sorry
chunhan
parents:
diff changeset
  1096
  ultimately show ?case by auto
chunhan
parents:
diff changeset
  1097
qed
chunhan
parents:
diff changeset
  1098