| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/sampler.h" | 5 #include "src/sampler.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX && !V8_OS_CYGWIN | 7 #if V8_OS_POSIX && !V8_OS_CYGWIN |
| 8 | 8 |
| 9 #define USE_SIGNALS | 9 #define USE_SIGNALS |
| 10 | 10 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 bool IsSamePage(byte* ptr1, byte* ptr2) { | 177 bool IsSamePage(byte* ptr1, byte* ptr2) { |
| 178 const uint32_t kPageSize = 4096; | 178 const uint32_t kPageSize = 4096; |
| 179 uintptr_t mask = ~static_cast<uintptr_t>(kPageSize - 1); | 179 uintptr_t mask = ~static_cast<uintptr_t>(kPageSize - 1); |
| 180 return (reinterpret_cast<uintptr_t>(ptr1) & mask) == | 180 return (reinterpret_cast<uintptr_t>(ptr1) & mask) == |
| 181 (reinterpret_cast<uintptr_t>(ptr2) & mask); | 181 (reinterpret_cast<uintptr_t>(ptr2) & mask); |
| 182 } | 182 } |
| 183 | 183 |
| 184 | 184 |
| 185 // Check if the code at specified address could potentially be a | 185 // Check if the code at specified address could potentially be a |
| 186 // frame setup code. | 186 // frame setup code. |
| 187 DISABLE_ASAN bool IsNoFrameRegion(Address address) { | 187 bool IsNoFrameRegion(Address address) { |
| 188 struct Pattern { | 188 struct Pattern { |
| 189 int bytes_count; | 189 int bytes_count; |
| 190 byte bytes[8]; | 190 byte bytes[8]; |
| 191 int offsets[4]; | 191 int offsets[4]; |
| 192 }; | 192 }; |
| 193 byte* pc = reinterpret_cast<byte*>(address); | 193 byte* pc = reinterpret_cast<byte*>(address); |
| 194 static Pattern patterns[] = { | 194 static Pattern patterns[] = { |
| 195 #if V8_HOST_ARCH_IA32 | 195 #if V8_HOST_ARCH_IA32 |
| 196 // push %ebp | 196 // push %ebp |
| 197 // mov %esp,%ebp | 197 // mov %esp,%ebp |
| (...skipping 14 matching lines...) Expand all Loading... |
| 212 // popq %rbp | 212 // popq %rbp |
| 213 // ret | 213 // ret |
| 214 {2, {0x5d, 0xc3}, {0, 1, -1}}, | 214 {2, {0x5d, 0xc3}, {0, 1, -1}}, |
| 215 #endif | 215 #endif |
| 216 {0, {}, {}} | 216 {0, {}, {}} |
| 217 }; | 217 }; |
| 218 for (Pattern* pattern = patterns; pattern->bytes_count; ++pattern) { | 218 for (Pattern* pattern = patterns; pattern->bytes_count; ++pattern) { |
| 219 for (int* offset_ptr = pattern->offsets; *offset_ptr != -1; ++offset_ptr) { | 219 for (int* offset_ptr = pattern->offsets; *offset_ptr != -1; ++offset_ptr) { |
| 220 int offset = *offset_ptr; | 220 int offset = *offset_ptr; |
| 221 if (!offset || IsSamePage(pc, pc - offset)) { | 221 if (!offset || IsSamePage(pc, pc - offset)) { |
| 222 MSAN_MEMORY_IS_INITIALIZED(pc - offset, pattern->bytes_count); |
| 222 if (!memcmp(pc - offset, pattern->bytes, pattern->bytes_count)) | 223 if (!memcmp(pc - offset, pattern->bytes, pattern->bytes_count)) |
| 223 return true; | 224 return true; |
| 224 } else { | 225 } else { |
| 225 // It is not safe to examine bytes on another page as it might not be | 226 // It is not safe to examine bytes on another page as it might not be |
| 226 // allocated thus causing a SEGFAULT. | 227 // allocated thus causing a SEGFAULT. |
| 227 // Check the pattern part that's on the same page and | 228 // Check the pattern part that's on the same page and |
| 228 // pessimistically assume it could be the entire pattern match. | 229 // pessimistically assume it could be the entire pattern match. |
| 230 MSAN_MEMORY_IS_INITIALIZED(pc, pattern->bytes_count - offset); |
| 229 if (!memcmp(pc, pattern->bytes + offset, pattern->bytes_count - offset)) | 231 if (!memcmp(pc, pattern->bytes + offset, pattern->bytes_count - offset)) |
| 230 return true; | 232 return true; |
| 231 } | 233 } |
| 232 } | 234 } |
| 233 } | 235 } |
| 234 return false; | 236 return false; |
| 235 } | 237 } |
| 236 | 238 |
| 237 } // namespace | 239 } // namespace |
| 238 | 240 |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 SampleStack(state); | 836 SampleStack(state); |
| 835 } | 837 } |
| 836 ResumeThread(profiled_thread); | 838 ResumeThread(profiled_thread); |
| 837 } | 839 } |
| 838 | 840 |
| 839 #endif // USE_SIGNALS | 841 #endif // USE_SIGNALS |
| 840 | 842 |
| 841 | 843 |
| 842 } // namespace internal | 844 } // namespace internal |
| 843 } // namespace v8 | 845 } // namespace v8 |
| OLD | NEW |