Skip to content

Commit

Permalink
overwrite weak new (std::nothrow) calls
Browse files Browse the repository at this point in the history
  • Loading branch information
d-a-v committed Aug 24, 2020
1 parent 2b6423e commit c111713
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,44 @@ extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));

// overwrite weak operators new/new[] definitions

void *operator new(size_t size)
void* operator new(size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
#if defined(NEW_OOM_ABORT)
__unhandled_exception(PSTR("OOM"));
#endif
}
return ret;
return ret;
}

void *operator new[](size_t size)
void* operator new[](size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
#if defined(NEW_OOM_ABORT)
__unhandled_exception(PSTR("OOM"));
#endif
}
return ret;
}

void* operator new (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}

void* operator new[] (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}
Expand Down

0 comments on commit c111713

Please sign in to comment.