Skip to content

fix(pj_plugins): entry-point symbol provenance + modern platform loaders (0.23.0) - #175

Merged
facontidavide merged 5 commits into
mainfrom
fix/loader-symbol-provenance
Aug 11, 2026
Merged

fix(pj_plugins): entry-point symbol provenance + modern platform loaders (0.23.0)#175
facontidavide merged 5 commits into
mainfrom
fix/loader-symbol-provenance

Conversation

@facontidavide

Copy link
Copy Markdown
Contributor

Implements the SDK half of PJ4 marketplace plan row 12b.

What

  • Symbol provenance: pj_plugin_abi_version and every PJ_get_*_vtable entry point must resolve from the candidate DSO itself. POSIX: dladdr compared byte-first against the recorded absolute dlopen path (zero filesystem access on the fast path; std::filesystem::equivalent fallback), so deferred dialog resolution survives file deletion and CWD changes. macOS adds RTLD_FIRST. Windows: GetModuleHandleExW(FROM_ADDRESS) closes the PE forwarded-export hole.
  • Modern Windows loading: LoadLibraryExW + LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|DEFAULT_DIRS in both loaders — CWD and PATH no longer resolve plugin dependencies. Loader signatures are path-typed with internal absolute normalization; the native-parser narrow API keeps its strict UTF-8 contract.
  • Single-open adoption API for the PJ4 admission helper: non-owning adopt, loadFromHandle on all four families (validation chain identical to load()), handle-based inspectPluginDso, provenance-checked family enumeration.
  • Rpath standardization: plugin targets get INSTALL_RPATH $ORIGIN / @loader_path (build rpaths untouched).

Verification

  • New tests: EntryPointSymbolResolvedFromDependencyIsRejected (first two-DSO fixture in the repo, both weak-symbol directions), DependencySearchExcludesCwdAndPath, UnicodeExtensionPathLoadsOnWindows, DialogVtableSurvivesCandidateFileDeletion, DialogVtableSurvivesCwdChangeAfterRelativeLoad, NativeParserNarrowPathIsUtf8, Windows-only ForwardedEntryPointIsRejected.
  • Two-round review (probe-licensed correctness + cold session); every surviving finding fixed TDD-first in the second commit.
  • Full suite 74/74; abi/baseline.abi untouched; zero behavior change for well-formed plugins (declined alternatives documented: no RTLD_NODELETE contract, no RTLD_DEEPBIND, no dlmopen).

Note: open PR #173 also stages VERSION 0.23.0 — whichever lands second rebases its version/changelog heading (the release workflow hard-fails on tag/VERSION mismatch, so this cannot ship wrong).

🤖 Generated with Claude Code

https://claude.ai/code/session_0165qLfnJYSYb51NQMdPidZr

facontidavide and others added 5 commits August 11, 2026 08:02
…ers (0.23.0)

Resolve pj_plugin_abi_version and the PJ_get_*_vtable entry points
strictly from the candidate DSO: dladdr + filesystem::equivalent identity
on Linux, RTLD_FIRST on macOS, module-scoped GetProcAddress unchanged on
Windows. Replace LoadLibraryExA + LOAD_WITH_ALTERED_SEARCH_PATH with
LoadLibraryExW + DLL_LOAD_DIR|DEFAULT_DIRS in both loaders (CWD and PATH
no longer resolve dependencies), make loader signatures path-typed with
internal absolute-path normalization, and delete the ACP/UTF-8 contract
mismatch. Add the single-open adoption API (non-owning adopt,
loadFromHandle on all four families, handle-based inspection, provenance-
checked family enumeration) for the admission helper. Standardize plugin
install rpaths ($ORIGIN / @loader_path). Tests: two-DSO provenance
fixtures in both directions, Unicode paths, CWD/PATH decoys.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0165qLfnJYSYb51NQMdPidZr
Record the normalized absolute dlopen path and prove provenance against
it byte-first (deferred dialog resolution survives file deletion and CWD
changes); restore the UTF-8 contract of the narrow native-parser API on
Windows; normalize native-parser paths to absolute; verify Windows
provenance via GetModuleHandleExW(FROM_ADDRESS) so PE forwarded exports
are rejected; route native-parser symbols through the shared provenance
resolver with RTLD_FIRST on macOS.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0165qLfnJYSYb51NQMdPidZr
…rded provenance paths

The forwarder fixture uses true forwarder syntax against the donor DLL
basename; load-time identity records both the exact absolute loader
argument and its weakly_canonical form so dyld's realpath dli_fname
byte-matches without live filesystem access (deletion test now also
loads through a symlinked directory to reproduce the macOS shape on
Linux).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0165qLfnJYSYb51NQMdPidZr
…f entry

MSVC LINK parses the .def EXPORTS forwarder entry as an internal-name
alias and demands a local definition (LNK2001 in two CI rounds); the
/export linker-directive form emits a true forwarder.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0165qLfnJYSYb51NQMdPidZr
…emantics

Rename instead of delete the mapped candidate on Windows (deletion of a
mapped image is impossible there; deferred resolution must survive the
path vanishing either way), and emit the real dependency fixture into
its own directory so LOAD_LIBRARY_SEARCH_APPLICATION_DIR cannot resolve
it from beside the test executable and defeat the decoy-only case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0165qLfnJYSYb51NQMdPidZr
@facontidavide
facontidavide merged commit 1d322d3 into main Aug 11, 2026
7 checks passed
@facontidavide
facontidavide deleted the fix/loader-symbol-provenance branch August 11, 2026 08:22
facontidavide added a commit that referenced this pull request Aug 30, 2026
…get (0.24.0)

SDK PR 1b of the parser-extensibility v4 architecture (spec: pj-official-plugins
PR #272), following the core PR (#172, 0.22.0): a second loader for the
already-frozen module ABI — wasmer execution, hardening, and the wasm
authoring target. Ships as its own 0.24.0 release (0.23.0 was taken by the
symbol-provenance fix, #175), so an SDK with the wasm loader is
distinguishable from one without it. Rebased onto main after #174#176: the
budget-aware NativeParserModule::load keeps #175's defining-object symbol
provenance, and the docs no longer describe wasm as unavailable.

- wasmer 7.0.1 statically linked (pinned; required only by the plugin_host
  component — plugin_sdk consumers stay wasmer-free). Exit-criterion prototype
  findings encoded in the loader contract: the pinned static lib exports no
  wasm_module_share/obtain symbols (engine-owned module reuse: one compilation,
  store-per-bound-instance with isolated state) and no creator-thread affinity
  exists — calls are sequential-only, host-serialized. Pin re-evaluated against
  7.2.1: no C-API gains, WASI-syscall CVEs unreachable under the empty import
  allow-list, and 7.2 drops x86_64-darwin (rationale in ARCHITECTURE.md)
- wasm loader: validation before any instantiation — manifest custom section
  via the shared codec (exactly one), reactor model enforced (_initialize
  required, start section/_start rejected), operational export set verified
  by name AND signature through the shared pj_base wasm inspector, and a
  frozen EMPTY import allow-list (a parser module may import nothing)
- execution runtime: metered store-per-instance calls (the pinned lib exports
  the wasmer_metering_* C API but no interrupt/epoch/deadline surface, so
  limits are enforceable instruction metering — fresh point allowance per
  guest call, exhaustion = distinct contract violation), linear-memory base
  re-acquired at every point of use with overflow-safe bounds, splices
  resolved against the original host payload, shared fault taxonomy + strike
  tracker with quarantine replay
- memory caps at validation: artifacts must declare a linear-memory maximum
  (default cap 256 MiB); the engine enforces it at runtime. Aggregate session
  budgets (modules, artifact size, claims, active instances, declared memory)
  gate admission with DECLINE and mutate nothing on rejection
- adversarial fixtures: unreachable trap, metered infinite loop, memory-growth
  bomb, admission limits, quarantine replay — plus the M1 rejection matrix
- pj-wasm-embed-manifest installed CLI (embed/verify) wrapping the shared
  section codec; pj_add_parser_module(... TARGETS native wasm) builds both
  artifacts from one source with post-link audit, dogfooded on the toy module
- fix: release the metering middleware on the adapter-failure path
- VERSION 0.24.0, CHANGELOG entry, CI wasmer job (metering-symbol check)

Tests: 80/80 Debug+ASAN with both toolchain roots; graceful skip verified for
each root independently.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_017U391nLF7Motf4FehVRiXz
facontidavide added a commit that referenced this pull request Aug 30, 2026
…get (0.24.0)

SDK PR 1b of the parser-extensibility v4 architecture (spec: pj-official-plugins
PR #272), following the core PR (#172, 0.22.0): a second loader for the
already-frozen module ABI — wasmer execution, hardening, and the wasm
authoring target. Ships as its own 0.24.0 release (0.23.0 was taken by the
symbol-provenance fix, #175), so an SDK with the wasm loader is
distinguishable from one without it. Rebased onto main after #174#176: the
budget-aware NativeParserModule::load keeps #175's defining-object symbol
provenance, and the docs no longer describe wasm as unavailable.

- wasmer 7.0.1 statically linked (pinned; required only by the plugin_host
  component — plugin_sdk consumers stay wasmer-free). Exit-criterion prototype
  findings encoded in the loader contract: the pinned static lib exports no
  wasm_module_share/obtain symbols (engine-owned module reuse: one compilation,
  store-per-bound-instance with isolated state) and no creator-thread affinity
  exists — calls are sequential-only, host-serialized. Pin re-evaluated against
  7.2.1: no C-API gains, WASI-syscall CVEs unreachable under the empty import
  allow-list, and 7.2 drops x86_64-darwin (rationale in ARCHITECTURE.md)
- wasm loader: validation before any instantiation — manifest custom section
  via the shared codec (exactly one), reactor model enforced (_initialize
  required, start section/_start rejected), operational export set verified
  by name AND signature through the shared pj_base wasm inspector, and a
  frozen EMPTY import allow-list (a parser module may import nothing)
- execution runtime: metered store-per-instance calls (the pinned lib exports
  the wasmer_metering_* C API but no interrupt/epoch/deadline surface, so
  limits are enforceable instruction metering — fresh point allowance per
  guest call, exhaustion = distinct contract violation), linear-memory base
  re-acquired at every point of use with overflow-safe bounds, splices
  resolved against the original host payload, shared fault taxonomy + strike
  tracker with quarantine replay
- memory caps at validation: artifacts must declare a linear-memory maximum
  (default cap 256 MiB); the engine enforces it at runtime. Aggregate session
  budgets (modules, artifact size, claims, active instances, declared memory)
  gate admission with DECLINE and mutate nothing on rejection
- adversarial fixtures: unreachable trap, metered infinite loop, memory-growth
  bomb, admission limits, quarantine replay — plus the M1 rejection matrix
- pj-wasm-embed-manifest installed CLI (embed/verify) wrapping the shared
  section codec; pj_add_parser_module(... TARGETS native wasm) builds both
  artifacts from one source with post-link audit, dogfooded on the toy module
- fix: release the metering middleware on the adapter-failure path
- VERSION 0.24.0, CHANGELOG entry, CI wasmer job (metering-symbol check)

Tests: 80/80 Debug+ASAN with both toolchain roots; graceful skip verified for
each root independently.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_017U391nLF7Motf4FehVRiXz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant