Skip to content

AF: (SIZE_T)mtype < COUNTOF(nativeSizes) when building COM vtable #53110

Closed

Description

@tarekgh

https://helixre8s23ayyeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-52992-merge-1da0184fed3444a4bd/System.Runtime.Tests/console.00381496.log?sv=2019-07-07&se=2021-06-10T21%3A55%3A13Z&sr=c&sp=rl&sig=Na%2FXK1cDDkv8h87piXD8wapDbv4gAyoGP0th40V9x6k%3D

https://dev.azure.com/dnceng/public/_build/results?buildId=1150299&view=logs&j=bbd47f15-9f4c-590a-7d78-32b645974ead&t=5f0d06d6-9390-514d-fa1d-79fe5d3023fe&l=56

Console log: 'System.Runtime.Tests' from job 1da0184f-ed34-44a4-bd6d-fa09fa6457c9 workitem f3c909b1-80b0-48f4-b9ac-df8309a98c73 (windows.10.amd64.open.rt) executed on machine a0049N5

C:\h\w\B46309D4\w\AF600982\e>call RunTests.cmd --runtime-path C:\h\w\B46309D4\p 
----- start Fri 05/21/2021 22:18:30.18 ===============  To repro directly: ===================================================== 
pushd C:\h\w\B46309D4\w\AF600982\e\
"C:\h\w\B46309D4\p\dotnet.exe" exec --runtimeconfig System.Runtime.Tests.runtimeconfig.json --depsfile System.Runtime.Tests.deps.json xunit.console.dll System.Runtime.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing 
popd
===========================================================================================================

C:\h\w\B46309D4\w\AF600982\e>"C:\h\w\B46309D4\p\dotnet.exe" exec --runtimeconfig System.Runtime.Tests.runtimeconfig.json --depsfile System.Runtime.Tests.deps.json xunit.console.dll System.Runtime.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing  
  Discovering: System.Runtime.Tests (method display = ClassAndMethod, method display options = None)

Assert failure(PID 4564 [0x000011d4], Thread: 9668 [0x25c4]): (SIZE_T)mtype < COUNTOF(nativeSizes)

CORECLR! GetCLRRuntimeHost + 0x2A92BC (0x71fbeb0c)
CORECLR! GetCLRRuntimeHost + 0x2AD03C (0x71fc288c)
CORECLR! GetCLRRuntimeHost + 0x3CF71B (0x720e4f6b)
CORECLR! GetCLRRuntimeHost + 0x3CF175 (0x720e49c5)
CORECLR! GetCLRRuntimeHost + 0x3B86EC (0x720cdf3c)
CORECLR! GetCLRRuntimeHost + 0x3B0678 (0x720c5ec8)
CORECLR! GetCLRRuntimeHost + 0x3AEDEE (0x720c463e)
CORECLR! GetCLRRuntimeHost + 0x3AE561 (0x720c3db1)
CORECLR! GetCLRRuntimeHost + 0x231669 (0x71f46eb9)
CORECLR! GetCLRRuntimeHost + 0x2435D2 (0x71f58e22)
    File: D:\workspace\_work\1\s\src\coreclr\vm\mlinfo.cpp Line: 2930
    Image: C:\h\w\B46309D4\p\dotnet.exe

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on May 21, 2021
  2. changed the title [-]CI Assert failure in System.Runtime.Tests[/-] [+]CI Assert failure when starting System.Runtime.Tests[/+] on May 21, 2021
  3. jkotas commented on May 21, 2021

    @jkotas
    Member

    The pattern leading to this assert: #52992 (comment)

    Stack trace:

    03 0b35c7cc 720feb0c coreclr!DbgAssertDialog+0x20b [D:\workspace\_work\1\s\src\coreclr\utilcode\debug.cpp @ 695] 
    04 0b35c848 7210288c coreclr!MarshalInfo::GetNativeSize+0x99 [D:\workspace\_work\1\s\src\coreclr\vm\mlinfo.cpp @ 2931] 
    05 0b35c8bc 72224f6b coreclr!MarshalInfo::SetupArgumentSizes+0xc9 [D:\workspace\_work\1\s\src\coreclr\vm\mlinfo.cpp @ 2903] 
    06 0b35cc44 722249c5 coreclr!ComCallMethodDesc::InitNativeInfo+0x3aa [D:\workspace\_work\1\s\src\coreclr\vm\comtoclrcall.cpp @ 1043] 
    07 0b35ccec 7220df3c coreclr!ComCallMethodDesc::InitField+0x191 [D:\workspace\_work\1\s\src\coreclr\vm\comtoclrcall.cpp @ 977] 
    08 0b35d068 72205ec8 coreclr!ComMethodTable::LayOutClassMethodTable+0x926 [D:\workspace\_work\1\s\src\coreclr\vm\comcallablewrapper.cpp @ 3505] 
    09 0b35d124 7220463e coreclr!ComCallWrapper::GetIClassXIP+0x1fc [D:\workspace\_work\1\s\src\coreclr\vm\comcallablewrapper.cpp @ 2341] 
    0a 0b35d1ec 72203db1 coreclr!GetComIPFromCCW_ForIntfMT_Worker+0x2e3 [D:\workspace\_work\1\s\src\coreclr\vm\comcallablewrapper.cpp @ 2649] 
    0b 0b35d2c8 72086eb9 coreclr!ComCallWrapper::GetComIPFromCCW+0x4aa [D:\workspace\_work\1\s\src\coreclr\vm\comcallablewrapper.cpp @ 2813] 
    0c 0b35d420 72098e22 coreclr!GetComIPFromObjectRef+0x649 [D:\workspace\_work\1\s\src\coreclr\vm\interopconverter.cpp @ 132] 
    0d 0b35d49c 7218902c coreclr!MarshalObjectToInterface+0xda [D:\workspace\_work\1\s\src\coreclr\vm\interoputil.cpp @ 4224] 
    0e 0b35d570 0b5fb2ee coreclr!StubHelpers::InterfaceMarshaler__ConvertToNative+0xdc [D:\workspace\_work\1\s\src\coreclr\vm\stubhelpers.cpp @ 432] 
    0f 0b35d5d0 0b5fb202 System_IO_FileSystem!ILStubClass.IL_STUB_PInvoke(EnumUILanguagesProc, UInt32, EnumContext)+0x46
    
  4. tarekgh commented on May 21, 2021

    @tarekgh
    MemberAuthor

    @jkotas we have reverted the original change showed the failure. Should we keep this issue open to fix from the runtime side? or you think nothing need to be done in the runtime side?

  5. jkotas commented on May 21, 2021

    @jkotas
    Member

    Yes, we should keep this issue open to fix the assert.

  6. changed the title [-]CI Assert failure when starting System.Runtime.Tests[/-] [+]AF: (SIZE_T)mtype < COUNTOF(nativeSizes) when building COM vtable[/+] on May 21, 2021
  7. added this to the 6.0.0 milestone on May 22, 2021
  8. AaronRobinsonMSFT commented on May 22, 2021

    @AaronRobinsonMSFT
    Member

    This has no issue on 64-bit. Just noticed the pointers are all 32-bit so switching to x86 build.

  9. AaronRobinsonMSFT commented on May 22, 2021

    @AaronRobinsonMSFT
    Member

    Confirmed this is only an x86 bug.

  10. AaronRobinsonMSFT commented on May 22, 2021

    @AaronRobinsonMSFT
    Member

    @jkoritzinsky Can you take a look at this. After taking a closer look here I agree with @jkotas that this should have failed in all cases. The field in question is a List<CultureInfo>. We are in a weird position here since we assert on x86 indicating the native type is unknown (correctly) whereas on Amd64 we don't perform the same field offset computation and just "do it".

    The below code is why x86 is failing - specifically line 1040 because the MarshalInfo has determined the field is generic, marks the error resource ID, and sets the type as MARSHAL_TYPE_UNKNOWN. This is what asserts when trying to compute the native size of the field in MarshalInfo::GetNativeSize().

    #ifdef TARGET_X86
    MetaSig fsig(pFD);
    fsig.NextArg();
    // Look up the best fit mapping info via Assembly & Interface level attributes
    BOOL BestFit = TRUE;
    BOOL ThrowOnUnmappableChar = FALSE;
    ReadBestFitCustomAttribute(fsig.GetModule(), pFD->GetEnclosingMethodTable()->GetCl(), &BestFit, &ThrowOnUnmappableChar);
    MarshalInfo info(fsig.GetModule(), fsig.GetArgProps(), fsig.GetSigTypeContext(), pFD->GetMemberDef(), MarshalInfo::MARSHAL_SCENARIO_COMINTEROP,
    (CorNativeLinkType)0, (CorNativeLinkFlags)0,
    FALSE, 0, fsig.NumFixedArgs(), BestFit, ThrowOnUnmappableChar, FALSE, NULL, FALSE
    #ifdef _DEBUG
    , szDebugName, szDebugClassName, 0
    #endif
    );
    if (IsFieldGetter())
    {
    // getter takes 'this' and the output argument by-ref
    nativeArgSize = sizeof(void *) + sizeof(void *);
    }
    else
    {
    info.SetupArgumentSizes();
    // setter takes 'this' and the input argument by-value
    nativeArgSize = sizeof(void *) + info.GetNativeArgSize();
    }
    #endif // TARGET_X86

    The repro is simple on Windows x86.

    public unsafe class Program
    {
        static void Main(string[] args)
        {
            var context = new EnumContext();
            EnumUILanguagesProc proc = EnumUiLanguagesCallback;
    
            EnumUILanguages(proc, MUI_ALL_INSTALLED_LANGUAGES | MUI_LANGUAGE_NAME, context);
            GC.KeepAlive(proc);
        }
    
        private static bool EnumUiLanguagesCallback(IntPtr lpUiLanguageString, EnumContext lParam)
        {
            Console.WriteLine($"{nameof(EnumUiLanguagesCallback)}");
            var cultureName = Marshal.PtrToStringUni(lpUiLanguageString);
            if (cultureName != null)
            {
                lParam.InstalledCultures.Add(CultureInfo.GetCultureInfo(cultureName));
                return true;
            }
    
            return false;
        }
    
        private const uint MUI_LANGUAGE_NAME = 0x8;
        private const uint MUI_ALL_INSTALLED_LANGUAGES = 0x20;
    
        [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
        private static extern bool EnumUILanguages(EnumUILanguagesProc lpUILanguageEnumProc, uint dwFlags, EnumContext lParam);
    
        private delegate bool EnumUILanguagesProc(IntPtr lpUILanguageString, EnumContext lParam);
    
        private class EnumContext
        {
            // Marshalling this field is invalid but on Amd64 we ignore it and on x86
            // we assert or will index into random memory.
            public readonly List<CultureInfo> InstalledCultures = new();
        }
    }
  11. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on May 24, 2021
  12. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 8, 2021
  13. ghost locked as resolved and limited conversation to collaborators on Jul 8, 2021
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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions