Skip to content

System.Darwing.Common Icon tests failures on Mono on Windows. #47759

Closed

Description

@lateralusX

System.Drawing.Tests.IconTests have a number of tests that hit this code path:

IPicture picture = OleCreatePictureIndirect(pictdesc, ref g, false);

This code depends on COM support and currently Mono on Windows have not enabled COM support (inline with other Mono netcore platforms). This triggers a rather subtle problem that can cause crash depending on what registers has been used up to this point.

Mono will not do anything specific with the signature:

internal static extern IPicture OleCreatePictureIndirect(PICTDESC pictdesc, [In]ref Guid refiid, bool fOwn);

and that method has 4 parameters:

https://docs.microsoft.com/en-us/windows/win32/api/olectl/nf-olectl-olecreatepictureindirect

so OleCreatePictureIndirect expects parameters in rcx,rdx,r8 and r9 inline with Windows x64 ABI, but since above dllimport is not handled differently on Mono compared to other dllimports, it will assume 3 parameters and that returned interface will be placed in rax, and that will, depending on content in r9 cause random crashes or undefined behaviour.

IconTests that hits this code path will be disabled with this issue as its active issue.

Activity

  1. ghost added
    untriaged
    on Feb 2, 2021
  2. jkotas commented on Feb 2, 2021

    @jkotas
    Member

    Should Mono throw when it encounters unsupported type in the PInvoke signatures? It is what CoreCLR does on non-Windows.

  3. lateralusX commented on Feb 2, 2021

    @lateralusX
    MemberAuthor

    Yes, I believe that is something we should probably investigate doing, one thing I was a little curious around is how CoreClr handles that signature, is there some logic that will detect that the return in this case is actually the forth parameter of the underlying method so the interop can do the right thing or is that an effect of PreserveSig=false? Reading docs on PreserveSig it only says it will handle HRESULT and raise exception on failure, and that the method will return void, https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute.preservesig?view=net-5.0#remarks, couldn't find anything saying that the return value of the signature will be appended as an out parameter to underlying call. Don't believe Mono implement PreserveSig at all, and certainly not using that behaviour.

  4. jkotas commented on Feb 2, 2021

    @jkotas
    Member

    is there some logic that will detect that the return in this case is actually the forth parameter of the underlying method so the interop can do the right thing or is that an effect of PreserveSig=false?

    It is effect of PreserveSig=false. PreserveSig=false changes the unmanaged return type to HRESULT and moves the managed return type into an extra unmanaged out argument.

  5. lateralusX commented on Feb 2, 2021

    @lateralusX
    MemberAuthor

    OK, that was what I suspected, then I believe this hits several underlying issues on Mono, first COM is not enabled/supported, and second, Mono doesn't implement the PreserveSig attribute, so above signature will not be adjusted. Is that behaviour of PreserveSig=false documented?

  6. jkotas commented on Feb 2, 2021

    @jkotas
    Member

    Submitted the documentation fix in dotnet/dotnet-api-docs#5303

  7. removed
    untriaged
    on Jun 14, 2021
  8. added this to the Future milestone on Jun 14, 2021
  9. JeremyKuhne commented on Apr 4, 2023

    @JeremyKuhne
    Member

    System.Drawing.Common has moved to WinForms.

  10. ghost locked as resolved and limited conversation to collaborators on May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions