Skip to content

Crash after working some time. #34

Open

Description

@mrzaxaryan

Hi, thank you for your great job.
I compile MemoryModulePP to MemoryModulePP.dll
I have host.exe that is dynamically linked with MemoryModulePP.dll
Host.exe loads plugin.dll from byte[] using MemoryModulePP
App crash with Fail Fast exception after working for some time.

Activity

  1. changed the title [-]Crash after working for while.[/-] [+]Crash after working some time.[/+] on Sep 23, 2023
  2. bb107 commented on Sep 23, 2023

    @bb107
    Owner

    Hi. Can you tell me the details about this exception? Thanks.

  3. mrzaxaryan commented on Sep 23, 2023

    @mrzaxaryan
    Author

    No exception is thrown app just crash.
    From event viewer.
    Faulting application name: Host.exe, version: 1.0.0.0, time stamp: 0x650ea3ea
    Faulting module name: 3F929562B0A1EF11.DLL, version: 0.0.0.0, time stamp: 0x650e2dbc
    Exception code: 0xc0000005
    Fault offset: 0x000000000001b830
    Faulting process id: 0x4094
    Faulting application start time: 0x01d9edf9569ff980
    Faulting application path: D:...\publish\Host.exe
    Faulting module path: 6F80ED08F9C18F55\3F929562B0A1EF11.DLL
    Report Id: 1e22cf37-50e8-44ed-9472-687aede1b8be
    Faulting package full name:
    Faulting package-relative application ID:

  4. mrzaxaryan commented on Sep 23, 2023

    @mrzaxaryan
    Author

    WinDbg
    (c48.7adc): Access violation - code c0000005 (first chance)
    First chance exceptions are reported before any exception handling.
    This exception may be expected and handled.
    00000297b0fa82fa 48032cc8 add rbp,qword ptr [rax+rcx*8] ds:000002d7b25cb0d0=????????????????

  5. mrzaxaryan commented on Sep 23, 2023

    @mrzaxaryan
    Author

    I make a simple test plugin.dll that creates a new thread and prints "Hello World!" in console after printing app crash with Access violation - code c0000005
    I think that it will make sense to write that plugin is written using C# net 8.0rc1 compiled using NativeAOT toolchain
    repro

    pfn = GetProcAddress(hModule, "thread");
    if (pfn && pfn()) {
    	printf("thread test failed.\n");
    }
    

    test.zip

  6. bb107 commented on Sep 24, 2023

    @bb107
    Owner

    Hi, I just created the MmpTlsFiber branch to solve this problem.

  7. mrzaxaryan commented on Sep 25, 2023

    @mrzaxaryan
    Author

    I can confirm that issue is fixed.
    Can you add crypto wallet address into readme for donations?

  8. mrzaxaryan commented on Sep 25, 2023

    @mrzaxaryan
    Author

    Second round.
    Steps.

    1. Load dll.
    2. Call dll method.
    3. App crashed.
      I think app is crashed on method return.
  9. bb107 commented on Sep 25, 2023

    @bb107
    Owner

    Any exception details in debugger?

  10. mrzaxaryan commented on Sep 26, 2023

    @mrzaxaryan
    Author

    exception

    Exception thrown at 0x0000022A85E7E140 in test.exe: 0xC0000005: 
    Access violation executing location 0x0000022A85E7E140.
    

    repro
    test.zip

    pfn = GetProcAddress(hModule, "thread");
    if (pfn && pfn()) {
    	printf("thread test failed.\n");
    }
    
  11. bb107 commented on Sep 27, 2023

    @bb107
    Owner

    The reason for this problem is that calling the thread function creates a thread that runs continuously and does not stop when the function returns. If you call FreeLibraryMemory at this point to release the module, it will result in a memory access conflict for the aforementioned thread. The solution is not to release this module.
    In addition, if the thread function is called, the module's load count will be set to -1, which means that FreeLibrary will not unload this module.
    screenshot

  12. mrzaxaryan commented on Sep 27, 2023

    @mrzaxaryan
    Author

    App is crashed before FreeLibraryMemory is called.
    After dll's method is called and on return application crashes.

  13. bb107 commented on Sep 27, 2023

    @bb107
    Owner

    Can you explain what happened in this method?

  14. bb107 commented on Sep 28, 2023

    @bb107
    Owner

    In addition, if the DLL is a .NET assembly, the DLL file buffer passed to the LoadLibraryMemory series of functions must be released after the DLL is unloaded. Because CLR.DLL will remap program files, but I'm not sure if it is still needed after Native AOT. If you can provide a sample, it can help me locate the problem.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions