Definition access_cohere (m: mem)  (phi: rmap) :=
forall loc,  access_at m loc Cur = perm_of_res (phi @ loc).
Definition max_access_at m loc := access_at m loc Max.
Definition max_access_cohere (m: mem) (phi: rmap)  :=
forall loc,
perm_order'' (max_access_at m loc) (perm_of_res' (phi @ loc)).
(* Definition max_access_cohere (m: mem) (phi: rmap)  := forall loc, match phi @ loc with | YES rsh sh _ _ => perm_order'' (max_access_at m loc) (perm_of_sh rsh (pshare_sh sh)) | NO rsh => perm_order'' (max_access_at m loc) (perm_of_sh rsh Share.bot ) | PURE _ _ => (fst loc < nextblock m)%positive end. *)
Definition alloc_cohere (m: mem) (phi: rmap) :=
forall loc,  (fst loc >= nextblock m)%positive -> phi @ loc = NO Share.bot bot_unreadable.
Inductive juicy_mem: Type :=
mkJuicyMem: forall (m: mem) (phi: rmap)
(JMcontents: contents_cohere m phi)
(JMaccess: access_cohere m phi)
(JMmax_access: max_access_cohere m phi)
(JMalloc: alloc_cohere m phi),
juicy_mem.
Section selectors.
Variable (j: juicy_mem).
Definition m_dry := match j with mkJuicyMem m _ _ _ _ _ => m end.
Definition m_phi := match j with mkJuicyMem _ phi _ _ _ _ => phi end.

Lemma nreadable_inv: forall phi loc, ~readable loc phi
-> (exists sh, exists nsh, phi @ loc = NO sh nsh)
\/ (exists sh, exists rsh, exists k, exists pp, phi @ loc = YES sh rsh k pp /\ ~isVAL k)
\/ (exists k, exists pp, phi @ loc = PURE k pp).