Goal forall mu Etgt Esrc m2 m2' (WD: SM_wd mu) m1
(TgtHyp: forall b ofs, Etgt b ofs = true ->
(Mem.valid_block m2 b /\
(locBlocksTgt mu b = false ->
exists b1 delta1, foreign_of mu b1 = Some(b,delta1) /\
Esrc b1 (ofs-delta1) = true /\ Mem.perm m1 b1 (ofs-delta1) Max Nonempty)))
(Unch2: Mem.unchanged_on (fun b z => Etgt b z = false) m2 m2')
(*(SrcHyp: forall b ofs, Esrc b ofs = true -> vis mu b = true)*)
nu (WDnu: SM_wd nu)
(X1: forall b, locBlocksTgt nu b = true -> locBlocksTgt mu b = false)
(X2: forall b1 b2 d, foreign_of mu b1 = Some(b2, d) ->
locBlocksSrc nu b1 || locBlocksTgt nu b2 = true ->
pub_of nu b1 = Some(b2,d)),
Mem.unchanged_on (fun b2 z => locBlocksTgt nu b2 = true /\
forall b1 d, (as_inj nu) b1 = Some (b2,d) ->
loc_out_of_bounds m1 b1 (z-d)) m2 m2'.
Inductive match_freelists (j:meminj): list (block * Z * Z) -> list (block * Z * Z) -> Prop :=
match_freelists_nil: match_freelists j nil nil
| match_freelists_cons: forall b1 lo1 hi1 t1 b2 lo2 hi2 t2 delta,
j b1 = Some (b2,delta) ->
lo2 = lo1+delta -> hi2 = hi1+delta ->
match_freelists j t1 t2 ->
match_freelists j ((b1,lo1,hi1)::t1) ((b2,lo2,hi2)::t2).

Lemma after_external_meminj_preserves_globals_as_inj:
forall {F V} (ge: Genv.t F V) mu (WDmu : SM_wd mu)
(PG: meminj_preserves_globals ge (as_inj mu) /\
(forall b, isGlobalBlock ge b = true -> frgnBlocksSrc mu b = true))
nu pubSrc' pubTgt' vals1 m1
(pubSrcHyp: pubSrc' = fun b => andb (locBlocksSrc mu b)
(REACH m1 (exportedSrc mu vals1) b))
(Hnu: nu = replace_locals mu pubSrc' pubTgt')
nu' (WDnu' : SM_wd nu') (INC: extern_incr nu nu')
m2 (SMV: sm_valid mu m1 m2) (SEP: sm_inject_separated nu nu' m1 m2)
frgnSrc' ret1 m1'
(frgnSrcHyp: frgnSrc' = fun b => andb (DomSrc nu' b)
(andb (negb (locBlocksSrc nu' b))
(REACH m1' (exportedSrc nu' (ret1::nil)) b)))
frgnTgt' ret2 m2'
(frgnTgtHyp: frgnTgt' = fun b => andb (DomTgt nu' b)
(andb (negb (locBlocksTgt nu' b))
(REACH m2' (exportedTgt nu' (ret2::nil)) b)))
mu' (WDmu': SM_wd mu') (Mu'Hyp: mu' = replace_externs nu' frgnSrc' frgnTgt'),
meminj_preserves_globals ge (as_inj mu') /\
(forall b, isGlobalBlock ge b = true -> frgnBlocksSrc mu' b = true).