Semantics.lean
Whole-Binary ELF Process Semantics & Safety/Correctness Specifications (Arm64.)
-
Layer / Role:
Arm64Trusted Computing Base (Role::Spec, definitions only, 0 theorems). -
Purpose & Key Exports: Process-level termination and safety relations over
Arm64./Step Arm64.(Steps Program.,pureWithSvc Program.,pureMem ProcessTerminatedOutcome,ProcessExitsWith, the partial-correctnessProcessPartialRunsTo,ProcessTerminates, and the totalProcessRunsTo:=ProcessTerminates∧ProcessPartialRunsTo) and the top-level whole-binary specifications over raw ELF bytes, an input preconditionpre, and a relational postconditionpost: totalElfRunsTo(with the wrappersElfCorrect(exit0) andElfSafe(exit0, trivialpost)) and partialElfPartialRunsTo(no termination claim). -
When to read: Read when auditing a whole-binary theorem statement (
ElfRunsTo,ElfPartialRunsTo,ElfCorrect,ElfSafe). Proof rules, per-image stepping stones, and executable runners live inProofLib/.Process.lean
@[expose] public sectionnamespace Arm647 declarations not shown (lines 35–61): theorems, which Lean checks, or definitions that no headline statement uses
Arm64., Arm64., Arm64., Arm64., Arm64., Arm64., Arm64.
namespace Processdef ProcessTerminatedOutcome
State sf has terminated normally (SYS_exit / SYS_exit_group with signal = none) or by fatal signal (ExecStatus. sig with exitCode = 128 + sig.signal = some sig.), yielding observable outcome out.
def ProcessTerminatedOutcome (sf : State) (out : ProcessOutcome) : Prop :=
(∃ code, sf.status = .Exited code ∧ out = ProcessOutcome.ofState code sf) ∨
(∃ sig, sf.status = .Signaled sig ∧ out = ProcessOutcome.ofSignal sig sf)def ProcessExitsWith
Execution of prog from initial state s0 reaches a terminated state sf (.Exited or .Signaled) whose observable outcome (exitCode, signal, stdout, stderr, fs) is out.
def ProcessExitsWith (prog : Program) (s0 : State) (out : ProcessOutcome) : Prop :=
∃ sf,
Steps prog s0 sf ∧
ProcessTerminatedOutcome sf outdef ProcessPartialRunsTo
Partial correctness (step safety) of the process run of prog from initial state s0: every state s' reachable from s0 under Steps prog either
-
has terminated (
ProcessTerminatedOutcomes' out, .Exitedor .Signaled) withpost out, -
has stopped with virtual or physical memory exhaustion (.
OutOfMemoryinbrk/mmap/mprotect/mremap) and satisfiesoom s'(defaultFalse), or -
is .
Runningand can take a validStepprog transition. In particular, no reachable state ever faults (.Exception), halts on unmapped/undecodable memory (.Halted), or hits a hook panic (.Panicked), and every terminated outcome satisfiespost. This makes no termination claim: a run that never stops satisfies it as long as it never gets stuck, sopostandoomconstrain only the runs that do stop.
def ProcessPartialRunsTo (prog : Program) (s0 : State)
(post : ProcessOutcome → Prop)
(oom : State → Prop := fun _ => False) : Prop :=
∀ s', Steps prog s0 s' →
(∃ out, ProcessTerminatedOutcome s' out ∧ post out) ∨
(s'.status = .OutOfMemory ∧ oom s') ∨
(s'.status = .Running ∧ ∃ s'', Step prog s' s'')def ProcessTerminates
Termination of the process run of prog from initial state s0: some run reaches a terminated state (ProcessExitsWith prog s0 out, .Exited or .Signaled) whose outcome satisfies post out, or stops with .OutOfMemory in a state satisfying oom (default False).
def ProcessTerminates (prog : Program) (s0 : State)
(post : ProcessOutcome → Prop)
(oom : State → Prop := fun _ => False) : Prop :=
(∃ out, ProcessExitsWith prog s0 out ∧ post out) ∨
(∃ sf, Steps prog s0 sf ∧ sf.status = .OutOfMemory ∧ oom sf)def ProcessRunsTo
Total correctness of the process run of prog from initial state s0: the run terminates (ProcessTerminates) and satisfies step safety (ProcessPartialRunsTo) with the same post and oom.
def ProcessRunsTo (prog : Program) (s0 : State)
(post : ProcessOutcome → Prop)
(oom : State → Prop := fun _ => False) : Prop :=
ProcessTerminates prog s0 post oom ∧ ProcessPartialRunsTo prog s0 post oom4 declarations not shown (lines 117–178): theorems, which Lean checks, or definitions that no headline statement uses
Arm64., Arm64., Arm64., Arm64.
end Processend Arm64