Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: base/debug/stack_trace.h

Issue 1975393002: Check stack pointer to be inside stack when unwinding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix renderer deadlock on Linux Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/debug/stack_trace.cc » ('j') | base/debug/stack_trace.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef BASE_DEBUG_STACK_TRACE_H_ 5 #ifndef BASE_DEBUG_STACK_TRACE_H_
6 #define BASE_DEBUG_STACK_TRACE_H_ 6 #define BASE_DEBUG_STACK_TRACE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iosfwd> 10 #include <iosfwd>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // doesn't give much more information. 95 // doesn't give much more information.
96 static const int kMaxTraces = 62; 96 static const int kMaxTraces = 62;
97 97
98 void* trace_[kMaxTraces]; 98 void* trace_[kMaxTraces];
99 99
100 // The number of valid frames in |trace_|. 100 // The number of valid frames in |trace_|.
101 size_t count_; 101 size_t count_;
102 }; 102 };
103 103
104 #if HAVE_TRACE_STACK_FRAME_POINTERS 104 #if HAVE_TRACE_STACK_FRAME_POINTERS
105
106 // Used by TraceStackFramePointers() to store info about the stack.
107 struct BASE_EXPORT PerThreadStackInfo {
108 PerThreadStackInfo();
109 uintptr_t start_address;
110 };
111
105 // Traces the stack by using frame pointers. This function is faster but less 112 // Traces the stack by using frame pointers. This function is faster but less
106 // reliable than StackTrace. It should work for debug and profiling builds, 113 // reliable than StackTrace. It should work for debug and profiling builds,
107 // but not for release builds (although there are some exceptions). 114 // but not for release builds (although there are some exceptions).
108 // 115 //
109 // Writes at most |max_depth| frames (instruction pointers) into |out_trace| 116 // Writes at most |max_depth| frames (instruction pointers) into |out_trace|
110 // after skipping |skip_initial| frames. Note that the function itself is not 117 // after skipping |skip_initial| frames. Note that the function itself is not
111 // added to the trace so |skip_initial| should be 0 in most cases. 118 // added to the trace so |skip_initial| should be 0 in most cases.
112 // Returns number of frames written. 119 // Returns number of frames written.
113 BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace, 120 //
114 size_t max_depth, 121 // Note on |stack_info|. By default the function relies on heuristics to check
115 size_t skip_initial); 122 // whether a stack pointer is within the stack before dereferencing it. That
123 // works, but is not very reliable. Proper way to check that is to ask the OS
124 // for the stack info, but that is costly thing to do on each call.
125 // This is what |stack_info| is for - it provides a place where function
126 // caches info about the stack. Put it in your per-thread data structure, pass
127 // into the function, and voila - stack pointers are properly checked without
128 // any runtime overhead.
129 BASE_EXPORT size_t TraceStackFramePointers(
130 const void** out_trace,
131 size_t max_depth,
132 size_t skip_initial,
133 PerThreadStackInfo* stack_info = nullptr);
134
116 #endif // HAVE_TRACE_STACK_FRAME_POINTERS 135 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
117 136
118 namespace internal { 137 namespace internal {
119 138
120 #if defined(OS_POSIX) && !defined(OS_ANDROID) 139 #if defined(OS_POSIX) && !defined(OS_ANDROID)
121 // POSIX doesn't define any async-signal safe function for converting 140 // POSIX doesn't define any async-signal safe function for converting
122 // an integer to ASCII. We'll have to define our own version. 141 // an integer to ASCII. We'll have to define our own version.
123 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the 142 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the
124 // conversion was successful or NULL otherwise. It never writes more than "sz" 143 // conversion was successful or NULL otherwise. It never writes more than "sz"
125 // bytes. Output will be truncated as needed, and a NUL character is always 144 // bytes. Output will be truncated as needed, and a NUL character is always
126 // appended. 145 // appended.
127 BASE_EXPORT char *itoa_r(intptr_t i, 146 BASE_EXPORT char *itoa_r(intptr_t i,
128 char *buf, 147 char *buf,
129 size_t sz, 148 size_t sz,
130 int base, 149 int base,
131 size_t padding); 150 size_t padding);
132 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) 151 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
133 152
134 } // namespace internal 153 } // namespace internal
135 154
136 } // namespace debug 155 } // namespace debug
137 } // namespace base 156 } // namespace base
138 157
139 #endif // BASE_DEBUG_STACK_TRACE_H_ 158 #endif // BASE_DEBUG_STACK_TRACE_H_
OLDNEW
« no previous file with comments | « no previous file | base/debug/stack_trace.cc » ('j') | base/debug/stack_trace.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698