(** *Diagrams for machine steps*)

(* Specifications: *)
Lemma acquire_step_diagram:
forall (cd : option compiler_index) (m1 : mem) (st1 : ThreadPool (Some hb)) (st2 : ThreadPool.t) (mu : meminj) (m2 : mem)
(tr1 tr2 : HybridMachineSig.event_trace)
(Hmatch : concur_match cd mu st1 m1 st2 m2) (Htr : List.Forall2 (inject_mevent mu) tr1 tr2)
(U : list nat)
(m1' : mem) (tid : nat)
(Htid : ThreadPool.containsThread st1 tid) (Hpeek : HybridMachineSig.schedPeek U = Some tid) (c : semC) (b : block)
(ofs : Integers.Ptrofs.int) (virtueThread : delta_map * delta_map)
(newThreadPerm : access_map * access_map) (pmap : lock_info)
(Hcmpt: mem_compatible st1 m1)
(Hlt': permMapLt
(setPermBlock (Some Writable) b (Integers.Ptrofs.intval ofs)
(snd (ThreadPool.getThreadR Htid)) LKSIZE_nat) (getMaxPerm m1))
(Hbounded : bounded_maps.sub_map (fst virtueThread) (snd (getMaxPerm m1)) /\
bounded_maps.sub_map (snd virtueThread) (snd (getMaxPerm m1)))
(Hinv : invariant st1),
semantics.at_external (semantics.csem (event_semantics.msem semSem))
c (restrPermMap (fst (ssrfun.pair_of_and (Hcmpt tid Htid)))) =
Some (LOCK, (Vptr b ofs :: nil)%list) ->
getThreadC Htid = Kblocked c ->
Mem.load AST.Mint32 (restrPermMap (snd (ssrfun.pair_of_and (Hcmpt tid Htid)))) b
(Integers.Ptrofs.intval ofs) = Some (Vint Integers.Int.one) ->
Mem.range_perm (restrPermMap (snd (ssrfun.pair_of_and (Hcmpt tid Htid)))) b
(Integers.Ptrofs.intval ofs) (BinInt.Z.add (Integers.Ptrofs.intval ofs) LKSIZE)
Cur Readable ->
Mem.store AST.Mint32 (restrPermMap Hlt') b (Integers.Ptrofs.intval ofs)
(Vint Integers.Int.zero) = Some m1' ->
ThreadPool.lockRes st1 (b, Integers.Ptrofs.intval ofs) = Some pmap ->
permMapJoin (fst pmap) (fst (ThreadPool.getThreadR Htid)) (fst newThreadPerm) ->
permMapJoin (snd pmap) (snd (ThreadPool.getThreadR Htid)) (snd newThreadPerm) ->
exists e' (st2' : ThreadPool.t) (m2' : mem) (cd' : option compiler_index) (mu' : meminj),
concur_match cd' mu'
(ThreadPool.updLockSet (ThreadPool.updThread Htid (Kresume c Vundef) newThreadPerm)
(b, Integers.Ptrofs.intval ofs) (empty_map, empty_map)) m1' st2' m2' /\
List.Forall2 (inject_mevent mu')
(seq.cat tr1
(Events.external tid
(Events.acquire
(b, Integers.Ptrofs.intval ofs)
(Some (build_delta_content (fst virtueThread) m1'))) :: nil))
(seq.cat tr2 (Events.external tid e' :: nil)) /\
HybridMachineSig.external_step(scheduler:=HybridMachineSig.HybridCoarseMachine.scheduler)
U tr2 st2 m2 (HybridMachineSig.schedSkip U)
(seq.cat tr2
(Events.external tid e' :: nil)) st2'
m2'.
(** *Lemmas about map, map1, bounded_maps.strong_tree_leq *)
Lemma map_map1:
forall {A B} f m,
@PTree.map1 A B f m = PTree.map (fun _=> f) m.
Lemma strong_tree_leq_xmap:
forall {A B} f1 f2 t (leq: option B -> option A -> Prop),
(forall a p, leq (Some (f1 p a)) (Some (f2 p a))) ->
leq None None ->
forall p,
bounded_maps.strong_tree_leq
(PTree.xmap f1 t p)
(@PTree.xmap A A f2 t p)
leq.
Lemma strong_tree_leq_map:
forall {A B} f1 f2 t (leq: option B -> option A -> Prop),
(forall a p, leq (Some (f1 p a)) (Some (f2 p a))) ->
leq None None ->
bounded_maps.strong_tree_leq
(@PTree.map A B f1 t)
(@PTree.map A A f2 t)
leq.
Lemma strong_tree_leq_map':
forall {A B} f1 f2 t (leq: option B -> option A -> Prop),
(forall a p0,
PTree.get p0 t = Some a ->
leq (Some (f1 (PTree.prev_append 1 p0)%positive a))
(Some (f2 (PTree.prev_append 1 p0)%positive a))) ->
leq None None ->
bounded_maps.strong_tree_leq
(@PTree.map A B f1 t)
(@PTree.map A A f2 t)
leq.
Lemma permMapLt_extensional:
forall p1 p2 p3,
(forall b, p2 !! b = p3 !! b) ->
permMapLt p1 p2 ->
permMapLt p1 p3.
Lemma trivial_map1:
forall {A} (t : PTree.t A),
PTree.map1 (fun (a : A) => a) t = t.
Lemma trivial_map:
forall {A} (t : PTree.t A),
PTree.map (fun (_ : positive) (a : A) => a) t = t.