-
Notifications
You must be signed in to change notification settings - Fork 108
/
CNodeInv_AI.thy
3655 lines (3052 loc) · 142 KB
/
CNodeInv_AI.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 2014, General Dynamics C4 Systems
*
* SPDX-License-Identifier: GPL-2.0-only
*)
(*
Results about CNode Invocations, particularly the
recursive revoke and delete operations.
*)
theory CNodeInv_AI
imports ArchIpc_AI
begin
arch_requalify_facts
cte_at_length_limit
arch_derive_cap_untyped
valid_arch_mdb_cap_swap
declare set_cap_arch[wp]
primrec
valid_cnode_inv :: "cnode_invocation \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_cnode_inv (InsertCall cap ptr ptr') =
(valid_cap cap and real_cte_at ptr and real_cte_at ptr' and
(\<lambda>s. cte_wp_at (is_derived (cdt s) ptr cap) ptr s) and
cte_wp_at (\<lambda>c. c = NullCap) ptr' and
ex_cte_cap_wp_to is_cnode_cap ptr' and K (ptr \<noteq> ptr') and
(\<lambda>s. \<forall>r\<in>obj_refs cap. \<forall>p'.
ptr' \<noteq> p' \<and> cte_wp_at (\<lambda>cap'. r \<in> obj_refs cap') p' s \<longrightarrow>
cte_wp_at (Not \<circ> is_zombie) p' s \<and> \<not> is_zombie cap))"
| "valid_cnode_inv (MoveCall cap ptr ptr') =
(valid_cap cap and cte_wp_at ((=) cap.NullCap) ptr' and
cte_wp_at ((\<noteq>) NullCap) ptr and cte_wp_at (weak_derived cap) ptr and
cte_wp_at (\<lambda>c. is_untyped_cap c \<longrightarrow> c = cap) ptr and
ex_cte_cap_wp_to is_cnode_cap ptr' and
real_cte_at ptr and real_cte_at ptr')"
| "valid_cnode_inv (RevokeCall ptr) = cte_at ptr"
| "valid_cnode_inv (DeleteCall ptr) = real_cte_at ptr"
| "valid_cnode_inv (RotateCall s_cap p_cap src pivot dest) =
(valid_cap s_cap and valid_cap p_cap and
real_cte_at src and real_cte_at dest and real_cte_at pivot and
cte_wp_at (weak_derived s_cap) src and
cte_wp_at (\<lambda>c. is_untyped_cap c \<longrightarrow> c = s_cap) src and
cte_wp_at ((\<noteq>) NullCap) src and
cte_wp_at (weak_derived p_cap) pivot and
cte_wp_at (\<lambda>c. is_untyped_cap c \<longrightarrow> c = p_cap) pivot and
cte_wp_at ((\<noteq>) NullCap) pivot and K (src \<noteq> pivot \<and> pivot \<noteq> dest) and
(\<lambda>s. src \<noteq> dest \<longrightarrow> cte_wp_at (\<lambda>c. c = NullCap) dest s) and
ex_cte_cap_wp_to is_cnode_cap pivot and ex_cte_cap_wp_to is_cnode_cap dest)"
| "valid_cnode_inv (SaveCall ptr) =
(ex_cte_cap_wp_to is_cnode_cap ptr and
cte_wp_at (\<lambda>c. c = NullCap) ptr and real_cte_at ptr)"
| "valid_cnode_inv (CancelBadgedSendsCall cap) =
(valid_cap cap and K (has_cancel_send_rights cap))"
primrec
valid_rec_del_call :: "rec_del_call \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_rec_del_call (CTEDeleteCall slot _) = \<top>"
| "valid_rec_del_call (FinaliseSlotCall slot _) = \<top>"
| "valid_rec_del_call (ReduceZombieCall cap slot _) =
(cte_wp_at ((=) cap) slot and is_final_cap' cap
and K (is_zombie cap))"
locale CNodeInv_AI =
fixes state_ext_t :: "'state_ext::state_ext itself"
assumes derive_cap_objrefs:
"\<And>P cap slot.
\<lbrace>\<lambda>s::'state_ext state. P (obj_refs cap)\<rbrace>
derive_cap slot cap
\<lbrace>\<lambda>rv s. rv \<noteq> NullCap \<longrightarrow> P (obj_refs rv)\<rbrace>,-"
assumes derive_cap_zobjrefs:
"\<And>P cap slot.
\<lbrace>\<lambda>s::'state_ext state. P (zobj_refs cap)\<rbrace>
derive_cap slot cap
\<lbrace>\<lambda>rv s. rv \<noteq> NullCap \<longrightarrow> P (zobj_refs rv)\<rbrace>,-"
assumes update_cap_objrefs:
"\<And>P dt cap. \<lbrakk> update_cap_data P dt cap \<noteq> NullCap \<rbrakk> \<Longrightarrow>
obj_refs (update_cap_data P dt cap) = obj_refs cap"
assumes update_cap_zobjrefs:
"\<And>P dt cap. \<lbrakk> update_cap_data P dt cap \<noteq> cap.NullCap \<rbrakk> \<Longrightarrow>
zobj_refs (update_cap_data P dt cap) = zobj_refs cap"
assumes copy_mask [simp]:
"\<And>R c. copy_of (mask_cap R c) = copy_of c"
assumes update_cap_data_mask_Null [simp]:
"\<And>P x m c. (update_cap_data P x (mask_cap m c) = NullCap) = (update_cap_data P x c = NullCap)"
assumes cap_master_update_cap_data:
"\<And>P x c. \<lbrakk> update_cap_data P x c \<noteq> NullCap \<rbrakk> \<Longrightarrow>
cap_master_cap (update_cap_data P x c) = cap_master_cap c"
assumes same_object_as_cap_master:
"\<And>cap cap'. same_object_as cap cap' \<Longrightarrow> cap_master_cap cap = cap_master_cap cap'"
assumes cap_asid_update_cap_data:
"\<And>P x c. update_cap_data P x c \<noteq> NullCap \<Longrightarrow> cap_asid (update_cap_data P x c) = cap_asid c"
assumes cap_vptr_update_cap_data:
"\<And>P x c. update_cap_data P x c \<noteq> NullCap \<Longrightarrow> cap_vptr (update_cap_data P x c) = cap_vptr c"
assumes cap_asid_base_update_cap_data:
"\<And>P x c. update_cap_data P x c \<noteq> NullCap \<Longrightarrow>
cap_asid_base (update_cap_data P x c) = cap_asid_base c"
assumes same_object_as_update_cap_data:
"\<And>P x c c'. \<lbrakk> update_cap_data P x c \<noteq> NullCap; same_object_as c' c \<rbrakk> \<Longrightarrow>
same_object_as c' (update_cap_data P x c)"
assumes weak_derived_update_cap_data:
"\<And>P x c c'. \<lbrakk>update_cap_data P x c \<noteq> NullCap; weak_derived c c'\<rbrakk> \<Longrightarrow>
weak_derived (update_cap_data P x c) c'"
assumes cap_badge_update_cap_data:
"\<And>x c bdg. update_cap_data False x c \<noteq> NullCap \<and> (bdg, cap_badge c) \<in> capBadge_ordering False
\<longrightarrow> (bdg, cap_badge (update_cap_data False x c)) \<in> capBadge_ordering False"
assumes cap_vptr_rights_update[simp]:
"\<And>f c. cap_vptr (cap_rights_update f c) = cap_vptr c"
assumes cap_vptr_mask[simp]:
"\<And>m c. cap_vptr (mask_cap m c) = cap_vptr c"
assumes cap_asid_base_rights [simp]:
"\<And>R c. cap_asid_base (cap_rights_update R c) = cap_asid_base c"
assumes cap_asid_base_mask[simp]:
"\<And>m c. cap_asid_base (mask_cap m c) = cap_asid_base c"
assumes weak_derived_mask:
"\<And>c c' m. \<lbrakk> weak_derived c c'; cap_aligned c \<rbrakk> \<Longrightarrow> weak_derived (mask_cap m c) c'"
assumes vs_cap_ref_update_cap_data[simp]:
"\<And>P d cap. vs_cap_ref (update_cap_data P d cap) = vs_cap_ref cap"
assumes weak_derived_cap_is_device:
"\<And>c c'. \<lbrakk>weak_derived c' c\<rbrakk> \<Longrightarrow> cap_is_device c = cap_is_device c'"
assumes invs_irq_state_independent[intro!, simp]:
"\<And>(s::'state_ext state) f.
invs (s\<lparr>machine_state := machine_state s\<lparr>irq_state := f (irq_state (machine_state s))\<rparr>\<rparr>)
= invs s"
assumes cte_at_nat_to_cref_zbits:
"\<And>(s::'state_ext state) oref zb n m.
\<lbrakk> s \<turnstile> Zombie oref zb n; m < n \<rbrakk> \<Longrightarrow> cte_at (oref, nat_to_cref (zombie_cte_bits zb) m) s"
assumes copy_of_cap_range:
"\<And>cap cap'. copy_of cap cap' \<Longrightarrow> cap_range cap = cap_range cap'"
assumes copy_of_zobj_refs:
"\<And>cap cap'. copy_of cap cap' \<Longrightarrow> zobj_refs cap = zobj_refs cap'"
assumes vs_cap_ref_master:
"\<And> cap cap'.
\<lbrakk> cap_master_cap cap = cap_master_cap cap';
cap_asid cap = cap_asid cap';
cap_asid_base cap = cap_asid_base cap';
cap_vptr cap = cap_vptr cap' \<rbrakk>
\<Longrightarrow> vs_cap_ref cap = vs_cap_ref cap'"
assumes weak_derived_vs_cap_ref:
"\<And>c c'. weak_derived c c' \<Longrightarrow> vs_cap_ref c = vs_cap_ref c'"
assumes weak_derived_table_cap_ref:
"\<And>c c'. weak_derived c c' \<Longrightarrow> table_cap_ref c = table_cap_ref c'"
assumes swap_of_caps_valid_arch_caps:
"\<And>c a c' b.
\<lbrace>valid_arch_caps and cte_wp_at (weak_derived c) a and cte_wp_at (weak_derived c') b\<rbrace>
do
y \<leftarrow> set_cap c b;
set_cap c' a
od
\<lbrace>\<lambda>rv. valid_arch_caps :: 'state_ext state \<Rightarrow> bool\<rbrace>"
assumes cap_swap_asid_map[wp]:
"\<And>c a c' b.
\<lbrace>valid_asid_map and cte_wp_at (weak_derived c) a and cte_wp_at (weak_derived c') b\<rbrace>
cap_swap c a c' b
\<lbrace>\<lambda>rv. valid_asid_map :: 'state_ext state \<Rightarrow> bool\<rbrace>"
assumes cap_swap_cap_refs_in_kernel_window[wp]:
"\<And>c a c' b.
\<lbrace>cap_refs_in_kernel_window and cte_wp_at (weak_derived c) a and cte_wp_at (weak_derived c') b\<rbrace>
cap_swap c a c' b
\<lbrace>\<lambda>rv. cap_refs_in_kernel_window :: 'state_ext state \<Rightarrow> bool\<rbrace>"
assumes cap_swap_ioports[wp]:
"\<lbrace>valid_ioports and cte_wp_at (weak_derived c) a and cte_wp_at (weak_derived c') b\<rbrace>
cap_swap c a c' b
\<lbrace>\<lambda>rv (s::'state_ext state). valid_ioports s\<rbrace>"
assumes cap_swap_vms[wp]:
"\<And>c a c' b.
\<lbrace>valid_machine_state :: 'state_ext state \<Rightarrow> bool\<rbrace>
cap_swap c a c' b
\<lbrace>\<lambda>rv. valid_machine_state\<rbrace>"
assumes unat_of_bl_nat_to_cref:
"\<And>n ln. \<lbrakk> n < 2 ^ ln; ln < word_bits \<rbrakk>
\<Longrightarrow> unat (of_bl (nat_to_cref ln n) :: machine_word) = n"
assumes zombie_is_cap_toE_pre:
"\<And>(s::'state_ext state) ptr zbits n m irqn.
\<lbrakk> s \<turnstile> Zombie ptr zbits n; invs s; m < n \<rbrakk>
\<Longrightarrow> (ptr, nat_to_cref (zombie_cte_bits zbits) m) \<in> cte_refs (Zombie ptr zbits n) irqn"
assumes finalise_cap_emptyable[wp]:
"\<And>sl c f.
\<lbrace>emptyable sl and invs\<rbrace>
finalise_cap c f
\<lbrace>\<lambda>_. emptyable sl :: 'state_ext state \<Rightarrow> bool\<rbrace>"
assumes deleting_irq_handler_emptyable[wp]:
"\<And>sl irq.
\<lbrace>emptyable sl and invs :: 'state_ext state \<Rightarrow> bool\<rbrace>
deleting_irq_handler irq
\<lbrace>\<lambda>_. emptyable sl\<rbrace>"
assumes arch_finalise_cap_emptyable[wp]:
"\<And>sl c f.
\<lbrace>emptyable sl :: 'state_ext state \<Rightarrow> bool\<rbrace>
arch_finalise_cap c f
\<lbrace>\<lambda>_. emptyable sl\<rbrace>"
assumes finalise_cap_not_reply_master_unlifted:
"\<And>rv s' cap sl (s::'state_ext state).
(rv, s') \<in> fst (finalise_cap cap sl s) \<Longrightarrow>
\<not> is_master_reply_cap (fst rv)"
assumes nat_to_cref_0_replicate:
"\<And>n. n < word_bits \<Longrightarrow> nat_to_cref n 0 = replicate n False"
assumes prepare_thread_delete_thread_cap:
"\<And>x p t. \<lbrace>\<lambda>(s::'state_ext state). caps_of_state s x = Some (cap.ThreadCap p)\<rbrace>
prepare_thread_delete t
\<lbrace>\<lambda>rv s. caps_of_state s x = Some (cap.ThreadCap p)\<rbrace>"
locale CNodeInv_AI_2 = CNodeInv_AI state_ext_t
for state_ext_t :: "'state_ext::state_ext itself" +
assumes rec_del_invs':
"\<And>(s::'state_ext state) call.
s \<turnstile> \<lbrace>\<lambda>x. invs x \<and> valid_rec_del_call call x \<and>
(\<not> exposed_rdcall call \<longrightarrow> ex_cte_cap_wp_to (\<lambda>cp. cap_irqs cp = {}) (slot_rdcall call) x) \<and>
emptyable (slot_rdcall call) x \<and>
(case call of ReduceZombieCall cap sl ex \<Rightarrow> \<not> cap_removeable cap sl \<and>
(\<forall>t\<in>obj_refs cap. halted_if_tcb t x)
| _ \<Rightarrow> True)\<rbrace>
rec_del call
\<lbrace>\<lambda>rv s. invs s \<and>
(case call of CTEDeleteCall _ bool \<Rightarrow> True
| FinaliseSlotCall sl x \<Rightarrow> (fst rv \<or> x \<longrightarrow> cte_wp_at (replaceable s sl NullCap) sl s) \<and>
(snd rv \<noteq> NullCap \<longrightarrow> post_cap_delete_pre (snd rv) ((caps_of_state s) (sl \<mapsto> cap.NullCap)))
| ReduceZombieCall cap sl x \<Rightarrow> \<not> x \<longrightarrow> ex_cte_cap_wp_to (\<lambda>cp. cap_irqs cp = {}) sl s) \<and>
emptyable (slot_rdcall call) s\<rbrace>,
\<lbrace>\<lambda>rv. invs\<rbrace>"
lemma mask_cap_all:
"mask_cap (all_rights \<inter> r) c = mask_cap r c"
unfolding all_rights_def by simp
lemma decode_cnode_cases2:
assumes mvins: "\<And>index bits src_index src_depth args' src_root_cap exs'.
\<lbrakk> args = index # bits # src_index # src_depth # args';
exs = src_root_cap # exs';
gen_invocation_type label \<in> set [CNodeCopy .e. CNodeMutate];
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller];
gen_invocation_type label \<notin> {CNodeRevoke, CNodeDelete,
CNodeCancelBadgedSends, CNodeRotate, CNodeSaveCaller} \<rbrakk> \<Longrightarrow> P"
assumes rvk: "\<And>index bits args'. \<lbrakk> args = index # bits # args';
gen_invocation_type label \<notin> set [CNodeCopy .e. CNodeMutate];
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller];
gen_invocation_type label = CNodeRevoke \<rbrakk> \<Longrightarrow> P"
assumes dlt: "\<And>index bits args'. \<lbrakk> args = index # bits # args';
gen_invocation_type label \<notin> set [CNodeCopy .e. CNodeMutate];
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller];
gen_invocation_type label = CNodeDelete \<rbrakk> \<Longrightarrow> P"
assumes svc: "\<And>index bits args'. \<lbrakk> args = index # bits # args';
gen_invocation_type label \<notin> set [CNodeCopy .e. CNodeMutate];
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller];
gen_invocation_type label = CNodeSaveCaller \<rbrakk> \<Longrightarrow> P"
assumes rcy: "\<And>index bits args'. \<lbrakk> args = index # bits # args';
gen_invocation_type label \<notin> set [CNodeCopy .e. CNodeMutate];
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller];
gen_invocation_type label = CNodeCancelBadgedSends \<rbrakk> \<Longrightarrow> P"
assumes rot: "\<And>index bits pivot_new_data pivot_index pivot_depth src_new_data
src_index src_depth args' pivot_root_cap src_root_cap exs'.
\<lbrakk> args = index # bits # pivot_new_data # pivot_index # pivot_depth
# src_new_data # src_index # src_depth # args';
exs = pivot_root_cap # src_root_cap # exs';
gen_invocation_type label \<notin> set [CNodeCopy .e. CNodeMutate];
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller];
gen_invocation_type label = CNodeRotate \<rbrakk> \<Longrightarrow> P"
assumes errs:
"\<lbrakk> gen_invocation_type label \<notin> set [CNodeRevoke .e. CNodeSaveCaller] \<or>
args = [] \<or> (\<exists>x. args = [x]) \<or> (\<exists>index bits args'. args = index # bits # args' \<and>
gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller] \<and>
(gen_invocation_type label \<in> set [CNodeCopy .e. CNodeMutate]
\<and> gen_invocation_type label \<notin> {CNodeRevoke, CNodeDelete,
CNodeCancelBadgedSends, CNodeRotate, CNodeSaveCaller}
\<and> (case (args', exs) of (src_index # src_depth # args'',
src_root_cap # exs') \<Rightarrow> False | _ \<Rightarrow> True) \<or>
gen_invocation_type label \<notin> set [CNodeCopy .e. CNodeMutate] \<and>
gen_invocation_type label = CNodeRotate \<and> (case (args', exs) of
(pivot_new_data # pivot_index # pivot_depth
# src_new_data # src_index # src_depth # args'',
pivot_root_cap # src_root_cap # exs') \<Rightarrow> False
| _ \<Rightarrow> True))) \<rbrakk> \<Longrightarrow> P"
shows "P"
proof -
have simps: "[CNodeRevoke .e. CNodeSaveCaller]
= [CNodeRevoke, CNodeDelete, CNodeCancelBadgedSends, CNodeCopy, CNodeMint,
CNodeMove, CNodeMutate, CNodeRotate, CNodeSaveCaller]"
"[CNodeCopy .e. CNodeMutate] = [CNodeCopy, CNodeMint,
CNodeMove, CNodeMutate]"
by (simp_all add: upto_enum_def fromEnum_def toEnum_def enum_invocation_label enum_gen_invocation_labels)
show ?thesis
apply (cases args)
apply (simp add: errs)
apply (case_tac list)
apply (simp add: errs)
apply (case_tac "gen_invocation_type label \<in> set [CNodeCopy .e. CNodeMutate]")
apply (case_tac "case (lista, exs) of (src_index # src_depth # args'',
src_root_cap # exs'') \<Rightarrow> False | _ \<Rightarrow> True")
apply (rule errs)
apply (simp add: simps)
apply (rule disjI2)
apply auto[1]
apply (simp split: prod.split_asm list.split_asm)
apply (erule(2) mvins, auto simp: simps)[1]
apply (case_tac "gen_invocation_type label \<in> set [CNodeRevoke .e. CNodeSaveCaller]")
apply (simp_all add: errs)
apply (insert rvk dlt svc rcy rot)
apply (simp add: simps)
apply atomize
apply (elim disjE, simp_all)
apply (case_tac "case (lista, exs) of
(pivot_new_data # pivot_index # pivot_depth
# src_new_data # src_index # src_depth # args'',
pivot_root_cap # src_root_cap # exs') \<Rightarrow> False
| _ \<Rightarrow> True")
apply (rule errs)
apply (simp add: simps)
apply (simp split: prod.split_asm list.split_asm)
done
qed
lemma Suc_length_not_empty:
"length xs = length xs' \<Longrightarrow> Suc 0 \<le> length xs' = (xs \<noteq> [])"
by (fastforce simp: le_simps)
lemma update_cap_hoare_helper:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. valid_cap (C rv s) s\<rbrace> \<Longrightarrow>
\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. valid_cap (update_cap_data prs n (C rv s)) s\<rbrace>"
apply (erule hoare_strengthen_post)
apply (erule update_cap_data_validI)
done
lemma mask_cap_hoare_helper:
"\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. valid_cap (C rv s) s\<rbrace> \<Longrightarrow>
\<lbrace>P\<rbrace> f \<lbrace>\<lambda>rv s. valid_cap (mask_cap (M rv s) (C rv s)) s\<rbrace>"
by (fastforce simp add: valid_def)
lemma derive_cap_untyped:
"\<lbrace>\<lambda>s. P (untyped_range cap)\<rbrace> derive_cap slot cap \<lbrace>\<lambda>rv s. rv \<noteq> cap.NullCap \<longrightarrow> P (untyped_range rv)\<rbrace>,-"
unfolding derive_cap_def is_zombie_def
by (cases cap; (wp ensure_no_children_inv arch_derive_cap_untyped | simp add: o_def)+)
lemma zombies_final_helper:
"\<lbrakk> cte_wp_at (\<lambda>c. c = cap) p s; \<not> is_zombie cap; zombies_final s \<rbrakk>
\<Longrightarrow> (\<forall>r\<in>obj_refs cap. \<forall>a b.
cte_wp_at (\<lambda>cap'. r \<in> obj_refs cap') (a, b) s \<longrightarrow> cte_wp_at (Not \<circ> is_zombie) (a, b) s)"
apply (clarsimp simp: cte_wp_at_def)
apply (case_tac "p = (a, b)")
apply simp
apply (drule(2) zombies_finalD2)
apply clarsimp
apply blast
apply simp
done
lemma cap_asid_mask[simp]:
"cap_asid (mask_cap m c) = cap_asid c"
by (simp add: mask_cap_def)
lemma cap_master_mask[simp]:
"cap_master_cap (mask_cap rs cap) = cap_master_cap cap"
by (simp add: mask_cap_def)
lemma cap_badge_mask[simp]:
"cap_badge (mask_cap rs cap) = cap_badge cap"
by (simp add: mask_cap_def)
lemma ensure_empty_cte_wp_at:
"\<lbrace>\<top>\<rbrace> ensure_empty c \<lbrace>\<lambda>rv s. cte_wp_at ((=) cap.NullCap) c s\<rbrace>, -"
unfolding ensure_empty_def
apply (wp whenE_throwError_wp get_cap_wp)
apply simp
done
lemmas get_cap_cte_caps_to_no_wp[wp]
= get_cap_cte_caps_to[where P="\<top>", simplified]
lemma lookup_cap_ex[wp]:
"\<lbrace>\<top>\<rbrace> lookup_cap t c \<lbrace>\<lambda>rv s. \<forall>r\<in>cte_refs rv (interrupt_irq_node s). ex_cte_cap_to r s\<rbrace>, -"
by (simp add: split_def lookup_cap_def) wp
lemmas cap_aligned_valid[elim!] = valid_cap_aligned
lemma cap_derive_not_null_helper2:
"\<lbrace>P\<rbrace> derive_cap slot cap \<lbrace>\<lambda>rv s. rv \<noteq> cap.NullCap \<longrightarrow> Q rv s\<rbrace>, -
\<Longrightarrow>
\<lbrace>\<lambda>s. cap \<noteq> cap.NullCap \<and> \<not> is_zombie cap \<and> cap \<noteq> cap.IRQControlCap \<longrightarrow> P s\<rbrace>
derive_cap slot cap
\<lbrace>\<lambda>rv s. rv \<noteq> cap.NullCap \<longrightarrow> Q rv s\<rbrace>, -"
apply (drule cap_derive_not_null_helper)
apply (erule hoare_strengthen_postE_R)
apply simp
done
lemma has_cancel_send_rights_ep_cap:
"has_cancel_send_rights cap \<Longrightarrow> is_ep_cap cap"
by (clarsimp simp: has_cancel_send_rights_def split: cap.splits)
lemma is_untyped_update_cap_data[intro]:
"is_untyped_cap r \<Longrightarrow> update_cap_data c x r = r"
by (cases r; clarsimp simp: update_cap_data_def is_arch_cap_def)
context CNodeInv_AI begin
lemma decode_cnode_inv_wf[wp]:
"\<And>cap.
\<lbrace>invs and valid_cap cap
and (\<lambda>s. \<forall>r\<in>zobj_refs cap. ex_nonz_cap_to r s)
and (\<lambda>s. is_cnode_cap cap \<longrightarrow> (\<forall>r\<in>cte_refs cap (interrupt_irq_node s).
ex_cte_cap_wp_to is_cnode_cap r s))
and (\<lambda>s. \<forall>cap \<in> set cs. s \<turnstile> cap)
and (\<lambda>s. \<forall>cap \<in> set cs. is_cnode_cap cap \<longrightarrow>
(\<forall>r\<in>cte_refs cap (interrupt_irq_node s). ex_cte_cap_wp_to is_cnode_cap r s)) \<rbrace>
decode_cnode_invocation mi args cap cs
\<lbrace>valid_cnode_inv\<rbrace>,-"
apply (rule decode_cnode_cases2[where args=args and exs=cs and label=mi])
\<comment> \<open>Move/Insert\<close>
apply (simp add: decode_cnode_invocation_def unlessE_whenE
split del: if_split)
apply (wp lsfco_cte_at ensure_no_children_wp whenE_throwError_wp
| simp add: split_beta split del: if_split
| (fold validE_R_def)[1])+
apply (rule cap_derive_not_null_helper2)
apply (simp only: imp_conjR)
apply ((wp derive_cap_is_derived
derive_cap_valid_cap
derive_cap_zobjrefs derive_cap_objrefs_iszombie
| wp (once) hoare_drop_imps)+ )[1]
apply (wp whenE_throwError_wp | wpcw)+
apply (rename_tac dest_slot y src_slot)
apply simp
apply (rule_tac Q'="\<lambda>src_cap. valid_cap src_cap and ex_cte_cap_wp_to is_cnode_cap dest_slot
and zombies_final and valid_objs
and real_cte_at src_slot and real_cte_at dest_slot
and cte_wp_at (\<lambda>c. c = src_cap) src_slot
and cte_wp_at ((=) cap.NullCap) dest_slot"
in hoare_post_imp)
apply (rename_tac src_cap s)
apply (clarsimp simp: cte_wp_at_caps_of_state all_rights_def)
apply (simp add: cap_master_update_cap_data weak_derived_update_cap_data
cap_asid_update_cap_data
update_cap_data_validI update_cap_objrefs)
apply (strengthen cap_badge_update_cap_data)
apply simp
apply (frule (1) caps_of_state_valid_cap)
apply (case_tac "is_zombie src_cap")
apply (clarsimp simp add: valid_cap_def2 update_cap_data_def
is_cap_simps
split: if_split_asm)
apply (frule(2) zombies_final_helper [OF caps_of_state_cteD[simplified cte_wp_at_eq_simp]])
apply (clarsimp simp: valid_cap_def2 cte_wp_at_caps_of_state)
apply (rule conjI, clarsimp+)+
apply (fastforce simp: is_untyped_update_cap_data
weak_derived_update_cap_data[OF _ weak_derived_refl])
apply (wp get_cap_cte_wp_at ensure_empty_cte_wp_at)+
apply simp
apply (clarsimp simp: invs_def valid_state_def valid_pspace_def)
\<comment> \<open>Revoke\<close>
apply (simp add: decode_cnode_invocation_def unlessE_whenE cong: if_cong)
apply (wp lsfco_cte_at hoare_drop_imps whenE_throwError_wp
| simp add: split_beta validE_R_def[symmetric])+
apply clarsimp
\<comment> \<open>Delete\<close>
apply (simp add: decode_cnode_invocation_def unlessE_whenE cong: if_cong)
apply (wp lsfco_cte_at hoare_drop_imps whenE_throwError_wp
| simp add: split_beta validE_R_def[symmetric])+
apply clarsimp
\<comment> \<open>Save\<close>
apply (simp add: decode_cnode_invocation_def unlessE_whenE cong: if_cong)
apply (rule hoare_pre)
apply (wp ensure_empty_stronger whenE_throwError_wp
lsfco_cte_at lookup_slot_for_cnode_op_cap_to
hoare_vcg_const_imp_lift
| simp add: split_beta
| wp (once) hoare_drop_imps)+
apply clarsimp
\<comment> \<open>CancelBadgedSends\<close>
apply (simp add: decode_cnode_invocation_def
unlessE_def whenE_def
split del: if_split)
apply (wp get_cap_wp hoare_vcg_all_liftE_R | simp add: )+
apply (rule_tac Q'="\<lambda>rv. invs and cte_wp_at (\<lambda>_. True) rv" in hoare_strengthen_postE_R)
apply (wp lsfco_cte_at)
apply (clarsimp simp: cte_wp_valid_cap invs_valid_objs has_cancel_send_rights_ep_cap)+
\<comment> \<open>Rotate\<close>
apply (simp add: decode_cnode_invocation_def split_def
whenE_def unlessE_def)
apply (rule hoare_pre)
apply (wp get_cap_wp ensure_empty_stronger | simp)+
apply (rename_tac dest_slot src_slot)
apply (rule_tac Q'="\<lambda>rv s. real_cte_at rv s \<and> real_cte_at dest_slot s
\<and> real_cte_at src_slot s
\<and> ex_cte_cap_wp_to is_cnode_cap rv s
\<and> ex_cte_cap_wp_to is_cnode_cap dest_slot s
\<and> invs s" in hoare_strengthen_postE_R)
apply wp+
apply (clarsimp simp: cte_wp_at_caps_of_state
dest!: real_cte_at_cte del: impI)
apply (frule invs_valid_objs)
apply (simp add: update_cap_data_validI weak_derived_update_cap_data
caps_of_state_valid_cap)
subgoal by (auto,(clarsimp simp:is_cap_simps update_cap_data_def)+)[1](* Bad practise *)
apply wp+
apply clarsimp
apply (elim disjE exE conjE,
simp_all add: decode_cnode_invocation_def validE_R_def
split_def unlessE_whenE
split: list.split_asm
split del: if_split)
apply (wp | simp)+
done
end
lemma decode_cnode_inv_inv[wp]:
"\<lbrace>P\<rbrace> decode_cnode_invocation mi args cap cs \<lbrace>\<lambda>rv. P\<rbrace>"
unfolding decode_cnode_invocation_def
apply (simp add: split_def unlessE_def whenE_def
cong: if_cong split del: if_split)
apply (rule hoare_pre)
apply (wp hoare_drop_imps | simp | wpcw)+
done
definition
not_recursive_cspaces :: "'z::state_ext state \<Rightarrow> cslot_ptr set"
where
"not_recursive_cspaces s \<equiv> {ptr. cte_wp_at (\<lambda>cap. ptr \<notin> fst_cte_ptrs cap) ptr s}"
definition
state_cte_ptrs :: "'z::state_ext state \<Rightarrow> cslot_ptr set"
where
"state_cte_ptrs s \<equiv> {ptr. cte_at ptr s}"
lemma fixed_length_finite:
"finite (UNIV :: 'a set) \<Longrightarrow> finite {x :: 'a list. length x = n}"
apply (induct n)
apply simp
apply (subgoal_tac "{x :: 'a list. length x = Suc n} = image (split Cons) (UNIV \<times> {x. length x = n})")
apply clarsimp
apply safe
apply (case_tac x, simp_all add: image_def)
done
lemma state_cte_ptrs_finite:
"finite (state_cte_ptrs s)"
apply (clarsimp simp add: state_cte_ptrs_def cte_at_cases Collect_disj_eq
Collect_conj_eq set_pair_UN tcb_cap_cases_def)
apply (clarsimp simp: well_formed_cnode_n_def fixed_length_finite)
done
lemma cte_wp_at_set_finite:
"finite {p. cte_wp_at (P p) p s}"
apply (rule finite_subset [OF _ state_cte_ptrs_finite[where s=s]])
apply (clarsimp simp: state_cte_ptrs_def elim!: cte_wp_at_weakenE)
done
lemma not_recursive_cspaces_finite:
"finite (not_recursive_cspaces s)"
unfolding not_recursive_cspaces_def
by (rule cte_wp_at_set_finite)
lemma set_cdt_not_recursive[wp]:
"\<lbrace>\<lambda>s. P (not_recursive_cspaces s)\<rbrace> set_cdt f \<lbrace>\<lambda>rv s. P (not_recursive_cspaces s)\<rbrace>"
apply (simp add: set_cdt_def, wp)
apply (simp add: not_recursive_cspaces_def)
done
lemma not_recursive_mdb[simp]:
"not_recursive_cspaces (is_original_cap_update f s) =
not_recursive_cspaces s"
"not_recursive_cspaces (cdt_update f' s) =
not_recursive_cspaces s"
by (simp add: not_recursive_cspaces_def)+
lemma set_cap_no_new_recursive:
"\<lbrace>\<lambda>s. x \<notin> not_recursive_cspaces s
\<and> cte_wp_at (\<lambda>cap. ptr \<notin> fst_cte_ptrs cap) ptr s\<rbrace>
set_cap cap ptr
\<lbrace>\<lambda>rv s. x \<notin> not_recursive_cspaces s\<rbrace>"
apply (simp add: not_recursive_cspaces_def)
apply (wp set_cap_cte_wp_at_neg)
apply (clarsimp simp: cte_wp_at_neg split: if_split)
done
lemma not_recursive_set_cap_shrinks:
"\<lbrace>\<lambda>s. card (not_recursive_cspaces s) \<le> n
\<and> cte_wp_at (\<lambda>cap. ptr \<notin> fst_cte_ptrs cap) ptr s
\<and> ptr \<in> fst_cte_ptrs cap\<rbrace>
set_cap cap ptr
\<lbrace>\<lambda>rv s. card (not_recursive_cspaces s) < n\<rbrace>"
apply (rule shrinks_proof[where x=ptr])
apply (rule not_recursive_cspaces_finite)
apply (wp set_cap_no_new_recursive)
apply simp
apply (simp add: not_recursive_cspaces_def)
apply (wp set_cap_cte_wp_at_neg)
apply (clarsimp elim!: cte_wp_at_weakenE)
apply (simp add: not_recursive_cspaces_def)
done
lemma not_recursive_set_cap_doesn't_grow:
"\<lbrace>\<lambda>s. card (not_recursive_cspaces s) < n
\<and> cte_wp_at (\<lambda>cap. ptr \<notin> fst_cte_ptrs cap) ptr s\<rbrace>
set_cap cap ptr
\<lbrace>\<lambda>rv s. card (not_recursive_cspaces s) < n\<rbrace>"
apply (rule doesn't_grow_proof)
apply (rule not_recursive_cspaces_finite)
apply (rule set_cap_no_new_recursive)
done
lemma final_cap_duplicate_obj_ref:
"\<lbrakk> fst (get_cap p1 s) = {(cap1, s)}; fst (get_cap p2 s) = {(cap2, s)}; is_final_cap' cap1 s;
x \<in> obj_refs cap1; p1 \<noteq> p2 \<rbrakk> \<Longrightarrow> x \<notin> obj_refs cap2"
apply (clarsimp simp: is_final_cap'_def gen_obj_refs_def)
apply (subgoal_tac "{p1, p2} \<subseteq> {(a, b)}")
apply simp
apply (drule sym[where s="Collect p" for p], simp)
apply blast
done
lemma final_cap_duplicate_irq:
"\<lbrakk> fst (get_cap p1 s) = {(cap1, s)}; fst (get_cap p2 s) = {(cap2, s)}; is_final_cap' cap1 s;
x \<in> cap_irqs cap1; p1 \<noteq> p2 \<rbrakk> \<Longrightarrow> x \<notin> cap_irqs cap2"
apply (clarsimp simp: is_final_cap'_def gen_obj_refs_def)
apply (subgoal_tac "{p1, p2} \<subseteq> {(a, b)}")
apply simp
apply (drule sym[where s="Collect p" for p], simp)
apply blast
done
lemma final_cap_duplicate_arch_refs:
"\<lbrakk> fst (get_cap p1 s) = {(cap1, s)}; fst (get_cap p2 s) = {(cap2, s)}; is_final_cap' cap1 s;
x \<in> arch_gen_refs cap1; p1 \<noteq> p2 \<rbrakk> \<Longrightarrow> x \<notin> arch_gen_refs cap2"
apply (clarsimp simp: is_final_cap'_def gen_obj_refs_def)
apply (subgoal_tac "{p1, p2} \<subseteq> {(a, b)}")
apply simp
apply (drule sym[where s="Collect p" for p], simp)
apply blast
done
lemma fst_cte_ptrs_link_obj_refs:
"x \<in> fst_cte_ptrs cap \<Longrightarrow> fst x \<in> obj_refs cap"
by (case_tac cap, simp_all add: fst_cte_ptrs_def)
lemma final_cap_duplicate_cte_ptr:
"\<lbrakk> fst (get_cap p s) = {(cap, s)}; fst (get_cap p' s) = {(cap', s)}; is_final_cap' cap s;
x \<in> fst_cte_ptrs cap; p \<noteq> p' \<rbrakk> \<Longrightarrow> x \<notin> fst_cte_ptrs cap'"
apply (drule(2) final_cap_duplicate_obj_ref)
apply (erule fst_cte_ptrs_link_obj_refs)
apply assumption
apply (clarsimp simp: fst_cte_ptrs_link_obj_refs)
done
lemma not_recursive_cspaces_more_update[iff]:
"not_recursive_cspaces (trans_state f s) = not_recursive_cspaces s"
by (simp add: not_recursive_cspaces_def)
lemma cap_swap_not_recursive:
"\<lbrace>\<lambda>s. card (not_recursive_cspaces s) \<le> n
\<and> cte_wp_at (\<lambda>cap. is_final_cap' cap s
\<and> p1 \<in> fst_cte_ptrs cap) p2 s
\<and> cte_wp_at ((=) c1) p1 s
\<and> cte_wp_at ((=) c2) p2 s
\<and> p1 \<noteq> p2\<rbrace>
cap_swap c1 p1 c2 p2
\<lbrace>\<lambda>rv s. card (not_recursive_cspaces s) < n\<rbrace>"
apply (cases "p1 = p2", simp_all)
apply (simp add: cap_swap_def set_cdt_def when_def)
apply (rule hoare_weaken_pre)
apply (wp | simp)+
apply (rule not_recursive_set_cap_doesn't_grow)
apply (wp not_recursive_set_cap_shrinks set_cap_cte_wp_at' get_cap_wp hoare_vcg_disj_lift)
apply (clarsimp simp: cte_wp_at_def)
apply (frule(3) final_cap_duplicate_cte_ptr)
apply simp
apply (case_tac c2, simp_all add: fst_cte_ptrs_def)
done
lemma cap_swap_fd_not_recursive:
"\<lbrace>\<lambda>s. card (not_recursive_cspaces s) \<le> n
\<and> cte_wp_at (\<lambda>cap. is_final_cap' cap s
\<and> p1 \<in> fst_cte_ptrs cap) p2 s
\<and> p1 \<noteq> p2\<rbrace>
cap_swap_for_delete p1 p2
\<lbrace>\<lambda>rv s. card (not_recursive_cspaces s) < n\<rbrace>"
unfolding cap_swap_for_delete_def
by (wpsimp wp: cap_swap_not_recursive get_cap_wp)
lemma set_mrs_typ_at [wp]:
"\<lbrace>\<lambda>s. P (typ_at T p s)\<rbrace> set_mrs p' b m \<lbrace>\<lambda>rv s. P (typ_at T p s)\<rbrace>"
apply (simp add: set_mrs_def bind_assoc set_object_def get_object_def)
apply (cases b)
apply simp
apply wp
apply clarsimp
apply (drule get_tcb_SomeD)
apply (clarsimp simp: obj_at_def)
apply (clarsimp simp: zipWithM_x_mapM split_def
split del: if_split)
apply (wp mapM_wp')
apply clarsimp
apply (drule get_tcb_SomeD)
apply (clarsimp simp: obj_at_def)
done
lemma cte_wp_and:
"cte_wp_at (P and Q) c s = (cte_wp_at P c s \<and> cte_wp_at Q c s)"
by (auto simp: cte_wp_at_def)
lemmas cte_wp_and' = cte_wp_and [unfolded pred_conj_def]
lemma in_pspace_typ_at:
"r \<notin> dom (kheap s) = (\<forall>T. \<not> typ_at T r s)"
apply (simp add: dom_def)
apply (subst simp_thms(2)[symmetric])
apply (fastforce simp: obj_at_def)
done
lemma prepare_thread_delete_not_recursive:
"\<lbrace>\<lambda>s. P (not_recursive_cspaces s)\<rbrace>
prepare_thread_delete t
\<lbrace>\<lambda>rv s. P (not_recursive_cspaces s)\<rbrace>"
apply (simp add: not_recursive_cspaces_def cte_wp_at_caps_of_state)
apply (wp prepare_thread_delete_caps_of_state)
done
lemma suspend_not_recursive:
"\<lbrace>\<lambda>s. P (not_recursive_cspaces s)\<rbrace>
IpcCancel_A.suspend t
\<lbrace>\<lambda>rv s. P (not_recursive_cspaces s)\<rbrace>"
apply (simp add: not_recursive_cspaces_def cte_wp_at_caps_of_state)
apply (wp suspend_caps_of_state)
apply (clarsimp simp: cte_wp_at_caps_of_state)
apply (erule rsubst[where P=P])
apply (intro set_eqI iffI)
apply (clarsimp simp: fst_cte_ptrs_def)
apply clarsimp
apply (clarsimp simp: fst_cte_ptrs_def can_fast_finalise_def
split: cap.split_asm)
done
lemma unbind_notification_not_recursive:
"\<lbrace>\<lambda>s. P (not_recursive_cspaces s)\<rbrace>
unbind_notification tcb
\<lbrace>\<lambda>rv s. P (not_recursive_cspaces s)\<rbrace>"
apply (simp add: not_recursive_cspaces_def cte_wp_at_caps_of_state)
apply (wp unbind_notification_caps_of_state)
done
lemma get_cap_det2:
"(r, s') \<in> fst (get_cap p s) \<Longrightarrow> get_cap p s = ({(r, s)}, False) \<and> s' = s"
apply (rule conjI)
apply (erule get_cap_det)
apply (erule use_valid [OF _ get_cap_inv])
apply simp
done
lemma set_zombie_not_recursive:
"\<lbrace>\<lambda>s. cte_wp_at (\<lambda>c. fst_cte_ptrs c = fst_cte_ptrs (cap.Zombie p zb n)) slot s
\<and> P (not_recursive_cspaces s)\<rbrace>
set_cap (cap.Zombie p zb n) slot
\<lbrace>\<lambda>rv s. P (not_recursive_cspaces s)\<rbrace>"
apply (simp add: not_recursive_cspaces_def)
apply (rule set_preserved_proof[where P=P])
apply simp_all
apply (wp hoare_vcg_all_lift hoare_vcg_disj_lift set_cap_cte_wp_at)
apply (fastforce simp: cte_wp_at_def fst_cte_ptrs_def)
apply (simp only: cte_wp_at_neg imp_conv_disj de_Morgan_conj simp_thms)
apply (wp hoare_vcg_ex_lift valid_cte_at_neg_typ[OF set_cap_typ_at]
hoare_vcg_disj_lift set_cap_cte_wp_at)
apply (fastforce simp: fst_cte_ptrs_def cte_wp_at_def)
done
definition
rdcall_finalise_ord_lift :: "((cslot_ptr \<times> 'z state) \<times> (cslot_ptr \<times> 'z state)) set
\<Rightarrow> ((rec_del_call \<times> 'z state) \<times> (rec_del_call \<times> 'z state)) set"
where
"rdcall_finalise_ord_lift S \<equiv>
(\<lambda>(x, s). case x of CTEDeleteCall a b \<Rightarrow> 3 | FinaliseSlotCall a b \<Rightarrow> 2
| ReduceZombieCall cap a b \<Rightarrow> 1)
<*mlex*>
((map_prod (\<lambda>(x, s). (FinaliseSlotCall x True, s)) (\<lambda>(x, s). (FinaliseSlotCall x True, s)) ` S)
\<union> (map_prod (\<lambda>(x, s). (FinaliseSlotCall x False, s)) (\<lambda>(x, s). (FinaliseSlotCall x False, s)) ` S))"
lemma wf_rdcall_finalise_ord_lift:
"wf S \<Longrightarrow> wf (rdcall_finalise_ord_lift S)"
unfolding rdcall_finalise_ord_lift_def
by (auto intro!: wf_mlex wf_Un wf_map_prod_image inj_onI)
definition
rec_del_recset :: "((rec_del_call \<times> 'z::state_ext state) \<times> (rec_del_call \<times> 'z::state_ext state)) set"
where
"rec_del_recset \<equiv>
wf_sum (exposed_rdcall \<circ> fst)
(rdcall_finalise_ord_lift (inv_image
(less_than <*lex*> less_than)
(\<lambda>(x, s). case caps_of_state s x of
Some cap.NullCap \<Rightarrow> (0, 0)
| Some (cap.Zombie p zb n) \<Rightarrow>
(if fst_cte_ptrs (cap.Zombie p zb n) = {x} then 1 else 2, n)
| _ \<Rightarrow> (3, 0))))
(rdcall_finalise_ord_lift (measure (\<lambda>(x, s). card (not_recursive_cspaces s))))"
lemma rec_del_recset_wf: "wf rec_del_recset"
unfolding rec_del_recset_def
by (intro wf_sum_wf wf_rdcall_finalise_ord_lift wf_measure
wf_inv_image wf_lex_prod wf_less_than)
lemma in_get_cap_cte_wp_at:
"(rv, s') \<in> fst (get_cap p s) = (s = s' \<and> cte_wp_at ((=) rv) p s)"
apply (rule iffI)
apply (clarsimp dest!: get_cap_det2 simp: cte_wp_at_def)
apply (clarsimp simp: cte_wp_at_def)
done
lemma fst_cte_ptrs_first_cte_of:
"fst_cte_ptrs (cap.Zombie ptr zb n) = {first_cslot_of (cap.Zombie ptr zb n)}"
by (simp add: fst_cte_ptrs_def tcb_cnode_index_def)
lemma final_cap_still_at:
"\<lbrace>\<lambda>s. cte_wp_at (\<lambda>c. gen_obj_refs cap = gen_obj_refs c
\<and> P cap (is_final_cap' c s)) ptr s\<rbrace>
set_cap cap ptr
\<lbrace>\<lambda>rv s. cte_wp_at (\<lambda>c. P c (is_final_cap' c s)) ptr s\<rbrace>"
apply (simp add: is_final_cap'_def2 cte_wp_at_caps_of_state)
apply wp
apply (clarsimp elim!: rsubst[where P="P cap"])
apply (intro ext arg_cong[where f=Ex] arg_cong[where f=All])
apply (case_tac "(aa, ba) = ptr", simp_all add: gen_obj_refs_def)
done
lemma suspend_thread_cap:
"\<lbrace>\<lambda>s. caps_of_state s x = Some (cap.ThreadCap p)\<rbrace>
IpcCancel_A.suspend t
\<lbrace>\<lambda>rv s. caps_of_state s x = Some (cap.ThreadCap p)\<rbrace>"
apply (rule hoare_chain)
apply (rule suspend_cte_wp_at_preserved
[where p=x and P="(=) (cap.ThreadCap p)"])
apply (clarsimp simp add: can_fast_finalise_def)
apply (simp add: cte_wp_at_caps_of_state)+
done
lemma emptyable_irq_state_independent[intro!, simp]:
"emptyable x (s\<lparr>machine_state := machine_state s\<lparr>irq_state := f (irq_state (machine_state s))\<rparr>\<rparr>)
= emptyable x s"
by (auto simp: emptyable_def)
lemma not_recursive_cspaces_irq_state_independent[intro!, simp]:
"not_recursive_cspaces (s \<lparr> machine_state := machine_state s \<lparr> irq_state := f (irq_state (machine_state s)) \<rparr> \<rparr>)
= not_recursive_cspaces s"
by (simp add: not_recursive_cspaces_def)
context CNodeInv_AI begin
lemma preemption_point_not_recursive_cspaces[wp]:
"preemption_point \<lbrace>\<lambda>s. P (not_recursive_cspaces s)\<rbrace>"
unfolding preemption_point_def
by (wpsimp wp: OR_choiceE_weak_wp hoare_drop_imp)
lemma preemption_point_caps_of_state[wp]:
"preemption_point \<lbrace>\<lambda>s. P (caps_of_state s)\<rbrace>"
unfolding preemption_point_def
by (wpsimp wp: OR_choiceE_weak_wp hoare_drop_imp)
lemma rec_del_termination:
"All (rec_del_dom :: rec_del_call \<times> 'state_ext state \<Rightarrow> bool)"
\<comment> \<open> rec_del.termination needs a well-formed measure and proofs that the 4 recursive calls
reduce this measure. \<close>
apply (rule rec_del.termination[where R=rec_del_recset])
\<comment> \<open> The measure is well-formed. \<close>
apply (rule rec_del_recset_wf)
\<comment> \<open> case 1: CTEDeleteCall --> FinaliseSlotCall \<close>
apply (simp add: rec_del_recset_def wf_sum_def rdcall_finalise_ord_lift_def mlex_prod_def)
\<comment> \<open> case 2: FinaliseSlotCall --> ReduceZombieCall \<close>
apply (simp add: rec_del_recset_def wf_sum_def rdcall_finalise_ord_lift_def mlex_prod_def)
\<comment> \<open> case 3: FinaliseSlotCall --> FinaliseSlotCall \<close>
apply (case_tac exposed; simp)
\<comment> \<open> FinaliseSlotCall _ True --> FinaliseSlotCall _ True \<close>
apply (simp add: rec_del_recset_def wf_sum_def rdcall_finalise_ord_lift_def mlex_prod_def)
apply (rule disjI1, rule map_prod_split_imageI, clarsimp)
apply (rename_tac oref cref exposed st1 fcap st2 is_final st3 pcap1 pcap2 st4 st5 success
cl_info st6 st7)
apply (erule use_valid [OF _ preemption_point_caps_of_state])
apply (case_tac pcap1; simp add: fail_def rec_del.psimps)
apply (rename_tac word option nat)
apply (case_tac nat; simp)
apply (clarsimp simp: in_monad rec_del.psimps)
apply (clarsimp simp: in_monad in_get_cap_cte_wp_at
cte_wp_at_caps_of_state rec_del.psimps
split: if_split_asm)
apply (erule use_valid [OF _ set_cap_caps_of_state])+
apply (case_tac fcap; clarsimp simp: fst_cte_ptrs_first_cte_of in_monad)
apply (case_tac new_cap; simp add: is_cap_simps)
apply (case_tac fcap; clarsimp simp: fst_cte_ptrs_first_cte_of)
apply (case_tac fcap; clarsimp simp: fst_cte_ptrs_first_cte_of in_monad)
\<comment> \<open> FinaliseSlotCall _ False --> FinaliseSlotCall _ False \<close>
apply (simp add: rec_del_recset_def wf_sum_def rdcall_finalise_ord_lift_def mlex_prod_def)
apply (rule disjI2, rule map_prod_split_imageI, clarsimp)
apply (rename_tac oref cref exposed st1 fcap st2 is_final st3 pcap1 pcap2 st4 st5 success
cl_info st6 st7)
apply (simp add: in_monad is_final_cap_def is_zombie_def)
apply (erule use_valid [OF _ preemption_point_not_recursive_cspaces])
apply (case_tac pcap1, simp_all add: fail_def rec_del.psimps)[1]
apply (rename_tac word option nat)
apply (case_tac nat, simp_all)
apply (clarsimp simp: in_monad prod_eqI rec_del.psimps)
apply (erule use_valid [OF _ cap_swap_fd_not_recursive])
apply (frule use_valid [OF _ get_cap_cte_wp_at, simplified])
apply (drule in_inv_by_hoareD [OF get_cap_inv], clarsimp)
apply (erule use_valid [OF _ hoare_vcg_conj_lift [OF set_zombie_not_recursive final_cap_still_at]])
apply (frule use_valid [OF _ finalise_cap_cases])
apply (fastforce simp add: cte_wp_at_eq_simp)
apply clarsimp
apply (case_tac fcap, simp_all add: fst_cte_ptrs_def)
apply (clarsimp simp: in_monad cte_wp_at_caps_of_state fst_cte_ptrs_def
split: if_split_asm)
apply (clarsimp simp: in_monad cte_wp_at_caps_of_state fst_cte_ptrs_def
split: if_split_asm)
apply (frule(1) use_valid [OF _ unbind_notification_caps_of_state],
frule(1) use_valid [OF _ suspend_thread_cap],
frule(1) use_valid [OF _ prepare_thread_delete_thread_cap])
apply clarsimp
apply (erule use_valid [OF _ prepare_thread_delete_not_recursive])
apply (erule use_valid [OF _ suspend_not_recursive])
apply (erule use_valid [OF _ unbind_notification_not_recursive])
apply simp
apply (clarsimp simp: in_monad cte_wp_at_caps_of_state
fst_cte_ptrs_def zombie_cte_bits_def
tcb_cnode_index_def
split: option.split_asm)
\<comment>\<open> case 4: ReduceZombieCall --> CTEDeleteCall \<close>
apply (simp add: rec_del_recset_def wf_sum_def rdcall_finalise_ord_lift_def mlex_prod_def)
done
lemma rec_del_dom: "\<And> (p :: rec_del_call \<times> 'state_ext state). rec_del_dom p"
using rec_del_termination by blast
lemmas rec_del_simps = rec_del.psimps[OF rec_del_dom]
lemmas rec_del_simps_ext =
rec_del_simps [THEN ext[where f="rec_del args" for args]]
lemmas rec_del_fails = spec_validE_fail rec_del_simps_ext(5-)
declare assertE_wp[wp]
declare unlessE_wp[wp_split]
lemma without_preemption_wp [wp_split]:
"\<lbrace>P\<rbrace> f \<lbrace>Q\<rbrace> \<Longrightarrow> \<lbrace>P\<rbrace> without_preemption f \<lbrace>Q\<rbrace>,\<lbrace>E\<rbrace>"
by simp
lemmas rec_del_induct = rec_del.pinduct[OF rec_del_dom]