Skip to content

Packing not emitted for some structs #233

Closed
@sotteson1

Description

@sotteson1

I'm traversing Include\10.0.19041.0\um\minidumpapiset.h, and in it I see:

#include <pshpack4.h>

Some emitted structs have Pack = 4 and some don't like the two below.

    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    public unsafe partial struct MINIDUMP_VM_POST_READ_CALLBACK
    {
        [NativeTypeName("ULONG64")]
        public ulong Offset;

        [NativeTypeName("PVOID")]
        public void* Buffer;

        [NativeTypeName("ULONG")]
        public uint Size;

        [NativeTypeName("ULONG")]
        public uint Completed;

        [NativeTypeName("HRESULT")]
        public int Status;
    }

    public partial struct MINIDUMP_CALLBACK_INPUT
    {
        [NativeTypeName("ULONG")]
        public uint ProcessId;

        [NativeTypeName("HANDLE")]
        public IntPtr ProcessHandle;

        [NativeTypeName("ULONG")]
        public uint CallbackType;

        [NativeTypeName("_MINIDUMP_CALLBACK_INPUT::(anonymous union at D:/repos/win32metadata/artifacts/InstalledPackages/Microsoft.Windows.SDK.CPP.10.0.19041.5/c/Include/10.0.19041.0/um/minidumpapiset.h:1141:5)")]
        public _Anonymous_e__Union Anonymous;

        [StructLayout(LayoutKind.Explicit)]
        public partial struct _Anonymous_e__Union
        {
...

I tried rolling my own C versions of these and debugging to see if it makes a difference, and it does. The offsets to CallbackType are different between these two:

typedef struct _MINIDUMP_CALLBACK_INPUT
{
    UINT ProcessId;

    HANDLE ProcessHandle;

    UINT CallbackType;
} MINIDUMP_CALLBACK_INPUT;


#pragma pack(4)
typedef struct _MINIDUMP_CALLBACK_INPUT4
{
    UINT ProcessId;

    HANDLE ProcessHandle;

    UINT CallbackType;
} MINIDUMP_CALLBACK_INPUT4;

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