This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
462 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* PROJECT: Universal C++ RunTime (UCXXRT) | ||
* FILE: malloc_km.h | ||
* DATA: 2022/06/17 | ||
* | ||
* PURPOSE: Universal C++ RunTime | ||
* | ||
* LICENSE: Relicensed under The MIT License from The CC BY 4.0 License | ||
* | ||
* DEVELOPER: MiroKaku (miro.kaku AT Outlook.com) | ||
*/ | ||
|
||
#pragma once | ||
#include <malloc.h> | ||
|
||
|
||
extern "C" _CRT_HYBRIDPATCHABLE __declspec(noinline) _CRTRESTRICT | ||
void* __cdecl kmalloc( | ||
_In_ _CRT_GUARDOVERFLOW size_t size, | ||
_In_ int pool_type, | ||
_In_ unsigned long tag | ||
); | ||
|
||
extern "C" _CRT_HYBRIDPATCHABLE __declspec(noinline) | ||
void __cdecl kfree( | ||
_Pre_maybenull_ _Post_invalid_ void* block, | ||
_In_ unsigned long tag | ||
); | ||
|
||
extern "C" _CRT_HYBRIDPATCHABLE __declspec(noinline) _CRTRESTRICT | ||
void* __cdecl kcalloc( | ||
_In_ _CRT_GUARDOVERFLOW size_t const count, | ||
_In_ _CRT_GUARDOVERFLOW size_t const size, | ||
_In_ int pool_type, | ||
_In_ unsigned long tag | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* PROJECT: Universal C++ RunTime (UCXXRT) | ||
* FILE: new_km.h | ||
* DATA: 2022/06/17 | ||
* | ||
* PURPOSE: Universal C++ RunTime | ||
* | ||
* LICENSE: Relicensed under The MIT License from The CC BY 4.0 License | ||
* | ||
* DEVELOPER: MiroKaku (miro.kaku AT Outlook.com) | ||
*/ | ||
|
||
// | ||
// Defines the user-defined operator new. | ||
// | ||
|
||
#include <vcruntime_new.h> | ||
|
||
// user-defined operator new functions | ||
_NODISCARD _VCRT_ALLOCATOR void* __CRTDECL operator new (size_t const size, int pool_type, unsigned long tag); | ||
_NODISCARD _VCRT_ALLOCATOR void* __CRTDECL operator new[](size_t const size, int pool_type, unsigned long tag); | ||
|
||
// user-defined operator deallocation functions | ||
void __CRTDECL operator delete (void* const block, int pool_type, unsigned long tag) noexcept; | ||
void __CRTDECL operator delete[](void* const block, int pool_type, unsigned long tag) noexcept; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* PROJECT: Universal C++ RunTime (UCXXRT) | ||
* FILE: delete_km.cpp | ||
* DATA: 2022/06/17 | ||
* | ||
* PURPOSE: Universal C++ RunTime | ||
* | ||
* LICENSE: Relicensed under The MIT License from The CC BY 4.0 License | ||
* | ||
* DEVELOPER: MiroKaku (miro.kaku AT Outlook.com) | ||
*/ | ||
|
||
#include <crtdbg.h> | ||
#include <malloc.h> | ||
#include <vcruntime_new.h> | ||
#include <vcstartup_internal.h> | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// delete() Fallback Ordering | ||
// | ||
// +-------------+ | ||
// |delete_scalar<----+-----------------------+ | ||
// +--^----------+ | | | ||
// | | | | ||
// +--+---------+ +--+---------------+ +----+----------------+ | ||
// |delete_array| |delete_scalar_size| |delete_scalar_nothrow| | ||
// +--^----^----+ +------------------+ +---------------------+ | ||
// | | | ||
// | +-------------------+ | ||
// | | | ||
// +--+--------------+ +------+-------------+ | ||
// |delete_array_size| |delete_array_nothrow| | ||
// +-----------------+ +--------------------+ | ||
|
||
_CRT_SECURITYCRITICAL_ATTRIBUTE | ||
void __CRTDECL operator delete(void* const block, int /*pool_type*/, unsigned long tag) noexcept | ||
{ | ||
kfree(block, tag); | ||
} | ||
|
||
_CRT_SECURITYCRITICAL_ATTRIBUTE | ||
void __CRTDECL operator delete[](void* const block, int pool_type, unsigned long tag) noexcept | ||
{ | ||
operator delete(block, pool_type, tag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* PROJECT: Universal C++ RunTime (UCXXRT) | ||
* FILE: new_km.cpp | ||
* DATA: 2022/06/17 | ||
* | ||
* PURPOSE: Universal C++ RunTime | ||
* | ||
* LICENSE: Relicensed under The MIT License from The CC BY 4.0 License | ||
* | ||
* DEVELOPER: MiroKaku (miro.kaku AT Outlook.com) | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <vcruntime_new.h> | ||
#include <vcstartup_internal.h> | ||
|
||
// Enable the compiler to elide null checks during LTCG | ||
#pragma comment(linker, "/ThrowingNew") | ||
|
||
//////////////////////////////////// | ||
// new() Fallback Ordering | ||
// | ||
// +----------+ | ||
// |new_scalar<---------------+ | ||
// +----^-----+ | | ||
// | | | ||
// +----+-------------+ +----+----+ | ||
// |new_scalar_nothrow| |new_array| | ||
// +------------------+ +----^----+ | ||
// | | ||
// +------------+----+ | ||
// |new_array_nothrow| | ||
// +-----------------+ | ||
|
||
_CRT_SECURITYCRITICAL_ATTRIBUTE | ||
void* __CRTDECL operator new(size_t const size, int pool_type, unsigned long tag) | ||
{ | ||
for (;;) | ||
{ | ||
if (void* const block = kmalloc(size, pool_type, tag)) | ||
{ | ||
return block; | ||
} | ||
|
||
if (_callnewh(size) == 0) | ||
{ | ||
if (size == SIZE_MAX) | ||
{ | ||
__scrt_throw_std_bad_array_new_length(); | ||
} | ||
else | ||
{ | ||
__scrt_throw_std_bad_alloc(); | ||
} | ||
} | ||
|
||
// The new handler was successful; try to allocate again... | ||
} | ||
} | ||
|
||
void* __CRTDECL operator new[](size_t const size, int pool_type, unsigned long tag) | ||
{ | ||
return operator new(size, pool_type, tag); | ||
} |
Oops, something went wrong.