OLD | NEW |
1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2016 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "syzygy/agent/common/stack_walker_x86.h" | 15 #include "syzygy/agent/common/stack_walker.h" |
16 | 16 |
17 #include <windows.h> | 17 #include <windows.h> |
18 #include <winnt.h> | |
19 | 18 |
| 19 #ifndef _WIN64 |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "syzygy/agent/common/stack_capture.h" | 21 #include "syzygy/agent/common/stack_capture.h" |
22 #include "syzygy/common/align.h" | 22 #include "syzygy/common/align.h" |
| 23 #endif |
23 | 24 |
24 namespace agent { | 25 namespace agent { |
25 namespace common { | 26 namespace common { |
26 | 27 |
| 28 #ifndef _WIN64 |
| 29 |
27 namespace { | 30 namespace { |
28 | 31 |
29 static size_t kPointerSize = sizeof(void*); | 32 static size_t kPointerSize = sizeof(void*); |
30 | 33 |
31 __declspec(naked) void* GetEbp() { | 34 __declspec(naked) void* GetEbp() { |
32 __asm { | 35 __asm { |
33 mov eax, ebp | 36 mov eax, ebp |
34 ret | 37 ret |
35 } | 38 } |
36 } | 39 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // The next frame pointer must be at least a full frame beyond the current | 92 // The next frame pointer must be at least a full frame beyond the current |
90 // frame. Checking that the next frame lies within the stack is done by | 93 // frame. Checking that the next frame lies within the stack is done by |
91 // 'FrameHasValidReturnAddress' before it gets read. | 94 // 'FrameHasValidReturnAddress' before it gets read. |
92 if (frame + 1 > frame->next_frame) | 95 if (frame + 1 > frame->next_frame) |
93 return false; | 96 return false; |
94 return true; | 97 return true; |
95 } | 98 } |
96 | 99 |
97 } // namespace | 100 } // namespace |
98 | 101 |
99 size_t __declspec(noinline) WalkStack(size_t bottom_frames_to_skip, | 102 size_t __declspec(noinline) WalkStack(uint32_t bottom_frames_to_skip, |
100 size_t max_frame_count, | 103 uint32_t max_frame_count, |
101 void** frames, | 104 void** frames, |
102 StackId* absolute_stack_id) { | 105 StackId* absolute_stack_id) { |
103 // Get the stack extents. | 106 // Get the stack extents. |
104 // The first thing in the TEB is actually the TIB. | 107 // The first thing in the TEB is actually the TIB. |
105 // http://www.nirsoft.net/kernel_struct/vista/TEB.html | 108 // http://www.nirsoft.net/kernel_struct/vista/TEB.html |
106 NT_TIB* tib = reinterpret_cast<NT_TIB*>(NtCurrentTeb()); | 109 NT_TIB* tib = reinterpret_cast<NT_TIB*>(NtCurrentTeb()); |
107 void* stack_bottom = tib->StackLimit; // Lower address. | 110 void* stack_bottom = tib->StackLimit; // Lower address. |
108 void* stack_top = tib->StackBase; // Higher address. | 111 void* stack_top = tib->StackBase; // Higher address. |
109 | 112 |
110 // Ensure that the stack extents make sense, and bail early if they | 113 // Ensure that the stack extents make sense, and bail early if they |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 178 |
176 current_frame = current_frame->next_frame; | 179 current_frame = current_frame->next_frame; |
177 } | 180 } |
178 | 181 |
179 *absolute_stack_id = | 182 *absolute_stack_id = |
180 StackCapture::FinalizeStackId(*absolute_stack_id, num_frames); | 183 StackCapture::FinalizeStackId(*absolute_stack_id, num_frames); |
181 | 184 |
182 return num_frames; | 185 return num_frames; |
183 } | 186 } |
184 | 187 |
| 188 #else |
| 189 |
| 190 size_t __declspec(noinline) WalkStack(uint32_t bottom_frames_to_skip, |
| 191 uint32_t max_frame_count, |
| 192 void** frames, |
| 193 StackId* absolute_stack_id) { |
| 194 // Skip one more frame for call of this function |
| 195 return CaptureStackBackTrace(bottom_frames_to_skip + 1, |
| 196 max_frame_count, |
| 197 frames, |
| 198 reinterpret_cast<PDWORD>(absolute_stack_id)); |
| 199 } |
| 200 |
| 201 #endif // !defined _WIN64 |
| 202 |
185 } // namespace common | 203 } // namespace common |
186 } // namespace agent | 204 } // namespace agent |
OLD | NEW |