no_shm_selinux/Info_flow_shm_prop.thy
author chunhan
Mon, 30 Dec 2013 23:41:58 +0800
changeset 86 690636b7b6f1
parent 77 6f7b9039715f
permissions -rw-r--r--
find bug: a created proc can be tainted by a message, which cannot remain and maynot be duplicated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77
chunhan
parents:
diff changeset
     1
theory Info_flow_shm_prop
chunhan
parents:
diff changeset
     2
imports Main Flask_type Flask My_list_prefix Init_prop Valid_prop Delete_prop Current_prop
chunhan
parents:
diff changeset
     3
begin
chunhan
parents:
diff changeset
     4
chunhan
parents:
diff changeset
     5
context flask begin
chunhan
parents:
diff changeset
     6
chunhan
parents:
diff changeset
     7
(*********** simpset for one_flow_shm **************)
chunhan
parents:
diff changeset
     8
chunhan
parents:
diff changeset
     9
lemma one_flow_not_self:
chunhan
parents:
diff changeset
    10
  "one_flow_shm s h p p \<Longrightarrow> False"
chunhan
parents:
diff changeset
    11
by (simp add:one_flow_shm_def)
chunhan
parents:
diff changeset
    12
chunhan
parents:
diff changeset
    13
lemma one_flow_shm_attach:
chunhan
parents:
diff changeset
    14
  "valid (Attach p h flag # s) \<Longrightarrow> one_flow_shm (Attach p h flag # s) = (\<lambda> h' pa pb. 
chunhan
parents:
diff changeset
    15
     if (h' = h) 
chunhan
parents:
diff changeset
    16
     then (pa = p \<and> pb \<noteq> p \<and> flag = SHM_RDWR \<and> (\<exists> flagb. (pb, flagb) \<in> procs_of_shm s h)) \<or>
chunhan
parents:
diff changeset
    17
          (pb = p \<and> pa \<noteq> p \<and> (pa, SHM_RDWR) \<in> procs_of_shm s h) \<or>
chunhan
parents:
diff changeset
    18
          (one_flow_shm s h pa pb)               
chunhan
parents:
diff changeset
    19
     else one_flow_shm s h' pa pb        )"
chunhan
parents:
diff changeset
    20
apply (rule ext, rule ext, rule ext, frule vd_cons, frule vt_grant_os)
chunhan
parents:
diff changeset
    21
by (auto simp add: one_flow_shm_def)
chunhan
parents:
diff changeset
    22
chunhan
parents:
diff changeset
    23
lemma one_flow_shm_detach:
chunhan
parents:
diff changeset
    24
  "valid (Detach p h # s) \<Longrightarrow> one_flow_shm (Detach p h # s) = (\<lambda> h' pa pb.
chunhan
parents:
diff changeset
    25
     if (h' = h) 
chunhan
parents:
diff changeset
    26
     then (pa \<noteq> p \<and> pb \<noteq> p \<and> one_flow_shm s h' pa pb)
chunhan
parents:
diff changeset
    27
     else one_flow_shm s h' pa pb)"
chunhan
parents:
diff changeset
    28
apply (rule ext, rule ext, rule ext, frule vt_grant_os)
chunhan
parents:
diff changeset
    29
by (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
    30
chunhan
parents:
diff changeset
    31
lemma one_flow_shm_deleteshm:
chunhan
parents:
diff changeset
    32
  "valid (DeleteShM p h # s) \<Longrightarrow> one_flow_shm (DeleteShM p h # s) = (\<lambda> h' pa pb. 
chunhan
parents:
diff changeset
    33
     if (h' = h) 
chunhan
parents:
diff changeset
    34
     then False
chunhan
parents:
diff changeset
    35
     else one_flow_shm s h' pa pb)"
chunhan
parents:
diff changeset
    36
apply (rule ext, rule ext, rule ext, frule vt_grant_os)
chunhan
parents:
diff changeset
    37
by (auto simp: one_flow_shm_def)
chunhan
parents:
diff changeset
    38
chunhan
parents:
diff changeset
    39
lemma one_flow_shm_clone:
chunhan
parents:
diff changeset
    40
  "valid (Clone p p' fds shms # s) \<Longrightarrow> one_flow_shm (Clone p p' fds shms # s) = (\<lambda> h pa pb. 
chunhan
parents:
diff changeset
    41
     if (pa = p' \<and> pb \<noteq> p' \<and> h \<in> shms)
chunhan
parents:
diff changeset
    42
     then (if (pb = p) then (flag_of_proc_shm s p h = Some SHM_RDWR) else one_flow_shm s h p pb)
chunhan
parents:
diff changeset
    43
     else if (pb = p' \<and> pa \<noteq> p' \<and> h \<in> shms)
chunhan
parents:
diff changeset
    44
          then (if (pa = p) then (flag_of_proc_shm s p h = Some SHM_RDWR) else one_flow_shm s h pa p)
chunhan
parents:
diff changeset
    45
          else one_flow_shm s h pa pb)"
chunhan
parents:
diff changeset
    46
apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons, clarsimp)
chunhan
parents:
diff changeset
    47
apply (frule_tac p = p' in procs_of_shm_prop2', simp)
chunhan
parents:
diff changeset
    48
apply (auto simp:one_flow_shm_def intro:procs_of_shm_prop4 flag_of_proc_shm_prop1)
chunhan
parents:
diff changeset
    49
done
chunhan
parents:
diff changeset
    50
chunhan
parents:
diff changeset
    51
lemma one_flow_shm_execve:
chunhan
parents:
diff changeset
    52
  "valid (Execve p f fds # s) \<Longrightarrow> one_flow_shm (Execve p f fds # s) = (\<lambda> h pa pb. 
chunhan
parents:
diff changeset
    53
     pa \<noteq> p \<and> pb \<noteq> p \<and> one_flow_shm s h pa pb    )"
chunhan
parents:
diff changeset
    54
apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
    55
by (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
    56
chunhan
parents:
diff changeset
    57
lemma one_flow_shm_kill:
chunhan
parents:
diff changeset
    58
  "valid (Kill p p' # s) \<Longrightarrow> one_flow_shm (Kill p p' # s) = (\<lambda> h pa pb. 
chunhan
parents:
diff changeset
    59
     pa \<noteq> p' \<and> pb \<noteq> p' \<and> one_flow_shm s h pa pb                 )"
chunhan
parents:
diff changeset
    60
apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
    61
by (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
    62
chunhan
parents:
diff changeset
    63
lemma one_flow_shm_exit:
chunhan
parents:
diff changeset
    64
  "valid (Exit p # s) \<Longrightarrow> one_flow_shm (Exit p # s) = (\<lambda> h pa pb. 
chunhan
parents:
diff changeset
    65
     pa \<noteq> p \<and> pb \<noteq> p \<and> one_flow_shm s h pa pb                          )"
chunhan
parents:
diff changeset
    66
apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
    67
by (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
    68
chunhan
parents:
diff changeset
    69
lemma one_flow_shm_other:
chunhan
parents:
diff changeset
    70
  "\<lbrakk>valid (e # s); 
chunhan
parents:
diff changeset
    71
    \<forall> p h flag. e \<noteq> Attach p h flag;
chunhan
parents:
diff changeset
    72
    \<forall> p h. e \<noteq> Detach p h;
chunhan
parents:
diff changeset
    73
    \<forall> p h. e \<noteq> DeleteShM p h;
chunhan
parents:
diff changeset
    74
    \<forall> p p' fds shms. e \<noteq> Clone p p' fds shms;
chunhan
parents:
diff changeset
    75
    \<forall> p f fds. e \<noteq> Execve p f fds;
chunhan
parents:
diff changeset
    76
    \<forall> p p'. e \<noteq> Kill p p';
chunhan
parents:
diff changeset
    77
    \<forall> p. e \<noteq> Exit p
chunhan
parents:
diff changeset
    78
   \<rbrakk> \<Longrightarrow> one_flow_shm (e # s) = one_flow_shm s"
chunhan
parents:
diff changeset
    79
apply (rule ext, rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
    80
apply (case_tac e, auto simp:one_flow_shm_def dest:procs_of_shm_prop2)
chunhan
parents:
diff changeset
    81
apply (drule procs_of_shm_prop1, auto)
chunhan
parents:
diff changeset
    82
done
chunhan
parents:
diff changeset
    83
chunhan
parents:
diff changeset
    84
lemmas one_flow_shm_simps = one_flow_shm_other one_flow_shm_attach one_flow_shm_detach one_flow_shm_deleteshm
chunhan
parents:
diff changeset
    85
  one_flow_shm_clone one_flow_shm_execve one_flow_shm_kill one_flow_shm_exit
chunhan
parents:
diff changeset
    86
chunhan
parents:
diff changeset
    87
type_synonym t_edge_shm = "t_process \<times> t_shm \<times> t_process"
chunhan
parents:
diff changeset
    88
fun Fst:: "t_edge_shm \<Rightarrow> t_process" where "Fst (a, b, c) = a"
chunhan
parents:
diff changeset
    89
fun Snd:: "t_edge_shm \<Rightarrow> t_shm" where "Snd (a, b, c) = b"
chunhan
parents:
diff changeset
    90
fun Trd:: "t_edge_shm \<Rightarrow> t_process" where "Trd (a, b, c) = c"
chunhan
parents:
diff changeset
    91
chunhan
parents:
diff changeset
    92
fun edge_related:: "t_edge_shm list \<Rightarrow> t_process \<Rightarrow> t_shm \<Rightarrow> bool"
chunhan
parents:
diff changeset
    93
where
chunhan
parents:
diff changeset
    94
  "edge_related [] p h = False"
chunhan
parents:
diff changeset
    95
| "edge_related ((from, shm, to) # path) p h = 
chunhan
parents:
diff changeset
    96
     (if (((p = from) \<or> (p = to)) \<and> (h = shm)) then True 
chunhan
parents:
diff changeset
    97
      else edge_related path p h)"
chunhan
parents:
diff changeset
    98
         
chunhan
parents:
diff changeset
    99
inductive path_by_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_edge_shm list \<Rightarrow> t_process \<Rightarrow> bool"
chunhan
parents:
diff changeset
   100
where
chunhan
parents:
diff changeset
   101
  pbs1: "p \<in> current_procs s \<Longrightarrow> path_by_shm s p [] p"
chunhan
parents:
diff changeset
   102
| pbs2: "\<lbrakk>path_by_shm s p path p'; one_flow_shm s h p' p''; p'' \<notin> set (map Fst path)\<rbrakk> 
chunhan
parents:
diff changeset
   103
         \<Longrightarrow> path_by_shm s p ((p', h, p'')# path) p''"
chunhan
parents:
diff changeset
   104
chunhan
parents:
diff changeset
   105
chunhan
parents:
diff changeset
   106
lemma one_step_path: "\<lbrakk>one_flow_shm s h p p'; valid s\<rbrakk> \<Longrightarrow> path_by_shm s p [(p, h, p')] p'"
chunhan
parents:
diff changeset
   107
apply (rule_tac path = "[]" and p = p in path_by_shm.intros(2))
chunhan
parents:
diff changeset
   108
apply (rule path_by_shm.intros(1))
chunhan
parents:
diff changeset
   109
apply (auto intro:procs_of_shm_prop2 simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   110
done
chunhan
parents:
diff changeset
   111
chunhan
parents:
diff changeset
   112
lemma pbs_prop1:
chunhan
parents:
diff changeset
   113
  "path_by_shm s p path p' \<Longrightarrow> ((path = []) = (p = p')) \<and> (path \<noteq> [] \<longrightarrow> p \<in> set (map Fst path))"
chunhan
parents:
diff changeset
   114
apply (erule path_by_shm.induct, simp)
chunhan
parents:
diff changeset
   115
apply (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   116
done
chunhan
parents:
diff changeset
   117
chunhan
parents:
diff changeset
   118
lemma pbs_prop2:
chunhan
parents:
diff changeset
   119
  "path_by_shm s p path p' \<Longrightarrow> (path = []) = (p = p')"
chunhan
parents:
diff changeset
   120
by (simp add:pbs_prop1)
chunhan
parents:
diff changeset
   121
chunhan
parents:
diff changeset
   122
lemma pbs_prop2':
chunhan
parents:
diff changeset
   123
  "path_by_shm s p path p \<Longrightarrow> path = []"
chunhan
parents:
diff changeset
   124
by (simp add:pbs_prop2)
chunhan
parents:
diff changeset
   125
chunhan
parents:
diff changeset
   126
lemma pbs_prop3:
chunhan
parents:
diff changeset
   127
  "\<lbrakk>path_by_shm s p path p'; path \<noteq> []\<rbrakk> \<Longrightarrow> p \<in> set (map Fst path)"
chunhan
parents:
diff changeset
   128
by (drule pbs_prop1, auto)
chunhan
parents:
diff changeset
   129
chunhan
parents:
diff changeset
   130
lemma pbs_prop4[rule_format]:
chunhan
parents:
diff changeset
   131
  "path_by_shm s p path p'\<Longrightarrow> path \<noteq> [] \<longrightarrow> p' \<in> set (map Trd path)"
chunhan
parents:
diff changeset
   132
by (erule path_by_shm.induct, auto)
chunhan
parents:
diff changeset
   133
chunhan
parents:
diff changeset
   134
lemma pbs_prop5[rule_format]:
chunhan
parents:
diff changeset
   135
  "path_by_shm s p path p' \<Longrightarrow> path \<noteq> [] \<longrightarrow> p' \<notin> set (map Fst path)"
chunhan
parents:
diff changeset
   136
by (erule path_by_shm.induct, auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   137
chunhan
parents:
diff changeset
   138
lemma pbs_prop6_aux:
chunhan
parents:
diff changeset
   139
  "path_by_shm s pa pathac pc \<Longrightarrow> valid s \<longrightarrow> (\<forall> pb \<in> set (map Fst pathac). \<exists> pathab pathbc. path_by_shm s pa pathab pb \<and> path_by_shm s pb pathbc pc \<and> pathac = pathbc @ pathab)"
chunhan
parents:
diff changeset
   140
apply (erule path_by_shm.induct)
chunhan
parents:
diff changeset
   141
apply simp
chunhan
parents:
diff changeset
   142
apply clarify
chunhan
parents:
diff changeset
   143
apply (case_tac "pb = p'", simp)
chunhan
parents:
diff changeset
   144
apply (rule_tac x = path in exI, simp)
chunhan
parents:
diff changeset
   145
apply (erule one_step_path, simp)
chunhan
parents:
diff changeset
   146
apply (erule_tac x = pb in ballE, simp_all, clarsimp)
chunhan
parents:
diff changeset
   147
apply (rule_tac x = pathab in exI, simp)
chunhan
parents:
diff changeset
   148
apply (erule pbs2, auto)
chunhan
parents:
diff changeset
   149
done
chunhan
parents:
diff changeset
   150
chunhan
parents:
diff changeset
   151
lemma pbs_prop6:
chunhan
parents:
diff changeset
   152
  "\<lbrakk>path_by_shm s pa pathac pc; pb \<in> set (map Fst pathac); valid s\<rbrakk>
chunhan
parents:
diff changeset
   153
   \<Longrightarrow> \<exists> pathab pathbc. path_by_shm s pa pathab pb \<and> path_by_shm s pb pathbc pc \<and> pathac = pathbc @ pathab"
chunhan
parents:
diff changeset
   154
by (drule pbs_prop6_aux, auto)
chunhan
parents:
diff changeset
   155
chunhan
parents:
diff changeset
   156
lemma pbs_prop7_aux:
chunhan
parents:
diff changeset
   157
  "path_by_shm s pa pathac pc \<Longrightarrow> valid s \<longrightarrow> (\<forall> pb \<in> set (map Trd pathac). \<exists> pathab pathbc. path_by_shm s pa pathab pb \<and> path_by_shm s pb pathbc pc \<and> pathac = pathbc @ pathab)"
chunhan
parents:
diff changeset
   158
apply (erule path_by_shm.induct)
chunhan
parents:
diff changeset
   159
apply simp
chunhan
parents:
diff changeset
   160
apply clarify
chunhan
parents:
diff changeset
   161
apply (case_tac "pb = p''", simp)
chunhan
parents:
diff changeset
   162
apply (rule_tac x = "(p',h,p'') # path" in exI, simp)
chunhan
parents:
diff changeset
   163
apply (rule conjI, erule pbs2, simp+)
chunhan
parents:
diff changeset
   164
apply (rule pbs1, clarsimp simp:one_flow_shm_def procs_of_shm_prop2)
chunhan
parents:
diff changeset
   165
apply (erule_tac x = pb in ballE, simp_all, clarsimp)
chunhan
parents:
diff changeset
   166
apply (rule_tac x = pathab in exI, simp)
chunhan
parents:
diff changeset
   167
apply (erule pbs2, auto)
chunhan
parents:
diff changeset
   168
done
chunhan
parents:
diff changeset
   169
chunhan
parents:
diff changeset
   170
lemma pbs_prop7:
chunhan
parents:
diff changeset
   171
  "\<lbrakk>path_by_shm s pa pathac pc; pb \<in> set (map Trd pathac); valid s\<rbrakk>
chunhan
parents:
diff changeset
   172
   \<Longrightarrow> \<exists> pathab pathbc. path_by_shm s pa pathab pb \<and> path_by_shm s pb pathbc pc \<and> pathac = pathbc @ pathab"
chunhan
parents:
diff changeset
   173
by (drule pbs_prop7_aux, drule mp, simp, erule_tac x = pb in ballE, auto)
chunhan
parents:
diff changeset
   174
chunhan
parents:
diff changeset
   175
lemma pbs_prop8:
chunhan
parents:
diff changeset
   176
  "path_by_shm s p path p' \<Longrightarrow> (set (map Fst path) - {p}) = (set (map Trd path) - {p'})"
chunhan
parents:
diff changeset
   177
proof (induct rule:path_by_shm.induct)
chunhan
parents:
diff changeset
   178
  case (pbs1 p s)
chunhan
parents:
diff changeset
   179
  thus ?case by simp
chunhan
parents:
diff changeset
   180
next
chunhan
parents:
diff changeset
   181
  case (pbs2 s p path p' h p'')
chunhan
parents:
diff changeset
   182
  assume p1:"path_by_shm s p path p'" and p2: "set (map Fst path) - {p} = set (map Trd path) - {p'}"
chunhan
parents:
diff changeset
   183
    and p3: "one_flow_shm s h p' p''" and p4: "p'' \<notin> set (map Fst path)" 
chunhan
parents:
diff changeset
   184
  show "set (map Fst ((p', h, p'') # path)) - {p} = set (map Trd ((p', h, p'') # path)) - {p''}"
chunhan
parents:
diff changeset
   185
    (is "?left = ?right")
chunhan
parents:
diff changeset
   186
  proof (cases "path = []")
chunhan
parents:
diff changeset
   187
    case True
chunhan
parents:
diff changeset
   188
    with p1 have "p = p'" by (drule_tac pbs_prop2, simp)
chunhan
parents:
diff changeset
   189
    thus ?thesis using True
chunhan
parents:
diff changeset
   190
      using p2 by (simp)
chunhan
parents:
diff changeset
   191
  next
chunhan
parents:
diff changeset
   192
    case False
chunhan
parents:
diff changeset
   193
    with p1 have a1: "p \<noteq> p'" by (drule_tac pbs_prop2, simp)
chunhan
parents:
diff changeset
   194
    from p3 have a2: "p' \<noteq> p''" by (simp add:one_flow_shm_def)
chunhan
parents:
diff changeset
   195
    from p1 False have a3: "p' \<in> set (map Trd path)" by (drule_tac pbs_prop4, simp+)
chunhan
parents:
diff changeset
   196
    from p4 p1 False have a4: "p \<noteq> p''" by (drule_tac pbs_prop3, auto)
chunhan
parents:
diff changeset
   197
    with p2 a2 p4 have a5: "p'' \<notin> set (map Trd path)" by auto
chunhan
parents:
diff changeset
   198
    
chunhan
parents:
diff changeset
   199
    have "?left = (set (map Fst path) - {p}) \<union> {p'}" using a1 by auto
chunhan
parents:
diff changeset
   200
    moreover have "... = (set (map Trd path) - {p'}) \<union> {p'}"  
chunhan
parents:
diff changeset
   201
      using p2 by auto
chunhan
parents:
diff changeset
   202
    moreover have "... = set (map Trd path)" using a3 by auto
chunhan
parents:
diff changeset
   203
    moreover have "... = set (map Trd path) - {p''}" using a5 by simp
chunhan
parents:
diff changeset
   204
    moreover have "... = ?right" by simp
chunhan
parents:
diff changeset
   205
    ultimately show ?thesis by simp
chunhan
parents:
diff changeset
   206
  qed
chunhan
parents:
diff changeset
   207
qed
chunhan
parents:
diff changeset
   208
chunhan
parents:
diff changeset
   209
lemma pbs_prop9_aux[rule_format]:
chunhan
parents:
diff changeset
   210
  "path_by_shm s p path p' \<Longrightarrow> h \<in> set (map Snd path) \<and> valid s \<longrightarrow> (\<exists> pa pb patha pathb. path_by_shm s p patha pa \<and> path_by_shm s pb pathb p' \<and> one_flow_shm s h pa pb \<and> path = pathb @ [(pa, h, pb)] @ patha \<and> h \<notin> set (map Snd patha))"
chunhan
parents:
diff changeset
   211
apply (erule path_by_shm.induct, simp)
chunhan
parents:
diff changeset
   212
apply (rule impI, case_tac "h \<in> set (map Snd path)", simp_all)
chunhan
parents:
diff changeset
   213
apply (erule exE|erule conjE)+
chunhan
parents:
diff changeset
   214
apply (rule_tac x = pa in exI, rule_tac x = pb in exI, rule_tac x = patha in exI, simp)
chunhan
parents:
diff changeset
   215
apply (rule pbs2, auto)
chunhan
parents:
diff changeset
   216
apply (rule_tac x = p' in exI, rule_tac x = p'' in exI, rule_tac x = path in exI, simp)
chunhan
parents:
diff changeset
   217
apply (rule pbs1, clarsimp simp:one_flow_shm_def procs_of_shm_prop2)
chunhan
parents:
diff changeset
   218
done
chunhan
parents:
diff changeset
   219
chunhan
parents:
diff changeset
   220
lemma pbs_prop9:
chunhan
parents:
diff changeset
   221
  "\<lbrakk>h \<in> set (map Snd path); path_by_shm s p path p'; valid s\<rbrakk>
chunhan
parents:
diff changeset
   222
   \<Longrightarrow> \<exists> pa pb patha pathb. path_by_shm s p patha pa \<and> path_by_shm s pb pathb p' \<and> 
chunhan
parents:
diff changeset
   223
        one_flow_shm s h pa pb \<and> path = pathb @ [(pa, h, pb)] @ patha \<and> h \<notin> set (map Snd patha)"
chunhan
parents:
diff changeset
   224
by (rule pbs_prop9_aux, auto)
chunhan
parents:
diff changeset
   225
chunhan
parents:
diff changeset
   226
lemma path_by_shm_trans_aux[rule_format]:
chunhan
parents:
diff changeset
   227
  "path_by_shm s p' path' p'' \<Longrightarrow> valid s \<longrightarrow> (\<forall> p path. path_by_shm s p path p' \<longrightarrow> (\<exists> path''. path_by_shm s p path'' p''))"
chunhan
parents:
diff changeset
   228
proof (induct rule:path_by_shm.induct)
chunhan
parents:
diff changeset
   229
  case (pbs1 p s)
chunhan
parents:
diff changeset
   230
  thus ?case
chunhan
parents:
diff changeset
   231
    by (clarify, rule_tac x = path in exI, simp)
chunhan
parents:
diff changeset
   232
next
chunhan
parents:
diff changeset
   233
  case (pbs2 s p path p' h p'')
chunhan
parents:
diff changeset
   234
  hence p1: "path_by_shm s p path p'" and p2: "one_flow_shm s h p' p''" 
chunhan
parents:
diff changeset
   235
    and p3: "valid s \<longrightarrow> (\<forall>pa path. path_by_shm s pa path p \<longrightarrow> (\<exists>path''. path_by_shm s pa path'' p'))"
chunhan
parents:
diff changeset
   236
    and p4: "p'' \<notin> set (map Fst path)" by auto
chunhan
parents:
diff changeset
   237
  show ?case
chunhan
parents:
diff changeset
   238
  proof clarify
chunhan
parents:
diff changeset
   239
    fix pa path'
chunhan
parents:
diff changeset
   240
    assume p5: "path_by_shm s pa path' p" and p6: "valid s"
chunhan
parents:
diff changeset
   241
    with p3 obtain path'' where a1: "path_by_shm s pa path'' p'" by auto
chunhan
parents:
diff changeset
   242
    have p3': "\<forall>pa path. path_by_shm s pa path p \<longrightarrow> (\<exists>path''. path_by_shm s pa path'' p')" 
chunhan
parents:
diff changeset
   243
      using p3 p6 by simp
chunhan
parents:
diff changeset
   244
    show "\<exists>path''. path_by_shm s pa path'' p''"
chunhan
parents:
diff changeset
   245
    proof (cases "p'' \<in> set (map Fst path'')")
chunhan
parents:
diff changeset
   246
      case True
chunhan
parents:
diff changeset
   247
      then obtain res where "path_by_shm s pa res p''" using a1 pbs_prop6 p6 by blast
chunhan
parents:
diff changeset
   248
      thus ?thesis by auto
chunhan
parents:
diff changeset
   249
    next
chunhan
parents:
diff changeset
   250
      case False
chunhan
parents:
diff changeset
   251
      with p2 a1 show ?thesis 
chunhan
parents:
diff changeset
   252
        apply (rule_tac x = "(p', h, p'') # path''" in exI)
chunhan
parents:
diff changeset
   253
        apply (rule path_by_shm.intros(2), auto)
chunhan
parents:
diff changeset
   254
        done
chunhan
parents:
diff changeset
   255
    qed
chunhan
parents:
diff changeset
   256
  qed
chunhan
parents:
diff changeset
   257
qed
chunhan
parents:
diff changeset
   258
chunhan
parents:
diff changeset
   259
lemma path_by_shm_trans:
chunhan
parents:
diff changeset
   260
  "\<lbrakk>path_by_shm s p path p'; path_by_shm s p' path' p''; valid s\<rbrakk> \<Longrightarrow> \<exists> path''. path_by_shm s p path'' p''"
chunhan
parents:
diff changeset
   261
by (drule_tac p' = p' and p'' = p'' in path_by_shm_trans_aux, auto)
chunhan
parents:
diff changeset
   262
chunhan
parents:
diff changeset
   263
lemma path_by_shm_intro1_prop:
chunhan
parents:
diff changeset
   264
  "\<not> path_by_shm s p [] p \<Longrightarrow> p \<notin> current_procs s"
chunhan
parents:
diff changeset
   265
by (auto dest:path_by_shm.intros(1))
chunhan
parents:
diff changeset
   266
chunhan
parents:
diff changeset
   267
lemma path_by_shm_intro3:
chunhan
parents:
diff changeset
   268
  "\<lbrakk>path_by_shm s p path from; (from, SHM_RDWR) \<in> procs_of_shm s h; (to, flag) \<in> procs_of_shm s h; 
chunhan
parents:
diff changeset
   269
    to \<notin> set (map Fst path); from \<noteq> to\<rbrakk>
chunhan
parents:
diff changeset
   270
   \<Longrightarrow> path_by_shm s p ((from, h, to)#path) to"
chunhan
parents:
diff changeset
   271
apply (rule path_by_shm.intros(2), simp_all)
chunhan
parents:
diff changeset
   272
by (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   273
chunhan
parents:
diff changeset
   274
lemma path_by_shm_intro4:
chunhan
parents:
diff changeset
   275
  "\<lbrakk>(p, flag) \<in> procs_of_shm s h; valid s\<rbrakk> \<Longrightarrow> path_by_shm s p [] p"
chunhan
parents:
diff changeset
   276
by (drule procs_of_shm_prop2, simp, simp add:path_by_shm.intros(1))
chunhan
parents:
diff changeset
   277
chunhan
parents:
diff changeset
   278
lemma path_by_shm_intro5:
chunhan
parents:
diff changeset
   279
  "\<lbrakk>(from, SHM_RDWR) \<in> procs_of_shm s h; (to,flag) \<in> procs_of_shm s h; valid s; from \<noteq> to\<rbrakk>
chunhan
parents:
diff changeset
   280
   \<Longrightarrow> path_by_shm s from [(from, h, to)] to"
chunhan
parents:
diff changeset
   281
apply (rule_tac p' = "from" and h = h in path_by_shm.intros(2))
chunhan
parents:
diff changeset
   282
apply (rule path_by_shm.intros(1), simp add:procs_of_shm_prop2)
chunhan
parents:
diff changeset
   283
apply (simp add:one_flow_shm_def, rule_tac x = flag in exI, auto)
chunhan
parents:
diff changeset
   284
done
chunhan
parents:
diff changeset
   285
chunhan
parents:
diff changeset
   286
(* p'' \<notin> set (map Fst path): not duplicated target process;
chunhan
parents:
diff changeset
   287
 * p1 - ha \<rightarrow> p2; p2 - hb \<rightarrow> p3; p3 - ha \<rightarrow> p4; so path_by_shm p1 [(p3,ha,p4), (p2,hb,p3),(p1,ha,p2)] p4,
chunhan
parents:
diff changeset
   288
 * but this could be also path_by_shm p1 [(p1,ha,p4)] p4, so the former one is redundant!  *)
chunhan
parents:
diff changeset
   289
chunhan
parents:
diff changeset
   290
inductive path_by_shm':: "t_state \<Rightarrow> t_process \<Rightarrow> t_edge_shm list \<Rightarrow> t_process \<Rightarrow> bool"
chunhan
parents:
diff changeset
   291
where
chunhan
parents:
diff changeset
   292
  pbs1': "p \<in> current_procs s \<Longrightarrow> path_by_shm' s p [] p"
chunhan
parents:
diff changeset
   293
| pbs2': "\<lbrakk>path_by_shm' s p path p'; one_flow_shm s h p' p''; p'' \<notin> set (map Fst path); 
chunhan
parents:
diff changeset
   294
           h \<notin> set (map Snd path)\<rbrakk> 
chunhan
parents:
diff changeset
   295
          \<Longrightarrow> path_by_shm' s p ((p', h, p'')# path) p''"
chunhan
parents:
diff changeset
   296
chunhan
parents:
diff changeset
   297
lemma pbs_prop10:
chunhan
parents:
diff changeset
   298
  "\<lbrakk>path_by_shm s p path p'; one_flow_shm s h p' p''; valid s\<rbrakk> \<Longrightarrow> \<exists>path'. path_by_shm s p path' p''"
chunhan
parents:
diff changeset
   299
apply (case_tac "p'' \<in> set (map Fst path)")
chunhan
parents:
diff changeset
   300
apply (drule_tac pb = p'' in pbs_prop6, simp+)
chunhan
parents:
diff changeset
   301
apply ((erule exE|erule conjE)+, rule_tac x = pathab in exI, simp)
chunhan
parents:
diff changeset
   302
apply (rule_tac x = "(p', h, p'') # path" in exI)
chunhan
parents:
diff changeset
   303
apply (erule pbs2, simp+)
chunhan
parents:
diff changeset
   304
done
chunhan
parents:
diff changeset
   305
chunhan
parents:
diff changeset
   306
lemma pbs'_imp_pbs[rule_format]:
chunhan
parents:
diff changeset
   307
  "path_by_shm' s p path p' \<Longrightarrow> valid s \<longrightarrow> (\<exists> path'. path_by_shm s p path' p')"
chunhan
parents:
diff changeset
   308
apply (erule path_by_shm'.induct)
chunhan
parents:
diff changeset
   309
apply (rule impI, rule_tac x = "[]" in exI, simp add:pbs1)
chunhan
parents:
diff changeset
   310
apply (rule impI, clarsimp)
chunhan
parents:
diff changeset
   311
apply (erule pbs_prop10, simp+)
chunhan
parents:
diff changeset
   312
done
chunhan
parents:
diff changeset
   313
chunhan
parents:
diff changeset
   314
lemma pbs_imp_pbs'[rule_format]:
chunhan
parents:
diff changeset
   315
  "path_by_shm s p path p' \<Longrightarrow> valid s \<longrightarrow> (\<exists> path'. path_by_shm' s p path' p')"
chunhan
parents:
diff changeset
   316
apply (erule path_by_shm.induct)
chunhan
parents:
diff changeset
   317
apply (rule impI, rule_tac x = "[]" in exI, erule pbs1')
chunhan
parents:
diff changeset
   318
apply (rule impI, simp, erule exE) (*
chunhan
parents:
diff changeset
   319
apply ( erule exE, case_tac "h \<in> set (map Snd path)")
chunhan
parents:
diff changeset
   320
apply (drule_tac s = s and p = p and p' = p' in pbs_prop9, simp+) defer
chunhan
parents:
diff changeset
   321
apply (rule_tac x = "(p', h, p'') # path'" in exI)
chunhan
parents:
diff changeset
   322
apply (erule pbs2', simp+) 
chunhan
parents:
diff changeset
   323
apply ((erule exE|erule conjE)+)
chunhan
parents:
diff changeset
   324
apply (rule_tac x = "(pa, h, p'') # patha" in exI)
chunhan
parents:
diff changeset
   325
apply (erule pbs2', auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   326
done*)
chunhan
parents:
diff changeset
   327
sorry
chunhan
parents:
diff changeset
   328
chunhan
parents:
diff changeset
   329
chunhan
parents:
diff changeset
   330
lemma pbs'_eq_pbs:
chunhan
parents:
diff changeset
   331
  "valid s \<Longrightarrow> (\<exists> path'. path_by_shm' s p path' p') = (\<exists> path. path_by_shm s p path p')"
chunhan
parents:
diff changeset
   332
by (rule iffI, auto intro:pbs_imp_pbs' pbs'_imp_pbs)
chunhan
parents:
diff changeset
   333
chunhan
parents:
diff changeset
   334
definition flow_by_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool"
chunhan
parents:
diff changeset
   335
where
chunhan
parents:
diff changeset
   336
  "flow_by_shm s p p' \<equiv> \<exists> path. path_by_shm s p path p'"
chunhan
parents:
diff changeset
   337
chunhan
parents:
diff changeset
   338
lemma flow_by_shm_intro':
chunhan
parents:
diff changeset
   339
  "valid s \<Longrightarrow> flow_by_shm s p p' = (\<exists> path. path_by_shm' s p path p')"
chunhan
parents:
diff changeset
   340
by (auto simp:flow_by_shm_def pbs'_eq_pbs)
chunhan
parents:
diff changeset
   341
chunhan
parents:
diff changeset
   342
lemma one_step_flows: "\<lbrakk>one_flow_shm s h p p'; valid s\<rbrakk> \<Longrightarrow> flow_by_shm s p p'"
chunhan
parents:
diff changeset
   343
by (drule one_step_path, auto simp:flow_by_shm_def)
chunhan
parents:
diff changeset
   344
chunhan
parents:
diff changeset
   345
lemma flow_by_shm_trans:
chunhan
parents:
diff changeset
   346
  "\<lbrakk>flow_by_shm s p p'; flow_by_shm s p' p''; valid s\<rbrakk> \<Longrightarrow> flow_by_shm s p p''"
chunhan
parents:
diff changeset
   347
by (auto simp:flow_by_shm_def intro!:path_by_shm_trans)
chunhan
parents:
diff changeset
   348
chunhan
parents:
diff changeset
   349
lemma flow_by_shm_intro1_prop:
chunhan
parents:
diff changeset
   350
  "\<not> flow_by_shm s p p \<Longrightarrow> p \<notin> current_procs s"
chunhan
parents:
diff changeset
   351
by (auto dest:path_by_shm.intros(1) simp:flow_by_shm_def)
chunhan
parents:
diff changeset
   352
chunhan
parents:
diff changeset
   353
lemma flow_by_shm_intro1:
chunhan
parents:
diff changeset
   354
  "p \<in> current_procs s \<Longrightarrow> flow_by_shm s p p"
chunhan
parents:
diff changeset
   355
by (auto dest:path_by_shm.intros(1) simp:flow_by_shm_def)
chunhan
parents:
diff changeset
   356
chunhan
parents:
diff changeset
   357
lemma flow_by_shm_intro2:
chunhan
parents:
diff changeset
   358
  "\<lbrakk>flow_by_shm s p p'; one_flow_shm s h p' p''; valid s\<rbrakk> \<Longrightarrow> flow_by_shm s p p''"
chunhan
parents:
diff changeset
   359
by (auto intro:flow_by_shm_trans dest:one_step_flows)
chunhan
parents:
diff changeset
   360
chunhan
parents:
diff changeset
   361
lemma flow_by_shm_intro3:
chunhan
parents:
diff changeset
   362
  "\<lbrakk>flow_by_shm s p from; (from, SHM_RDWR) \<in> procs_of_shm s h; (to, flag) \<in> procs_of_shm s h; from \<noteq> to; valid s\<rbrakk>
chunhan
parents:
diff changeset
   363
   \<Longrightarrow> flow_by_shm s p to"
chunhan
parents:
diff changeset
   364
apply (rule flow_by_shm_intro2)
chunhan
parents:
diff changeset
   365
by (auto simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   366
chunhan
parents:
diff changeset
   367
lemma flow_by_shm_intro4:
chunhan
parents:
diff changeset
   368
  "\<lbrakk>(p, flag) \<in> procs_of_shm s h; valid s\<rbrakk> \<Longrightarrow> flow_by_shm s p p"
chunhan
parents:
diff changeset
   369
by (drule procs_of_shm_prop2, simp, simp add:flow_by_shm_intro1)
chunhan
parents:
diff changeset
   370
chunhan
parents:
diff changeset
   371
lemma flow_by_shm_intro5:
chunhan
parents:
diff changeset
   372
  "\<lbrakk>(from, SHM_RDWR) \<in> procs_of_shm s h; (to,flag) \<in> procs_of_shm s h; valid s; from \<noteq> to\<rbrakk>
chunhan
parents:
diff changeset
   373
   \<Longrightarrow> flow_by_shm s from  to"
chunhan
parents:
diff changeset
   374
apply (rule_tac p' = "from" and h = h in flow_by_shm_intro2)
chunhan
parents:
diff changeset
   375
apply (rule flow_by_shm_intro1, simp add:procs_of_shm_prop2)
chunhan
parents:
diff changeset
   376
apply (simp add:one_flow_shm_def, rule_tac x = flag in exI, auto)
chunhan
parents:
diff changeset
   377
done
chunhan
parents:
diff changeset
   378
chunhan
parents:
diff changeset
   379
lemma flow_by_shm_intro6:
chunhan
parents:
diff changeset
   380
  "path_by_shm s p path p' \<Longrightarrow> flow_by_shm s p p'"
chunhan
parents:
diff changeset
   381
by (auto simp:flow_by_shm_def)
chunhan
parents:
diff changeset
   382
chunhan
parents:
diff changeset
   383
(********* simpset for inductive Info_flow_shm **********)
chunhan
parents:
diff changeset
   384
lemma path_by_shm_detach1_aux:
chunhan
parents:
diff changeset
   385
  "path_by_shm s' pa path pb \<Longrightarrow> valid (Detach p h # s) \<and> (s' = Detach p h # s) 
chunhan
parents:
diff changeset
   386
     \<longrightarrow> \<not> edge_related path p h \<and> path_by_shm s pa path pb"
chunhan
parents:
diff changeset
   387
apply (erule path_by_shm.induct, simp)
chunhan
parents:
diff changeset
   388
apply (rule impI, rule path_by_shm.intros(1), simp+)
chunhan
parents:
diff changeset
   389
by (auto simp:one_flow_shm_def split:if_splits intro:path_by_shm_intro3)
chunhan
parents:
diff changeset
   390
chunhan
parents:
diff changeset
   391
lemma path_by_shm_detach1:
chunhan
parents:
diff changeset
   392
  "\<lbrakk>path_by_shm (Detach p h # s) pa path pb; valid (Detach p h # s)\<rbrakk> 
chunhan
parents:
diff changeset
   393
   \<Longrightarrow> \<not> edge_related path p h \<and> path_by_shm s pa path pb"
chunhan
parents:
diff changeset
   394
by (auto dest:path_by_shm_detach1_aux)
chunhan
parents:
diff changeset
   395
chunhan
parents:
diff changeset
   396
lemma path_by_shm_detach2_aux[rule_format]:
chunhan
parents:
diff changeset
   397
  "path_by_shm s pa path pb \<Longrightarrow> valid (Detach p h # s) \<and> \<not> edge_related path p h 
chunhan
parents:
diff changeset
   398
   \<longrightarrow> path_by_shm (Detach p h # s) pa path pb"
chunhan
parents:
diff changeset
   399
apply (induct rule:path_by_shm.induct)
chunhan
parents:
diff changeset
   400
apply (rule impI, rule path_by_shm.intros(1), simp)
chunhan
parents:
diff changeset
   401
apply (rule impI, erule conjE, simp split:if_splits)
chunhan
parents:
diff changeset
   402
apply (rule path_by_shm.intros(2), simp)
chunhan
parents:
diff changeset
   403
apply (simp add:one_flow_shm_detach)
chunhan
parents:
diff changeset
   404
apply (rule impI, simp+)
chunhan
parents:
diff changeset
   405
done
chunhan
parents:
diff changeset
   406
chunhan
parents:
diff changeset
   407
lemma path_by_shm_detach2:
chunhan
parents:
diff changeset
   408
  "\<lbrakk>valid (Detach p h # s); \<not> edge_related path p h; path_by_shm s pa path pb\<rbrakk> 
chunhan
parents:
diff changeset
   409
   \<Longrightarrow> path_by_shm (Detach p h # s) pa path pb"
chunhan
parents:
diff changeset
   410
by (auto intro!:path_by_shm_detach2_aux)
chunhan
parents:
diff changeset
   411
chunhan
parents:
diff changeset
   412
lemma path_by_shm_detach:
chunhan
parents:
diff changeset
   413
  "valid (Detach p h # s) \<Longrightarrow>
chunhan
parents:
diff changeset
   414
   path_by_shm (Detach p h # s) pa path pb = (\<not> edge_related path p h  \<and> path_by_shm s pa path pb)"
chunhan
parents:
diff changeset
   415
by (auto dest:path_by_shm_detach1 path_by_shm_detach2)
chunhan
parents:
diff changeset
   416
chunhan
parents:
diff changeset
   417
lemma flow_by_shm_detach:
chunhan
parents:
diff changeset
   418
  "valid (Detach p h # s) \<Longrightarrow> 
chunhan
parents:
diff changeset
   419
   flow_by_shm (Detach p h # s) pa pb = (\<exists> path. \<not> edge_related path p h \<and> path_by_shm s pa path pb)"
chunhan
parents:
diff changeset
   420
by (auto dest:path_by_shm_detach simp:flow_by_shm_def)
chunhan
parents:
diff changeset
   421
chunhan
parents:
diff changeset
   422
lemma path_by_shm'_attach1_aux:
chunhan
parents:
diff changeset
   423
  "path_by_shm' s' pa path pb \<Longrightarrow> valid s' \<and> (s' = Attach p h flag # s) \<longrightarrow>
chunhan
parents:
diff changeset
   424
     (path_by_shm' s pa path pb) \<or>
chunhan
parents:
diff changeset
   425
     (\<exists> path1 path2 p'. path_by_shm' s pa path1 p' \<and> path_by_shm' s p path2 pb \<and> 
chunhan
parents:
diff changeset
   426
         (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path = path2 @ [(p', h, p)] @ path1 ) \<or>
chunhan
parents:
diff changeset
   427
     (\<exists> path1 path2 p' flag'. path_by_shm' s pa path1 p \<and> path_by_shm' s p' path2 pb \<and> 
chunhan
parents:
diff changeset
   428
         (p', flag') \<in> procs_of_shm s h \<and> path = path2 @ [(p, h, p')] @ path1 \<and> flag = SHM_RDWR)"
chunhan
parents:
diff changeset
   429
apply (erule path_by_shm'.induct)
chunhan
parents:
diff changeset
   430
apply (simp, rule impI, rule pbs1', simp)
chunhan
parents:
diff changeset
   431
apply (rule impI, erule impE, clarsimp)
chunhan
parents:
diff changeset
   432
apply (erule disjE)
chunhan
parents:
diff changeset
   433
apply (clarsimp simp:one_flow_shm_attach split:if_splits)
chunhan
parents:
diff changeset
   434
apply (erule disjE, clarsimp)
chunhan
parents:
diff changeset
   435
apply (erule_tac x = path in allE, clarsimp)
chunhan
parents:
diff changeset
   436
apply (erule impE, rule pbs1', erule procs_of_shm_prop2, erule vd_cons, simp)
chunhan
parents:
diff changeset
   437
apply (erule disjE, clarsimp)
chunhan
parents:
diff changeset
   438
apply (rule_tac x = path in exI, rule_tac x = "[]" in exI, rule_tac x = p' in exI, simp)
chunhan
parents:
diff changeset
   439
apply (rule pbs1', drule vt_grant_os, clarsimp)
chunhan
parents:
diff changeset
   440
apply (drule_tac p = pa and p' = p' and p'' = p'' in pbs2', simp+)
chunhan
parents:
diff changeset
   441
apply (drule_tac p = pa and p' = p' and p'' = p'' in pbs2', simp+)
chunhan
parents:
diff changeset
   442
chunhan
parents:
diff changeset
   443
apply (erule disjE)
chunhan
parents:
diff changeset
   444
apply ((erule exE|erule conjE)+, clarsimp split:if_splits simp:one_flow_shm_attach)
chunhan
parents:
diff changeset
   445
apply (clarsimp simp:one_flow_shm_attach split:if_splits)
chunhan
parents:
diff changeset
   446
apply (erule disjE, clarsimp)
chunhan
parents:
diff changeset
   447
apply (clarsimp)
chunhan
parents:
diff changeset
   448
chunhan
parents:
diff changeset
   449
chunhan
parents:
diff changeset
   450
apply (erule conjE)+
chunhan
parents:
diff changeset
   451
chunhan
parents:
diff changeset
   452
chunhan
parents:
diff changeset
   453
chunhan
parents:
diff changeset
   454
apply (erule conjE, clarsimp simp only:one_flow_shm_attach split:if_splits)
chunhan
parents:
diff changeset
   455
apply simp
chunhan
parents:
diff changeset
   456
chunhan
parents:
diff changeset
   457
chunhan
parents:
diff changeset
   458
chunhan
parents:
diff changeset
   459
lemma path_by_shm_attach1_aux:
chunhan
parents:
diff changeset
   460
  "path_by_shm s' pa path pb \<Longrightarrow> valid s' \<and> (s' = Attach p h flag # s) \<longrightarrow> 
chunhan
parents:
diff changeset
   461
     path_by_shm s pa path pb \<or>
chunhan
parents:
diff changeset
   462
      (if (pa = p \<and> flag = SHM_RDWR)
chunhan
parents:
diff changeset
   463
       then \<exists> p' flagb path'. (p', flagb) \<in> procs_of_shm s h \<and> 
chunhan
parents:
diff changeset
   464
               path_by_shm s p' path' pb \<and> path = path' @ [(p, h, p')]
chunhan
parents:
diff changeset
   465
       else if (pb = p)
chunhan
parents:
diff changeset
   466
            then \<exists> p' path'. path_by_shm s pa path' p' \<and> path = (p', h, p) # path' \<and> 
chunhan
parents:
diff changeset
   467
                   (p', SHM_RDWR) \<in> procs_of_shm s h
chunhan
parents:
diff changeset
   468
            else (\<exists> p' flag' patha pathb. path_by_shm s pa patha p \<and> flag = SHM_RDWR \<and> 
chunhan
parents:
diff changeset
   469
                   (p', flag') \<in> procs_of_shm s h \<and> path_by_shm s p' pathb pb \<and> 
chunhan
parents:
diff changeset
   470
                   path = pathb @ [(p, h, p')] @ patha) \<or>
chunhan
parents:
diff changeset
   471
                 (\<exists> p' patha pathb. path_by_shm s pa patha p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and> 
chunhan
parents:
diff changeset
   472
                   path_by_shm s p pathb pb \<and> path = pathb @ [(p', h, p)] @ patha))"
chunhan
parents:
diff changeset
   473
proof (induct rule:path_by_shm.induct)
chunhan
parents:
diff changeset
   474
  case (pbs1 proc \<tau>)
chunhan
parents:
diff changeset
   475
  show ?case
chunhan
parents:
diff changeset
   476
  proof (rule impI)
chunhan
parents:
diff changeset
   477
    assume pre: "valid \<tau> \<and> \<tau> = Attach p h flag # s"
chunhan
parents:
diff changeset
   478
    from pbs1 pre have "proc \<in> current_procs s" by simp 
chunhan
parents:
diff changeset
   479
    thus "path_by_shm s proc [] proc \<or>
chunhan
parents:
diff changeset
   480
         (if proc = p \<and> flag = SHM_RDWR
chunhan
parents:
diff changeset
   481
          then \<exists>p' flagb path'.
chunhan
parents:
diff changeset
   482
                  (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' path' proc \<and> [] = path' @ [(p, h, p')]
chunhan
parents:
diff changeset
   483
          else if proc = p
chunhan
parents:
diff changeset
   484
               then \<exists>p' path'.
chunhan
parents:
diff changeset
   485
                       path_by_shm s proc path' p' \<and> [] = (p', h, p) # path' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h
chunhan
parents:
diff changeset
   486
               else (\<exists>p' flag' patha pathb.
chunhan
parents:
diff changeset
   487
                        path_by_shm s proc patha p \<and>
chunhan
parents:
diff changeset
   488
                        flag = SHM_RDWR \<and>
chunhan
parents:
diff changeset
   489
                        (p', flag') \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   490
                        path_by_shm s p' pathb proc \<and> [] = pathb @ [(p, h, p')] @ patha) \<or>
chunhan
parents:
diff changeset
   491
                    (\<exists>p' patha pathb.
chunhan
parents:
diff changeset
   492
                        path_by_shm s proc patha p' \<and>
chunhan
parents:
diff changeset
   493
                        (p', SHM_RDWR) \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   494
                        path_by_shm s p pathb proc \<and> [] = pathb @ [(p', h, p)] @ patha))"
chunhan
parents:
diff changeset
   495
      by (auto intro:path_by_shm.intros)
chunhan
parents:
diff changeset
   496
  qed
chunhan
parents:
diff changeset
   497
next
chunhan
parents:
diff changeset
   498
  case (pbs2 \<tau> pa path pb h' pc)
chunhan
parents:
diff changeset
   499
  thus ?case
chunhan
parents:
diff changeset
   500
  proof (rule_tac impI)
chunhan
parents:
diff changeset
   501
    assume p1:"path_by_shm \<tau> pa path pb" and p2: "valid \<tau> \<and> \<tau> = Attach p h flag # s \<longrightarrow>
chunhan
parents:
diff changeset
   502
     path_by_shm s pa path pb \<or>
chunhan
parents:
diff changeset
   503
     (if pa = p \<and> flag = SHM_RDWR
chunhan
parents:
diff changeset
   504
      then \<exists>p' flagb path'. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' path' pb \<and> path = path' @ [(p, h, p')]
chunhan
parents:
diff changeset
   505
      else if pb = p
chunhan
parents:
diff changeset
   506
           then \<exists>p' path'. path_by_shm s pa path' p' \<and> path = (p', h, p) # path' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h
chunhan
parents:
diff changeset
   507
           else (\<exists>p' flag' pathaa pathb. path_by_shm s pa pathaa p \<and> flag = SHM_RDWR \<and> 
chunhan
parents:
diff changeset
   508
                    (p', flag') \<in> procs_of_shm s h \<and> path_by_shm s p' pathb pb \<and> 
chunhan
parents:
diff changeset
   509
                    path = pathb @ [(p, h, p')] @ pathaa) \<or>
chunhan
parents:
diff changeset
   510
                (\<exists>p' pathaa pathb. path_by_shm s pa pathaa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   511
                    path_by_shm s p pathb pb \<and> path = pathb @ [(p', h, p)] @ pathaa))"
chunhan
parents:
diff changeset
   512
      and p3: "one_flow_shm \<tau> h' pb pc" and p4: "valid \<tau> \<and> \<tau> = Attach p h flag # s"
chunhan
parents:
diff changeset
   513
    
chunhan
parents:
diff changeset
   514
    from p2 and p4 have p2': "
chunhan
parents:
diff changeset
   515
      path_by_shm s pa path pb \<or>
chunhan
parents:
diff changeset
   516
     (if pa = p \<and> flag = SHM_RDWR
chunhan
parents:
diff changeset
   517
      then \<exists>p' flagb path'. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' path' pb \<and> path = path' @ [(p, h, p')]
chunhan
parents:
diff changeset
   518
      else if pb = p
chunhan
parents:
diff changeset
   519
           then \<exists>p' path'. path_by_shm s pa path' p' \<and> path = (p', h, p) # path' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h
chunhan
parents:
diff changeset
   520
           else (\<exists>p' flag' pathaa pathb. path_by_shm s pa pathaa p \<and> flag = SHM_RDWR \<and> 
chunhan
parents:
diff changeset
   521
                    (p', flag') \<in> procs_of_shm s h \<and> path_by_shm s p' pathb pb \<and> 
chunhan
parents:
diff changeset
   522
                    path = pathb @ [(p, h, p')] @ pathaa) \<or>
chunhan
parents:
diff changeset
   523
                (\<exists>p' pathaa pathb. path_by_shm s pa pathaa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   524
                    path_by_shm s p pathb pb \<and> path = pathb @ [(p', h, p)] @ pathaa))"
chunhan
parents:
diff changeset
   525
      by (erule_tac impE, simp)
chunhan
parents:
diff changeset
   526
    from p4 have p5: "valid s" and p6: "os_grant s (Attach p h flag)" by (auto intro:vd_cons dest:vt_grant_os)
chunhan
parents:
diff changeset
   527
    from p6 have "p \<in> current_procs s" by simp hence p7:"path_by_shm s p [] p" by (erule_tac path_by_shm.intros)
chunhan
parents:
diff changeset
   528
    from p3 p4 have p8: "if (h' = h) 
chunhan
parents:
diff changeset
   529
     then (pb = p \<and> pc \<noteq> p \<and> flag = SHM_RDWR \<and> (\<exists> flagb. (pc, flagb) \<in> procs_of_shm s h)) \<or>
chunhan
parents:
diff changeset
   530
          (pc = p \<and> pb \<noteq> p \<and> (pb, SHM_RDWR) \<in> procs_of_shm s h) \<or>
chunhan
parents:
diff changeset
   531
          (one_flow_shm s h pb pc)               
chunhan
parents:
diff changeset
   532
     else one_flow_shm s h' pb pc" by (auto simp add:one_flow_shm_attach) 
chunhan
parents:
diff changeset
   533
    
chunhan
parents:
diff changeset
   534
    
chunhan
parents:
diff changeset
   535
(*
chunhan
parents:
diff changeset
   536
    have "\<And> flagb. (pc, flagb) \<in> procs_of_shm s h 
chunhan
parents:
diff changeset
   537
      \<Longrightarrow> \<exists> p' flagb. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' [] pc"
chunhan
parents:
diff changeset
   538
      apply (rule_tac x= pc in exI, rule_tac x = flagb in exI, frule procs_of_shm_prop2)
chunhan
parents:
diff changeset
   539
      by (simp add:p5, simp add:path_by_shm.intros(1))
chunhan
parents:
diff changeset
   540
    hence p10: "\<not> path_by_shm s p path pc \<Longrightarrow> (\<exists>p' flagb. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p'  pc) \<or>
chunhan
parents:
diff changeset
   541
      path_by_shm s pa pc"
chunhan
parents:
diff changeset
   542
      using p2' p7 p8 p5
chunhan
parents:
diff changeset
   543
      by (auto split:if_splits dest:path_by_shm.intros(2))      
chunhan
parents:
diff changeset
   544
  (*     apply (rule_tac x = pb in exI, simp add:one_flow_flows, rule_tac x = flagb in exI, simp)+  *) *)
chunhan
parents:
diff changeset
   545
chunhan
parents:
diff changeset
   546
    from p1 have a0: "(path = []) = (pa = pb)" using pbs_prop2 by simp
chunhan
parents:
diff changeset
   547
    have a1:"\<lbrakk>pa = p; flag = SHM_RDWR; \<not> path_by_shm s pa path pb\<rbrakk> \<Longrightarrow> 
chunhan
parents:
diff changeset
   548
      \<exists>p' flagb path'. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' path' pb \<and> path = path' @ [(p, h, p')]"
chunhan
parents:
diff changeset
   549
      using p2' by auto
chunhan
parents:
diff changeset
   550
    have b1: "\<lbrakk>pa = p; flag = SHM_RDWR; \<not> path_by_shm s pa path pc\<rbrakk> \<Longrightarrow> 
chunhan
parents:
diff changeset
   551
      \<exists>p' flagb path'. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' path' pc \<and>
chunhan
parents:
diff changeset
   552
        (pb, h', pc) # path = path' @ [(p, h, p')]"
chunhan
parents:
diff changeset
   553
      
chunhan
parents:
diff changeset
   554
      
chunhan
parents:
diff changeset
   555
      using p8 a1 p7 p5 a0 
chunhan
parents:
diff changeset
   556
      apply (auto split:if_splits elim:path_by_shm_intro4)
chunhan
parents:
diff changeset
   557
      apply (rule_tac x = pb in exI, rule conjI, rule_tac x = SHM_RDWR in exI, simp)
chunhan
parents:
diff changeset
   558
      apply (rule_tac x = pc in exI, rule conjI, rule_tac x = flagb in exI, simp)
chunhan
parents:
diff changeset
   559
      apply (rule_tac x = "[]" in exI, rule conjI)
chunhan
parents:
diff changeset
   560
apply (erule path_by_shm_intro4, simp)
chunhan
parents:
diff changeset
   561
chunhan
parents:
diff changeset
   562
      apply (case_tac "path_by_shm s pa path pb", simp) defer
chunhan
parents:
diff changeset
   563
      apply (drule a1, simp+, clarsimp)
chunhan
parents:
diff changeset
   564
      apply (rule conjI, rule_tac x = flagb in exI, simp)
chunhan
parents:
diff changeset
   565
      apply (rule path_by_shm_
chunhan
parents:
diff changeset
   566
      using p2' p8 p5
chunhan
parents:
diff changeset
   567
      apply (auto split:if_splits dest!:pbs_prop2' simp:path_by_shm_intro4)
chunhan
parents:
diff changeset
   568
      apply (drule pbs_prop2', simp)
chunhan
parents:
diff changeset
   569
      apply (erule_tac x = pc in allE, simp add:path_by_shm_intro4)
chunhan
parents:
diff changeset
   570
     
chunhan
parents:
diff changeset
   571
      apply (drule_tac x = "pc" in allE)
chunhan
parents:
diff changeset
   572
      
chunhan
parents:
diff changeset
   573
      apply simp
chunhan
parents:
diff changeset
   574
chunhan
parents:
diff changeset
   575
      sorry
chunhan
parents:
diff changeset
   576
    moreover have "pc = p \<Longrightarrow> (\<exists>p' path'. path_by_shm s pa path' p' \<and>
chunhan
parents:
diff changeset
   577
             (pb, h', pc) # path = path' @ [(p', h, p)] \<and> (p', SHM_RDWR) \<in> procs_of_shm s h) \<or>
chunhan
parents:
diff changeset
   578
      (path_by_shm s pa path pc \<and> \<not> edge_related path p h)"
chunhan
parents:
diff changeset
   579
      using p2' p7 p8 p5
chunhan
parents:
diff changeset
   580
      sorry (*
chunhan
parents:
diff changeset
   581
      apply (auto split:if_splits intro:path_by_shm_intro3 simp:one_flow_shm_def) *)
chunhan
parents:
diff changeset
   582
    moreover have "\<lbrakk>pc \<noteq> p; pa \<noteq> p \<or> flag \<noteq> SHM_RDWR\<rbrakk> \<Longrightarrow> 
chunhan
parents:
diff changeset
   583
      (\<exists>p' flag' pathaa pathb. path_by_shm s pa pathaa p \<and> flag = SHM_RDWR \<and> (p', flag') \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   584
           path_by_shm s p' pathb pc \<and> (pb, h', pc) # path = pathaa @ [(p, h, p')] @ pathb) \<or>
chunhan
parents:
diff changeset
   585
      (\<exists>p' pathaa pathb. path_by_shm s pa pathaa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   586
           path_by_shm s p pathb pc \<and> (pb, h', pc) # path = pathaa @ [(p', h, p)] @ pathb) \<or>
chunhan
parents:
diff changeset
   587
      (path_by_shm s pa path pc \<and> \<not> edge_related path p h)"
chunhan
parents:
diff changeset
   588
      using p2' p7 p8 p5 (*
chunhan
parents:
diff changeset
   589
      apply (auto split:if_splits intro:path_by_shm_intro3 simp:one_flow_shm_def)
chunhan
parents:
diff changeset
   590
      apply (rule_tac x = pc in exI, simp add:path_by_shm_intro4)
chunhan
parents:
diff changeset
   591
      apply (rule_tac x = flagb in exI, simp)      
chunhan
parents:
diff changeset
   592
      done *)
chunhan
parents:
diff changeset
   593
      sorry
chunhan
parents:
diff changeset
   594
    ultimately  
chunhan
parents:
diff changeset
   595
    show "if (pb, h', pc) # path = [] then pa = pc \<and> pa \<in> current_procs s
chunhan
parents:
diff changeset
   596
       else path_by_shm s pa ((pb, h', pc) # path) pc \<and> \<not> edge_related ((pb, h', pc) # path) p h \<or>
chunhan
parents:
diff changeset
   597
       (if pa = p \<and> flag = SHM_RDWR
chunhan
parents:
diff changeset
   598
        then \<exists>p' flagb path'. (p', flagb) \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   599
                path_by_shm s p' path' pc \<and> (pb, h', pc) # path = path' @ [(p, h, p')]
chunhan
parents:
diff changeset
   600
        else if pc = p
chunhan
parents:
diff changeset
   601
             then \<exists>p' path'. path_by_shm s pa path' p' \<and>
chunhan
parents:
diff changeset
   602
                     (pb, h', pc) # path = (p', h, p) # path' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h
chunhan
parents:
diff changeset
   603
             else (\<exists>p' flag' pathaa pathb. path_by_shm s pa pathaa p \<and> flag = SHM_RDWR \<and>
chunhan
parents:
diff changeset
   604
                      (p', flag') \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   605
                      path_by_shm s p' pathb pc \<and> (pb, h', pc) # path = pathb @ [(p, h, p')] @ pathaa) \<or>
chunhan
parents:
diff changeset
   606
                  (\<exists>p' pathaa pathb. path_by_shm s pa pathaa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and>
chunhan
parents:
diff changeset
   607
                      path_by_shm s p pathb pc \<and> (pb, h', pc) # path = pathb @ [(p', h, p)] @ pathaa))"
chunhan
parents:
diff changeset
   608
        apply (auto split:if_splits)
chunhan
parents:
diff changeset
   609
        using p7 by auto
chunhan
parents:
diff changeset
   610
  qed
chunhan
parents:
diff changeset
   611
qed
chunhan
parents:
diff changeset
   612
chunhan
parents:
diff changeset
   613
lemma path_by_shm_attach1:
chunhan
parents:
diff changeset
   614
  "\<lbrakk>valid (Attach p h flag # s); path_by_shm (Attach p h flag # s) pa pb\<rbrakk>
chunhan
parents:
diff changeset
   615
   \<Longrightarrow> (if path_by_shm s pa pb then True else
chunhan
parents:
diff changeset
   616
     (if (pa = p \<and> flag = SHM_RDWR) 
chunhan
parents:
diff changeset
   617
      then (\<exists> p' flagb. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' pb)
chunhan
parents:
diff changeset
   618
      else if (pb = p) 
chunhan
parents:
diff changeset
   619
           then (\<exists> p'. (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path_by_shm s pa p')
chunhan
parents:
diff changeset
   620
           else (\<exists> p' flag'. path_by_shm s pa p \<and> flag = SHM_RDWR \<and> (p', flag') \<in> procs_of_shm s h \<and> 
chunhan
parents:
diff changeset
   621
                             path_by_shm s p' pb) \<or>
chunhan
parents:
diff changeset
   622
                (\<exists> p'. path_by_shm s pa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path_by_shm s p pb)
chunhan
parents:
diff changeset
   623
     )  )"
chunhan
parents:
diff changeset
   624
apply (drule_tac p = p and h = h and flag = flag in path_by_shm_attach1_aux)
chunhan
parents:
diff changeset
   625
by auto
chunhan
parents:
diff changeset
   626
chunhan
parents:
diff changeset
   627
lemma path_by_shm_attach_aux[rule_format]:
chunhan
parents:
diff changeset
   628
  "path_by_shm s pa pb \<Longrightarrow> valid (Attach p h flag # s) \<longrightarrow> path_by_shm (Attach p h flag # s) pa pb"
chunhan
parents:
diff changeset
   629
apply (erule path_by_shm.induct)
chunhan
parents:
diff changeset
   630
apply (rule impI, rule path_by_shm.intros(1), simp)
chunhan
parents:
diff changeset
   631
apply (rule impI, simp, rule_tac h = ha in path_by_shm.intros(2), simp)
chunhan
parents:
diff changeset
   632
apply (auto simp add:one_flow_shm_simps)
chunhan
parents:
diff changeset
   633
done
chunhan
parents:
diff changeset
   634
chunhan
parents:
diff changeset
   635
lemma path_by_shm_attach2:
chunhan
parents:
diff changeset
   636
  "\<lbrakk>valid (Attach p h flag # s); if path_by_shm s pa pb then True else
chunhan
parents:
diff changeset
   637
     (if (pa = p \<and> flag = SHM_RDWR) 
chunhan
parents:
diff changeset
   638
      then (\<exists> p' flagb. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' pb)
chunhan
parents:
diff changeset
   639
      else if (pb = p) 
chunhan
parents:
diff changeset
   640
           then (\<exists> p'. (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path_by_shm s pa p')
chunhan
parents:
diff changeset
   641
           else (\<exists> p' flag'. path_by_shm s pa p \<and> flag = SHM_RDWR \<and> (p', flag') \<in> procs_of_shm s h \<and> 
chunhan
parents:
diff changeset
   642
                             path_by_shm s p' pb) \<or>
chunhan
parents:
diff changeset
   643
                (\<exists> p'. path_by_shm s pa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path_by_shm s p pb))\<rbrakk>
chunhan
parents:
diff changeset
   644
   \<Longrightarrow> path_by_shm (Attach p h flag # s) pa pb"
chunhan
parents:
diff changeset
   645
apply (frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
   646
apply (auto split:if_splits intro:path_by_shm_intro3 simp:one_flow_shm_def intro:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   647
apply (rule_tac p' = p' in Info_flow_trans)
chunhan
parents:
diff changeset
   648
apply (rule_tac p' = p and h = h in path_by_shm.intros(2))
chunhan
parents:
diff changeset
   649
apply (rule path_by_shm.intros(1), simp)
chunhan
parents:
diff changeset
   650
apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def)
chunhan
parents:
diff changeset
   651
apply (rule conjI, rule notI, simp, rule_tac x = flagb in exI, simp)
chunhan
parents:
diff changeset
   652
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   653
chunhan
parents:
diff changeset
   654
apply (rule_tac p' = p' in Info_flow_trans)
chunhan
parents:
diff changeset
   655
apply (rule_tac p' = p in Info_flow_trans)
chunhan
parents:
diff changeset
   656
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   657
apply (rule_tac p' = p and h = h in path_by_shm.intros(2))
chunhan
parents:
diff changeset
   658
apply (rule path_by_shm.intros(1), simp)
chunhan
parents:
diff changeset
   659
apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def)
chunhan
parents:
diff changeset
   660
apply (rule conjI, rule notI, simp, rule_tac x = flag' in exI, simp)
chunhan
parents:
diff changeset
   661
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   662
chunhan
parents:
diff changeset
   663
apply (rule_tac p' = p in Info_flow_trans)
chunhan
parents:
diff changeset
   664
apply (rule_tac p' = p' in Info_flow_trans)
chunhan
parents:
diff changeset
   665
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   666
apply (rule_tac p' = p' and h = h in path_by_shm.intros(2))
chunhan
parents:
diff changeset
   667
apply (rule path_by_shm.intros(1), simp add:procs_of_shm_prop2)
chunhan
parents:
diff changeset
   668
apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def)
chunhan
parents:
diff changeset
   669
apply (rule notI, simp)
chunhan
parents:
diff changeset
   670
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   671
chunhan
parents:
diff changeset
   672
apply (rule_tac p' = p in Info_flow_trans)
chunhan
parents:
diff changeset
   673
apply (rule_tac p' = p' in Info_flow_trans)
chunhan
parents:
diff changeset
   674
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   675
apply (rule_tac p' = p' and h = h in path_by_shm.intros(2))
chunhan
parents:
diff changeset
   676
apply (rule path_by_shm.intros(1), simp add:procs_of_shm_prop2)
chunhan
parents:
diff changeset
   677
apply (simp add:one_flow_shm_simps, simp add:one_flow_shm_def)
chunhan
parents:
diff changeset
   678
apply (rule notI, simp)
chunhan
parents:
diff changeset
   679
apply (simp add:path_by_shm_attach_aux)
chunhan
parents:
diff changeset
   680
done
chunhan
parents:
diff changeset
   681
chunhan
parents:
diff changeset
   682
lemma path_by_shm_attach:
chunhan
parents:
diff changeset
   683
  "valid (Attach p h flag # s) \<Longrightarrow> path_by_shm (Attach p h flag # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   684
     path_by_shm s pa pb \<or>
chunhan
parents:
diff changeset
   685
     (if (pa = p \<and> flag = SHM_RDWR) 
chunhan
parents:
diff changeset
   686
      then (\<exists> p' flagb. (p', flagb) \<in> procs_of_shm s h \<and> path_by_shm s p' pb)
chunhan
parents:
diff changeset
   687
      else if (pb = p) 
chunhan
parents:
diff changeset
   688
           then (\<exists> p'. (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path_by_shm s pa p')
chunhan
parents:
diff changeset
   689
           else (\<exists> p' flag'. path_by_shm s pa p \<and> flag = SHM_RDWR \<and> (p', flag') \<in> procs_of_shm s h \<and> 
chunhan
parents:
diff changeset
   690
                             path_by_shm s p' pb) \<or>
chunhan
parents:
diff changeset
   691
                (\<exists> p'. path_by_shm s pa p' \<and> (p', SHM_RDWR) \<in> procs_of_shm s h \<and> path_by_shm s p pb)
chunhan
parents:
diff changeset
   692
     )  )"
chunhan
parents:
diff changeset
   693
apply (rule ext, rule ext, rule iffI)
chunhan
parents:
diff changeset
   694
apply (drule_tac pa = pa and pb = pb in path_by_shm_attach1, simp)
chunhan
parents:
diff changeset
   695
apply (auto split:if_splits)[1]
chunhan
parents:
diff changeset
   696
apply (drule_tac pa = pa and pb = pb in path_by_shm_attach2)
chunhan
parents:
diff changeset
   697
apply (auto split:if_splits)
chunhan
parents:
diff changeset
   698
done
chunhan
parents:
diff changeset
   699
chunhan
parents:
diff changeset
   700
chunhan
parents:
diff changeset
   701
chunhan
parents:
diff changeset
   702
lemma info_flow_shm_detach:
chunhan
parents:
diff changeset
   703
  "valid (Detach p h # s) \<Longrightarrow> info_flow_shm (Detach p h # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   704
     self_shm s pa pb \<or> ((p = pa \<or> p = pb) \<and> (\<exists> h'. h' \<noteq> h \<and> one_flow_shm s h' pa pb)) \<or>
chunhan
parents:
diff changeset
   705
     (pa \<noteq> p \<and> pb \<noteq> p \<and> info_flow_shm s pa pb) )"
chunhan
parents:
diff changeset
   706
apply (rule ext, rule ext, frule vt_grant_os)
chunhan
parents:
diff changeset
   707
by (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
   708
chunhan
parents:
diff changeset
   709
lemma info_flow_shm_deleteshm:
chunhan
parents:
diff changeset
   710
  "valid (DeleteShM p h # s) \<Longrightarrow> info_flow_shm (DeleteShM p h # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   711
     self_shm s pa pb \<or> (\<exists> h'. h' \<noteq> h \<and> one_flow_shm s h' pa pb)     )"
chunhan
parents:
diff changeset
   712
apply (rule ext, rule ext, frule vt_grant_os)
chunhan
parents:
diff changeset
   713
by (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
   714
chunhan
parents:
diff changeset
   715
lemma info_flow_shm_clone:
chunhan
parents:
diff changeset
   716
  "valid (Clone p p' fds shms # s) \<Longrightarrow> info_flow_shm (Clone p p' fds shms # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   717
     (pa = p' \<and> pb = p') \<or> (pa = p' \<and> pb \<noteq> p' \<and> (\<exists> h \<in> shms. one_flow_shm s h p pb)) \<or> 
chunhan
parents:
diff changeset
   718
     (pb = p' \<and> pa \<noteq> p' \<and> (\<exists> h \<in> shms. one_flow_shm s h pa p)) \<or> 
chunhan
parents:
diff changeset
   719
     (pa \<noteq> p' \<and> pb \<noteq> p' \<and> info_flow_shm s pa pb))"
chunhan
parents:
diff changeset
   720
apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons, clarsimp)
chunhan
parents:
diff changeset
   721
apply (frule_tac p = p' in procs_of_shm_prop2', simp)
chunhan
parents:
diff changeset
   722
sorry (*
chunhan
parents:
diff changeset
   723
apply (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
   724
done *)
chunhan
parents:
diff changeset
   725
chunhan
parents:
diff changeset
   726
lemma info_flow_shm_execve:
chunhan
parents:
diff changeset
   727
  "valid (Execve p f fds # s) \<Longrightarrow> info_flow_shm (Execve p f fds # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   728
     (pa = p \<and> pb = p) \<or> (pa \<noteq> p \<and> pb \<noteq> p \<and> info_flow_shm s pa pb)    )"
chunhan
parents:
diff changeset
   729
apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
   730
by (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
   731
chunhan
parents:
diff changeset
   732
lemma info_flow_shm_kill:
chunhan
parents:
diff changeset
   733
  "valid (Kill p p' # s) \<Longrightarrow> info_flow_shm (Kill p p' # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   734
     pa \<noteq> p' \<and> pb \<noteq> p' \<and> info_flow_shm s pa pb                 )"
chunhan
parents:
diff changeset
   735
apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
   736
by (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
   737
chunhan
parents:
diff changeset
   738
lemma info_flow_shm_exit:
chunhan
parents:
diff changeset
   739
  "valid (Exit p # s) \<Longrightarrow> info_flow_shm (Exit p # s) = (\<lambda> pa pb. 
chunhan
parents:
diff changeset
   740
     pa \<noteq> p \<and> pb \<noteq> p \<and> info_flow_shm s pa pb                          )"
chunhan
parents:
diff changeset
   741
apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
   742
by (auto simp:info_flow_shm_def one_flow_shm_def)
chunhan
parents:
diff changeset
   743
chunhan
parents:
diff changeset
   744
lemma info_flow_shm_other:
chunhan
parents:
diff changeset
   745
  "\<lbrakk>valid (e # s); 
chunhan
parents:
diff changeset
   746
    \<forall> p h flag. e \<noteq> Attach p h flag;
chunhan
parents:
diff changeset
   747
    \<forall> p h. e \<noteq> Detach p h;
chunhan
parents:
diff changeset
   748
    \<forall> p h. e \<noteq> DeleteShM p h;
chunhan
parents:
diff changeset
   749
    \<forall> p p' fds shms. e \<noteq> Clone p p' fds shms;
chunhan
parents:
diff changeset
   750
    \<forall> p f fds. e \<noteq> Execve p f fds;
chunhan
parents:
diff changeset
   751
    \<forall> p p'. e \<noteq> Kill p p';
chunhan
parents:
diff changeset
   752
    \<forall> p. e \<noteq> Exit p
chunhan
parents:
diff changeset
   753
   \<rbrakk> \<Longrightarrow> info_flow_shm (e # s) = info_flow_shm s"
chunhan
parents:
diff changeset
   754
apply (rule ext, rule ext, frule vt_grant_os, frule vd_cons)
chunhan
parents:
diff changeset
   755
apply (case_tac e, auto simp:info_flow_shm_def one_flow_shm_def dest:procs_of_shm_prop2)
chunhan
parents:
diff changeset
   756
apply (erule_tac x = h in allE, simp)
chunhan
parents:
diff changeset
   757
apply (drule procs_of_shm_prop1, auto)
chunhan
parents:
diff changeset
   758
done
chunhan
parents:
diff changeset
   759
chunhan
parents:
diff changeset
   760
chunhan
parents:
diff changeset
   761
(*
chunhan
parents:
diff changeset
   762
lemma info_flow_shm_prop1: 
chunhan
parents:
diff changeset
   763
  "\<lbrakk>info_flow_shm s p p'; p \<noteq> p'; valid s\<rbrakk> 
chunhan
parents:
diff changeset
   764
   \<Longrightarrow> \<exists> h h' flag. (p, SHM_RDWR) \<in> procs_of_shm s h \<and> (p', flag) \<in> procs_of_shm s h'"
chunhan
parents:
diff changeset
   765
by (induct rule: info_flow_shm.induct, auto)
chunhan
parents:
diff changeset
   766
chunhan
parents:
diff changeset
   767
lemma info_flow_shm_cases:
chunhan
parents:
diff changeset
   768
  "\<lbrakk>info_flow_shm \<tau> pa pb; \<And>p s. \<lbrakk>s = \<tau> ; pa = p; pb = p; p \<in> current_procs s\<rbrakk> \<Longrightarrow> P;
chunhan
parents:
diff changeset
   769
  \<And>s p p' h p'' flag. \<lbrakk>s = \<tau>; pa = p; pb = p''; info_flow_shm s p p'; (p', SHM_RDWR) \<in> procs_of_shm s h;
chunhan
parents:
diff changeset
   770
                       (p'', flag) \<in> procs_of_shm s h\<rbrakk>\<Longrightarrow> P\<rbrakk>
chunhan
parents:
diff changeset
   771
  \<Longrightarrow> P"
chunhan
parents:
diff changeset
   772
by (erule info_flow_shm.cases, auto)
chunhan
parents:
diff changeset
   773
chunhan
parents:
diff changeset
   774
definition one_flow_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool"
chunhan
parents:
diff changeset
   775
where
chunhan
parents:
diff changeset
   776
  "one_flow_shm s p p' \<equiv> p \<noteq> p' \<and> (\<exists> h flag. (p, SHM_RDWR) \<in> procs_of_shm s h \<and> (p', flag) \<in> procs_of_shm s h)"
chunhan
parents:
diff changeset
   777
chunhan
parents:
diff changeset
   778
inductive flows_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process \<Rightarrow> bool"
chunhan
parents:
diff changeset
   779
where
chunhan
parents:
diff changeset
   780
  "p \<in> current_procs s \<Longrightarrow> flows_shm s p p"
chunhan
parents:
diff changeset
   781
| "\<lbrakk>flows_shm s p p'; one_flow_shm s p' p''\<rbrakk> \<Longrightarrow> flows_shm s p p''"
chunhan
parents:
diff changeset
   782
chunhan
parents:
diff changeset
   783
definition attached_procs :: "t_state \<Rightarrow> t_shm \<Rightarrow> t_process set"
chunhan
parents:
diff changeset
   784
where
chunhan
parents:
diff changeset
   785
  "attached_procs s h \<equiv> {p. \<exists> flag. (p, flag) \<in> procs_of_shm s h}"
chunhan
parents:
diff changeset
   786
chunhan
parents:
diff changeset
   787
definition flowed_procs:: "t_state \<Rightarrow> t_shm \<Rightarrow> t_process set"
chunhan
parents:
diff changeset
   788
where
chunhan
parents:
diff changeset
   789
  "flowed_procs s h \<equiv> {p'. \<exists> p \<in> attached_procs s h. flows_shm s p p'}"
chunhan
parents:
diff changeset
   790
chunhan
parents:
diff changeset
   791
inductive flowed_shm:: "t_state \<Rightarrow> t_process \<Rightarrow> t_shm set"
chunhan
parents:
diff changeset
   792
chunhan
parents:
diff changeset
   793
fun Info_flow_shm :: "t_state \<Rightarrow> t_process \<Rightarrow> t_process set"
chunhan
parents:
diff changeset
   794
where
chunhan
parents:
diff changeset
   795
  "Info_flow_shm [] = (\<lambda> p. {p'. flows_shm [] p p'})"
chunhan
parents:
diff changeset
   796
| "Info_flow_shm (Attach p h flag # s) = (\<lambda> p'. 
chunhan
parents:
diff changeset
   797
     if (p' = p) then flowed_procs s h 
chunhan
parents:
diff changeset
   798
     else if ()
chunhan
parents:
diff changeset
   799
    "
chunhan
parents:
diff changeset
   800
chunhan
parents:
diff changeset
   801
chunhan
parents:
diff changeset
   802
lemma info_flow_shm_attach:
chunhan
parents:
diff changeset
   803
  "valid (Attach p h flag # s) \<Longrightarrow> info_flow_shm (Attach p h flag # s) = (\<lambda> pa pb. (info_flow_shm s pa pb) \<or> 
chunhan
parents:
diff changeset
   804
     (if (pa = p) 
chunhan
parents:
diff changeset
   805
      then (if (flag = SHM_RDWR) 
chunhan
parents:
diff changeset
   806
            then (\<exists> flag. (pb, flag) \<in> procs_of_shm s h)
chunhan
parents:
diff changeset
   807
            else (pb = p)) 
chunhan
parents:
diff changeset
   808
      else (if (pb = p) 
chunhan
parents:
diff changeset
   809
            then (pa, SHM_RDWR) \<in> procs_of_shm s h
chunhan
parents:
diff changeset
   810
            else info_flow_shm s pa pb)) )"
chunhan
parents:
diff changeset
   811
apply (frule vd_cons, frule vt_grant_os, rule ext, rule ext)
chunhan
parents:
diff changeset
   812
apply (case_tac "info_flow_shm s pa pb", simp)
chunhan
parents:
diff changeset
   813
chunhan
parents:
diff changeset
   814
thm info_flow_shm.cases
chunhan
parents:
diff changeset
   815
apply (auto split:if_splits intro:info_flow_shm.intros elim:info_flow_shm_cases)
chunhan
parents:
diff changeset
   816
apply (erule info_flow_shm_cases, simp, simp split:if_splits)
chunhan
parents:
diff changeset
   817
apply (rule_tac p = pa and p' = p' in info_flow_shm.intros(2), simp+)
chunhan
parents:
diff changeset
   818
apply (rule notI, erule info_flow_shm.cases, simp+)
chunhan
parents:
diff changeset
   819
pr 5
chunhan
parents:
diff changeset
   820
*)
chunhan
parents:
diff changeset
   821
lemmas info_flow_shm_simps = info_flow_shm_other (* info_flow_shm_attach *) info_flow_shm_detach info_flow_shm_deleteshm
chunhan
parents:
diff changeset
   822
  info_flow_shm_clone info_flow_shm_execve info_flow_shm_kill info_flow_shm_exit
chunhan
parents:
diff changeset
   823
chunhan
parents:
diff changeset
   824
chunhan
parents:
diff changeset
   825
chunhan
parents:
diff changeset
   826
chunhan
parents:
diff changeset
   827
chunhan
parents:
diff changeset
   828
chunhan
parents:
diff changeset
   829
end
chunhan
parents:
diff changeset
   830
chunhan
parents:
diff changeset
   831
end