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

Side by Side Diff: third_party/tcmalloc/chromium/src/malloc_hook.cc

Issue 576001: Merged third_party/tcmalloc/vendor/src(google-perftools r87) into... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Removed the unnecessary printf and ASSERT(0) Created 10 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 { 416 {
417 // Fall back to old 32-bit offset mmap() call 417 // Fall back to old 32-bit offset mmap() call
418 // Old syscall interface cannot handle six args, so pass in an array 418 // Old syscall interface cannot handle six args, so pass in an array
419 int32 args[6] = { (int32) start, length, prot, flags, fd, (off_t) offset }; 419 int32 args[6] = { (int32) start, length, prot, flags, fd, (off_t) offset };
420 result = (void *)syscall(SYS_mmap, args); 420 result = (void *)syscall(SYS_mmap, args);
421 } 421 }
422 out: 422 out:
423 return result; 423 return result;
424 } 424 }
425 425
426 # endif 426 # endif // defined(__x86_64__)
427 427
428 // We use do_mmap64 abstraction to put MallocHook::InvokeMmapHook 428 // We use do_mmap64 abstraction to put MallocHook::InvokeMmapHook
429 // calls right into mmap and mmap64, so that the stack frames in the caller's 429 // calls right into mmap and mmap64, so that the stack frames in the caller's
430 // stack are at the same offsets for all the calls of memory allocating 430 // stack are at the same offsets for all the calls of memory allocating
431 // functions. 431 // functions.
432 432
433 // Put all callers of MallocHook::Invoke* in this module into 433 // Put all callers of MallocHook::Invoke* in this module into
434 // malloc_hook section, 434 // malloc_hook section,
435 // so that MallocHook::GetCallerStackTrace can function accurately: 435 // so that MallocHook::GetCallerStackTrace can function accurately:
436 436
(...skipping 28 matching lines...) Expand all
465 465
466 extern "C" void* mmap(void *start, size_t length, int prot, int flags, 466 extern "C" void* mmap(void *start, size_t length, int prot, int flags,
467 int fd, off_t offset) __THROW { 467 int fd, off_t offset) __THROW {
468 MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset); 468 MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset);
469 void *result = do_mmap64(start, length, prot, flags, fd, 469 void *result = do_mmap64(start, length, prot, flags, fd,
470 static_cast<size_t>(offset)); // avoid sign extension 470 static_cast<size_t>(offset)); // avoid sign extension
471 MallocHook::InvokeMmapHook(result, start, length, prot, flags, fd, offset); 471 MallocHook::InvokeMmapHook(result, start, length, prot, flags, fd, offset);
472 return result; 472 return result;
473 } 473 }
474 474
475 #endif 475 #endif // !defined(__USE_FILE_OFFSET64) || !defined(__REDIRECT_NTH)
476 476
477 extern "C" int munmap(void* start, size_t length) __THROW { 477 extern "C" int munmap(void* start, size_t length) __THROW {
478 MallocHook::InvokeMunmapHook(start, length); 478 MallocHook::InvokeMunmapHook(start, length);
479 return syscall(SYS_munmap, start, length); 479 return syscall(SYS_munmap, start, length);
480 } 480 }
481 481
482 extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size, 482 extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size,
483 int flags, ...) __THROW { 483 int flags, ...) __THROW {
484 va_list ap; 484 va_list ap;
485 va_start(ap, flags); 485 va_start(ap, flags);
486 void *new_address = va_arg(ap, void *); 486 void *new_address = va_arg(ap, void *);
487 va_end(ap); 487 va_end(ap);
488 void* result = sys_mremap(old_addr, old_size, new_size, flags, new_address); 488 void* result = sys_mremap(old_addr, old_size, new_size, flags, new_address);
489 MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags, 489 MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags,
490 new_address); 490 new_address);
491 return result; 491 return result;
492 } 492 }
493 493
494 // libc's version: 494 // libc's version:
495 extern "C" void* __sbrk(ptrdiff_t increment); 495 extern "C" void* __sbrk(ptrdiff_t increment);
496 496
497 extern "C" void* sbrk(ptrdiff_t increment) __THROW { 497 extern "C" void* sbrk(ptrdiff_t increment) __THROW {
498 MallocHook::InvokePreSbrkHook(increment); 498 MallocHook::InvokePreSbrkHook(increment);
499 void *result = __sbrk(increment); 499 void *result = __sbrk(increment);
500 MallocHook::InvokeSbrkHook(result, increment); 500 MallocHook::InvokeSbrkHook(result, increment);
501 return result; 501 return result;
502 } 502 }
503 503
504 #endif 504 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot,
505 int flags, int fd, off_t offset) {
506 return do_mmap64(start, length, prot, flags, fd, offset);
507 }
508
509 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) {
510 return sys_munmap(start, length);
511 }
512
513 #else // defined(__linux) &&
514 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__))
515
516 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot,
517 int flags, int fd, off_t offset) {
518 return mmap(start, length, prot, flags, fd, offset);
519 }
520
521 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) {
522 return munmap(start, length);
523 }
524
525 #endif // defined(__linux) &&
526 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__))
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/malloc_extension.cc ('k') | third_party/tcmalloc/chromium/src/memfs_malloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698