Section RESTORE_CALLEE_SAVE.
Variable j: meminj.
Variable cs: list stackframe.
Variable fb: block.
Variable sp: block.
Variable ls0: locset.
Variable m: mem.
Definition agree_unused (ls0: locset) (rs: regset) : Prop :=
forall r, ~(mreg_within_bounds b r) -> Val.inject j (ls0 (R r)) (rs r).
End RESTORE_CALLEE_SAVE.
(** As a corollary, we obtain the following correctness result for the execution of a function epilogue (reloading of used callee-save registers + reloading of the link and return address + freeing of the frame). *)
End FRAME_PROPERTIES.
(** * Call stack invariants *)
(** This is the memory assertion that captures the contents of the stack frames mentioned in the call stacks. *)
Fixpoint stack_contents (j: meminj) (cs: list Linear.stackframe) (cs': list Mach.stackframe) : massert :=
match cs, cs' with
| nil, nil => pure True
| Linear.Stackframe f _ ls c :: cs, Mach.Stackframe fb (Vptr sp' _) ra c' :: cs' =>
frame_contents f j sp' ls (parent_locset cs) (parent_sp cs') (parent_ra cs')
** stack_contents j cs cs'
| _, _ => pure False
end.
(** [match_stacks] captures additional properties (not related to memory) of the Linear and Mach call stacks. *)
Inductive match_stacks (j: meminj):
list Linear.stackframe -> list stackframe -> signature -> Prop :=
| match_stacks_empty: forall sg,
tailcall_possible sg ->
match_stacks j nil nil sg
| match_stacks_cons: forall f sp ls c cs fb sp' ra c' cs' sg trf
(TAIL: is_tail c (Linear.fn_code f))
(FINDF: Genv.find_funct_ptr tge fb = Some (Internal trf))
(TRF: transf_function f = OK trf)
(TRC: transl_code (make_env (function_bounds f)) c = c')
(INJ: j sp = Some(sp', (fe_stack_data (make_env (function_bounds f)))))
(TY_RA: Val.has_type ra Tptr)
(AGL: agree_locs f ls (parent_locset cs))
(ARGS: forall ofs ty,
In (S Outgoing ofs ty) (regs_of_rpairs (loc_arguments sg)) ->
slot_within_bounds (function_bounds f) Outgoing ofs ty)
(STK: match_stacks j cs cs' (Linear.fn_sig f)),
match_stacks j
(Linear.Stackframe f (Vptr sp Ptrofs.zero) ls c :: cs)
(Stackframe fb (Vptr sp' Ptrofs.zero) ra c' :: cs')
sg.
(** Invariance with respect to change of memory injection. *)
(** Invariance with respect to change of signature. *)
(** Typing properties of [match_stacks]. *)

Lemma match_stacks_type_sp:
forall j cs cs' sg,
match_stacks j cs cs' sg ->
Val.has_type (parent_sp cs') Tptr.