Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
wip: remove debug heap
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroKaku committed Nov 13, 2022
1 parent 570b1d9 commit c16a1f9
Show file tree
Hide file tree
Showing 35 changed files with 373 additions and 1,616 deletions.
File renamed without changes.
File renamed without changes.
18 changes: 3 additions & 15 deletions msvc/ucxxrt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@
<ClCompile Include="..\src\crt\vcruntime\delete_array_nothrow.cpp" />
<ClCompile Include="..\src\crt\vcruntime\delete_array_size.cpp" />
<ClCompile Include="..\src\crt\vcruntime\delete_array_size_align.cpp" />
<ClCompile Include="..\src\crt\vcruntime\delete_debug.cpp" />
<ClCompile Include="..\src\crt\vcruntime\delete_km.cpp" />
<ClCompile Include="..\src\crt\vcruntime\delete_scalar.cpp" />
<ClCompile Include="..\src\crt\vcruntime\delete_scalar_align.cpp" />
Expand Down Expand Up @@ -299,7 +298,6 @@
<ClCompile Include="..\src\crt\vcruntime\new_array_align.cpp" />
<ClCompile Include="..\src\crt\vcruntime\new_array_align_nothrow.cpp" />
<ClCompile Include="..\src\crt\vcruntime\new_array_nothrow.cpp" />
<ClCompile Include="..\src\crt\vcruntime\new_debug.cpp" />
<ClCompile Include="..\src\crt\vcruntime\new_km.cpp" />
<ClCompile Include="..\src\crt\vcruntime\new_mode.cpp" />
<ClCompile Include="..\src\crt\vcruntime\new_scalar.cpp" />
Expand Down Expand Up @@ -343,26 +341,16 @@
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\align.cpp" />
<ClCompile Include="..\src\ucrt\heap\calloc.cpp" />
<ClCompile Include="..\src\ucrt\heap\calloc_base.cpp" />
<ClCompile Include="..\src\ucrt\heap\calloc_km.cpp" />
<ClCompile Include="..\src\ucrt\heap\debug_heap.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\kcalloc.cpp" />
<ClCompile Include="..\src\ucrt\heap\expand.cpp" />
<ClCompile Include="..\src\ucrt\heap\free.cpp" />
<ClCompile Include="..\src\ucrt\heap\free_base.cpp" />
<ClCompile Include="..\src\ucrt\heap\free_km.cpp" />
<ClCompile Include="..\src\ucrt\heap\kfree.cpp" />
<ClCompile Include="..\src\ucrt\heap\malloc.cpp" />
<ClCompile Include="..\src\ucrt\heap\malloc_base.cpp" />
<ClCompile Include="..\src\ucrt\heap\malloc_km.cpp" />
<ClCompile Include="..\src\ucrt\heap\kmalloc.cpp" />
<ClCompile Include="..\src\ucrt\heap\msize.cpp" />
<ClCompile Include="..\src\ucrt\heap\new_handler.cpp" />
<ClCompile Include="..\src\ucrt\heap\new_mode.cpp" />
<ClCompile Include="..\src\ucrt\heap\realloc.cpp" />
<ClCompile Include="..\src\ucrt\heap\realloc_base.cpp" />
<ClCompile Include="..\src\ucrt\heap\recalloc.cpp" />
<ClCompile Include="..\src\ucrt\internal\initialization.cpp" />
<ClCompile Include="..\src\ucrt\internal\locks.cpp" />
Expand Down
27 changes: 3 additions & 24 deletions msvc/ucxxrt.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,6 @@
<ClCompile Include="..\src\crt\vcruntime\delete_array_size_align.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
<ClCompile Include="..\src\crt\vcruntime\delete_debug.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
<ClCompile Include="..\src\crt\vcruntime\delete_scalar.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
Expand Down Expand Up @@ -338,9 +335,6 @@
<ClCompile Include="..\src\crt\vcruntime\new_array_nothrow.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
<ClCompile Include="..\src\crt\vcruntime\new_debug.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
<ClCompile Include="..\src\crt\vcruntime\new_mode.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
Expand Down Expand Up @@ -647,33 +641,18 @@
<ClCompile Include="..\src\ucrt\heap\calloc.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\calloc_base.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\debug_heap.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\expand.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\free.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\free_base.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\malloc_base.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\msize.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\realloc.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\realloc_base.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\recalloc.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
Expand All @@ -686,13 +665,13 @@
<ClCompile Include="..\src\crt\vcruntime\user.cpp">
<Filter>ucxxrt\crt\vcruntime</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\malloc_km.cpp">
<ClCompile Include="..\src\ucrt\heap\kmalloc.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\free_km.cpp">
<ClCompile Include="..\src\ucrt\heap\kfree.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\ucrt\heap\calloc_km.cpp">
<ClCompile Include="..\src\ucrt\heap\kcalloc.cpp">
<Filter>ucxxrt\ucrt\heap</Filter>
</ClCompile>
<ClCompile Include="..\src\crt\vcruntime\delete_km.cpp">
Expand Down
72 changes: 0 additions & 72 deletions src/crt/vcruntime/delete_debug.cpp

This file was deleted.

1 change: 1 addition & 0 deletions src/crt/vcruntime/delete_km.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <malloc.h>
#include <vcruntime_new.h>
#include <vcstartup_internal.h>
#include <kext/kmalloc.h>

////////////////////////////////////////////////////////////////
// delete() Fallback Ordering
Expand Down
4 changes: 0 additions & 4 deletions src/crt/vcruntime/delete_scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@
_CRT_SECURITYCRITICAL_ATTRIBUTE
void __CRTDECL operator delete(void* const block) noexcept
{
#ifdef _DEBUG
_free_dbg(block, _UNKNOWN_BLOCK);
#else
free(block);
#endif
}
73 changes: 9 additions & 64 deletions src/crt/vcruntime/internal_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,62 +248,24 @@ extern "C++"
// CRT Memory Allocation and Management
//
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#ifdef _DEBUG

// These must match the definitions in the CoreCRT's debug header. They
// are defined separately here to avoid unwanted CRT header dependencies.
#define _NORMAL_BLOCK 1
#define _CRT_BLOCK 2

#define _calloc_crt(c, s) (_calloc_dbg ( c, s, _CRT_BLOCK, __FILE__, __LINE__))
#define _free_crt(p) (_free_dbg (p, _CRT_BLOCK ))
#define _malloc_crt(s) (_malloc_dbg ( s, _CRT_BLOCK, __FILE__, __LINE__))
#define _msize_crt(p) (_msize_dbg (p, _CRT_BLOCK ))
#define _recalloc_crt(p, c, s) (_recalloc_dbg(p, c, s, _CRT_BLOCK, __FILE__, __LINE__))
#define _realloc_crt(p, s) (_realloc_dbg (p, s, _CRT_BLOCK, __FILE__, __LINE__))

#define _malloca_crt(size) \
__pragma(warning(suppress: 6255)) \
(_MallocaComputeSize(size) != 0 \
? _MarkAllocaS(_malloc_crt(_MallocaComputeSize(size)), _ALLOCA_S_HEAP_MARKER) \
: NULL)
// When building for vcruntime*.dll, we are not a part of the UCRT or OS so we
// should use the public allocation functions exported by the UCRT.
#define _calloc_crt calloc
#define _free_crt free
#define _malloc_crt malloc
#define _realloc_crt realloc
#define _msize_crt _msize
#define _recalloc_crt _recalloc

#else // ^^^ _DEBUG ^^^ // vvv !_DEBUG vvv

// The *_crt macros call the allocation function that vcruntime should use for
// internal allocations. It changes based off of where it is being built.

#ifdef _CRT_WINDOWS
// When building for the UCRT, we want to use the internal allocation functions.
// We need to ensure that users hooking the public allocation functions do not
// interfere with the UCRT's allocations.
#define _calloc_crt _calloc_base
#define _free_crt _free_base
#define _malloc_crt _malloc_base
#define _realloc_crt _realloc_base
#define _msize_crt _msize_base
#define _recalloc_crt _recalloc_base
#else
// When building for vcruntime*.dll, we are not a part of the UCRT or OS so we
// should use the public allocation functions exported by the UCRT.
#define _calloc_crt calloc
#define _free_crt free
#define _malloc_crt malloc
#define _realloc_crt realloc
#define _msize_crt _msize
#define _recalloc_crt _recalloc
#endif

#define _malloca_crt(size) \
#define _malloca_crt(size) \
__pragma(warning(suppress: 6255)) \
(_MallocaComputeSize(size) != 0 \
? ((_MallocaComputeSize(size) <= _ALLOCA_S_THRESHOLD) \
? _MarkAllocaS(_alloca(_MallocaComputeSize(size)), _ALLOCA_S_STACK_MARKER) \
: _MarkAllocaS(_malloc_crt(_MallocaComputeSize(size)), _ALLOCA_S_HEAP_MARKER)) \
: NULL)

#endif // !_DEBUG

#pragma warning(push)
#pragma warning(disable: 6014)
__inline void __CRTDECL _freea_crt(_Pre_maybenull_ _Post_invalid_ void* memory)
Expand Down Expand Up @@ -482,7 +444,6 @@ extern "C++" {
#define _malloca_crt_t(t, n) (__crt_scoped_stack_ptr_tag<t>(static_cast<t*>(_malloca_crt ( (n) * sizeof(t)))))



enum : int
{
__crt_maximum_pointer_shift = sizeof(uintptr_t) * 8
Expand Down Expand Up @@ -650,22 +611,6 @@ extern "C++" {



#define _CRT_DEBUGGER_IGNORE -1
#define _CRT_DEBUGGER_GSFAILURE 1
#define _CRT_DEBUGGER_INVALIDPARAMETER 2
#define _CRT_DEBUGGER_ABORT 3

// Note: These names are well-known to the debugger
#ifdef _M_IX86
void __cdecl _crt_debugger_hook(int);
#define _CRT_DEBUGGER_HOOK _crt_debugger_hook
#else
void __cdecl __crt_debugger_hook(int);
#define _CRT_DEBUGGER_HOOK __crt_debugger_hook
#endif



//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
// Precondition Validation Macros
Expand Down
Loading

0 comments on commit c16a1f9

Please sign in to comment.