Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION not getting marked as unsafe when it contains a pointer #366

Closed
sotteson1 opened this issue Aug 11, 2022 · 2 comments · Fixed by #372 or #374

Comments

@sotteson1
Copy link
Contributor

winnt.h:

typedef struct _ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION {
    DWORD ElementCount;
    COMPATIBILITY_CONTEXT_ELEMENT Elements[];
} ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION, * PACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION;

Scanned output:

    public partial struct ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION
    {
        [NativeTypeName("DWORD")]
        public uint ElementCount;

        [NativeTypeName("COMPATIBILITY_CONTEXT_ELEMENT[]")]
        public COMPATIBILITY_CONTEXT_ELEMENT* Elements;
    }

This was using 14.0.0-beta2, which I'm trying to upgrade to in the Win32Metadata project. The previous version I was using omitted the * but I was able to turn it into an array by looking at the NativeTypeName attribute.

@tannergooding
Copy link
Member

Reopening. The issue isn't that unsafe is missing but this being treated as a pointer at all.

C incomplete arrays are the "same" as zero sized arrays (that is COMPATIBILITY_CONTEXT_ELEMENT Elements[] is the same as COMPATIBILITY_CONTEXT_ELEMENT Elements[0]).

This has interesting behaviors where-as it is functionally:

    public partial struct ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION
    {
        [NativeTypeName("DWORD")]
        public uint ElementCount;

        [NativeTypeName("COMPATIBILITY_CONTEXT_ELEMENT[]")]
        public COMPATIBILITY_CONTEXT_ELEMENT Elements;
    }

And where Elements impacts the alignment/packing of the struct, but where sizeof is not supposed to include the size of the single Elements entry.

@tannergooding
Copy link
Member

Much like many structs that have 0/1 fixed-sized buffers, these "must" be the last element and the overall struct must always be accessed/passed by reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants