Repository navigation
feat!: reach foreign code only through a contract - #87
Open
owenthcarey wants to merge 2 commits into
Open
owenthcarey wants to merge 2 commits into
owenthcarey wants to merge 2 commits into
Conversation
Implements RFC 0057 (docs/rfcs/0057-foreign-code-by-contract.md). A safe function reaches code WeaveC did not compile (the C library, a system library, a unit built with -fno-weavec) only through a contract: a row of the library table, which now has one for every function and global of the covered headers through which a pointer crosses (scripts/check-table.py), or a declaration the program marks WEAVEC_FOREIGN (with *p counts and WEAVEC_FOREIGN_FIELD for a foreign struct's members), which the checker lowers to a row (lib/Frontend/SafeForeign.cpp). Each safe unit records what it calls with no contract, and the driver refuses a link in which no input WeaveC compiled defines one ([weavec-safe:foreign-call], with the contract proposed). The checked build watches the bytes after what a contract lets foreign code write (foreign-overflow). The ledger and the audit list every contract and say whether the program is closed. BREAKING CHANGE: runtime ABI 53, weavec-ledger 17, weavec-audit 12, weavec-defs 3, weavec.h 3.6. A safe program that calls a foreign function through which a pointer crosses, with no contract, no longer links. In safe C a pointer passed through `...` to a function with no row is foreign-call. Table rows that keep a pointer say `kept`, and a contract that gives foreign code a struct with a WEAVEC_ENDED_BY member is bad-annotation. The RFC stays Accepted: its gates G4 (time) and G7 fail; see its Measured gates.
A zero-byte watch at the end of an object now finds the slot `end` lies in, so `__weavec_rt_foreign_before` no longer writes its pattern into the next slot. `__weavec_rt_foreign_after` compares and reports the bytes only while they are still the redzone `before` watched, and puts them back only then or while they still hold the pattern: a callback that grows its block in its slot with `realloc`, or releases it, during the call keeps its bytes and gets no false foreign-overflow (rt_test `foreign-watch-changes`). The link's records keep the bytes of an LTO object named on the command line for as long as the module read lazily from them. Refs RFC 0057 (docs/rfcs/0057-foreign-code-by-contract.md).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements RFC 0057 — Foreign code by contract (Accepted; its Implementation amendments and Measured gates record what was built differently and what was measured).
What changes
A safe function reaches code WeaveC did not compile (the C library, a system library, a unit built with
-fno-weavec) only through a contract:scripts/check-table.py(the hygiene gate'stable-row) holds the table to the platform's headers. The grammar gains*aN,aE-aS,handle,kept,ptr:str,ptr:bytes,ptr:ofandglobalrows.WEAVEC_FOREIGNon a redeclared prototype (with*pcounts) andWEAVEC_FOREIGN_FIELDfor a foreign struct's members are lowered to rows (lib/Frontend/SafeForeign.cpp), so safe callers compare, guarded callers guard and address-taken functions get thunks exactly as for the table.-fweavec-contracts=<header>gives a contract header to every unit.foreign-callat the link. Each safe unit records what it calls with no contract (weavec-defs 3:X,K,N,U); the driver refuses a link in which no input WeaveC compiled defines one, and prints the contract it proposes. Images WeaveC linked carry a mark.__weavec_rt_foreign_before,__weavec_rt_foreign_after) and reportsforeign-overflow.foreign,expects,uncrossed,unchecked), audit 12 (closed), the link's summary.Breaking
weavec-ledger17,weavec-audit12,weavec-defs3,weavec.h3.6.[weavec-safe:foreign-call])....to a function with no row isforeign-callwhen the unit compiles; calls that pass no pointer are no longervariadic.setvbuf,setbuf,setbuffer,putenv,tsearch,initstate,setstate,openlog,aio_read,aio_write): a borrow or a local given to them isescapein safe code.WEAVEC_ENDED_BYmember isbad-annotation.Gates (RFC §14; details in Measured gates)
ci-release).The RFC stays Accepted, not Implemented, because G4's time and G7 fail.
Found on main, not changed here
static_cast<const unsigned char *>of aconst void *(pointer-cast) and accepts the non-constform.int-to-pointerdoes not see a cast a system header's macro makes (SQLITE_TRANSIENT) in safe C++.definition-mismatchfor six of its types whose descriptions print alike.