(** [True] whenever some resource in [tp] has above [Readable] lock-permission on [laddr]*)
(* I could not prove the stronger version, where quantification happens inside each case*)
Definition isLock tp laddr :=
forall ofs, Intv.In ofs (laddr.2, laddr.2 + lksize.LKSIZE)%Z ->
(exists i (cnti: containsThread tp i),
Mem.perm_order'' ((getThreadR cnti).2 !! (laddr.1) ofs) (Some Readable)) \/
(exists laddr' rmap, lockRes tp laddr' = Some rmap /\
Mem.perm_order'' (rmap.2 !! (laddr.1) ofs) (Some Readable)).

(* Specifications: *)
(** If no freelock event is generated by a step, locks are preserved*)
Lemma remLockRes_Freelock:
forall i U tr tr' tp m tp' m' addr
(Hlock: lockRes tp addr)
(HisLock: isLock tp addr)
(Hstep: MachStep (i :: U, tr, tp) m
(U, tr ++ tr', tp') m')
(Hev: forall u ev, nth_error tr' u = Some ev ->
action ev <> Freelock \/
location ev <> Some (addr, lksize.LKSIZE_nat)),
lockRes tp' addr /\
isLock tp' addr.
(** If some address is a lock and there is no event of type Freelock at this address in some trace tr then the address is still a lock at the resulting state *)
Lemma remLockRes_Freelock_execution:
forall U U' tr tr' tp m tp' m' addr
(Hlock: lockRes tp addr)
(HisLock: isLock tp addr)
(Hstep: multi_step (U, tr, tp) m
(U', tr ++ tr', tp') m')
(Hfreelock: forall (u : nat) (evu : machine_event),
nth_error tr' u = Some evu ->
action evu <> Freelock \/
location evu <> Some (addr, lksize.LKSIZE_nat)),
lockRes tp' addr /\
isLock tp' addr.
(** *** Properties of internal steps*)
(** Permissions of addresses that are valid and not freeable do not change by internal steps*)
Lemma ev_elim_stable:
forall m m' b ofs es
(Hvalid: Mem.valid_block m b)
(Hperm: Mem.perm_order'' (Some Writable)
(permission_at m b ofs Cur))
(Helim: ev_elim m es m'),
permission_at m b ofs Cur = permission_at m' b ofs Cur.