-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathInvariants_AI.thy
3495 lines (2886 loc) · 135 KB
/
Invariants_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 2022, Proofcraft Pty Ltd
* Copyright 2014, General Dynamics C4 Systems
*
* SPDX-License-Identifier: GPL-2.0-only
*)
theory Invariants_AI
imports ArchInvariants_AI
begin
arch_requalify_types
iarch_tcb
arch_requalify_consts (A)
arch_cap_is_device
ASIDPoolObj
(* we need to know the sizes of arch objects in the generic context *)
arch_requalify_facts (A)
cte_level_bits_def
tcb_bits_def
endpoint_bits_def
ntfn_bits_def
arch_requalify_consts
not_kernel_window
global_refs
arch_obj_bits_type
is_nondevice_page_cap
state_hyp_refs_of
hyp_refs_of
hyp_live
wellformed_acap
valid_arch_cap
valid_arch_cap_ref
acap_class
valid_ipc_buffer_cap
arch_valid_obj
valid_asid_map
valid_vspace_obj
valid_arch_tcb
valid_arch_idle
valid_arch_state
valid_vspace_objs
valid_arch_caps
valid_global_objs
valid_kernel_mappings
equal_kernel_mappings
valid_global_vspace_mappings
pspace_in_kernel_window
valid_vs_lookup
user_mem
device_mem
device_region
tcb_arch_ref
valid_arch_mdb
arch_tcb_to_iarch_tcb
vs_lookup
vs_lookup_pages
arch_requalify_facts
valid_arch_sizes
aobj_bits_T
valid_arch_cap_def2
idle_global
valid_ipc_buffer_cap_null
valid_arch_cap_typ
valid_vspace_obj_typ
arch_kobj_size_bounded
global_refs_lift
aobj_at_default_arch_cap_valid
aobj_ref_default
wf_acap_rights_update_id
physical_arch_cap_has_ref
wellformed_arch_default
valid_vspace_obj_default'
typ_at_pg
state_hyp_refs_of_elemD
ko_at_state_hyp_refs_ofD
hyp_sym_refs_obj_atD
hyp_sym_refs_ko_atD
state_hyp_refs_of_pspaceI
state_hyp_refs_update
hyp_refs_of_hyp_live
hyp_refs_of_hyp_live_obj
hyp_refs_of_simps
tcb_arch_ref_simps
hyp_live_tcb_simps
hyp_live_tcb_def
wellformed_arch_pspace
wellformed_arch_typ
valid_arch_tcb_pspaceI
valid_arch_tcb_lift
obj_ref_not_arch_gen_ref
arch_gen_ref_not_obj_ref
arch_gen_obj_refs_inD
same_aobject_same_arch_gen_refs
valid_arch_mdb_eqI
iarch_tcb_context_set
iarch_tcb_set_registers
lemmas [simp] =
tcb_bits_def
endpoint_bits_def
ntfn_bits_def
iarch_tcb_context_set
iarch_tcb_set_registers
lemmas [intro!] = idle_global wf_acap_rights_update_id
lemmas [simp] = wf_acap_rights_update_id state_hyp_refs_update
tcb_arch_ref_simps hyp_live_tcb_simps hyp_refs_of_simps
\<comment> \<open>---------------------------------------------------------------------------\<close>
section "Invariant Definitions for Abstract Spec"
definition
"is_ep ko \<equiv> case ko of Endpoint p \<Rightarrow> True | _ \<Rightarrow> False"
definition
"is_ntfn ko \<equiv> case ko of Notification p \<Rightarrow> True | _ \<Rightarrow> False"
definition
"is_tcb ko \<equiv> case ko of TCB t \<Rightarrow> True | _ \<Rightarrow> False"
definition
"is_cap_table bits ko \<equiv>
case ko of CNode sz cs \<Rightarrow> bits = sz \<and> well_formed_cnode_n bits cs
| _ \<Rightarrow> False"
abbreviation
"ep_at \<equiv> obj_at is_ep"
abbreviation
"ntfn_at \<equiv> obj_at is_ntfn"
abbreviation
"tcb_at \<equiv> obj_at is_tcb"
abbreviation
"cap_table_at bits \<equiv> obj_at (is_cap_table bits)"
abbreviation
"real_cte_at cref \<equiv> cap_table_at (length (snd cref)) (fst cref)"
(*
'itcb' is a projection of the "mostly preserved" fields of 'tcb'. Many
functions in the spec will leave these fields of a TCB unchanged. The 'crunch'
tool is easily able to ascertain this from the types of the fields.
The 'itcb' record is closely associated with the 'pred_tcb_at' definition.
'pred_tcb_at' is used to assert an arbitrary predicate over the fields in
'itcb' for a TCB. Before the introduction of this data structure 'st_tcb_at'
was defined directly. It is now an abbreviation of a partial application of
the 'pred_tcb_at' function, specifically a partial application to the
projection function 'itcb_state'.
The advantage of this approach is that we an assert 'pred_tcb_at proj P t' is
preserved across calls to many functions. We get "for free" that 'st_tcb_at P
t' is also preserved. In the future we may introduce other abbreviations that
assert preservation over other fields in the TCB record.
*)
record itcb =
itcb_state :: thread_state
itcb_fault_handler :: cap_ref
itcb_ipc_buffer :: vspace_ref
itcb_fault :: "fault option"
itcb_bound_notification :: "obj_ref option"
itcb_mcpriority :: priority
itcb_arch :: iarch_tcb
abbreviation
"tcb_iarch tcb \<equiv> arch_tcb_to_iarch_tcb (tcb_arch tcb)"
definition
tcb_to_itcb :: "tcb \<Rightarrow> itcb"
where
"tcb_to_itcb tcb \<equiv>
\<lparr> itcb_state = tcb_state tcb,
itcb_fault_handler = tcb_fault_handler tcb,
itcb_ipc_buffer = tcb_ipc_buffer tcb,
itcb_fault = tcb_fault tcb,
itcb_bound_notification = tcb_bound_notification tcb,
itcb_mcpriority = tcb_mcpriority tcb,
itcb_arch = tcb_iarch tcb \<rparr>"
(*
The simplification rules below are used to help produce lemmas that talk about
fields of the 'tcb' data structure rather than the 'itcb' data structure when
the lemma refers to a predicate of the form 'pred_tcb_at proj P t'.
e.g. You might have a lemma that has an assumption
\<And>tcb. itcb_state (tcb_to_itcb (f tcb)) = itcb_state (tcb_to_itcb tcb)
This simplifies to:
\<And>tcb. tcb_state (f tcb) = tcb_state tcb
*)
(* Need one of these simp rules for each field in 'itcb' *)
lemma tcb_to_itcb_simps[simp]:
"itcb_state (tcb_to_itcb tcb) = tcb_state tcb"
"itcb_fault_handler (tcb_to_itcb tcb) = tcb_fault_handler tcb"
"itcb_ipc_buffer (tcb_to_itcb tcb) = tcb_ipc_buffer tcb"
"itcb_fault (tcb_to_itcb tcb) = tcb_fault tcb"
"itcb_bound_notification (tcb_to_itcb tcb) = tcb_bound_notification tcb"
"itcb_mcpriority (tcb_to_itcb tcb) = tcb_mcpriority tcb"
"itcb_arch (tcb_to_itcb tcb) = tcb_iarch tcb"
by (auto simp: tcb_to_itcb_def)
(* This is used to assert whether an itcb projection is affected by a tcb
field update, such as tcb_arch_update. *)
abbreviation
"proj_not_field proj field_upd \<equiv>
\<forall>f tcb. proj (tcb_to_itcb ((field_upd f) tcb)) = proj (tcb_to_itcb tcb)"
definition
pred_tcb_at :: "(itcb \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> machine_word \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"pred_tcb_at proj test \<equiv> obj_at (\<lambda>ko. \<exists>tcb. ko = TCB tcb \<and> test (proj (tcb_to_itcb tcb)))"
abbreviation "st_tcb_at \<equiv> pred_tcb_at itcb_state"
abbreviation "bound_tcb_at \<equiv> pred_tcb_at itcb_bound_notification"
abbreviation "mcpriority_tcb_at \<equiv> pred_tcb_at itcb_mcpriority"
abbreviation "arch_tcb_at \<equiv> pred_tcb_at itcb_arch"
(* sseefried: 'st_tcb_at_def' only exists to make existing proofs go through. Use 'pred_tcb_at_def' from now on. *)
lemma st_tcb_at_def: "st_tcb_at test \<equiv> obj_at (\<lambda>ko. \<exists>tcb. ko = TCB tcb \<and> test (tcb_state tcb))"
by (simp add: pred_tcb_at_def)
text \<open>cte with property at\<close>
definition
cte_wp_at :: "(cap \<Rightarrow> bool) \<Rightarrow> cslot_ptr \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"cte_wp_at P p s \<equiv> \<exists>cap. fst (get_cap p s) = {(cap,s)} \<and> P cap"
abbreviation
cte_at :: "cslot_ptr \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"cte_at \<equiv> cte_wp_at \<top>"
lemma cte_wp_at_lift:
"\<lbrakk>cte_wp_at P p s ; \<And>s. P s \<Longrightarrow> Q s \<rbrakk> \<Longrightarrow> cte_wp_at Q p s"
by (fastforce simp: cte_wp_at_def)
subsection "Valid caps and objects"
primrec
untyped_range :: "cap \<Rightarrow> machine_word set"
where
"untyped_range (cap.UntypedCap dev p n f) = {p..p + (1 << n) - 1}"
| "untyped_range (cap.NullCap) = {}"
| "untyped_range (cap.EndpointCap r badge rights) = {}"
| "untyped_range (cap.NotificationCap r badge rights) = {}"
| "untyped_range (cap.CNodeCap r bits guard) = {}"
| "untyped_range (cap.ThreadCap r) = {}"
| "untyped_range (cap.DomainCap) = {}"
| "untyped_range (cap.ReplyCap r master rights) = {}"
| "untyped_range (cap.IRQControlCap) = {}"
| "untyped_range (cap.IRQHandlerCap irq) = {}"
| "untyped_range (cap.Zombie r b n) = {}"
| "untyped_range (cap.ArchObjectCap cap) = {}"
primrec (nonexhaustive)
usable_untyped_range :: "cap \<Rightarrow> machine_word set"
where
"usable_untyped_range (UntypedCap _ p n f) =
(if f < 2^n then {p+of_nat f .. p + 2 ^ n - 1} else {})"
definition
"obj_range p obj \<equiv> {p .. p + 2^obj_bits obj - 1}" (* FIXME mask_range *)
definition
"pspace_no_overlap S \<equiv>
\<lambda>s. \<forall>x ko. kheap s x = Some ko \<longrightarrow>
{x .. x + (2 ^ obj_bits ko - 1)} \<inter> S = {}" (* FIXME obj_range *)
definition
"valid_untyped c \<equiv> \<lambda>s.
\<forall>p obj.
kheap s p = Some obj \<longrightarrow>
obj_range p obj \<inter> untyped_range c \<noteq> {} \<longrightarrow>
( obj_range p obj \<subseteq> untyped_range c \<and> usable_untyped_range c \<inter> obj_range p obj = {} )"
primrec
cap_bits :: "cap \<Rightarrow> nat"
where
"cap_bits NullCap = 0"
| "cap_bits (UntypedCap dev r b f) = b"
| "cap_bits (EndpointCap r b R) = obj_bits (Endpoint undefined)"
| "cap_bits (NotificationCap r b R) = obj_bits (Notification undefined)"
| "cap_bits (CNodeCap r b m) = cte_level_bits + b"
| "cap_bits (ThreadCap r) = obj_bits (TCB undefined)"
| "cap_bits (DomainCap) = 0"
| "cap_bits (ReplyCap r m R) = obj_bits (TCB undefined)"
| "cap_bits (Zombie r zs n) =
(case zs of None \<Rightarrow> obj_bits (TCB undefined)
| Some n \<Rightarrow> cte_level_bits + n)"
| "cap_bits (IRQControlCap) = 0"
| "cap_bits (IRQHandlerCap irq) = 0"
| "cap_bits (ArchObjectCap x) = arch_obj_size x"
fun
cap_is_device :: "cap \<Rightarrow> bool"
where
"cap_is_device (cap.UntypedCap dev r b f) = dev"
| "cap_is_device (cap.ArchObjectCap x) = arch_cap_is_device x"
| "cap_is_device _ = False"
definition
"cap_aligned c \<equiv>
is_aligned (obj_ref_of c) (cap_bits c) \<and> cap_bits c < word_bits"
text \<open>
Below, we define several predicates for capabilities on the abstract specification.
Please note that we distinguish between well-formedness predicates,
which merely refine the basic type and are independent of the kernel state,
and the validity of the capability references,
which necessarily depends on the current kernel state.
Eventually, we will combine all predicates into @{text valid_cap}.
\<close>
definition
wellformed_cap :: "cap \<Rightarrow> bool"
where
"wellformed_cap c \<equiv>
case c of
UntypedCap dev p sz idx \<Rightarrow> untyped_min_bits \<le> sz
| NotificationCap r badge rights \<Rightarrow> AllowGrant \<notin> rights \<and> AllowGrantReply \<notin> rights
| CNodeCap r bits guard \<Rightarrow> bits \<noteq> 0 \<and> length guard \<le> word_bits
| IRQHandlerCap irq \<Rightarrow> irq \<le> maxIRQ
| Zombie r b n \<Rightarrow> (case b of None \<Rightarrow> n \<le> 5
| Some b \<Rightarrow> n \<le> 2 ^ b \<and> b \<noteq> 0)
| ArchObjectCap ac \<Rightarrow> wellformed_acap ac
| ReplyCap t master rights \<Rightarrow> AllowWrite \<in> rights \<and> AllowRead \<notin> rights \<and>
AllowGrantReply \<notin> rights
| _ \<Rightarrow> True"
definition
valid_cap_ref :: "cap \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_cap_ref c s \<equiv> case c of
NullCap \<Rightarrow> True
| UntypedCap dev p b idx \<Rightarrow> valid_untyped c s \<and> idx \<le> 2^ b \<and> p \<noteq> 0
| EndpointCap r badge rights \<Rightarrow> ep_at r s
| NotificationCap r badge rights \<Rightarrow> ntfn_at r s
| CNodeCap r bits guard \<Rightarrow> cap_table_at bits r s
| ThreadCap r \<Rightarrow> tcb_at r s
| DomainCap \<Rightarrow> True
| ReplyCap r m rights \<Rightarrow> tcb_at r s
| IRQControlCap \<Rightarrow> True
| IRQHandlerCap irq \<Rightarrow> True
| Zombie r b n \<Rightarrow>
(case b of None \<Rightarrow> tcb_at r s | Some b \<Rightarrow> cap_table_at b r s)
| ArchObjectCap ac \<Rightarrow> valid_arch_cap_ref ac s"
definition
valid_cap :: "cap \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_cap c s \<equiv> cap_aligned c \<and> (case c of
NullCap \<Rightarrow> True
| UntypedCap dev p b f \<Rightarrow> valid_untyped c s \<and> untyped_min_bits \<le> b \<and> f \<le> 2 ^ b \<and> p \<noteq> 0
| EndpointCap r badge rights \<Rightarrow> ep_at r s
| NotificationCap r badge rights \<Rightarrow>
ntfn_at r s \<and> AllowGrant \<notin> rights \<and> AllowGrantReply \<notin> rights
| CNodeCap r bits guard \<Rightarrow>
cap_table_at bits r s \<and> bits \<noteq> 0 \<and> length guard \<le> word_bits
| ThreadCap r \<Rightarrow> tcb_at r s
| DomainCap \<Rightarrow> True
| ReplyCap r m rights \<Rightarrow> tcb_at r s
\<and> AllowWrite \<in> rights \<and> AllowRead \<notin> rights \<and> AllowGrantReply \<notin> rights
| IRQControlCap \<Rightarrow> True
| IRQHandlerCap irq \<Rightarrow> irq \<le> maxIRQ
| Zombie r b n \<Rightarrow>
(case b of None \<Rightarrow> tcb_at r s \<and> n \<le> 5
| Some b \<Rightarrow> cap_table_at b r s \<and> n \<le> 2 ^ b \<and> b \<noteq> 0)
| ArchObjectCap ac \<Rightarrow> valid_arch_cap ac s)"
abbreviation
valid_cap_syn :: "'z::state_ext state \<Rightarrow> cap \<Rightarrow> bool" ("_ \<turnstile> _" [60, 60] 61)
where
"s \<turnstile> c \<equiv> valid_cap c s"
definition
"valid_caps cs s \<equiv> \<forall>slot cap. cs slot = Some cap \<longrightarrow> valid_cap cap s"
primrec
cap_class :: "cap \<Rightarrow> capclass"
where
"cap_class (cap.NullCap) = NullClass"
| "cap_class (cap.UntypedCap dev p n f) = PhysicalClass"
| "cap_class (cap.EndpointCap ref badge r) = PhysicalClass"
| "cap_class (cap.NotificationCap ref badge r) = PhysicalClass"
| "cap_class (cap.CNodeCap ref n bits) = PhysicalClass"
| "cap_class (cap.ThreadCap ref) = PhysicalClass"
| "cap_class (cap.DomainCap) = DomainClass"
| "cap_class (cap.Zombie r b n) = PhysicalClass"
| "cap_class (cap.IRQControlCap) = IRQClass"
| "cap_class (cap.IRQHandlerCap irq) = IRQClass"
| "cap_class (cap.ReplyCap tcb m rights) = ReplyClass tcb"
| "cap_class (cap.ArchObjectCap cap) = acap_class cap"
definition
valid_cs_size :: "nat \<Rightarrow> cnode_contents \<Rightarrow> bool" where
"valid_cs_size sz cs \<equiv>
sz < word_bits - cte_level_bits \<and> well_formed_cnode_n sz cs"
definition
valid_cs :: "nat \<Rightarrow> cnode_contents \<Rightarrow> 'z::state_ext state \<Rightarrow> bool" where
"valid_cs sz cs s \<equiv> (\<forall>cap \<in> ran cs. s \<turnstile> cap) \<and> valid_cs_size sz cs"
definition
valid_tcb_state :: "thread_state \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_tcb_state ts s \<equiv> case ts of
BlockedOnReceive ref sp \<Rightarrow> ep_at ref s
| BlockedOnSend ref sp \<Rightarrow> ep_at ref s
| BlockedOnNotification ref \<Rightarrow> ntfn_at ref s
| _ \<Rightarrow> True"
abbreviation
"inactive st \<equiv> st = Inactive"
abbreviation
"halted st \<equiv> case st of
Inactive \<Rightarrow> True
| IdleThreadState \<Rightarrow> True
| _ \<Rightarrow> False"
text \<open>
For each slot in the tcb, we give the accessor function, the update function and
The invariant that should be verified about that slot.
The invariant parameters are: thread_ptr, thread_state, cap_in_that_slot
\<close>
(* WARNING to anyone who would like to add an invariant to ctable slot:
During deletion procedure, any type of cap can land in that slot *)
definition
tcb_cap_cases ::
"cap_ref \<rightharpoonup> ((tcb \<Rightarrow> cap) \<times>
((cap \<Rightarrow> cap) \<Rightarrow> tcb \<Rightarrow> tcb) \<times>
(obj_ref \<Rightarrow> thread_state \<Rightarrow> cap \<Rightarrow> bool))"
where
"tcb_cap_cases \<equiv>
[tcb_cnode_index 0 \<mapsto> (tcb_ctable, tcb_ctable_update, (\<lambda>_ _. \<top>)),
tcb_cnode_index 1 \<mapsto> (tcb_vtable, tcb_vtable_update,
(\<lambda>_ _. is_valid_vtable_root or ((=) NullCap))),
tcb_cnode_index 2 \<mapsto> (tcb_reply, tcb_reply_update,
(\<lambda>t st c. (is_master_reply_cap c \<and> obj_ref_of c = t
\<and> AllowGrant \<in> cap_rights c)
\<or> (halted st \<and> (c = NullCap)))),
tcb_cnode_index 3 \<mapsto> (tcb_caller, tcb_caller_update,
(\<lambda>_ st. case st of
BlockedOnReceive e data \<Rightarrow>
(=) NullCap
| _ \<Rightarrow> is_reply_cap or (=) NullCap)),
tcb_cnode_index 4 \<mapsto> (tcb_ipcframe, tcb_ipcframe_update,
(\<lambda>_ _. is_nondevice_page_cap or ((=) NullCap)))]"
definition
valid_fault :: "ExceptionTypes_A.fault \<Rightarrow> bool"
where
"valid_fault f \<equiv>
\<forall>mw b n g. f = (ExceptionTypes_A.CapFault mw b
(ExceptionTypes_A.GuardMismatch n g)) \<longrightarrow> length g\<le>word_bits"
definition
valid_bound_ntfn :: "machine_word option \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_bound_ntfn ntfn_opt s \<equiv> case ntfn_opt of
None \<Rightarrow> True
| Some a \<Rightarrow> ntfn_at a s"
definition
valid_bound_tcb :: "machine_word option \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_bound_tcb tcb_opt s \<equiv> case tcb_opt of
None \<Rightarrow> True
| Some t \<Rightarrow> tcb_at t s"
definition
valid_ntfn :: "notification \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_ntfn ntfn s \<equiv> (case ntfn_obj ntfn of
IdleNtfn \<Rightarrow> True
| WaitingNtfn ts \<Rightarrow>
(ts \<noteq> [] \<and> (\<forall>t \<in> set ts. tcb_at t s)
\<and> distinct ts
\<and> (case ntfn_bound_tcb ntfn of Some tcb \<Rightarrow> ts = [tcb] | _ \<Rightarrow> True))
| ActiveNtfn b \<Rightarrow> True)
\<and> valid_bound_tcb (ntfn_bound_tcb ntfn) s"
definition
valid_tcb :: "obj_ref \<Rightarrow> tcb \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_tcb p t s \<equiv>
(\<forall>(getF, setF, restr) \<in> ran tcb_cap_cases.
s \<turnstile> getF t \<and> restr p (tcb_state t) (getF t))
\<and> valid_ipc_buffer_cap (tcb_ipcframe t) (tcb_ipc_buffer t)
\<and> valid_tcb_state (tcb_state t) s
\<and> (case tcb_fault t of Some f \<Rightarrow> valid_fault f | _ \<Rightarrow> True)
\<and> length (tcb_fault_handler t) = word_bits
\<and> valid_bound_ntfn (tcb_bound_notification t) s
\<and> valid_arch_tcb (tcb_arch t) s"
definition
tcb_cap_valid :: "cap \<Rightarrow> cslot_ptr \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"tcb_cap_valid cap ptr s \<equiv> tcb_at (fst ptr) s \<longrightarrow>
st_tcb_at (\<lambda>st. case tcb_cap_cases (snd ptr) of
Some (getF, setF, restr) \<Rightarrow> restr (fst ptr) st cap
| None \<Rightarrow> True)
(fst ptr) s
\<and> (snd ptr = tcb_cnode_index 4 \<longrightarrow>
(\<forall>tcb. ko_at (TCB tcb) (fst ptr) s
\<longrightarrow> valid_ipc_buffer_cap cap (tcb_ipc_buffer tcb)))"
definition
valid_ep :: "endpoint \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_ep ep s \<equiv> case ep of
IdleEP \<Rightarrow> True
| SendEP ts \<Rightarrow>
(ts \<noteq> [] \<and> (\<forall>t \<in> set ts. tcb_at t s) \<and> distinct ts)
| RecvEP ts \<Rightarrow>
(ts \<noteq> [] \<and> (\<forall>t \<in> set ts. tcb_at t s) \<and> distinct ts)"
definition
valid_obj :: "obj_ref \<Rightarrow> kernel_object \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_obj ptr ko s \<equiv> case ko of
Endpoint p \<Rightarrow> valid_ep p s
| Notification p \<Rightarrow> valid_ntfn p s
| TCB t \<Rightarrow> valid_tcb ptr t s
| CNode sz cs \<Rightarrow> valid_cs sz cs s
| ArchObj ao \<Rightarrow> arch_valid_obj ao s"
definition
valid_objs :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_objs s \<equiv> \<forall>ptr \<in> dom $ kheap s. \<exists>obj. kheap s ptr = Some obj \<and> valid_obj ptr obj s"
text \<open>simple kernel objects\<close>
lemma obj_at_eq_helper:
"\<lbrakk> \<And>obj. P obj = P' obj \<rbrakk> \<Longrightarrow> obj_at P = obj_at P'"
apply (rule ext)+
apply (simp add: obj_at_def)
done
lemma is_ep_def2: "(is_ep ko) = bound (partial_inv Endpoint ko)"
by (auto simp: is_ep_def split: kernel_object.splits)
lemma ep_at_def2: "ep_at = (obj_at (\<lambda>ko. bound (partial_inv Endpoint ko)))"
by (rule obj_at_eq_helper, simp add: is_ep_def2)
lemma is_ntfn_def2: "(is_ntfn ko) = bound (partial_inv Notification ko)"
by (auto simp: is_ntfn_def split: kernel_object.splits)
lemma ntfn_at_def2: "ntfn_at = (obj_at (\<lambda>ko. bound (partial_inv Notification ko)))"
by (rule obj_at_eq_helper, simp add: is_ntfn_def2)
definition
valid_simple_obj :: "kernel_object \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_simple_obj ko s \<equiv> case ko of
Endpoint p \<Rightarrow> valid_ep p s
| Notification p \<Rightarrow> valid_ntfn p s
| TCB t \<Rightarrow> True
| CNode sz cs \<Rightarrow> True
| ArchObj ao \<Rightarrow> arch_valid_obj ao s"
definition
valid_simple_objs :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_simple_objs s \<equiv> \<forall>ptr \<in> dom $ kheap s. \<exists>obj. kheap s ptr = Some obj \<and> valid_simple_obj obj s"
lemma valid_obj_imp_valid_simple: "valid_obj p ko s \<Longrightarrow> valid_simple_obj ko s"
by (clarsimp simp: valid_obj_def valid_simple_obj_def split: kernel_object.splits)
lemma valid_objs_imp_valid_simple_objs: "valid_objs s \<Longrightarrow> valid_simple_objs s"
by (fastforce simp: valid_obj_imp_valid_simple valid_objs_def valid_simple_objs_def
split: kernel_object.splits)
declare valid_simple_obj_def[simp]
lemma valid_ep_def2: "valid_ep = (\<lambda>x s. valid_simple_obj (Endpoint x) s)"
by simp
lemma valid_ntfn_def2: "valid_ntfn = (\<lambda>x s. valid_simple_obj (Notification x) s)"
by simp
lemma valid_simple_kheap:"\<lbrakk>kheap s p = Some v ;
a_type v \<in> {AEndpoint, ANTFN} \<rbrakk>\<Longrightarrow> valid_obj p v s = valid_simple_obj v s"
by (auto simp: valid_obj_imp_valid_simple valid_obj_def a_type_def
split: kernel_object.splits if_splits)
abbreviation
"simple_typ_at \<equiv> obj_at (\<lambda>ob. a_type ob \<in> {AEndpoint, ANTFN})"
text \<open>symref related definitions\<close>
definition
tcb_st_refs_of :: "thread_state \<Rightarrow> (obj_ref \<times> reftype) set"
where
"tcb_st_refs_of z \<equiv> case z of
(Running) => {}
| (Inactive) => {}
| (Restart) => {}
| (BlockedOnReply) => {}
| (IdleThreadState) => {}
| (BlockedOnReceive x payl) => {(x, TCBBlockedRecv)}
| (BlockedOnSend x payl) => {(x, TCBBlockedSend)}
| (BlockedOnNotification x) => {(x, TCBSignal)}"
definition
ep_q_refs_of :: "endpoint \<Rightarrow> (obj_ref \<times> reftype) set"
where
"ep_q_refs_of x \<equiv> case x of
IdleEP => {}
| (RecvEP q) => set q \<times> {EPRecv}
| (SendEP q) => set q \<times> {EPSend}"
definition
ntfn_q_refs_of :: "ntfn \<Rightarrow> (obj_ref \<times> reftype) set"
where
"ntfn_q_refs_of x \<equiv> case x of
IdleNtfn => {}
| (WaitingNtfn q) => set q \<times> {NTFNSignal}
| (ActiveNtfn b) => {}"
(* FIXME-NTFN: two new functions: ntfn_bound_refs and tcb_bound_refs, include below by union *)
definition
ntfn_bound_refs :: "obj_ref option \<Rightarrow> (obj_ref \<times> reftype) set"
where
"ntfn_bound_refs t \<equiv> case t of
Some tcb \<Rightarrow> {(tcb, NTFNBound)}
| None \<Rightarrow> {}"
definition
tcb_bound_refs :: "obj_ref option \<Rightarrow> (obj_ref \<times> reftype) set"
where
"tcb_bound_refs a \<equiv> case a of
Some ntfn \<Rightarrow> {(ntfn, TCBBound)}
| None \<Rightarrow> {}"
definition (* ARMHYP *)
refs_of :: "kernel_object \<Rightarrow> (obj_ref \<times> reftype) set"
where
"refs_of x \<equiv> case x of
CNode sz fun => {}
| TCB tcb => tcb_st_refs_of (tcb_state tcb) \<union> tcb_bound_refs (tcb_bound_notification tcb)
| Endpoint ep => ep_q_refs_of ep
| Notification ntfn => ntfn_q_refs_of (ntfn_obj ntfn) \<union> ntfn_bound_refs (ntfn_bound_tcb ntfn)
| ArchObj ao => {}"
definition
state_refs_of :: "'z::state_ext state \<Rightarrow> obj_ref \<Rightarrow> (obj_ref \<times> reftype) set"
where
"state_refs_of s \<equiv> \<lambda>x. case (kheap s x) of Some ko \<Rightarrow> refs_of ko | None \<Rightarrow> {}"
definition all_refs_of :: "kernel_object \<Rightarrow> (obj_ref \<times> reftype) set"
where "all_refs_of x \<equiv> refs_of x \<union> hyp_refs_of x"
definition
state_all_refs_of :: "'z::state_ext state \<Rightarrow> obj_ref \<Rightarrow> (obj_ref \<times> reftype) set"
where
"state_all_refs_of s \<equiv> \<lambda>x. case (kheap s x) of Some ko \<Rightarrow> refs_of ko | None \<Rightarrow> {}"
text "objects live in device_region or non_device_region"
definition
pspace_respects_device_region:: "'z::state_ext state \<Rightarrow> bool"
where
"pspace_respects_device_region \<equiv> \<lambda>s. (dom (user_mem s)) \<subseteq> - (device_region s)
\<and> (dom (device_mem s)) \<subseteq> (device_region s)"
primrec
live0 :: "kernel_object \<Rightarrow> bool"
where
"live0 (CNode sz fun) = False"
| "live0 (TCB tcb) = (bound (tcb_bound_notification tcb) \<or> (tcb_state tcb \<noteq> Inactive \<and>
tcb_state tcb \<noteq> IdleThreadState))"
| "live0 (Endpoint ep) = (ep \<noteq> IdleEP)"
| "live0 (Notification ntfn) = (bound (ntfn_bound_tcb ntfn) \<or> (\<exists>ts. ntfn_obj ntfn = WaitingNtfn ts))"
| "live0 (ArchObj ao) = False"
definition live :: "kernel_object \<Rightarrow> bool"
where
"live ko \<equiv> case ko of
CNode sz fun => False
| TCB tcb => live0 ko \<or> hyp_live ko
| Endpoint ep => live0 ko
| Notification ntfn => live0 ko
| ArchObj ao => hyp_live ko"
lemma a_type_arch_live:
"a_type ko = AArch tp \<Longrightarrow> \<not> live0 ko"
by (simp add: a_type_def
split: Structures_A.kernel_object.split_asm)
fun
zobj_refs :: "cap \<Rightarrow> obj_ref set"
where
"zobj_refs (Zombie r b n) = {}"
| "zobj_refs x = obj_refs x"
definition
ex_nonz_cap_to :: "obj_ref \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"ex_nonz_cap_to ref \<equiv> (\<lambda>s. \<exists>cref. cte_wp_at (\<lambda>c. ref \<in> zobj_refs c) cref s)"
text \<open>All live objects have caps. The contrapositive
of this is significant in establishing invariants
over retype. The exception are objects that are
not in the scope of any untyped capability, as
these can never be retyped.\<close>
definition
if_live_then_nonz_cap :: "'z::state_ext state \<Rightarrow> bool"
where
"if_live_then_nonz_cap s \<equiv>
\<forall>ptr. obj_at live ptr s \<longrightarrow> ex_nonz_cap_to ptr s"
primrec
cte_refs :: "cap \<Rightarrow> (irq \<Rightarrow> obj_ref) \<Rightarrow> cslot_ptr set"
where
"cte_refs (UntypedCap dev p n fr) f = {}"
| "cte_refs (NullCap) f = {}"
| "cte_refs (EndpointCap r badge rights) f = {}"
| "cte_refs (NotificationCap r badge rights) f = {}"
| "cte_refs (CNodeCap r bits guard) f =
{r} \<times> {xs. length xs = bits}"
| "cte_refs (ThreadCap r) f =
{r} \<times> (dom tcb_cap_cases)"
| "cte_refs (DomainCap) f = {}"
| "cte_refs (Zombie r b n) f =
{r} \<times> {xs. length xs = (zombie_cte_bits b) \<and>
unat (of_bl xs :: machine_word) < n}"
| "cte_refs (IRQControlCap) f = {}"
| "cte_refs (IRQHandlerCap irq) f = {(f irq, [])}"
| "cte_refs (ReplyCap tcb master rights) f = {}"
| "cte_refs (ArchObjectCap cap) f = {}"
definition
ex_cte_cap_wp_to :: "(cap \<Rightarrow> bool) \<Rightarrow> cslot_ptr \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"ex_cte_cap_wp_to P ptr \<equiv> \<lambda>s. \<exists>cref.
cte_wp_at (\<lambda>c. P c \<and> ptr \<in> cte_refs c (interrupt_irq_node s)) cref s"
abbreviation
"ex_cte_cap_to \<equiv> ex_cte_cap_wp_to \<top>"
(* All non-Null caps live either in capability tables to which there
are appropriate existing capabilities. *)
definition
appropriate_cte_cap :: "cap \<Rightarrow> cap \<Rightarrow> bool"
where
"appropriate_cte_cap cap cte_cap \<equiv>
case cap of
NullCap \<Rightarrow> True
| NotificationCap _ _ _ \<Rightarrow> True
| _ \<Rightarrow> cap_irqs cte_cap = {}"
definition
if_unsafe_then_cap :: "'z::state_ext state \<Rightarrow> bool"
where
"if_unsafe_then_cap s \<equiv> \<forall>cref cap. caps_of_state s cref = Some cap
\<longrightarrow> cap \<noteq> NullCap
\<longrightarrow> ex_cte_cap_wp_to (appropriate_cte_cap cap) cref s"
text \<open>All zombies are final.\<close>
definition
zombies_final :: "'z::state_ext state \<Rightarrow> bool"
where
"zombies_final \<equiv>
\<lambda>s. \<forall>p. cte_wp_at is_zombie p s \<longrightarrow> cte_wp_at (\<lambda>cap. is_final_cap' cap s) p s"
definition
valid_pspace :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_pspace \<equiv> valid_objs and pspace_aligned and
pspace_distinct and if_live_then_nonz_cap
and zombies_final
and (\<lambda>s. sym_refs (state_refs_of s))
and (\<lambda>s. sym_refs (state_hyp_refs_of s))" (* ARMHYP *)
definition
null_filter :: "('a \<Rightarrow> cap option) \<Rightarrow> ('a \<Rightarrow> cap option)"
where
"null_filter f \<equiv> (\<lambda>x. if f x = Some NullCap then None else f x)"
definition
untyped_mdb :: "cdt \<Rightarrow> (cslot_ptr \<rightharpoonup> cap) \<Rightarrow> bool"
where
"untyped_mdb m cs \<equiv>
\<forall>ptr ptr' cap cap'.
cs ptr = Some cap \<longrightarrow> is_untyped_cap cap \<longrightarrow>
cs ptr' = Some cap' \<longrightarrow> obj_refs cap' \<inter> untyped_range cap \<noteq> {} \<longrightarrow>
ptr' \<in> descendants_of ptr m"
text "inclusion properties on untyped caps"
definition
untyped_inc :: "cdt \<Rightarrow> (cslot_ptr \<rightharpoonup> cap) \<Rightarrow> bool"
where
"untyped_inc m cs \<equiv>
\<forall>p p' c c'.
cs p = Some c \<longrightarrow> is_untyped_cap c \<longrightarrow>
cs p' = Some c' \<longrightarrow> is_untyped_cap c' \<longrightarrow>
(untyped_range c \<subseteq> untyped_range c' \<or>
untyped_range c' \<subseteq> untyped_range c \<or>
untyped_range c \<inter> untyped_range c' = {}) \<and>
(untyped_range c \<subset> untyped_range c' \<longrightarrow> (p \<in> descendants_of p' m \<and> untyped_range c \<inter> usable_untyped_range c' = {})) \<and>
(untyped_range c' \<subset> untyped_range c \<longrightarrow> (p' \<in> descendants_of p m \<and> untyped_range c' \<inter> usable_untyped_range c = {})) \<and>
(untyped_range c = untyped_range c' \<longrightarrow>
(p' \<in> descendants_of p m \<and> usable_untyped_range c = {} \<or> p \<in> descendants_of p' m \<and> usable_untyped_range c' = {} \<or> p = p'))"
definition
"cap_range c \<equiv> untyped_range c \<union> obj_refs c"
definition
descendants_inc :: "cdt \<Rightarrow> (cslot_ptr \<rightharpoonup> cap) \<Rightarrow> bool"
where
"descendants_inc m cs \<equiv>
\<forall>p p'. p \<in> descendants_of p' m \<longrightarrow> (cap_class (the (cs p)) = cap_class (the (cs p')) \<and> cap_range (the (cs p)) \<subseteq> cap_range (the (cs p')))"
abbreviation
"awaiting_reply ts \<equiv> ts = BlockedOnReply"
definition
"valid_ioc s \<equiv>
\<forall>p. is_original_cap s p \<longrightarrow> cte_wp_at (\<lambda>x. x \<noteq> NullCap) p s"
definition
"is_reply_cap_to t \<equiv> \<lambda>cap. \<exists>rights. cap = ReplyCap t False rights"
definition
"is_master_reply_cap_to t \<equiv> \<lambda>cap. \<exists>rights. cap = ReplyCap t True rights"
definition
"has_reply_cap t s \<equiv> \<exists>p. cte_wp_at (is_reply_cap_to t) p s"
definition
"mdb_cte_at ct_at m \<equiv> \<forall>p c. m c = Some p \<longrightarrow> ct_at p \<and> ct_at c"
definition
"no_mloop m \<equiv> \<forall>p. \<not> m \<Turnstile> p \<rightarrow> p"
definition
"ut_revocable r cs \<equiv> \<forall>p cap. cs p = Some cap \<longrightarrow> is_untyped_cap cap \<longrightarrow> r p"
definition
"irq_revocable r cs \<equiv> \<forall>p. cs p = Some IRQControlCap \<longrightarrow> r p"
definition
"reply_master_revocable r cs \<equiv> \<forall>p cap. cs p = Some cap \<longrightarrow>
is_master_reply_cap cap \<longrightarrow> r p"
definition reply_caps_mdb
where
"reply_caps_mdb m cs \<equiv> \<forall>ptr t rights.
cs ptr = Some (ReplyCap t False rights) \<longrightarrow>
(\<exists>ptr' rights'. m ptr = Some ptr' \<and> cs ptr' = Some (ReplyCap t True rights'))"
lemma reply_caps_mdbE:
assumes hyp:"reply_caps_mdb m cs"
assumes side_hyp: "cs slot = Some (ReplyCap t False R)"
obtains ptr R' where "m slot = Some ptr" and "cs ptr = Some (ReplyCap t True R')"
using side_hyp hyp by (fastforce simp:reply_caps_mdb_def)
definition
"reply_masters_mdb m cs \<equiv> \<forall>ptr t rights.
cs ptr = Some (ReplyCap t True rights) \<longrightarrow> m ptr = None \<and>
(\<forall>ptr'\<in>descendants_of ptr m. \<exists>rights'. cs ptr' = Some (ReplyCap t False rights'))"
definition
"reply_mdb m cs \<equiv> reply_caps_mdb m cs \<and> reply_masters_mdb m cs"
definition
"valid_mdb \<equiv> \<lambda>s. mdb_cte_at (swp (cte_wp_at ((\<noteq>) NullCap)) s) (cdt s) \<and>
untyped_mdb (cdt s) (caps_of_state s) \<and> descendants_inc (cdt s) (caps_of_state s) \<and>
no_mloop (cdt s) \<and> untyped_inc (cdt s) (caps_of_state s) \<and>
ut_revocable (is_original_cap s) (caps_of_state s) \<and>
irq_revocable (is_original_cap s) (caps_of_state s) \<and>
reply_master_revocable (is_original_cap s) (caps_of_state s) \<and>
reply_mdb (cdt s) (caps_of_state s) \<and>
valid_arch_mdb (is_original_cap s) (caps_of_state s)"
abbreviation
"idle_tcb_at \<equiv> pred_tcb_at (\<lambda>t. (itcb_state t, itcb_bound_notification t, itcb_arch t))"
definition
"valid_idle \<equiv>
\<lambda>s. idle_tcb_at (\<lambda>(st, ntfn, arch). idle st \<and> ntfn = None \<and> valid_arch_idle arch)
(idle_thread s) s
\<and> idle_thread s = idle_thread_ptr"
definition
"only_idle \<equiv> \<lambda>s. \<forall>t. st_tcb_at idle t s \<longrightarrow> t = idle_thread s"
definition
"valid_reply_masters \<equiv> \<lambda>s. \<forall>p t. cte_wp_at (is_master_reply_cap_to t) p s \<longrightarrow>
p = (t, tcb_cnode_index 2)"
definition
"reply_cap_get_tcb cap \<equiv> case cap of (ReplyCap t _ _) \<Rightarrow> t"
lemma reply_cap_get_tcb_simp[simp]: "reply_cap_get_tcb (ReplyCap t m R) = t"
by (simp add: reply_cap_get_tcb_def)
definition
"unique_reply_caps cs \<equiv>
\<forall>ptr ptr' t R R'.
cs ptr = Some (ReplyCap t False R) \<longrightarrow>
cs ptr' = Some (ReplyCap t False R') \<longrightarrow> ptr = ptr'"
definition
"valid_reply_caps \<equiv> \<lambda>s.
(\<forall>t. has_reply_cap t s \<longrightarrow> st_tcb_at awaiting_reply t s) \<and>
unique_reply_caps (caps_of_state s)"
definition
valid_refs :: "obj_ref set \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"valid_refs R \<equiv> \<lambda>s. \<forall>cref. \<not>cte_wp_at (\<lambda>c. R \<inter> cap_range c \<noteq> {}) cref s"
text "caps point at objects in the kernel window"
definition
cap_refs_in_kernel_window :: "'z::state_ext state \<Rightarrow> bool"
where
"cap_refs_in_kernel_window \<equiv> \<lambda>s. valid_refs (not_kernel_window s) s"
definition
valid_global_refs :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_global_refs \<equiv> \<lambda>s. valid_refs (global_refs s) s"
definition
valid_irq_node :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_irq_node \<equiv> \<lambda>s. inj (interrupt_irq_node s)
\<and> (\<forall>irq. cap_table_at 0 (interrupt_irq_node s irq) s)"
definition
irq_issued :: "irq \<Rightarrow> 'z::state_ext state \<Rightarrow> bool"
where
"irq_issued irq \<equiv> \<lambda>s. interrupt_states s irq = irq_state.IRQSignal"
definition
valid_irq_handlers :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_irq_handlers \<equiv> \<lambda>s. \<forall>cap \<in> ran (caps_of_state s). \<forall>irq \<in> cap_irqs cap. irq_issued irq s"
definition valid_irq_masks :: "(irq \<Rightarrow> irq_state) \<Rightarrow> (irq \<Rightarrow> bool) \<Rightarrow> bool" where
"valid_irq_masks table masked \<equiv> \<forall>irq. table irq = IRQInactive \<longrightarrow> masked irq"
definition valid_irq_states :: "'z::state_ext state \<Rightarrow> bool" where
"valid_irq_states \<equiv> \<lambda>s.
valid_irq_masks (interrupt_states s) (irq_masks (machine_state s))"
definition "cap_range_respects_device_region c s \<equiv>
if (cap_is_device c) then cap_range c \<subseteq> device_region s
else cap_range c \<subseteq> - device_region s"
definition
cap_refs_respects_device_region :: "'z::state_ext state \<Rightarrow> bool"
where
"cap_refs_respects_device_region \<equiv> \<lambda>s. \<forall>cref.
\<not> cte_wp_at (\<lambda>c. \<not> cap_range_respects_device_region c s) cref s"
definition
"valid_machine_state \<equiv>
\<lambda>s. \<forall>p. in_user_frame p (s::'z::state_ext state) \<or> underlying_memory (machine_state s) p = 0"
definition
valid_state :: "'z::state_ext state \<Rightarrow> bool"
where
"valid_state \<equiv> valid_pspace
and valid_mdb
and valid_ioc
and valid_idle
and only_idle
and if_unsafe_then_cap
and valid_reply_caps
and valid_reply_masters