forked from seL4/l4v
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNode_DR.thy
2764 lines (2613 loc) · 133 KB
/
CNode_DR.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: GPL-2.0-only
*)
theory CNode_DR
imports Finalise_DR
begin
context begin interpretation Arch . (*FIXME: arch_split*)
definition
translate_cnode_invocation :: "Invocations_A.cnode_invocation \<Rightarrow> cdl_cnode_invocation"
where
"translate_cnode_invocation x \<equiv> case x of
Invocations_A.InsertCall cap src_slot dest_slot
\<Rightarrow> Invocations_D.InsertCall (transform_cap cap)
(transform_cslot_ptr src_slot) (transform_cslot_ptr dest_slot)
| Invocations_A.MoveCall cap src_slot dest_slot
\<Rightarrow> Invocations_D.MoveCall (transform_cap cap)
(transform_cslot_ptr src_slot) (transform_cslot_ptr dest_slot)
| Invocations_A.RevokeCall slot \<Rightarrow> Invocations_D.RevokeCall (transform_cslot_ptr slot)
| Invocations_A.DeleteCall slot \<Rightarrow> Invocations_D.DeleteCall (transform_cslot_ptr slot)
| Invocations_A.SaveCall slot \<Rightarrow> Invocations_D.SaveCall (transform_cslot_ptr slot)
| Invocations_A.CancelBadgedSendsCall cap \<Rightarrow> Invocations_D.CancelBadgedSendsCall (transform_cap cap)
| Invocations_A.RotateCall cap1 cap2 slot1 slot2 slot3
\<Rightarrow> Invocations_D.RotateCall (transform_cap cap1) (transform_cap cap2)
(transform_cslot_ptr slot1) (transform_cslot_ptr slot2)
(transform_cslot_ptr slot3)"
lemma corres_assert_lhs:
"(F \<Longrightarrow> corres_underlying sr False False r P P' (f ()) g)
\<Longrightarrow> corres_underlying sr False False r (\<lambda>s. F \<and> P s) P' (assert F >>= f) g"
by (cases F; simp add: corres_underlying_def)
lemma ex_cte_cap_to_not_idle:
"\<lbrakk> ex_cte_cap_wp_to P p s; valid_global_refs s;
valid_idle s; valid_irq_node s \<rbrakk> \<Longrightarrow> fst p \<noteq> idle_thread s"
apply (cases p)
apply (clarsimp simp: ex_cte_cap_wp_to_def cte_wp_at_caps_of_state)
apply (drule(1) valid_global_refsD2)
apply (case_tac cap, simp_all add: cap_range_def global_refs_def)
apply (rename_tac word)
apply (clarsimp simp: valid_idle_def valid_irq_node_def pred_tcb_at_def
obj_at_def is_cap_table_def)
apply (drule_tac x=word in spec, simp)
done
definition
"cap_insert_dest_original cap src_cap
= (if is_ep_cap cap then cap_ep_badge cap \<noteq> cap_ep_badge src_cap
else if is_ntfn_cap cap then cap_ep_badge cap \<noteq> cap_ep_badge src_cap
else if \<exists>irq. cap = cap.IRQHandlerCap irq then src_cap = cap.IRQControlCap else is_untyped_cap cap)"
lemma option_return_modify_modify:
"case_option (return ()) (\<lambda>x. modify (f x))
= (\<lambda>opt. modify (case_option id f opt))"
by (auto split: option.split simp: modify_id_return)
lemma update_cdt_modify:
"update_cdt f = modify (cdt_update f)"
apply (simp add: update_cdt_def set_cdt_modify gets_fold_into_modify)
apply (rule ext, simp add: simpler_modify_def)
done
lemma is_untyped_cap_transform_cap[simp]:
"Types_D.is_untyped_cap (transform_cap src_cap)
= is_untyped_cap src_cap"
apply (case_tac src_cap)
apply (simp_all add:transform_cap_def cap_type_simps)
apply (clarsimp simp:cap_type_simps split:arch_cap.splits)
done
lemma is_untyped_cap_eqD:
"Structures_A.is_untyped_cap src_cap
\<Longrightarrow> \<exists>dev ptr sz idx. src_cap = cap.UntypedCap dev ptr sz idx"
by (case_tac src_cap, simp_all)
lemma p2_less_minus:
"2 ^ sz - Suc 0 < 2 ^ sz"
by auto
lemma dcorres_set_untyped_cap_as_full:
"dcorres dc \<top> (K (cap_aligned cap) and cte_wp_at ((=) src_cap) src
and valid_objs and not_idle_thread (fst src) and valid_idle and valid_etcbs)
(CSpace_D.set_untyped_cap_as_full (transform_cap src_cap) (transform_cap cap) (transform_cslot_ptr src))
(CSpace_A.set_untyped_cap_as_full src_cap cap src)"
apply (simp add:set_untyped_cap_as_full_def CSpace_D.set_untyped_cap_as_full_def
split del:if_split)
apply (case_tac "is_untyped_cap src_cap \<and> is_untyped_cap cap")
apply (rule dcorres_expand_pfx)
apply (rule corres_guard_imp)
apply (rule corres_if)
apply clarsimp
apply (clarsimp dest!:is_untyped_cap_eqD)
apply (drule(1) cte_wp_valid_cap)
apply (simp add:valid_cap_def cap_aligned_def)
apply (rule iffI)
apply clarsimp
apply (drule two_power_eq[THEN iffD1,rotated 2])
apply (simp add:valid_cap_def word_bits_def cap_aligned_def)
apply (simp add:valid_cap_def word_bits_def cap_aligned_def)
apply simp
apply simp
apply (rule_tac F = "is_untyped_cap src_cap \<and> is_untyped_cap cap" in corres_gen_asm)
apply (clarsimp dest!:is_untyped_cap_eqD)
apply (rule set_cap_corres)
apply (clarsimp simp:transform_cap_def free_range_of_untyped_def cap_aligned_def max_free_index_def
dest!:is_untyped_cap_eqD)
apply (cut_tac sz = sz in p2_less_minus)
apply simp
apply simp
apply simp
apply fastforce
apply (fastforce simp:not_idle_thread_def)
apply auto
done
lemma dcorres_opt_parent_set_parent_helper:
"dcorres dc \<top> P
(gets (opt_parent (transform_cslot_ptr src)) >>=
case_option (return ())
(\<lambda>parent. modify (\<lambda>s. s\<lparr>cdl_cdt := cdl_cdt s(transform_cslot_ptr child \<mapsto> parent)\<rparr>)))
g \<Longrightarrow>
dcorres dc \<top> (\<lambda>s. cdt s child = None \<and> cte_at child s \<and>
mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s) \<and> P s)
(gets (opt_parent (transform_cslot_ptr src)) >>=
case_option (return ()) (set_parent (transform_cslot_ptr child)))
g"
apply (clarsimp simp:gets_def set_parent_def bind_def
return_def get_def assert_def corres_underlying_def
fail_def
simpler_modify_def split:option.splits)
apply (drule_tac x = b in spec)
apply (intro conjI impI)
apply clarsimp
apply clarsimp
apply (clarsimp simp:KHeap_DR.cdl_cdt_transform)
apply (drule(2) transform_cdt_none)
apply simp
done
lemma dcorres_set_parent_helper:
"dcorres dc \<top> P
(modify (\<lambda>s. s\<lparr>cdl_cdt := cdl_cdt s(transform_cslot_ptr child \<mapsto> parent)\<rparr>))
g \<Longrightarrow>
dcorres dc \<top> (\<lambda>s. cdt s child = None \<and> cte_at child s \<and>
mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s) \<and> P s)
(set_parent (transform_cslot_ptr child) parent)
g"
apply (clarsimp simp:gets_def set_parent_def bind_def
return_def get_def assert_def corres_underlying_def
fail_def
simpler_modify_def split:option.splits)
apply (drule_tac x = b in spec)
apply (clarsimp simp:KHeap_DR.cdl_cdt_transform)
apply (drule(2) transform_cdt_none)
apply simp
done
lemma revokable_cap_insert_dest_original:
"is_cap_revocable capa cap = cap_insert_dest_original capa cap"
by (clarsimp simp: is_cap_revocable_def arch_is_cap_revocable_def cap_insert_dest_original_def split: cap.splits)
lemma insert_cap_sibling_corres:
"dcorres dc \<top>
(\<lambda>s. cte_wp_at (\<lambda>cap'. \<not> should_be_parent_of cap' (is_original_cap s src)
cap (cap_insert_dest_original cap cap')) src s
\<and> cte_wp_at ((=) cap.NullCap) sibling s
\<and> cte_at src s
\<and> not_idle_thread (fst sibling) s
\<and> not_idle_thread (fst src) s \<and> valid_etcbs s
\<and> valid_mdb s \<and> valid_idle s \<and> valid_objs s \<and> cap_aligned cap)
(insert_cap_sibling (transform_cap cap) (transform_cslot_ptr src) (transform_cslot_ptr sibling))
(cap_insert cap src sibling)"
supply if_cong[cong]
apply (simp add: cap_insert_def[folded cap_insert_dest_original_def])
apply (simp add: insert_cap_sibling_def insert_cap_orphan_def bind_assoc
option_return_modify_modify
gets_fold_into_modify update_cdt_modify
set_original_def modify_modify
cap_insert_ext_def update_cdt_list_def set_cdt_list_modify
cong: option.case_cong)
apply (rule stronger_corres_guard_imp)
apply (rule corres_split_deprecated[OF _ get_cap_corres])+
apply (rule corres_assert_lhs corres_assert_rhs)+
apply (rule_tac F = "src_cap = transform_cap src_capa" in corres_gen_asm)
apply simp
apply (rule corres_split_deprecated[OF _ dcorres_set_untyped_cap_as_full])
apply (rule corres_split_deprecated[OF _ set_cap_corres[OF refl refl]])
apply (rule dcorres_opt_parent_set_parent_helper)
apply (clarsimp simp:gets_fold_into_modify dc_def[symmetric]
option_return_modify_modify modify_modify bind_assoc
cong:option.case_cong)
apply (rule_tac P=\<top> and P'="(\<lambda>s. \<not> should_be_parent_of src_capa (is_original_cap s src) cap orig')
and cte_at src and cte_at sibling
and (\<lambda>s. mdb_cte_at (swp cte_at s) (cdt s))
and (\<lambda>s. cdt s sibling = None)" for orig'
in corres_modify)
apply (clarsimp split del: if_split)
apply (subst if_not_P, assumption)+
apply (clarsimp simp: opt_parent_def transform_def
transform_objects_def transform_cdt_def
transform_current_thread_def
transform_asid_table_def
split: option.split)
apply (clarsimp simp: fun_upd_def[symmetric] cong:if_cong)
apply (subgoal_tac "inj_on transform_cslot_ptr ({src, sibling} \<union> dom (cdt s') \<union> ran (cdt s'))")
apply (subst map_lift_over_f_eq map_lift_over_upd,
erule subset_inj_on, fastforce)+
apply (simp add: map_option_is_None[THEN trans [OF eq_commute]]
fun_eq_iff del: inj_on_insert)
apply (subst eq_commute [where a=None])
apply (subst map_lift_over_f_eq map_lift_over_upd,
erule subset_inj_on, fastforce)+
apply clarsimp
apply (rule_tac s=s' in transform_cdt_slot_inj_on_cte_at[where P=\<top>])
apply (auto simp: swp_def dest: mdb_cte_atD
elim!: ranE)[1]
apply ((wp set_cap_caps_of_state2 get_cap_wp static_imp_wp
| simp add: swp_def cte_wp_at_caps_of_state)+)
apply (wp set_cap_idle |
simp add:set_untyped_cap_as_full_def split del: if_split)+
apply (rule_tac Q = "\<lambda>r s. cdt s sibling = None
\<and> \<not> should_be_parent_of src_capa (is_original_cap s sibling) cap (cap_insert_dest_original cap src_capa)
\<and> mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s)"
in hoare_strengthen_post)
apply (wp set_cap_mdb_cte_at arch_update_cap_valid_mdb)
apply (clarsimp simp:mdb_cte_at_def should_be_parent_of_def
cte_wp_at_caps_of_state has_parent_cte_at is_physical_def
dest!:is_untyped_cap_eqD)
apply fastforce
apply (wp get_cap_wp set_cap_idle static_imp_wp
| simp add:set_untyped_cap_as_full_def
split del: if_split)+
apply (rule_tac Q = "\<lambda>r s. cdt s sibling = None
\<and> (\<exists>cap. caps_of_state s src = Some cap)
\<and> \<not> should_be_parent_of src_capa (is_original_cap s src) cap (cap_insert_dest_original cap src_capa)
\<and> mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s)"
in hoare_strengthen_post)
apply (wp set_cap_mdb_cte_at arch_update_cap_valid_mdb)
apply (clarsimp simp:mdb_cte_at_def should_be_parent_of_def
cte_wp_at_caps_of_state has_parent_cte_at is_physical_def
dest!:is_untyped_cap_eqD)
apply fastforce
apply (wp get_cap_wp set_cap_idle | simp)+
apply clarsimp
apply (clarsimp simp: not_idle_thread_def)
apply (clarsimp simp: caps_of_state_transform_opt_cap cte_wp_at_caps_of_state
transform_cap_def)
apply (clarsimp simp: not_idle_thread_def cte_wp_at_caps_of_state)
apply (clarsimp simp: valid_mdb_def cte_wp_at_cases dest!:invs_mdb)
apply (case_tac "cdt s' sibling", safe intro!: mdb_cte_atI)
(* 145 subgoals *)
by (auto dest: mdb_cte_atD is_untyped_cap_eqD
simp: revokable_cap_insert_dest_original valid_mdb_def
swp_def cte_wp_at_caps_of_state not_idle_thread_def)
lemma insert_cap_child_corres:
"dcorres dc \<top>
(\<lambda>s. cte_wp_at (\<lambda>cap'. should_be_parent_of cap' (is_original_cap s src)
cap (cap_insert_dest_original cap cap')) src s
\<and> not_idle_thread (fst child) s \<and> valid_idle s \<and> valid_etcbs s
\<and> valid_mdb s \<and> not_idle_thread (fst src) s \<and> valid_objs s \<and> cap_aligned cap)
(insert_cap_child (transform_cap cap) (transform_cslot_ptr src) (transform_cslot_ptr child))
(cap_insert cap src child)"
supply revokable_cap_insert_dest_original[simp]
supply if_cong[cong]
apply (simp add: cap_insert_def[folded cap_insert_dest_original_def])
apply (simp add: insert_cap_child_def insert_cap_orphan_def bind_assoc
option_return_modify_modify
gets_fold_into_modify update_cdt_modify
set_original_def modify_modify
cap_insert_ext_def update_cdt_list_def set_cdt_list_modify
cong: option.case_cong)
apply (rule stronger_corres_guard_imp)
apply (rule corres_split_deprecated[OF _ get_cap_corres])+
apply (rule_tac P="old_cap \<noteq> cdl_cap.NullCap" and P'="rv' \<noteq> cap.NullCap"
in corres_symmetric_bool_cases)
apply (clarsimp simp :transform_cap_def split:cap.splits arch_cap.splits)
apply (simp add:assert_def)
apply (rule corres_trivial)
apply (simp add:corres_free_fail)
apply (simp add:assert_def)
apply (rule corres_split_deprecated[OF _ dcorres_set_untyped_cap_as_full])
apply (rule corres_split_deprecated[OF _ set_cap_corres[OF refl refl]])
apply (rule dcorres_set_parent_helper)
apply (rule_tac P=\<top> and P'="(\<lambda>s. should_be_parent_of src_capa (orig s) cap orig')
and cte_at src and cte_at child
and (\<lambda>s. mdb_cte_at (swp cte_at s) (cdt s))" for orig orig'
in corres_modify)
apply (clarsimp split del: if_split)
apply (subst if_P, assumption)+
apply (clarsimp simp: opt_parent_def transform_def transform_asid_table_def
transform_objects_def transform_cdt_def
transform_current_thread_def)
apply (clarsimp simp: fun_upd_def[symmetric] cong:if_cong)
apply (subgoal_tac "inj_on transform_cslot_ptr ({src, child} \<union> dom (cdt s') \<union> ran (cdt s'))")
apply (subst map_lift_over_f_eq map_lift_over_upd,
erule subset_inj_on, fastforce)+
apply (simp add: fun_eq_iff)
apply (rule_tac s=s' in transform_cdt_slot_inj_on_cte_at[where P=\<top>])
apply (auto simp: swp_def dest: mdb_cte_atD
elim!: ranE)[1]
apply (wp set_cap_caps_of_state2 get_cap_wp static_imp_wp
| simp add: swp_def cte_wp_at_caps_of_state)+
apply (wp set_cap_idle |
simp add:set_untyped_cap_as_full_def split del:if_split)+
apply (rule_tac Q = "\<lambda>r s. not_idle_thread (fst child) s
\<and> should_be_parent_of src_capa (is_original_cap s child) cap (cap_insert_dest_original cap src_capa)
\<and> mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s)"
in hoare_strengthen_post)
apply (wp set_cap_mdb_cte_at | simp add:not_idle_thread_def)+
apply (clarsimp simp:mdb_cte_at_def cte_wp_at_caps_of_state)
apply fastforce
apply (wp get_cap_wp set_cap_idle static_imp_wp
| simp split del:if_split add:set_untyped_cap_as_full_def)+
apply (rule_tac Q = "\<lambda>r s. not_idle_thread (fst child) s
\<and> (\<exists>cap. caps_of_state s src = Some cap)
\<and> should_be_parent_of src_capa (is_original_cap s src) cap (cap_insert_dest_original cap src_capa)
\<and> mdb_cte_at (swp (cte_wp_at ((\<noteq>) cap.NullCap)) s) (cdt s)"
in hoare_strengthen_post)
apply (wp set_cap_mdb_cte_at static_imp_wp | simp add:not_idle_thread_def)+
apply (clarsimp simp:mdb_cte_at_def cte_wp_at_caps_of_state)
apply fastforce
apply clarsimp
apply (wp get_cap_wp |simp)+
apply (clarsimp simp: not_idle_thread_def)
apply (clarsimp simp: caps_of_state_transform_opt_cap cte_wp_at_caps_of_state
transform_cap_def)+
apply (clarsimp simp: valid_mdb_def cte_wp_at_cases dest!:invs_mdb)
apply (case_tac "cdt s' child", safe intro!: mdb_cte_atI;
auto dest: mdb_cte_atD is_untyped_cap_eqD
simp: valid_mdb_def swp_def cte_wp_at_caps_of_state not_idle_thread_def)
done
lemma reply_cap_insert_corres:
"sid \<noteq> did\<Longrightarrow>dcorres dc \<top>
(valid_idle and not_idle_thread did and valid_mdb and st_tcb_at (\<lambda>r. \<not> inactive r \<and> \<not> idle r) sid
and valid_etcbs and tcb_at did and tcb_at sid and valid_objs)
(insert_cap_child (cdl_cap.ReplyCap sid rights) (sid, tcb_replycap_slot)
(did, tcb_caller_slot))
(cap_insert (cap.ReplyCap sid False rights) (sid,tcb_cnode_index 2) (did,tcb_cnode_index 3))"
apply (rule corres_guard_imp)
apply (rule insert_cap_child_corres [where cap = "cap.ReplyCap sid False rights"
and src = "(sid, tcb_cnode_index 2)" and child = "(did, tcb_cnode_index 3)",
unfolded transform_cap_def transform_tcb_slot_simp
,simplified])
apply clarsimp+
apply (frule st_tcb_at_reply_cap_valid)
apply simp+
apply (frule tcb_caller_cap)
apply simp+
apply (clarsimp simp:cte_wp_at_caps_of_state should_be_parent_of_def)
apply (clarsimp simp: word_bits_def is_master_reply_cap_def
split:cap.splits)
apply (rule conjI)
apply (drule caps_of_state_cteD)+
apply (frule(1) cte_wp_tcb_cap_valid)
apply (clarsimp simp:valid_mdb_def reply_master_revocable_def)
apply (drule_tac x = "sid" in spec)
apply (drule_tac x = "tcb_cnode_index 2" in spec)
apply (clarsimp simp:cte_wp_at_caps_of_state is_master_reply_cap_def)
apply (drule caps_of_state_cteD)+
apply (frule(1) cte_wp_tcb_cap_valid[where p = "(did,tcb_cnode_index 3)"])
apply (rule conjI)
apply (clarsimp simp:valid_idle_def not_idle_thread_def)
apply (clarsimp simp:pred_tcb_at_def2 obj_at_def)
apply (clarsimp simp:tcb_at_def dest!:get_tcb_SomeD)
apply (drule cte_wp_valid_cap)
apply simp
apply (simp add:valid_cap_def cap_aligned_def)
done
lemma cap_move_swap_ext_def:
"(cap_move new_cap src_slot dest_slot :: (unit, unit) s_monad)=
do CSpaceAcc_A.set_cap new_cap dest_slot;
CSpaceAcc_A.set_cap cap.NullCap src_slot;
src_p \<leftarrow> gets (\<lambda>s. cdt s src_slot);
dest_p \<leftarrow> gets (\<lambda>s. cdt s dest_slot);
cdt \<leftarrow> gets cdt;
parent \<leftarrow> return $ cdt src_slot;
cdt' \<leftarrow> return $ cdt(dest_slot := parent, src_slot := None);
set_cdt
(\<lambda>r. if cdt' r = Some src_slot then Some dest_slot
else cdt' r);
is_original \<leftarrow> gets is_original_cap;
set_original dest_slot (is_original src_slot);
set_original src_slot False;
do_extended_op
(cap_move_ext src_slot dest_slot src_p dest_p)
od"
unfolding cap_move_def
apply (simp add: set_original_def gets_fold_into_modify)
done
lemma move_cap_corres:
"dcorres dc \<top> (cte_wp_at ((=) cap.NullCap) p'
and invs and valid_etcbs and cte_wp_at ((\<noteq>) cap.NullCap) p
and not_idle_thread (fst p')
and not_idle_thread (fst p))
(move_cap (transform_cap cap) (transform_cslot_ptr p)
(transform_cslot_ptr p'))
(cap_move cap p p')"
proof -
note inj_on_insert[iff del]
have insert_sub_walk:
"\<And>p p' S. p \<noteq> p' \<Longrightarrow> insert p S - {p'} = insert p (S - {p'})"
by auto
show ?thesis
supply if_cong[cong]
apply (simp add: cap_move_def move_cap_def cap_move_swap_ext_def swap_parents_def
del: fun_upd_apply)
apply (rule stronger_corres_guard_imp)
apply (rule corres_split_nor)
apply (rule corres_split_nor)
apply (rule dcorres_gets_all_param)
apply (rule dcorres_gets_all_param)
apply (simp add: swap_parents_def
set_original_def set_cdt_modify
gets_fold_into_modify modify_modify
cap_move_ext_def bind_assoc update_cdt_list_def set_cdt_list_modify)
apply (rule conjI, clarsimp)
apply (rule_tac P'="cte_at p and cte_at p' and (\<lambda>s. cdt s p' = None)
and (\<lambda>s. p' \<notin> ran (cdt s)) and no_mloop o cdt
and (\<lambda>s. mdb_cte_at (swp cte_at s) (cdt s)) and K (p \<noteq> p')" and P=\<top>
in corres_inst)
apply (rule corres_modify)
apply (clarsimp simp: transform_def transform_current_thread_def
transform_cdt_def transform_asid_table_def
transform_objects_def)
apply clarsimp
apply (rule corres_modify)
apply (clarsimp simp: transform_def transform_current_thread_def
transform_cdt_def transform_asid_table_def
transform_objects_def)
apply (subgoal_tac "inj_on transform_cslot_ptr
({p, p'} \<union> dom (cdt s') \<union> ran (cdt s')) \<and> cdt s' p \<noteq> Some p")
apply (elim conjE)
apply (subst map_lift_over_if_eq)
apply (erule subset_inj_on, auto elim!: ranE split: if_split_asm)[1]
apply (rule sym)
apply (simp add: Fun.swap_def split del: if_split)
apply (subst map_lift_over_upd[unfolded fun_upd_def],
((erule subset_inj_on, auto elim!: ranE split: if_split_asm)[1]))+
apply (rule ext)
apply (cases p, cases p')
apply (simp split del: if_split)
apply simp
apply (subst subset_inj_on map_lift_over_f_eq[OF subset_inj_on],
assumption, fastforce)+
apply (simp add: inj_on_eq_iff[where f="transform_cslot_ptr"]
ranI domI map_option_eq_Some[THEN trans [OF eq_commute]])
apply (auto simp: inj_on_eq_iff[where f="transform_cslot_ptr"]
ranI domI,
auto simp: inj_on_eq_iff[where f="transform_cslot_ptr"]
ranI domI map_lift_over_eq_Some)[1]
apply (clarsimp simp: no_cdt_loop_mloop)
apply (rule_tac s=s' in transform_cdt_slot_inj_on_cte_at[where P=\<top>])
apply (auto simp: swp_def dest: mdb_cte_atD
elim!: ranE)[1]
apply (rule set_cap_corres)
apply (simp add: transform_cap_def)
apply simp
apply (wp set_cap_caps_of_state2
| simp add: swp_def cte_wp_at_caps_of_state)+
apply (simp add: insert_cap_orphan_def)
apply (rule corres_dummy_return_pr[where b="()"])
apply (rule corres_split_deprecated[where r'=dc])
apply (rule corres_assert_lhs)
apply simp
apply (rule set_cap_corres, simp+)[1]
apply (rule corres_gets_the)
apply simp
apply (rule corres_trivial, rule gets_symb_exec_l)
apply (wp set_cap_caps_of_state2 set_cap_idle)+
apply clarsimp
apply (clarsimp simp: cte_wp_at_caps_of_state
caps_of_state_transform_opt_cap
transform_cap_def not_idle_thread_def)
apply (clarsimp simp: mdb_Null_None[OF _ invs_mdb])
apply (frule invs_mdb)
apply (clarsimp simp: cte_wp_at_caps_of_state valid_mdb_def)
apply (safe intro!: mdb_cte_atI)
apply (auto simp: swp_def cte_wp_at_caps_of_state not_idle_thread_def
dest: mdb_cte_atD elim!: ranE)
done
qed
lemma cap_null_reply_case_If:
"(case cap of cap.ReplyCap t b R \<Rightarrow> f t b R | cap.NullCap \<Rightarrow> g | _ \<Rightarrow> h)
= (if cap = cap.NullCap then g
else if is_reply_cap cap \<or> is_master_reply_cap cap
then f (obj_ref_of cap) (is_master_reply_cap cap) (cap_rights cap)
else h)"
by (simp add: is_reply_cap_def is_master_reply_cap_def split: cap.split)
(* FIXME: move *)
lemma corres_if_rhs2:
"\<lbrakk> G \<Longrightarrow> corres_underlying sr nf nf' rvr P Q a b;
\<not> G \<Longrightarrow> corres_underlying sr nf nf' rvr P' Q' a c \<rbrakk>
\<Longrightarrow> corres_underlying sr nf nf' rvr (P and P') (\<lambda>s. (G \<longrightarrow> Q s) \<and> (\<not> G \<longrightarrow> Q' s))
a (if G then b else c)"
by (rule corres_guard_imp, rule corres_if_rhs, simp+)
lemma transform_cap_is_Null:
"(transform_cap cap = cdl_cap.NullCap) = (cap = cap.NullCap)"
by (simp add: transform_cap_def split: cap.split arch_cap.split)
lemma delete_cap_corres:
"dcorres (dc \<oplus> dc) (\<lambda>_. True) (cap_table_at (length b) a and invs and valid_etcbs
and valid_pdpt_objs and ct_active)
(delete_cap (transform_cslot_ptr (a, b))) (cap_delete (a, b))"
apply (simp add:delete_cap_def cap_delete_def)
apply (subst rec_del_simps_ext)
apply (simp add:bindE_assoc)
apply (rule corres_guard_imp)
apply (rule corres_splitEE[OF _ dcorres_finalise_slot])
apply (clarsimp simp:bindE_assoc when_def)
apply (rule empty_slot_corres)
apply wp+
apply (rule validE_validE_R)
apply (simp add:validE_def weak_valid_mdb_def)
apply (rule hoare_drop_imp)
apply (rule_tac Q = "\<lambda>r. invs and not_idle_thread a and valid_etcbs" in hoare_strengthen_post)
apply (wp rec_del_invs)
apply (simp add:not_idle_thread_def validE_def)
apply wp
apply (clarsimp simp:invs_def valid_state_def valid_mdb_def)
apply clarsimp+
apply (simp add:cap_table_at_cte_at)
apply (clarsimp simp:emptyable_def obj_at_def is_cap_table_def)
apply (clarsimp simp:is_tcb_def split:Structures_A.kernel_object.splits)
apply (clarsimp simp:invs_def valid_state_def)
apply (drule cnode_not_idle,simp)
apply (simp add:not_idle_thread_def)
done
lemma delete_cap_corres':
"dcorres (dc \<oplus> dc) (\<lambda>_. True) (cte_at (a,b) and invs and emptyable (a,b)
and not_idle_thread a and valid_pdpt_objs and valid_etcbs)
(delete_cap (transform_cslot_ptr (a, b))) (cap_delete (a, b))"
apply (simp add:delete_cap_def cap_delete_def)
apply (subst rec_del_simps_ext)
apply (simp add:bindE_assoc)
apply (rule corres_guard_imp)
apply (rule corres_splitEE[OF _ dcorres_finalise_slot])
apply (clarsimp simp:bindE_assoc when_def)
apply (rule empty_slot_corres)
apply wp+
apply (rule validE_validE_R)
apply (simp add:validE_def weak_valid_mdb_def)
apply (rule hoare_drop_imp)
apply (rule_tac Q = "\<lambda>r. invs and not_idle_thread a and valid_etcbs" in hoare_strengthen_post)
apply (wp rec_del_invs)
apply (simp add:not_idle_thread_def validE_def)
apply wp
apply (clarsimp simp:invs_def valid_state_def valid_mdb_def)
apply (clarsimp simp:not_idle_thread_def)+
done
definition boolean_exception :: "'c + bool \<Rightarrow> 'a+'b \<Rightarrow> bool"
where "boolean_exception r r' \<equiv> case r' of Inr a \<Rightarrow> r = Inr True | Inl a \<Rightarrow> r = Inr False \<or> (\<exists>k. r = Inl k)"
lemma boolean_exception_corres:
"\<lbrakk>dcorres (boolean_exception) P P' a b\<rbrakk>
\<Longrightarrow> dcorres (dc\<oplus>dc) P P' (doE r \<leftarrow> a; unlessE r Monads_D.throw odE) b"
apply (clarsimp simp:bindE_def lift_def unlessE_def corres_underlying_def bind_def)
apply (erule allE, erule impE, rule conjI, assumption, assumption)
apply (drule_tac x = "(aa,baa)" in bspec)
apply simp
apply clarsimp
apply (rule bexI)
prefer 2
apply assumption
apply (clarsimp simp: boolean_exception_def validE_def valid_def lift_def
throwError_def returnOk_def return_def
split: sum.splits)
done
lemma cdl_Null_descendants:
"\<lbrakk>cte_wp_at ((=) cap.NullCap) slot' s';valid_mdb s'\<rbrakk>
\<Longrightarrow> KHeap_D.descendants_of (transform_cslot_ptr slot') (transform s') = {}"
apply (subst descendants_of_eqv,clarsimp simp:valid_mdb_def,simp)
apply (erule cte_wp_at_weakenE,simp_all)
apply (erule mdb_Null_descendants,simp)
done
lemma empty_set_eq: "{x. False} = {}"
by auto
lemma preemption_corres:
"dcorres (dc \<oplus> dc) P P'
(Monads_D.throw \<sqinter> returnOk x)
preemption_point"
apply (simp add: preemption_point_def)
apply (auto simp: preemption_point_def o_def gets_def liftE_def whenE_def getActiveIRQ_def
corres_underlying_def select_def bind_def get_def bindE_def select_f_def modify_def
alternative_def throwError_def returnOk_def return_def lift_def
put_def do_machine_op_def
update_work_units_def wrap_ext_bool_det_ext_ext_def work_units_limit_def
work_units_limit_reached_def OR_choiceE_def reset_work_units_def mk_ef_def
split: option.splits kernel_object.splits)
done
lemma in_monad_cap_delete_invs:
"\<lbrakk> invs sfix;slot \<in> CSpaceAcc_A.descendants_of slot' (cdt sfix);
(r, s) \<in> fst (cap_delete slot sfix)\<rbrakk>
\<Longrightarrow> invs s"
using cap_delete_invs[unfolded valid_def,simplified]
apply clarsimp
apply (case_tac slot)
apply (drule_tac x = a in meta_spec)
apply (drule_tac x = b in meta_spec)
apply (drule_tac x = sfix in spec)
apply (clarsimp simp:emptyable_def)
apply (auto simp:reply_slot_not_descendant)
done
lemma descendants_emptyable:
"\<lbrakk>invs s; slot \<in> CSpaceAcc_A.descendants_of slot' (cdt s)\<rbrakk> \<Longrightarrow> emptyable slot s"
apply (case_tac slot)
apply (clarsimp simp:emptyable_def st_tcb_at_def obj_at_def is_tcb_def)
apply (clarsimp split:Structures_A.kernel_object.splits)
apply (frule reply_slot_not_descendant)
apply (simp add:tcb_at_def)
apply (rule exI)
apply (erule get_tcb_rev)
apply fastforce
done
lemma descendants_not_idle:
"\<lbrakk> invs sfix; (a, b) \<in> CSpaceAcc_A.descendants_of slot' (cdt sfix)\<rbrakk>
\<Longrightarrow> not_idle_thread a sfix"
apply (clarsimp simp:not_idle_thread_def invs_def valid_state_def valid_mdb_def valid_pspace_def)
apply (frule descendants_not_null_cap)
apply simp
apply (frule obj_ref_not_idle)
apply simp+
apply (erule cte_wp_at_weakenE)
apply simp
apply (clarsimp simp:cte_wp_at_caps_of_state)
apply (frule valid_idle_has_null_cap)
apply simp+
done
lemma valid_pdpt_objs_irq_state_independent[intro!, simp]:
"valid_pdpt_objs (s \<lparr> machine_state := machine_state s \<lparr> irq_state := f (irq_state (machine_state s)) \<rparr> \<rparr> )
= valid_pdpt_objs s"
by (simp add: obj_valid_pdpt_def)
lemma cdt_machine_state_independent[intro!, simp]:
"cdt (update_machine x s) = cdt s"
by (simp)
lemma cte_wp_at_machine_state[simp]:
"update_machine z s = s' \<Longrightarrow> cte_wp_at x y s' = cte_wp_at x y s"
by (drule sym, simp add: cte_wp_at_def)
lemma valid_mdb_machine_state[simp]:
"update_machine z s = s' \<Longrightarrow> valid_mdb s' = valid_mdb s"
by (drule sym, simp add: valid_mdb_def swp_def)
lemma valid_idle_machine_state[simp]:
"update_machine z s = s' \<Longrightarrow> valid_idle s' = valid_idle s"
by (drule sym, simp add: valid_idle_def)
lemma not_idle_thread_machine_state[simp]:
"update_machine z s = s'\<Longrightarrow> not_idle_thread x s' = not_idle_thread x s"
by (drule sym, simp add: not_idle_thread_def)
lemma dcorres_select_select_ext:
"\<forall>s'\<in>S'. \<exists>s\<in>S. rvr s s' \<Longrightarrow>
dcorres rvr \<top> \<top> (select S) (select_ext a S')"
by (clarsimp simp: select_def select_ext_def get_def bind_def return_def assert_def fail_def corres_underlying_def)
crunch valid_etcbs[wp]: cap_delete "valid_etcbs"
(wp: rec_del_preservation_valid_pdpt_objs cap_revoke_preservation_valid_pdpt_objs)
lemma cap_revoke_corres_helper:
"dcorres boolean_exception (\<lambda>_. True)
((=) s' and invs and valid_pdpt_objs and valid_etcbs)
(monadic_trancl_preemptible
(\<lambda>y. do S \<leftarrow> gets (KHeap_D.descendants_of (transform_cslot_ptr slot'));
if S = {} then returnOk True
else do child \<leftarrow> select S;
cap \<leftarrow> KHeap_D.get_cap child;
doE y \<leftarrow> assertE (cap \<noteq> cdl_cap.NullCap);
y \<leftarrow> delete_cap child;
Monads_D.throw \<sqinter> returnOk False
odE
od
od)
False)
(cap_revoke slot')
"
proof (induct rule: cap_revoke.induct)
case (1 slot' sfix)
show ?case
supply if_cong[cong]
apply (subst cap_revoke.simps)
apply (rule monadic_rewrite_corres2[where P =\<top>,simplified])
apply (rule Finalise_DR.monadic_trancl_preemptible_step)
apply (rule dcorres_expand_pfx)
apply (clarsimp simp:liftE_bindE)
apply (rule_tac Q'="\<lambda>cap. (=) sfix and cte_wp_at (\<lambda>x. x = cap) slot'" in corres_symb_exec_r)
apply (rule dcorres_expand_pfx)
apply (rule_tac Q'="\<lambda>cdt' s. s = sfix \<and> cdt' = cdt sfix" in corres_symb_exec_r)
apply clarsimp
apply (rule dcorres_expand_pfx)
apply clarsimp
apply (case_tac "rv = cap.NullCap")
apply (simp add:gets_def bindE_def bind_assoc whenE_def)
apply (rule dcorres_absorb_get_l)
apply (subst cdl_Null_descendants)
apply (subst identity_eq, simp )
apply (drule invs_mdb, simp)
apply (clarsimp simp:empty_set_eq)+
apply (clarsimp simp:returnOk_def lift_def)
apply (rule corres_guard_imp)
apply (rule monadic_rewrite_corres2[where P=\<top> ,simplified])
apply (rule monadic_trancl_preemptible_return)
apply (rule corres_trivial)
apply (clarsimp simp:returnOk_def boolean_exception_def)+
apply (case_tac "CSpaceAcc_A.descendants_of slot' (cdt sfix) = {}")
apply (clarsimp simp:whenE_def empty_set_eq)
apply (simp add:gets_def bindE_def bind_assoc whenE_def)
apply (rule dcorres_absorb_get_l)
apply (subst descendants_of_eqv)
apply (drule invs_mdb_cte)
apply (drule sym, force simp: swp_def)
apply (rule cte_wp_at_weakenE)
apply simp+
apply (clarsimp simp: lift_def empty_set_eq)+
apply (rule corres_guard_imp)
apply (rule monadic_rewrite_corres2[where P=\<top> ,simplified])
apply (rule monadic_trancl_preemptible_return)
apply (rule corres_trivial)
apply (clarsimp simp:returnOk_def boolean_exception_def)+
apply (clarsimp simp:whenE_def empty_set_eq)
apply (subst gets_def)
apply (simp add: bind_assoc bindE_def)
apply (rule dcorres_absorb_get_l)
apply (subst descendants_of_eqv)
apply (drule invs_mdb_cte)
apply (drule sym, force simp: swp_def)
apply (rule cte_wp_at_weakenE, simp+)
apply (clarsimp simp:bind_assoc)
apply (rule corres_underlying_split[where r'="\<lambda>slot slot'. slot = transform_cslot_ptr slot'"
and P =" \<lambda>r. \<top>" and P'="\<lambda>r s. s = sfix \<and> r \<in> (CSpaceAcc_A.descendants_of slot' (cdt sfix)) \<and> (r, s) \<in> fst ((select_ext (next_revoke_cap slot') (CSpaceAcc_A.descendants_of slot' (cdt sfix))) sfix)"])
apply (rule corres_guard_imp[OF dcorres_select_select_ext])
apply (subst descendants_of_eqv)
apply (drule invs_mdb_cte)
apply (simp add: swp_def)
apply (erule cte_wp_at_weakenE, simp)
apply (simp,blast)
apply simp+
apply (wp select_wp,(clarsimp simp: select_ext_def in_monad)+)
apply (rule dcorres_expand_pfx)
apply (rule_tac r'="\<lambda>cap cap'. cap = transform_cap cap'"
and P ="\<lambda>r. \<top>" and P'="\<lambda>r s. cte_wp_at (\<lambda>x. x = r) (aa,ba) s \<and> s = sfix" in corres_underlying_split)
apply (rule corres_guard_imp[OF get_cap_corres],simp+)
apply (case_tac "next_revoke_cap slot' sfix")
apply clarsimp
apply (frule(1) descendants_not_idle)
apply (simp add:invs_def valid_state_def)
apply (wp get_cap_cte_wp_at | clarsimp)+
apply (clarsimp simp:assertE_def corres_free_fail returnOk_def lift_def)
apply (simp add:bindE_def[symmetric] return_returnOk)
apply (simp add:bindE_assoc)
apply (simp add:bindE_def)
apply (rule dcorres_expand_pfx)
apply (rule_tac r'= "dc\<oplus>dc" and P =" \<lambda>r. \<top>"
and P'="\<lambda>r s. (r,s)\<in> fst (cap_delete (aa,ba) sfix)" in corres_underlying_split)
apply (case_tac "next_revoke_cap slot' sfix")
apply clarsimp
apply (rule corres_guard_imp[OF delete_cap_corres'])
apply clarsimp+
apply (intro conjI, erule cte_wp_at_weakenE,simp)
apply (rule descendants_emptyable,simp+)
apply (rule descendants_not_idle,simp+)
apply (clarsimp|wp)+
apply (fastforce simp:valid_def)
apply (clarsimp simp:bindE_def[symmetric] lift_def)
apply (case_tac rva)
apply (clarsimp simp:boolean_exception_def)+
apply (simp add:bindE_def)
apply (rule dcorres_expand_pfx)
apply (rule_tac r'= "dc \<oplus> dc" and P =" \<lambda>r s. case r of Inr a \<Rightarrow> a = False | _ \<Rightarrow> True"
and P' = "\<lambda>r s. (case r of Inr rva \<Rightarrow> (r , s) \<in> fst (Exceptions_A.preemption_point s') | _ \<Rightarrow> True)"
in corres_underlying_split)
apply (rule corres_guard_imp[OF corres_trivial[OF preemption_corres]])
apply simp+
apply (rule alternative_valid)
apply (simp add:valid_def throwError_def return_def)
apply (simp add:valid_def returnOk_def return_def)
apply (clarsimp simp: valid_def)
apply clarsimp
apply (case_tac rva)
apply (clarsimp simp:lift_def boolean_exception_def)
apply (rule dcorres_expand_pfx)
apply (clarsimp simp:lift_def assertE_def[symmetric] bindE_def[symmetric])
apply (rule corres_guard_imp)
apply (rule_tac rv = rv and rva = "cdt sfix" and rvb = "descendants_of slot' (cdt sfix)"
and rvc = "(aa,ba)" and rvd = rv' and rve = "()" and rvf = "()"
and st = sfix and sta = sfix and stb = sfix and stc = sfix
and std = sfix and ste = sfix and stf = s' and stg = s'a in "1")
apply ((clarsimp simp: cte_wp_at_def in_monad select_def select_ext_def | rule refl)+)
apply (erule use_valid[OF _ preemption_point_inv'])
apply simp
apply simp
apply (simp add: in_monad_cap_delete_invs use_valid [OF _ cap_delete_valid_pdpt_objs] use_valid [OF _ cap_delete_valid_etcbs] select_def)
apply (simp add: gets_def valid_def bind_def get_def return_def)
apply ((wp get_cap_cte_wp_at|clarsimp)+)
done
qed
lemma revoke_cap_spec_corres:
"dcorres (dc \<oplus> dc) \<top> ((=) s' and invs and valid_pdpt_objs and valid_etcbs)
(revoke_cap (transform_cslot_ptr slot')) (cap_revoke slot')"
apply (subst revoke_cap_def)
apply (rule boolean_exception_corres)
unfolding K_def
apply (clarsimp simp: liftE_bindE cong: if_cong)
apply (rule cap_revoke_corres_helper)
done
lemma revoke_cap_corres:
"slot = transform_cslot_ptr slot'
\<Longrightarrow> dcorres (dc\<oplus>dc) \<top> (invs and valid_pdpt_objs and valid_etcbs)
(revoke_cap (slot)) (cap_revoke (slot'))"
apply (rule dcorres_expand_pfx)
apply clarsimp
apply (rule corres_guard_imp[OF revoke_cap_spec_corres])
apply simp+
done
lemma cancel_badged_sends_def':
"CSpace_D.cancel_badged_sends ep badge =
( do s\<leftarrow>get;
tcb_filter_modify {x. \<exists>tcb. (cdl_objects s) x = Some (Tcb tcb) \<and> is_thread_blocked_on_endpoint tcb ep}
(\<lambda>x. (case x of Some (Tcb tcb ) \<Rightarrow>
if get_tcb_ep_badge tcb = Some badge then Some (Tcb (remove_pending_operation tcb cdl_cap.RestartCap))
else x))
od)"
apply (simp add:CSpace_D.cancel_badged_sends_def get_def simpler_modify_def tcb_filter_modify_def)
apply (clarsimp simp:bind_def)
apply (rule ext)
apply clarsimp
apply (case_tac s)
apply clarsimp
apply (rule ext)
apply (clarsimp simp:option_map_def split:option.splits cdl_object.split)
done
lemma cancel_badged_sends_def'':
"CSpace_D.cancel_badged_sends ep badge =
( do s\<leftarrow>get;
tcb_filter_modify {x. \<exists>tcb. (cdl_objects s) x = Some (Tcb tcb) \<and> is_thread_blocked_on_endpoint tcb ep
\<and> get_tcb_ep_badge tcb = Some badge}
(\<lambda>x. (case x of Some (Tcb tcb) \<Rightarrow> Some (Tcb (remove_pending_operation tcb cdl_cap.RestartCap))))
od)"
apply (simp add:CSpace_D.cancel_badged_sends_def get_def simpler_modify_def tcb_filter_modify_def)
apply (clarsimp simp:bind_def)
apply (rule ext)
apply clarsimp
apply (case_tac s)
apply clarsimp
apply (rule ext)
apply (clarsimp simp:option_map_def split:option.splits cdl_object.split)
done
lemma corres_mapM_to_mapM_x:
"corres_underlying sr fl fl' dc P P' f (mapM_x g xs)
\<Longrightarrow> corres_underlying sr fl fl' dc P P' f (mapM g xs)"
by (simp add: mapM_x_mapM liftM_def[symmetric])
lemma ep_waiting_set_recv_upd_kh:
"ep_at epptr s \<Longrightarrow> (ep_waiting_set_recv epptr (update_kheap (kheap s(epptr \<mapsto> kernel_object.Endpoint X)) s))
= (ep_waiting_set_recv epptr s)"
apply (rule set_eqI)
apply (clarsimp simp:ep_waiting_set_recv_def obj_at_def is_ep_def)
done
lemma ep_waiting_set_send_upd_kh:
"ep_at epptr s \<Longrightarrow> (ep_waiting_set_send epptr (update_kheap (kheap s(epptr \<mapsto> kernel_object.Endpoint X)) s))
= (ep_waiting_set_send epptr s)"
apply (rule set_eqI)
apply (clarsimp simp:ep_waiting_set_send_def obj_at_def is_ep_def)
done
lemma ntfn_waiting_set_upd_kh:
"ep_at epptr s \<Longrightarrow> (ntfn_waiting_set epptr (update_kheap (kheap s(epptr \<mapsto> kernel_object.Endpoint X)) s))
= (ntfn_waiting_set epptr s)"
apply (rule set_eqI)
apply (clarsimp simp:ntfn_waiting_set_def obj_at_def is_ep_def)
done
lemma dcorres_ep_cancel_badge_sends:
notes hoare_post_taut[wp]
shows
"dcorres dc \<top> (valid_state and valid_etcbs)
(CSpace_D.cancel_badged_sends epptr word2)
(IpcCancel_A.cancel_badged_sends epptr word2)"
supply if_cong[cong]
apply (clarsimp simp:IpcCancel_A.cancel_badged_sends_def)
apply (rule dcorres_expand_pfx)
apply clarsimp
apply (rule_tac Q' = "\<lambda>r. (=) s' and ko_at (kernel_object.Endpoint r) epptr and valid_ep r"
in corres_symb_exec_r)
apply (case_tac rv)
apply (clarsimp simp: cancel_badged_sends_def')
apply (rule dcorres_absorb_get_l)
apply (rule corres_guard_imp[OF filter_modify_empty_corres])
apply (clarsimp simp:invs_def)
apply (frule_tac epptr = epptr in get_endpoint_pick ,simp add:obj_at_def)
apply (cut_tac ep = epptr and s = "transform s'a" in is_thread_blocked_on_sth)
apply (drule_tac x = x in eqset_imp_iff)
apply (clarsimp simp: valid_state_def valid_ep_abstract_def none_is_sending_ep_def
none_is_receiving_ep_def)
apply (clarsimp simp: ntfn_waiting_set_lift ep_waiting_set_send_lift
ep_waiting_set_recv_lift)
apply (drule ep_not_waiting_ntfn[rotated])
apply (simp add:valid_pspace_def)
apply auto[1]
apply simp+
apply (rule dcorres_expand_pfx)
apply (rule_tac
Q'="\<lambda>r s. s = (update_kheap ((kheap s')(epptr\<mapsto> (Endpoint Structures_A.endpoint.IdleEP))) s')"
in dcorres_symb_exec_r)
apply (clarsimp simp: filterM_mapM cancel_badged_sends_def')
apply (rule dcorres_absorb_get_l)
apply (rule corres_dummy_return_l)
apply (rule corres_underlying_split[where r'=dc])
apply (rule corres_mapM_to_mapM_x)
apply (rule corres_guard_imp)
apply (rule_tac lift_func = id in set_list_modify_corres_helper)
apply (simp add:valid_ep_def)
apply (simp add:inj_on_def)
apply (simp add:is_thread_blocked_on_sth[simplified])
apply (subgoal_tac "valid_idle s' \<and> valid_etcbs s'")
apply (clarsimp simp: ntfn_waiting_set_lift ep_waiting_set_send_lift
ep_waiting_set_recv_lift)
apply (subst ntfn_waiting_set_upd_kh)
apply (simp add:obj_at_def is_ep_def)
apply (subst ep_waiting_set_send_upd_kh)
apply (simp add:obj_at_def is_ep_def)
apply (subst ep_waiting_set_recv_upd_kh)
apply (simp add:obj_at_def is_ep_def)
apply (frule_tac epptr = epptr in get_endpoint_pick)
apply (simp add:obj_at_def)
apply (clarsimp simp:valid_ep_abstract_def none_is_receiving_ep_def)
apply (subst ep_not_waiting_ntfn)
apply (simp add:valid_state_def valid_pspace_def)
apply (simp add:obj_at_def)
apply (rule set_eqI)
apply (clarsimp simp:image_def)
apply (rule conjI)
apply (clarsimp simp:valid_idle_def valid_state_def pred_tcb_at_def obj_at_def)
apply (clarsimp simp: obj_at_def, frule(1) valid_etcbs_ko_etcb)
apply (clarsimp simp: valid_etcbs_def obj_at_def st_tcb_at_def st_tcb_at_kh_def
obj_at_kh_def is_etcb_at_def)
apply (clarsimp simp: tcb_filter_modify_def bind_assoc thread_get_def
get_thread_state_def)
apply (rule_tac
Q'="\<lambda>s. valid_idle s \<and> valid_etcbs s \<and> not_idle_thread a s
\<and> idle_thread s = idle_thread s'a \<and>
st_tcb_at (\<lambda>ts. \<exists>pl. ts = Structures_A.thread_state.BlockedOnSend epptr pl) a s"
in corres_guard_imp[where Q=\<top>])
apply (rule dcorres_absorb_gets_the)
apply (clarsimp simp:pred_tcb_at_def obj_at_def dest!:get_tcb_SomeD)
apply (rule conjI)
apply (clarsimp simp:set_thread_state_def bind_assoc | rule conjI)+
apply (rule dcorres_absorb_gets_the)
apply (rule corres_guard_imp)
apply (rule_tac P="(=) (transform s'b)" and P'="(=) s'b"
and Q=\<top> and Q'=\<top> in corres_split_noop_rhs2)
apply (rule dcorres_rhs_noop_above_True[OF set_thread_state_ext_dcorres])
apply (rule dcorres_rhs_noop_above_True[OF tcb_sched_action_dcorres])
apply simp
apply (clarsimp simp: set_object_def get_object_def in_monad simpler_modify_def
get_def return_def bind_def put_def corres_underlying_def)
apply (clarsimp simp:transform_def transform_current_thread_def)
apply (rule ext)
apply (frule(1) valid_etcbs_get_tcb_get_etcb)
apply (clarsimp simp:transform_objects_tcb not_idle_thread_def )
apply (clarsimp simp:transform_tcb_def transform_objects_def
get_tcb_ep_badge_def remove_pending_operation_def get_tcb_SomeD get_etcb_SomeD)
apply (fastforce simp: restrict_map_def map_add_def map_def tcb_slot_defs)
apply (wp | simp)+
apply (clarsimp simp: simpler_modify_def corres_underlying_def return_def
transform_def
dest!: get_tcb_rev)
apply (rule ext)
apply (frule(1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (case_tac "a=idle_thread s'", simp add: not_idle_thread_def)
apply (drule (2) transform_objects_tcb)
apply (clarsimp simp: transform_current_thread_def transform_def)