You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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=????????????????
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");
}
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.
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.
Activity
[-]Crash after working for while.[/-][+]Crash after working some time.[/+]bb107 commentedon Sep 23, 2023
Hi. Can you tell me the details about this exception? Thanks.
mrzaxaryan commentedon Sep 23, 2023
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:
mrzaxaryan commentedon Sep 23, 2023
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.
00000297
b0fa82fa 48032cc8 add rbp,qword ptr [rax+rcx*8] ds:000002d7b25cb0d0=????????????????mrzaxaryan commentedon Sep 23, 2023
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
test.zip
bb107 commentedon Sep 24, 2023
Hi, I just created the MmpTlsFiber branch to solve this problem.
mrzaxaryan commentedon Sep 25, 2023
I can confirm that issue is fixed.
Can you add crypto wallet address into readme for donations?
mrzaxaryan commentedon Sep 25, 2023
Second round.
Steps.
I think app is crashed on method return.
bb107 commentedon Sep 25, 2023
Any exception details in debugger?
mrzaxaryan commentedon Sep 26, 2023
exception
repro
test.zip
bb107 commentedon Sep 27, 2023
The reason for this problem is that calling the

threadfunction creates a thread that runs continuously and does not stop when the function returns. If you callFreeLibraryMemoryat 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
threadfunction is called, the module's load count will be set to -1, which means thatFreeLibrarywill not unload this module.mrzaxaryan commentedon Sep 27, 2023
App is crashed before
FreeLibraryMemoryis called.After dll's method is called and on return application crashes.
bb107 commentedon Sep 27, 2023
Can you explain what happened in this method?
bb107 commentedon Sep 28, 2023
In addition, if the DLL is a .NET assembly, the DLL file buffer passed to the
LoadLibraryMemoryseries of functions must be released after the DLL is unloaded. BecauseCLR.DLLwill 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.