-
Notifications
You must be signed in to change notification settings - Fork 108
/
CNode_AC.thy
1764 lines (1532 loc) · 80.1 KB
/
CNode_AC.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_AC
imports ArchAccess_AC
begin
section\<open>CNode-specific AC.\<close>
(* FIXME: Move. *)
lemma tcb_domain_map_wellformed_ekheap[intro!, simp]:
"ekheap (P s) = ekheap s \<Longrightarrow> tcb_domain_map_wellformed aag (P s) = tcb_domain_map_wellformed aag s"
by (simp add: tcb_domain_map_wellformed_aux_def get_etcb_def)
(* FIXME: for some reason crunch does not discover the right precondition *)
lemma set_cap_integrity_autarch:
"\<lbrace>integrity aag X st and K (is_subject aag (fst slot))\<rbrace> set_cap cap slot \<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
by (wpsimp simp: set_cap_def wp: set_object_integrity_autarch get_object_wp)
lemma integrity_cdt_list_as_list_integ:
"cdt_list_integrity_state aag st s =
list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st s"
by (fastforce elim: integrity_cdt_listE list_integE intro: list_integI integrity_cdt_list_intros)
crunch cap_swap_ext,cap_move_ext,empty_slot_ext
for ekheap[wp]: "\<lambda>s. P (ekheap s)"
and ready_queues[wp]: "\<lambda>s. P (ready_queues s)"
crunch set_untyped_cap_as_full
for integrity_autarch: "integrity aag X st"
locale CNode_AC_1 =
fixes aag :: "'a PAS"
and val_t :: "'b"
assumes sata_cdt_update[simp]:
"\<And>f. state_asids_to_policy aag (cdt_update f s) = state_asids_to_policy aag s"
and sata_is_original_cap_update[simp]:
"\<And>f. state_asids_to_policy aag (is_original_cap_update f s) = state_asids_to_policy aag s"
and sata_interrupt_states_update[simp]:
"\<And>f. state_asids_to_policy aag (interrupt_states_update f s) = state_asids_to_policy aag s"
and sata_machine_state_update[simp]:
"\<And>f. state_asids_to_policy aag (machine_state_update f s) = state_asids_to_policy aag s"
and sata_update:
"\<lbrakk> pas_wellformed aag; cap_links_asid_slot aag (pasObjectAbs aag (fst ptr)) cap;
state_asids_to_policy_arch aag (caps :: cslot_ptr \<Rightarrow> cap option) as vrefs \<subseteq> pasPolicy aag \<rbrakk>
\<Longrightarrow> state_asids_to_policy_arch aag (caps(ptr \<mapsto> cap)) as vrefs \<subseteq> pasPolicy aag"
and sata_update2:
"\<lbrakk> pas_wellformed aag; cap_links_asid_slot aag (pasObjectAbs aag (fst ptr)) cap;
cap_links_asid_slot aag (pasObjectAbs aag (fst ptr')) cap';
state_asids_to_policy_arch aag caps (as :: arch_state) vrefs \<subseteq> pasPolicy aag \<rbrakk>
\<Longrightarrow> state_asids_to_policy_arch aag (caps(ptr \<mapsto> cap, ptr' \<mapsto> cap')) as vrefs \<subseteq> pasPolicy aag"
and state_vrefs_tcb_upd:
"\<lbrakk> pspace_aligned s; valid_vspace_objs s; valid_arch_state s; tcb_at tptr s \<rbrakk>
\<Longrightarrow> state_vrefs (s\<lparr>kheap := (kheap s)(tptr \<mapsto> TCB tcb)\<rparr>) = state_vrefs s"
and state_vrefs_simple_type_upd:
"\<lbrakk> pspace_aligned s; valid_vspace_objs s; valid_arch_state s;
ko_at ko p s; is_simple_type ko; a_type ko = a_type (f (val :: 'b)) \<rbrakk>
\<Longrightarrow> state_vrefs (s\<lparr>kheap := (kheap s)(p \<mapsto> f val)\<rparr>) = state_vrefs s"
and a_type_arch_object_not_tcb[simp]:
"a_type (ArchObj arch_kernel_obj) \<noteq> ATCB"
and set_cap_state_vrefs:
"\<And>P. \<lbrace>pspace_aligned and valid_vspace_objs and valid_arch_state and (\<lambda>s. P (state_vrefs s))\<rbrace>
set_cap cap slot
\<lbrace>\<lambda>_ s :: det_ext state. P (state_vrefs s)\<rbrace>"
and set_cdt_state_vrefs[wp]:
"\<And>P. set_cdt t \<lbrace>\<lambda>s :: det_ext state. P (state_vrefs s)\<rbrace>"
and set_cdt_state_asids_to_policy[wp]:
"\<And>P. set_cdt t \<lbrace>\<lambda>s. P (state_asids_to_policy aag s)\<rbrace>"
and arch_post_cap_deletion_integrity[wp]:
"arch_post_cap_deletion acap \<lbrace>integrity aag X st\<rbrace>"
and arch_post_cap_deletion_cur_domain[wp]:
"\<And>P. arch_post_cap_deletion acap \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
and arch_finalise_cap_cur_domain:
"\<And>P. arch_finalise_cap acap final \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
and prepare_thread_delete_cur_domain:
"\<And>P. prepare_thread_delete p \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
and maskInterrupt_underlying_memory[wp]:
"\<And>P. maskInterrupt m irq \<lbrace>\<lambda>s. P (underlying_memory s)\<rbrace>"
and maskInterrupt_device_state[wp]:
"\<And>P. maskInterrupt m irq \<lbrace>\<lambda>s. P (device_state s)\<rbrace>"
and cap_insert_ext_extended_list_integ_lift:
"\<And>Q a b c d e.
\<lbrakk> \<lbrace>list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st and Q\<rbrace>
cap_insert_ext a b c d e
\<lbrace>\<lambda>_. list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st\<rbrace>;
\<And>P. cap_insert_ext a b c d e \<lbrace>\<lambda>s. P (ekheap s)\<rbrace>; \<And>P. cap_insert_ext a b c d e \<lbrace>\<lambda>s. P (ready_queues s)\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>integrity aag X st and Q\<rbrace> cap_insert_ext a b c d e \<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
and cap_move_ext_list_integ_lift:
"\<And>Q a b c d.
\<lbrakk> \<lbrace>list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st and Q\<rbrace>
cap_move_ext a b c d
\<lbrace>\<lambda>_. list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st\<rbrace>;
\<And>P. cap_move_ext a b c d \<lbrace>\<lambda>s. P (ekheap s)\<rbrace>; \<And>P. cap_move_ext a b c d \<lbrace>\<lambda>s. P (ready_queues s)\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>integrity aag X st and Q\<rbrace> cap_move_ext a b c d \<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
and cap_swap_ext_extended_list_integ_lift:
"\<And>Q a b c d.
\<lbrakk> \<lbrace>list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st and Q\<rbrace>
cap_swap_ext a b c d
\<lbrace>\<lambda>_. list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st\<rbrace>;
\<And>P. cap_swap_ext a b c d \<lbrace>\<lambda>s. P (ekheap s)\<rbrace>; \<And>P. cap_swap_ext a b c d \<lbrace>\<lambda>s. P (ready_queues s)\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>integrity aag X st and Q\<rbrace> cap_swap_ext a b c d \<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
and empty_slot_extended_list_integ_lift:
"\<And>Q a b.
\<lbrakk> \<lbrace>list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st and Q\<rbrace>
empty_slot_ext a b
\<lbrace>\<lambda>_. list_integ (cdt_change_allowed aag {pasSubject aag} (cdt st) (tcb_states_of_state st)) st\<rbrace>;
\<And>P. empty_slot_ext a b \<lbrace>\<lambda>s. P (ekheap s)\<rbrace>; \<And>P. empty_slot_ext a b \<lbrace>\<lambda>s. P (ready_queues s)\<rbrace> \<rbrakk>
\<Longrightarrow> \<lbrace>integrity aag X st and Q\<rbrace> empty_slot_ext a b \<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
begin
lemma set_original_integrity_autarch:
"\<lbrace>integrity aag X st and K (is_subject aag (fst slot))\<rbrace>
set_original slot orig
\<lbrace>\<lambda>rv. integrity aag X st\<rbrace>"
apply (wpsimp simp: set_original_def)
apply (clarsimp simp: integrity_def intro!: integrity_cdt_direct)
done
lemma set_original_integrity:
"\<lbrace>integrity aag X st and cdt_change_allowed' aag slot\<rbrace>
set_original slot orig
\<lbrace>\<lambda>rv. integrity aag X st\<rbrace>"
apply integrity_trans_start
apply (wpsimp simp: set_original_def integrity_def)
done
lemma update_cdt_fun_upd_integrity_autarch:
"\<lbrace>integrity aag X st and K (is_subject aag (fst slot))\<rbrace>
update_cdt (\<lambda>cdt. cdt (slot := v cdt))
\<lbrace>\<lambda>rv. integrity aag X st\<rbrace>"
apply (wpsimp simp: update_cdt_def set_cdt_def)
apply (clarsimp simp: integrity_def intro!: integrity_cdt_direct)
done
lemma cap_insert_integrity_autarch:
"\<lbrace>integrity aag X st and K (is_subject aag (fst src_slot) \<and> is_subject aag (fst dest_slot))\<rbrace>
cap_insert cap src_slot dest_slot
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (simp add: cap_insert_def)
apply (wp set_original_integrity_autarch cap_insert_ext_extended_list_integ_lift
cap_insert_list_integrity update_cdt_fun_upd_integrity_autarch gets_inv
set_cap_integrity_autarch set_untyped_cap_as_full_integrity_autarch assert_inv)
apply fastforce
done
end
text\<open>
Establish that the pointers this syscall will change are labelled with
the current agent's label.
NOTE: @{term "(\<subseteq>)"} is used consciously here to block the simplifier
rewriting (the equivalent equalities) in the wp proofs.
\<close>
definition authorised_cnode_inv ::
"'a PAS \<Rightarrow> Invocations_A.cnode_invocation \<Rightarrow> 'z::state_ext state \<Rightarrow> bool" where
"authorised_cnode_inv aag ci \<equiv> K (case ci of
InsertCall cap ptr ptr' \<Rightarrow> pasObjectAbs aag ` {fst ptr, fst ptr'} \<subseteq> {pasSubject aag}
| MoveCall cap ptr ptr' \<Rightarrow> pasObjectAbs aag ` {fst ptr, fst ptr'} \<subseteq> {pasSubject aag}
| RotateCall s_cap p_cap src pivot dest \<Rightarrow>
pasObjectAbs aag ` {fst src, fst pivot, fst dest} \<subseteq> {pasSubject aag}
| SaveCall ptr \<Rightarrow> is_subject aag (fst ptr)
| DeleteCall ptr \<Rightarrow> is_subject aag (fst ptr)
| CancelBadgedSendsCall cap \<Rightarrow> pas_cap_cur_auth aag cap
| RevokeCall ptr \<Rightarrow> is_subject aag (fst ptr))"
lemma resolve_address_bits_authorised_aux:
"s \<turnstile> \<lbrace>pas_refined aag and K (is_cnode_cap (fst (cap, cref))
\<longrightarrow> (\<forall>x \<in> obj_refs_ac (fst (cap, cref)). is_subject aag x))\<rbrace>
resolve_address_bits (cap, cref)
\<lbrace>\<lambda>rv s. is_subject aag (fst (fst rv))\<rbrace>, \<lbrace>\<lambda>rv. \<top>\<rbrace>"
unfolding resolve_address_bits_def
proof (induct arbitrary: s rule: resolve_address_bits'.induct)
case (1 z cap' cref' s')
have P: "\<And>s f P Q. s \<turnstile> \<lbrace>P\<rbrace> throwError f \<lbrace>Q\<rbrace>,\<lbrace>\<lambda>rv s. True\<rbrace>"
by wp+
show ?case
apply (subst resolve_address_bits'.simps)
apply (cases cap', simp_all add: P split del: if_split)
apply (rule hoare_pre_spec_validE)
apply (wp "1.hyps", (assumption | simp add: in_monad | rule conjI)+)
apply (wp get_cap_wp)+
apply (auto simp: cte_wp_at_caps_of_state is_cap_simps cap_auth_conferred_def
dest: caps_of_state_pasObjectAbs_eq)
done
qed
lemma resolve_address_bits_authorised[wp]:
"\<lbrace>pas_refined aag and K (is_cnode_cap cap \<longrightarrow> (\<forall>x \<in> obj_refs_ac cap. is_subject aag x))\<rbrace>
resolve_address_bits (cap, cref)
\<lbrace>\<lambda>rv s. is_subject aag (fst (fst rv))\<rbrace>, -"
apply (unfold validE_R_def)
apply (rule hoare_pre)
apply (rule use_spec(2)[OF resolve_address_bits_authorised_aux])
apply simp
done
lemma lookup_slot_for_cnode_op_authorised[wp]:
"\<lbrace>pas_refined aag and K (is_cnode_cap croot \<longrightarrow> (\<forall>x \<in> obj_refs_ac croot. is_subject aag x))\<rbrace>
lookup_slot_for_cnode_op is_source croot ptr depth
\<lbrace>\<lambda>rv s. is_subject aag (fst rv)\<rbrace>, -"
apply (simp add: lookup_slot_for_cnode_op_def split del: if_split)
apply (wp whenE_throwError_wp hoare_drop_imps
resolve_address_bits_authorised
[THEN hoare_strengthen_postE_R[where Q'="\<lambda>x s. is_subject aag (fst (fst x))"]]
| wpc | fastforce)+
done
(* FIXME MOVE *)
lemma is_cnode_into_is_subject:
"\<lbrakk> pas_cap_cur_auth aag cap; pas_refined aag s; is_cnode_cap cap \<rbrakk>
\<Longrightarrow> \<forall>x\<in>obj_refs_ac cap. is_subject aag x"
by (clarsimp simp: is_cap_simps cap_auth_conferred_def
pas_refined_all_auth_is_owns aag_cap_auth_def)
lemma get_cap_prop_imp:
"\<lbrace>cte_wp_at (\<lambda>cap. P cap \<longrightarrow> Q cap) slot\<rbrace> get_cap slot \<lbrace>\<lambda>rv s. P rv \<longrightarrow> cte_wp_at Q slot s\<rbrace>"
by (wpsimp wp: get_cap_wp simp: cte_wp_at_caps_of_state)
lemma get_cap_prop_imp2:
"\<lbrace>cte_wp_at (\<lambda>cap. P cap) slot\<rbrace> get_cap slot \<lbrace>\<lambda>rv s. P rv\<rbrace>"
by (wpsimp wp: get_cap_wp simp: cte_wp_at_def)
lemma get_cap_cur_auth:
"\<lbrace>pas_refined aag and cte_wp_at (\<lambda>_. True) slot and K (is_subject aag (fst slot))\<rbrace>
get_cap slot
\<lbrace>\<lambda>rv s. pas_cap_cur_auth aag rv\<rbrace>"
apply (wp get_cap_wp)
apply (clarsimp simp: cte_wp_at_caps_of_state cap_cur_auth_caps_of_state)
done
lemma decode_cnode_inv_authorised:
"\<lbrace>pas_refined aag and invs and valid_cap cap
and K (\<forall>c \<in> {cap} \<union> set excaps. pas_cap_cur_auth aag c)\<rbrace>
decode_cnode_invocation label args cap excaps
\<lbrace>\<lambda>rv s. authorised_cnode_inv aag rv s\<rbrace>,-"
apply (simp add: authorised_cnode_inv_def decode_cnode_invocation_def
split_def whenE_def unlessE_def set_eq_iff
cong: if_cong Invocations_A.cnode_invocation.case_cong split del: if_split)
apply (wpsimp wp: hoare_vcg_all_lift hoare_vcg_const_imp_liftE_R hoare_vcg_all_liftE_R lsfco_cte_at
| wp (once) get_cap_cur_auth)+
apply (subgoal_tac "\<forall>n. n < length excaps
\<longrightarrow> (is_cnode_cap (excaps ! n)
\<longrightarrow> (\<forall>x\<in>obj_refs_ac (excaps ! n). is_subject aag x))")
apply (fastforce simp: invs_valid_objs is_cnode_into_is_subject)
apply (intro allI impI is_cnode_into_is_subject; fastforce)
done
lemma set_cap_thread_st_auth[wp]:
"set_cap cap ptr \<lbrace>\<lambda>s. P (thread_st_auth s)\<rbrace>"
apply (wpsimp wp: get_object_wp simp: set_cap_def split_def set_object_def)
apply (fastforce simp: obj_at_def get_tcb_def tcb_states_of_state_def
thread_st_auth_def rsubst[where P=P, OF _ ext])
done
lemma set_cap_tcb_states_of_state[wp]:
"set_cap cap ptr \<lbrace>\<lambda>s. P (tcb_states_of_state s)\<rbrace>"
apply (simp add: set_cap_def split_def set_object_def)
apply (wpsimp wp: get_object_wp)
apply (fastforce simp: obj_at_def get_tcb_def tcb_states_of_state_def rsubst[where P=P, OF _ ext])
done
lemma set_cap_thread_bound_ntfns[wp]:
"set_cap cap ptr \<lbrace>\<lambda>s. P (thread_bound_ntfns s)\<rbrace>"
apply (wpsimp wp: get_object_wp simp: set_cap_def split_def set_object_def)
apply (fastforce simp: obj_at_def get_tcb_def thread_bound_ntfns_def rsubst[where P=P, OF _ ext])
done
lemma sita_caps_update:
"\<lbrakk> pas_wellformed aag; state_irqs_to_policy_aux aag caps \<subseteq> pasPolicy aag;
cap_links_irq aag (pasObjectAbs aag (fst ptr)) cap \<rbrakk>
\<Longrightarrow> state_irqs_to_policy_aux aag (caps(ptr \<mapsto> cap)) \<subseteq> pasPolicy aag"
by (fastforce intro: state_irqs_to_policy_aux.intros
elim: state_irqs_to_policy_aux.cases
simp: cap_links_irq_def split: if_splits)
lemma sita_caps_update2:
"\<lbrakk> pas_wellformed aag; state_irqs_to_policy_aux aag caps \<subseteq> pasPolicy aag;
cap_links_irq aag (pasObjectAbs aag (fst ptr')) cap';
cap_links_irq aag (pasObjectAbs aag (fst ptr)) cap \<rbrakk>
\<Longrightarrow> state_irqs_to_policy_aux aag (caps(ptr \<mapsto> cap, ptr' \<mapsto> cap')) \<subseteq> pasPolicy aag"
by (fastforce intro: state_irqs_to_policy_aux.intros
elim: state_irqs_to_policy_aux.cases
simp: cap_links_irq_def split: if_splits)
context CNode_AC_1 begin
lemma set_cap_pas_refined:
"\<lbrace>pas_refined aag and pspace_aligned and valid_vspace_objs and valid_arch_state and
(\<lambda>s. (is_transferable_in ptr s \<and> (\<not> Option.is_none (cdt s ptr)))
\<longrightarrow> is_transferable_cap cap \<or>
abs_has_auth_to aag Control (fst $ the $ cdt s ptr) (fst ptr)) and
K (aag_cap_auth aag (pasObjectAbs aag (fst ptr)) cap)\<rbrace>
set_cap cap ptr
\<lbrace>\<lambda>_. pas_refined aag\<rbrace>"
apply (simp add: pas_refined_def state_objs_to_policy_def aag_cap_auth_def)
apply (rule hoare_pre)
apply (wp set_cap_caps_of_state set_cap_state_vrefs | wps)+
apply clarsimp
apply (intro conjI) \<comment> \<open>auth_graph_map\<close>
apply (clarsimp dest!: auth_graph_map_memD)
apply (erule state_bits_to_policy.cases;
solves\<open>auto simp: cap_links_asid_slot_def label_owns_asid_slot_def
intro: auth_graph_map_memI state_bits_to_policy.intros
split: if_split_asm\<close>)
apply (erule (2) sata_update[unfolded fun_upd_def])
apply (erule (2) sita_caps_update[unfolded fun_upd_def])
done
lemma set_cap_pas_refined_not_transferable:
"\<lbrace>pas_refined aag and pspace_aligned and valid_vspace_objs and valid_arch_state
and cte_wp_at (\<lambda>c. \<not>is_transferable (Some c)) ptr
and K (aag_cap_auth aag (pasObjectAbs aag (fst ptr)) cap)\<rbrace>
set_cap cap ptr
\<lbrace>\<lambda>_. pas_refined aag\<rbrace>"
by (wpsimp wp: set_cap_pas_refined simp: cte_wp_at_caps_of_state)
end
(* FIXME MOVE *)
lemma parent_ofI[intro!]: "m x = Some src \<Longrightarrow> m \<Turnstile> src \<leadsto> x"
by (simp add: cdt_parent_rel_def is_cdt_parent_def)
declare set_original_wp[wp del]
context CNode_AC_1 begin
lemma cap_move_respects[wp]:
"\<lbrace>integrity aag X st and pas_refined aag
and K (is_subject aag (fst dest) \<and> is_subject aag (fst src))\<rbrace>
cap_move cap src dest
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (rule hoare_gen_asm)
apply (clarsimp simp: cap_move_def)
apply (wpsimp wp: get_cap_wp set_cap_integrity_autarch set_original_integrity_autarch
cap_move_ext_list_integ_lift[where Q="\<top>"] cap_move_list_integrity
simp: set_cdt_def | blast)+
apply (rule wp_integrity_clean')
apply (simp add: integrity_def integrity_cdt_def)
apply (blast intro: cca_owned)
apply (wpsimp wp: set_cap_integrity_autarch)+
done
lemma cap_swap_respects[wp]:
"\<lbrace>integrity aag X st and pas_refined aag
and K (is_subject aag (fst slot) \<and> is_subject aag (fst slot'))\<rbrace>
cap_swap cap slot cap' slot'
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (rule hoare_gen_asm)
apply (clarsimp simp: cap_swap_def)
apply (wp get_cap_wp set_cap_integrity_autarch cap_swap_list_integrity
cap_swap_ext_extended_list_integ_lift[where Q="\<top>"]
set_original_integrity_autarch[unfolded pred_conj_def K_def]
| simp add: set_cdt_def split del: if_split | blast)+
apply (rule wp_integrity_clean')
apply (simp add: integrity_def)
apply (blast intro: cca_owned)
apply (wpsimp wp: set_cap_integrity_autarch set_cap_pas_refined)+
done
lemma cap_swap_for_delete_respects[wp]:
"\<lbrace>integrity aag X st and pas_refined aag
and K (is_subject aag (fst slot) \<and> is_subject aag (fst slot'))\<rbrace>
cap_swap_for_delete slot slot'
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
by (wpsimp simp: cap_swap_for_delete_def)
lemma dmo_no_mem_respects:
assumes p: "\<And>P. mop \<lbrace>\<lambda>ms. P (underlying_memory ms)\<rbrace>"
assumes q: "\<And>P. mop \<lbrace>\<lambda>ms. P (device_state ms)\<rbrace>"
shows "do_machine_op mop \<lbrace>integrity aag X st\<rbrace>"
unfolding do_machine_op_def
apply (rule hoare_pre)
apply (simp add: split_def)
apply wp
apply (clarsimp simp: integrity_def)
apply (rule conjI)
apply clarsimp
apply (drule_tac x = x in spec)+
apply (erule (1) use_valid [OF _ p])
apply clarsimp
apply (drule_tac x = x in spec)+
apply (erule (1) use_valid [OF _ q])
done
lemma set_irq_state_respects[wp]:
"\<lbrace>integrity aag X st and K (is_subject_irq aag irq)\<rbrace>
set_irq_state irqst irq
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
unfolding set_irq_state_def
by (wpsimp wp: dmo_no_mem_respects simp: integrity_subjects_def integrity_interrupts_def)
end
(* FIXME: MOVE *)
(* Only works after a hoare_pre! *)
lemma dmo_wp:
assumes mopv: "\<And>s. \<lbrace>P s\<rbrace> mop \<lbrace>\<lambda>a b. R a (s\<lparr>machine_state := b\<rparr>)\<rbrace>"
shows "\<lbrace>\<lambda>s. P s (machine_state s)\<rbrace> do_machine_op mop \<lbrace>R\<rbrace>"
by (wpsimp simp: do_machine_op_def use_valid[OF _ mopv])
lemmas cases_simp_options = cases_simp_option cases_simp_option[where 'a="'b \<times> 'c", simplified]
(* FIXME MOVE *)
lemma cdt_change_allowed_all_children:
"all_children (cdt_change_allowed aag subject (cdt s) (tcb_states_of_state s)) (cdt s)"
by (rule all_childrenI) (erule cdt_change_allowed_to_child)
abbreviation cleanup_info_wf :: "cap \<Rightarrow> 'a PAS \<Rightarrow> bool" where
"cleanup_info_wf c aag \<equiv> c \<noteq> NullCap \<and> \<not>is_arch_cap c
\<longrightarrow> (\<exists>irq. c = (IRQHandlerCap irq) \<and> is_subject_irq aag irq)"
(* FIXME: MOVE *)
named_theorems wp_transferable
named_theorems wp_not_transferable
context CNode_AC_1 begin
crunch deleted_irq_handler
for respects[wp]: "integrity aag X st"
lemma post_cap_deletion_integrity[wp]:
"\<lbrace>integrity aag X s and K (cleanup_info_wf cleanup_info aag)\<rbrace>
post_cap_deletion cleanup_info
\<lbrace>\<lambda>_. integrity aag X s\<rbrace>"
by (wpsimp simp: post_cap_deletion_def is_cap_simps wp: arch_post_cap_deletion_integrity)
lemma empty_slot_integrity_spec:
notes split_paired_All[simp del]
shows
"s \<turnstile> \<lbrace>valid_list and valid_mdb and valid_objs and pas_refined aag
and K (is_subject aag (fst slot) \<and> cleanup_info_wf cleanup_info aag)\<rbrace>
empty_slot slot cleanup_info
\<lbrace>\<lambda>_. integrity aag X s\<rbrace>"
apply (simp add: spec_valid_def)
apply (simp add: empty_slot_def)
apply (wp add: get_cap_wp set_cap_integrity_autarch set_original_integrity_autarch
empty_slot_extended_list_integ_lift empty_slot_list_integrity[where m="cdt s"]
| simp add: set_cdt_def | wpc)+
apply (safe; \<comment> \<open>for speedup\<close>
(clarsimp simp add: integrity_def)?,
blast intro: cca_owned cdt_change_allowed_all_children)
done
lemma empty_slot_integrity[wp,wp_not_transferable]:
"\<lbrace>integrity aag X st and valid_list and valid_objs and valid_mdb and pas_refined aag
and K (is_subject aag (fst slot) \<and> cleanup_info_wf c aag)\<rbrace>
empty_slot slot c
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (integrity_trans_start)
apply (rule hoare_pre)
apply (wp empty_slot_integrity_spec[simplified spec_valid_def])
by force
end
lemma reply_masters_mdbD1:
"\<lbrakk> reply_masters_mdb m cs ; cs slot = Some (ReplyCap t True R) \<rbrakk>
\<Longrightarrow> m slot = None"
by (fastforce simp:reply_masters_mdb_def simp del:split_paired_All)
lemma reply_cap_no_grand_parent:
"\<lbrakk> m \<Turnstile> pptr \<rightarrow>* slot ; reply_mdb m cs ; cs slot = Some (ReplyCap t False R) \<rbrakk>
\<Longrightarrow> pptr = slot \<or> (m \<Turnstile> pptr \<leadsto> slot \<and> (\<exists> R'. cs pptr = Some (ReplyCap t True R')))"
apply (clarsimp simp: reply_mdb_def del: disjCI)
apply (erule(1) reply_caps_mdbE)
apply (drule(1) reply_masters_mdbD1)
apply (erule rtrancl.cases, blast)
apply (erule rtrancl.cases, simp add: cdt_parent_of_def)
apply (simp add: cdt_parent_of_def)
done
(* FIXME MOVE ? *)
crunch set_cdt_list, update_cdt_list
for cdt[wp]: "\<lambda>s. P (cdt s)"
and kheap[wp]: "\<lambda>s. P (kheap s)"
and valid_mdb[wp]: "\<lambda>s. P (valid_mdb s)"
and valid_objs[wp]: "\<lambda>s. P (valid_objs s)"
and arch_state[wp]: "\<lambda>s. P (arch_state s)"
and thread_st_auth[wp]: "\<lambda>s. P (thread_st_auth s)"
and caps_of_state[wp]: "\<lambda>s. P (caps_of_state s)"
and is_original_cap[wp]: "\<lambda>s. P (is_original_cap s)"
and interrupt_irq_node[wp]: "\<lambda>s. P (interrupt_irq_node s)"
and thread_bound_ntfns[wp]: "\<lambda>s. P (thread_bound_ntfns s)"
locale CNode_AC_2 = CNode_AC_1 +
assumes integrity_asids_set_cap_Nullcap:
"\<lbrace>(=) s\<rbrace> set_cap NullCap slot \<lbrace>\<lambda>_. integrity_asids aag subjects x a (s :: det_ext state)\<rbrace>"
and set_original_state_asids_to_policy[wp]:
"\<And>P. set_original slot v \<lbrace>\<lambda>s. P (state_asids_to_policy aag s)\<rbrace>"
and set_original_state_objs_to_policy[wp]:
"\<And>P. set_original slot v \<lbrace>\<lambda>s. P (state_objs_to_policy s)\<rbrace>"
and set_cdt_list_state_vrefs[wp]:
"\<And>P. set_cdt_list t \<lbrace>\<lambda>s. P (state_vrefs s)\<rbrace>"
and set_cdt_list_state_asids_to_policy[wp]:
"\<And>P. set_cdt_list t \<lbrace>\<lambda>s. P (state_asids_to_policy aag s)\<rbrace>"
and update_cdt_list_state_vrefs[wp]:
"\<And>P. update_cdt_list f \<lbrace>\<lambda>s. P (state_vrefs s)\<rbrace>"
and update_cdt_list_state_asids_to_policy[wp]:
"\<And>P. update_cdt_list f \<lbrace>\<lambda>s. P (state_asids_to_policy aag s)\<rbrace>"
begin
crunch set_original
for tcb_domain_map_wellformed[wp]: "\<lambda>s. P (tcb_domain_map_wellformed aag s)"
and state_irqs_to_policy[wp]: "\<lambda>s. P (state_irqs_to_policy aag s)"
and cdt_change_allowed[wp]: "\<lambda>s. P (cdt_change_allowed' aag slot s)"
and irq_map_wellformed[wp]: "\<lambda>s. P (irq_map_wellformed aag s)"
and pas_refined[wp]: "\<lambda>s. P (pas_refined aag s)"
and valid_objs[wp]: "\<lambda>s. P (valid_objs s)"
and cte_wp_at[wp]: "cte_wp_at P slot"
(simp: state_objs_to_policy_def pas_refined_def)
lemma set_cap_integrity_deletion_aux:
"\<lbrace>integrity aag X st and valid_mdb and valid_objs and pas_refined aag and is_transferable_in slot
and cdt_change_allowed' aag slot and K(\<not> is_subject aag (fst slot))\<rbrace>
set_cap NullCap slot
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (integrity_trans_start)
apply (rule hoare_pre)
apply (unfold integrity_subjects_def)[1]
apply (wp hoare_wp_combs)
apply (unfold set_cap_def)[1]
apply (wpc)
apply (wp set_object_wp)
apply wpc
apply wp+
apply (wp get_object_wp)
apply wps
apply (wp integrity_asids_set_cap_Nullcap hoare_vcg_all_lift)
apply (safe ; clarsimp simp add: cte_wp_at_caps_of_state dest!: ko_atD)
(* cnode *)
subgoal for s obj addr cnode_size content cap'
apply (rule tro_cnode, simp, simp)
apply (rule cnode_integrityI)
apply simp
apply (intro impI disjI2)
apply (frule_tac addr=addr in caps_of_state_cnode, simp)
apply clarsimp
apply (erule is_transferable.cases, blast)
apply (fastforce intro: reply_cap_deletion_integrity_intros)
apply clarsimp
apply (rule reply_cap_deletion_integrityI2[OF refl refl])
apply (elim cdt_change_allowedE cdt_direct_change_allowed.cases)
apply (drule reply_cap_no_grand_parent[where cs="caps_of_state s"]; fastforce?)
apply (fastforce simp: aag_cap_auth_def cap_auth_conferred_def reply_cap_rights_to_auth_def
dest: cap_auth_caps_of_state pas_refined_Control)
apply (fastforce dest: tcb_states_of_state_kheapD descendant_of_caller_slot[OF _ _ tcb_atI]
parent_of_rtrancl_no_descendant)
done
(* tcb_ctable *)
subgoal for s obj tcb
apply (rule_tac tro_tcb_empty_ctable, simp, simp, simp)
apply (frule_tac addr="tcb_cnode_index 0" in caps_of_state_tcb)
apply clarsimp
apply (elim is_transferable.cases, simp)
apply (fastforce intro: reply_cap_deletion_integrity_intros)
apply clarsimp
apply (rule reply_cap_deletion_integrityI2[OF refl refl])
apply (elim cdt_change_allowedE cdt_direct_change_allowed.cases)
apply (force simp: aag_cap_auth_def cap_auth_conferred_def reply_cap_rights_to_auth_def
dest: reply_cap_no_grand_parent cap_auth_caps_of_state pas_refined_Control)
apply (fastforce simp: direct_call_def
dest: tcb_caller_slot_empty_on_recieve parent_of_rtrancl_no_descendant
descendant_of_caller_slot[OF _ _ tcb_atI] tcb_states_of_state_kheapD)
done
(* tcb_vtable *)
apply (rename_tac s obj tcb)
apply (rule tro_orefl)
apply (fastforce simp: caps_of_state_tcb valid_obj_def valid_tcb_def ran_tcb_cap_cases
elim:pspace_valid_objsE[OF _ invs_valid_objs] elim!:is_transferable.cases)
(* tcb_reply *)
apply (rename_tac s obj tcb)
apply (rule tro_orefl)
apply (fastforce simp: is_cap_simps caps_of_state_tcb valid_obj_def valid_tcb_def
ran_tcb_cap_cases
elim: pspace_valid_objsE[OF _ invs_valid_objs] elim!:is_transferable.cases)
(* tcb_caller *)
subgoal for s obj tcb
apply (rule_tac tro_tcb_empty_caller, simp, simp, simp)
apply (frule_tac addr="tcb_cnode_index 3" in caps_of_state_tcb)
apply clarsimp
apply (elim is_transferable.cases, simp)
apply (fastforce intro: reply_cap_deletion_integrity_intros)
apply clarsimp
apply (rule reply_cap_deletion_integrityI2[OF refl refl])
apply (elim cdt_change_allowedE cdt_direct_change_allowed.cases)
apply (force simp:aag_cap_auth_def cap_auth_conferred_def reply_cap_rights_to_auth_def
dest: reply_cap_no_grand_parent cap_auth_caps_of_state pas_refined_Control)
apply (fastforce simp: direct_call_def
dest: tcb_caller_slot_empty_on_recieve parent_of_rtrancl_no_descendant
descendant_of_caller_slot[OF _ _ tcb_atI] tcb_states_of_state_kheapD)
done
(* tcb_ipcframe*)
apply (rename_tac s obj tcb)
apply (rule tro_orefl)
apply (fastforce simp: is_nondevice_page_cap_simps caps_of_state_tcb
valid_obj_def valid_tcb_def ran_tcb_cap_cases
elim: pspace_valid_objsE[OF _ invs_valid_objs] elim!:is_transferable.cases)
done
lemma set_cap_integrity_deletion[wp_transferable]:
"\<lbrace>integrity aag X st and valid_mdb and valid_objs
and pas_refined aag and cdt_change_allowed' aag slot\<rbrace>
set_cap NullCap slot
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply (cases "is_subject aag (fst slot)")
apply (wpsimp wp: set_cap_integrity_autarch)
apply (wpsimp wp: set_cap_integrity_deletion_aux)
by (fastforce dest: cca_to_transferable_or_subject simp: cte_wp_at_caps_of_state)
lemma update_cdt_list_pas_refined[wp]:
"update_cdt_list f \<lbrace>pas_refined aag\<rbrace>"
by (wpsimp simp: pas_refined_def state_objs_to_policy_def | wps)+
end
text \<open>
For the @{const empty_slot} proof, we need to rearrange the operations
so that the CDT is updated after emptying the slot. Here we prove the
rearrangement is valid.
\<close>
(* Flesh out the monad_commute framework.
* FIXME: MOVE *)
lemma monad_commuteI2:
"monad_commute P (f :: ('s, unit) nondet_monad) g \<Longrightarrow> (\<And>s. P s) \<Longrightarrow>
(do f; g od) = (do g; f od)"
by (monad_eq simp: monad_commute_def)
lemmas monad_commute_split2 = monad_commute_split[THEN commute_commute]
lemma modify_modify_commute:
"monad_commute (\<lambda>s. f (g s) = g (f s)) (modify f) (modify g)"
by (monad_eq simp: monad_commute_def)
lemma modify_gets_commute:
"monad_commute (\<lambda>s. g (f s) = g s) (modify f) (gets g)"
by (monad_eq simp: monad_commute_def)
lemma set_eq_iff_imp:
"(A = B) = ((\<forall>x. x \<in> A \<longrightarrow> x \<in> B) \<and> (\<forall>x. x \<in> B \<longrightarrow> x \<in> A))"
by blast
lemma modify_get_commute:
"(\<And>s0. \<lbrace>(=) s0\<rbrace> g \<lbrace>\<lambda>r t. s0 = t\<rbrace>)
\<Longrightarrow> monad_commute (\<lambda>s. fst ` fst (g (f s)) = fst ` fst (g s) \<and>
snd (g (f s)) = snd (g s)) (modify f) g"
(* FIXME: proof cleanup *)
apply (monad_eq simp: monad_commute_def valid_def
set_eq_iff_imp[where A="fst ` fst _"] image_iff)
apply atomize
apply (intro conjI; clarsimp)
apply (rename_tac s0 r t)
apply (clarsimp split: prod.splits)
apply (rule_tac x=s0 in exI)
apply (rule conjI)
apply (drule_tac x=s0 in spec)
apply fastforce
apply fastforce
apply (rename_tac s0 r t)
apply (clarsimp split: prod.splits)
apply (subgoal_tac "t = s0")
apply (drule_tac x="f t" in spec)
apply fastforce
apply fastforce
done
(* We use this version for the automation: the precond that falls out
* will look like "\<forall>x. (\<exists>r. r \<in> fst (gets ?foo (?upd s)) \<and> x = fst r) = \<dots>"
* which the monad_eq method can easily reduce with in_monad rules. *)
lemmas modify_get_commute' =
modify_get_commute[simplified set_eq_iff image_iff Ball_def Bex_def]
lemma put_as_modify:
"put t = modify (\<lambda>_. t)"
by monad_eq
lemma put_commuteI:
"monad_commute P f (modify (\<lambda>_. t)) \<Longrightarrow> monad_commute P f (put t)"
by (simp add: put_as_modify)
lemma get_commuteI:
"monad_commute P f (gets (\<lambda>s. s)) \<Longrightarrow> monad_commute P f get"
by (simp add: gets_def)
lemma gets_gets_commute:
"monad_commute \<top> (gets f) (gets g)"
by (monad_eq simp: monad_commute_def)
lemma gets_get_commute:
"(\<And>s0. \<lbrace>(=) s0\<rbrace> g \<lbrace>\<lambda>r t. s0 = t\<rbrace>) \<Longrightarrow>
monad_commute \<top> (gets f) g"
by (monad_eq simp: monad_commute_def valid_def) fastforce
lemma assert_commute':
"empty_fail f \<Longrightarrow> monad_commute \<top> (assert G) f"
by (monad_eq simp: monad_commute_def empty_fail_def) fastforce
named_theorems monad_commute_wp
lemmas[monad_commute_wp] =
monad_commute_split
monad_commute_split2
modify_modify_commute
gets_gets_commute
put_commuteI put_commuteI[THEN commute_commute]
get_commuteI get_commuteI[THEN commute_commute]
return_commute return_commute[THEN commute_commute]
assert_commute' assert_commute'[THEN commute_commute]
(* Sort-of VCG for monad_commute goals *)
lemma wpc_helper_monad_commute:
"monad_commute P f g \<Longrightarrow> wpc_helper (P, P', P'') (Q, Q', Q'') (monad_commute P f g)"
by (clarsimp simp: wpc_helper_def)
wpc_setup "\<lambda>m. monad_commute P f m" wpc_helper_monad_commute
method monad_commute_wpc =
(match conclusion in "monad_commute _ _ _" \<Rightarrow> succeed),
(wpc | (rule commute_commute, wpc))
method monad_commute_step methods more_solver =
determ \<open>wp monad_commute_wp\<close>
| (* Conditional rules for fully schematic programs fragments:
* make sure to solve the first condition before continuing *)
(rule modify_get_commute' modify_get_commute'[THEN commute_commute],
solves \<open>(changed \<open>wp | more_solver\<close>)+\<close>)
| more_solver
method monad_commute methods more_solver =
((monad_commute_wpc; rule monad_commute_guard_imp),
(monad_commute more_solver, more_solver)+)
| (monad_commute_step more_solver,
((changed \<open>monad_commute more_solver\<close>)+)?)[1]
method monad_commute_default =
monad_commute \<open>solves \<open>monad_eq\<close>
| solves \<open>(wpc, (changed \<open>wp | fastforce\<close>)+)\<close>
| solves \<open>(changed \<open>wp | fastforce\<close>)+\<close>
| fastforce\<close>
(* Now the commute steps *)
(* FIXME: remove and generalise version in ainvs *)
lemma set_original_set_cap_comm:
"(do set_original slot' val; set_cap cap slot od) =
(do set_cap cap slot; set_original slot' val od)"
apply (rule ext)
apply (clarsimp simp: bind_def split_def set_cap_def set_original_def
get_object_def set_object_def get_def put_def
simpler_gets_def simpler_modify_def
assert_def fail_def)
apply (case_tac y; simp add: return_def fail_def)
done
lemma set_cdt_set_cap_comm:
"(do set_cdt c; set_cap cap slot od) =
(do set_cap cap slot; set_cdt c od)"
apply (rule ext)
apply (clarsimp simp: bind_def split_def set_cap_def set_cdt_def
get_object_def set_object_def get_def put_def
simpler_gets_def simpler_modify_def
assert_def fail_def)
apply (case_tac y; simp add: return_def fail_def)
done
lemma set_cdt_set_original_comm:
"(do set_cdt c; set_original slot val od) =
(do set_original slot val; set_cdt c od)"
apply (clarsimp simp: set_cdt_def[folded modify_def]
set_original_def[folded gets_modify_def]
get_object_def set_object_def
simp del: K_bind_def)
apply (simp only: modify_def[symmetric])
apply (rule monad_commuteI2)
apply monad_commute_default
apply monad_eq
done
lemma set_cdt_empty_slot_ext_comm:
"(do set_cdt c; empty_slot_ext slot slot_p od) =
(do empty_slot_ext slot slot_p; set_cdt c od)"
supply K_bind_def[simp del]
apply (clarsimp simp: set_cdt_def empty_slot_ext_def
update_cdt_list_def set_cdt_list_def)
apply (simp only: modify_def[symmetric])
apply (rule monad_commuteI2)
apply monad_commute_default
apply monad_eq
done
lemma set_cap_empty_slot_ext_comm:
"(do set_cap cap slot; empty_slot_ext slot' slot_p od) =
(do empty_slot_ext slot' slot_p; set_cap cap slot od)"
apply (rule ext)
apply (clarsimp simp: bind_def split_def set_cap_def empty_slot_ext_def
update_cdt_list_def set_cdt_list_def
get_object_def set_object_def get_def put_def
simpler_gets_def simpler_modify_def
assert_def fail_def)
apply (case_tac y; simp add: return_def fail_def split: option.splits)
done
lemma K_bind_assoc:
"(do (do f; g od); h od) = (do f; g; h od)"
by (simp add: bind_assoc)
lemmas K_bind_eqI = arg_cong2[where f="\<lambda>f g. do f; g od"]
lemmas K_bind_eqI' = K_bind_eqI[OF _ refl]
lemma aag_cap_auth_max_free_index_update[simp]:
"aag_cap_auth aag (pasObjectAbs aag x) (max_free_index_update y) =
aag_cap_auth aag (pasObjectAbs aag x) y"
by (clarsimp simp: aag_cap_auth_def free_index_update_def cap_links_asid_slot_def cap_links_irq_def
split: cap.splits)
context CNode_AC_2 begin
(* Putting it all together *)
lemma empty_slot_shuffle:
"(do set_cdt c;
empty_slot_ext slot slot_p;
set_original slot False;
set_cap NullCap slot;
post_cap_deletion NullCap od) =
(do set_cap NullCap slot;
empty_slot_ext slot slot_p;
set_original slot False;
set_cdt c;
post_cap_deletion NullCap od :: (det_ext state \<Rightarrow> _))"
by (simp only: set_cdt_empty_slot_ext_comm[THEN K_bind_eqI', simplified K_bind_assoc]
set_cdt_set_original_comm[THEN K_bind_eqI', simplified K_bind_assoc]
set_cdt_set_cap_comm[THEN K_bind_eqI', simplified K_bind_assoc]
set_original_set_cap_comm[THEN K_bind_eqI', simplified K_bind_assoc]
set_cap_empty_slot_ext_comm[THEN K_bind_eqI', simplified K_bind_assoc])
lemma empty_slot_integrity_transferable[wp_transferable]:
"\<lbrace>integrity aag X st and valid_list and valid_objs and valid_mdb and pas_refined aag
and cdt_change_allowed' aag slot and K (c = NullCap)\<rbrace>
empty_slot slot c
\<lbrace>\<lambda>_. integrity aag X st\<rbrace>"
apply integrity_trans_start
apply (rule hoare_pre)
apply (simp add: empty_slot_def)
apply (simp add: empty_slot_shuffle[simplified])
apply (simp add: set_cdt_def)
apply (wp set_original_wp)
apply (rename_tac cdtv x)
apply (rule_tac Q'="\<lambda>_ s'. integrity aag X s s'\<and> cdtv = cdt s \<and>
is_original_cap s = is_original_cap s'"
in hoare_post_imp)
apply (clarsimp simp add: integrity_def)
apply (frule all_childrenD[OF cdt_change_allowed_all_children];fastforce)
apply (wp empty_slot_extended_list_integ_lift)
apply (rule hoare_pre)
apply (rule_tac m = "cdt s" in empty_slot_list_integrity)
apply simp
apply wp+
apply (wp set_cap_integrity_deletion gets_wp get_cap_wp)+
by (fastforce intro: cdt_change_allowed_all_children)
lemma set_cdt_pas_refined:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows "\<lbrace>pas_refined aag and (\<lambda>s. \<forall>x y. c x = Some y \<and> cdt s x \<noteq> Some y
\<longrightarrow> (is_transferable (caps_of_state s x) \<or>
abs_has_auth_to aag Control (fst y) (fst x)) \<and>
abs_has_auth_to aag DeleteDerived (fst y) (fst x))\<rbrace>
set_cdt c
\<lbrace>\<lambda>_. pas_refined aag\<rbrace>"
apply (simp add: pas_refined_def state_objs_to_policy_def set_cdt_def)
apply (wp | simp | simp_all)+
apply (clarsimp dest!: auth_graph_map_memD)
apply (subgoal_tac
"\<forall>x y. c x = Some y \<longrightarrow>
(is_transferable (caps_of_state s x) \<or> abs_has_auth_to aag Control (fst y) (fst x))
\<and> abs_has_auth_to aag DeleteDerived (fst y) (fst x)")
defer
apply (intro allI, case_tac "cdt s x = Some y")
apply (solves\<open>auto intro: auth_graph_map_memI state_bits_to_policy.intros\<close>)
apply (fastforce dest!: spec elim!: mp)
apply (erule state_bits_to_policy.cases)
apply (auto intro: auth_graph_map_memI state_bits_to_policy.intros
split: if_split_asm | blast)+
done
lemma pas_refined_original_cap_update[simp]:
"pas_refined aag (is_original_cap_update f s) = pas_refined aag s"
by (simp add: pas_refined_def state_objs_to_policy_def)
lemma pas_refined_machine_state_update[simp]:
"pas_refined aag (machine_state_update f s) = pas_refined aag s"
by (simp add: pas_refined_def state_objs_to_policy_def state_refs_of_def)
lemma pas_refined_interrupt_states_update[simp]:
"pas_refined aag (interrupt_states_update f s) = pas_refined aag s"
by (simp add: pas_refined_def state_objs_to_policy_def state_refs_of_def)
crunch deleted_irq_handler
for pas_refined[wp]: "pas_refined aag"
crunch set_untyped_cap_as_full
for pas_refined: "pas_refined aag"
lemmas set_untyped_cap_as_full_pas_refined'[wp] = set_untyped_cap_as_full_pas_refined[simplified]
lemma update_cdt_pas_refined:
"\<lbrace>pas_refined aag and (\<lambda>s. \<forall>x y. c (cdt s) x = Some y \<and> cdt s x \<noteq> Some y
\<longrightarrow> (is_transferable (caps_of_state s x) \<or>
abs_has_auth_to aag Control (fst y) (fst x))
\<and> abs_has_auth_to aag DeleteDerived (fst y) (fst x))\<rbrace>
update_cdt c
\<lbrace>\<lambda>_. pas_refined aag\<rbrace>"
apply (simp add: update_cdt_def)
apply (wp set_cdt_pas_refined)
apply simp
done
lemma state_objs_to_policy_more_update[simp]:
"state_objs_to_policy (trans_state f s) =
state_objs_to_policy s"
by (simp add: state_objs_to_policy_def)
end
lemma set_untyped_cap_as_full_cdt_is_original_cap:
"\<lbrace>\<lambda>s. P (cdt s) (is_original_cap s)\<rbrace>
set_untyped_cap_as_full src_cap new_cap src_slot
\<lbrace>\<lambda>_ s. P (cdt s) (is_original_cap s)\<rbrace>"
unfolding set_untyped_cap_as_full_def
apply (rule hoare_pre)
apply (wp set_cap_caps_of_state2)
apply clarsimp
done
(* FIXME MOVE *)
lemma untyped_not_transferable:
"is_untyped_cap cap \<Longrightarrow> \<not> is_transferable (Some cap)"
by (fastforce simp: is_cap_simps elim!: is_transferable.cases)
(* FIXME MOVE *)
lemma is_transferable_max_free_index_update[simp]:
"is_transferable (Some (max_free_index_update cap)) = is_transferable (Some cap)"
by (simp add: is_transferable.simps free_index_update_def split: cap.splits)
lemma set_untyped_cap_as_full_is_transferable[wp]:
"set_untyped_cap_as_full src_cap new_cap slot \<lbrace>\<lambda>s. \<not> is_transferable (caps_of_state s other_slot)\<rbrace>"
apply (clarsimp simp: set_untyped_cap_as_full_def)
apply wp
using untyped_not_transferable max_free_index_update_preserve_untyped by simp
lemma set_untyped_cap_as_full_is_transferable':
"\<lbrace>\<lambda>s. is_transferable (((caps_of_state s)(slot2 \<mapsto> new_cap)) slot3) \<and>
Some src_cap = (caps_of_state s slot)\<rbrace>
set_untyped_cap_as_full src_cap new_cap slot
\<lbrace>\<lambda>_ s. is_transferable (((caps_of_state s)(slot2 \<mapsto> new_cap)) slot3)\<rbrace>"
apply (clarsimp simp: set_untyped_cap_as_full_def)
apply safe
apply (wp,fastforce)+
done
lemma cap_links_irq_Nullcap [simp]:
"cap_links_irq aag l NullCap" unfolding cap_links_irq_def by simp
lemma aag_cap_auth_NullCap [simp]:
"aag_cap_auth aag l NullCap"
unfolding aag_cap_auth_def
by (simp add: clas_no_asid)
crunch set_cdt
for thread_st_auth[wp]: "\<lambda>s. P (thread_st_auth s)"
crunch set_cdt
for thread_bound_ntfns[wp]: "\<lambda>s. P (thread_bound_ntfns s)"
locale CNode_AC_3 = CNode_AC_2 +
assumes cap_move_ext_pas_refined_tcb_domain_map_wellformed[wp]:
"\<And>a b c d. cap_move_ext a b c d \<lbrace>tcb_domain_map_wellformed aag\<rbrace>
\<Longrightarrow> cap_move_ext a b c d \<lbrace>pas_refined aag\<rbrace>"
and cap_insert_ext_pas_refined_tcb_domain_map_wellformed[wp]: