Module JuicyMemOps <: JUICY_MEM_OPS.
Program Definition juicy_mem_store j ch b ofs v: option juicy_mem :=
if valid_access_dec (m_dry j) ch b ofs Writable
then Some (store_juicy_mem j _ ch b ofs v _)
else None.
Next Obligation.
intros.
apply (proj1_sig (valid_access_store (m_dry j) ch b ofs v H)).
Defined.
Next Obligation.
apply (proj2_sig (valid_access_store (m_dry j) ch b ofs v H)).
Defined.
Program Definition juicy_mem_storebytes j b ofs bytes: option juicy_mem :=
if range_perm_dec (m_dry j) b ofs (ofs + Z_of_nat (length bytes)) Cur Writable
then Some (storebytes_juicy_mem j _ b ofs bytes _)
else None.
Next Obligation.
apply (proj1_sig (range_perm_storebytes (m_dry j) b ofs bytes H)).
Defined.
Next Obligation.
apply (proj2_sig (range_perm_storebytes (m_dry j) b ofs bytes H)).
Qed.
Definition juicy_mem_alloc (jm: juicy_mem) (lo hi: Z) : juicy_mem * block :=
(mkJuicyMem (fst (alloc (m_dry jm) lo hi))
(after_alloc lo hi (snd (alloc (m_dry jm) lo hi)) (m_phi jm)
(juicy_mem_alloc_aux1 _ _ _ _ _ (eq_refl _)))
(after_alloc_contents_cohere _ _ _ _ _ (eq_refl _))
(after_alloc_access_cohere _ _ _ _ _ (eq_refl _))
(after_alloc_max_access_cohere _ _ _ _ _ (eq_refl _))
(after_alloc_alloc_cohere _ _ _ _ _ (eq_refl _)),
snd (alloc (m_dry jm) lo hi)).

Lemma juicy_mem_alloc_succeeds: forall j j' b lo hi,
juicy_mem_alloc j lo hi = (j', b) -> (m_dry j', b) = alloc (m_dry j) lo hi.