no_shm_selinux/Enrich.thy
author chunhan
Fri, 20 Dec 2013 10:58:00 +0800
changeset 80 c9cfc416fa2d
parent 79 c09fcbcdb871
child 81 1ac0c3031ed2
permissions -rw-r--r--
fixed bug in enrich_proc
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 = (
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
    33
     if (tp = p \<and> fd \<in> proc_file_fds s p)
77
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 = (
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
    47
     if (tp = p') then Kill p p' # s
77
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
lemma enrich_search_check:
chunhan
parents:
diff changeset
    55
  assumes grant: "search_check s (up, rp, tp) f"
chunhan
parents:
diff changeset
    56
  and cf2sf: "\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile s' f = cf2sfile s f"
chunhan
parents:
diff changeset
    57
  and vd: "valid s" and f_in: "is_file s f"  and f_in': "is_file s' f"
chunhan
parents:
diff changeset
    58
  and sec: "sectxt_of_obj s' (O_file f) = sectxt_of_obj s (O_file f)"
chunhan
parents:
diff changeset
    59
  shows "search_check s' (up, rp, tp) f"
chunhan
parents:
diff changeset
    60
proof (cases f)
chunhan
parents:
diff changeset
    61
  case Nil
chunhan
parents:
diff changeset
    62
  with f_in vd have "False" 
chunhan
parents:
diff changeset
    63
    by (auto dest:root_is_dir') 
chunhan
parents:
diff changeset
    64
  thus ?thesis by simp
chunhan
parents:
diff changeset
    65
next
chunhan
parents:
diff changeset
    66
  case (Cons n pf)
chunhan
parents:
diff changeset
    67
  from vd f_in obtain sf where sf: "cf2sfile s f = Some sf"
chunhan
parents:
diff changeset
    68
    apply (drule_tac is_file_in_current, drule_tac current_file_has_sfile, simp)
chunhan
parents:
diff changeset
    69
    apply (erule exE, simp)
chunhan
parents:
diff changeset
    70
    done
chunhan
parents:
diff changeset
    71
  then obtain psfs where psfs: "get_parentfs_ctxts s pf = Some psfs" using Cons
chunhan
parents:
diff changeset
    72
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents:
diff changeset
    73
  from sf cf2sf f_in have sf': "cf2sfile s' f = Some sf" by (auto dest:is_file_in_current)
chunhan
parents:
diff changeset
    74
  then obtain psfs' where psfs': "get_parentfs_ctxts s' pf = Some psfs'"using Cons
chunhan
parents:
diff changeset
    75
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents:
diff changeset
    76
  with sf sf' psfs have psfs_eq: "set psfs' = set psfs" using Cons f_in f_in'
chunhan
parents:
diff changeset
    77
    apply (simp add:cf2sfile_def split:option.splits)
chunhan
parents:
diff changeset
    78
    apply (case_tac sf, simp)
chunhan
parents:
diff changeset
    79
    done
chunhan
parents:
diff changeset
    80
  show ?thesis using grant f_in f_in' psfs psfs' psfs_eq sec
chunhan
parents:
diff changeset
    81
    apply (simp add:Cons split:option.splits)
chunhan
parents:
diff changeset
    82
    by (case_tac a, simp)
chunhan
parents:
diff changeset
    83
qed
chunhan
parents:
diff changeset
    84
78
chunhan
parents: 77
diff changeset
    85
lemma enrich_search_check':
chunhan
parents: 77
diff changeset
    86
  assumes grant: "search_check s (up, rp, tp) f"
chunhan
parents: 77
diff changeset
    87
  and cf2sf: "\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile s' f = cf2sfile s f"
chunhan
parents: 77
diff changeset
    88
  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
    89
  and sec: "sectxt_of_obj s' (O_dir f) = sectxt_of_obj s (O_dir f)"
chunhan
parents: 77
diff changeset
    90
  shows "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
    91
proof (cases f)
chunhan
parents: 77
diff changeset
    92
  case Nil
chunhan
parents: 77
diff changeset
    93
  have "sectxt_of_obj s' (O_dir []) = sectxt_of_obj s (O_dir [])"
chunhan
parents: 77
diff changeset
    94
    using cf2sf 
chunhan
parents: 77
diff changeset
    95
    apply (erule_tac x = "[]" in allE)
chunhan
parents: 77
diff changeset
    96
    by (auto simp:cf2sfile_def root_sec_remains vd vd')
chunhan
parents: 77
diff changeset
    97
  thus ?thesis using grant Nil 
chunhan
parents: 77
diff changeset
    98
    by auto
chunhan
parents: 77
diff changeset
    99
next
chunhan
parents: 77
diff changeset
   100
  case (Cons n pf)
chunhan
parents: 77
diff changeset
   101
  from vd f_in obtain sf where sf: "cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   102
    apply (drule_tac is_dir_in_current, drule_tac current_file_has_sfile, simp)
chunhan
parents: 77
diff changeset
   103
    apply (erule exE, simp)
chunhan
parents: 77
diff changeset
   104
    done
chunhan
parents: 77
diff changeset
   105
  then obtain psfs where psfs: "get_parentfs_ctxts s pf = Some psfs" using Cons
chunhan
parents: 77
diff changeset
   106
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents: 77
diff changeset
   107
  from sf cf2sf f_in have sf': "cf2sfile s' f = Some sf" by (auto dest:is_dir_in_current)
chunhan
parents: 77
diff changeset
   108
  then obtain psfs' where psfs': "get_parentfs_ctxts s' pf = Some psfs'"using Cons
chunhan
parents: 77
diff changeset
   109
    by (auto simp:cf2sfile_def split:option.splits if_splits)
chunhan
parents: 77
diff changeset
   110
  with sf sf' psfs have psfs_eq: "set psfs' = set psfs" using Cons f_in f_in'
chunhan
parents: 77
diff changeset
   111
    apply (drule_tac is_dir_not_file)
chunhan
parents: 77
diff changeset
   112
    apply (drule is_dir_not_file)    
chunhan
parents: 77
diff changeset
   113
    apply (simp add:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   114
    apply (case_tac sf, simp)
chunhan
parents: 77
diff changeset
   115
    done
chunhan
parents: 77
diff changeset
   116
  show ?thesis using grant f_in f_in' psfs psfs' psfs_eq sec
chunhan
parents: 77
diff changeset
   117
    apply (drule_tac is_dir_not_file)
chunhan
parents: 77
diff changeset
   118
    apply (drule_tac is_dir_not_file)
chunhan
parents: 77
diff changeset
   119
    apply (simp add:Cons split:option.splits)
chunhan
parents: 77
diff changeset
   120
    by (case_tac a, simp)
chunhan
parents: 77
diff changeset
   121
qed
chunhan
parents: 77
diff changeset
   122
77
chunhan
parents:
diff changeset
   123
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
   124
apply (simp add:proc_file_fds_def)
chunhan
parents:
diff changeset
   125
apply (auto dest: current_filefd_has_sfd)
chunhan
parents:
diff changeset
   126
done
chunhan
parents:
diff changeset
   127
chunhan
parents:
diff changeset
   128
lemma enrich_inherit_fds_check:
chunhan
parents:
diff changeset
   129
  assumes grant: "inherit_fds_check s (up, nr, nt) p fds"  and vd: "valid s"
chunhan
parents:
diff changeset
   130
  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
   131
  and fd_in: "fds \<subseteq> proc_file_fds s p" and fd_in': "fds \<subseteq> proc_file_fds s' p"
chunhan
parents:
diff changeset
   132
  shows "inherit_fds_check s' (up, nr, nt) p fds"
chunhan
parents:
diff changeset
   133
proof-
chunhan
parents:
diff changeset
   134
  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
   135
  proof-
chunhan
parents:
diff changeset
   136
    fix fd
chunhan
parents:
diff changeset
   137
    assume fd_in_fds: "fd \<in> fds"
chunhan
parents:
diff changeset
   138
    hence fd_in_cfds: "fd \<in> proc_file_fds s p" 
chunhan
parents:
diff changeset
   139
      and fd_in_cfds': "fd \<in> proc_file_fds s' p" 
chunhan
parents:
diff changeset
   140
      using fd_in fd_in' by auto
chunhan
parents:
diff changeset
   141
    with cfd2sfd
chunhan
parents:
diff changeset
   142
    have cfd_eq: "cfd2sfd s' p fd = cfd2sfd s p fd" by auto
chunhan
parents:
diff changeset
   143
    from fd_in_cfds obtain f where ffd: "file_of_proc_fd s p fd = Some f"
chunhan
parents:
diff changeset
   144
      by (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   145
    moreover have "flags_of_proc_fd s p fd \<noteq> None"
chunhan
parents:
diff changeset
   146
      using ffd vd by (auto dest:current_filefd_has_flags)
chunhan
parents:
diff changeset
   147
    moreover have "sectxt_of_obj s (O_fd p fd) \<noteq> None"
chunhan
parents:
diff changeset
   148
      using fd_in_cfds vd
chunhan
parents:
diff changeset
   149
      apply (rule_tac notI)
chunhan
parents:
diff changeset
   150
      by (auto dest!:current_has_sec' file_fds_subset_pfds[where p = p] intro:vd)
chunhan
parents:
diff changeset
   151
    moreover have "cf2sfile s f \<noteq> None"
chunhan
parents:
diff changeset
   152
      apply (rule notI)
chunhan
parents:
diff changeset
   153
      apply (drule current_file_has_sfile')
chunhan
parents:
diff changeset
   154
      using ffd
chunhan
parents:
diff changeset
   155
      by (auto simp:vd is_file_in_current dest:file_of_pfd_is_file)
chunhan
parents:
diff changeset
   156
    ultimately show "sectxt_of_obj s' (O_fd p fd) = sectxt_of_obj s (O_fd p fd)"
chunhan
parents:
diff changeset
   157
      using cfd_eq
chunhan
parents:
diff changeset
   158
      by (auto simp:cfd2sfd_def split:option.splits)
chunhan
parents:
diff changeset
   159
  qed
chunhan
parents:
diff changeset
   160
  hence "sectxts_of_fds s' p fds = sectxts_of_fds s p fds"
chunhan
parents:
diff changeset
   161
    by (simp add:sectxts_of_fds_def)
chunhan
parents:
diff changeset
   162
  thus ?thesis using grant
chunhan
parents:
diff changeset
   163
    by (simp add:inherit_fds_check_def)
chunhan
parents:
diff changeset
   164
qed
chunhan
parents:
diff changeset
   165
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   166
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   167
lemma enrich_inherit_fds_check_dup:
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   168
  assumes grant: "inherit_fds_check s (up, nr, nt) p fds"  and vd: "valid s"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   169
  and cfd2sfd: "\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd s' p' fd = cfd2sfd s p fd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   170
  and fd_in: "fds' \<subseteq> fds \<inter> proc_file_fds s p" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   171
  shows "inherit_fds_check s' (up, nr, nt) p' fds'"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   172
proof- 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   173
  have "sectxts_of_fds s' p' fds' \<subseteq> sectxts_of_fds s p fds"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   174
  proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   175
    have "\<And> fd sfd. \<lbrakk>fd \<in> fds'; sectxt_of_obj s' (O_fd p' fd) = Some sfd\<rbrakk> 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   176
                     \<Longrightarrow> \<exists> fd \<in> fds. sectxt_of_obj s (O_fd p fd) = Some sfd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   177
    proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   178
      fix fd sfd
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   179
      assume fd_in_fds': "fd \<in> fds'"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   180
        and sec: "sectxt_of_obj s' (O_fd p' fd) = Some sfd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   181
      from fd_in_fds' fd_in
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   182
      have fd_in_fds: "fd \<in> fds" and fd_in_cfds: "fd \<in> proc_file_fds s p" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   183
        by auto
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   184
      from fd_in_cfds obtain f where ffd: "file_of_proc_fd s p fd = Some f"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   185
        by (auto simp:proc_file_fds_def)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   186
      moreover have "flags_of_proc_fd s p fd \<noteq> None"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   187
        using ffd vd by (auto dest:current_filefd_has_flags)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   188
      moreover have "cf2sfile s f \<noteq> None"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   189
        apply (rule notI)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   190
        apply (drule current_file_has_sfile')
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   191
        using ffd
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   192
        by (auto simp:vd is_file_in_current dest:file_of_pfd_is_file)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   193
      moreover have "sectxt_of_obj s (O_fd p fd) \<noteq> None"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   194
        using fd_in_cfds vd
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   195
        apply (rule_tac notI)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   196
        by (auto dest!:current_has_sec' file_fds_subset_pfds[where p = p] intro:vd)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   197
      ultimately 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   198
      have "sectxt_of_obj s (O_fd p fd) = Some sfd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   199
        using fd_in_cfds cfd2sfd sec
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   200
        apply (erule_tac x = fd in allE)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   201
        apply (auto simp:cfd2sfd_def split:option.splits)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   202
        done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   203
      thus "\<exists> fd \<in> fds. sectxt_of_obj s (O_fd p fd) = Some sfd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   204
        using fd_in_fds
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   205
        by (rule_tac x = fd in bexI, auto)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   206
    qed
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   207
    thus ?thesis by (auto simp:sectxts_of_fds_def)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   208
  qed
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   209
  thus ?thesis using grant
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   210
    by (auto simp:inherit_fds_check_def inherit_fds_check_ctxt_def)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   211
qed
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
   212
77
chunhan
parents:
diff changeset
   213
lemma not_all_procs_cons:
chunhan
parents:
diff changeset
   214
  "p \<notin> all_procs (e # s) \<Longrightarrow> p \<notin> all_procs s"
chunhan
parents:
diff changeset
   215
by (case_tac e, auto)
chunhan
parents:
diff changeset
   216
chunhan
parents:
diff changeset
   217
lemma not_all_procs_prop:
chunhan
parents:
diff changeset
   218
  "\<lbrakk>p' \<notin> all_procs s; p \<in> current_procs s; valid s\<rbrakk> \<Longrightarrow> p' \<noteq> p"
chunhan
parents:
diff changeset
   219
apply (induct s, rule notI, simp)
chunhan
parents:
diff changeset
   220
apply (frule vt_grant_os, frule vd_cons, frule not_all_procs_cons, simp, rule notI)
chunhan
parents:
diff changeset
   221
apply (case_tac a, auto)
chunhan
parents:
diff changeset
   222
done
chunhan
parents:
diff changeset
   223
78
chunhan
parents: 77
diff changeset
   224
fun enrich_not_alive :: "t_state \<Rightarrow> t_enrich_obj \<Rightarrow> bool"
77
chunhan
parents:
diff changeset
   225
where
78
chunhan
parents: 77
diff changeset
   226
  "enrich_not_alive s (E_file f) = (f \<notin> current_files s)"
chunhan
parents: 77
diff changeset
   227
| "enrich_not_alive s (E_proc p) = (p \<notin> current_procs s)"
chunhan
parents: 77
diff changeset
   228
| "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
   229
| "enrich_not_alive s (E_msgq q) = (q \<notin> current_msgqs s)"
chunhan
parents: 77
diff changeset
   230
| "enrich_not_alive s (E_inum i) = (i \<notin> current_inode_nums s)"
chunhan
parents: 77
diff changeset
   231
| "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
   232
chunhan
parents: 77
diff changeset
   233
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
   234
apply (case_tac f)
chunhan
parents: 77
diff changeset
   235
apply (simp, drule root_is_dir', simp+)
chunhan
parents: 77
diff changeset
   236
apply (simp add:parentf_is_dir_prop2)
chunhan
parents: 77
diff changeset
   237
done
77
chunhan
parents:
diff changeset
   238
chunhan
parents:
diff changeset
   239
lemma enrich_valid_intro_cons:
chunhan
parents:
diff changeset
   240
  assumes vs': "valid s'"
chunhan
parents:
diff changeset
   241
    and os: "os_grant s e" and grant: "grant s e" and vd: "valid s"
chunhan
parents:
diff changeset
   242
    and alive: "\<forall> obj. alive s obj \<longrightarrow> alive s' obj"
chunhan
parents:
diff changeset
   243
    and alive': "\<forall> obj. enrich_not_alive s obj \<longrightarrow> enrich_not_alive s' obj"
78
chunhan
parents: 77
diff changeset
   244
    and hungs: "files_hung_by_del s' = files_hung_by_del s"
77
chunhan
parents:
diff changeset
   245
    and cp2sp: "\<forall> p. p \<in> current_procs s \<longrightarrow> cp2sproc s' p = cp2sproc s p"
chunhan
parents:
diff changeset
   246
    and cf2sf: "\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile s' f = cf2sfile s f"
78
chunhan
parents: 77
diff changeset
   247
    and cq2sq: "\<forall> q. q \<in> current_msgqs s \<longrightarrow> cq2smsgq s' q = cq2smsgq s q"
77
chunhan
parents:
diff changeset
   248
    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
   249
    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
   250
    and sms_remain: "\<forall> q. msgs_of_queue s' q = msgs_of_queue s q"
chunhan
parents: 77
diff changeset
   251
   (* and empty_remain: "\<forall> f. dir_is_empty s f \<longrightarrow> dir_is_empty s' f" *)
77
chunhan
parents:
diff changeset
   252
    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
   253
  shows "valid (e # s')"
chunhan
parents:
diff changeset
   254
proof (cases e)
chunhan
parents:
diff changeset
   255
  case (Execve p f fds)
chunhan
parents:
diff changeset
   256
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents:
diff changeset
   257
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents:
diff changeset
   258
    by (auto simp:Execve)
chunhan
parents:
diff changeset
   259
  have f_in: "is_file s' f" using os alive
chunhan
parents:
diff changeset
   260
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents:
diff changeset
   261
    by (auto simp:Execve)
chunhan
parents:
diff changeset
   262
  have fd_in: "fds \<subseteq> proc_file_fds s' p" using os alive ffd_remain
chunhan
parents:
diff changeset
   263
    by (auto simp:Execve proc_file_fds_def)
chunhan
parents:
diff changeset
   264
  have "os_grant s' e" using p_in f_in fd_in by (simp add:Execve)
chunhan
parents:
diff changeset
   265
  moreover have "grant s' e"
chunhan
parents:
diff changeset
   266
  proof-
chunhan
parents:
diff changeset
   267
    from grant obtain up rp tp uf rf tf 
chunhan
parents:
diff changeset
   268
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   269
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents:
diff changeset
   270
      by (simp add:Execve split:option.splits, blast)
chunhan
parents:
diff changeset
   271
    with grant obtain pu nr nt where p3: "npctxt_execve (up, rp, tp) (uf, rf, tf) = Some (pu, nr, nt)"
chunhan
parents:
diff changeset
   272
      by (simp add:Execve split:option.splits del:npctxt_execve.simps, blast)
chunhan
parents:
diff changeset
   273
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   274
      using os cp2sp
chunhan
parents:
diff changeset
   275
      apply (erule_tac x = p in allE)
chunhan
parents:
diff changeset
   276
      by (auto simp:Execve co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   277
    from os have f_in': "is_file s f" by (simp add:Execve)
chunhan
parents:
diff changeset
   278
    from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents:
diff changeset
   279
      by (auto dest!:is_file_in_current current_file_has_sfile simp:Execve)
chunhan
parents:
diff changeset
   280
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" using f_in f_in' p2 cf2sf
chunhan
parents:
diff changeset
   281
      apply (erule_tac x = f in allE)
chunhan
parents:
diff changeset
   282
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents:
diff changeset
   283
      apply (case_tac f, simp)
chunhan
parents:
diff changeset
   284
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents:
diff changeset
   285
      done
chunhan
parents:
diff changeset
   286
    have "inherit_fds_check s' (pu, nr, nt) p fds"
chunhan
parents:
diff changeset
   287
    proof-
chunhan
parents:
diff changeset
   288
      have "fds \<subseteq> proc_file_fds s' p" using os ffd_remain Execve
chunhan
parents:
diff changeset
   289
        by (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   290
      thus ?thesis using Execve grant vd cfd2sfd p1 p2 p3 os
chunhan
parents:
diff changeset
   291
        apply (rule_tac s = s in enrich_inherit_fds_check)
chunhan
parents:
diff changeset
   292
        by (simp_all split:option.splits)
chunhan
parents:
diff changeset
   293
    qed
chunhan
parents:
diff changeset
   294
    moreover have "search_check s' (pu, rp, tp) f"
chunhan
parents:
diff changeset
   295
      using p1 p2 p2' vd cf2sf f_in' grant Execve p3 f_in
chunhan
parents:
diff changeset
   296
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents:
diff changeset
   297
      by (simp_all split:option.splits)
chunhan
parents:
diff changeset
   298
    ultimately show ?thesis using p1' p2' p3
chunhan
parents:
diff changeset
   299
      apply (simp add:Execve split:option.splits) 
chunhan
parents:
diff changeset
   300
      using grant Execve p1 p2
chunhan
parents:
diff changeset
   301
      by (simp add:Execve grant p1 p2)
chunhan
parents:
diff changeset
   302
  qed
chunhan
parents:
diff changeset
   303
  ultimately show ?thesis using vs'
chunhan
parents:
diff changeset
   304
    by (erule_tac valid.intros(2), simp+)
chunhan
parents:
diff changeset
   305
next
chunhan
parents:
diff changeset
   306
  case (Clone p p' fds)
chunhan
parents:
diff changeset
   307
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents:
diff changeset
   308
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents:
diff changeset
   309
    by (auto simp:Clone)
chunhan
parents:
diff changeset
   310
  have p'_not_in: "p' \<notin> current_procs s'" using os alive'
78
chunhan
parents: 77
diff changeset
   311
    apply (erule_tac x = "E_proc p'" in allE)
77
chunhan
parents:
diff changeset
   312
    by (auto simp:Clone)
chunhan
parents:
diff changeset
   313
  have fd_in: "fds \<subseteq> proc_file_fds s' p" using os alive ffd_remain
chunhan
parents:
diff changeset
   314
    by (auto simp:Clone proc_file_fds_def)
chunhan
parents:
diff changeset
   315
  have "os_grant s' e" using p_in p'_not_in fd_in by (simp add:Clone)
chunhan
parents:
diff changeset
   316
  moreover have "grant s' e" 
chunhan
parents:
diff changeset
   317
  proof-
chunhan
parents:
diff changeset
   318
    from grant obtain up rp tp 
chunhan
parents:
diff changeset
   319
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   320
      apply (simp add:Clone split:option.splits)
chunhan
parents:
diff changeset
   321
      by (case_tac a, auto)
chunhan
parents:
diff changeset
   322
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents:
diff changeset
   323
      using os cp2sp
chunhan
parents:
diff changeset
   324
      apply (erule_tac x = p in allE)
chunhan
parents:
diff changeset
   325
      by (auto simp:Clone co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents:
diff changeset
   326
    have p2: "inherit_fds_check s' (up, rp, tp) p fds"
chunhan
parents:
diff changeset
   327
    proof-
chunhan
parents:
diff changeset
   328
      have "fds \<subseteq> proc_file_fds s' p" using os ffd_remain Clone
chunhan
parents:
diff changeset
   329
        by (auto simp:proc_file_fds_def)
chunhan
parents:
diff changeset
   330
      thus ?thesis using Clone grant vd cfd2sfd p1 os
chunhan
parents:
diff changeset
   331
        apply (rule_tac s = s in enrich_inherit_fds_check)
chunhan
parents:
diff changeset
   332
        by (simp_all split:option.splits)
chunhan
parents:
diff changeset
   333
    qed
chunhan
parents:
diff changeset
   334
    show ?thesis using p1 p2 p1' grant
chunhan
parents:
diff changeset
   335
      by (simp add:Clone)
chunhan
parents:
diff changeset
   336
  qed
chunhan
parents:
diff changeset
   337
  ultimately show ?thesis using vs'
chunhan
parents:
diff changeset
   338
    by (erule_tac valid.intros(2), simp+)
chunhan
parents:
diff changeset
   339
next
78
chunhan
parents: 77
diff changeset
   340
  case (Kill p p')
chunhan
parents: 77
diff changeset
   341
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   342
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   343
    by (auto simp:Kill)
chunhan
parents: 77
diff changeset
   344
  have p'_in: "p' \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   345
    apply (erule_tac x = "O_proc p'" in allE)
chunhan
parents: 77
diff changeset
   346
    by (auto simp:Kill)
chunhan
parents: 77
diff changeset
   347
  have "os_grant s' e" using p_in p'_in by (simp add:Kill)
chunhan
parents: 77
diff changeset
   348
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   349
  proof-
chunhan
parents: 77
diff changeset
   350
    from grant obtain up rp tp up' rp' tp'
chunhan
parents: 77
diff changeset
   351
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   352
      and p'1: "sectxt_of_obj s (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   353
      apply (simp add:Kill split:option.splits)
chunhan
parents: 77
diff changeset
   354
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   355
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   356
      using os cp2sp
chunhan
parents: 77
diff changeset
   357
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   358
      by (auto simp:Kill co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   359
    from p'1 have p'1': "sectxt_of_obj s' (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   360
      using os cp2sp
chunhan
parents: 77
diff changeset
   361
      apply (erule_tac x = p' in allE)
chunhan
parents: 77
diff changeset
   362
      by (auto simp:Kill co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   363
    show ?thesis using p1 p'1 p1' p'1' grant
chunhan
parents: 77
diff changeset
   364
      by (simp add:Kill)
chunhan
parents: 77
diff changeset
   365
  qed
chunhan
parents: 77
diff changeset
   366
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   367
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   368
next
chunhan
parents: 77
diff changeset
   369
  case (Ptrace p p')
chunhan
parents: 77
diff changeset
   370
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   371
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   372
    by (auto simp:Ptrace)
chunhan
parents: 77
diff changeset
   373
  have p'_in: "p' \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   374
    apply (erule_tac x = "O_proc p'" in allE)
chunhan
parents: 77
diff changeset
   375
    by (auto simp:Ptrace)
chunhan
parents: 77
diff changeset
   376
  have "os_grant s' e" using p_in p'_in by (simp add:Ptrace)
chunhan
parents: 77
diff changeset
   377
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   378
  proof-
chunhan
parents: 77
diff changeset
   379
    from grant obtain up rp tp up' rp' tp'
chunhan
parents: 77
diff changeset
   380
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   381
      and p'1: "sectxt_of_obj s (O_proc p') = Some (up', rp', tp')"
chunhan
parents: 77
diff changeset
   382
      apply (simp add:Ptrace split:option.splits)
chunhan
parents: 77
diff changeset
   383
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   384
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   385
      using os cp2sp
chunhan
parents: 77
diff changeset
   386
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   387
      by (auto simp:Ptrace co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   388
    from p'1 have p'1': "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:Ptrace co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   392
    show ?thesis using p1 p'1 p1' p'1' grant
chunhan
parents: 77
diff changeset
   393
      by (simp add:Ptrace)
chunhan
parents: 77
diff changeset
   394
  qed
chunhan
parents: 77
diff changeset
   395
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   396
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   397
next
chunhan
parents: 77
diff changeset
   398
  case (Exit p)
chunhan
parents: 77
diff changeset
   399
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   400
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   401
    by (auto simp:Exit)
chunhan
parents: 77
diff changeset
   402
  have "os_grant s' e" using p_in by (simp add:Exit)
chunhan
parents: 77
diff changeset
   403
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   404
    by (simp add:Exit)
chunhan
parents: 77
diff changeset
   405
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   406
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   407
next
chunhan
parents: 77
diff changeset
   408
  case (Open p f flags fd opt)
chunhan
parents: 77
diff changeset
   409
  show ?thesis
chunhan
parents: 77
diff changeset
   410
  proof (cases opt)
chunhan
parents: 77
diff changeset
   411
    case None
chunhan
parents: 77
diff changeset
   412
    have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   413
      apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   414
      by (auto simp:Open None)
chunhan
parents: 77
diff changeset
   415
    have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   416
      apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   417
      by (auto simp:Open None)
chunhan
parents: 77
diff changeset
   418
    have fd_not_in: "fd \<notin> current_proc_fds s' p"
chunhan
parents: 77
diff changeset
   419
      using os alive' p_in
chunhan
parents: 77
diff changeset
   420
      apply (erule_tac x = "E_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   421
      by (simp add:Open None)
chunhan
parents: 77
diff changeset
   422
    have "os_grant s' e" using p_in f_in fd_not_in os
chunhan
parents: 77
diff changeset
   423
      by (simp add:Open None)
chunhan
parents: 77
diff changeset
   424
    moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   425
    proof-
chunhan
parents: 77
diff changeset
   426
      from grant obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   427
        where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   428
        and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   429
        apply (simp add:Open None split:option.splits)
chunhan
parents: 77
diff changeset
   430
        by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   431
      from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   432
        using os cp2sp
chunhan
parents: 77
diff changeset
   433
        apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   434
        by (auto simp:Open None co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   435
      from os have f_in': "is_file s f" by (simp add:Open None)
chunhan
parents: 77
diff changeset
   436
      from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   437
        by (auto dest!:is_file_in_current current_file_has_sfile simp:Open None)
chunhan
parents: 77
diff changeset
   438
      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
   439
        apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   440
        apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   441
        apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   442
        apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   443
        done
chunhan
parents: 77
diff changeset
   444
      have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   445
        using p1 p2 p2' vd cf2sf f_in' grant Open None f_in
chunhan
parents: 77
diff changeset
   446
        apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   447
        by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   448
      thus ?thesis using p1' p2' 
chunhan
parents: 77
diff changeset
   449
        apply (simp add:Open None split:option.splits) 
chunhan
parents: 77
diff changeset
   450
        using grant Open None p1 p2 
chunhan
parents: 77
diff changeset
   451
        by simp
chunhan
parents: 77
diff changeset
   452
    qed
chunhan
parents: 77
diff changeset
   453
    ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   454
      by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   455
  next
chunhan
parents: 77
diff changeset
   456
    case (Some inum)
chunhan
parents: 77
diff changeset
   457
    from os obtain pf where pf_in_s: "is_dir s pf" and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   458
      by (auto simp:Open Some)
chunhan
parents: 77
diff changeset
   459
    have pf_in: "is_dir s' pf" using pf_in_s alive
chunhan
parents: 77
diff changeset
   460
      apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   461
      by simp
chunhan
parents: 77
diff changeset
   462
    have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   463
      apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   464
      by (auto simp:Open Some)
chunhan
parents: 77
diff changeset
   465
    have f_not_in: "f \<notin> current_files s'" using os alive'
chunhan
parents: 77
diff changeset
   466
      apply (erule_tac x = "E_file f" in allE)
chunhan
parents: 77
diff changeset
   467
      by (auto simp:Open Some)
chunhan
parents: 77
diff changeset
   468
    have fd_not_in: "fd \<notin> current_proc_fds s' p"
chunhan
parents: 77
diff changeset
   469
      using os alive' p_in
chunhan
parents: 77
diff changeset
   470
      apply (erule_tac x = "E_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   471
      by (simp add:Open Some)
chunhan
parents: 77
diff changeset
   472
    have inum_not_in: "inum \<notin> current_inode_nums s'"
chunhan
parents: 77
diff changeset
   473
      using os alive' 
chunhan
parents: 77
diff changeset
   474
      apply (erule_tac x = "E_inum inum" in allE)
chunhan
parents: 77
diff changeset
   475
      by (simp add:Open Some)
chunhan
parents: 77
diff changeset
   476
    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
   477
      by (simp add:Open Some hungs)
chunhan
parents: 77
diff changeset
   478
    moreover have "grant s' e"  
chunhan
parents: 77
diff changeset
   479
    proof-
chunhan
parents: 77
diff changeset
   480
      from grant parent obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   481
        where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   482
        and p2: "sectxt_of_obj s (O_dir pf) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   483
        apply (simp add:Open Some split:option.splits)
chunhan
parents: 77
diff changeset
   484
        by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   485
      from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   486
        using os cp2sp
chunhan
parents: 77
diff changeset
   487
        apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   488
        by (auto simp:Open Some co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   489
      from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   490
        by (auto dest!:is_dir_in_current current_file_has_sfile simp:Open Some)
chunhan
parents: 77
diff changeset
   491
      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
   492
        apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   493
        apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   494
        apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   495
        apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   496
        apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   497
        by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   498
      have "search_check s' (up, rp, tp) pf"
chunhan
parents: 77
diff changeset
   499
        using p1 p2 p2' vd cf2sf pf_in grant Open Some pf_in_s parent vs'
chunhan
parents: 77
diff changeset
   500
        apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   501
        by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   502
      thus ?thesis using p1' p2' parent 
chunhan
parents: 77
diff changeset
   503
        apply (simp add:Open Some split:option.splits) 
chunhan
parents: 77
diff changeset
   504
        using grant Open Some p1 p2 
chunhan
parents: 77
diff changeset
   505
        by simp
chunhan
parents: 77
diff changeset
   506
    qed
chunhan
parents: 77
diff changeset
   507
    ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   508
      by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   509
  qed
chunhan
parents: 77
diff changeset
   510
next
chunhan
parents: 77
diff changeset
   511
  case (ReadFile p fd)
chunhan
parents: 77
diff changeset
   512
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   513
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   514
    by (auto simp:ReadFile)
chunhan
parents: 77
diff changeset
   515
  have fd_in: "fd \<in> current_proc_fds s' p" using os alive
chunhan
parents: 77
diff changeset
   516
    apply (erule_tac x = "O_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   517
    by (auto simp:ReadFile)
chunhan
parents: 77
diff changeset
   518
  obtain f where ffd: "file_of_proc_fd s p fd = Some f"
chunhan
parents: 77
diff changeset
   519
    using os ReadFile by auto
chunhan
parents: 77
diff changeset
   520
  hence f_in_s: "is_file s f" using vd
chunhan
parents: 77
diff changeset
   521
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   522
  obtain flags where fflag: "flags_of_proc_fd s p fd = Some flags"
chunhan
parents: 77
diff changeset
   523
    using os ReadFile by auto
chunhan
parents: 77
diff changeset
   524
  have ffd_in: "file_of_proc_fd s' p fd = Some f"
chunhan
parents: 77
diff changeset
   525
    using ffd_remain ffd by auto
chunhan
parents: 77
diff changeset
   526
  hence f_in: "is_file s' f" using vs'
chunhan
parents: 77
diff changeset
   527
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   528
  have flags_in: "flags_of_proc_fd s' p fd = Some flags"
chunhan
parents: 77
diff changeset
   529
    using fflags_remain fflag by auto
chunhan
parents: 77
diff changeset
   530
  have "os_grant s' e" using p_in fd_in ffd_in flags_in fflag os f_in 
chunhan
parents: 77
diff changeset
   531
    by (auto simp add:ReadFile is_file_in_current)
chunhan
parents: 77
diff changeset
   532
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   533
  proof-
chunhan
parents: 77
diff changeset
   534
    from grant ffd obtain up rp tp uf rf tf ufd rfd tfd
chunhan
parents: 77
diff changeset
   535
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   536
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)"
chunhan
parents: 77
diff changeset
   537
      and p3: "sectxt_of_obj s (O_fd p fd) = Some (ufd, rfd, tfd)"
chunhan
parents: 77
diff changeset
   538
      apply (simp add:ReadFile split:option.splits)
chunhan
parents: 77
diff changeset
   539
      by (case_tac a, case_tac aa, case_tac ab, blast)
chunhan
parents: 77
diff changeset
   540
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   541
      using os cp2sp
chunhan
parents: 77
diff changeset
   542
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   543
      by (auto simp:ReadFile co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   544
    from vd f_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   545
      by (auto dest!:is_file_in_current current_file_has_sfile)
chunhan
parents: 77
diff changeset
   546
    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
   547
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   548
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   549
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   550
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   551
      done
chunhan
parents: 77
diff changeset
   552
    have p3': "sectxt_of_obj s' (O_fd p fd) = Some (ufd, rfd, tfd)" 
chunhan
parents: 77
diff changeset
   553
      using cfd2sfd ffd_in ffd p3 f_in f_in_s vd
chunhan
parents: 77
diff changeset
   554
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   555
      apply (erule_tac x = fd in allE)
chunhan
parents: 77
diff changeset
   556
      apply (simp add:proc_file_fds_def)
chunhan
parents: 77
diff changeset
   557
      apply (auto simp:cfd2sfd_def fflag flags_in p3 split:option.splits
chunhan
parents: 77
diff changeset
   558
        dest!:current_file_has_sfile' simp:is_file_in_current)
chunhan
parents: 77
diff changeset
   559
      done
chunhan
parents: 77
diff changeset
   560
    show ?thesis using p1' p2' p3' ffd_in ffd
chunhan
parents: 77
diff changeset
   561
      apply (simp add:ReadFile split:option.splits) 
chunhan
parents: 77
diff changeset
   562
      using grant p1 p2 p3 ReadFile
chunhan
parents: 77
diff changeset
   563
      by simp
chunhan
parents: 77
diff changeset
   564
  qed
chunhan
parents: 77
diff changeset
   565
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   566
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   567
next
chunhan
parents: 77
diff changeset
   568
  case (WriteFile p fd)
chunhan
parents: 77
diff changeset
   569
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   570
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   571
    by (auto simp:WriteFile)
chunhan
parents: 77
diff changeset
   572
  have fd_in: "fd \<in> current_proc_fds s' p" using os alive
chunhan
parents: 77
diff changeset
   573
    apply (erule_tac x = "O_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   574
    by (auto simp:WriteFile)
chunhan
parents: 77
diff changeset
   575
  obtain f where ffd: "file_of_proc_fd s p fd = Some f"
chunhan
parents: 77
diff changeset
   576
    using os WriteFile by auto
chunhan
parents: 77
diff changeset
   577
  hence f_in_s: "is_file s f" using vd
chunhan
parents: 77
diff changeset
   578
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   579
  obtain flags where fflag: "flags_of_proc_fd s p fd = Some flags"
chunhan
parents: 77
diff changeset
   580
    using os WriteFile by auto
chunhan
parents: 77
diff changeset
   581
  have ffd_in: "file_of_proc_fd s' p fd = Some f"
chunhan
parents: 77
diff changeset
   582
    using ffd_remain ffd by auto
chunhan
parents: 77
diff changeset
   583
  hence f_in: "is_file s' f" using vs'
chunhan
parents: 77
diff changeset
   584
    by (auto intro:file_of_pfd_is_file)
chunhan
parents: 77
diff changeset
   585
  have flags_in: "flags_of_proc_fd s' p fd = Some flags"
chunhan
parents: 77
diff changeset
   586
    using fflags_remain fflag by auto
chunhan
parents: 77
diff changeset
   587
  have "os_grant s' e" using p_in fd_in ffd_in flags_in fflag os f_in 
chunhan
parents: 77
diff changeset
   588
    by (auto simp add:WriteFile is_file_in_current)
chunhan
parents: 77
diff changeset
   589
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   590
  proof-
chunhan
parents: 77
diff changeset
   591
    from grant ffd obtain up rp tp uf rf tf ufd rfd tfd
chunhan
parents: 77
diff changeset
   592
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   593
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)"
chunhan
parents: 77
diff changeset
   594
      and p3: "sectxt_of_obj s (O_fd p fd) = Some (ufd, rfd, tfd)"
chunhan
parents: 77
diff changeset
   595
      apply (simp add:WriteFile split:option.splits)
chunhan
parents: 77
diff changeset
   596
      by (case_tac a, case_tac aa, case_tac ab, blast)
chunhan
parents: 77
diff changeset
   597
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   598
      using os cp2sp
chunhan
parents: 77
diff changeset
   599
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   600
      by (auto simp:WriteFile co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   601
    from vd f_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   602
      by (auto dest!:is_file_in_current current_file_has_sfile)
chunhan
parents: 77
diff changeset
   603
    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
   604
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   605
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   606
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   607
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   608
      done
chunhan
parents: 77
diff changeset
   609
    have p3': "sectxt_of_obj s' (O_fd p fd) = Some (ufd, rfd, tfd)" 
chunhan
parents: 77
diff changeset
   610
      using cfd2sfd ffd_in ffd p3 f_in f_in_s vd
chunhan
parents: 77
diff changeset
   611
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   612
      apply (erule_tac x = fd in allE)
chunhan
parents: 77
diff changeset
   613
      apply (simp add:proc_file_fds_def)
chunhan
parents: 77
diff changeset
   614
      apply (auto simp:cfd2sfd_def fflag flags_in p3 split:option.splits
chunhan
parents: 77
diff changeset
   615
        dest!:current_file_has_sfile' simp:is_file_in_current)
chunhan
parents: 77
diff changeset
   616
      done
chunhan
parents: 77
diff changeset
   617
    show ?thesis using p1' p2' p3' ffd_in ffd
chunhan
parents: 77
diff changeset
   618
      apply (simp add:WriteFile split:option.splits) 
chunhan
parents: 77
diff changeset
   619
      using grant p1 p2 p3 WriteFile
chunhan
parents: 77
diff changeset
   620
      by simp
chunhan
parents: 77
diff changeset
   621
  qed
chunhan
parents: 77
diff changeset
   622
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   623
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   624
next
chunhan
parents: 77
diff changeset
   625
  case (CloseFd p fd)
chunhan
parents: 77
diff changeset
   626
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   627
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   628
    by (auto simp:CloseFd)
chunhan
parents: 77
diff changeset
   629
  have fd_in: "fd \<in> current_proc_fds s' p" using os alive
chunhan
parents: 77
diff changeset
   630
    apply (erule_tac x = "O_fd p fd" in allE)
chunhan
parents: 77
diff changeset
   631
    by (auto simp:CloseFd)
chunhan
parents: 77
diff changeset
   632
  have "os_grant s' e" using p_in fd_in 
chunhan
parents: 77
diff changeset
   633
    by (auto simp add:CloseFd)
chunhan
parents: 77
diff changeset
   634
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   635
    by(simp add:CloseFd)
chunhan
parents: 77
diff changeset
   636
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   637
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   638
next
chunhan
parents: 77
diff changeset
   639
  case (UnLink p f)
chunhan
parents: 77
diff changeset
   640
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   641
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   642
    by (auto simp:UnLink)
chunhan
parents: 77
diff changeset
   643
  have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   644
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   645
    by (auto simp:UnLink)
chunhan
parents: 77
diff changeset
   646
  from os vd obtain pf where pf_in_s: "is_dir s pf"
chunhan
parents: 77
diff changeset
   647
    and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   648
    by (auto simp:UnLink dest!:file_has_parent)
chunhan
parents: 77
diff changeset
   649
  from pf_in_s alive have pf_in: "is_dir s' pf"
chunhan
parents: 77
diff changeset
   650
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   651
    by (auto simp:UnLink)
chunhan
parents: 77
diff changeset
   652
  have "os_grant s' e" using p_in f_in os
chunhan
parents: 77
diff changeset
   653
    by (simp add:UnLink hungs)
chunhan
parents: 77
diff changeset
   654
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   655
  proof-    
chunhan
parents: 77
diff changeset
   656
    from grant parent obtain up rp tp uf rf tf upf rpf tpf
chunhan
parents: 77
diff changeset
   657
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   658
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   659
      and p3: "sectxt_of_obj s (O_dir pf) = Some (upf, rpf, tpf)" 
chunhan
parents: 77
diff changeset
   660
      apply (simp add:UnLink split:option.splits)
chunhan
parents: 77
diff changeset
   661
      by (case_tac a, case_tac aa, case_tac ab, blast) 
chunhan
parents: 77
diff changeset
   662
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   663
      using os cp2sp
chunhan
parents: 77
diff changeset
   664
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   665
      by (auto simp:UnLink co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   666
    from vd os pf_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   667
      by (auto dest!:is_file_in_current current_file_has_sfile simp:UnLink)
chunhan
parents: 77
diff changeset
   668
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   669
      using p2 cf2sf f_in os parent 
chunhan
parents: 77
diff changeset
   670
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   671
      apply (erule exE, clarsimp simp:UnLink)
chunhan
parents: 77
diff changeset
   672
      apply (frule_tac s = s in is_file_in_current, simp)
chunhan
parents: 77
diff changeset
   673
      by (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   674
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   675
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:UnLink)
chunhan
parents: 77
diff changeset
   676
    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
   677
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   678
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   679
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   680
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   681
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   682
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   683
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   684
      using p1 p2 p2' vd cf2sf f_in grant UnLink os parent vs'
chunhan
parents: 77
diff changeset
   685
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   686
      by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   687
    thus ?thesis using p1' p2' p3' parent 
chunhan
parents: 77
diff changeset
   688
      apply (simp add:UnLink split:option.splits) 
chunhan
parents: 77
diff changeset
   689
      using grant UnLink p1 p2 p3
chunhan
parents: 77
diff changeset
   690
      by simp
chunhan
parents: 77
diff changeset
   691
  qed
chunhan
parents: 77
diff changeset
   692
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   693
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   694
next
chunhan
parents: 77
diff changeset
   695
  case (Rmdir p f)
chunhan
parents: 77
diff changeset
   696
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   697
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   698
    by (auto simp:Rmdir)
chunhan
parents: 77
diff changeset
   699
  have f_in: "is_dir s' f" using os alive
chunhan
parents: 77
diff changeset
   700
    apply (erule_tac x = "O_dir f" in allE)
chunhan
parents: 77
diff changeset
   701
    by (auto simp:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   702
  have not_root: "f \<noteq> []" using os 
chunhan
parents: 77
diff changeset
   703
    by (auto simp:Rmdir)
chunhan
parents: 77
diff changeset
   704
  from os vd obtain pf where pf_in_s: "is_dir s pf"
chunhan
parents: 77
diff changeset
   705
    and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   706
    apply (auto simp:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   707
    apply (case_tac f, simp+)
chunhan
parents: 77
diff changeset
   708
    apply (drule parentf_is_dir_prop1, auto)
chunhan
parents: 77
diff changeset
   709
    done
chunhan
parents: 77
diff changeset
   710
  from pf_in_s alive have pf_in: "is_dir s' pf"
chunhan
parents: 77
diff changeset
   711
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   712
    by (auto simp:Rmdir)
chunhan
parents: 77
diff changeset
   713
  have empty_in: "dir_is_empty s' f" using os
chunhan
parents: 77
diff changeset
   714
    apply (simp add:dir_is_empty_def f_in)
chunhan
parents: 77
diff changeset
   715
    apply auto using alive'
chunhan
parents: 77
diff changeset
   716
    apply (erule_tac x = "E_file f'" in allE)
chunhan
parents: 77
diff changeset
   717
    by (simp add:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   718
  have "os_grant s' e" using p_in f_in os empty_in
chunhan
parents: 77
diff changeset
   719
    by (simp add:Rmdir hungs)
chunhan
parents: 77
diff changeset
   720
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   721
  proof-
chunhan
parents: 77
diff changeset
   722
    from grant parent obtain up rp tp uf rf tf upf rpf tpf
chunhan
parents: 77
diff changeset
   723
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   724
      and p2: "sectxt_of_obj s (O_dir f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   725
      and p3: "sectxt_of_obj s (O_dir pf) = Some (upf, rpf, tpf)" 
chunhan
parents: 77
diff changeset
   726
      apply (simp add:Rmdir split:option.splits)
chunhan
parents: 77
diff changeset
   727
      by (case_tac a, case_tac aa, case_tac ab, blast) 
chunhan
parents: 77
diff changeset
   728
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   729
      using os cp2sp
chunhan
parents: 77
diff changeset
   730
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   731
      by (auto simp:Rmdir co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   732
    from vd os pf_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   733
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:dir_is_empty_def Rmdir)
chunhan
parents: 77
diff changeset
   734
    hence p2': "sectxt_of_obj s' (O_dir f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   735
      using p2 cf2sf f_in os parent 
chunhan
parents: 77
diff changeset
   736
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   737
      apply (erule exE, clarsimp simp:Rmdir dir_is_empty_def)
chunhan
parents: 77
diff changeset
   738
      apply (frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   739
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   740
      by (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   741
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   742
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:Rmdir)
chunhan
parents: 77
diff changeset
   743
    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
   744
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   745
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   746
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   747
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   748
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   749
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   750
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   751
      using p1 p2 p2' vd cf2sf f_in grant Rmdir os parent vs'
chunhan
parents: 77
diff changeset
   752
      apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   753
      by (simp_all add:dir_is_empty_def split:option.splits)
chunhan
parents: 77
diff changeset
   754
    thus ?thesis using p1' p2' p3' parent 
chunhan
parents: 77
diff changeset
   755
      apply (simp add:Rmdir split:option.splits) 
chunhan
parents: 77
diff changeset
   756
      using grant Rmdir p1 p2 p3
chunhan
parents: 77
diff changeset
   757
      by simp
chunhan
parents: 77
diff changeset
   758
  qed
chunhan
parents: 77
diff changeset
   759
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   760
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   761
next
chunhan
parents: 77
diff changeset
   762
  case (Mkdir p f inum)
chunhan
parents: 77
diff changeset
   763
  from os obtain pf where pf_in_s: "is_dir s pf" and parent: "parent f = Some pf"
chunhan
parents: 77
diff changeset
   764
    by (auto simp:Mkdir)
chunhan
parents: 77
diff changeset
   765
  have pf_in: "is_dir s' pf" using pf_in_s alive
chunhan
parents: 77
diff changeset
   766
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   767
    by simp
chunhan
parents: 77
diff changeset
   768
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   769
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   770
    by (auto simp:Mkdir)
chunhan
parents: 77
diff changeset
   771
  have f_not_in: "f \<notin> current_files s'" using os alive'
chunhan
parents: 77
diff changeset
   772
    apply (erule_tac x = "E_file f" in allE)
chunhan
parents: 77
diff changeset
   773
    by (auto simp:Mkdir)
chunhan
parents: 77
diff changeset
   774
  have inum_not_in: "inum \<notin> current_inode_nums s'"
chunhan
parents: 77
diff changeset
   775
    using os alive' 
chunhan
parents: 77
diff changeset
   776
    apply (erule_tac x = "E_inum inum" in allE)
chunhan
parents: 77
diff changeset
   777
    by (simp add:Mkdir)
chunhan
parents: 77
diff changeset
   778
  have "os_grant s' e" using p_in pf_in parent f_not_in os inum_not_in
chunhan
parents: 77
diff changeset
   779
    by (simp add:Mkdir hungs)
chunhan
parents: 77
diff changeset
   780
  moreover have "grant s' e"  
chunhan
parents: 77
diff changeset
   781
  proof-
chunhan
parents: 77
diff changeset
   782
    from grant parent obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   783
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   784
      and p2: "sectxt_of_obj s (O_dir pf) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   785
      apply (simp add:Mkdir split:option.splits)
chunhan
parents: 77
diff changeset
   786
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   787
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   788
      using os cp2sp
chunhan
parents: 77
diff changeset
   789
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   790
      by (auto simp:Mkdir co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   791
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   792
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:Mkdir)
chunhan
parents: 77
diff changeset
   793
    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
   794
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   795
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   796
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   797
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   798
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   799
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   800
    have "search_check s' (up, rp, tp) pf"
chunhan
parents: 77
diff changeset
   801
      using p1 p2 p2' vd cf2sf pf_in grant Mkdir pf_in_s parent vs'
chunhan
parents: 77
diff changeset
   802
      apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   803
      apply (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   804
      done
chunhan
parents: 77
diff changeset
   805
    thus ?thesis using p1' p2' parent 
chunhan
parents: 77
diff changeset
   806
      apply (simp add:Mkdir split:option.splits) 
chunhan
parents: 77
diff changeset
   807
      using grant Mkdir p1 p2 
chunhan
parents: 77
diff changeset
   808
      apply simp 
chunhan
parents: 77
diff changeset
   809
      done
chunhan
parents: 77
diff changeset
   810
  qed
chunhan
parents: 77
diff changeset
   811
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   812
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   813
next
chunhan
parents: 77
diff changeset
   814
  case (LinkHard p f f')
chunhan
parents: 77
diff changeset
   815
  from os obtain pf where pf_in_s: "is_dir s pf" and parent: "parent f' = Some pf"
chunhan
parents: 77
diff changeset
   816
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   817
  have pf_in: "is_dir s' pf" using pf_in_s alive
chunhan
parents: 77
diff changeset
   818
    apply (erule_tac x = "O_dir pf" in allE)
chunhan
parents: 77
diff changeset
   819
    by simp
chunhan
parents: 77
diff changeset
   820
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   821
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   822
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   823
  have f'_not_in: "f' \<notin> current_files s'" using os alive'
chunhan
parents: 77
diff changeset
   824
    apply (erule_tac x = "E_file f'" in allE)
chunhan
parents: 77
diff changeset
   825
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   826
  have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   827
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   828
    by (auto simp:LinkHard)
chunhan
parents: 77
diff changeset
   829
  have "os_grant s' e" using p_in pf_in parent os f_in f'_not_in
chunhan
parents: 77
diff changeset
   830
    by (simp add:LinkHard hungs)
chunhan
parents: 77
diff changeset
   831
  moreover have "grant s' e"
chunhan
parents: 77
diff changeset
   832
  proof-
chunhan
parents: 77
diff changeset
   833
    from grant parent obtain up rp tp uf rf tf upf rpf tpf
chunhan
parents: 77
diff changeset
   834
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   835
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   836
      and p3: "sectxt_of_obj s (O_dir pf) = Some (upf, rpf, tpf)" 
chunhan
parents: 77
diff changeset
   837
      apply (simp add:LinkHard split:option.splits)
chunhan
parents: 77
diff changeset
   838
      by (case_tac a, case_tac aa, case_tac ab, blast) 
chunhan
parents: 77
diff changeset
   839
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   840
      using os cp2sp
chunhan
parents: 77
diff changeset
   841
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   842
      by (auto simp:LinkHard co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   843
    from vd os pf_in_s have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   844
      by (auto dest!:is_file_in_current current_file_has_sfile simp:LinkHard)
chunhan
parents: 77
diff changeset
   845
    hence p2': "sectxt_of_obj s' (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   846
      using p2 cf2sf f_in os parent 
chunhan
parents: 77
diff changeset
   847
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   848
      apply (erule exE, clarsimp simp:LinkHard)
chunhan
parents: 77
diff changeset
   849
      apply (frule_tac s = s in is_file_in_current, simp)
chunhan
parents: 77
diff changeset
   850
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   851
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   852
      by (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   853
    from vd os pf_in_s have "\<exists> sf. cf2sfile s pf = Some sf"
chunhan
parents: 77
diff changeset
   854
      by (auto dest!:is_dir_in_current current_file_has_sfile simp:LinkHard)
chunhan
parents: 77
diff changeset
   855
    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
   856
      apply (erule_tac x = pf in allE)
chunhan
parents: 77
diff changeset
   857
      apply (erule exE, frule_tac s = s in is_dir_in_current, simp)
chunhan
parents: 77
diff changeset
   858
      apply (drule is_dir_not_file, drule is_dir_not_file)
chunhan
parents: 77
diff changeset
   859
      apply (auto simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   860
      apply (case_tac pf, simp_all)
chunhan
parents: 77
diff changeset
   861
      by (simp add:sroot_def root_sec_remains vd vs')
chunhan
parents: 77
diff changeset
   862
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   863
      using p1 p2 p2' vd cf2sf f_in grant LinkHard os parent vs'
chunhan
parents: 77
diff changeset
   864
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   865
      by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   866
    moreover have "search_check s' (up, rp, tp) pf"
chunhan
parents: 77
diff changeset
   867
      using p1 p3 p3' vd cf2sf pf_in grant LinkHard os parent vs'
chunhan
parents: 77
diff changeset
   868
      apply (rule_tac s = s in enrich_search_check')
chunhan
parents: 77
diff changeset
   869
      apply (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   870
      done
chunhan
parents: 77
diff changeset
   871
    ultimately show ?thesis using p1' p2' p3' parent 
chunhan
parents: 77
diff changeset
   872
      apply (simp add:LinkHard split:option.splits) 
chunhan
parents: 77
diff changeset
   873
      using grant LinkHard p1 p2 p3
chunhan
parents: 77
diff changeset
   874
      apply simp 
chunhan
parents: 77
diff changeset
   875
      done
chunhan
parents: 77
diff changeset
   876
  qed
chunhan
parents: 77
diff changeset
   877
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   878
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   879
next
chunhan
parents: 77
diff changeset
   880
  case (Truncate p f len)
chunhan
parents: 77
diff changeset
   881
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   882
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   883
    by (auto simp:Truncate)
chunhan
parents: 77
diff changeset
   884
  have f_in: "is_file s' f" using os alive
chunhan
parents: 77
diff changeset
   885
    apply (erule_tac x = "O_file f" in allE)
chunhan
parents: 77
diff changeset
   886
    by (auto simp:Truncate)
chunhan
parents: 77
diff changeset
   887
  have "os_grant s' e" using p_in f_in by (simp add:Truncate)
chunhan
parents: 77
diff changeset
   888
  moreover have "grant s' e"
chunhan
parents: 77
diff changeset
   889
  proof-
chunhan
parents: 77
diff changeset
   890
    from grant obtain up rp tp uf rf tf 
chunhan
parents: 77
diff changeset
   891
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   892
      and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
chunhan
parents: 77
diff changeset
   893
      apply (simp add:Truncate split:option.splits)
chunhan
parents: 77
diff changeset
   894
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   895
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   896
      using os cp2sp
chunhan
parents: 77
diff changeset
   897
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   898
      by (auto simp:Truncate co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   899
    from os have f_in': "is_file s f" by (simp add:Truncate)
chunhan
parents: 77
diff changeset
   900
    from vd os have "\<exists> sf. cf2sfile s f = Some sf"
chunhan
parents: 77
diff changeset
   901
      by (auto dest!:is_file_in_current current_file_has_sfile simp:Truncate)
chunhan
parents: 77
diff changeset
   902
    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
   903
      apply (erule_tac x = f in allE)
chunhan
parents: 77
diff changeset
   904
      apply (auto dest:is_file_in_current simp:cf2sfile_def split:option.splits)
chunhan
parents: 77
diff changeset
   905
      apply (case_tac f, simp)
chunhan
parents: 77
diff changeset
   906
      apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
chunhan
parents: 77
diff changeset
   907
      done
chunhan
parents: 77
diff changeset
   908
    have "search_check s' (up, rp, tp) f"
chunhan
parents: 77
diff changeset
   909
      using p1 p2 p2' vd cf2sf f_in' grant Truncate f_in
chunhan
parents: 77
diff changeset
   910
      apply (rule_tac s = s in enrich_search_check)
chunhan
parents: 77
diff changeset
   911
      by (simp_all split:option.splits)
chunhan
parents: 77
diff changeset
   912
    thus ?thesis using p1' p2' 
chunhan
parents: 77
diff changeset
   913
      apply (simp add:Truncate split:option.splits) 
chunhan
parents: 77
diff changeset
   914
      using grant Truncate p1 p2
chunhan
parents: 77
diff changeset
   915
      by (simp add:Truncate grant p1 p2)
chunhan
parents: 77
diff changeset
   916
  qed
chunhan
parents: 77
diff changeset
   917
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   918
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   919
next
chunhan
parents: 77
diff changeset
   920
  case (CreateMsgq p q)
chunhan
parents: 77
diff changeset
   921
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   922
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   923
    by (auto simp:CreateMsgq)
chunhan
parents: 77
diff changeset
   924
  have q_not_in: "q \<notin> current_msgqs s'" using os alive'
chunhan
parents: 77
diff changeset
   925
    apply (erule_tac x = "E_msgq q" in allE)
chunhan
parents: 77
diff changeset
   926
    by (simp add:CreateMsgq)
chunhan
parents: 77
diff changeset
   927
  have "os_grant s' e" using p_in q_not_in by (simp add:CreateMsgq)
chunhan
parents: 77
diff changeset
   928
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   929
  proof-
chunhan
parents: 77
diff changeset
   930
    from grant obtain up rp tp 
chunhan
parents: 77
diff changeset
   931
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   932
      apply (simp add:CreateMsgq split:option.splits)
chunhan
parents: 77
diff changeset
   933
      by (case_tac a, blast)
chunhan
parents: 77
diff changeset
   934
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   935
      using os cp2sp
chunhan
parents: 77
diff changeset
   936
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   937
      by (auto simp:CreateMsgq co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   938
    show ?thesis using p1' 
chunhan
parents: 77
diff changeset
   939
      apply (simp add:CreateMsgq split:option.splits) 
chunhan
parents: 77
diff changeset
   940
      using grant CreateMsgq p1
chunhan
parents: 77
diff changeset
   941
      by simp
chunhan
parents: 77
diff changeset
   942
  qed
chunhan
parents: 77
diff changeset
   943
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   944
    by (erule_tac valid.intros(2), simp+)
chunhan
parents: 77
diff changeset
   945
next
chunhan
parents: 77
diff changeset
   946
  case (RemoveMsgq p q)
chunhan
parents: 77
diff changeset
   947
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   948
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   949
    by (auto simp:RemoveMsgq)
chunhan
parents: 77
diff changeset
   950
  have q_in: "q \<in> current_msgqs s'" using os alive
chunhan
parents: 77
diff changeset
   951
    apply (erule_tac x = "O_msgq q" in allE)
chunhan
parents: 77
diff changeset
   952
    by (simp add:RemoveMsgq)
chunhan
parents: 77
diff changeset
   953
  have "os_grant s' e" using p_in q_in by (simp add:RemoveMsgq)
chunhan
parents: 77
diff changeset
   954
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   955
  proof-
chunhan
parents: 77
diff changeset
   956
    from grant obtain up rp tp uq rq tq
chunhan
parents: 77
diff changeset
   957
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   958
      and p2: "sectxt_of_obj s (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   959
      apply (simp add:RemoveMsgq split:option.splits)
chunhan
parents: 77
diff changeset
   960
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   961
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   962
      using os cp2sp
chunhan
parents: 77
diff changeset
   963
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   964
      by (auto simp:RemoveMsgq co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   965
    from p2 have p2': "sectxt_of_obj s' (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   966
      using os cq2sq vd
chunhan
parents: 77
diff changeset
   967
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
   968
      by (auto simp:RemoveMsgq co2sobj.simps cq2smsgq_def dest!:current_has_sms' split:option.splits)
chunhan
parents: 77
diff changeset
   969
    show ?thesis using p1' p2' grant p1 p2
chunhan
parents: 77
diff changeset
   970
      by (simp add:RemoveMsgq)
chunhan
parents: 77
diff changeset
   971
  qed
chunhan
parents: 77
diff changeset
   972
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
   973
    by (erule_tac valid.intros(2), simp+)  
chunhan
parents: 77
diff changeset
   974
next
chunhan
parents: 77
diff changeset
   975
  case (SendMsg p q m)
chunhan
parents: 77
diff changeset
   976
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
   977
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
   978
    by (auto simp:SendMsg)
chunhan
parents: 77
diff changeset
   979
  have q_in: "q \<in> current_msgqs s'" using os alive
chunhan
parents: 77
diff changeset
   980
    apply (erule_tac x = "O_msgq q" in allE)
chunhan
parents: 77
diff changeset
   981
    by (simp add:SendMsg)
chunhan
parents: 77
diff changeset
   982
  have m_not_in: "m \<notin> set (msgs_of_queue s' q)" using os alive'
chunhan
parents: 77
diff changeset
   983
    apply (erule_tac x = "E_msg q m" in allE)
chunhan
parents: 77
diff changeset
   984
    by (simp add:SendMsg q_in)
chunhan
parents: 77
diff changeset
   985
  have "os_grant s' e" using p_in q_in m_not_in
chunhan
parents: 77
diff changeset
   986
    by (simp add:SendMsg)
chunhan
parents: 77
diff changeset
   987
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
   988
  proof-
chunhan
parents: 77
diff changeset
   989
    from grant obtain up rp tp uq rq tq
chunhan
parents: 77
diff changeset
   990
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   991
      and p2: "sectxt_of_obj s (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   992
      apply (simp add:SendMsg split:option.splits)
chunhan
parents: 77
diff changeset
   993
      by (case_tac a, case_tac aa, blast)
chunhan
parents: 77
diff changeset
   994
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
   995
      using os cp2sp
chunhan
parents: 77
diff changeset
   996
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
   997
      by (auto simp:SendMsg co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
   998
    from p2 have p2': "sectxt_of_obj s' (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
   999
      using os cq2sq vd
chunhan
parents: 77
diff changeset
  1000
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
  1001
      by (auto simp:SendMsg co2sobj.simps cq2smsgq_def dest!:current_has_sms' split:option.splits)
chunhan
parents: 77
diff changeset
  1002
    show ?thesis using p1' p2' grant p1 p2
chunhan
parents: 77
diff changeset
  1003
      by (simp add:SendMsg)
chunhan
parents: 77
diff changeset
  1004
  qed
chunhan
parents: 77
diff changeset
  1005
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
  1006
    by (erule_tac valid.intros(2), simp+)  
chunhan
parents: 77
diff changeset
  1007
next
chunhan
parents: 77
diff changeset
  1008
  case (RecvMsg p q m)
chunhan
parents: 77
diff changeset
  1009
  have p_in: "p \<in> current_procs s'" using os alive
chunhan
parents: 77
diff changeset
  1010
    apply (erule_tac x = "O_proc p" in allE)
chunhan
parents: 77
diff changeset
  1011
    by (auto simp:RecvMsg)
chunhan
parents: 77
diff changeset
  1012
  have q_in: "q \<in> current_msgqs s'" using os alive
chunhan
parents: 77
diff changeset
  1013
    apply (erule_tac x = "O_msgq q" in allE)
chunhan
parents: 77
diff changeset
  1014
    by (simp add:RecvMsg) 
chunhan
parents: 77
diff changeset
  1015
  have m_in: "m = hd (msgs_of_queue s' q)" 
chunhan
parents: 77
diff changeset
  1016
    and sms_not_empty: "msgs_of_queue s' q \<noteq> []"
chunhan
parents: 77
diff changeset
  1017
    using os sms_remain
chunhan
parents: 77
diff changeset
  1018
    by (auto simp:RecvMsg)
chunhan
parents: 77
diff changeset
  1019
  have "os_grant s' e" using p_in q_in m_in sms_not_empty os
chunhan
parents: 77
diff changeset
  1020
    by (simp add:RecvMsg)
chunhan
parents: 77
diff changeset
  1021
  moreover have "grant s' e" 
chunhan
parents: 77
diff changeset
  1022
  proof-
chunhan
parents: 77
diff changeset
  1023
    from grant obtain up rp tp uq rq tq um rm tm
chunhan
parents: 77
diff changeset
  1024
      where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
  1025
      and p2: "sectxt_of_obj s (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
  1026
      and p3: "sectxt_of_obj s (O_msg q m) = Some (um, rm, tm)"
chunhan
parents: 77
diff changeset
  1027
      apply (simp add:RecvMsg split:option.splits)
chunhan
parents: 77
diff changeset
  1028
      by (case_tac a, case_tac aa, case_tac ab, blast)
chunhan
parents: 77
diff changeset
  1029
    from p1 have p1': "sectxt_of_obj s' (O_proc p) = Some (up, rp, tp)"
chunhan
parents: 77
diff changeset
  1030
      using os cp2sp
chunhan
parents: 77
diff changeset
  1031
      apply (erule_tac x = p in allE)
chunhan
parents: 77
diff changeset
  1032
      by (auto simp:RecvMsg co2sobj.simps cp2sproc_def split:option.splits)
chunhan
parents: 77
diff changeset
  1033
    from p2 have p2': "sectxt_of_obj s' (O_msgq q) = Some (uq, rq, tq)"
chunhan
parents: 77
diff changeset
  1034
      using os cq2sq vd
chunhan
parents: 77
diff changeset
  1035
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
  1036
      by (auto simp:RecvMsg co2sobj.simps cq2smsgq_def dest!:current_has_sms' split:option.splits)
chunhan
parents: 77
diff changeset
  1037
    from p3 have p3': "sectxt_of_obj s' (O_msg q m) = Some (um, rm, tm)"
chunhan
parents: 77
diff changeset
  1038
      using sms_remain cq2sq vd os p2 p2' p3 
chunhan
parents: 77
diff changeset
  1039
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
  1040
      apply (erule_tac x = q in allE)
chunhan
parents: 77
diff changeset
  1041
      apply (clarsimp simp:RecvMsg)
chunhan
parents: 77
diff changeset
  1042
      apply (simp add:cq2smsgq_def split:option.splits if_splits)
chunhan
parents: 77
diff changeset
  1043
      apply (drule current_has_sms', simp, simp)
chunhan
parents: 77
diff changeset
  1044
      apply (case_tac "msgs_of_queue s q", simp)
chunhan
parents: 77
diff changeset
  1045
      apply (simp add:cqm2sms.simps split:option.splits)
chunhan
parents: 77
diff changeset
  1046
      apply (auto simp add:cm2smsg_def split:option.splits if_splits)[1]
chunhan
parents: 77
diff changeset
  1047
      apply (case_tac "msgs_of_queue s q", simp)
chunhan
parents: 77
diff changeset
  1048
      apply (simp add:cqm2sms.simps split:option.splits)
chunhan
parents: 77
diff changeset
  1049
      apply (auto simp add:cm2smsg_def split:option.splits if_splits)[1]
chunhan
parents: 77
diff changeset
  1050
      done
chunhan
parents: 77
diff changeset
  1051
    show ?thesis using p1' p2' p3' grant p1 p2 p3
chunhan
parents: 77
diff changeset
  1052
      by (simp add:RecvMsg)
chunhan
parents: 77
diff changeset
  1053
  qed
chunhan
parents: 77
diff changeset
  1054
  ultimately show ?thesis using vs'
chunhan
parents: 77
diff changeset
  1055
    by (erule_tac valid.intros(2), simp+)  
chunhan
parents: 77
diff changeset
  1056
next
chunhan
parents: 77
diff changeset
  1057
  case (CreateSock p af st fd inum)
chunhan
parents: 77
diff changeset
  1058
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1059
    by (simp add:CreateSock)
chunhan
parents: 77
diff changeset
  1060
next
chunhan
parents: 77
diff changeset
  1061
  case (Bind p fd addr)
chunhan
parents: 77
diff changeset
  1062
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1063
    by (simp add:Bind)
chunhan
parents: 77
diff changeset
  1064
next
chunhan
parents: 77
diff changeset
  1065
  case (Connect p fd addr)
chunhan
parents: 77
diff changeset
  1066
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1067
    by (simp add:Connect)
chunhan
parents: 77
diff changeset
  1068
next
chunhan
parents: 77
diff changeset
  1069
  case (Listen p fd)
chunhan
parents: 77
diff changeset
  1070
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1071
    by (simp add:Listen)
chunhan
parents: 77
diff changeset
  1072
next
chunhan
parents: 77
diff changeset
  1073
  case (Accept p fd addr port fd' inum)
chunhan
parents: 77
diff changeset
  1074
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1075
    by (simp add:Accept)
chunhan
parents: 77
diff changeset
  1076
next
chunhan
parents: 77
diff changeset
  1077
  case (SendSock p fd)
chunhan
parents: 77
diff changeset
  1078
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1079
    by (simp add:SendSock)
chunhan
parents: 77
diff changeset
  1080
next
chunhan
parents: 77
diff changeset
  1081
  case (RecvSock p fd)
chunhan
parents: 77
diff changeset
  1082
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1083
    by (simp add:RecvSock)
chunhan
parents: 77
diff changeset
  1084
next
chunhan
parents: 77
diff changeset
  1085
  case (Shutdown p fd how)
chunhan
parents: 77
diff changeset
  1086
  show ?thesis using grant
chunhan
parents: 77
diff changeset
  1087
    by (simp add:Shutdown)
chunhan
parents: 77
diff changeset
  1088
qed  
77
chunhan
parents:
diff changeset
  1089
  
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1090
lemma not_all_procs_prop2:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1091
  "p' \<notin> all_procs s \<Longrightarrow> p' \<notin> init_procs"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1092
apply (induct s, simp)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1093
by (case_tac a, auto)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1094
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1095
lemma not_all_procs_prop3:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1096
  "p' \<notin> all_procs s \<Longrightarrow> p' \<notin> current_procs s"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1097
apply (induct s, simp)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1098
by (case_tac a, auto)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1099
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1100
definition is_created_proc:: "t_state \<Rightarrow> t_process \<Rightarrow> bool"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1101
where
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1102
  "is_created_proc s p \<equiv> p \<in> current_procs s \<and> (p \<in> init_procs \<longrightarrow> died (O_proc p) s)"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1103
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1104
lemma created_proc_clone:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1105
  "valid (Clone p p' fds # s) \<Longrightarrow> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1106
   is_created_proc (Clone p p' fds # s) tp = (if (tp = p') then True else is_created_proc s tp)"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1107
apply (drule vt_grant_os)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1108
apply (auto simp:is_created_proc_def dest:not_all_procs_prop2)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1109
using not_died_init_proc
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1110
by auto
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1111
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1112
lemma created_proc_exit: 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1113
  "is_created_proc (Exit p # s) tp = (if (tp = p) then False else is_created_proc s tp)"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1114
by (simp add:is_created_proc_def)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1115
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1116
lemma created_proc_kill:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1117
  "is_created_proc (Kill p p' # s) tp = (if (tp = p') then False else is_created_proc s tp)"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1118
by (simp add:is_created_proc_def)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1119
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1120
lemma created_proc_other:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1121
  "\<lbrakk>\<And> p p' fds. e \<noteq> Clone p p' fds;
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1122
    \<And> p. e \<noteq> Exit p;
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1123
    \<And> p p'. e \<noteq> Kill p p'\<rbrakk> \<Longrightarrow> is_created_proc (e # s) tp = is_created_proc s tp"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1124
by (case_tac e, auto simp:is_created_proc_def)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1125
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1126
lemmas is_created_proc_simps = created_proc_clone created_proc_exit created_proc_kill created_proc_other
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1127
(*
77
chunhan
parents:
diff changeset
  1128
chunhan
parents:
diff changeset
  1129
chunhan
parents:
diff changeset
  1130
chunhan
parents:
diff changeset
  1131
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1132
       (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>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1133
       (\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p')  obj) \<and> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1134
       (\<forall> p'. p' \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') p' = cp2sproc s p) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1135
       (\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') f = cf2sfile s f) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1136
       (Tainted (enrich_proc s p p') = (Tainted s \<union> (if (O_proc p \<in> Tainted s) then {O_proc p'} else {})))"*)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1137
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1138
lemma enrich_proc_dup_in:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1139
  "\<lbrakk>is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1140
   \<Longrightarrow> p' \<in> current_procs (enrich_proc s p p')"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1141
apply (induct s, simp add:is_created_proc_def)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1142
apply (frule vt_grant_os, frule vd_cons)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1143
apply (case_tac a, auto simp:is_created_proc_def dest:not_all_procs_prop3)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1144
done
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1145
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1146
lemma enrich_proc_dup_ffd:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1147
  "\<lbrakk>file_of_proc_fd s p fd = Some f; is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1148
   \<Longrightarrow> file_of_proc_fd (enrich_proc s p p') p' fd = Some f"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1149
apply (induct s, simp add:is_created_proc_def)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1150
apply (frule vt_grant_os, frule vd_cons)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1151
apply (case_tac a, auto simp:is_created_proc_def proc_file_fds_def
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1152
  dest:not_all_procs_prop3 split:if_splits option.splits)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1153
done 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1154
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1155
lemma enrich_proc_dup_ffd':
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1156
  "\<lbrakk>file_of_proc_fd (enrich_proc s p p') p' fd = Some f; is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1157
   \<Longrightarrow> file_of_proc_fd s p fd = Some f"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1158
apply (induct s, simp add:is_created_proc_def)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1159
apply (frule vt_grant_os, frule vd_cons)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1160
apply (case_tac a, auto simp:is_created_proc_def proc_file_fds_def
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1161
  dest:not_all_procs_prop3 split:if_splits option.splits)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1162
done 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1163
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1164
lemma current_fflag_in_fds:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1165
  "\<lbrakk>flags_of_proc_fd s p fd = Some flag; valid s\<rbrakk> \<Longrightarrow> fd \<in> current_proc_fds s p"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1166
apply (induct s arbitrary:p)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1167
apply (simp add:flags_of_proc_fd.simps file_of_proc_fd.simps init_oflags_prop2) 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1168
apply (frule vd_cons, frule vt_grant_os, case_tac a)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1169
apply (auto split:if_splits option.splits dest:proc_fd_in_fds)
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1170
done
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1171
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1172
lemma current_fflag_has_ffd:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1173
  "\<lbrakk>flags_of_proc_fd s p fd = Some flag; valid s\<rbrakk> \<Longrightarrow> \<exists> f. file_of_proc_fd s p fd = Some f"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1174
apply (induct s arbitrary:p)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1175
apply (simp add: file_of_proc_fd.simps init_fileflag_valid) 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1176
apply (frule vd_cons, frule vt_grant_os, case_tac a)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1177
apply (auto split:if_splits option.splits dest:proc_fd_in_fds)
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1178
done
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1179
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1180
lemma enrich_proc_dup_fflags:
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1181
  "\<lbrakk>flags_of_proc_fd s p fd = Some flag; is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1182
   \<Longrightarrow> flags_of_proc_fd (enrich_proc s p p') p' fd = Some (remove_create_flag flag) \<or>
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1183
       flags_of_proc_fd (enrich_proc s p p') p' fd = Some flag"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1184
apply (induct s arbitrary:p, simp add:is_created_proc_def)
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1185
apply (frule vt_grant_os, frule vd_cons)
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1186
apply (case_tac a, auto simp:is_created_proc_def proc_file_fds_def is_creat_flag_def
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1187
  dest:not_all_procs_prop3 split:if_splits option.splits)
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1188
done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1189
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1190
lemma enrich_proc_dup_ffds:
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1191
  "\<lbrakk>is_created_proc s p; p' \<notin> all_procs s; valid s\<rbrakk>
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1192
   \<Longrightarrow> proc_file_fds (enrich_proc s p p') p' = proc_file_fds s p"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1193
apply (auto simp:proc_file_fds_def)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1194
apply (rule_tac x = f in exI) 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1195
apply (erule enrich_proc_dup_ffd', simp+)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1196
apply (rule_tac x = f in exI)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1197
apply (erule enrich_proc_dup_ffd, simp+)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1198
done
77
chunhan
parents:
diff changeset
  1199
chunhan
parents:
diff changeset
  1200
lemma enrich_proc_prop:
chunhan
parents:
diff changeset
  1201
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk>
chunhan
parents:
diff changeset
  1202
   \<Longrightarrow> valid (enrich_proc s p p') \<and> 
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1203
       (\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj) \<and> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1204
       (\<forall> obj. enrich_not_alive s obj \<longrightarrow> enrich_not_alive (enrich_proc s p p') obj) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1205
       (files_hung_by_del (enrich_proc s p p') = files_hung_by_del s) \<and> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1206
       (\<forall> tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1207
       (\<forall> f. f \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') f = cf2sfile s f) \<and> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1208
       (\<forall> q. q \<in> current_msgqs s \<longrightarrow> cq2smsgq (enrich_proc s p p') q = cq2smsgq s q) \<and> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1209
       (\<forall> tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> file_of_proc_fd (enrich_proc s p p') tp fd = Some f) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1210
       (\<forall> tp fd flags. flags_of_proc_fd s tp fd = Some flags \<longrightarrow> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1211
                      flags_of_proc_fd (enrich_proc s p p') tp fd = Some flags) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1212
       (\<forall> q. msgs_of_queue (enrich_proc s p p') q = msgs_of_queue s q) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1213
       (\<forall> tp fd. fd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp fd = cfd2sfd s tp fd) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1214
       (cp2sproc (enrich_proc s p p') p' = cp2sproc s p) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1215
       (\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd)"
77
chunhan
parents:
diff changeset
  1216
proof (induct s)
chunhan
parents:
diff changeset
  1217
  case Nil
chunhan
parents:
diff changeset
  1218
  thus ?case by (auto simp:is_created_proc_def)
chunhan
parents:
diff changeset
  1219
next
chunhan
parents:
diff changeset
  1220
  case (Cons e s)
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1221
  hence vd_cons: "valid (e # s)" and created_cons: "is_created_proc (e # s) p"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1222
    and all_procs_cons: "p' \<notin> all_procs (e # s)" and vd: "valid s" 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1223
    and os: "os_grant s e" and grant: "grant s e"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1224
    by (auto dest:vd_cons vt_grant_os vt_grant)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1225
  from all_procs_cons have all_procs: "p' \<notin> all_procs s" by (case_tac e, auto)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1226
  from Cons have pre: "is_created_proc s p \<Longrightarrow> valid (enrich_proc s p p') \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1227
     (\<forall>obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1228
     (\<forall>obj. enrich_not_alive s obj \<longrightarrow> enrich_not_alive (enrich_proc s p p') obj) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1229
     files_hung_by_del (enrich_proc s p p') = files_hung_by_del s \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1230
     (\<forall>tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1231
     (\<forall>f. f \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') f = cf2sfile s f) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1232
     (\<forall>q. q \<in> current_msgqs s \<longrightarrow> cq2smsgq (enrich_proc s p p') q = cq2smsgq s q) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1233
     (\<forall>tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> file_of_proc_fd (enrich_proc s p p') tp fd = Some f) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1234
     (\<forall>tp fd flags.
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1235
         flags_of_proc_fd s tp fd = Some flags \<longrightarrow> flags_of_proc_fd (enrich_proc s p p') tp fd = Some flags) \<and>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1236
     (\<forall>q. msgs_of_queue (enrich_proc s p p') q = msgs_of_queue s q) \<and>
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1237
     (\<forall>tp fd. fd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp fd = cfd2sfd s tp fd) \<and>     
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1238
     (cp2sproc (enrich_proc s p p') p' = cp2sproc s p) \<and>
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1239
     (\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd)"
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1240
    using vd all_procs by auto
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1241
  have alive_pre: "is_created_proc s p \<Longrightarrow> (\<forall>obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1242
    using pre by simp
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1243
  hence curf_pre: "is_created_proc s p \<Longrightarrow> (\<forall>f. f \<in> current_files s \<longrightarrow> f \<in> current_files (enrich_proc s p p'))"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1244
    using vd apply auto
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1245
    apply (drule is_file_or_dir, simp)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1246
    apply (erule disjE)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1247
    apply (erule_tac x = "O_file f" in allE, simp add:is_file_in_current)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1248
    apply (erule_tac x = "O_dir f" in allE, simp add:is_dir_in_current)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1249
    done
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1250
  have "valid (enrich_proc (e # s) p p')"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1251
  proof-
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1252
    from pre have pre': "is_created_proc s p \<Longrightarrow> valid (enrich_proc s p p')" by simp
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1253
    have "is_created_proc s p \<Longrightarrow> valid (e # enrich_proc s p p')" 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1254
      apply (frule pre')
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1255
      apply (erule_tac s = s in enrich_valid_intro_cons)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1256
      apply (simp_all add:os grant vd pre)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1257
      done  
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1258
    moreover have "\<And>f fds. \<lbrakk>valid (Execve p f fds # enrich_proc s p p'); is_created_proc s p; 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1259
      valid (Execve p f fds # s); p' \<notin> all_procs s\<rbrakk>
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1260
      \<Longrightarrow> valid (Execve p' f (fds \<inter> proc_file_fds s p) # Execve p f fds # enrich_proc s p p')"
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1261
    proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1262
      fix f fds
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1263
      assume a1: "valid (Execve p f fds # enrich_proc s p p')" and a2: "is_created_proc s p"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1264
        and a3: "valid (Execve p f fds # s)" and a0: "p' \<notin> all_procs s"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1265
      have cp2sp: "\<forall> tp. tp \<in> current_procs s \<longrightarrow> cp2sproc (enrich_proc s p p') tp = cp2sproc s tp"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1266
        and cf2sf: "\<forall> tf. tf \<in> current_files s \<longrightarrow> cf2sfile (enrich_proc s p p') tf = cf2sfile s tf"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1267
        and cfd2sfd: "\<forall> tp tfd. tfd \<in> proc_file_fds s tp \<longrightarrow> cfd2sfd (enrich_proc s p p') tp tfd = cfd2sfd s tp tfd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1268
        and ffd_remain: "\<forall>tp fd f. file_of_proc_fd s tp fd = Some f \<longrightarrow> 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1269
                                   file_of_proc_fd (enrich_proc s p p') tp fd = Some f"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1270
        and dup_sp: "cp2sproc (enrich_proc s p p') p' = cp2sproc s p"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1271
        and dup_sfd: "\<forall> fd. fd \<in> proc_file_fds s p \<longrightarrow> cfd2sfd (enrich_proc s p p') p' fd = cfd2sfd s p fd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1272
        using pre a2 by auto
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1273
      show "valid (Execve p' f (fds \<inter> proc_file_fds s p) # Execve p f fds # enrich_proc s p p')"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1274
      proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1275
        from a0 a3 have a0': "p' \<noteq> p" by (auto dest!:vt_grant_os not_all_procs_prop3)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1276
        from a3 have grant: "grant s (Execve p f fds)" and os: "os_grant s (Execve p f fds)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1277
          by (auto dest:vt_grant_os vt_grant simp del:os_grant.simps)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1278
        have f_in: "is_file (enrich_proc s p p') f" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1279
        proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1280
          from pre a2
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1281
          have a4: "\<forall> obj. alive s obj \<longrightarrow> alive (enrich_proc s p p') obj"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1282
            by (auto)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1283
          show ?thesis using a3 a4
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1284
            apply (erule_tac x = "O_file f" in allE)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1285
            by (auto dest:vt_grant_os)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1286
        qed
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1287
        moreover have a5: "proc_file_fds s p \<subseteq> proc_file_fds (Execve p f fds # enrich_proc s p p') p'" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1288
          using a3 a0'
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1289
          apply (frule_tac vt_grant_os)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1290
          apply (auto simp:proc_file_fds_def)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1291
          apply (rule_tac x = fa in exI)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1292
          apply (erule enrich_proc_dup_ffd)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1293
          apply (simp_all add:vd all_procs a2)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1294
          done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1295
        ultimately have "os_grant (Execve p f fds # enrich_proc s p p') (Execve p' f (fds \<inter> proc_file_fds s p))"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1296
          apply (auto simp:is_file_simps enrich_proc_dup_in a2 vd all_procs a1 enrich_proc_dup_ffds)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1297
          done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1298
        moreover have "grant (Execve p f fds # enrich_proc s p p') (Execve p' f (fds \<inter> proc_file_fds s p))"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1299
        proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1300
          from grant obtain up rp tp uf rf tf 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1301
            where p1: "sectxt_of_obj s (O_proc p) = Some (up, rp, tp)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1302
            and p2: "sectxt_of_obj s (O_file f) = Some (uf, rf, tf)" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1303
            by (simp split:option.splits, blast)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1304
          with grant obtain pu nr nt where p3: "npctxt_execve (up, rp, tp) (uf, rf, tf) = Some (pu, nr, nt)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1305
            by (simp split:option.splits del:npctxt_execve.simps, blast)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1306
          have p1': "sectxt_of_obj (Execve p f fds # enrich_proc s p p') (O_proc p') = Some (up, rp, tp)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1307
            using p1 dup_sp a1 a0'
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1308
            apply (simp add:sectxt_of_obj_simps)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1309
            by (simp add:cp2sproc_def split:option.splits)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1310
          from os have f_in': "is_file s f"  by simp 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1311
          from vd os have "\<exists> sf. cf2sfile s f = Some sf"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1312
            by (auto dest!:is_file_in_current current_file_has_sfile)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1313
          hence p2': "sectxt_of_obj (Execve p f fds # enrich_proc s p p') (O_file f) = Some (uf, rf, tf)" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1314
            using f_in p2 cf2sf os a1
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1315
            apply (erule_tac x = f in allE)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1316
            apply (auto dest:is_file_in_current simp:cf2sfile_def sectxt_of_obj_simps split:option.splits)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1317
            apply (case_tac f, simp)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1318
            apply (drule_tac s = s in root_is_dir', simp add:vd, simp+)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1319
            done 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1320
          from dup_sfd a5 have "\<forall>fd. fd \<in> proc_file_fds s p \<longrightarrow> 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1321
            cfd2sfd (Execve p f fds # enrich_proc s p p') p' fd = cfd2sfd s p fd"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1322
            apply (rule_tac allI)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1323
            apply (erule_tac x = fd in allE, clarsimp)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1324
            apply (drule set_mp, simp)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1325
            apply (auto simp:cfd2sfd_execve proc_file_fds_def a1)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1326
            done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1327
          hence "inherit_fds_check (Execve p f fds # enrich_proc s p p') (up, nr, nt) p' (fds \<inter> proc_file_fds s p)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1328
            using grant os p1 p2 p3 vd
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1329
            apply (clarsimp)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1330
            apply (rule_tac s = s and p = p and fds = fds in enrich_inherit_fds_check_dup)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1331
            apply simp_all
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1332
            done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1333
          moreover have "search_check (Execve p f fds # enrich_proc s p p') (up, rp, tp) f"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1334
            using p1 p2 p2' vd cf2sf f_in f_in' grant p3 f_in a1
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1335
            apply (rule_tac s = s in enrich_search_check)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1336
            apply (simp_all add:is_file_simps)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1337
            apply (rule allI, rule impI, erule_tac x = fa in allE, simp)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1338
            apply (drule_tac ff = fa in cf2sfile_other')
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1339
            by (auto simp:a2 curf_pre)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1340
          ultimately show ?thesis 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1341
            using p1' p2' p3
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1342
            apply (simp split:option.splits)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1343
            using grant p1 p2
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1344
            apply simp
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1345
            done
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1346
        qed
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1347
        ultimately show ?thesis using a1
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1348
          by (erule_tac valid.intros(2), auto)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1349
      qed
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1350
    qed
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1351
    moreover have "\<And>tp fds. \<lbrakk>valid (Clone tp p fds # s); p' \<noteq> p; p' \<notin> all_procs s\<rbrakk> \<Longrightarrow> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1352
      valid (Clone tp p' (fds \<inter> proc_file_fds s tp) # Clone tp p fds # s)"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1353
      apply (frule vt_grant_os, frule vt_grant, drule not_all_procs_prop3)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1354
      apply (rule valid.intros(2))
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1355
      apply (simp_all split:option.splits add:sectxt_of_obj_simps)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1356
      apply (auto simp add:proc_file_fds_def)[1]
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1357
      apply (auto simp:inherit_fds_check_def sectxt_of_obj_simps sectxts_of_fds_def inherit_fds_check_ctxt_def)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1358
      done
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1359
    moreover have "\<And>f flags fd inum.
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1360
       \<lbrakk>valid (Open p f flags fd inum # enrich_proc s p p'); is_created_proc s p\<rbrakk>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1361
       \<Longrightarrow> valid (Open p' f (remove_create_flag flags) fd inum # Open p f flags fd inum # enrich_proc s p p')"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1362
      sorry
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1363
    moreover have "\<And>fd. \<lbrakk>valid (CloseFd p fd # enrich_proc s p p'); is_created_proc s p; 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1364
      valid (CloseFd p fd # s); p' \<notin> all_procs s\<rbrakk>
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1365
           \<Longrightarrow> valid (CloseFd p' fd # CloseFd p fd # enrich_proc s p p')"
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1366
    proof-
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1367
      fix fd
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1368
      assume a1: "valid (CloseFd p fd # enrich_proc s p p')" and a2: "is_created_proc s p" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1369
        and a3: "p' \<notin> all_procs s" and a4: "valid (CloseFd p fd # s)"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1370
      from a4 a3 have a0: "p' \<noteq> p" by (auto dest!:vt_grant_os not_all_procs_prop3)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1371
      have "p' \<in> current_procs (enrich_proc s p p')" 
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1372
        using a2 a3 vd
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1373
        by (auto intro:enrich_proc_dup_in)
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1374
      moreover have "fd \<in> current_proc_fds (enrich_proc s p p') p'"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1375
      ultimately show "valid (CloseFd p' fd # CloseFd p fd # enrich_proc s p p')"
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1376
        apply (rule valid.intros(2))
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1377
        apply (simp_all add:a1 a0 a2 pre')
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1378
      
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1379
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1380
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1381
      sorry 
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1382
(*
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1383
       thus ?thesis using created_cons vd_cons all_procs_cons
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1384
      apply (case_tac e)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1385
      apply (auto simp:is_created_proc_simps split:if_splits)
80
c9cfc416fa2d fixed bug in enrich_proc
chunhan
parents: 79
diff changeset
  1386
        *)
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1387
    ultimately show ?thesis using created_cons vd_cons all_procs_cons
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1388
      apply (case_tac e)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1389
      apply (auto simp:is_created_proc_simps split:if_splits)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1390
      done
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1391
  qed
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1392
  moreover have "\<forall>obj. alive (e # s) obj \<longrightarrow> alive (enrich_proc (e # s) p p') obj"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1393
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1394
  moreover have "\<forall>obj. enrich_not_alive (e # s) obj \<longrightarrow> enrich_not_alive (enrich_proc (e # s) p p') obj"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1395
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1396
  moreover have "files_hung_by_del (enrich_proc (e # s) p p') = files_hung_by_del (e # s)"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1397
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1398
  moreover have "\<forall>p. p \<in> current_procs (e # s) \<longrightarrow> cp2sproc (enrich_proc (e # s) p p') p = cp2sproc (e # s) p"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1399
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1400
  moreover have "\<forall>f. f \<in> current_files (e # s) \<longrightarrow> cf2sfile (enrich_proc (e # s) p p') f = cf2sfile (e # s) f"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1401
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1402
  moreover have "\<forall>q. q \<in> current_msgqs (e # s) \<longrightarrow> cq2smsgq (enrich_proc (e # s) p p') q = cq2smsgq (e # s) q"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1403
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1404
  moreover have "\<forall>p fd f. file_of_proc_fd (e # s) p fd = Some f \<longrightarrow> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1405
    file_of_proc_fd (enrich_proc (e # s) p p') p fd = Some f"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1406
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1407
  moreover have "\<forall>p fd flags. flags_of_proc_fd (e # s) p fd = Some flags \<longrightarrow>
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1408
        flags_of_proc_fd (enrich_proc (e # s) p p') p fd = Some flags"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1409
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1410
  moreover have "\<forall>q. msgs_of_queue (enrich_proc (e # s) p p') q = msgs_of_queue (e # s) q"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1411
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1412
  moreover have "\<forall>p fd. fd \<in> proc_file_fds (e # s) p \<longrightarrow> 
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1413
    cfd2sfd (enrich_proc (e # s) p p') p fd = cfd2sfd (e # s) p fd"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1414
    sorry
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1415
  ultimately show ?case
77
chunhan
parents:
diff changeset
  1416
    by auto
chunhan
parents:
diff changeset
  1417
qed
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1418
  
77
chunhan
parents:
diff changeset
  1419
79
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1420
lemma enrich_proc_valid:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1421
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk> \<Longrightarrow> valid (enrich_proc s p p')"
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1422
by (auto dest:enrich_proc_prop)
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1423
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1424
lemma enrich_proc_valid:
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1425
  "\<lbrakk>valid s; is_created_proc s p; p' \<notin> all_procs s\<rbrakk> \<Longrightarrow> "
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1426
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1427
c09fcbcdb871 fixed bug in flags_of_proc_fd
chunhan
parents: 78
diff changeset
  1428