Skip to content

Improve heuristics for struct size field detection and annotate several structs by hand#2206

Open
DoctorKrolic wants to merge 3 commits intomicrosoft:mainfrom
DoctorKrolic:better-struct-size
Open

Improve heuristics for struct size field detection and annotate several structs by hand#2206
DoctorKrolic wants to merge 3 commits intomicrosoft:mainfrom
DoctorKrolic:better-struct-size

Conversation

@DoctorKrolic
Copy link
Contributor

Let's say this fixes #2202

Windows.Win32.NetworkManagement.Rras.RAS_STATS : [Documentation(https://learn.microsoft.com/windows/win32/api/ras/ns-ras-ras_stats)] => [Documentation(https://learn.microsoft.com/windows/win32/api/ras/ns-ras-ras_stats),StructSizeField(dwSize)]
Windows.Win32.NetworkManagement.Rras.RASADPARAMS removed
Windows.Win32.NetworkManagement.Rras.RASADPARAMS(X64, Arm64) added
Windows.Win32.NetworkManagement.Rras.RASADPARAMS(X86) added
Copy link
Contributor Author

@DoctorKrolic DoctorKrolic Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug BTW. Adding [StructSizeField] attribute has nothing to do with CPU architecture and should not cause a split. This is at least somewhat related to #2203

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm yeah that's weird. I don't know how the tooling is determining there's a layout difference. I haven't had time to think about or look into solving the architecture layout discrepancies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debugged the project a little bit and found out the problem is here:

// If the x86 node doesn't have any attributes, try using the ones cached from the non-x86 version
if (structNode.AttributeLists.Count == 0 && this.namesTo64BitStructs.TryGetValue(name, out var nonX86Node))
{
var tempNode = structNode.WithAttributeLists(nonX86Node.AttributeLists);
// Save these off to see if we match with previous items
altSignatureForX86 = GetFullSignature(tempNode);
}

Since RASADPARAMS didn't have any attributes before this PR and we are adding [StructSizeField], this branch is no longer taken for that struct. It appears to be the actual cause of #2203 as well, since RASDIALPARAMSW has a [Unicode] attribute which also breaks this code path. I am not sure why the logic is as it is though. I don't understand why any unrelated attribute makes the cross-arch merge unable to be performed. Can you please take a look?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the intent here was to look for StructLayout or other attributes that would affect cross-arch. Now that safe attributes exist, I agree that we need to tighten things up here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StructLayout or other attributes that would affect cross-arch

We should white-list those. Can you list all of them please?

@jevansaks
Copy link
Member

This is a great improvement, thanks for taking this on. Before we merge this in we should figure out why the attribute is causing that struct to become architecture specific, since devs get upset when that happens.

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.

Annotate struct size fields in metadata

3 participants

Comments