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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 : is_initialized_(false) { | 466 : is_initialized_(false) { |
467 Init(); | 467 Init(); |
468 } | 468 } |
469 | 469 |
470 ~SandboxSymbolizeHelper() { | 470 ~SandboxSymbolizeHelper() { |
471 UnregisterCallback(); | 471 UnregisterCallback(); |
472 CloseObjectFiles(); | 472 CloseObjectFiles(); |
473 } | 473 } |
474 | 474 |
475 // Returns a O_RDONLY file descriptor for |file_path| if it was opened | 475 // Returns a O_RDONLY file descriptor for |file_path| if it was opened |
476 // sucessfully during the initialization. The file is repositioned at | 476 // successfully during the initialization. The file is repositioned at |
477 // offset 0. | 477 // offset 0. |
478 // IMPORTANT: This function must be async-signal-safe because it can be | 478 // IMPORTANT: This function must be async-signal-safe because it can be |
479 // called from a signal handler (symbolizing stack frames for a crash). | 479 // called from a signal handler (symbolizing stack frames for a crash). |
480 int GetFileDescriptor(const char* file_path) { | 480 int GetFileDescriptor(const char* file_path) { |
481 int fd = -1; | 481 int fd = -1; |
482 | 482 |
483 #if !defined(OFFICIAL_BUILD) | 483 #if !defined(OFFICIAL_BUILD) |
484 if (file_path) { | 484 if (file_path) { |
485 // The assumption here is that iterating over std::map<std::string, int> | 485 // The assumption here is that iterating over std::map<std::string, int> |
486 // using a const_iterator does not allocate dynamic memory, hense it is | 486 // using a const_iterator does not allocate dynamic memory, hense it is |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 #if !defined(__UCLIBC__) | 734 #if !defined(__UCLIBC__) |
735 void StackTrace::OutputToStream(std::ostream* os) const { | 735 void StackTrace::OutputToStream(std::ostream* os) const { |
736 StreamBacktraceOutputHandler handler(os); | 736 StreamBacktraceOutputHandler handler(os); |
737 ProcessBacktrace(trace_, count_, &handler); | 737 ProcessBacktrace(trace_, count_, &handler); |
738 } | 738 } |
739 #endif | 739 #endif |
740 | 740 |
741 namespace internal { | 741 namespace internal { |
742 | 742 |
743 // NOTE: code from sandbox/linux/seccomp-bpf/demo.cc. | 743 // NOTE: code from sandbox/linux/seccomp-bpf/demo.cc. |
744 char *itoa_r(intptr_t i, char *buf, size_t sz, int base, size_t padding) { | 744 char* itoa_r(intptr_t i, char* buf, size_t sz, int base, size_t padding) { |
745 // Make sure we can write at least one NUL byte. | 745 // Make sure we can write at least one NUL byte. |
746 size_t n = 1; | 746 size_t n = 1; |
747 if (n > sz) | 747 if (n > sz) |
748 return NULL; | 748 return NULL; |
749 | 749 |
750 if (base < 2 || base > 16) { | 750 if (base < 2 || base > 16) { |
751 buf[0] = '\000'; | 751 buf[0] = '\000'; |
752 return NULL; | 752 return NULL; |
753 } | 753 } |
754 | 754 |
755 char *start = buf; | 755 char* start = buf; |
756 | 756 |
757 uintptr_t j = i; | 757 uintptr_t j = i; |
758 | 758 |
759 // Handle negative numbers (only for base 10). | 759 // Handle negative numbers (only for base 10). |
760 if (i < 0 && base == 10) { | 760 if (i < 0 && base == 10) { |
761 // This does "j = -i" while avoiding integer overflow. | 761 // This does "j = -i" while avoiding integer overflow. |
762 j = static_cast<uintptr_t>(-(i + 1)) + 1; | 762 j = static_cast<uintptr_t>(-(i + 1)) + 1; |
763 | 763 |
764 // Make sure we can write the '-' character. | 764 // Make sure we can write the '-' character. |
765 if (++n > sz) { | 765 if (++n > sz) { |
766 buf[0] = '\000'; | 766 buf[0] = '\000'; |
767 return NULL; | 767 return NULL; |
768 } | 768 } |
769 *start++ = '-'; | 769 *start++ = '-'; |
770 } | 770 } |
771 | 771 |
772 // Loop until we have converted the entire number. Output at least one | 772 // Loop until we have converted the entire number. Output at least one |
773 // character (i.e. '0'). | 773 // character (i.e. '0'). |
774 char *ptr = start; | 774 char* ptr = start; |
775 do { | 775 do { |
776 // Make sure there is still enough space left in our output buffer. | 776 // Make sure there is still enough space left in our output buffer. |
777 if (++n > sz) { | 777 if (++n > sz) { |
778 buf[0] = '\000'; | 778 buf[0] = '\000'; |
779 return NULL; | 779 return NULL; |
780 } | 780 } |
781 | 781 |
782 // Output the next digit. | 782 // Output the next digit. |
783 *ptr++ = "0123456789abcdef"[j % base]; | 783 *ptr++ = "0123456789abcdef"[j % base]; |
784 j /= base; | 784 j /= base; |
(...skipping 14 matching lines...) Expand all Loading... |
799 *ptr = *start; | 799 *ptr = *start; |
800 *start++ = ch; | 800 *start++ = ch; |
801 } | 801 } |
802 return buf; | 802 return buf; |
803 } | 803 } |
804 | 804 |
805 } // namespace internal | 805 } // namespace internal |
806 | 806 |
807 } // namespace debug | 807 } // namespace debug |
808 } // namespace base | 808 } // namespace base |
OLD | NEW |