chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.28k stars 457 forks source link

Windows: CEF 2987 (57) crashes on AnyCPU (x64) (crome_elf and .NET) #2122

Closed magreenblatt closed 7 years ago

magreenblatt commented 7 years ago

Original report by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


I'm encounter in issue that x64 CEF 57 (2987 stable release branch at this moment) build just crashes. Issue are tied to crashpad integration, but there is no matter has config file or it absent, because it is no matter actually, due to nature of chrome_elf integration. I'm tried spotify's builds 3.2987.1591 as well as 1590. My private local 1591 also fails (both release & debug configurations).

I'm get reproduction of this issue by using very simple .NET program (be sure that you are remove prefer 32-bit and use AnyCPU (x64) build). Assemblies which is marked with pure x64 architecture is actually works. I.e. issue happens only on arch-hybrid assemblies.

#!csharp
namespace CefIssue_LoadingInsideDotNet
{
    using System;
    using System.Runtime.InteropServices;

    internal class Program
    {
        [STAThread]
        private static void Main(string[] args)
        {
            // We usually use LoadLibraryEx with altered path to load libcef from different location.
            // This call succeeds.
            var handle = LoadLibrary("libcef");
            Console.WriteLine("libcef loaded...");

            var entries = new[]
            {
                "CEF_VERSION_MAJOR", "CEF_COMMIT_NUMBER",
                "CHROME_VERSION_MAJOR", "CHROME_VERSION_MINOR", "CHROME_VERSION_BUILD", "CHROME_VERSION_PATCH"
            };

            for (var i = 0; i < entries.Length; i++)
            {
                var x = cef_version_info(i); // CRASH OCCURS HERE!
                Console.WriteLine("{0} = {1}", entries[i], x);
            }
        }

        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern IntPtr LoadLibrary(string lpFileName);

        private const CallingConvention CEF_CALL = CallingConvention.Cdecl;

        [DllImport("libcef", EntryPoint = "cef_version_info", CallingConvention = CEF_CALL)]
        private static extern int cef_version_info(int entry);
    }
}

This program just prints some CEF version info.

It works on x86, and should produce next output:

libcef loaded...
CEF_VERSION_MAJOR = 3
CEF_COMMIT_NUMBER = 1590
CHROME_VERSION_MAJOR = 57
CHROME_VERSION_MINOR = 0
CHROME_VERSION_BUILD = 2987
CHROME_VERSION_PATCH = 74

Instead on x64 it is just crashed and what of course handled by WerFault silently (no any dialogs, no ask for debugging). But configuring WER is easy for application, so out of scope.

I'm debugged error case with WinDbg a bit and got crash site:

#!c++
// somewhere in chromium/src/base/win/pe_image.cc

bool PEImage::EnumOneImportChunk(EnumImportsFunction callback,
                                 LPCSTR module_name,
                                 PIMAGE_THUNK_DATA name_table,
                                 PIMAGE_THUNK_DATA iat, PVOID cookie) const {
  if (NULL == name_table)
    return false;

  for (; name_table && name_table->u1.Ordinal; name_table++, iat++) {
    LPCSTR name = NULL;
    WORD ordinal = 0;
    WORD hint = 0;

    if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) {
      ordinal = static_cast<WORD>(IMAGE_ORDINAL32(name_table->u1.Ordinal));
    } else {
      PIMAGE_IMPORT_BY_NAME import = reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(
          RVAToAddr(name_table->u1.ForwarderString));

      hint = import->Hint;   // CRASHED HERE: import == NULL
      name = reinterpret_cast<LPCSTR>(&import->Name);
    }

    if (!callback(*this, module_name, ordinal, name, hint, iat, cookie))
      return false;
  }

  return true;
}

Stacktrace (only interested thread is shown):

0:000> ~* kp

.  0  Id: c274.c044 Suspend: 1 Teb: [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87ea4000 Unfrozen
 # Child-SP          RetAddr           Call Site
00 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0cfb0 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43c6e1e6 chrome_elf(<HRESULT 0x80004005>)+0x3ad365 [v:\cef\build\chromium_git\chromium\src\base\win\pe_image.cc @ 410]
01 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d020 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43c6d048 chrome_elf!base::win::ProcessImportChunk(class base::win::PEImage * image = 0x000000c0`87d0d148, char * module = 0x000002b2`292c72ae "mscoree.dll", struct _IMAGE_THUNK_DATA64 * name_table = 0x000002b2`292c7294, struct _IMAGE_THUNK_DATA64 * iat = 0x000002b2`292c2000, void * cookie = 0x000000c0`87d0d100)+0x56 [v:\cef\build\chromium_git\chromium\src\base\win\pe_image.cc @ 59]
02 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d070 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43c6ca0d chrome_elf!base::win::PEImage::EnumImportChunks(<function> * callback = 0x000002b2`438dbd56, void * cookie = 0x000000c0`87d0d100)+0xe8 [v:\cef\build\chromium_git\chromium\src\base\win\pe_image.cc @ 385]
03 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d0e0 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`439351ba chrome_elf!base::win::PEImage::EnumAllImports(<function> * callback = 0x000002b2`43935420, void * cookie = 0x000000c0`87d0d158)+0x3d [v:\cef\build\chromium_git\chromium\src\base\win\pe_image.cc @ 424]
04 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d120 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43935326 chrome_elf!`anonymous namespace'::ApplyIATHook(struct HINSTANCE__ * module_handle = 0x000002b2`292c0000, char * imported_from_module = 0x000002b2`43e3f878 "kernel32.dll", char * function_name = 0x000002b2`43e3f858 "SetUnhandledExceptionFilter", void * new_function = 0x000002b2`43925870, void ** old_function = 0x000002b2`295f45f8, struct _IMAGE_THUNK_DATA64 ** iat_thunk = 0x000002b2`295f4600)+0xba [v:\cef\build\chromium_git\chromium\src\chrome_elf\hook_util\hook_util.cc @ 182]
05 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d1a0 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43925520 chrome_elf!elf_hook::IATHook::Hook(struct HINSTANCE__ * module = 0x000002b2`292c0000, char * imported_from_module = 0x000002b2`43e3f878 "kernel32.dll", char * function_name = 0x000002b2`43e3f858 "SetUnhandledExceptionFilter", void * new_function = 0x000002b2`43925870)+0xa6 [v:\cef\build\chromium_git\chromium\src\chrome_elf\hook_util\hook_util.cc @ 275]
06 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d1f0 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`438fdbd0 chrome_elf!elf_crash::DisableSetUnhandledExceptionFilter(void)+0x50 [v:\cef\build\chromium_git\chromium\src\chrome_elf\crash\crash_helper.cc @ 112]
07 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d350 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43d268b8 chrome_elf!DllMain(struct HINSTANCE__ * module = 0x000002b2`438c0000, unsigned long reason = 1, void * reserved = 0x00000000`00000000)+0x50 [v:\cef\build\chromium_git\chromium\src\chrome_elf\chrome_elf_main.cc @ 48]
08 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d390 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43d26a91 chrome_elf!dllmain_dispatch(struct HINSTANCE__ * instance = 0x000002b2`438c0000, unsigned long reason = 1, void * reserved = 0x00000000`00000000)+0x98 [f:\dd\vctools\crt\vcstartup\src\startup\dll_dllmain.cpp @ 195]
09 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d3e0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba89c2eb chrome_elf!_DllMainCRTStartup(struct HINSTANCE__ * instance = 0x000002b2`438c0000, unsigned long reason = 1, void * reserved = 0x00000000`00000000)+0x31 [f:\dd\vctools\crt\vcstartup\src\startup\dll_dllmain.cpp @ 249]
0a [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d410 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba8943d2 ntdll!RtlEqualUnicodeString+0x11b
0b [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d470 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba89416f ntdll!RtlAppendUnicodeStringToString+0x3f2
0c [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d590 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba894195 ntdll!RtlAppendUnicodeStringToString+0x18f
0d [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d5d0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba8937e9 ntdll!RtlAppendUnicodeStringToString+0x1b5
0e [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d610 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba8974cc ntdll!LdrAddRefDll+0x469
0f [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d650 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba8972f7 ntdll!LdrGetDllHandleEx+0x9fc
10 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d6d0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba8964dc ntdll!LdrGetDllHandleEx+0x827
11 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d870 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6cc2a94 ntdll!LdrLoadDll+0x8c
12 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d970 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98dcfbb4 KERNELBASE!LoadLibraryExW+0x184
13 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0d9e0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98dcfc91 clr!GetMetaDataPublicInterfaceFromInternal+0x13704
14 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0da30 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98dcfd79 clr!GetMetaDataPublicInterfaceFromInternal+0x137e1
15 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0da80 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98da5f21 clr!GetMetaDataPublicInterfaceFromInternal+0x138c9
16 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0dab0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98eacdac clr!StrongNameFreeBuffer+0x10601
17 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0e2d0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98eacc83 clr!MetaDataGetDispenser+0x3cf8c
18 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0e600 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98eaca05 clr!MetaDataGetDispenser+0x3ce63
19 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0e650 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98eac906 clr!MetaDataGetDispenser+0x3cbe5
1a [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0e690 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e8f02f clr!MetaDataGetDispenser+0x3cae6
1b [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0e860 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98d14655 clr!MetaDataGetDispenser+0x1f20f
1c [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ea20 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`397228a3 clr+0x4655
1d [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ead0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`39721c24 0x00007ffe`397228a3
1e [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0eba0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`39721bd7 0x00007ffe`39721c24
1f [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ebd0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`39721ac6 0x00007ffe`39721bd7
20 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ec40 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`3972146a 0x00007ffe`39721ac6
21 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ec70 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`3972066f 0x00007ffe`3972146a
22 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0edc0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`397204f1 0x00007ffe`3972066f
23 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ee30 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98d16833 0x00007ffe`397204f1
24 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ee90 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98d16748 clr!LogHelp_LogAssert+0x1cb3
25 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0eed0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98d16db5 clr!LogHelp_LogAssert+0x1bc8
26 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0ef10 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e3862e clr!LogHelp_LogAssert+0x2235
27 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0f010 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e38f92 clr!SetRuntimeInfo+0x14de
28 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0f1f0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e38e4e clr!SetRuntimeInfo+0x1e42
29 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0f4e0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e387e0 clr!SetRuntimeInfo+0x1cfe
2a [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fb00 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e3875e clr!SetRuntimeInfo+0x1690
2b [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fb70 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`98e39954 clr!SetRuntimeInfo+0x160e
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll - 
2c [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fc00 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a12d80bd clr!CorExeMain+0x14
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\SYSTEM32\MSCOREE.DLL - 
2d [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fc40 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a137a844 mscoreei!CorExeMain+0x6d
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\System32\KERNEL32.dll - 
2e [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fca0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba7e3984 MSCOREE!CorExeMain+0x74
2f [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fcd0 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba8d3e71 KERNEL32!BaseThreadInitThunk+0x14
30 [000000c0 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000000c0)`87d0fd00 [00000000 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00000000)`00000000 ntdll!RtlUserThreadStart+0x21

Exception Info:

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: [000002b243c6d365 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b243c6d365) (chrome_elf+0x00000000003ad365)
   ExceptionCode: [c0000005 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/c0000005) (Access violation)
  ExceptionFlags: [00000000 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00000000)
NumberParameters: 2
   Parameter[0]: [0000000000000000 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/0000000000000000)
   Parameter[1]: [0000000000000000 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/0000000000000000)
Attempt to read from address [0000000000000000 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/0000000000000000)

Loaded modules:

0:000> lm
start             end                 module name
00000001`80000000 [00000001 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00000001)`9b7a5000   libcef     (deferred)             
000002b2`292c0000 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`292cc000   Xilium_CefGlue_Demo_WinForms   (deferred)             
000002b2`295a0000 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`295ac000   Xilium_CefGlue_Demo_2b2295a0000   (deferred)             
000002b2`43800000 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`438b8000   Xilium_CefGlue_2b243800000   (deferred)             
000002b2`438c0000 [000002b2 (bb)](https://bitbucket.org/chromiumembedded/cef/commits/000002b2)`43fca000   chrome_elf C (pdb symbols)          V:\cef\build\chromium_git\chromium\src\out\Debug_GN_x64\chrome_elf.dll.pdb
00007ffe`7fbf0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`80830000   System_ni   (deferred)             
00007ffe`80830000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`81dfb000   mscorlib_ni   (deferred)             
00007ffe`8ebb0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`8ed4b000   d3d9       (deferred)             
00007ffe`98d10000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`996f1000   clr        (export symbols)       C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
00007ffe`9a020000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`9a117000   MSVCR120_CLR0400   (deferred)             
00007ffe`9eb50000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`9ebbc000   OLEACC     (deferred)             
00007ffe`a12d0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a136c000   mscoreei   (export symbols)       C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll
00007ffe`a1370000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a13da000   MSCOREE    (export symbols)       C:\WINDOWS\SYSTEM32\MSCOREE.DLL
00007ffe`a3180000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a3218000   CRYPTUI    (deferred)             
00007ffe`a4cc0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a4dce000   clrjit     (deferred)             
00007ffe`a4e00000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a4e24000   dxva2      (deferred)             
00007ffe`a6610000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a6895000   COMCTL32   (deferred)             
00007ffe`a75b0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a7853000   DWrite     (deferred)             
00007ffe`a8de0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`a8e02000   FONTSUB    (deferred)             
00007ffe`aa1b0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`aa380000   urlmon     (deferred)             
00007ffe`aa480000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`aa700000   iertutil   (deferred)             
00007ffe`aac60000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`aae0c000   dbghelp    (deferred)             
00007ffe`aae30000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`aae3a000   VERSION    (deferred)             
00007ffe`ac0c0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ac0cc000   Secur32    (deferred)             
00007ffe`ac0d0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ac0e8000   NETAPI32   (deferred)             
00007ffe`af350000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`af3db000   WINSPOOL   (deferred)             
00007ffe`b13d0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b13eb000   dhcpcsvc   (deferred)             
00007ffe`b2880000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b2950000   WINHTTP    (deferred)             
00007ffe`b2c80000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b2c93000   WTSAPI32   (deferred)             
00007ffe`b2cc0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b2cd1000   credui     (deferred)             
00007ffe`b2ed0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b2ef7000   dwmapi     (deferred)             
00007ffe`b2f30000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b2f49000   SAMCLI     (deferred)             
00007ffe`b3ae0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b3b0c000   WINMMBASE   (deferred)             
00007ffe`b3b10000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b3b35000   WINMM      (deferred)             
00007ffe`b4070000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b4089000   USP10      (deferred)             
00007ffe`b4720000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b4a25000   d3d11      (deferred)             
00007ffe`b52d0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b536d000   uxtheme    (deferred)             
00007ffe`b5a00000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b5a0d000   HID        (deferred)             
00007ffe`b5aa0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b5b49000   dxgi       (deferred)             
00007ffe`b6210000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6249000   IPHLPAPI   (deferred)             
00007ffe`b6300000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b630e000   NETUTILS   (deferred)             
00007ffe`b6310000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6337000   USERENV    (deferred)             
00007ffe`b6680000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b668c000   CRYPTBASE   (deferred)             
00007ffe`b6700000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6737000   NTASN1     (deferred)             
00007ffe`b6740000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6768000   ncrypt     (deferred)             
00007ffe`b6770000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b679c000   bcrypt     (deferred)             
00007ffe`b6890000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b68c1000   SSPICLI    (deferred)             
00007ffe`b6ba0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6bb1000   MSASN1     (deferred)             
00007ffe`b6bc0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6c0e000   powrprof   (deferred)             
00007ffe`b6c10000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6c21000   kernel_appcore   (deferred)             
00007ffe`b6c30000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6c45000   profapi    (deferred)             
00007ffe`b6c50000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6c95000   cfgmgr32   (deferred)             
00007ffe`b6ca0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6ed6000   KERNELBASE   (export symbols)       C:\WINDOWS\System32\KERNELBASE.dll
00007ffe`b6ee0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6f3b000   WINTRUST   (deferred)             
00007ffe`b6f40000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b6f5e000   win32u     (deferred)             
00007ffe`b6f60000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b70ed000   gdi32full   (deferred)             
00007ffe`b70f0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7200000   ucrtbase   (deferred)             
00007ffe`b72b0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7a1a000   windows_storage   (deferred)             
00007ffe`b7a20000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7bff000   CRYPT32    (deferred)             
00007ffe`b7c00000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7ca0000   msvcp_win   (deferred)             
00007ffe`b7ca0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7d09000   bcryptPrimitives   (deferred)             
00007ffe`b7d30000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7dd8000   msvcrt     (deferred)             
00007ffe`b7de0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b7f15000   ole32      (export symbols)       C:\WINDOWS\System32\ole32.dll
00007ffe`b7f20000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b8016000   COMDLG32   (deferred)             
00007ffe`b8020000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b80de000   OLEAUT32   (deferred)             
00007ffe`b80e0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b822c000   USER32     (deferred)             
00007ffe`b86f0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b86f8000   PSAPI      (deferred)             
00007ffe`b8700000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b8831000   RPCRT4     (deferred)             
00007ffe`b8840000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b8898000   SHLWAPI    (deferred)             
00007ffe`b88a0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b9d2b000   SHELL32    (deferred)             
00007ffe`b9ed0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b9ed8000   NSI        (deferred)             
00007ffe`b9ee0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b9f08000   GDI32      (deferred)             
00007ffe`b9f10000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b9f7f000   WS2_32     (deferred)             
00007ffe`ba240000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba26f000   IMM32      (deferred)             
00007ffe`ba2f0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba39a000   ADVAPI32   (deferred)             
00007ffe`ba3a0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba452000   shcore     (deferred)             
00007ffe`ba460000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba4bc000   sechost    (deferred)             
00007ffe`ba4c0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba7c2000   combase    (export symbols)       C:\WINDOWS\System32\combase.dll
00007ffe`ba7d0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`ba87d000   KERNEL32   (export symbols)       C:\WINDOWS\System32\KERNEL32.dll
00007ffe`ba880000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`baa53000   ntdll      (export symbols)       C:\WINDOWS\SYSTEM32\ntdll.dll

Unloaded modules:
00007ffe`b86f0000 [00007ffe (bb)](https://bitbucket.org/chromiumembedded/cef/commits/00007ffe)`b86f8000   psapi.dll

Of course when EnumOneImportChunk fails it is process "mscoree.dll" (you can see it from callstack), so it is surely tied to .NET CLR.

This code path triggered by chrome_elf's DllMain:

#!c++
    // CRT on initialization installs an exception filter which calls
    // TerminateProcess. We need to hook CRT's attempt to set an exception.
    elf_crash::DisableSetUnhandledExceptionFilter();

PS: I'm tried to blacklist "mscoree.dll" in chrome_elf's blacklist, but then realize that it is not used in this case.

PPS: CEF 56 (which is also built with chrome_elf) has no this issue there. I.e. it is work at same host with same .NET CLR version.

magreenblatt commented 7 years ago

Original comment by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


Discussion thread.

magreenblatt commented 7 years ago

Original comment by Peiyuan Song (Bitbucket: SquallATF, GitHub: SquallATF).


Issue #2123 was marked as a duplicate of this issue.

Because chrome_elf.dll set hook for all pe module, but .NET Any Cpu bin is pe32 not pe64, chrome_elf will crash when DisableSetUnhandledExceptionFilter. The easiest way to fix this issue is create a patch for base/win/pe_image.cc, in PEImage::VerifyMagic() function, check pe image type ,if not pe64 return false to skip hook.

#ifdef _WIN64
  if (nt_headers->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64)
      return false;
#endif // _WIN64
magreenblatt commented 7 years ago

Original comment by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


@SquallATF it will be a bit dirty, because in that case CEF debug builds will constantly do crash because of assert in DisableSetUnhandledExceptionFilter. This acceptable, but annoying in long-term.

magreenblatt commented 7 years ago

Original comment by Peiyuan Song (Bitbucket: SquallATF, GitHub: SquallATF).


Another way is to implement a 32-bit hook or do not use any cpu. Implement a 32-bit hook is the best way, check pe type and choose right method found iat and do hook, that may need modify a lot of code.

magreenblatt commented 7 years ago

Original comment by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


@SquallATF actually this requires additional testing to understand how it is really affects on exception handling:

  1. throwing .NET exceptions from handler methods (i.e. when CEF on stack)

  2. system exceptions (like AV) from CEF

And this handling in cases:

  1. Exceptions on UI thread (which runs CefRunMessageLoop)

  2. Exceptions on UI thread (with wrap CefRunMessageLoop with try/catch, and mark wrapper method with HandleProcessCorruptedStateExceptions attribute) (previously only one way to reliable die in case of AVs)

  3. Exceptions on other CEF threads

Previously all .NET exceptions had been handled by AppDomain.OnUnhandledException regardless to where they occurs, but this partially breaks crash dump generation. But this should be carefully tested to make productive decisions.

I'm no have do plans do this just now (not earlier than CefGlue vNext will be released, and this testings effectively in scope of .NET bindings rather than CEF).

Personally i'm switched to use of separate executables for x64 / x86, so not critical.

magreenblatt commented 7 years ago

Original comment by Peiyuan Song (Bitbucket: SquallATF, GitHub: SquallATF).


@dmitry-azaraev may be I was wrong:

  1. Any CPU Assembly at runtime will fix PE32 Header to PE64(not change FileHeader.Machine), but I did not known why IMAGE_THUNK_DATA did not fix.

  2. DisableSetUnhandledExceptionFilter only set hook on SetUnhandledExceptionFilter from kernel32.dll, but .NET Assembly only import _CorExeMain from mscoree.dll, skip main module hook may not affect chrome_elf work.

    void DisableSetUnhandledExceptionFilter() {
        if (g_set_unhandled_exception_filter == nullptr) {
            g_set_unhandled_exception_filter = new elf_hook::IATHook();
        }
        if (g_set_unhandled_exception_filter->Hook(
            ::GetModuleHandle(nullptr), "kernel32.dll",
            "SetUnhandledExceptionFilter",
            SetUnhandledExceptionFilterPatch) != NO_ERROR) {
#ifdef _DEBUG
            assert(false);
#endif  //_DEBUG
        }
    }

chrome_elf search imports and delay imports and set hook, did not hook child module, so can safely ignore hook set for the .NET assembly:

    // Applies an import-address-table hook.  Returns a system winerror.h code.
    // Call RemoveIATHook() with |new_function|, |old_function| and |iat_thunk|
    // to remove the hook.
    DWORD ApplyIATHook(HMODULE module_handle,
        const char* imported_from_module,
        const char* function_name,
        void* new_function,
        void** old_function,
        IMAGE_THUNK_DATA** iat_thunk) {
        base::win::PEImage target_image(module_handle);
        if (!target_image.VerifyMagic())
            return ERROR_INVALID_PARAMETER;
        IATHookFunctionInfo hook_info = { false,
            imported_from_module,
            function_name,
            new_function,
            old_function,
            iat_thunk,
            ERROR_PROC_NOT_FOUND };
        // First go through the IAT. If we don't find the import we are looking
        // for in IAT, search delay import table.
        target_image.EnumAllImports(IATFindHookFuncCallback, &hook_info);
        if (!hook_info.finished_operation) {
            target_image.EnumAllDelayImports(IATFindHookFuncCallback, &hook_info);
        }
        return hook_info.return_code;
    }
magreenblatt commented 7 years ago

Original comment by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


@SquallATF i'm don't think that you are wrong. The only thing about .NET modules is that it is undocumented very well: when they introduce .NET modules as native executables, they implement them via shims (mscoree import which loads CLR). But starting from Windows 7? they integrate .NET module recognition into OS loader: it effectively can ignore all of this shims, as well as transform PE to corresponding arch. But... as you show - it is doesn't work in this way (surprisingly for me).

From "correctness" perspective I think that it is better to recognize if we running in .NET AnyCPU module in DisableSetUnhandledExceptionFilter before calling Hook, and suppress this call in that case.

I.e. in pseudo-code:

#!c++
    void DisableSetUnhandledExceptionFilter() {
        if (g_set_unhandled_exception_filter == nullptr) {
            g_set_unhandled_exception_filter = new elf_hook::IATHook();
        }

        base::win::PEImage target_image(::GetModuleHandle(nullptr));
        if (target_image.VerifyMagicNetAnyCpu()) return; // assume that we patch PEImage and add this method
                                                         // but should be doable ad-hoc in chrome_elf if we don't want patch chrome_elf

        if (g_set_unhandled_exception_filter->Hook(
            ::GetModuleHandle(nullptr), "kernel32.dll",
            "SetUnhandledExceptionFilter",
            SetUnhandledExceptionFilterPatch) != NO_ERROR) {
#ifdef _DEBUG
            assert(false);
#endif  //_DEBUG
        }
    }

But, i'm also can be wrong.

PS: Also it is interesting how it works before in CEF 56.

magreenblatt commented 7 years ago

Original comment by Peiyuan Song (Bitbucket: SquallATF, GitHub: SquallATF).


@dmitry-azaraev may be this is why CEF 56 can work chrome_elf_main.ccADDRESS_SANITIZER is defined then DisableSetUnhandledExceptionFilter will not executed.

#if !defined(ADDRESS_SANITIZER)
    elf_crash::DisableSetUnhandledExceptionFilter();
#endif  // !defined (ADDRESS_SANITIZER)
magreenblatt commented 7 years ago

Original comment by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


@SquallATF FYI: after 7 hours bitbucket still not publish your last comment into this issue, but notify me on email. I'm repost your last comment again.

May be this is why CEF 56 can work chrome_elf_main.cc, ADDRESS_SANITIZER is defined then DisableSetUnhandledExceptionFilter may not executed.

#!c++
#if !defined(ADDRESS_SANITIZER)

    elf_crash::DisableSetUnhandledExceptionFilter();

#endif  // !defined (ADDRESS_SANITIZER)
magreenblatt commented 7 years ago

Looks like the early chrome_elf initialization has been reverted in https://bugs.chromium.org/p/chromium/issues/detail?id=700371#c21 and the revert will be merged back to 2987 branch shortly. That may be sufficient to resolve this issue.

magreenblatt commented 7 years ago

Original comment by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


Thanks. Looks like this kind of revert has no chance be included in standard CEF distribution. If we had right - testing that image is PE32+AnyCPU should be actually a tiny patch, which should be much easier to maintain.

magreenblatt commented 7 years ago

Original comment by Peiyuan Song (Bitbucket: SquallATF, GitHub: SquallATF).


I try to write a method to verify dot net AnyCPU.

bool PEImage::IsDotNetAnyCPU() const {
    PVOID directory = GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR);
    DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR);

    if (NULL == directory || 0 == size)
        return false;
    PIMAGE_COR20_HEADER cor20 = reinterpret_cast<PIMAGE_COR20_HEADER>(
                                    directory);
    if (cor20->Flags != COMIMAGE_FLAGS_ILONLY)
        return false;

    return true;
}
magreenblatt commented 7 years ago

The early chrome_elf initialization has been reverted in 57.0.2987.110 (https://bitbucket.org/chromiumembedded/cef/commits/ffc57735)

magreenblatt commented 7 years ago

I believe this issue is resolved with the revert in Chromium. Please re-open if you disagree.

magreenblatt commented 7 years ago

Original comment by amaitland (Bitbucket: amaitland, GitHub: amaitland).


Everything appears to be working again.

magreenblatt commented 7 years ago

Original comment by amaitland (Bitbucket: amaitland, GitHub: amaitland).


Tested with CEF 3.2987.1597.gffc5773

magreenblatt commented 7 years ago

Original changes by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


magreenblatt commented 7 years ago

Original changes by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


magreenblatt commented 7 years ago

Original changes by Dmitry Azaraev (Bitbucket: dmitry-azaraev, GitHub: dmitry-azaraev).


magreenblatt commented 7 years ago