| Index: hax/haxlib.cc
|
| diff --git a/hax/haxlib.cc b/hax/haxlib.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cd6b9d31194355d61dab8a2c06e9b27e4416b5b5
|
| --- /dev/null
|
| +++ b/hax/haxlib.cc
|
| @@ -0,0 +1,40 @@
|
| +#include "base/allocator/allocator_shim.h"
|
| +#include "base/logging.h"
|
| +#include "base/process/memory.h"
|
| +
|
| +volatile bool did_call_new_handler = false;
|
| +
|
| +static void NewHandler() {
|
| + printf("Did call the std::new_handler. SUCCESS.\n");
|
| + fflush(stdout);
|
| + exit(0);
|
| +}
|
| +
|
| +extern "C" void __attribute__((visibility("default"))) Hax() {
|
| + void* ptr;
|
| +
|
| + // Normal malloc/free - no problems
|
| + ptr = malloc(64);
|
| + free(ptr);
|
| +
|
| + // Unchecked malloc/free - problems!
|
| + CHECK(base::UncheckedMalloc(42, &ptr));
|
| + free(ptr);
|
| +
|
| + printf("malloc and unchecked malloc test passed, now testing SetCallNewHandlerOnMallocFailure\n");
|
| +
|
| + std::set_new_handler(&NewHandler);
|
| + base::allocator::SetCallNewHandlerOnMallocFailure(true);
|
| + while(true) {
|
| + const size_t kAllocSize = 128 * 1024 * 102;
|
| + volatile uint8_t* x = (volatile uint8_t*) malloc(kAllocSize);
|
| + if (!x) {
|
| + printf("Bummer, malloc returned nullptr without calling the new handler. FAIL\n");
|
| + exit(1);
|
| + break;
|
| + }
|
| + x[0] = 1;
|
| + x[kAllocSize - 1] = 1;
|
| + }
|
| +
|
| +}
|
|
|