sys_pipe is proven and LINKED (ProofSysPipe.v / LinkSysPipe.v), over
the contracts of myproc / argaddr / pipealloc / fdalloc / fileclose / copyout.
The one callee that used to lack a proof, fileclose, has one now
(../completed/fileclose.md); the cone's only
assumption is the fs-side wp_iput_sconf, which fileclose's inode arm
reaches.
Rocq: SpecSysPipe.v (contract), CodeSysPipe.v (71 instruction facts),
ProofSysPipe.v (the functor). Supporting specs written for it:
SpecArgaddr.v, SpecFdalloc.v.
Every earlier syscall proof touched one end of the model. sys_pipe touches all of them at once and has to make them balance:
- it creates two file references (pipealloc) and installs them in descriptors (fdalloc), where sys_close only destroyed one;
- it copies kernel data out to user memory, so it crosses the
proc_ptaltitude (ProcInv.proc_priv_copy) and the process's page table may grow under it — hence theuptd_extdescriptor in the continuation, as for fetchaddr; - it has four exits over three error tails, each of which must hand back the same resources.
Two fd_slots go in — the per-syscall allowance the +4 in FdSlots.FDSLOTS
exists for — and two come back on every exit:
| exit | where the two units end up |
|---|---|
| pipealloc failed | both returned by pipealloc itself |
| fdalloc(rf) failed | the two fileclose calls return them |
| fdalloc(wf) failed | fdalloc(rf)'s unit pays to re-null ofile[fd0]; the two fileclose calls return two |
| copyout failed | the two fdalloc units pay to re-null both descriptors; the two fileclose return two |
| success | one per fdalloc, straight through |
Making that true required two upstream fixes, both landed:
SpecFilealloc's failure arm now returns itsfd_slot. The scan ran off the end of the table and created no reference, so keeping the unit burned one of a conserved supply on a call that did nothing.SpecPipealloc's failure arm now returns both. InProofPipealloc.vthe unit rides with the cell, exactly asProcInv.ofile_slotdoes it:PF1is now "either*f1is null and its unit is banked, or*f1names a live file whose reference we hold" — and the fileclose that undoes it hands the unit back.T8gained a plainfd_slotpremise for the read end.
Without these, sys_pipe's postcondition could not return its allowance, and a whole-kernel proof could only run sys_pipe finitely often.
SpecFdalloc.v carries a small pure layer — fd_frees fs, the free
descriptors of fs in increasing order, as a fixpoint over the list (not a
filter over seq: every fact is then one induction, and the accumulator is
literally the loop counter fdalloc keeps in a0). Three lemmas carry everything:
fd_frees_head— the head is really a null slot;fd_frees_insert— filling the head pops it, which is what makes two successive fdalloc calls compose: sys_pipe's post saysfd_frees (pv_ofile W) = fd0 :: fd1 :: land never re-derives anything;fd_frees_nil— the empty case.
fdalloc's postcondition is a case analysis on fd_frees, not an
unconstrained "succeeded or not" — the SpecArgfd.arg_fd discipline.
- Nothing about the user's array.
SpecCopyoutdoes not record what the user pages end up holding (proc_ptowns them with existential contents), so no resource here could carry "fdarray[0] = fd0". The limitation is copyout's. - Nothing about the descriptors' contents. The two
file_refs land insideproc_priv, andProcInv.ofile_slotquantifies thefcontentexistentially — so the post can say descriptorfd0names ftable slotk0, but not thatk0's type is FD_PIPE and its pipe is the onefd1names. Recovering that needs a persistent content witness on the ftable authority (anagreecomponent inFileInv.fileUR), which changes the algebra and all three of its proved ghost steps. Flagged, not built. - The two pipe-end references are dropped.
file_refis stage 1 and carries nofile_payload, so the ends pipealloc hands back have nowhere to go once the files enter the fd table.ProofSysPipe.vdrops them with a comment: a leak of the pipe's page in the model, not a soundness hole, and it disappears the momentfile_payloadlands (pipealloc will fold the ends into the twofile_refs and this proof will not mention them).
- The frame is the state. Like pipealloc, every branch after a call
re-reads a stack local rather than a register. The two
ints share one 8-byte slot —fd1low,fd0high — so slot 8 spends the whole function split byInstrBytes.word_pointsto_split4and is rejoined only in the epilogue. - Two blocks that gcc emitted twice are one lemma each, parameterized by
their entry pcs and given their own
instrfacts:sp_ofile_null(slli/addi/add/sd, "p->ofile[fd] = 0" for a symbolic fd — +0x80, +0x90, +0xb8) andsp_close2(ld/jal/ld/jal/c.li, "close both and load −1" — +0x9c and +0xc4). Both are over a symbolic descriptor index; casing on the sixteen fds would be sixteen times the work (the argraw lesson). - Four exits, one epilogue (
sp_epiat +0xd6), plus the copyout-failure tailT7Cat +0x7c which both copyouts branch to.EPI ∧ T7Cis offered as a conjunction — exactly one is taken per path andT7C's own exit is the epilogue, so they must share it rather than split it (the pipealloc idiom). fnodeinjectivity is not needed. A descriptor borrowed back out ofproc_privyieldsfile_ref γf k' q' C'with onlyfnode k = fnode k'; rewriting the cell with that equation is enough for fileclose, which reads its argument out of the cell.
They are lifted into ../durable-notes.md and
../optimization.md; in brief:
- a failing tactic inside a whole-function WP prints the whole goal —
including
tf_page's 4096-conjunct big-op — soSet Printing Depthat the top of such a file is what turns an apparent hang into an error message; timeout N coqcleaves an orphanrocqworker, andpgrep -x coqcdoes not find it, so the next build silently competes with it;- a shared-block lemma must take its pcs as literals, never
a + karithmetic; iFrameon a goal containingproc_privsearches the trapframe page.
Nothing on sys_pipe itself. The two things this file used to flag as blocked are both settled:
filecloseis proven and linked, soLinkSysPipe.vexists (../completed/fileclose.md).- The two pipe-end references are no longer dropped.
file_refcarries its payload now, so pipealloc folds the ends INTO the two references and this proof does not mention them: a descriptor sys_pipe creates really does own its end of the pipe in the model.
What did change in the contract: sys_pipe now carries fileclose's closing
environment (both bundles) and case-splits at the call, because a file taken
back out of a descriptor has an existentially-quantified fcontent and the
type is not recoverable. That knowledge is going to be per-ofile ghost
state in struct proc; see
../design/file-table.md's open items.