Skip to content

Lazy-load GDI cleanup and USER32 helper APIs - #174

Merged
leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-lazy-system-dll-helpers
Sep 20, 2026
Merged

leileizhang (lei9444) merged 3 commits into
mainfrom
lei9444-lazy-system-dll-helpers

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes direct GDI32/USER32 ordinary and delay imports from the measured production binaries. Cold-process DLL counts did not decrease on this machine: the Node host and remaining Windows dependencies still map those DLLs. This is not complete non-UI physical isolation or a startup-speed claim.

This independent PR targets main from 34eb6246627c671113a501c00edc8e3317fc8b3d and is limited to DeleteObject, DestroyIcon, CreateWindowExW, and the four existing DPI-awareness helpers. OLEAUT32 and normal WinRT COM infrastructure remain unchanged. No binary split, domain redesign, or changes to the existing CoreMessaging/MAPI/GDI+/MF/Winsock loaders.

Implementation

  • Shared, metadata-independent typed helpers use SDK extern "system" signatures and System32-only DLL search. Success-only caches retain the winning loader reference; failed and race-loser references are released. Loading/export lookup runs outside publication locks.
  • GDI cleanup is admitted at actual invocation, before native dispatch can produce owned outputs—not at registration/import. Failed HRESULTs, partial outputs, extraction failures, post-call validation and JS owners use the already prepared deleter. Cleanup never performs a fallible first resolution.
  • Explicit raw GDI/icon cleanup retains pointer provenance on resolution/native failure. HICON still uses DestroyIcon. Existing DPI policy and thread affinity remain intact.
  • Successful cold resolution restores incoming LastError before the target call; nothing restores it after the API returns, so native failure reads retain their original timing.
  • Production PE gates intentionally reject entire GDI32/USER32 descriptors, plus scoped symbols through aliases, in both import tables. CoreMessaging also checks both tables. The existing optional MAPI/GDI+/Winsock/MF policy remains ordinary-import-only; PE32/PE32+ CLI regressions accept their delay-only imports and still reject their ordinary imports.
  • JS artifacts, the existing no-test-hooks dev-profile CI Python wheel, and actual release-wheel consumer lanes share the same dependency-free reader. Release consumers explicitly set up Node 24 and inspect the installed .pyd without rebuilding it.

Validation

Check Result
Release ARM64 .node and CPython 3.13 .pyd, before/after Scoped direct imports present before; absent afterward in ordinary and delay tables
Cross-built release x64 addon payload No GDI32/USER32 ordinary or delay imports
Independent PE control MSVC dumpbin /imports confirms all three changed production images
Scoped native cleanup/cache/DPI tests 20 pass on native ARM64; 20 each on x64 and i686 under Windows-on-ARM emulation
JS native ownership/explicit cleanup regressions 9 pass
PE reader/policy / production import gates / CI wiring 129 / 8 / 6 pass
WinRT generated snapshots 6 pass; 16 generated JS runtime files and 4 Python package source/stub files remain byte-identical
Live safe operations Generated Uri in Node/Python, generated WIC COM stream creation, flat Win32 GetTickCount, real bitmap/icon cleanup, hidden-window and DPI paths pass

26 calibrated before/after cold child-process observations use an external K32 observer with child-reported PID, phase handshake, ntdll.dll/module-count controls, and bounded natural exit. Node remains 35 host → 37 import/primitive → 39 Uri modules; Python remains 15 → 28 → 30. Registration adds no modules; hidden-window creation is an explicit opt-in probe.

The x64 addon was cross-built and statically inspected, not run in an x64 Node host. x64/i686 native tests used ARM-host emulation, not physical x64/i686 hardware. Local Python measurements cover ARM64 CPython 3.13 only; no general older-Windows compatibility claim.

Design and precise limits · Retained PE tables, hashes, module observations and regression-log digests

No merge, release, or tag performed; ready for coordinator review.

Resolve typed System32 helpers on demand and admit GDI cleanup before native calls can produce owned outputs. Preserve native errors, explicit cleanup retry, and success-only process-lifetime caches. Add production ordinary/delay PE gates, release-wheel checks, focused ownership tests, and retained import evidence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the optional subsystem policy ordinary-only while checking GDI/USER32 and CoreMessaging against both import tables. Cover delay-only acceptance and eager rejection for all four optional subsystem DLLs in PE32 and PE32+ CLI fixtures.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 86.15% 81.41% 85.74% regions
Python aggregate 71.06% n/a 37.9% branches
Python runtime 99.12% n/a 97.37% branches
Generated Python WinRT projections 70.05% n/a 27.07% branches
Generated Python WinRT implementations 72.29% n/a 47.04% branches
JavaScript aggregate 22.14% 25.22% 57.85% branches
JavaScript runtime 44.27% 45.76% 78.99% branches
Generated WinRT projections 22.96% 18.72% 54.88% branches
Generated WinRT implementations 48.66% 59.76% 61.14% branches
Generated Classic COM projections 11.92% 23.97% 54.2% branches

View workflow run and download full HTML/LCOV/XML reports

Integrate main f446adb while retaining shared PreparedCall ownership. Recompute cleanup admission when methods are built or rebound, and verify that missing GDI cleanup still prevents dispatch. Retain separate ARM64 production and metadata-lifetime merge-validation evidence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@lei9444
leileizhang (lei9444) merged commit d3ecaf6 into main Sep 20, 2026
33 checks passed
@lei9444
leileizhang (lei9444) deleted the lei9444-lazy-system-dll-helpers branch September 20, 2026 09:06
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.

3 participants