Skip to content

Preserve MI function table and nested callback signatures - #2407

Open
Perdixky wants to merge 1 commit into
microsoft:mainfrom
Perdixky:codex/fix-mi-function-tables
Open

Perdixky wants to merge 1 commit into
microsoft:mainfrom
Perdixky:codex/fix-mi-function-tables

Conversation

@Perdixky

@Perdixky Perdixky commented Nov 9, 2026

Copy link
Copy Markdown

MI function table members are currently emitted as IntPtr, so projections expose addresses rather than callable signatures. For example, MI_ApplicationFT.NewSession becomes isize in Zig.

Add named unmanaged delegates in manual/Mi.cs and map the anonymous members to them in emitter.settings.rsp. This covers all 172 anonymous function pointers in 19 MI function tables, both session callbacks, and six nested operation callback parameters. Four additional delegates preserve the session close completion callback, prompt/error responses, and result acknowledgements. Preserve the native calling convention, primitive widths, const annotations, parameter directions, optional parameters and expressible buffer counts.

New delegate names follow the existing MI_ProviderFT_* convention: <struct>_<field>. Nested completion/response/acknowledgement callbacks receive explicit helper delegate names; these names are introduced by this patch, while their signatures come from mi.h.

Fixes #842.

Validation:

  • Build the upstream emitter, scraper and Windows.Win32.Tests project: passed.
  • Scrape the unmodified SDK mi.h and emit baseline/patched MI-only WinMD with the real upstream emitter: passed.
  • Added 30 metadata regression cases: baseline fails all 30; patched passes all 30.
  • Compile 180 native prototype comparisons against SDK mi.h on Windows x86, x64 and ARM64: passed.
  • Generate Zig bindings with the real zigwin32gen and cross-compile direct session creation, enumeration, invocation, result retrieval and close calls on all three architectures: passed.

Validation ran on Linux. The focused scraper harness disables the Linux-only UnixTypes option to match Windows character widths, and uses Zig's MinGW support headers with the repository's unchanged mi.h. The tests share the exact upstream MiTests.cs, with only the Windows-specific fixture path supplied by a temporary harness. For the pinned 42.0.39 Zig generator, the fixture adapts the metadata attribute namespace rename and overlays only the 26 modified existing MI types and 178 new delegates onto its baseline metadata text. No MI signature is rewritten for Zig. The full Windows SDK crossarch build and live Windows MI execution remain for Windows CI/runtime validation.

Header-only inline convenience functions are outside this change; clients can call the typed function tables directly.

Define named unmanaged delegates for anonymous MI function pointers and remap
the corresponding struct fields and callback parameters to those delegates.
Add metadata regression tests for callable types and representative signatures.

Fixes microsoft#842.

Co-authored-by: Codex <[email protected]>
@Perdixky

Perdixky commented Nov 9, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@jevansaks

Copy link
Copy Markdown
Member

Thanks Perdixky for the contribution! I've been working to roll back these hand-authored things that are outside the headers. I'll take a look at the toolchain and figure out why these things aren't being scraped out of the headers.

This branch has not been deployed

No deployments
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.

WMI MI_ApplicationFT struct is hard to use

2 participants