Closed AffluentOwl closed 4 weeks ago
A similar proposal sent to win32metadata: microsoft/win32metadata/issues/1917
However, they may feel that it's CsWin32's job to unify definitions where possible. Even when they over document the metadata differences that make no semantic impact.
Took a look at https://github.com/microsoft/win32metadata/issues/1300#issuecomment-1464715747
Turns out that Packing can leak out beyond just the struct that the attribute is applied to. Therefore, the simplification I proposed will not allow for nested packed structs.
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct MINIDUMP_INCLUDE_MODULE_CALLBACK1
{
public ulong BaseOfImage;
}
public struct MINIDUMP_INCLUDE_MODULE_CALLBACK2
{
public ulong BaseOfImage;
}
public struct Test1
{
public byte x;
public MINIDUMP_INCLUDE_MODULE_CALLBACK1 y;
}
public struct Test2
{
public byte x;
public MINIDUMP_INCLUDE_MODULE_CALLBACK2 y;
}
{
Test1 a = new();
byte* addr = (byte*)&a;
Console.WriteLine($"{(byte*)&a.x - addr} {(byte*)&a.y - addr} {sizeof(Test1)}");
}
{
Test2 a = new();
byte* addr = (byte*)&a;
Console.WriteLine($"{(byte*)&a.x - addr} {(byte*)&a.y - addr} {sizeof(Test2)}");
}
0 4 12
0 8 16
Repro
NativeMethods.txt
content:Any CPU
selectedActual
Errors
Expected
Build succeeds without failures
Context
0.3.49-beta
net8.0
Background
See #505 . In particular, the argument against this compiling was that StructLayout was used with the Pack = 1 parameter. However, this definition is semantically equivalent on x86 as leaving off the Pack = 1 parameter. Perhaps this was a machine generated value which doesn't apply to this struct and can be removed from the metadata?
I'd like this bug to track whether or not CsWin32 should check if two alternative definitions are semantically equivalent before throwing an error. For example, by using reflection over the fields and ensuring matching field offsets. I'm unsure of the magnitude of structs affected by this issue, but this approach could help with a number of metadata issues.