Definition AccessMap_EI_Property (j:meminj) (m1 m1' m2 : mem)
(AM:ZMap.t (Z -> perm_kind -> option permission)):Prop :=
forall b2,
(Mem.valid_block m2 b2 -> forall k ofs2,
match j b2 with
None => PMap.get b2 AM ofs2 k  =
PMap.get b2 m2.(Mem.mem_access) ofs2 k
| Some (b3,d3) =>
(Mem.perm m1 b2 ofs2 Max Nonempty ->
PMap.get b2 AM ofs2 k = PMap.get b2 m1'.(Mem.mem_access) ofs2 k)
/\ (~Mem.perm m1 b2 ofs2 Max Nonempty ->
PMap.get b2 AM ofs2 k  = PMap.get b2 m2.(Mem.mem_access) ofs2 k)
end)
/\ (~ Mem.valid_block m2 b2 -> forall k ofs2,
(Mem.perm m1' b2 ofs2 Max Nonempty ->
PMap.get b2 AM ofs2 k = PMap.get b2 m1'.(Mem.mem_access) ofs2 k)
/\ (~Mem.perm m1' b2 ofs2 Max Nonempty -> PMap.get b2 AM ofs2 k = None)).
Definition Content_EI_Property (j:meminj) (m1 m1' m2:Mem.mem)
(CM:ZMap.t (ZMap.t memval)):=
forall b2,
(Mem.valid_block m2 b2 -> forall ofs2,
match j b2 with
None =>  ZMap.get ofs2 (PMap.get b2 CM) =
ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
| Some (b3,delta3) =>
(Mem.perm m1 b2 ofs2 Max Nonempty ->
ZMap.get ofs2 (PMap.get b2 CM) =
ZMap.get ofs2 (PMap.get b2 m1'.(Mem.mem_contents)))
/\ (~Mem.perm m1 b2 ofs2 Max Nonempty ->
ZMap.get ofs2 (PMap.get b2 CM) =
ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents)))
end)
/\ (~ Mem.valid_block m2 b2 -> forall (HM1': Mem.valid_block m1' b2) ofs2,
(Mem.perm m1' b2 ofs2 Cur Readable ->
ZMap.get ofs2 (PMap.get b2 CM) =
ZMap.get ofs2 (PMap.get b2 m1'.(Mem.mem_contents)))
/\ (~Mem.perm m1' b2 ofs2 Cur Readable ->
ZMap.get ofs2 (PMap.get b2 CM) =Undef))
/\ fst CM !! b2 = Undef.
Definition AccessMap_EI_FUN (j:meminj) (m1 m1' m2 : mem) (b2:block):
Z -> perm_kind -> option permission :=
if plt b2 (Mem.nextblock m2)
then (fun ofs2 k =>
match j b2 with
None => PMap.get b2 m2.(Mem.mem_access) ofs2 k
| Some (b3,d3) =>
if Mem.perm_dec m1 b2 ofs2 Max Nonempty
then PMap.get b2 m1'.(Mem.mem_access) ofs2 k
else PMap.get b2 m2.(Mem.mem_access) ofs2 k
end)
else (fun ofs2 k =>
if Mem.perm_dec m1' b2 ofs2 Max Nonempty
then PMap.get b2 m1'.(Mem.mem_access) ofs2 k
else None).
Definition ContentMap_EI_ValidBlock_FUN (j:meminj) m1 m1' m2 b2 ofs2: memval :=
match j b2 with
None => ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
| Some (b3,delta3) =>
if Mem.perm_dec m1 b2 ofs2 Max Nonempty
then ZMap.get ofs2 (PMap.get b2 m1'.(Mem.mem_contents))
else ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
end.
Definition ContentMap_EI_InvalidBlock_FUN m1' b2 ofs2: memval :=
if Mem.perm_dec m1' b2 ofs2 Cur Readable
then ZMap.get ofs2 (PMap.get b2 m1'.(Mem.mem_contents))
else Undef.
Definition ContentMap_EI_Block_FUN j m1 m1' m2 b ofs : memval:=
if plt b (Mem.nextblock m2)
then ContentMap_EI_ValidBlock_FUN j m1 m1' m2 b ofs
else ContentMap_EI_InvalidBlock_FUN m1' b ofs.
Definition ContentsMap_EI_FUN (j:meminj) (m1 m1' m2:Mem.mem) (b:block):
ZMap.t memval.
destruct (plt b (Mem.nextblock m1')).
apply(CM_block_EI_existsT j m1 m1' m2 b).
apply (ZMap.init Undef).
Defined.

Lemma ContentsMap_EI_existsT: forall (j:meminj) (m1 m1' m2:Mem.mem),
{ M : PMap.t (ZMap.t memval) |
fst M = ZMap.init Undef /\
forall b, PMap.get b M = ContentsMap_EI_FUN j m1 m1' m2 b}.