microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.06k stars 87 forks source link

Do not use an array for a pointer field that doesn't actually refer to an array #907

Closed AArnott closed 1 year ago

AArnott commented 1 year ago

The old behavior was breaking interop for the PROCESS_BASIC_INFORMATION struct's PEB* PebBaseAddress field. When this field was changed to a PEB[], the struct became a 'managed' type (in interop terms) yet the CLR's interop layer has no information about array length, etc. and marshaling would fail.

It turned out this "small" change led to a series of test failures due to other latent bugs that only manifest when we changed the mixture of how structs (with their managed and unmanaged variants) interact, leading to this surprisingly large set of changes.

Fixes #904