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 #ifndef SYZYGY_AGENT_COMMON_STACK_WALKER_H_ |
| 16 #define SYZYGY_AGENT_COMMON_STACK_WALKER_H_ |
| 17 #include "syzygy/common/asan_parameters.h" |
| 18 |
15 // Defines an X86 stack walker for standard frames that contain a saved EBP | 19 // Defines an X86 stack walker for standard frames that contain a saved EBP |
16 // value at the top, generated by the common preamble: | 20 // value at the top, generated by the common preamble: |
17 // | 21 // |
18 // push ebp // Save the previous EBP. ESP now points at the saved EBP. | 22 // push ebp // Save the previous EBP. ESP now points at the saved EBP. |
19 // mov ebp, esp // EBP now points at the saved EBP. | 23 // mov ebp, esp // EBP now points at the saved EBP. |
20 // | 24 // |
21 // The algorithms expects the stack to be laid out as follows: | 25 // The algorithms expects the stack to be laid out as follows: |
22 // | 26 // |
23 // +-------------+ <-- top of stack | 27 // +-------------+ <-- top of stack |
24 // | ...data.... | | 28 // | ...data.... | |
(...skipping 26 matching lines...) Expand all Loading... |
51 // 4-byte aligned. | 55 // 4-byte aligned. |
52 // - There must be the content of the saved EBP and a return pointer between | 56 // - There must be the content of the saved EBP and a return pointer between |
53 // any two successive EBP values, so they must be at least 8 bytes apart. | 57 // any two successive EBP values, so they must be at least 8 bytes apart. |
54 // - The frames must be entirely contained within the stack itself, so strictly | 58 // - The frames must be entirely contained within the stack itself, so strictly |
55 // between the known bottom and top of the stack. | 59 // between the known bottom and top of the stack. |
56 // | 60 // |
57 // The algorithm walks the stack as far as it can while the above invariants | 61 // The algorithm walks the stack as far as it can while the above invariants |
58 // hold true, saving the value of the return pointer for each valid frame | 62 // hold true, saving the value of the return pointer for each valid frame |
59 // encountered. Note that it can quickly derail if frame pointer optimization | 63 // encountered. Note that it can quickly derail if frame pointer optimization |
60 // is enabled, or at any frame that uses a non-standard layout. | 64 // is enabled, or at any frame that uses a non-standard layout. |
| 65 // |
| 66 // All the information above is valid for X86. As for Win64, the only major |
| 67 // difference is the register names and sizes, all the other principles |
| 68 // still apply. |
61 | 69 |
62 #ifndef SYZYGY_AGENT_COMMON_STACK_WALKER_X86_H_ | |
63 #define SYZYGY_AGENT_COMMON_STACK_WALKER_X86_H_ | |
64 | |
65 #include "syzygy/common/asan_parameters.h" | |
66 | 70 |
67 namespace agent { | 71 namespace agent { |
68 namespace common { | 72 namespace common { |
69 | 73 |
70 using StackId = ::common::AsanStackId; | 74 using StackId = ::common::AsanStackId; |
71 | 75 |
72 // Heuristically walks the current stack. Does not consider its own stack | 76 // Heuristically walks the current stack. Does not consider its own stack |
73 // frame. Frames are expected to have a standard layout with the top of the | 77 // frame. Frames are expected to have a standard layout with the top of the |
74 // frame being a saved frame pointer, and the bottom of a frame being a return | 78 // frame being a saved frame pointer, and the bottom of a frame being a return |
75 // address. | 79 // address. |
76 // @param bottom_frames_to_skip The number of frames to skip from the bottom | 80 // @param bottom_frames_to_skip The number of frames to skip from the bottom |
77 // of the stack. | 81 // of the stack. |
78 // @param max_frame_count The maximum number of frames that can be written to | 82 // @param max_frame_count The maximum number of frames that can be written to |
79 // @p frames. | 83 // @p frames. |
80 // @param frames The array to be populated with the computed frames. | 84 // @param frames The array to be populated with the computed frames. |
81 // @param absolute_stack_id Pointer to the stack ID that will be calculated as | 85 // @param absolute_stack_id Pointer to the stack ID that will be calculated as |
82 // we are walking the stack. | 86 // we are walking the stack. |
83 // @returns the number of frames successfully walked and stored in @p frames. | 87 // @returns the number of frames successfully walked and stored in @p frames. |
84 size_t WalkStack(size_t bottom_frames_to_skip, | 88 size_t WalkStack(uint32_t bottom_frames_to_skip, |
85 size_t max_frame_count, | 89 uint32_t max_frame_count, |
86 void** frames, | 90 void** frames, |
87 StackId* absolute_stack_id); | 91 StackId* absolute_stack_id); |
88 | 92 |
| 93 #ifndef _WIN64 |
89 // Implementation of WalkStack, with explicitly provided @p current_ebp, | 94 // Implementation of WalkStack, with explicitly provided @p current_ebp, |
90 // @p stack_bottom and @p stack_top. Exposed for much easier unittesting. | 95 // @p stack_bottom and @p stack_top. Exposed for much easier unittesting. |
91 // @param current_ebp The current stack frame base to start walking from. | 96 // @param current_ebp The current stack frame base to start walking from. |
92 // This must be a valid stack location from which to start walking. | 97 // This must be a valid stack location from which to start walking. |
93 // @param stack_bottom The bottom of the stack to walk. (Lower address.) | 98 // @param stack_bottom The bottom of the stack to walk. (Lower address.) |
94 // @param stack_top The top of the stack to walk. (Higher address.) | 99 // @param stack_top The top of the stack to walk. (Higher address.) |
95 // @param bottom_frames_to_skip The number of frames to skip from the bottom | 100 // @param bottom_frames_to_skip The number of frames to skip from the bottom |
96 // of the stack. | 101 // of the stack. |
97 // @param max_frame_count The maximum number of frames that can be written to | 102 // @param max_frame_count The maximum number of frames that can be written to |
98 // @p frames. | 103 // @p frames. |
99 // @param frames The array to be populated with the computed frames. | 104 // @param frames The array to be populated with the computed frames. |
100 // @param absolute_stack_id Pointer to the stack ID that will be calculated as | 105 // @param absolute_stack_id Pointer to the stack ID that will be calculated as |
101 // we are walking the stack. | 106 // we are walking the stack. |
102 // @returns the number of frames successfully walked and stored in @p frames. | 107 // @returns the number of frames successfully walked and stored in @p frames. |
103 size_t WalkStackImpl(const void* current_ebp, | 108 size_t WalkStackImpl(const void* current_ebp, |
104 const void* stack_bottom, | 109 const void* stack_bottom, |
105 const void* stack_top, | 110 const void* stack_top, |
106 size_t bottom_frames_to_skip, | 111 uint32_t bottom_frames_to_skip, |
107 size_t max_frame_count, | 112 uint32_t max_frame_count, |
108 void** frames, | 113 void** frames, |
109 StackId* absolute_stack_id); | 114 StackId* absolute_stack_id); |
| 115 #endif // !defined _WIN64 |
110 | 116 |
111 } // namespace common | 117 } // namespace common |
112 } // namespace agent | 118 } // namespace agent |
113 | 119 |
114 #endif // SYZYGY_AGENT_COMMON_STACK_WALKER_X86_H_ | 120 #endif // SYZYGY_AGENT_COMMON_STACK_WALKER_H_ |
OLD | NEW |