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

Side by Side Diff: hax/haxlib.cc

Issue 2270923003: Alternative solution for crbug.com/594674 base ond DEEPBIND 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 extern "C" void* tc_malloc();
6
7 volatile bool did_call_new_handler = false;
8
9 static void NewHandler() {
10 printf("Did call the std::new_handler. SUCCESS.\n");
11 fflush(stdout);
12 exit(0);
13 }
14
15 extern "C" void __attribute__((visibility("default"))) Hax() {
16 void* ptr;
17
18 printf("DSO malloc: %p\n", &malloc);
19 printf("DSO tc_malloc: %p\n", &tc_malloc);
20 printf("DSO free: %p\n", &free);
21 printf("DSO UncheckedMalloc: %p\n", &base::UncheckedMalloc);
22
23 // Normal malloc/free - no problems
24 ptr = malloc(64);
25 free(ptr);
26
27 // Unchecked malloc/free - problems!
28 CHECK(base::UncheckedMalloc(42, &ptr));
29 free(ptr);
30
31 printf("malloc and unchecked malloc test passed, now testing SetCallNewHandler OnMallocFailure\n");
32
33 std::set_new_handler(&NewHandler);
34 base::allocator::SetCallNewHandlerOnMallocFailure(true);
35 while(true) {
36 const size_t kAllocSize = 128 * 1024 * 102;
37 volatile uint8_t* x = (volatile uint8_t*) malloc(kAllocSize);
38 if (!x) {
39 printf("Bummer, malloc returned nullptr without calling the new handler. F AIL\n");
40 exit(1);
41 break;
42 }
43 x[0] = 1;
44 x[kAllocSize - 1] = 1;
45 }
46
47 }
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