-
Notifications
You must be signed in to change notification settings - Fork 108
/
Ipc_DR.thy
2834 lines (2675 loc) · 134 KB
/
Ipc_DR.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: GPL-2.0-only
*)
theory Ipc_DR
imports CNode_DR
begin
context begin interpretation Arch . (*FIXME: arch-split*)
abbreviation
"thread_is_running y s \<equiv> st_tcb_at ((=) Structures_A.Running) y s"
lemmas [wp] = abs_typ_at_lifts[OF set_simple_ko_typ_at]
lemma set_object_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s)\<rbrace> KHeap_A.set_object word x
\<lbrace>\<lambda>yb s. P (cur_thread s) (idle_thread s)\<rbrace>"
by (wpsimp wp: set_object_wp)
lemma set_thread_state_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s) \<rbrace> set_thread_state thread x \<lbrace>\<lambda>rv s. P (cur_thread s) (idle_thread s)\<rbrace>"
apply (simp add: set_thread_state_def)
apply (wp set_object_cur_thread_idle_thread dxo_wp_weak | simp)+
done
lemma thread_set_cur_thread_idle_thread:
" \<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s)\<rbrace> thread_set (tcb_fault_update Map.empty) word \<lbrace>\<lambda>xg s. P (cur_thread s) (idle_thread s)\<rbrace>"
apply (simp add:thread_set_def)
apply (wp set_object_cur_thread_idle_thread)
apply simp
done
lemma as_user_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s)\<rbrace> as_user thread x \<lbrace>\<lambda>rv s. P (cur_thread s) (idle_thread s)\<rbrace>"
by (wpsimp wp: set_object_cur_thread_idle_thread simp: as_user_def split_def)
lemma do_fault_transfer_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s)\<rbrace> do_fault_transfer c a e recv_buffer \<lbrace>\<lambda>rv s. P (cur_thread s) (idle_thread s)\<rbrace>"
apply (simp add:do_fault_transfer_def set_message_info_def)
apply (wp as_user_cur_thread_idle_thread |wpc|clarsimp)+
apply (wps | wp transfer_caps_it copy_mrs_it | simp)+
apply wpc
apply (wp | simp add:thread_get_def)+
done
lemma do_normal_transfer_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s) \<rbrace> Ipc_A.do_normal_transfer a b c d e f g \<lbrace>\<lambda>rv s. P (cur_thread s) (idle_thread s)\<rbrace>"
apply (simp add:do_normal_transfer_def set_message_info_def cong: if_cong)
apply (wp as_user_cur_thread_idle_thread |wpc|clarsimp)+
apply (wps | wp transfer_caps_it copy_mrs_it)+
apply clarsimp
done
lemma do_ipc_transfer_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s) \<rbrace> Ipc_A.do_ipc_transfer a b c d e \<lbrace>\<lambda>rv s. P (cur_thread s) (idle_thread s)\<rbrace>"
apply (simp add:do_ipc_transfer_def)
apply (wp do_fault_transfer_cur_thread_idle_thread do_normal_transfer_cur_thread_idle_thread|wpc)+
apply (wp | simp add:thread_get_def)+
done
lemma handle_reply_cur_thread_idle_thread:
"\<lbrace>\<lambda>s. P (cur_thread s) (idle_thread s)\<rbrace> Syscall_A.handle_reply
\<lbrace>\<lambda>rv s. P (cur_thread s) (idle_thread s) \<rbrace>"
apply (simp add:handle_reply_def)
apply (wp do_ipc_transfer_cur_thread_idle_thread|wpc)+
apply (clarsimp simp:Ipc_A.do_reply_transfer_def)
apply (wp set_thread_state_cur_thread_idle_thread dxo_wp_weak
|wpc|simp add: trans_state_def)+
apply ((wps|wp cap_delete_one_it)+)[1]
apply (wp do_ipc_transfer_cur_thread_idle_thread dxo_wp_weak)+
apply (clarsimp simp: trans_state_def)
apply (case_tac rvf)
apply (simp | wp set_thread_state_cur_thread_idle_thread
thread_set_cur_thread_idle_thread)+
apply ((wps | wp)+)[1]
apply wp+
apply ((wps | wp cap_delete_one_it)+)[1]
apply (rule hoare_drop_imp | rule hoare_conjI | rule hoare_allI | wp)+
apply simp+
done
declare pbfs_atleast_pageBits [simp]
lemma dcorres_move_guard:
"dcorres r P P' a c \<Longrightarrow> dcorres r \<top> (P' and (P o transform)) a c"
apply (rule corres_underlyingI)
apply (erule (1) corres_underlyingE, simp_all)[1]
apply (fastforce intro: bexI [rotated])
apply simp
done
lemma dcorres_move_guard_back:
"dcorres r \<top> (P' and (P o transform)) a c \<Longrightarrow> dcorres r P P' a c"
apply (rule corres_underlyingI)
apply (erule (1) corres_underlyingE, rule TrueI)
apply (fastforce intro: bexI [rotated])+
done
lemma dcorres_move_guard_iff:
"dcorres r P P' a c = dcorres r \<top> (P' and (P o transform)) a c"
apply (rule iffI)
apply (erule dcorres_move_guard)
apply (erule dcorres_move_guard_back)
done
lemma transform_cdt_cong:
"\<lbrakk> cdt s = cdt s'; interrupt_irq_node s = interrupt_irq_node s' \<rbrakk> \<Longrightarrow> transform_cdt s = transform_cdt s'"
unfolding transform_cdt_def by (simp)
lemma transform_current_thread_cong:
"\<lbrakk> cur_thread s = cur_thread s'; idle_thread s = idle_thread s' \<rbrakk> \<Longrightarrow> transform_current_thread s = transform_current_thread s'"
unfolding transform_current_thread_def by (simp)
lemma cap_installed_at_irq_weak_cong:
"\<lbrakk> w = w'; caps_of_state s = caps_of_state s'; interrupt_irq_node s = interrupt_irq_node s' \<rbrakk> \<Longrightarrow> cap_installed_at_irq w s = cap_installed_at_irq w' s'"
unfolding cap_installed_at_irq_def by (simp)
lemmas transform_congs = transform_cdt_cong transform_current_thread_cong
cap_installed_at_irq_weak_cong caps_of_state_pspace
lemma is_arch_page_capE:
assumes ispc: "is_arch_page_cap cap"
and rl: "\<And>buf rights sz mapdata dev. \<lbrakk> cap = cap.ArchObjectCap (arch_cap.PageCap dev buf rights sz mapdata)\<rbrakk> \<Longrightarrow> R"
shows "R"
using ispc unfolding is_arch_page_cap_def
apply (simp split: cap.splits arch_cap.splits)
apply (erule rl)
done
lemma get_ipc_buffer_words_Nil:
"get_ipc_buffer_words ms tcb [] = []"
unfolding get_ipc_buffer_words_def
by (auto simp: mapM_Nil split: cap.splits arch_cap.splits)
lemma det_loadWord:
"is_aligned x 2 \<Longrightarrow> det (loadWord x)"
unfolding loadWord_def
by (simp add: is_aligned_mask)
definition
"functional f \<equiv> (\<forall>P. \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. P\<rbrace>)"
lemma return_functional [simp]:
"functional (return x)"
unfolding functional_def by (rule allI, wp)
lemma functional_from_wp:
"(\<And>P. \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. P\<rbrace>) \<Longrightarrow> functional f"
unfolding functional_def
by clarsimp
lemma detE:
"\<lbrakk> det f; \<And>a b. fst (f s) = {(a, b)} \<Longrightarrow> R \<rbrakk> \<Longrightarrow> R"
unfolding det_def
apply (drule spec [where x = s])
apply fastforce
done
(* might be an equality *)
lemma evalMonad_from_wp:
"\<lbrakk> \<lbrace>(=) s\<rbrace> f \<lbrace>\<lambda>rv _. P rv\<rbrace>; det f \<rbrakk> \<Longrightarrow> P (the (evalMonad f s))"
apply (erule detE [where s = s])
apply (drule use_valid [rotated])
apply (rule refl)
apply (erule in_singleton)
apply (clarsimp simp: evalMonad_def)
done
lemma evalMonad_bind_functional:
"\<lbrakk> functional f; det f \<rbrakk> \<Longrightarrow> evalMonad (f >>= g) s = evalMonad (g (the (evalMonad f s))) s "
unfolding evalMonad_def
apply (erule detE [where s = s])
apply (clarsimp simp: bind_def)
apply (drule in_inv_by_hoareD [OF _ in_singleton, rotated])
apply (clarsimp simp: functional_def)
apply simp
done
lemma mapM_functional:
assumes fn: "\<And>n. functional (f n)"
shows "functional (mapM f ns)"
apply (rule functional_from_wp)
apply (wp mapM_wp')
apply (rule fn [unfolded functional_def, THEN spec])
apply assumption
done
lemma evalMonad_mapM_functional:
assumes fn: "\<And>n. functional (f n)"
and det: "\<And>n. n \<in> set ns \<Longrightarrow> det (f n)"
shows "the (evalMonad (mapM f ns) s) = map (\<lambda>n. the (evalMonad (f n) s)) ns"
using det
proof (induct ns)
case Nil
thus ?case by (simp add: mapM_Nil)
next
case (Cons n ns')
have det': "det (f n)" using Cons.prems by clarsimp
show ?case
apply (simp add: mapM_Cons evalMonad_bind_functional [OF fn det'])
apply (subst evalMonad_bind_functional)
apply (rule mapM_functional [OF fn])
apply (rule det_mapM [OF Cons.prems])
apply assumption
apply clarsimp
apply simp
apply (subst Cons.hyps)
apply (rule Cons.prems)
apply simp
apply simp
done
qed
lemma loadWord_functional [simp]:
"functional (loadWord n)"
unfolding loadWord_def
apply (rule functional_from_wp)
apply wp
apply simp
done
lemma is_aligned_buffer_offset:
"\<lbrakk> is_aligned buf (pageBitsForSize sz); is_aligned p msg_align_bits \<rbrakk> \<Longrightarrow>
is_aligned (buf + (p && mask (pageBitsForSize sz)) + of_nat n * of_nat word_size) 2"
apply (rule aligned_add_aligned)
apply (erule aligned_add_aligned)
apply (erule is_aligned_andI1)
apply simp
apply simp
apply (simp add: word_size_def is_aligned_mult_triv2[where n = 2, simplified]
word_bits_conv)
done
abbreviation
"ipc_buf_addr buf ptr sz n \<equiv> (buf + (ptr && mask (pageBitsForSize sz)) + of_nat n * of_nat word_size)"
lemma evalMonad_singleton [simp]:
"evalMonad (\<lambda>s. ({(f s, g s)}, b)) s = Some (f s)"
unfolding evalMonad_def by simp
lemma mi_length_dest : "of_nat (unat (mi_length rva)) = mi_length rva"
by (rule word_unat.Rep_inverse)
(* CORRES RULES *)
lemma no_pending_cap_when_active_corres:
"dcorres (\<lambda>cap rv'. cap = cdl_cap.NullCap) \<top> (st_tcb_at (\<lambda>t. \<not> generates_pending t) thread and not_idle_thread thread and valid_etcbs)
(KHeap_D.get_cap (thread, tcb_pending_op_slot))
(return b)"
apply (simp add:gets_the_def gets_def assert_opt_def)
apply (rule dcorres_absorb_get_l)
apply (clarsimp simp:st_tcb_at_def obj_at_def)
apply (frule(1) valid_etcbs_tcb_etcb)
apply (subst opt_cap_tcb)
apply (erule get_tcb_rev)
apply (clarsimp simp: get_etcb_def)
apply (simp add:not_idle_thread_def)
apply (clarsimp simp:tcb_pending_op_slot_def tcb_caller_slot_def tcb_cspace_slot_def tcb_ipcbuffer_slot_def
tcb_replycap_slot_def tcb_vspace_slot_def assert_opt_def)
apply (clarsimp simp:object_slots_def generates_pending_def infer_tcb_pending_op_def return_def
split:Structures_A.thread_state.splits)
done
lemma dummy_finalise_wp[wp]:
"is_pending_cap obj
\<Longrightarrow> \<lbrace>(=) s\<rbrace> PageTableUnmap_D.fast_finalise obj (PageTableUnmap_D.is_final_cap' obj s) \<lbrace>\<lambda>x. (=) s\<rbrace>"
by (clarsimp simp:is_pending_cap_def split:cdl_cap.splits)
lemma cte_at_into_opt_cap:
"cte_at p s = (\<exists>cap. cte_wp_at ((=) cap) p s
\<and> (fst p \<noteq> idle_thread s \<and> valid_etcbs s \<longrightarrow> opt_cap (transform_cslot_ptr p) (transform s) = Some (transform_cap cap)))"
apply (clarsimp simp: cte_wp_at_caps_of_state)
apply (safe, simp_all)
apply (clarsimp simp: caps_of_state_transform_opt_cap)
done
lemma object_slots_has_slots [simp]:
"object_slots obj p = Some v \<Longrightarrow> has_slots obj"
unfolding object_slots_def has_slots_def
by (simp split: cdl_object.splits)
lemma dcorres_when_l:
assumes tc: "R \<Longrightarrow> dcorres dc \<top> P l r"
and fc: "\<not> R \<Longrightarrow> dcorres dc \<top> Q (return ()) r"
shows "dcorres dc \<top> (\<lambda>s. (R \<longrightarrow> P s) \<and> (\<not> R \<longrightarrow> Q s)) (when R l) r"
unfolding when_def
apply (cases R)
apply simp
apply (erule tc)
apply simp
apply (erule fc)
done
lemma corres_guard_from_wp_r:
assumes ac: "corres_underlying sr False False r G G' a c"
and rl: "\<lbrace>\<lambda>s. \<not> P s\<rbrace> c \<lbrace>\<lambda>_ _. False\<rbrace>"
shows "corres_underlying sr False False r G (\<lambda>s. P s \<longrightarrow> G' s) a c"
apply (rule corres_name_pre)
apply (case_tac "P s'")
apply simp
apply (rule corres_guard_imp)
apply (rule ac)
apply simp
apply simp
apply (rule corres_underlyingI)
apply (frule use_valid [OF _ rl])
apply simp
apply simp
apply simp
done
lemma corres_guard_from_wp_bind_r:
assumes ac: "corres_underlying sr False False r G G' a (c >>= d)"
and rl: "\<lbrace>\<lambda>s. \<not> P s\<rbrace> c \<lbrace>\<lambda>_ _. False\<rbrace>"
shows "corres_underlying sr False False r G (\<lambda>s. P s \<longrightarrow> G' s) a (c >>= d)"
apply (rule corres_guard_from_wp_r)
apply (rule ac)
apply (wp rl)
done
lemma thread_set_gwp:
"dcorres dc P P' a (thread_set f p)
\<Longrightarrow> dcorres dc P (\<lambda>s. tcb_at p s \<longrightarrow> P' s) a (thread_set f p)"
unfolding thread_set_def
apply (erule corres_guard_from_wp_r)
apply (wp gets_the_wp)
apply (simp add: tcb_at_def)
done
lemma sts_gwp:
"dcorres dc P P' a (set_thread_state p st)
\<Longrightarrow> dcorres dc P (\<lambda>s. tcb_at p s \<longrightarrow> P' s) a (set_thread_state p st)"
apply (simp add: set_thread_state_thread_set thread_set_def)
apply (erule corres_guard_from_wp_r)
apply (wp gets_the_wp)
apply (simp add: tcb_at_def)
done
lemma block_thread_on_send_corres:
"dcorres dc \<top> (not_idle_thread thread and valid_etcbs)
(KHeap_D.set_cap (thread, tcb_pending_op_slot)
(PendingSyncSendCap epptr badge call can_grant can_grant_reply
False))
(set_thread_state thread
(Structures_A.thread_state.BlockedOnSend epptr
\<lparr>sender_badge = badge, sender_can_grant = can_grant,
sender_can_grant_reply = can_grant_reply, sender_is_call = call\<rparr>))"
apply (clarsimp simp:KHeap_D.set_cap_def set_thread_state_def)
apply (rule dcorres_gets_the, clarsimp)
apply (rule dcorres_rhs_noop_below_True[OF set_thread_state_ext_dcorres])
apply (frule(1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (clarsimp simp: obj_at_def not_idle_thread_def opt_object_tcb assert_def
transform_tcb_def has_slots_def split: option.splits)
apply (clarsimp simp:update_slots_def object_slots_def)
apply (clarsimp simp:set_object_def get_object_def in_monad simpler_modify_def KHeap_D.set_object_def
get_def put_def bind_def corres_underlying_def return_def)
apply (clarsimp simp:transform_def transform_objects_def transform_current_thread_def)
apply (rule ext)
apply (clarsimp simp: |rule conjI)+
apply (fastforce dest!: get_tcb_SomeD get_etcb_SomeD
simp: transform_tcb_def infer_tcb_pending_op_def tcb_slot_defs)
apply (clarsimp simp:restrict_map_def map_add_def)
apply (clarsimp, frule(1) valid_etcbs_get_tcb_get_etcb)
apply (fastforce simp:not_idle_thread_def dest!:opt_object_tcb)
done
lemma block_thread_on_recv_corres:
"dcorres dc \<top> (not_idle_thread thread and valid_etcbs)
(KHeap_D.set_cap (thread, tcb_pending_op_slot)
(PendingSyncRecvCap epptr False can_grant))
(set_thread_state thread
(Structures_A.thread_state.BlockedOnReceive epptr \<lparr>receiver_can_grant = can_grant\<rparr>))"
apply (clarsimp simp:KHeap_D.set_cap_def set_thread_state_def)
apply (rule dcorres_gets_the, clarsimp)
apply (rule dcorres_rhs_noop_below_True[OF set_thread_state_ext_dcorres])
apply (frule(1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (clarsimp simp:not_idle_thread_def opt_object_tcb assert_def
transform_tcb_def has_slots_def)
apply (clarsimp simp:update_slots_def object_slots_def)
apply (clarsimp simp:set_object_def get_object_def in_monad simpler_modify_def KHeap_D.set_object_def
get_def put_def bind_def corres_underlying_def return_def)
apply (clarsimp simp:transform_def transform_objects_def transform_current_thread_def)
apply (rule ext)
apply (clarsimp simp: get_etcb_def|rule conjI)+
apply (fastforce simp:transform_tcb_def infer_tcb_pending_op_def tcb_slot_defs)
apply (clarsimp simp:restrict_map_def map_add_def)
apply (clarsimp, frule(1) valid_etcbs_get_tcb_get_etcb)
apply (fastforce simp:not_idle_thread_def dest!:opt_object_tcb)
done
lemma block_thread_on_ntfn_recv_corres:
"dcorres dc \<top> (not_idle_thread thread and valid_etcbs)
(KHeap_D.set_cap (thread, tcb_pending_op_slot)
(PendingNtfnRecvCap w))
(set_thread_state thread (Structures_A.thread_state.BlockedOnNotification w))"
apply (clarsimp simp:KHeap_D.set_cap_def set_thread_state_def)
apply (rule dcorres_gets_the, clarsimp)
apply (rule dcorres_rhs_noop_below_True[OF set_thread_state_ext_dcorres])
apply (frule(1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (clarsimp simp:not_idle_thread_def opt_object_tcb assert_def
transform_tcb_def has_slots_def)
apply (clarsimp simp:update_slots_def object_slots_def)
apply (clarsimp simp:set_object_def get_object_def in_monad simpler_modify_def KHeap_D.set_object_def
get_def put_def bind_def corres_underlying_def return_def)
apply (clarsimp simp:transform_def transform_objects_def transform_current_thread_def)
apply (rule ext)
apply (clarsimp simp: get_etcb_def|rule conjI)+
apply (fastforce simp:transform_tcb_def infer_tcb_pending_op_def tcb_slot_defs)
apply (clarsimp simp:restrict_map_def map_add_def)
apply (clarsimp, frule(1) valid_etcbs_get_tcb_get_etcb)
apply (fastforce simp:not_idle_thread_def dest!:opt_object_tcb)
done
lemma corres_ignore_ret_lhs: "dcorres rv P P' (do f;g od) f' \<Longrightarrow> dcorres rv P P' (do a\<leftarrow>f;g od) f'"
by (clarsimp simp:corres_underlying_def)
crunch set_thread_state, set_object
for not_idle[wp]: "not_idle_thread y :: 'a::state_ext state \<Rightarrow> bool"
(simp: not_idle_thread_def get_object_def wp: dxo_wp_weak)
lemma set_scheduler_action_dcorres:
"dcorres dc P P' (return ()) (set_scheduler_action sa)"
by (clarsimp simp: set_scheduler_action_def modify_def get_def put_def bind_def return_def corres_underlying_def)
lemma tcb_sched_action_transform_inv: "\<lbrace>\<lambda>ps. transform ps = cs\<rbrace> tcb_sched_action tcb_sched_enqueue t \<lbrace>\<lambda>r s. transform s = cs\<rbrace>"
apply (clarsimp simp: tcb_sched_action_def)
apply (wp | simp)+
done
lemma set_scheduler_action_transform_inv:
"\<lbrace>\<lambda>ps. transform ps = cs\<rbrace> set_scheduler_action act \<lbrace>\<lambda>r s. transform s = cs\<rbrace>"
by (wpsimp simp: set_scheduler_action_def)
lemma possible_switch_to_dcorres:
"dcorres dc P P' (return ()) (possible_switch_to t)"
apply (clarsimp simp: possible_switch_to_def cong: if_cong)
apply (rule dcorres_symb_exec_r)+
apply (rule corres_guard1_imp, rule corres_if_rhs)
apply (rule tcb_sched_action_dcorres[THEN corres_trivial])
apply (rule corres_if_rhs)
apply (rule dcorres_symb_exec_r)+
apply (rule tcb_sched_action_dcorres[THEN corres_trivial])
apply (wp set_scheduler_action_transform_inv tcb_sched_action_transform_inv
| simp add: reschedule_required_def
| wpc
| rule set_scheduler_action_dcorres[THEN corres_trivial])+
done
lemma corres_update_waiting_ntfn_do_notification_transfer:
"dcorres dc \<top>
(pspace_aligned and valid_objs and valid_mdb and pspace_distinct and valid_idle and valid_etcbs and
(st_tcb_at ((=) (Structures_A.thread_state.BlockedOnNotification epptr)) y) and
valid_ntfn (\<lparr>ntfn_obj = case ys of [] \<Rightarrow> Structures_A.ntfn.IdleNtfn | a # list \<Rightarrow> Structures_A.ntfn.WaitingNtfn ys, ntfn_bound_tcb = bound_tcb\<rparr> ))
(Endpoint_D.do_notification_transfer y)
(update_waiting_ntfn epptr (y # ys) bound_tcb badge)"
apply (simp add: Endpoint_D.do_notification_transfer_def update_waiting_ntfn_def assert_def)
apply (rule corres_dummy_return_pl)
apply (rule corres_split_keep_pfx[where r'="dc" and Q="%x. \<top>" and Q'="%x. \<top>"])
apply (rule corres_guard_imp,rule corres_dummy_set_notification,clarsimp+)
apply (rule dcorres_expand_pfx)
apply clarsimp
apply (frule_tac y = y in generates_pending_not_idle)
apply (clarsimp simp:st_tcb_at_def obj_at_def)
apply (drule_tac t = "tcb_state tcb" in sym)
apply (simp add:generates_pending_def)
apply (rule corres_guard_imp)
apply (rule dcorres_dc_rhs_noop_below_2_True[OF allI[OF possible_switch_to_dcorres]])
apply (rule corres_split[OF set_thread_state_corres])
apply (rule set_register_corres)
apply (wp)+
apply simp
apply (frule generates_pending_not_idle[where y = y])
apply (clarsimp simp: pred_tcb_at_def obj_at_def generates_pending_def)
apply (drule_tac t = "tcb_state tcb" in sym)
apply ((clarsimp simp:pred_tcb_at_def obj_at_def not_idle_thread_def split:Structures_A.thread_state.splits)+)[3]
apply (wp set_simple_ko_aligned set_ep_mdb set_simple_ko_valid_objs sts_typ_ats)
apply (simp add: not_idle_thread_def a_type_def ntfn_at_def2[symmetric, simplified])
apply (clarsimp simp: pred_tcb_at_def obj_at_def)
apply (drule valid_tcb_objs,erule get_tcb_rev)
apply (drule_tac t = "tcb_state tcb" in sym)
apply (clarsimp simp: valid_tcb_def valid_tcb_state_def obj_at_def)
done
lemma ntfn_waiting_set_spec:
"\<lbrakk>y\<in> ntfn_waiting_set epptr s\<rbrakk>\<Longrightarrow> st_tcb_at ((=) (Structures_A.thread_state.BlockedOnNotification epptr)) y s"
by (clarsimp simp: ntfn_waiting_set_def st_tcb_at_def obj_at_def)
lemma not_empty_list_not_empty_set:
"a \<noteq> [] \<Longrightarrow> \<exists>x. x \<in> (set a)"
apply (case_tac a)
apply auto
done
lemma set_thread_state_block_on_notification_corres:
"dcorres dc \<top>
(not_idle_thread thread and tcb_at thread and valid_etcbs)
(block_thread_on_ipc thread (PendingNtfnRecvCap w))
(set_thread_state thread (Structures_A.thread_state.BlockedOnNotification w))"
apply (simp add: block_thread_on_ipc_def)
apply (clarsimp simp: KHeap_D.set_cap_def set_thread_state_def)
apply (rule dcorres_dc_rhs_noop_below_2_True[OF allI[OF set_thread_state_ext_dcorres]])
apply (rule dcorres_gets_the)
apply (clarsimp, frule(1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (clarsimp simp: not_idle_thread_def opt_object_tcb assert_def transform_tcb_def has_slots_def)
apply (clarsimp simp: update_slots_def object_slots_def)
apply (clarsimp simp: set_object_def get_object_def in_monad simpler_modify_def KHeap_D.set_object_def
get_def put_def bind_def corres_underlying_def return_def)
apply (clarsimp simp: transform_def transform_current_thread_def)
apply (intro ext conjI)
apply (case_tac x)
apply (clarsimp simp: |rule conjI)+
apply (clarsimp simp: transform_tcb_def transform_objects_def infer_tcb_pending_op_def)
apply ((fastforce simp: transform_objects_def restrict_map_def map_add_def tcb_at_def
transform_tcb_def tcb_slot_defs
dest!: get_tcb_SomeD get_etcb_SomeD)+)[2]
apply (clarsimp, frule(1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (fastforce simp: not_idle_thread_def dest!:opt_object_tcb get_tcb_rev get_etcb_rev)
done
lemma insert_contr:
"\<lbrakk>\<forall>x. x \<notin> insert y Q\<rbrakk> \<Longrightarrow> P"
apply (drule_tac x = y in spec)
apply (clarsimp simp:insertI1)
done
lemma recv_signal_corres:
"cap = transform_cap cap' \<Longrightarrow>
dcorres dc \<top> (invs and not_idle_thread thread and st_tcb_at active thread and valid_etcbs)
(recv_signal thread cap)
(receive_signal thread cap' is_blocking)"
apply (clarsimp simp:receive_signal_def invs_def recv_signal_def corres_free_fail split:cap.splits)
apply (rename_tac word1 word2 rights)
apply (rule dcorres_expand_pfx)
apply (rule_tac Q' = "\<lambda>r. (=) s' and ko_at (kernel_object.Notification r) word1 and valid_ntfn r" in corres_symb_exec_r)
apply (rule dcorres_expand_pfx)
apply (clarsimp simp:obj_at_def is_ntfn_def)
apply (case_tac "ntfn_obj rv"; simp)
apply (clarsimp simp: ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def
none_is_waiting_ntfn_def )
apply (case_tac is_blocking; simp)
apply (rule corres_guard_imp)
apply (rule corres_alternate1)
apply (rule corres_dummy_return_l)
apply (rule corres_split[OF set_thread_state_block_on_notification_corres])
apply (rule corres_dummy_set_notification,simp)
apply (wp|simp)+
apply (clarsimp simp:st_tcb_at_def tcb_at_def obj_at_def get_tcb_rev)
apply (simp add: do_nbrecv_failed_transfer_def)
apply (rule corres_guard_imp)
apply (rule corres_alternate2)
apply (rule corrupt_tcb_intent_as_user_corres)
apply simp
apply simp
(* WaitingNtfn *)
apply (clarsimp simp: ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def
none_is_waiting_ntfn_def)
apply (case_tac is_blocking; simp)
apply (rule corres_guard_imp)
apply (rule corres_alternate1)
apply (rule corres_dummy_return_l)
apply (rule corres_split[OF set_thread_state_block_on_notification_corres])
apply (rule corres_dummy_set_notification,simp)
apply (wp|simp)+
apply (clarsimp simp:st_tcb_at_def tcb_at_def obj_at_def get_tcb_rev)
apply (simp add: do_nbrecv_failed_transfer_def)
apply (rule corres_guard_imp)
apply (rule corres_alternate2)
apply (rule corrupt_tcb_intent_as_user_corres)
apply simp
apply simp
(* Active NTFN *)
apply (clarsimp simp: ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def
none_is_waiting_ntfn_def)
apply (rule corres_alternate2)
apply (rule corres_guard_imp )
apply (rule corres_dummy_return_l)
apply (rule corres_split[OF set_register_corres corres_dummy_set_notification])
apply (wp |clarsimp)+
apply (rule_tac Q'="\<lambda>r. ko_at (kernel_object.Notification r) word1 and valid_state" in hoare_strengthen_post)
apply (wp get_simple_ko_ko_at | clarsimp)+
apply (rule valid_objs_valid_ntfn_simp)
apply (clarsimp simp:valid_objs_valid_ntfn_simp valid_state_def valid_pspace_def)
apply (simp add:obj_at_def)
apply (clarsimp|wp)+
done
lemma bound_tcb_fold:
"\<lbrakk>kheap s x = Some (TCB tcb); tcb_bound_notification tcb = Some ntfnptr\<rbrakk> \<Longrightarrow> bound_tcb_at (\<lambda>ntfn. ntfn = Some ntfnptr) x s"
by (auto simp: pred_tcb_at_def obj_at_def)
lemma receive_blocked_waiting_syncs:
"\<lbrakk>valid_state s; valid_etcbs s; kheap s ntfnptr = Some (kernel_object.Notification ntfn);
ntfn_bound_tcb ntfn = Some a; get_tcb a s = Some aa; receive_blocked (tcb_state aa)\<rbrakk>
\<Longrightarrow> get_waiting_sync_bound_ntfn_threads ntfnptr (transform s) = {a}"
apply (clarsimp simp: get_waiting_sync_bound_ntfn_threads_def)
apply (frule get_notification_pick, simp)
apply (clarsimp simp: valid_ntfn_abstract_def ntfn_bound_set_def get_tcb_def
split: Structures_A.kernel_object.splits option.splits)
apply (rule set_eqI)
apply clarsimp
apply (rule iffI)
apply (clarsimp)
apply (rule_tac x=aa in exI)
apply (clarsimp simp: valid_state_def valid_pspace_def)
apply (frule (3) ntfn_bound_tcb_at[where P="\<lambda>a. a = Some ntfnptr"], simp)
apply (clarsimp simp: pred_tcb_at_def obj_at_def)
apply (clarsimp simp: transform_def transform_objects_def restrict_map_def map_add_def
split: option.splits)
apply (subst (asm) handy_if_lemma)+
apply clarsimp
apply (case_tac "x \<noteq> idle_thread s")
apply (clarsimp simp: transform_object_def
split: Structures_A.kernel_object.splits ARM_A.arch_kernel_obj.splits
option.splits nat.splits)
apply (frule_tac ptr=x in valid_etcbs_tcb_etcb, simp+)
apply (clarsimp simp add: transform_tcb_def tcb_pending_op_slot_def
tcb_boundntfn_slot_def infer_tcb_bound_notification_def
split: option.splits)
apply (frule_tac tcb="x2a" in bound_tcb_fold, simp)
apply (frule (3) bound_tcb_bound_notification_at)
apply clarsimp
apply clarsimp
apply clarsimp
apply (frule_tac tcb=t in bound_tcb_fold, simp)
apply (clarsimp simp: valid_state_def valid_pspace_def)
apply (frule (3) bound_tcb_bound_notification_at)
apply clarsimp
apply (drule get_tcb_rev)
apply (frule (1) valid_etcbs_get_tcb_get_etcb, clarsimp)
apply (clarsimp simp: transform_def)
apply (frule (1) transform_objects_tcb)
apply (clarsimp simp: valid_idle_def pred_tcb_at_def obj_at_def)
apply (clarsimp simp: transform_tcb_def tcb_pending_op_slot_def tcb_boundntfn_slot_def
infer_tcb_pending_op_def infer_tcb_bound_notification_def receive_blocked_def
split: Structures_A.thread_state.splits)
done
lemma dcorres_dat:
"dcorres dc \<top> (valid_etcbs and not_idle_thread a and valid_idle)
(do_notification_transfer a)
(do y \<leftarrow> set_thread_state a Structures_A.thread_state.Running;
y \<leftarrow> as_user a (set_register badge_register badge);
possible_switch_to a
od)"
apply (simp add: Endpoint_D.do_notification_transfer_def)
apply (rule dcorres_expand_pfx)
apply clarsimp
apply (rule corres_guard_imp)
apply (rule dcorres_dc_rhs_noop_below_2_True[OF allI[OF possible_switch_to_dcorres]])
apply (rule corres_split[OF set_thread_state_corres])
apply (rule set_register_corres)
apply (wp)+
apply simp
apply (clarsimp simp: not_idle_thread_def valid_state_def)
done
lemma not_idle_after_blocked_cancel_ipc:
"\<lbrace>valid_idle and not_idle_thread obj_id' and valid_objs and st_tcb_at ((=) state) obj_id'\<rbrace>
blocked_cancel_ipc state obj_id' \<lbrace>\<lambda>y. valid_idle\<rbrace>"
including no_pre
apply (simp add:blocked_cancel_ipc_def)
apply wp
apply (clarsimp simp:not_idle_thread_def)
apply (clarsimp simp:get_blocking_object_def)
apply (case_tac state)
apply clarsimp+
apply (clarsimp simp:valid_def return_def st_tcb_at_def valid_objs_def obj_at_def)
apply (drule_tac x = obj_id' in bspec)
apply (clarsimp simp:valid_obj_def valid_tcb_def valid_tcb_state_def)+
apply (drule_tac t = "tcb_state tcb" in sym)
apply (clarsimp simp:obj_at_def is_ep_def2)
apply (clarsimp simp:valid_def return_def st_tcb_at_def obj_at_def valid_objs_def)
apply (drule_tac x = obj_id' in bspec)
apply (clarsimp simp:valid_obj_def valid_tcb_def valid_tcb_state_def)+
apply (drule_tac t = "tcb_state tcb" in sym)
apply (clarsimp simp:obj_at_def is_ep_def2)
apply (clarsimp)+
done
lemma valid_idle_set_thread_state:
"\<lbrace>not_idle_thread xa and valid_idle :: det_state \<Rightarrow> bool\<rbrace> set_thread_state xa Structures_A.thread_state.Restart \<lbrace>\<lambda>xa. valid_idle\<rbrace>"
apply (simp add: set_thread_state_def not_idle_thread_def)
apply (simp add: set_object_def get_object_def)
apply wp
apply (clarsimp simp: not_idle_thread_def)
apply (clarsimp simp: obj_at_def dest!:get_tcb_SomeD)
apply (auto simp: valid_idle_def pred_tcb_at_def obj_at_def)
done
crunch tcb_sched_action
for not_idle_thread[wp]: "not_idle_thread a"
(wp: simp: not_idle_thread_def)
lemma tcb_sched_action_tcb_at_not_idle[wp]:
"\<lbrace>\<lambda>s. \<forall>x\<in>set list. tcb_at x s \<and> not_idle_thread x s\<rbrace> tcb_sched_action a b
\<lbrace>\<lambda>x s. \<forall>x\<in>set list. tcb_at x s \<and> not_idle_thread x s\<rbrace>"
by (wp hoare_Ball_helper)
lemma valid_idle_cancel_all_ipc:
"\<lbrace>valid_idle and valid_state :: det_state \<Rightarrow> bool\<rbrace> IpcCancel_A.cancel_all_ipc word1 \<lbrace>\<lambda>a. valid_idle\<rbrace>"
including classic_wp_pre
apply (simp add:cancel_all_ipc_def)
apply (wp|wpc|simp)+
apply (rename_tac queue list)
apply (rule_tac I = "(\<lambda>s. (queue = list) \<and> (\<forall>a\<in> set list. tcb_at a s \<and> not_idle_thread a s))
and ko_at (kernel_object.Endpoint Structures_A.endpoint.IdleEP) word1 and valid_idle" in mapM_x_inv_wp)
apply clarsimp
apply (wp KHeap_DR.tcb_at_set_thread_state_wp)
apply (rule hoare_conjI)
apply (rule_tac P="(\<lambda>s. (queue = list) \<and> (\<forall>a\<in> set list. tcb_at a s \<and> not_idle_thread a s))
and valid_idle and ko_at (kernel_object.Endpoint Structures_A.endpoint.IdleEP) word1"
in hoare_weaken_pre)
apply (wp | clarsimp)+
apply (rule set_thread_state_ko)
apply (simp add:is_tcb_def)
apply (wp valid_idle_set_thread_state)
apply (clarsimp simp:)+
apply wp
apply (rule hoare_vcg_conj_lift)
apply (rule hoare_Ball_helper)
apply (wp simple_obj_set_prop_at | clarsimp simp :get_ep_queue_def not_idle_thread_def)+
apply (rename_tac queue list)
apply (rule_tac I = "(\<lambda>s. (queue = list) \<and> (\<forall>a\<in> set list. tcb_at a s \<and> not_idle_thread a s))
and ko_at (kernel_object.Endpoint Structures_A.endpoint.IdleEP) word1 and valid_idle" in mapM_x_inv_wp)
apply clarsimp
apply (wp KHeap_DR.tcb_at_set_thread_state_wp)
apply (rule hoare_conjI)
apply (rule_tac P="(\<lambda>s. (queue = list) \<and> (\<forall>a\<in> set list. tcb_at a s \<and> not_idle_thread a s))
and valid_idle and ko_at (kernel_object.Endpoint Structures_A.endpoint.IdleEP) word1"
in hoare_weaken_pre)
apply (rule set_thread_state_ko)
apply (simp add:is_tcb_def)
apply (wp valid_idle_set_thread_state)
apply (clarsimp simp:)+
apply wp
apply (rule hoare_vcg_conj_lift)
apply (rule hoare_Ball_helper)
apply (wp simple_obj_set_prop_at | clarsimp simp :get_ep_queue_def not_idle_thread_def)+
apply (rule hoare_strengthen_post[OF get_simple_ko_sp])
apply (clarsimp | rule conjI)+
apply (clarsimp simp:obj_at_def valid_pspace_def valid_state_def)
apply (drule(1) valid_objs_valid_ep_simp)
apply (clarsimp simp:is_tcb_def valid_ep_def obj_at_def)
apply (drule(1) pending_thread_in_send_not_idle)
apply (simp add:not_idle_thread_def obj_at_def is_ep_def)+
apply (clarsimp | rule conjI)+
apply (clarsimp simp:obj_at_def valid_pspace_def valid_state_def)
apply (drule(1) valid_objs_valid_ep_simp)
apply (clarsimp simp:is_tcb_def valid_ep_def obj_at_def)
apply (drule(1) pending_thread_in_recv_not_idle)
apply (simp add:not_idle_thread_def obj_at_def is_ep_def)+
done
lemma valid_idle_cancel_all_signals:
"\<lbrace>valid_idle and valid_state :: det_state \<Rightarrow> bool\<rbrace> IpcCancel_A.cancel_all_signals word1 \<lbrace>\<lambda>a. valid_idle\<rbrace>"
including classic_wp_pre
apply (simp add:cancel_all_signals_def)
apply (wp|wpc|simp)+
apply (rename_tac list)
apply (rule_tac I = "(\<lambda>s. (\<forall>a\<in> set list. tcb_at a s \<and> not_idle_thread a s))
and ko_at (kernel_object.Notification (ntfn_set_obj ntfn Structures_A.ntfn.IdleNtfn)) word1 and valid_idle" in mapM_x_inv_wp)
apply clarsimp
apply (wp KHeap_DR.tcb_at_set_thread_state_wp)
apply (rule hoare_conjI)
apply (rule_tac P="(\<lambda>s. (\<forall>a\<in> set list. tcb_at a s \<and> not_idle_thread a s))
and valid_idle and ko_at (kernel_object.Notification (ntfn_set_obj ntfn Structures_A.ntfn.IdleNtfn)) word1"
in hoare_weaken_pre)
apply (rule set_thread_state_ko)
apply (simp add:is_tcb_def)
apply (wp valid_idle_set_thread_state)+
apply (clarsimp simp:)+
apply (rule hoare_vcg_conj_lift)
apply (rule hoare_Ball_helper)
apply (wp set_simple_ko_tcb| clarsimp simp : not_idle_thread_def)+
apply (wp simple_obj_set_prop_at)+
apply (rule hoare_strengthen_post[OF get_simple_ko_sp])
apply (clarsimp | rule conjI)+
apply (clarsimp simp:obj_at_def valid_pspace_def valid_state_def)
apply (drule(1) valid_objs_valid_ntfn_simp)
apply (clarsimp simp:is_tcb_def valid_ntfn_def obj_at_def)
apply (drule(1) pending_thread_in_wait_not_idle)
apply (simp add:not_idle_thread_def obj_at_def is_ntfn_def)+
done
lemma not_idle_after_reply_cancel_ipc:
"\<lbrace>not_idle_thread obj_id' and invs :: det_state \<Rightarrow> bool \<rbrace> reply_cancel_ipc obj_id'
\<lbrace>\<lambda>y. valid_idle\<rbrace>"
apply (simp add:reply_cancel_ipc_def)
apply wp
apply (simp add:cap_delete_one_def unless_def)
apply wp+
apply (simp add:IpcCancel_A.empty_slot_def)
apply (wp set_cap_idle | simp add: if_apply_def2 imp_conjR
| strengthen imp_consequent[where P="invs s" for s] imp_consequent[where P="valid_idle s" for s])+
apply (strengthen invs_valid_idle)
apply (wp thread_set_invs_trivial | simp add: ran_tcb_cap_cases)+
done
lemma not_idle_thread_cancel_signal:
"\<lbrace>not_idle_thread obj_id' and valid_idle\<rbrace> cancel_signal obj_id' word \<lbrace>\<lambda>r. valid_idle\<rbrace>"
including no_pre
apply (simp add:cancel_signal_def)
apply (wp valid_idle_set_thread_state|wpc)+
apply (rule hoare_strengthen_post[OF get_simple_ko_sp])
apply (clarsimp simp:not_idle_thread_def obj_at_def is_ntfn_def)
done
lemma cancel_ipc_valid_idle:
"\<lbrace>valid_idle and not_idle_thread obj_id' and invs :: det_state \<Rightarrow> bool\<rbrace> IpcCancel_A.cancel_ipc obj_id' \<lbrace>\<lambda>_. valid_idle\<rbrace>"
apply (clarsimp simp: cancel_ipc_def)
apply (wp not_idle_after_blocked_cancel_ipc not_idle_after_reply_cancel_ipc
not_idle_thread_cancel_signal | wpc | simp)+
apply (rule hoare_strengthen_post[where Q'="\<lambda>r. st_tcb_at ((=) r) obj_id'
and not_idle_thread obj_id' and invs"])
apply (wp gts_sp)
apply (clarsimp simp: invs_def valid_state_def valid_pspace_def not_idle_thread_def | rule conjI)+
done
lemma send_signal_corres:
notes if_split [split del]
shows
"ep_id = epptr \<Longrightarrow> dcorres dc \<top> (invs and valid_etcbs)
(Endpoint_D.send_signal ep_id)
(Ipc_A.send_signal epptr badge)"
apply (unfold Endpoint_D.send_signal_def Ipc_A.send_signal_def invs_def)
apply (rule dcorres_expand_pfx)
apply (clarsimp simp:get_simple_ko_def get_object_def gets_def bind_assoc split: if_split)
apply (rule dcorres_absorb_get_r)
apply (clarsimp simp:assert_def corres_free_fail partial_inv_def a_type_def the_equality
split:Structures_A.kernel_object.splits if_split)
apply (rule conjI, clarsimp+)
apply (rename_tac ntfn_ext)
apply (case_tac "ntfn_obj ntfn_ext", clarsimp)
apply (case_tac "ntfn_bound_tcb ntfn_ext", clarsimp)
\<comment> \<open>Idle, not bound\<close>
apply (rule corres_alternate1)
apply (rule dcorres_absorb_get_l)
apply (clarsimp)
apply (frule valid_objs_valid_ntfn_simp[rotated])
apply (simp add:valid_state_def valid_pspace_def)
apply (simp add:gets_def bind_assoc option_select_def)
apply (frule get_notification_pick,simp)
apply (clarsimp simp:ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def none_is_waiting_ntfn_def)
apply (rule corres_guard_imp,rule corres_dummy_set_notification,simp+)[1]
\<comment> \<open>Idle, bound\<close>
apply (clarsimp simp: get_thread_state_def thread_get_def gets_the_def gets_def bind_assoc)
apply (rule dcorres_absorb_get_r)
apply (clarsimp simp: assert_opt_def corres_free_fail split: Structures_A.kernel_object.splits option.splits)
apply (case_tac "receive_blocked (tcb_state x2)")
\<comment> \<open>receive_blocked\<close>
apply (clarsimp)
apply (rule corres_alternate2)
apply (clarsimp simp: send_signal_bound_def gets_def)
apply (rule dcorres_absorb_get_l)
apply (clarsimp simp: receive_blocked_waiting_syncs)
apply (clarsimp simp: IpcCancel_A.cancel_ipc_def get_thread_state_def thread_get_def gets_the_def gets_def bind_assoc)
apply (rule dcorres_absorb_get_r)
apply (clarsimp simp: assert_opt_def corres_free_fail split: Structures_A.kernel_object.splits option.splits)
apply (simp add: receive_blocked_def)
apply (case_tac "tcb_state x2";clarsimp)
apply (rule corres_guard_imp)
apply (simp add: blocked_cancel_ipc_def bind_assoc)
apply (rule corres_symb_exec_r)
apply (rule corres_symb_exec_r)
apply (rule corres_symb_exec_r)
apply (rule corres_dummy_return_pl)
apply (rule corres_split[OF corres_dummy_set_sync_ep])
apply (simp add: when_def dc_def[symmetric])
apply (rule corres_split[OF set_thread_state_corres dcorres_dat])
apply (wp cancel_ipc_valid_idle
| simp add: not_idle_thread_def invs_def valid_state_def get_blocking_object_def)+
apply (clarsimp dest!:get_tcb_rev simp:invs_def ep_at_def2[symmetric, simplified])
apply (frule valid_tcb_if_valid_state[rotated], clarsimp simp: valid_state_def)
apply (fastforce dest!: get_tcb_SomeD
simp: receive_blocked_def valid_idle_def pred_tcb_at_def obj_at_def
valid_tcb_def valid_tcb_state_def infer_tcb_pending_op_def
split: Structures_A.thread_state.splits)
apply clarsimp
apply (rule corres_alternate1)
apply (rule dcorres_absorb_get_l)
apply (clarsimp)
apply (frule valid_objs_valid_ntfn_simp[rotated])
apply (simp add:valid_state_def valid_pspace_def)
apply (simp add:gets_def bind_assoc option_select_def)
apply (frule get_notification_pick,simp)
apply (clarsimp simp:ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def none_is_waiting_ntfn_def)
apply (rule corres_guard_imp,rule corres_dummy_set_notification,simp+)[1]
\<comment> \<open>Waiting\<close>
apply (rule corres_alternate1)
apply (rule dcorres_absorb_get_l)
apply (clarsimp)
apply (frule valid_objs_valid_ntfn_simp[rotated])
apply (simp add:valid_state_def valid_pspace_def)
apply (simp add:gets_def bind_assoc option_select_def)
apply (frule get_notification_pick,simp)
apply (clarsimp simp:ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def split: if_split)
apply (rule conjI)
apply (clarsimp simp: dest!:not_empty_list_not_empty_set)
apply (clarsimp simp:neq_Nil_conv)
apply (rule corres_guard_imp)
apply (rule select_pick_corres)
apply (rule corres_update_waiting_ntfn_do_notification_transfer)
apply (drule_tac s = "insert y (set ys)" in sym)
apply (clarsimp simp: image_def)
apply (drule_tac s = "insert y (set ys)" in sym)
apply (drule_tac A="ntfn_waiting_set epptr s'" and x = y in eqset_imp_iff)
apply (clarsimp simp:valid_pspace_def ntfn_waiting_set_def)
apply (clarsimp simp: pred_tcb_at_def obj_at_def valid_ntfn_def split:list.splits option.splits)
\<comment> \<open>Active\<close>
apply (rule corres_alternate1)
apply (rule dcorres_absorb_get_l)
apply (clarsimp)
apply (frule valid_objs_valid_ntfn_simp[rotated])
apply (simp add:valid_state_def valid_pspace_def)
apply (clarsimp simp:gets_def bind_assoc option_select_def)
apply (frule get_notification_pick,simp)
apply (clarsimp simp:ntfn_waiting_set_lift valid_state_def valid_ntfn_abstract_def none_is_waiting_ntfn_def)
apply (rule corres_guard_imp,rule corres_dummy_set_notification,simp+)
done
lemma set_thread_state_block_on_send_corres:
"dcorres dc \<top>
(not_idle_thread thread and valid_etcbs)
(block_thread_on_ipc thread
(PendingSyncSendCap epptr badge call can_grant can_grant_reply False))
(set_thread_state thread
(Structures_A.thread_state.BlockedOnSend epptr
\<lparr>sender_badge = badge, sender_can_grant = can_grant,
sender_can_grant_reply = can_grant_reply, sender_is_call = call\<rparr>))"
by (simp add:block_thread_on_ipc_def,rule block_thread_on_send_corres)
lemma set_thread_state_block_on_receive_corres:
"dcorres dc \<top> (not_idle_thread thread and valid_etcbs)
(block_thread_on_ipc thread (PendingSyncRecvCap epptr False can_grant))
(set_thread_state thread
(Structures_A.thread_state.BlockedOnReceive epptr \<lparr>receiver_can_grant = can_grant\<rparr>))"
apply (simp add:block_thread_on_ipc_def)
apply (rule block_thread_on_recv_corres)
done
lemma corres_setup_caller_cap:
"sender \<noteq> receiver \<Longrightarrow> dcorres dc \<top>
(valid_mdb and valid_idle and not_idle_thread sender and not_idle_thread receiver
and tcb_at sender and tcb_at receiver
and st_tcb_at (Not \<circ> halted) sender and valid_objs and valid_etcbs)
(inject_reply_cap sender receiver can_grant)
(setup_caller_cap sender receiver can_grant)"
apply (rule dcorres_expand_pfx)
apply (rule corres_guard_imp)
apply (simp add: inject_reply_cap_def setup_caller_cap_def split del: if_split)
apply (rule corres_split[OF set_thread_state_corres])
apply (rule reply_cap_insert_corres)
apply (simp add: not_idle_thread_def)+
apply (wp set_thread_state_it|simp )+
apply (rule hoare_vcg_conj_lift)
apply (clarsimp simp: not_idle_thread_def set_thread_state_def)
apply wp
apply (simp add: set_object_def get_object_def)
apply wp+
apply simp
apply (clarsimp simp: not_idle_thread_def tcb_at_def obj_at_def st_tcb_at_def)
apply (rule conjI|clarsimp simp: is_tcb_def)+
apply (drule valid_tcb_objs)
apply (erule get_tcb_rev)
apply (simp add: valid_tcb_state_def)
done
lemma seq_alt_when:"(do a \<leftarrow> when c (f \<sqinter> g); h a od) = ((do a\<leftarrow>when c f ; h a od)\<sqinter> (do a\<leftarrow>when c g; h a od))"
apply (clarsimp simp:when_def)
apply (subst alternative_bind_distrib)+
apply (clarsimp simp:alternative_def)
done
lemma evalMonad_mapM:
assumes as:"evalMonad (mapM f ls) s = Some v"
assumes "\<And>l. empty_when_fail (f l)"
assumes "\<And>P l. weak_det_spec P (f l)"
assumes wp: "\<And>s l. \<lbrace>(=) s\<rbrace> f l \<lbrace>\<lambda>r. (=) s\<rbrace>"
shows "v = (map (\<lambda>p. the (evalMonad (f p) s)) ls)"
using as
proof (induct ls arbitrary: v)
case Nil
thus ?case
by (clarsimp simp:evalMonad_def mapM_def sequence_def return_def)
next
case (Cons l ls)
show ?case
using Cons.prems
apply clarsimp
apply (clarsimp simp:mapM_Cons)
apply (subst (asm) evalMonad_compose)
apply (simp add: Cons assms)+
apply (clarsimp split:option.splits)
apply (subst (asm) evalMonad_compose)
apply (rule empty_when_fail_mapM)