(*Lenb: moved to mpred Definition assert := environ -> mpred.  (* Unfortunately can't export this abbreviation through SeparationLogic.v because it confuses the Lift system *)
*)
Definition writable_block (id: ident) (n: Z): assert :=
fun rho =>
EX b: block,  EX sh: Share.t,
!! (writable_share sh /\ ge_of rho id = Some b) && VALspec_range n sh (b, 0).
Fixpoint writable_blocks (bl : list (ident*Z)) : assert :=
match bl with
| nil =>  fun rho => emp
| (b,n)::bl' =>  fun rho => writable_block b n rho * writable_blocks bl' rho
end.
Fixpoint address_mapsto_zeros (sh: share) (n: nat) (adr: address) : mpred :=
match n with
| O => emp
| S n' => address_mapsto Mint8unsigned (Vint Int.zero) sh adr
* address_mapsto_zeros sh n' (fst adr, Z.succ (snd adr))
end.
Definition address_mapsto_zeros' (n: Z) : spec :=
fun (sh: Share.t) (l: address) =>
allp (jam (adr_range_dec l (Z.max n 0))
(fun l' => yesat NoneP (VAL (Byte Byte.zero)) sh l')
noat) && noghost.
Definition mapsto_zeros (n: Z) (sh: share) (a: val) : mpred :=
match a with
| Vptr b z =>
!! (0 <= Ptrofs.unsigned z  /\ n + Ptrofs.unsigned z < Ptrofs.modulus)%Z &&
address_mapsto_zeros sh (Z.to_nat n) (b, Ptrofs.unsigned z)
| _ => FF
end.
Fixpoint memory_block' (sh: share) (n: nat) (b: block) (i: Z) : mpred :=
match n with
| O => emp
| S n' => mapsto_ sh (Tint I8 Unsigned noattr) (Vptr b (Ptrofs.repr i))
* memory_block' sh n' b (i+1)
end.
Definition memory_block'_alt (sh: share) (n: nat) (b: block) (ofs: Z) : mpred :=
if readable_share_dec sh
then VALspec_range (Z_of_nat n) sh (b, ofs)
else nonlock_permission_bytes sh (b,ofs) (Z.of_nat n).
Definition memory_block (sh: share) (n: Z) (v: val) : mpred :=
match v with
| Vptr b ofs => (!!(Ptrofs.unsigned ofs + n < Ptrofs.modulus)) && memory_block' sh (Z.to_nat n) b (Ptrofs.unsigned ofs)
| _ => FF
end.
Hint Resolve is_pointer_or_null_nullval : core.
Hint Resolve tc_val_pointer_nullval' : core.
Arguments type_is_volatile ty / .
Definition is_int32_noattr_type t :=
match t with
| Tint I32 _ {| attr_volatile := false; attr_alignas := None |} => True
| _ => False
end.

Lemma tc_val_pointer_nullval:
forall t, tc_val (Tpointer t noattr) nullval.