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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 ATTRIBUTE_WEAK | 95 ATTRIBUTE_WEAK |
96 extern void InitialMallocHook_MMap(const void* result, | 96 extern void InitialMallocHook_MMap(const void* result, |
97 const void* start, | 97 const void* start, |
98 size_t size, | 98 size_t size, |
99 int protection, | 99 int protection, |
100 int flags, | 100 int flags, |
101 int fd, | 101 int fd, |
102 off_t offset); | 102 off_t offset); |
103 | 103 |
104 ATTRIBUTE_WEAK | 104 ATTRIBUTE_WEAK |
105 extern void InitialMallocHook_PreSbrk(ptrdiff_t increment); | 105 extern void InitialMallocHook_PreSbrk(std::ptrdiff_t increment); |
106 | 106 |
107 ATTRIBUTE_WEAK | 107 ATTRIBUTE_WEAK |
108 extern void InitialMallocHook_Sbrk(const void* result, ptrdiff_t increment); | 108 extern void InitialMallocHook_Sbrk(const void* result, std::ptrdiff_t increment)
; |
109 | 109 |
110 namespace base { namespace internal { | 110 namespace base { namespace internal { |
111 template<typename PtrT> | 111 template<typename PtrT> |
112 PtrT AtomicPtr<PtrT>::Exchange(PtrT new_val) { | 112 PtrT AtomicPtr<PtrT>::Exchange(PtrT new_val) { |
113 base::subtle::MemoryBarrier(); // Release semantics. | 113 base::subtle::MemoryBarrier(); // Release semantics. |
114 // Depending on the system, NoBarrier_AtomicExchange(AtomicWord*) | 114 // Depending on the system, NoBarrier_AtomicExchange(AtomicWord*) |
115 // may have been defined to return an AtomicWord, Atomic32, or | 115 // may have been defined to return an AtomicWord, Atomic32, or |
116 // Atomic64. We hide that implementation detail here with an | 116 // Atomic64. We hide that implementation detail here with an |
117 // explicit cast. This prevents MSVC 2005, at least, from complaining. | 117 // explicit cast. This prevents MSVC 2005, at least, from complaining. |
118 PtrT old_val = reinterpret_cast<PtrT>(static_cast<AtomicWord>( | 118 PtrT old_val = reinterpret_cast<PtrT>(static_cast<AtomicWord>( |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 const void* start, | 233 const void* start, |
234 size_t size, | 234 size_t size, |
235 int protection, | 235 int protection, |
236 int flags, | 236 int flags, |
237 int fd, | 237 int fd, |
238 off_t offset) { | 238 off_t offset) { |
239 if (MallocHook::GetMmapHook() == &InitialMallocHook_MMap) | 239 if (MallocHook::GetMmapHook() == &InitialMallocHook_MMap) |
240 MallocHook::SetMmapHook(NULL); | 240 MallocHook::SetMmapHook(NULL); |
241 } | 241 } |
242 | 242 |
243 void InitialMallocHook_PreSbrk(ptrdiff_t increment) { | 243 void InitialMallocHook_PreSbrk(std::ptrdiff_t increment) { |
244 if (MallocHook::GetPreSbrkHook() == &InitialMallocHook_PreSbrk) | 244 if (MallocHook::GetPreSbrkHook() == &InitialMallocHook_PreSbrk) |
245 MallocHook::SetPreSbrkHook(NULL); | 245 MallocHook::SetPreSbrkHook(NULL); |
246 } | 246 } |
247 | 247 |
248 void InitialMallocHook_Sbrk(const void* result, ptrdiff_t increment) { | 248 void InitialMallocHook_Sbrk(const void* result, std::ptrdiff_t increment) { |
249 if (MallocHook::GetSbrkHook() == &InitialMallocHook_Sbrk) | 249 if (MallocHook::GetSbrkHook() == &InitialMallocHook_Sbrk) |
250 MallocHook::SetSbrkHook(NULL); | 250 MallocHook::SetSbrkHook(NULL); |
251 } | 251 } |
252 | 252 |
253 DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc); | 253 DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc); |
254 DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc); | 254 DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc); |
255 // actual functions are in debugallocation.cc or tcmalloc.cc | 255 // actual functions are in debugallocation.cc or tcmalloc.cc |
256 DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook); | 256 DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook); |
257 DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook); | 257 DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook); |
258 // actual functions are in this file, malloc_hook.cc, and low_level_alloc.cc | 258 // actual functions are in this file, malloc_hook.cc, and low_level_alloc.cc |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 int fd, __off64_t offset ) __THROW | 442 int fd, __off64_t offset ) __THROW |
443 ATTRIBUTE_SECTION(malloc_hook); | 443 ATTRIBUTE_SECTION(malloc_hook); |
444 void* mmap(void *start, size_t length,int prot, int flags, | 444 void* mmap(void *start, size_t length,int prot, int flags, |
445 int fd, off_t offset) __THROW | 445 int fd, off_t offset) __THROW |
446 ATTRIBUTE_SECTION(malloc_hook); | 446 ATTRIBUTE_SECTION(malloc_hook); |
447 int munmap(void* start, size_t length) __THROW | 447 int munmap(void* start, size_t length) __THROW |
448 ATTRIBUTE_SECTION(malloc_hook); | 448 ATTRIBUTE_SECTION(malloc_hook); |
449 void* mremap(void* old_addr, size_t old_size, size_t new_size, | 449 void* mremap(void* old_addr, size_t old_size, size_t new_size, |
450 int flags, ...) __THROW | 450 int flags, ...) __THROW |
451 ATTRIBUTE_SECTION(malloc_hook); | 451 ATTRIBUTE_SECTION(malloc_hook); |
452 void* sbrk(ptrdiff_t increment) __THROW | 452 void* sbrk(std::ptrdiff_t increment) __THROW |
453 ATTRIBUTE_SECTION(malloc_hook); | 453 ATTRIBUTE_SECTION(malloc_hook); |
454 } | 454 } |
455 | 455 |
456 extern "C" void* mmap64(void *start, size_t length, int prot, int flags, | 456 extern "C" void* mmap64(void *start, size_t length, int prot, int flags, |
457 int fd, __off64_t offset) __THROW { | 457 int fd, __off64_t offset) __THROW { |
458 MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset); | 458 MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset); |
459 void *result = do_mmap64(start, length, prot, flags, fd, offset); | 459 void *result = do_mmap64(start, length, prot, flags, fd, offset); |
460 MallocHook::InvokeMmapHook(result, start, length, prot, flags, fd, offset); | 460 MallocHook::InvokeMmapHook(result, start, length, prot, flags, fd, offset); |
461 return result; | 461 return result; |
462 } | 462 } |
(...skipping 22 matching lines...) Expand all Loading... |
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(std::ptrdiff_t increment); |
496 | 496 |
497 extern "C" void* sbrk(ptrdiff_t increment) __THROW { | 497 extern "C" void* sbrk(std::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 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, | 504 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, |
505 int flags, int fd, off_t offset) { | 505 int flags, int fd, off_t offset) { |
506 return do_mmap64(start, length, prot, flags, fd, offset); | 506 return do_mmap64(start, length, prot, flags, fd, offset); |
507 } | 507 } |
508 | 508 |
509 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { | 509 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { |
510 return sys_munmap(start, length); | 510 return sys_munmap(start, length); |
511 } | 511 } |
512 | 512 |
513 #else // defined(__linux) && | 513 #else // defined(__linux) && |
514 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) | 514 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) |
515 | 515 |
516 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, | 516 /*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot, |
517 int flags, int fd, off_t offset) { | 517 int flags, int fd, off_t offset) { |
518 return mmap(start, length, prot, flags, fd, offset); | 518 return mmap(start, length, prot, flags, fd, offset); |
519 } | 519 } |
520 | 520 |
521 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { | 521 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { |
522 return munmap(start, length); | 522 return munmap(start, length); |
523 } | 523 } |
524 | 524 |
525 #endif // defined(__linux) && | 525 #endif // defined(__linux) && |
526 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) | 526 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) |
OLD | NEW |