Skip to content

PAINTSTRUCT is not defined properly #625

Closed

Description

PAINTSTRUCT is currently being generated as:

internal partial struct PAINTSTRUCT
{
	internal winmdroot.Graphics.Gdi.HDC hdc;
	internal winmdroot.Foundation.BOOL fErase;
	internal winmdroot.Foundation.RECT rcPaint;
	internal winmdroot.Foundation.BOOL fRestore;
	internal winmdroot.Foundation.BOOL fIncUpdate;
	internal unsafe byte* rgbReserved;
}

The final field is actually a fixed array:

BYTE rgbReserved[32];

Activity

  1. added
    bug
    on Jul 27, 2022
  2. JeremyKuhne commented on Jul 27, 2022

    @JeremyKuhne
    MemberAuthor
  3. JeremyKuhne commented on Jul 27, 2022

    @JeremyKuhne
    MemberAuthor

    Note that this only causes failures running as a 32bit process on a 64bit OS. The BeginPaint implementation doesn't reference the final field, but the WOW layer does.

  4. AaronRobinsonMSFT commented on Jul 27, 2022

    @AaronRobinsonMSFT
    Member

    It is fine to clarify a particular scenario is heavily impacted by this incorrect definition, but it doesn't change the definition is incorrect. It is possible to create a GC hole via heap corruption, that means it is suspect. This definition and any similar patterns should be scrutinized heavily because end-users are far less likely to have the experience to track down the problem this type of definition can cause.

  5. JeremyKuhne commented on Jul 27, 2022

    @JeremyKuhne
    MemberAuthor

    It is fine to clarify a particular scenario is heavily impacted by this incorrect definition, but it doesn't change the definition is incorrect.

    The point was to clarify a way these can get missed for a commonly used API. One would suspect that the majority of users are running as 64bit. It was not an attempt to lower the priority. :)

  6. elachlan commented on Jul 28, 2022

    @elachlan
    Contributor
  7. elachlan commented on Jul 28, 2022

    @elachlan
    Contributor

    This is the underlying generated code for the rgbReserved field: internal __byte_32 rgbReserved;

  8. AArnott commented on Jul 28, 2022

    @AArnott
    Member

    CsWin32 gets this right when allowMarshaling=true. So this is unique to allowMarshaling=false. This seems really similar to #597, so I'm surprised fixing that didn't fix this. I'll try to look into this by early next week. Or Lachlan Ennis (@elachlan), as you have been great at investigating these so far, you're welcome to grab it.

  9. AaronRobinsonMSFT commented on Jul 28, 2022

    @AaronRobinsonMSFT
    Member

    Note that this only causes failures running as a 32bit process on a 64bit OS.

    I am seeing this when running as a 64-bit process too.

  10. JeremyKuhne commented on Jul 28, 2022

    @JeremyKuhne
    MemberAuthor

    I am seeing this when running as a 64-bit process too.

    Yeah, I was looking at the wrong endpoint. BeginPaint is actually NtUserBeginPaint, which always does a copy. I suspect we're not seeing runtime failures on x64 due to padding/alignment.

  11. JeremyKuhne commented on Jul 28, 2022

    @JeremyKuhne
    MemberAuthor

    Andrew Arnott (@AArnott) we're out of date here- we are using 0.2.1, so this is probably fixed. Validating.

  12. JeremyKuhne commented on Jul 28, 2022

    @JeremyKuhne
    MemberAuthor

    Yes, updating to 0.2.10 fixes the problem. Sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpartner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions