Section FineGrainedExecutions.
Context
{Sem : Semantics}
{initU : seq.seq nat}
{SemAx : CoreLanguage.SemAxioms}.
Existing Instance dryResources.
Existing Instance HybridFineMachine.scheduler.
Existing Instance OrdinalPool.OrdinalThreadPool.
Existing Instance DryHybridMachineSig.
Existing Instance FineDilMem.
Existing Instance dryFineMach.
(** A location that the machine has no access to (i.e. the permission is empty in all its resources) *)
Inductive deadLocation tp m b ofs : Prop :=
| Dead: forall
(Hvalid: Mem.valid_block m b)
(Hthreads: forall i (cnti: containsThread tp i),
(getThreadR cnti).1 !! b ofs = None /\ (getThreadR cnti).2 !! b ofs = None)
(Hresources: forall l pmap,
lockRes tp l = Some pmap ->
pmap.1 !! b ofs = None /\ pmap.2 !! b ofs = None),
deadLocation tp m b ofs.
(** ** Properties of specific stepss and executions *)
(** [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)).
(*TODO: Move to ev_semantics*)
Definition in_free_list (b : block) ofs xs :=
exists x, List.In x xs /\
let '(b', lo, hi) := x in
b = b' /\
(lo <= ofs < hi)%Z.
Fixpoint in_free_list_trace (b : block) ofs es :=
match es with
| event_semantics.Free l :: es =>
in_free_list b ofs l \/ in_free_list_trace b ofs es
| _ :: es =>
in_free_list_trace b ofs es
| [:: ] =>
False
end.
(** Either the location was freed*)
(** or it wasn't and the operation denoted by the event implies the permission*)
(** or it wasn't and the operation denoted by the event implies the permission*)
(** *** Properties about permission decay and events *)
Fixpoint lockRes_data_permission_add_execution U
U' tr tpi mi tpj mj tr' laddr rmapj b ofs
(Hres: lockRes tpi laddr = None)
(Hres': lockRes tpj laddr = Some rmapj)
(Hexec: multi_step (U, tr, tpi) mi (U', tr ++ tr', tpj) mj)
(Hperm': Mem.perm_order'' (rmapj.1 !! b ofs) (Some Readable)) {struct U}:
exists v ev,
nth_error tr' v = Some ev /\ action ev = Release /\
location ev = Some (laddr, lksize.LKSIZE_nat)
with
lockRes_data_permission_increase_execution U {struct U}:
forall U' tr tpi mi tpj mj tr' laddr rmapi rmapj b ofs
(Hres: lockRes tpi laddr = Some rmapi)
(Hres': lockRes tpj laddr = Some rmapj)
(Hexec: multi_step (U, tr, tpi) mi (U', tr ++ tr', tpj) mj)
(Hperm: ~ Mem.perm_order'' (rmapi.1 !! b ofs) (Some Readable))
(Hperm': Mem.perm_order'' (rmapj.1 !! b ofs) (Some Readable)),
exists v ev,
nth_error tr' v = Some ev /\ action ev = Release /\
location ev = Some (laddr, lksize.LKSIZE_nat).
Fixpoint lockRes_lock_permission_add_execution U
U' tr tpi mi tpj mj tr' laddr rmapj b ofs
(Hres: lockRes tpi laddr = None)
(Hres': lockRes tpj laddr = Some rmapj)
(Hexec: multi_step (U, tr, tpi) mi (U', tr ++ tr', tpj) mj)
(Hperm': Mem.perm_order'' (rmapj.2 !! b ofs) (Some Readable)) {struct U}:
exists v ev,
nth_error tr' v = Some ev /\ action ev = Release /\
location ev = Some (laddr, lksize.LKSIZE_nat)
with
lockRes_lock_permission_increase_execution U {struct U}:
forall U' tr tpi mi tpj mj tr' laddr rmapi rmapj b ofs
(Hres: lockRes tpi laddr = Some rmapi)
(Hres': lockRes tpj laddr = Some rmapj)
(Hexec: multi_step (U, tr, tpi) mi (U', tr ++ tr', tpj) mj)
(Hperm: ~ Mem.perm_order'' (rmapi.2 !! b ofs) (Some Readable))
(Hperm': Mem.perm_order'' (rmapj.2 !! b ofs) (Some Readable)),
exists v ev,
nth_error tr' v = Some ev /\ action ev = Release /\
location ev = Some (laddr, lksize.LKSIZE_nat).

Lemma thread_spawn_step:
forall U tr tp m U' tp' m' tr' tidn
(cnt: ~ containsThread tp tidn)
(cnt': containsThread tp' tidn)
(Hstep: MachStep (U, tr, tp) m (U', tr ++ tr', tp') m'),
exists ev,
tr' = [:: ev] /\ action ev = Spawn.