Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3473)

Unified Diff: hax/haxlib.cc

Issue 2279473002: [OBSOLETE]new experiment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « hax/hax.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
+
+}
« no previous file with comments | « hax/hax.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698