OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 PrintToStderr(" <unknown> "); | 274 PrintToStderr(" <unknown> "); |
275 } | 275 } |
276 if (signal == SIGBUS || signal == SIGFPE || | 276 if (signal == SIGBUS || signal == SIGFPE || |
277 signal == SIGILL || signal == SIGSEGV) { | 277 signal == SIGILL || signal == SIGSEGV) { |
278 internal::itoa_r(reinterpret_cast<intptr_t>(info->si_addr), | 278 internal::itoa_r(reinterpret_cast<intptr_t>(info->si_addr), |
279 buf, sizeof(buf), 16, 12); | 279 buf, sizeof(buf), 16, 12); |
280 PrintToStderr(buf); | 280 PrintToStderr(buf); |
281 } | 281 } |
282 PrintToStderr("\n"); | 282 PrintToStderr("\n"); |
283 | 283 |
| 284 #if defined(CFI_ENFORCEMENT) |
| 285 if (signal == SIGILL && info->si_code == ILL_ILLOPN) { |
| 286 PrintToStderr( |
| 287 "CFI: Most likely a control flow integrity violation; for more " |
| 288 "information see:\n"); |
| 289 PrintToStderr( |
| 290 "https://www.chromium.org/developers/testing/control-flow-integrity\n"); |
| 291 } |
| 292 #endif |
| 293 |
284 debug::StackTrace().Print(); | 294 debug::StackTrace().Print(); |
285 | 295 |
286 #if defined(OS_LINUX) | 296 #if defined(OS_LINUX) |
287 #if ARCH_CPU_X86_FAMILY | 297 #if ARCH_CPU_X86_FAMILY |
288 ucontext_t* context = reinterpret_cast<ucontext_t*>(void_context); | 298 ucontext_t* context = reinterpret_cast<ucontext_t*>(void_context); |
289 const struct { | 299 const struct { |
290 const char* label; | 300 const char* label; |
291 greg_t value; | 301 greg_t value; |
292 } registers[] = { | 302 } registers[] = { |
293 #if ARCH_CPU_32_BITS | 303 #if ARCH_CPU_32_BITS |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 "ip: %x, cs: %x, ds: %x, es: %x, fs: %x, gs: %x\n", | 398 "ip: %x, cs: %x, ds: %x, es: %x, fs: %x, gs: %x\n", |
389 context->uc_mcontext->__ss.__eip, | 399 context->uc_mcontext->__ss.__eip, |
390 context->uc_mcontext->__ss.__cs, | 400 context->uc_mcontext->__ss.__cs, |
391 context->uc_mcontext->__ss.__ds, | 401 context->uc_mcontext->__ss.__ds, |
392 context->uc_mcontext->__ss.__es, | 402 context->uc_mcontext->__ss.__es, |
393 context->uc_mcontext->__ss.__fs, | 403 context->uc_mcontext->__ss.__fs, |
394 context->uc_mcontext->__ss.__gs)); | 404 context->uc_mcontext->__ss.__gs)); |
395 write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); | 405 write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); |
396 #endif // ARCH_CPU_32_BITS | 406 #endif // ARCH_CPU_32_BITS |
397 #endif // defined(OS_MACOSX) | 407 #endif // defined(OS_MACOSX) |
| 408 |
| 409 PrintToStderr("[end of stack trace]\n"); |
| 410 |
398 _exit(1); | 411 _exit(1); |
399 } | 412 } |
400 | 413 |
401 class PrintBacktraceOutputHandler : public BacktraceOutputHandler { | 414 class PrintBacktraceOutputHandler : public BacktraceOutputHandler { |
402 public: | 415 public: |
403 PrintBacktraceOutputHandler() {} | 416 PrintBacktraceOutputHandler() {} |
404 | 417 |
405 void HandleOutput(const char* output) override { | 418 void HandleOutput(const char* output) override { |
406 // NOTE: This code MUST be async-signal safe (it's used by in-process | 419 // NOTE: This code MUST be async-signal safe (it's used by in-process |
407 // stack dumping signal handler). NO malloc or stdio is allowed here. | 420 // stack dumping signal handler). NO malloc or stdio is allowed here. |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 *ptr = *start; | 838 *ptr = *start; |
826 *start++ = ch; | 839 *start++ = ch; |
827 } | 840 } |
828 return buf; | 841 return buf; |
829 } | 842 } |
830 | 843 |
831 } // namespace internal | 844 } // namespace internal |
832 | 845 |
833 } // namespace debug | 846 } // namespace debug |
834 } // namespace base | 847 } // namespace base |
OLD | NEW |