Skip to content

Suspicious duplicate structs that differ in architecture and pack only #2203

@DoctorKrolic

Description

@DoctorKrolic

I was ivestigating the underlying issue for microsoft/CsWin32#1617 (comment). It turned out metadata defines 2 nearly identical RASDIALPARAMSW structs which differs only in supported architecture and pack size:

.class public sequential ansi sealed beforefieldinit Windows.Win32.NetworkManagement.Rras.RASDIALPARAMSW
	extends [netstandard]System.ValueType
{
	.custom instance void [Windows.Win32.winmd]Windows.Win32.Foundation.Metadata.UnicodeAttribute::.ctor() = (
		01 00 00 00
	)
	.custom instance void [Windows.Win32.winmd]Windows.Win32.Foundation.Metadata.SupportedArchitectureAttribute::.ctor(valuetype [Windows.Win32.winmd]Windows.Win32.Foundation.Metadata.Architecture) = (
+		01 00 06 00 00 00 00 00 // X64 | Arm64
-		01 00 01 00 00 00 00 00 // X86
	)
+	.pack 4
+	.size 0

	// Fields
	.field public uint32 dwSize
	.field public char[0...256] szEntryName
	.field public char[0...128] szPhoneNumber
	.field public char[0...128] szCallbackNumber
	.field public char[0...256] szUserName
	.field public char[0...256] szPassword
	.field public char[0...15] szDomain
	.field public uint32 dwSubEntry
	.field public native uint dwCallbackId
	.field public uint32 dwIfIndex
	.field public valuetype [Windows.Win32.winmd]Windows.Win32.Foundation.PWSTR szEncPassword

} // end of class Windows.Win32.NetworkManagement.Rras.RASDIALPARAMSW

This seems suspicious. The struct has nothing to do with memory or any other hardware access, so it seems wrong that it is emitted as architecture-specific. I am not an expert in such low-level stuff as memory alignment on different architectures, but I have a suspicion that on x86 .pack 4 is a default value, so it isn't emitted explicitly and that makes the wrong split later on. If true, both definitions can be collapsed into a single one without need for architecture-specific structs. I would like to either confirm or deny my suspicion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions