Library mcertikos.trap.TSysCall
This file defines the general semantics for primitives at all layers
Require Import Coqlib.
Require Import Maps.
Require Import ASTExtra.
Require Import Integers.
Require Import Floats.
Require Import Values.
Require Import Memory.
Require Import Events.
Require Import Stacklayout.
Require Import Globalenvs.
Require Import AsmX.
Require Import Smallstep.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import FlatMemory.
Require Import CommonTactic.
Require Import AuxLemma.
Require Import RealParams.
Require Import PrimSemantics.
Require Import PrimTMSemantics.
Require Import LAsm.
Require Import XOmega.
Require Import compcert.cfrontend.Ctypes.
Require Import Conventions.
Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatGenSem.
Require Import CalRealPTPool.
Require Import CalRealPT.
Require Import CalRealIDPDE.
Require Import CalRealInitPTE.
Require Import CalRealSMSPool.
Require Import CalRealProcModule.
Require Import INVLemmaMemory.
Require Import INVLemmaThread.
Require Import INVLemmaProc.
Require Import AbstractDataType.
Require Import LoadStoreSem3high.
Require Import IntelPrimSemantics.
Require Export TDispatch.
Require Import GlobalOracleProp.
Require Import SingleOracle.
Require Import Maps.
Require Import ASTExtra.
Require Import Integers.
Require Import Floats.
Require Import Values.
Require Import Memory.
Require Import Events.
Require Import Stacklayout.
Require Import Globalenvs.
Require Import AsmX.
Require Import Smallstep.
Require Import AuxStateDataType.
Require Import Constant.
Require Import GlobIdent.
Require Import FlatMemory.
Require Import CommonTactic.
Require Import AuxLemma.
Require Import RealParams.
Require Import PrimSemantics.
Require Import PrimTMSemantics.
Require Import LAsm.
Require Import XOmega.
Require Import compcert.cfrontend.Ctypes.
Require Import Conventions.
Require Import liblayers.logic.PTreeModules.
Require Import liblayers.logic.LayerLogicImpl.
Require Import liblayers.compat.CompatLayers.
Require Import liblayers.compat.CompatGenSem.
Require Import CalRealPTPool.
Require Import CalRealPT.
Require Import CalRealIDPDE.
Require Import CalRealInitPTE.
Require Import CalRealSMSPool.
Require Import CalRealProcModule.
Require Import INVLemmaMemory.
Require Import INVLemmaThread.
Require Import INVLemmaProc.
Require Import AbstractDataType.
Require Import LoadStoreSem3high.
Require Import IntelPrimSemantics.
Require Export TDispatch.
Require Import GlobalOracleProp.
Require Import SingleOracle.
Section WITHMEM.
Local Open Scope Z_scope.
Context `{single_oracle_prop: SingleOracleProp}.
Context `{real_params : RealParams}.
Context `{multi_oracle_prop: MultiOracleProp}.
Context `{Hstencil: Stencil}.
Context `{Hmem: Mem.MemoryModelX}.
Context `{Hmwd: UseMemWithData mem}.
Local Open Scope Z_scope.
Context `{single_oracle_prop: SingleOracleProp}.
Context `{real_params : RealParams}.
Context `{multi_oracle_prop: MultiOracleProp}.
Context `{Hstencil: Stencil}.
Context `{Hmem: Mem.MemoryModelX}.
Context `{Hmwd: UseMemWithData mem}.
Section Prim.
Definition trap_into_kernel_spec id s m rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16:=
let uctx1:= ZMap.set U_EBX (Vint v4)
(ZMap.set U_OESP (Vint v3)
(ZMap.set U_EBP (Vint v2)
(ZMap.set U_ESI (Vint v1)
(ZMap.set U_EDI (Vint v0) (ZMap.init Vundef))))) in
let uctx2:= ZMap.set U_ES (Vint v8)
(ZMap.set U_EAX (Vint v7)
(ZMap.set U_ECX (Vint v6)
(ZMap.set U_EDX (Vint v5) uctx1))) in
let uctx3:= ZMap.set U_EIP (Vint v12)
(ZMap.set U_ERR (Vint v11)
(ZMap.set U_TRAPNO (Vint v10)
(ZMap.set U_DS (Vint v9) uctx2))) in
let uctx4:= ZMap.set U_SS (Vint v16)
(ZMap.set U_ESP (Vint v15)
(ZMap.set U_EFLAGS (Vint v14)
(ZMap.set U_CS (Vint v13) uctx3))) in
vargs = (Vint v0:: Vint v1 :: Vint v2 :: Vint v3:: Vint v4 :: Vint v5 :: Vint v6
:: Vint v7 :: Vint v8 :: Vint v9:: Vint v10 :: Vint v11 :: Vint v12
:: Vint v13 :: Vint v14 :: Vint v15:: Vint v16 ::nil)
∧ sg = mksignature (AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::
AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::
AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::
AST.Tint::nil) None cc_default
∧ extcall_arguments rs m sg vargs
∧ find_symbol s id = Some b
∧ rs PC = Vptr b Int.zero
∧ thread_proc_exit_user_spec labd uctx4 = Some labd0
∧ rs ESP ≠ Vundef
∧ (∀ b0 o,
rs ESP = Vptr b0 o →
Ple (genv_next s) b0 ∧ Plt b0 (Mem.nextblock m)).
Definition syscall_spec id s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16:=
trap_into_kernel_spec id s m rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16
∧ thread_proc_start_user_spec labd1 = Some (labd´, rs´)
∧ rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF
:: IR ECX :: IR EAX :: RA :: nil)
(undef_regs (List.map preg_of destroyed_at_call) rs))
# EDI <- (ZMap.get U_EDI rs´)# ESI <- (ZMap.get U_ESI rs´)
# EBP <- (ZMap.get U_EBP rs´)# ESP <- (ZMap.get U_ESP rs´)
# EBX <- (ZMap.get U_EBX rs´)# EDX <- (ZMap.get U_EDX rs´)
# ECX <- (ZMap.get U_ECX rs´)# EAX <- (ZMap.get U_EAX rs´)
# PC <- (ZMap.get U_EIP rs´)
∧ (∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
Val.has_type v AST.Tint)
∧ (∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
val_inject (Mem.flat_inj (Mem.nextblock m)) v v).
Lemma proc_start_user_spec_asm_inv :
∀ s m0 labd labd´ (rs:regset) rs´ rs0,
thread_proc_start_user_spec labd = Some (labd´, rs´) →
rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF
:: IR ECX :: IR EAX :: RA :: nil)
(undef_regs (List.map preg_of destroyed_at_call) rs))
# EDI <- (ZMap.get U_EDI rs´)# ESI <- (ZMap.get U_ESI rs´)
# EBP <- (ZMap.get U_EBP rs´)# ESP <- (ZMap.get U_ESP rs´)
# EBX <- (ZMap.get U_EBX rs´)# EDX <- (ZMap.get U_EDX rs´)
# ECX <- (ZMap.get U_ECX rs´)# EAX <- (ZMap.get U_EAX rs´)
# PC <- (ZMap.get U_EIP rs´) →
(∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
Val.has_type v AST.Tint) →
(∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
val_inject (Mem.flat_inj (Mem.nextblock m0)) v v) →
asm_invariant (mem:= mwd (cdata RData)) s rs (m0, labd) →
asm_invariant (mem:= mwd (cdata RData)) s rs0 (m0, labd´).
Proof.
intros. inv H3.
constructor; eauto.
+
inv inv_inject_neutral.
constructor; eauto.
lift_unfold.
val_inject_simpl;
try (eapply H2; omega).
+
repeat apply set_reg_wt;
try constructor; try assumption; simpl;
eapply H1; omega.
Qed.
Lemma syscall_spec_asm_inv :
∀ s m0 labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b id,
syscall_spec id s m0 rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
asm_invariant (mem:= mwd (cdata RData)) s rs (m0, labd) →
asm_invariant (mem:= mwd (cdata RData)) s rs0 (m0, labd´).
Proof.
intros. inv H. destruct H2 as [Hp [Hr[Hv1 Hv2]]].
eapply proc_start_user_spec_asm_inv; eauto.
inv H0.
constructor; eauto.
inv inv_inject_neutral.
constructor; eauto.
Qed.
Lemma trap_into_kernel_low_inv:
∀ id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 n,
trap_into_kernel_spec id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
low_level_invariant n labd →
low_level_invariant n labd0.
Proof.
intros. inv H.
destruct H2 as (_ & _ & _ & _ & HT & _).
destruct thread_proc_exit_user_inv.
eapply tm_exit_user_low_level_invariant; eauto.
Qed.
Lemma syscall_spec_low_inv:
∀ s m0 labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b n id,
syscall_spec id s m0 rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
asm_invariant s rs m0 →
low_level_invariant n labd →
(low_level_invariant n labd0 → low_level_invariant n labd1) →
low_level_invariant n labd´.
Proof.
intros. destruct H as (HT1 & HT2 & _).
destruct thread_proc_start_user_inv.
eapply tm_start_user_low_level_invariant; eauto.
eapply H2.
eapply trap_into_kernel_low_inv; eauto.
Qed.
Lemma trap_into_kernel_high_inv:
∀ id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16,
trap_into_kernel_spec id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
high_level_invariant labd →
high_level_invariant labd0.
Proof.
intros. inv H.
destruct H2 as (_ & _ & _ & _ & HT & _).
destruct thread_proc_exit_user_inv.
eapply tm_exit_user_high_level_invariant; eauto.
Qed.
Lemma syscall_spec_high_inv :
∀ s m0 labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b id,
syscall_spec id s m0 rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
high_level_invariant labd →
(high_level_invariant labd0 → high_level_invariant labd1) →
high_level_invariant labd´.
Proof.
intros. destruct H as (HT1 & HT2 & _).
destruct thread_proc_start_user_inv.
eapply tm_start_user_high_level_invariant; eauto.
eapply H1.
eapply trap_into_kernel_high_inv; eauto.
Qed.
Inductive primcall_sys_dispatch_c_sem
(s: stencil): regset → (mwd (cdata RData)) → regset → (mwd (cdata RData)) → Prop :=
| primcall_sys_dispatch_c_sem_intro:
∀ m labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b,
v12 ≠ Int.repr 0 →
syscall_spec syscall_dispatch s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
sys_dispatch_c_spec s m labd0 = Some labd1 →
primcall_sys_dispatch_c_sem s rs (m, labd) rs0 (m, labd´).
Global Instance primcall_sys_dispatch_c_invariants:
PrimcallInvariants primcall_sys_dispatch_c_sem.
Proof.
destruct sys_dispatch_c_inv.
constructor; intros; inv H.
-
eapply syscall_spec_asm_inv; eauto.
-
eapply syscall_spec_low_inv; eauto. intros.
inv H0. inv inv_inject_neutral.
eapply trap_proc_create_low_inv; eauto.
-
eapply syscall_spec_high_inv; eauto. intros.
eapply trap_proc_create_high_inv; eauto.
Qed.
Definition primcall_sys_dispatch_c_compatsem : compatsem (cdata RData) :=
compatsem_inr
{|
sprimcall_primsem_step :=
{|
sprimcall_step := primcall_sys_dispatch_c_sem;
sprimcall_sig := null_signature;
sprimcall_valid s := true
|};
sprimcall_name := Some syscall_dispatch;
sprimcall_props := Error nil;
sprimcall_invs := OK primcall_sys_dispatch_c_invariants
|}.
Inductive primcall_pagefault_handler_sem
(s: stencil): regset → (mwd (cdata RData)) → regset → (mwd (cdata RData)) → Prop :=
| primcall_pagefault_handler_sem_intro:
∀ m labd labd0 labd1 labd´ rs0 vadr (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b,
v12 ≠ Int.repr 0 →
syscall_spec pgf_handler s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
vadr = fst (ti labd0) →
ptfault_resv_spec (Int.unsigned vadr) labd0 = Some labd1 →
primcall_pagefault_handler_sem s rs (m, labd) rs0 (m, labd´).
Global Instance primcall_pgf_handler_sem_invariants:
PrimcallInvariants primcall_pagefault_handler_sem.
Proof.
constructor; intros; inv H.
-
eapply syscall_spec_asm_inv; eauto.
-
eapply syscall_spec_low_inv; eauto. intros.
destruct ptfault_resv_inv.
eapply semprops_low_level_invariant.
constructor_gen_sem_intro. assumption.
-
eapply syscall_spec_high_inv; eauto. intros.
destruct ptfault_resv_inv.
eapply semprops_high_level_invariant.
constructor_gen_sem_intro. assumption.
Qed.
Definition primcall_pagefault_handler_compatsem : compatsem (cdata RData) :=
compatsem_inr
{|
sprimcall_primsem_step :=
{|
sprimcall_step := primcall_pagefault_handler_sem;
sprimcall_sig := null_signature;
sprimcall_valid s := true
|};
sprimcall_name := Some pgf_handler;
sprimcall_props := Error nil;
sprimcall_invs := OK primcall_pgf_handler_sem_invariants
|}.
Inductive primcall_sys_run_vm_sem
(s: stencil): regset → (mwd (cdata RData)) → regset → (mwd (cdata RData)) → Prop :=
| primcall_sys_run_vm_sem_intro:
∀ m (rs:regset) labd labd0 labd´ rs´ rs0 rs01 rs2 v0 v1 v2 v3 v5 v6 v7
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 vargs sg b,
v12 ≠ Int.repr 0 →
trap_into_kernel_spec sys_run_vm s m rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
rs01 = (Pregmap.init Vundef) #EDI <- (rs EDI) #EBP <- (rs EBP) →
thread_vm_run_spec rs01 labd0 = Some (labd´, rs´) →
rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF :: RA :: nil)
(undef_regs (List.map preg_of destroyed_at_call) rs)) →
rs2 = (rs0#EAX<- (rs´#EAX)#EBX <- (rs´#EBX)#EDX <- (rs´#EDX)
#ESI <- (rs´#ESI)#EDI <- (rs´#EDI)#EBP <- (rs´#EBP)
#PC <- (rs´#RA)) →
∀ N_TYPE: (∀ r, Val.has_type (rs´#r) AST.Tint),
∀ N_INJECT_NEUTRAL: (∀ r, val_inject (Mem.flat_inj (Mem.nextblock m)) (rs´#r) (rs´#r)),
primcall_sys_run_vm_sem s rs (m, labd) rs2 (m, labd´).
Global Instance primcall_sys_run_vm_sem_invariants:
PrimcallInvariants primcall_sys_run_vm_sem.
Proof.
constructor; intros; inv H.
-
inv H0.
constructor; eauto.
+
inv inv_inject_neutral.
constructor; eauto.
val_inject_simpl;
try (eapply N_INJECT_NEUTRAL; simpl; reflexivity).
+
repeat apply set_reg_wt; try eapply N_INJECT_NEUTRAL;
try constructor; try assumption; simpl;
eapply N_TYPE; simpl; reflexivity.
-
exploit (vmx_enter_low_level_invariant thread_vm_run_spec); eauto.
intros. inv H0. inv inv_inject_neutral.
inv H; try (split; [apply inv_reg_wt| apply inv_reg_inject_neutral]).
eapply trap_into_kernel_low_inv; eauto.
-
exploit (vmx_enter_high_level_invariant thread_vm_run_spec); eauto.
eapply trap_into_kernel_high_inv; eauto.
Qed.
Definition primcall_sys_run_vm_compatsem : compatsem (cdata RData) :=
compatsem_inr
{|
sprimcall_primsem_step :=
{|
sprimcall_step := primcall_sys_run_vm_sem;
sprimcall_sig := null_signature;
sprimcall_valid s := true
|};
sprimcall_name := Some sys_run_vm;
sprimcall_props := Error nil;
sprimcall_invs := OK primcall_sys_run_vm_sem_invariants
|}.
End Prim.
Definition trap_into_kernel_spec id s m rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16:=
let uctx1:= ZMap.set U_EBX (Vint v4)
(ZMap.set U_OESP (Vint v3)
(ZMap.set U_EBP (Vint v2)
(ZMap.set U_ESI (Vint v1)
(ZMap.set U_EDI (Vint v0) (ZMap.init Vundef))))) in
let uctx2:= ZMap.set U_ES (Vint v8)
(ZMap.set U_EAX (Vint v7)
(ZMap.set U_ECX (Vint v6)
(ZMap.set U_EDX (Vint v5) uctx1))) in
let uctx3:= ZMap.set U_EIP (Vint v12)
(ZMap.set U_ERR (Vint v11)
(ZMap.set U_TRAPNO (Vint v10)
(ZMap.set U_DS (Vint v9) uctx2))) in
let uctx4:= ZMap.set U_SS (Vint v16)
(ZMap.set U_ESP (Vint v15)
(ZMap.set U_EFLAGS (Vint v14)
(ZMap.set U_CS (Vint v13) uctx3))) in
vargs = (Vint v0:: Vint v1 :: Vint v2 :: Vint v3:: Vint v4 :: Vint v5 :: Vint v6
:: Vint v7 :: Vint v8 :: Vint v9:: Vint v10 :: Vint v11 :: Vint v12
:: Vint v13 :: Vint v14 :: Vint v15:: Vint v16 ::nil)
∧ sg = mksignature (AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::
AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::
AST.Tint::AST.Tint::AST.Tint::AST.Tint::AST.Tint::
AST.Tint::nil) None cc_default
∧ extcall_arguments rs m sg vargs
∧ find_symbol s id = Some b
∧ rs PC = Vptr b Int.zero
∧ thread_proc_exit_user_spec labd uctx4 = Some labd0
∧ rs ESP ≠ Vundef
∧ (∀ b0 o,
rs ESP = Vptr b0 o →
Ple (genv_next s) b0 ∧ Plt b0 (Mem.nextblock m)).
Definition syscall_spec id s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16:=
trap_into_kernel_spec id s m rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16
∧ thread_proc_start_user_spec labd1 = Some (labd´, rs´)
∧ rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF
:: IR ECX :: IR EAX :: RA :: nil)
(undef_regs (List.map preg_of destroyed_at_call) rs))
# EDI <- (ZMap.get U_EDI rs´)# ESI <- (ZMap.get U_ESI rs´)
# EBP <- (ZMap.get U_EBP rs´)# ESP <- (ZMap.get U_ESP rs´)
# EBX <- (ZMap.get U_EBX rs´)# EDX <- (ZMap.get U_EDX rs´)
# ECX <- (ZMap.get U_ECX rs´)# EAX <- (ZMap.get U_EAX rs´)
# PC <- (ZMap.get U_EIP rs´)
∧ (∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
Val.has_type v AST.Tint)
∧ (∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
val_inject (Mem.flat_inj (Mem.nextblock m)) v v).
Lemma proc_start_user_spec_asm_inv :
∀ s m0 labd labd´ (rs:regset) rs´ rs0,
thread_proc_start_user_spec labd = Some (labd´, rs´) →
rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF
:: IR ECX :: IR EAX :: RA :: nil)
(undef_regs (List.map preg_of destroyed_at_call) rs))
# EDI <- (ZMap.get U_EDI rs´)# ESI <- (ZMap.get U_ESI rs´)
# EBP <- (ZMap.get U_EBP rs´)# ESP <- (ZMap.get U_ESP rs´)
# EBX <- (ZMap.get U_EBX rs´)# EDX <- (ZMap.get U_EDX rs´)
# ECX <- (ZMap.get U_ECX rs´)# EAX <- (ZMap.get U_EAX rs´)
# PC <- (ZMap.get U_EIP rs´) →
(∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
Val.has_type v AST.Tint) →
(∀ i, 0 ≤ i < UCTXT_SIZE →
let v:= (ZMap.get i rs´) in
val_inject (Mem.flat_inj (Mem.nextblock m0)) v v) →
asm_invariant (mem:= mwd (cdata RData)) s rs (m0, labd) →
asm_invariant (mem:= mwd (cdata RData)) s rs0 (m0, labd´).
Proof.
intros. inv H3.
constructor; eauto.
+
inv inv_inject_neutral.
constructor; eauto.
lift_unfold.
val_inject_simpl;
try (eapply H2; omega).
+
repeat apply set_reg_wt;
try constructor; try assumption; simpl;
eapply H1; omega.
Qed.
Lemma syscall_spec_asm_inv :
∀ s m0 labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b id,
syscall_spec id s m0 rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
asm_invariant (mem:= mwd (cdata RData)) s rs (m0, labd) →
asm_invariant (mem:= mwd (cdata RData)) s rs0 (m0, labd´).
Proof.
intros. inv H. destruct H2 as [Hp [Hr[Hv1 Hv2]]].
eapply proc_start_user_spec_asm_inv; eauto.
inv H0.
constructor; eauto.
inv inv_inject_neutral.
constructor; eauto.
Qed.
Lemma trap_into_kernel_low_inv:
∀ id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 n,
trap_into_kernel_spec id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
low_level_invariant n labd →
low_level_invariant n labd0.
Proof.
intros. inv H.
destruct H2 as (_ & _ & _ & _ & HT & _).
destruct thread_proc_exit_user_inv.
eapply tm_exit_user_low_level_invariant; eauto.
Qed.
Lemma syscall_spec_low_inv:
∀ s m0 labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b n id,
syscall_spec id s m0 rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
asm_invariant s rs m0 →
low_level_invariant n labd →
(low_level_invariant n labd0 → low_level_invariant n labd1) →
low_level_invariant n labd´.
Proof.
intros. destruct H as (HT1 & HT2 & _).
destruct thread_proc_start_user_inv.
eapply tm_start_user_low_level_invariant; eauto.
eapply H2.
eapply trap_into_kernel_low_inv; eauto.
Qed.
Lemma trap_into_kernel_high_inv:
∀ id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16,
trap_into_kernel_spec id s m0 rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
high_level_invariant labd →
high_level_invariant labd0.
Proof.
intros. inv H.
destruct H2 as (_ & _ & _ & _ & HT & _).
destruct thread_proc_exit_user_inv.
eapply tm_exit_user_high_level_invariant; eauto.
Qed.
Lemma syscall_spec_high_inv :
∀ s m0 labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b id,
syscall_spec id s m0 rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
high_level_invariant labd →
(high_level_invariant labd0 → high_level_invariant labd1) →
high_level_invariant labd´.
Proof.
intros. destruct H as (HT1 & HT2 & _).
destruct thread_proc_start_user_inv.
eapply tm_start_user_high_level_invariant; eauto.
eapply H1.
eapply trap_into_kernel_high_inv; eauto.
Qed.
Inductive primcall_sys_dispatch_c_sem
(s: stencil): regset → (mwd (cdata RData)) → regset → (mwd (cdata RData)) → Prop :=
| primcall_sys_dispatch_c_sem_intro:
∀ m labd labd´ labd0 labd1 rs0 (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b,
v12 ≠ Int.repr 0 →
syscall_spec syscall_dispatch s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
sys_dispatch_c_spec s m labd0 = Some labd1 →
primcall_sys_dispatch_c_sem s rs (m, labd) rs0 (m, labd´).
Global Instance primcall_sys_dispatch_c_invariants:
PrimcallInvariants primcall_sys_dispatch_c_sem.
Proof.
destruct sys_dispatch_c_inv.
constructor; intros; inv H.
-
eapply syscall_spec_asm_inv; eauto.
-
eapply syscall_spec_low_inv; eauto. intros.
inv H0. inv inv_inject_neutral.
eapply trap_proc_create_low_inv; eauto.
-
eapply syscall_spec_high_inv; eauto. intros.
eapply trap_proc_create_high_inv; eauto.
Qed.
Definition primcall_sys_dispatch_c_compatsem : compatsem (cdata RData) :=
compatsem_inr
{|
sprimcall_primsem_step :=
{|
sprimcall_step := primcall_sys_dispatch_c_sem;
sprimcall_sig := null_signature;
sprimcall_valid s := true
|};
sprimcall_name := Some syscall_dispatch;
sprimcall_props := Error nil;
sprimcall_invs := OK primcall_sys_dispatch_c_invariants
|}.
Inductive primcall_pagefault_handler_sem
(s: stencil): regset → (mwd (cdata RData)) → regset → (mwd (cdata RData)) → Prop :=
| primcall_pagefault_handler_sem_intro:
∀ m labd labd0 labd1 labd´ rs0 vadr (rs:regset) rs´ v0 v1 v2 v3 v5 v6
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 v7 vargs sg b,
v12 ≠ Int.repr 0 →
syscall_spec pgf_handler s m rs rs´ rs0 labd labd0 labd1 labd´ vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
vadr = fst (ti labd0) →
ptfault_resv_spec (Int.unsigned vadr) labd0 = Some labd1 →
primcall_pagefault_handler_sem s rs (m, labd) rs0 (m, labd´).
Global Instance primcall_pgf_handler_sem_invariants:
PrimcallInvariants primcall_pagefault_handler_sem.
Proof.
constructor; intros; inv H.
-
eapply syscall_spec_asm_inv; eauto.
-
eapply syscall_spec_low_inv; eauto. intros.
destruct ptfault_resv_inv.
eapply semprops_low_level_invariant.
constructor_gen_sem_intro. assumption.
-
eapply syscall_spec_high_inv; eauto. intros.
destruct ptfault_resv_inv.
eapply semprops_high_level_invariant.
constructor_gen_sem_intro. assumption.
Qed.
Definition primcall_pagefault_handler_compatsem : compatsem (cdata RData) :=
compatsem_inr
{|
sprimcall_primsem_step :=
{|
sprimcall_step := primcall_pagefault_handler_sem;
sprimcall_sig := null_signature;
sprimcall_valid s := true
|};
sprimcall_name := Some pgf_handler;
sprimcall_props := Error nil;
sprimcall_invs := OK primcall_pgf_handler_sem_invariants
|}.
Inductive primcall_sys_run_vm_sem
(s: stencil): regset → (mwd (cdata RData)) → regset → (mwd (cdata RData)) → Prop :=
| primcall_sys_run_vm_sem_intro:
∀ m (rs:regset) labd labd0 labd´ rs´ rs0 rs01 rs2 v0 v1 v2 v3 v5 v6 v7
v8 v9 v10 v11 v12 v13 v14 v15 v16 v4 vargs sg b,
v12 ≠ Int.repr 0 →
trap_into_kernel_spec sys_run_vm s m rs labd labd0 vargs sg b
v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 →
rs01 = (Pregmap.init Vundef) #EDI <- (rs EDI) #EBP <- (rs EBP) →
thread_vm_run_spec rs01 labd0 = Some (labd´, rs´) →
rs0 = (undef_regs (CR ZF :: CR CF :: CR PF :: CR SF :: CR OF :: RA :: nil)
(undef_regs (List.map preg_of destroyed_at_call) rs)) →
rs2 = (rs0#EAX<- (rs´#EAX)#EBX <- (rs´#EBX)#EDX <- (rs´#EDX)
#ESI <- (rs´#ESI)#EDI <- (rs´#EDI)#EBP <- (rs´#EBP)
#PC <- (rs´#RA)) →
∀ N_TYPE: (∀ r, Val.has_type (rs´#r) AST.Tint),
∀ N_INJECT_NEUTRAL: (∀ r, val_inject (Mem.flat_inj (Mem.nextblock m)) (rs´#r) (rs´#r)),
primcall_sys_run_vm_sem s rs (m, labd) rs2 (m, labd´).
Global Instance primcall_sys_run_vm_sem_invariants:
PrimcallInvariants primcall_sys_run_vm_sem.
Proof.
constructor; intros; inv H.
-
inv H0.
constructor; eauto.
+
inv inv_inject_neutral.
constructor; eauto.
val_inject_simpl;
try (eapply N_INJECT_NEUTRAL; simpl; reflexivity).
+
repeat apply set_reg_wt; try eapply N_INJECT_NEUTRAL;
try constructor; try assumption; simpl;
eapply N_TYPE; simpl; reflexivity.
-
exploit (vmx_enter_low_level_invariant thread_vm_run_spec); eauto.
intros. inv H0. inv inv_inject_neutral.
inv H; try (split; [apply inv_reg_wt| apply inv_reg_inject_neutral]).
eapply trap_into_kernel_low_inv; eauto.
-
exploit (vmx_enter_high_level_invariant thread_vm_run_spec); eauto.
eapply trap_into_kernel_high_inv; eauto.
Qed.
Definition primcall_sys_run_vm_compatsem : compatsem (cdata RData) :=
compatsem_inr
{|
sprimcall_primsem_step :=
{|
sprimcall_step := primcall_sys_run_vm_sem;
sprimcall_sig := null_signature;
sprimcall_valid s := true
|};
sprimcall_name := Some sys_run_vm;
sprimcall_props := Error nil;
sprimcall_invs := OK primcall_sys_run_vm_sem_invariants
|}.
End Prim.
Definition tsyscall_fresh : compatlayer (cdata RData) :=
∅ ⊕
syscall_dispatch ↦ primcall_sys_dispatch_c_compatsem
⊕ pgf_handler ↦ primcall_pagefault_handler_compatsem
⊕ sys_run_vm ↦ primcall_sys_run_vm_compatsem.
∅ ⊕
syscall_dispatch ↦ primcall_sys_dispatch_c_compatsem
⊕ pgf_handler ↦ primcall_pagefault_handler_compatsem
⊕ sys_run_vm ↦ primcall_sys_run_vm_compatsem.
Definition tsyscall_passthrough : compatlayer (cdata RData) :=
vmxinfo_get ↦ gensem thread_vmxinfo_get_spec
⊕ pt_read ↦ gensem thread_ptRead_spec
⊕ uctx_get ↦ gensem thread_uctx_get_spec
⊕ uctx_set ↦ gensem thread_uctx_set_spec
⊕ get_CPU_ID ↦ gensem thread_get_CPU_ID_spec
⊕ get_curid ↦ gensem thread_get_curid_spec
⊕ vmx_return_from_guest ↦ primcall_vmx_return_compatsem thread_vmx_return_from_guest_spec
⊕ vmx_init ↦ vmcs_set_defaults_compatsem thread_vmx_init_spec
⊕ trap_get ↦ primcall_trap_info_get_compatsem thread_trap_info_get_spec
⊕ trap_set ↦ primcall_trap_info_ret_compatsem thread_trap_info_ret_spec
⊕ accessors ↦ {| exec_load := (@exec_loadex _ _ _ _ _ _ _ _ Hmwd);
exec_store := (@exec_storeex _ _ _ _ _ _ _ _ Hmwd) |}.
vmxinfo_get ↦ gensem thread_vmxinfo_get_spec
⊕ pt_read ↦ gensem thread_ptRead_spec
⊕ uctx_get ↦ gensem thread_uctx_get_spec
⊕ uctx_set ↦ gensem thread_uctx_set_spec
⊕ get_CPU_ID ↦ gensem thread_get_CPU_ID_spec
⊕ get_curid ↦ gensem thread_get_curid_spec
⊕ vmx_return_from_guest ↦ primcall_vmx_return_compatsem thread_vmx_return_from_guest_spec
⊕ vmx_init ↦ vmcs_set_defaults_compatsem thread_vmx_init_spec
⊕ trap_get ↦ primcall_trap_info_get_compatsem thread_trap_info_get_spec
⊕ trap_set ↦ primcall_trap_info_ret_compatsem thread_trap_info_ret_spec
⊕ accessors ↦ {| exec_load := (@exec_loadex _ _ _ _ _ _ _ _ Hmwd);
exec_store := (@exec_storeex _ _ _ _ _ _ _ _ Hmwd) |}.
Definition tsyscall : compatlayer (cdata RData) := tsyscall_fresh ⊕ tsyscall_passthrough.
End WITHMEM.
End WITHMEM.