Skip to content

Commit

Permalink
Fix DAC issue with redefined standard new / delete operators (#55945)
Browse files Browse the repository at this point in the history
I have found that since .NET 6 preview 5, SOS on macOS arm64 crashes
when running basic commands like clrstack due to the fact that
its std::string allocations are done using standard new operator,
but the freeing at some places is done using our overriden delete
operator due to inlining of STL code.

This change removes our redefinitions of those operators for DAC
compilation, so this clash cannot happen.
  • Loading branch information
janvorli authored Jul 22, 2021
1 parent c205295 commit a81fee2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/coreclr/utilcode/clrhost_nodependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ ClrDebugState *CLRInitDebugState()

const NoThrow nothrow = { 0 };

#ifdef HAS_ADDRESS_SANITIZER
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address santizier
#else

Expand Down Expand Up @@ -345,11 +345,11 @@ operator new[](size_t n)
return result;
};

#endif // HAS_ADDRESS_SANITIZER
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE

void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT
{
#ifdef HAS_ADDRESS_SANITIZER
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address santizier (which doesn't provide for NoThrow)
void * result = operator new(n);
#else
Expand All @@ -361,14 +361,14 @@ void * __cdecl operator new(size_t n, const NoThrow&) NOEXCEPT
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));

void* result = ClrMalloc(n);
#endif // HAS_ADDRESS_SANITIZER
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
TRASH_LASTERROR;
return result;
}

void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT
{
#ifdef HAS_ADDRESS_SANITIZER
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address santizier (which doesn't provide for NoThrow)
void * result = operator new[](n);
#else
Expand All @@ -380,12 +380,12 @@ void * __cdecl operator new[](size_t n, const NoThrow&) NOEXCEPT
INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN()));

void* result = ClrMalloc(n);
#endif // HAS_ADDRESS_SANITIZER
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE
TRASH_LASTERROR;
return result;
}

#ifdef HAS_ADDRESS_SANITIZER
#if defined(HAS_ADDRESS_SANITIZER) || defined(DACCESS_COMPILE)
// use standard heap functions for address santizier
#else
void __cdecl
Expand All @@ -411,7 +411,7 @@ operator delete[](void *p) NOEXCEPT
TRASH_LASTERROR;
}

#endif // HAS_ADDRESS_SANITIZER
#endif // HAS_ADDRESS_SANITIZER || DACCESS_COMPILE

/* ------------------------------------------------------------------------ *
* New operator overloading for the executable heap
Expand Down

0 comments on commit a81fee2

Please sign in to comment.