Skip to content

Add safe flat Win32 code generation - #102

Closed
leileizhang (lei9444) wants to merge 4 commits into
mainfrom
leilzh/win32-flat-refactor
Closed

leileizhang (lei9444) wants to merge 4 commits into
mainfrom
leilzh/win32-flat-refactor

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a metadata-driven flat Win32 ABI model and immutable libffi call plans, isolated from WinRT and Classic COM
  • generate idiomatic safe JavaScript bindings under @microsoft/dynwinrt/win32, with explicit raw access under /win32/unsafe
  • model buffers, native layouts, resource ownership, pointer-bearing structures, and dedicated OVERLAPPED ReadFile/WriteFile promises
  • add deterministic manifests, a safe-coverage census, CI gates, documentation, samples, and live E2E coverage

Safety model

  • fail closed when ABI, layout, count, cleanup, ownership, or pointer contracts are incomplete
  • retain Buffer-backed pointers and reject numeric data addresses from the safe entrypoint
  • restrict DLL loading to bare System32 module names
  • protect managed handles from close/consume races while asynchronous I/O is pending

Review hardening

  • revalidate detached/transferred read Buffers on the JS thread before copy-back
  • require managed resources for consuming handle APIs, including exact cleanup and lease checks
  • check asynchronous leases while holding the same resource mutex used by lease creation and consuming native calls
  • preserve NullNullTerminatedAttribute and ReservedAttribute through semantic projection
  • use a centralized fixed eight-thread OVERLAPPED waiter; excess operations reject explicitly instead of allocating unbounded OS threads or consuming libuv workers
  • bound aggregate descriptors/layouts and use fallible native allocations
  • route APIs-only Windows.Win32.* namespace generation through flat Win32 and reject Python
  • initialize WinRT explicitly in the standalone flat Win32 runner
  • give every COM/Win32 Node E2E runner a 180-second process timeout and add stage diagnostics to returns.mjs

Coverage

  • 8,959 of 18,321 eligible Windows.Win32 functions project safely (48.90%)
  • unsupported callbacks, ambiguous ownership, recursive/nested pointer graphs, and unknown native layouts remain omitted with explicit reasons

Validation

  • core Rust: 229 passed, 1 ignored
  • codegen unit tests: 333 passed; real Classic COM and flat Win32 metadata suites also passed
  • JavaScript: 44 passed, 2 environment-dependent skips
  • E2E: Python 41/41, WinRT TypeScript 37/37, Classic COM 16/16, flat Win32 2/2
  • flat Win32 E2E covers detached read buffers, capacity rejection, libuv availability, cancellation, and raw-handle consuming rejection
  • hardened flat Win32 E2E passed four consecutive runs
  • x86, x64, and ARM64 compile checks passed

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 80.04% 75.75% 80.03% regions
Generated Python projections 77.01% n/a 62.35% branches
JavaScript aggregate 18.83% 20.83% 52.26% branches
JavaScript runtime 23.42% 14.28% 7.14% branches
Generated WinRT projections 22.27% 20.02% 52.85% branches
Generated Classic COM projections 12.97% 23.45% 52.17% branches

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

@lei9444
leileizhang (lei9444) force-pushed the leilzh/win32-flat-refactor branch 2 times, most recently from 157872a to 0d798d7 Compare August 18, 2026 06:22
Introduce metadata-driven flat Win32 call planning, safe and unsafe JavaScript entrypoints, resource ownership, pointer-bearing structures, OVERLAPPED I/O, coverage reporting, samples, documentation, and end-to-end tests.

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

Copilot-Session: 6307886d-3c24-4596-8924-ba44b0e850a5
Split the synchronous flat Win32 runner path into API-level milestones so hosted CI hangs identify the exact native call.

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

Copilot-Session: 6307886d-3c24-4596-8924-ba44b0e850a5
Exclude mapi32.dll from safe flat Win32 generation until its required initialization lifecycle is modeled, and replace the hosted E2E probe with deterministic PtInRect by-value ABI coverage.

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

Copilot-Session: 6307886d-3c24-4596-8924-ba44b0e850a5
Replace blocking OVERLAPPED waiters with a windows-rs IOCP runtime and add guarded Winsock, GDI+, Media Foundation, and MAPI utility initialization contexts with generated codegen requirements and live E2E coverage.

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

Copilot-Session: 6307886d-3c24-4596-8924-ba44b0e850a5
@lei9444

Copy link
Copy Markdown
Contributor Author

Superseded by #152. The replacement is based on main and starts with the independent Win32 contract registry and five SystemInformation/Registry exports. The broader implementation is preserved for incremental migration; follow-up scope is recorded in #152. Closing this PR without deleting its branch.

@lei9444

Copy link
Copy Markdown
Contributor Author

Reopening: #152 currently implements only a foundation subset and does not yet replace the full functionality of this PR. #102 remains the capability baseline. The replacement must preserve the complete supported export set, ABI and ownership semantics, IOCP operations and subsystem contexts, without regressing WinRT. #152 will remain draft until full parity is demonstrated.

@lei9444

Copy link
Copy Markdown
Contributor Author

The complete committed capability set from this PR (13e4758) is now implemented in #152, rather than the earlier five-export prototype. The frozen gate preserves all 8,936 projections and 10,680 public exports/helpers with matching default ABI/projection semantics, enums, builders and subsystem requirements. Original Win32 runners and samples, plus WinRT/COM regressions, pass on the main-based implementation including #151. Keeping #102 open during #152 review/CI; no branch or archived implementation has been deleted.

@lei9444
leileizhang (lei9444) deleted the leilzh/win32-flat-refactor branch September 20, 2026 01:14
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