(*memories that do not contain "dangling pointers"*)
Definition mem_wd m := Mem.inject_neutral (Mem.nextblock m) m.

(* Specifications: *)
Lemma mem_wdI: forall m, (forall (b:block) ofs (R:Mem.perm m b ofs Cur Readable), memval_inject (Mem.flat_inj (Mem.nextblock m)) (ZMap.get ofs (PMap.get b (Mem.mem_contents m))) (ZMap.get ofs (PMap.get b (Mem.mem_contents m)))) -> mem_wd m.
Lemma mem_wd_E: forall m, mem_wd m -> Mem.inject (Mem.flat_inj (Mem.nextblock m)) m m.
Lemma meminj_split_flatinjR: forall j m m' (J:Mem.inject j m' m), mem_wd m -> j = compose_meminj j (Mem.flat_inj (Mem.nextblock m)).
Lemma meminj_split_flatinjL: forall j m m' (J:Mem.inject j m m'), mem_wd m -> j = compose_meminj (Mem.flat_inj (Mem.nextblock m)) j.
Lemma mem_wd_inject_splitL: forall j m1 m2 (J:Mem.inject j m1 m2) (WD: mem_wd m1), Mem.inject (Mem.flat_inj (Mem.nextblock m1)) m1 m1 /\ j = compose_meminj (Mem.flat_inj (Mem.nextblock m1)) j.
Lemma mem_wd_inject_splitR: forall j m1 m2 (J:Mem.inject j m1 m2) (WD: mem_wd m2), Mem.inject (Mem.flat_inj (Mem.nextblock m2)) m2 m2 /\ j = compose_meminj j (Mem.flat_inj (Mem.nextblock m2)).
Lemma mem_wd_empty: mem_wd Mem.empty.
Lemma mem_wd_alloc: forall m b lo hi m' (ALL: Mem.alloc m lo hi = (m',b)) (WDm: mem_wd m), mem_wd m'.
Lemma mem_wd_drop: forall m b lo hi p m' (DROP: Mem.drop_perm m b lo hi p = Some m') (WDm: mem_wd m), Mem.valid_block m b -> mem_wd m'.
Lemma free_neutral: forall (thr : block) (m : mem) (lo hi : Z) (b : block) (m' : Mem.mem') (FREE: Mem.free m b lo hi = Some m'), Mem.inject_neutral thr m -> Mem.inject_neutral thr m'.
Lemma mem_wd_free: forall m b lo hi m' (WDm: mem_wd m) (FREE: Mem.free m b lo hi = Some m'), mem_wd m'.
Lemma mem_wd_store: forall m b ofs v m' chunk (WDm: mem_wd m) (ST: Mem.store chunk m b ofs v = Some m') (V: val_valid v m), mem_wd m'.
Lemma extends_memwd: forall m1 m2 (Ext: Mem.extends m1 m2), mem_wd m2 -> mem_wd m1.