End DROP.
(** * Generic injections *)
(** A memory state [m1] generically injects into another memory state [m2] via the memory injection [f] if the following conditions hold: - each access in [m2] that corresponds to a valid access in [m1] is itself valid; - the memory value associated in [m1] to an accessible address must inject into [m2]'s memory value at the corersponding address. *)
Record mem_inj (f: meminj) (m1 m2: mem) : Prop :=
mk_mem_inj {
mi_perm:
forall b1 b2 delta ofs k p,
f b1 = Some(b2, delta) ->
perm m1 b1 ofs k p ->
perm m2 b2 (ofs + delta) k p;
mi_align:
forall b1 b2 delta chunk ofs p,
f b1 = Some(b2, delta) ->
range_perm m1 b1 ofs (ofs + size_chunk chunk) Max p ->
(align_chunk chunk | delta);
mi_memval:
forall b1 ofs b2 delta,
f b1 = Some(b2, delta) ->
perm m1 b1 ofs Cur Readable ->
memval_inject f (ZMap.get ofs m1.(mem_contents)#b1) (ZMap.get (ofs+delta) m2.(mem_contents)#b2)
}.
(** Preservation of permissions *)

(* Specifications: *)
Lemma perm_inj:
forall f m1 m2 b1 ofs k p b2 delta,
mem_inj f m1 m2 ->
perm m1 b1 ofs k p ->
f b1 = Some(b2, delta) ->
perm m2 b2 (ofs + delta) k p.
Lemma range_perm_inj:
forall f m1 m2 b1 lo hi k p b2 delta,
mem_inj f m1 m2 ->
range_perm m1 b1 lo hi k p ->
f b1 = Some(b2, delta) ->
range_perm m2 b2 (lo + delta) (hi + delta) k p.
Lemma valid_access_inj:
forall f m1 m2 b1 b2 delta chunk ofs p,
mem_inj f m1 m2 ->
f b1 = Some(b2, delta) ->
valid_access m1 chunk b1 ofs p ->
valid_access m2 chunk b2 (ofs + delta) p.
Lemma perm_inj:
forall f m1 m2 b1 ofs k p b2 delta,
mem_inj f m1 m2 ->
perm m1 b1 ofs k p ->
f b1 = Some(b2, delta) ->
perm m2 b2 (ofs + delta) k p.
Lemma range_perm_inj:
forall f m1 m2 b1 lo hi k p b2 delta,
mem_inj f m1 m2 ->
range_perm m1 b1 lo hi k p ->
f b1 = Some(b2, delta) ->
range_perm m2 b2 (lo + delta) (hi + delta) k p.
Lemma valid_access_inj:
forall f m1 m2 b1 b2 delta chunk ofs p,
mem_inj f m1 m2 ->
f b1 = Some(b2, delta) ->
valid_access m1 chunk b1 ofs p ->
valid_access m2 chunk b2 (ofs + delta) p.