feat(host): add trusted C ABI ResourceProvider v1

- Add the frozen marqdo_resource_provider.h ABI (version + open/read/write/
  close/last_error) and a libloading-based host adapter with version/symbol
  checks and callsite-attached host errors (ADR-0036).
- Add StdHost::register_c_resource_provider using the same kind/name validation
  and project-mode name grant as the in-process/worker providers.
- Compile a C shared-library test provider; cover round-trip and fail-closed
  missing-library behavior. Trusted native code, not a sandbox; plugin-Worker
  binding remains open.
- Update ADRs/spec/status/README/changelog and evidence.

Gate: fmt, clippy -D warnings, 435 tests passed.
This commit is contained in:
cflmy committed 2026-11-20 23:26:25 +08:00
1 parent 01f6fe46a7
commit b22a89e7b4
15 files changed
+577 -2

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
# RFC-CM CM-A09 evidence: C ABI ResourceProvider v1
Date: 2026-11-20 (Asia/Shanghai)
Repository: `marqdo-cli`
Baseline: `12be02e` plus this step's changes.
Decision record: [ADR-0036](../adr/0036-c-abi-resource-provider.md)
Header: [`marqdo_resource_provider.h`](../../crates/marqdo-host/include/marqdo_resource_provider.h)
Related: [in-process provider](2026-11-20-provider-abi-cm-a09.md),
[worker provider](2026-11-20-worker-provider.md), [STATUS §5](../STATUS.md).
Scope: trusted native C ABI adapter; plugin-Worker binding still open.
## ABI
```c
marqdo_resource_provider_abi_version() -> uint32_t (must be 1)
marqdo_resource_open(kind, descriptor, rights_csv, *token) -> i32
marqdo_resource_read(token, buffer, capacity, *read, *eof) -> i32
marqdo_resource_write(token, bytes, length, *written) -> i32
marqdo_resource_close(token) -> i32
marqdo_resource_last_error(buffer, capacity) -> i32
```
The host resolves these symbols at registration, rejects non-v1 libraries and
missing symbols, attaches callsite spans to errors, and never lets a provider
token enter a language `Value`, wire frame or trace.
## Test
`crates/marqdo-host/tests/c_provider.rs` (`#[cfg(unix)]`):
1. builds a C shared library with `cc -shared -fPIC` (skips if `cc` is absent);
2. registers it as provider `cabi` for kind `cabi.sensor` with a project-mode
grant;
3. `resource.open/read/write/close` round-trips `c-`/`abi`, `write=3`, second
close `resource.closed`;
4. a missing library path fails with `kernel.unavailable`.
No Rust runtime/`HostOp`/parser change was needed; language code still sees the
same `resource.*` surface.
## Security boundary
The C library is loaded in-process with host privileges. It is trusted native
code and explicitly **not** a sandbox. Pure/strict refuse provider kinds; strict
remains fail-closed. Untrusted plugin loading remains the separate plugin Worker
transport.
## Not done
* Plugin-Worker resource-provider binding through the existing plugin ABI.
* Provider package installation/signatures/discovery.
* ABI version negotiation beyond v1 rejection.
* Untrusted-provider isolation or strict-mode providers.
* Windows shared-library build/lane.