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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « hax/hax.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "base/allocator/allocator_shim.h"
2 #include "base/logging.h"
3 #include "base/process/memory.h"
4
5 volatile bool did_call_new_handler = false;
6
7 static void NewHandler() {
8 printf("Did call the std::new_handler. SUCCESS.\n");
9 fflush(stdout);
10 exit(0);
11 }
12
13 extern "C" void __attribute__((visibility("default"))) Hax() {
14 void* ptr;
15
16 // Normal malloc/free - no problems
17 ptr = malloc(64);
18 free(ptr);
19
20 // Unchecked malloc/free - problems!
21 CHECK(base::UncheckedMalloc(42, &ptr));
22 free(ptr);
23
24 printf("malloc and unchecked malloc test passed, now testing SetCallNewHandler OnMallocFailure\n");
25
26 std::set_new_handler(&NewHandler);
27 base::allocator::SetCallNewHandlerOnMallocFailure(true);
28 while(true) {
29 const size_t kAllocSize = 128 * 1024 * 102;
30 volatile uint8_t* x = (volatile uint8_t*) malloc(kAllocSize);
31 if (!x) {
32 printf("Bummer, malloc returned nullptr without calling the new handler. F AIL\n");
33 exit(1);
34 break;
35 }
36 x[0] = 1;
37 x[kAllocSize - 1] = 1;
38 }
39
40 }
OLDNEW
« 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