OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. 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, |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include <vector> | 25 #include <vector> |
26 | 26 |
27 #include "base/basictypes.h" | 27 #include "base/basictypes.h" |
28 #include "base/memory/scoped_ptr.h" | 28 #include "base/memory/scoped_ptr.h" |
29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
30 #include "util/mach/task_memory.h" | 30 #include "util/mach/task_memory.h" |
31 #include "util/misc/initialization_state_dcheck.h" | 31 #include "util/misc/initialization_state_dcheck.h" |
32 | 32 |
33 namespace crashpad { | 33 namespace crashpad { |
34 | 34 |
35 //! \brief Contains information about a thread that belongs to a task (process). | |
36 struct ProcessReaderThread { | |
37 #if defined(ARCH_CPU_X86_FAMILY) | |
38 union ThreadContext { | |
39 x86_thread_state64_t t64; | |
40 x86_thread_state32_t t32; | |
41 }; | |
42 union FloatContext { | |
43 x86_float_state64_t f64; | |
44 x86_float_state32_t f32; | |
45 }; | |
46 union DebugContext { | |
47 x86_debug_state64_t d64; | |
48 x86_debug_state32_t d32; | |
49 }; | |
50 #endif | |
51 | |
52 ProcessReaderThread(); | |
53 ~ProcessReaderThread() {} | |
54 | |
55 ThreadContext thread_context; | |
56 FloatContext float_context; | |
57 DebugContext debug_context; | |
58 uint64_t id; | |
59 mach_vm_address_t stack_region_address; | |
60 mach_vm_size_t stack_region_size; | |
61 mach_vm_address_t thread_specific_data_address; | |
62 mach_port_t port; | |
63 int suspend_count; | |
64 int priority; | |
65 }; | |
66 | |
67 //! \brief Contains information about a module loaded into a process. | |
68 struct ProcessReaderModule { | |
69 ProcessReaderModule(); | |
70 ~ProcessReaderModule(); | |
71 | |
72 //! \brief The pathname used to load the module from disk. | |
73 std::string name; | |
74 | |
75 //! \brief The address where the base of the module is loaded in the remote | |
76 //! process. | |
77 mach_vm_address_t address; | |
78 | |
79 //! \brief The module’s timestamp. | |
80 //! | |
81 //! This field will be `0` if its value cannot be determined. It can only be | |
82 //! determined for images that are loaded by dyld, so it will be `0` for the | |
83 //! main executable and for dyld itself. | |
84 time_t timestamp; | |
85 }; | |
86 | |
87 //! \brief Accesses information about another process, identified by a Mach | 35 //! \brief Accesses information about another process, identified by a Mach |
88 //! task. | 36 //! task. |
89 class ProcessReader { | 37 class ProcessReader { |
90 public: | 38 public: |
| 39 //! \brief Contains information about a thread that belongs to a task |
| 40 //! (process). |
| 41 struct Thread { |
| 42 #if defined(ARCH_CPU_X86_FAMILY) |
| 43 union ThreadContext { |
| 44 x86_thread_state64_t t64; |
| 45 x86_thread_state32_t t32; |
| 46 }; |
| 47 union FloatContext { |
| 48 x86_float_state64_t f64; |
| 49 x86_float_state32_t f32; |
| 50 }; |
| 51 union DebugContext { |
| 52 x86_debug_state64_t d64; |
| 53 x86_debug_state32_t d32; |
| 54 }; |
| 55 #endif |
| 56 |
| 57 Thread(); |
| 58 ~Thread() {} |
| 59 |
| 60 ThreadContext thread_context; |
| 61 FloatContext float_context; |
| 62 DebugContext debug_context; |
| 63 uint64_t id; |
| 64 mach_vm_address_t stack_region_address; |
| 65 mach_vm_size_t stack_region_size; |
| 66 mach_vm_address_t thread_specific_data_address; |
| 67 mach_port_t port; |
| 68 int suspend_count; |
| 69 int priority; |
| 70 }; |
| 71 |
| 72 //! \brief Contains information about a module loaded into a process. |
| 73 struct Module { |
| 74 Module(); |
| 75 ~Module(); |
| 76 |
| 77 //! \brief The pathname used to load the module from disk. |
| 78 std::string name; |
| 79 |
| 80 //! \brief The address where the base of the module is loaded in the remote |
| 81 //! process. |
| 82 mach_vm_address_t address; |
| 83 |
| 84 //! \brief The module’s timestamp. |
| 85 //! |
| 86 //! This field will be `0` if its value cannot be determined. It can only be |
| 87 //! determined for images that are loaded by dyld, so it will be `0` for the |
| 88 //! main executable and for dyld itself. |
| 89 time_t timestamp; |
| 90 }; |
| 91 |
91 ProcessReader(); | 92 ProcessReader(); |
92 ~ProcessReader(); | 93 ~ProcessReader(); |
93 | 94 |
94 //! \brief Initializes this object. This method must be called before any | 95 //! \brief Initializes this object. This method must be called before any |
95 //! other. | 96 //! other. |
96 //! | 97 //! |
97 //! \param[in] task A send right to the target task’s task port. This object | 98 //! \param[in] task A send right to the target task’s task port. This object |
98 //! does not take ownership of the send right. | 99 //! does not take ownership of the send right. |
99 //! | 100 //! |
100 //! \return `true` on success, indicating that this object will respond | 101 //! \return `true` on success, indicating that this object will respond |
(...skipping 21 matching lines...) Expand all Loading... |
122 //! \return `true` on success, `false` on failure, with a warning logged. On | 123 //! \return `true` on success, `false` on failure, with a warning logged. On |
123 //! failure, \a user_time and \a system_time will be set to represent no | 124 //! failure, \a user_time and \a system_time will be set to represent no |
124 //! time spent executing code in user or system mode. | 125 //! time spent executing code in user or system mode. |
125 bool CPUTimes(timeval* user_time, timeval* system_time) const; | 126 bool CPUTimes(timeval* user_time, timeval* system_time) const; |
126 | 127 |
127 //! \return Accesses the memory of the target task. | 128 //! \return Accesses the memory of the target task. |
128 TaskMemory* Memory() { return task_memory_.get(); } | 129 TaskMemory* Memory() { return task_memory_.get(); } |
129 | 130 |
130 //! \return The threads that are in the task (process). The first element (at | 131 //! \return The threads that are in the task (process). The first element (at |
131 //! index `0`) corresponds to the main thread. | 132 //! index `0`) corresponds to the main thread. |
132 const std::vector<ProcessReaderThread>& Threads(); | 133 const std::vector<Thread>& Threads(); |
133 | 134 |
134 //! \return The modules loaded in the process. The first element (at index | 135 //! \return The modules loaded in the process. The first element (at index |
135 //! `0`) corresponds to the main executable, and the final element | 136 //! `0`) corresponds to the main executable, and the final element |
136 //! corresponds to the dynamic loader, dyld. | 137 //! corresponds to the dynamic loader, dyld. |
137 const std::vector<ProcessReaderModule>& Modules(); | 138 const std::vector<Module>& Modules(); |
138 | 139 |
139 private: | 140 private: |
140 //! Performs lazy initialization of the \a threads_ vector on behalf of | 141 //! Performs lazy initialization of the \a threads_ vector on behalf of |
141 //! Threads(). | 142 //! Threads(). |
142 void InitializeThreads(); | 143 void InitializeThreads(); |
143 | 144 |
144 //! Performs lazy initialization of the \a modules_ vector on behalf of | 145 //! Performs lazy initialization of the \a modules_ vector on behalf of |
145 //! Modules(). | 146 //! Modules(). |
146 void InitializeModules(); | 147 void InitializeModules(); |
147 | 148 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 //! by the initial values of \a region_base and \a region_size. The red | 195 //! by the initial values of \a region_base and \a region_size. The red |
195 //! zone will only be allowed to extend out of the region described by | 196 //! zone will only be allowed to extend out of the region described by |
196 //! these initial values if the user tag is appropriate for stack memory | 197 //! these initial values if the user tag is appropriate for stack memory |
197 //! and the expanded region has the same user tag value. | 198 //! and the expanded region has the same user tag value. |
198 void LocateRedZone(mach_vm_address_t* start_address, | 199 void LocateRedZone(mach_vm_address_t* start_address, |
199 mach_vm_address_t* region_base, | 200 mach_vm_address_t* region_base, |
200 mach_vm_address_t* region_size, | 201 mach_vm_address_t* region_size, |
201 unsigned int user_tag); | 202 unsigned int user_tag); |
202 | 203 |
203 kinfo_proc kern_proc_info_; | 204 kinfo_proc kern_proc_info_; |
204 std::vector<ProcessReaderThread> threads_; // owns send rights | 205 std::vector<Thread> threads_; // owns send rights |
205 std::vector<ProcessReaderModule> modules_; | 206 std::vector<Module> modules_; |
206 scoped_ptr<TaskMemory> task_memory_; | 207 scoped_ptr<TaskMemory> task_memory_; |
207 mach_port_t task_; // weak | 208 mach_port_t task_; // weak |
208 InitializationStateDcheck initialized_; | 209 InitializationStateDcheck initialized_; |
209 | 210 |
210 // This shadows a bit in kern_proc_info_, but it’s accessed so frequently that | 211 // This shadows a bit in kern_proc_info_, but it’s accessed so frequently that |
211 // it’s given a first-class field to save a few bit operations on each access. | 212 // it’s given a first-class field to save a few bit operations on each access. |
212 bool is_64_bit_; | 213 bool is_64_bit_; |
213 | 214 |
214 bool initialized_threads_; | 215 bool initialized_threads_; |
215 bool initialized_modules_; | 216 bool initialized_modules_; |
216 | 217 |
217 DISALLOW_COPY_AND_ASSIGN(ProcessReader); | 218 DISALLOW_COPY_AND_ASSIGN(ProcessReader); |
218 }; | 219 }; |
219 | 220 |
220 } // namespace crashpad | 221 } // namespace crashpad |
221 | 222 |
222 #endif // CRASHPAD_UTIL_MAC_PROCESS_READER_H_ | 223 #endif // CRASHPAD_UTIL_MAC_PROCESS_READER_H_ |
OLD | NEW |