Section SyncCallsDiagrams.
Context (hb: nat).
(*Instantiate definitions in Concur with the current hybridbound*)
Notation concur_match:= (concur_match hb).
Notation match_thread:= (match_thread hb).
Notation match_thread_source:= (match_thread_source hb).
Notation match_thread_target:= (match_thread_target hb).
Notation memcompat2:= (memcompat2 hb).
Notation memcompat1:= (memcompat1 hb).
Notation contains12:= (contains12 hb).
Notation mtch_target:= (mtch_target hb).
Notation mtch_compiled:= (mtch_compiled hb).
Notation mtch_source:= (mtch_source hb).
Notation thread_perms st i cnt:= (fst (@getThreadR _ _ st i cnt)).
Notation lock_perms st i cnt:= (snd (@getThreadR  _ _ st i cnt)).
(* Thread states *)
(* angel,lock permissions and new thread permissions *)
(*Hangel_bound: sub_map_virtue angel (getMaxPerm m1)*)
(* Thread states *)
(* angel, lock permissions and new thread permissions *)

Lemma make_step_diagram_self Sem: (*5336*)
let CoreSem:= sem_coresem Sem in
forall (SelfSim: (self_simulation (@semC Sem) CoreSem))
(st1 : mach_state hb) (st2 : mach_state (S hb))
(m1 m1' m2 : mem) (mu : meminj) tid i b1 b2 ofs delt
(Hinj_b : mu b1 = Some (b2, delt)) new_perms1 new_perms2
cnt1 cnt2 (* Threads are contained *)
(CMatch: concur_match i mu st1 m1 st2 m2)
(th_state1: @semC Sem) th_state2 sum_state1 sum_state2
(HState1: coerce_state_type _ sum_state1 th_state1
(CSem, Clight.state) (AsmSem,Asm.state) (Sem,@semC Sem))
(HState2: coerce_state_type _ sum_state2 th_state2
(CSem, Clight.state) (AsmSem,Asm.state) (Sem,@semC Sem))
(Hget_th_state1: @getThreadC _ _ tid st1 cnt1 = Kblocked sum_state1)
(Hget_th_state2: @getThreadC _ _ tid st2 cnt2 = Kblocked sum_state2)
(HH1: set_new_mems b1 (unsigned ofs) (getThreadR cnt1) LKSIZE_nat new_perms1)
(HH1: set_new_mems b2 (unsigned ofs+delt) (getThreadR cnt2) LKSIZE_nat new_perms2)
(HisLock: lockRes st1 (b1, Integers.Ptrofs.unsigned ofs) = None )
(Hthread_mem1: access_map_equiv (thread_perms tid st1 cnt1) (getCurPerm m1))
(Hthread_mem2: access_map_equiv (thread_perms tid st2 cnt2) (getCurPerm m2)),
let Hcmpt2:= memcompat2 CMatch in
forall (Amatch : match_self (code_inject _ _ SelfSim) mu th_state1 m1 th_state2 m2)
(Hat_external: semantics.at_external CoreSem th_state1 m1 =
Some (MKLOCK, (Vptr b1 ofs :: nil)%list))
(Hlock_update_mem_strict: lock_update_mem_strict b1 (unsigned ofs) m1 m1' vzero),
let evnt1:= Events.mklock (b1, unsigned ofs) in
exists event2 (m2' : mem),
let st2':= fullThreadUpdate st2 tid cnt2 (Kresume sum_state2 Vundef)
(new_perms2, pair0 empty_map) (b2, unsigned ofs + delt) in
match_self (code_inject _ _ SelfSim) mu th_state1 m1 th_state2 m2 /\
inject_sync_event mu evnt1 event2 /\
syncStep(Sem:=HybridSem (Some (S hb))) true cnt2 Hcmpt2 st2' m2' event2.