| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // __THROW is defined in glibc systems. It means, counter-intuitively, | 65 // __THROW is defined in glibc systems. It means, counter-intuitively, |
| 66 // "This function will never throw an exception." It's an optional | 66 // "This function will never throw an exception." It's an optional |
| 67 // optimization tool, but we may need to use it to match glibc prototypes. | 67 // optimization tool, but we may need to use it to match glibc prototypes. |
| 68 #ifndef __THROW // I guess we're not on a glibc system | 68 #ifndef __THROW // I guess we're not on a glibc system |
| 69 # define __THROW // __THROW is just an optimization, so ok to make it "" | 69 # define __THROW // __THROW is just an optimization, so ok to make it "" |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 using std::copy; | 72 using std::copy; |
| 73 | 73 |
| 74 DECLARE_bool(deep_heap_profile); |
| 75 |
| 74 | 76 |
| 75 // Declaration of default weak initialization function, that can be overridden | 77 // Declaration of default weak initialization function, that can be overridden |
| 76 // by linking-in a strong definition (as heap-checker.cc does). This is | 78 // by linking-in a strong definition (as heap-checker.cc does). This is |
| 77 // extern "C" so that it doesn't trigger gold's --detect-odr-violations warning, | 79 // extern "C" so that it doesn't trigger gold's --detect-odr-violations warning, |
| 78 // which only looks at C++ symbols. | 80 // which only looks at C++ symbols. |
| 79 // | 81 // |
| 80 // This function is declared here as weak, and defined later, rather than a more | 82 // This function is declared here as weak, and defined later, rather than a more |
| 81 // straightforward simple weak definition, as a workround for an icc compiler | 83 // straightforward simple weak definition, as a workround for an icc compiler |
| 82 // issue ((Intel reference 290819). This issue causes icc to resolve weak | 84 // issue ((Intel reference 290819). This issue causes icc to resolve weak |
| 83 // symbols too early, at compile rather than link time. By declaring it (weak) | 85 // symbols too early, at compile rather than link time. By declaring it (weak) |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // and 3 is to account for some hook daisy chaining. | 672 // and 3 is to account for some hook daisy chaining. |
| 671 static const int kStackSize = kMaxSkip + 1; | 673 static const int kStackSize = kMaxSkip + 1; |
| 672 void* stack[kStackSize]; | 674 void* stack[kStackSize]; |
| 673 int depth = GetStackTrace(stack, kStackSize, 1); // skip this function frame | 675 int depth = GetStackTrace(stack, kStackSize, 1); // skip this function frame |
| 674 if (depth == 0) // silenty propagate cases when GetStackTrace does not work | 676 if (depth == 0) // silenty propagate cases when GetStackTrace does not work |
| 675 return 0; | 677 return 0; |
| 676 for (int i = 0; i < depth; ++i) { // stack[0] is our immediate caller | 678 for (int i = 0; i < depth; ++i) { // stack[0] is our immediate caller |
| 677 if (InHookCaller(stack[i])) { | 679 if (InHookCaller(stack[i])) { |
| 678 RAW_VLOG(10, "Found hooked allocator at %d: %p <- %p", | 680 RAW_VLOG(10, "Found hooked allocator at %d: %p <- %p", |
| 679 i, stack[i], stack[i+1]); | 681 i, stack[i], stack[i+1]); |
| 680 i += 1; // skip hook caller frame | 682 if (!FLAGS_deep_heap_profile) { |
| 683 i += 1; // skip hook caller frame |
| 684 } |
| 681 depth -= i; // correct depth | 685 depth -= i; // correct depth |
| 682 if (depth > max_depth) depth = max_depth; | 686 if (depth > max_depth) depth = max_depth; |
| 683 copy(stack + i, stack + i + depth, result); | 687 copy(stack + i, stack + i + depth, result); |
| 684 if (depth < max_depth && depth + i == kStackSize) { | 688 if (depth < max_depth && depth + i == kStackSize) { |
| 685 // get frames for the missing depth | 689 // get frames for the missing depth |
| 686 depth += | 690 depth += |
| 687 GetStackTrace(result + depth, max_depth - depth, 1 + kStackSize); | 691 GetStackTrace(result + depth, max_depth - depth, 1 + kStackSize); |
| 688 } | 692 } |
| 689 return depth; | 693 return depth; |
| 690 } | 694 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { | 901 /*static*/int MallocHook::UnhookedMUnmap(void *start, size_t length) { |
| 898 int result; | 902 int result; |
| 899 if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) { | 903 if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) { |
| 900 result = munmap(start, length); | 904 result = munmap(start, length); |
| 901 } | 905 } |
| 902 return result; | 906 return result; |
| 903 } | 907 } |
| 904 | 908 |
| 905 #endif // defined(__linux) && | 909 #endif // defined(__linux) && |
| 906 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) | 910 // (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) |
| OLD | NEW |