microsoft / microsoft/mimalloc

Loading C++ dll from C# executable with mimalloc

Open
#378 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

I am using a C# executable that loads a C++ dll with VS2019 msvc compiler (that also has dependencies on some other C++ dll's under my control). As soon as i enable mimalloc within C++ it crashes. See below.

I am correctly linking with mimalloc-override.lib and using
`#include `
It crashes directly when i try to load the C++ dll from within C#. This process is already working with both the default allocator and another custom allocator. Any clues what i am doing wrong? Or is this not supported?

Exception:
`Unhandled exception at 0x77252465 (ntdll.dll) in program.exe: 0xC0000005: Access violation reading location 0x00000000.`
when starting the program i'm getting the following callstack:

```
ntdll.dll!_RtlUnicodeToMultiByteN@20() Unknown
ntdll.dll!RtlUnicodeStringToAnsiString() Unknown
mimalloc-redirect32.dll!78a92e04() Unknown
mimalloc-redirect32.dll![Frames below may be incorrect and/or missing, no symbols loaded for mimalloc-redirect32.dll] Unknown
mimalloc-redirect32.dll!78a93663() Unknown
mimalloc-redirect32.dll!78a9268a() Unknown
ntdll.dll!LdrEnumerateLoadedModules() Unknown
mimalloc-redirect32.dll!78a926f6() Unknown
mimalloc-redirect32.dll!78a93b44() Unknown
mimalloc-redirect32.dll!78a922af() Unknown
` ntdll.dll!_LdrxCallInitRoutine@16() Unknown
ntdll.dll!LdrpCallInitRoutine() Unknown
ntdll.dll!LdrpInitializeNode() Unknown
ntdll.dll!LdrpInitializeGraphRecurse() Unknown
ntdll.dll!LdrpInitializeGraphRecurse() Unknown
ntdll.dll!LdrpInitializeGraphRecurse() Unknown
ntdll.dll!LdrpPrepareModuleForExecution() Unknown
ntdll.dll!LdrpLoadDllInternal() Unknown
ntdll.dll!_LdrpLoadDll@16() Unknown
ntdll.dll!LdrLoadDll() Unknown
....
```

I think this is the C# callstack trying to load my C++ dll.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the crash when the C# executable loads the C++ DLL with mimalloc-override.lib and mimalloc-new-delete.h enabled. Inspect the mimalloc-redirect32.dll frames in the provided loader call stack and compare behavior with the default and other custom allocators. Done means identifying the supported configuration or documenting the incompatibility and its cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.