| OLD | NEW |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 void InitialPreMMapHook(const void* start, | 121 void InitialPreMMapHook(const void* start, |
| 122 size_t size, | 122 size_t size, |
| 123 int protection, | 123 int protection, |
| 124 int flags, | 124 int flags, |
| 125 int fd, | 125 int fd, |
| 126 off_t offset) { | 126 off_t offset) { |
| 127 perftools_pthread_once(&once, &RemoveInitialHooksAndCallInitializers); | 127 perftools_pthread_once(&once, &RemoveInitialHooksAndCallInitializers); |
| 128 MallocHook::InvokePreMmapHook(start, size, protection, flags, fd, offset); | 128 MallocHook::InvokePreMmapHook(start, size, protection, flags, fd, offset); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void InitialPreSbrkHook(ptrdiff_t increment) { | 131 void InitialPreSbrkHook(std::ptrdiff_t increment) { |
| 132 perftools_pthread_once(&once, &RemoveInitialHooksAndCallInitializers); | 132 perftools_pthread_once(&once, &RemoveInitialHooksAndCallInitializers); |
| 133 MallocHook::InvokePreSbrkHook(increment); | 133 MallocHook::InvokePreSbrkHook(increment); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // This function is called at most once by one of the above initial malloc | 136 // This function is called at most once by one of the above initial malloc |
| 137 // hooks. It removes all initial hooks and initializes all other clients that | 137 // hooks. It removes all initial hooks and initializes all other clients that |
| 138 // want to get control at the very first memory allocation. The initializers | 138 // want to get control at the very first memory allocation. The initializers |
| 139 // may assume that the initial malloc hooks have been removed. The initializers | 139 // may assume that the initial malloc hooks have been removed. The initializers |
| 140 // may set up malloc hooks and allocate memory. | 140 // may set up malloc hooks and allocate memory. |
| 141 void RemoveInitialHooksAndCallInitializers() { | 141 void RemoveInitialHooksAndCallInitializers() { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 void MallocHook::InvokeMremapHookSlow(const void* result, | 582 void MallocHook::InvokeMremapHookSlow(const void* result, |
| 583 const void* old_addr, | 583 const void* old_addr, |
| 584 size_t old_size, | 584 size_t old_size, |
| 585 size_t new_size, | 585 size_t new_size, |
| 586 int flags, | 586 int flags, |
| 587 const void* new_addr) { | 587 const void* new_addr) { |
| 588 INVOKE_HOOKS(MremapHook, mremap_hooks_, (result, old_addr, old_size, new_size, | 588 INVOKE_HOOKS(MremapHook, mremap_hooks_, (result, old_addr, old_size, new_size, |
| 589 flags, new_addr)); | 589 flags, new_addr)); |
| 590 } | 590 } |
| 591 | 591 |
| 592 void MallocHook::InvokePreSbrkHookSlow(ptrdiff_t increment) { | 592 void MallocHook::InvokePreSbrkHookSlow(std::ptrdiff_t increment) { |
| 593 INVOKE_HOOKS(PreSbrkHook, presbrk_hooks_, (increment)); | 593 INVOKE_HOOKS(PreSbrkHook, presbrk_hooks_, (increment)); |
| 594 } | 594 } |
| 595 | 595 |
| 596 void MallocHook::InvokeSbrkHookSlow(const void* result, ptrdiff_t increment) { | 596 void MallocHook::InvokeSbrkHookSlow(const void* result, std::ptrdiff_t increment
) { |
| 597 INVOKE_HOOKS(SbrkHook, sbrk_hooks_, (result, increment)); | 597 INVOKE_HOOKS(SbrkHook, sbrk_hooks_, (result, increment)); |
| 598 } | 598 } |
| 599 | 599 |
| 600 #undef INVOKE_HOOKS | 600 #undef INVOKE_HOOKS |
| 601 | 601 |
| 602 DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc); | 602 DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc); |
| 603 DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc); | 603 DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc); |
| 604 // actual functions are in debugallocation.cc or tcmalloc.cc | 604 // actual functions are in debugallocation.cc or tcmalloc.cc |
| 605 DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook); | 605 DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook); |
| 606 DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook); | 606 DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 int fd, __off64_t offset ) __THROW | 792 int fd, __off64_t offset ) __THROW |
| 793 ATTRIBUTE_SECTION(malloc_hook); | 793 ATTRIBUTE_SECTION(malloc_hook); |
| 794 void* mmap(void *start, size_t length,int prot, int flags, | 794 void* mmap(void *start, size_t length,int prot, int flags, |
| 795 int fd, off_t offset) __THROW | 795 int fd, off_t offset) __THROW |
| 796 ATTRIBUTE_SECTION(malloc_hook); | 796 ATTRIBUTE_SECTION(malloc_hook); |
| 797 int munmap(void* start, size_t length) __THROW | 797 int munmap(void* start, size_t length) __THROW |
| 798 ATTRIBUTE_SECTION(malloc_hook); | 798 ATTRIBUTE_SECTION(malloc_hook); |
| 799 void* mremap(void* old_addr, size_t old_size, size_t new_size, | 799 void* mremap(void* old_addr, size_t old_size, size_t new_size, |
| 800 int flags, ...) __THROW | 800 int flags, ...) __THROW |
| 801 ATTRIBUTE_SECTION(malloc_hook); | 801 ATTRIBUTE_SECTION(malloc_hook); |
| 802 void* sbrk(ptrdiff_t increment) __THROW | 802 void* sbrk(std::ptrdiff_t increment) __THROW |
| 803 ATTRIBUTE_SECTION(malloc_hook); | 803 ATTRIBUTE_SECTION(malloc_hook); |
| 804 } | 804 } |
| 805 | 805 |
| 806 extern "C" void* mmap64(void *start, size_t length, int prot, int flags, | 806 extern "C" void* mmap64(void *start, size_t length, int prot, int flags, |
| 807 int fd, __off64_t offset) __THROW { | 807 int fd, __off64_t offset) __THROW { |
| 808 MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset); | 808 MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset); |
| 809 void *result; | 809 void *result; |
| 810 if (!MallocHook::InvokeMmapReplacement( | 810 if (!MallocHook::InvokeMmapReplacement( |
| 811 start, length, prot, flags, fd, offset, &result)) { | 811 start, length, prot, flags, fd, offset, &result)) { |
| 812 result = do_mmap64(start, length, prot, flags, fd, offset); | 812 result = do_mmap64(start, length, prot, flags, fd, offset); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 va_start(ap, flags); | 847 va_start(ap, flags); |
| 848 void *new_address = va_arg(ap, void *); | 848 void *new_address = va_arg(ap, void *); |
| 849 va_end(ap); | 849 va_end(ap); |
| 850 void* result = sys_mremap(old_addr, old_size, new_size, flags, new_address); | 850 void* result = sys_mremap(old_addr, old_size, new_size, flags, new_address); |
| 851 MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags, | 851 MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags, |
| 852 new_address); | 852 new_address); |
| 853 return result; | 853 return result; |
| 854 } | 854 } |
| 855 | 855 |
| 856 // libc's version: | 856 // libc's version: |
| 857 extern "C" void* __sbrk(ptrdiff_t increment); | 857 extern "C" void* __sbrk(std::ptrdiff_t increment); |
| 858 | 858 |
| 859 extern "C" void* sbrk(ptrdiff_t increment) __THROW { | 859 extern "C" void* sbrk(std::ptrdiff_t increment) __THROW { |
| 860 MallocHook::InvokePreSbrkHook(increment); | 860 MallocHook::InvokePreSbrkHook(increment); |
| 861 void *result = __sbrk(increment); | 861 void *result = __sbrk(increment); |
| 862 MallocHook::InvokeSbrkHook(result, increment); | 862 MallocHook::InvokeSbrkHook(result, increment); |
| 863 return result; | 863 return result; |
| 864 } | 864 } |
| 865 | 865 |
| 866 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, | 866 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, |
| 867 int flags, int fd, off_t offset) { | 867 int flags, int fd, off_t offset) { |
| 868 void* result; | 868 void* result; |
| 869 if (!MallocHook::InvokeMmapReplacement( | 869 if (!MallocHook::InvokeMmapReplacement( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 897 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { | 897 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { |
| 898 int result; | 898 int result; |
| 899 if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) { | 899 if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) { |
| 900 result = munmap(start, length); | 900 result = munmap(start, length); |
| 901 } | 901 } |
| 902 return result; | 902 return result; |
| 903 } | 903 } |
| 904 | 904 |
| 905 #endif // defined(__linux) && | 905 #endif // defined(__linux) && |
| 906 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) | 906 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) |
| OLD | NEW |