| 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, |
| 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 CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_H_ | 15 #ifndef CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_H_ |
| 16 #define CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_H_ | 16 #define CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_H_ |
| 17 | 17 |
| 18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
| 19 #include <sys/sysctl.h> | |
| 20 #include <sys/time.h> | 19 #include <sys/time.h> |
| 21 #include <sys/types.h> | 20 #include <sys/types.h> |
| 22 #include <time.h> | 21 #include <time.h> |
| 23 | 22 |
| 24 #include <string> | 23 #include <string> |
| 25 #include <vector> | 24 #include <vector> |
| 26 | 25 |
| 27 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
| 28 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
| 29 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 30 #include "util/mach/task_memory.h" | 29 #include "util/mach/task_memory.h" |
| 31 #include "util/misc/initialization_state_dcheck.h" | 30 #include "util/misc/initialization_state_dcheck.h" |
| 31 #include "util/posix/process_info.h" |
| 32 #include "util/stdlib/pointer_container.h" | 32 #include "util/stdlib/pointer_container.h" |
| 33 | 33 |
| 34 namespace crashpad { | 34 namespace crashpad { |
| 35 | 35 |
| 36 class MachOImageReader; | 36 class MachOImageReader; |
| 37 | 37 |
| 38 //! \brief Accesses information about another process, identified by a Mach | 38 //! \brief Accesses information about another process, identified by a Mach |
| 39 //! task. | 39 //! task. |
| 40 class ProcessReader { | 40 class ProcessReader { |
| 41 public: | 41 public: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 //! | 105 //! |
| 106 //! \return `true` on success, indicating that this object will respond | 106 //! \return `true` on success, indicating that this object will respond |
| 107 //! validly to further method calls. `false` on failure. On failure, no | 107 //! validly to further method calls. `false` on failure. On failure, no |
| 108 //! further method calls should be made. | 108 //! further method calls should be made. |
| 109 bool Initialize(task_t task); | 109 bool Initialize(task_t task); |
| 110 | 110 |
| 111 //! \return `true` if the target task is a 64-bit process. | 111 //! \return `true` if the target task is a 64-bit process. |
| 112 bool Is64Bit() const { return is_64_bit_; } | 112 bool Is64Bit() const { return is_64_bit_; } |
| 113 | 113 |
| 114 //! \return The target task’s process ID. | 114 //! \return The target task’s process ID. |
| 115 pid_t ProcessID() const { return kern_proc_info_.kp_proc.p_pid; } | 115 pid_t ProcessID() const { return process_info_.ProcessID(); } |
| 116 | 116 |
| 117 //! \return The target task’s parent process ID. | 117 //! \return The target task’s parent process ID. |
| 118 pid_t ParentProcessID() const { return kern_proc_info_.kp_eproc.e_ppid; } | 118 pid_t ParentProcessID() const { return process_info_.ParentProcessID(); } |
| 119 | 119 |
| 120 //! \brief Determines the target process’ start time. |
| 121 //! |
| 120 //! \param[out] start_time The time that the process started. | 122 //! \param[out] start_time The time that the process started. |
| 121 void StartTime(timeval* start_time) const; | 123 void StartTime(timeval* start_time) const { |
| 124 process_info_.StartTime(start_time); |
| 125 } |
| 122 | 126 |
| 127 //! \brief Determines the target process’ execution time. |
| 128 //! |
| 123 //! \param[out] user_time The amount of time the process has executed code in | 129 //! \param[out] user_time The amount of time the process has executed code in |
| 124 //! user mode. | 130 //! user mode. |
| 125 //! \param[out] system_time The amount of time the process has executed code | 131 //! \param[out] system_time The amount of time the process has executed code |
| 126 //! in system mode. | 132 //! in system mode. |
| 127 //! | 133 //! |
| 128 //! \return `true` on success, `false` on failure, with a warning logged. On | 134 //! \return `true` on success, `false` on failure, with a warning logged. On |
| 129 //! failure, \a user_time and \a system_time will be set to represent no | 135 //! failure, \a user_time and \a system_time will be set to represent no |
| 130 //! time spent executing code in user or system mode. | 136 //! time spent executing code in user or system mode. |
| 131 bool CPUTimes(timeval* user_time, timeval* system_time) const; | 137 bool CPUTimes(timeval* user_time, timeval* system_time) const; |
| 132 | 138 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 //! \param[in] user_tag The Mach VM system’s user tag for the region described | 205 //! \param[in] user_tag The Mach VM system’s user tag for the region described |
| 200 //! by the initial values of \a region_base and \a region_size. The red | 206 //! by the initial values of \a region_base and \a region_size. The red |
| 201 //! zone will only be allowed to extend out of the region described by | 207 //! zone will only be allowed to extend out of the region described by |
| 202 //! these initial values if the user tag is appropriate for stack memory | 208 //! these initial values if the user tag is appropriate for stack memory |
| 203 //! and the expanded region has the same user tag value. | 209 //! and the expanded region has the same user tag value. |
| 204 void LocateRedZone(mach_vm_address_t* start_address, | 210 void LocateRedZone(mach_vm_address_t* start_address, |
| 205 mach_vm_address_t* region_base, | 211 mach_vm_address_t* region_base, |
| 206 mach_vm_address_t* region_size, | 212 mach_vm_address_t* region_size, |
| 207 unsigned int user_tag); | 213 unsigned int user_tag); |
| 208 | 214 |
| 209 kinfo_proc kern_proc_info_; | 215 ProcessInfo process_info_; |
| 210 std::vector<Thread> threads_; // owns send rights | 216 std::vector<Thread> threads_; // owns send rights |
| 211 std::vector<Module> modules_; | 217 std::vector<Module> modules_; |
| 212 PointerVector<MachOImageReader> module_readers_; | 218 PointerVector<MachOImageReader> module_readers_; |
| 213 scoped_ptr<TaskMemory> task_memory_; | 219 scoped_ptr<TaskMemory> task_memory_; |
| 214 task_t task_; // weak | 220 task_t task_; // weak |
| 215 InitializationStateDcheck initialized_; | 221 InitializationStateDcheck initialized_; |
| 216 | 222 |
| 217 // This shadows a bit in kern_proc_info_, but it’s accessed so frequently that | 223 // This shadows a method of process_info_, but it’s accessed so frequently |
| 218 // it’s given a first-class field to save a few bit operations on each access. | 224 // that it’s given a first-class field to save a call and a few bit operations |
| 225 // on each access. |
| 219 bool is_64_bit_; | 226 bool is_64_bit_; |
| 220 | 227 |
| 221 bool initialized_threads_; | 228 bool initialized_threads_; |
| 222 bool initialized_modules_; | 229 bool initialized_modules_; |
| 223 | 230 |
| 224 DISALLOW_COPY_AND_ASSIGN(ProcessReader); | 231 DISALLOW_COPY_AND_ASSIGN(ProcessReader); |
| 225 }; | 232 }; |
| 226 | 233 |
| 227 } // namespace crashpad | 234 } // namespace crashpad |
| 228 | 235 |
| 229 #endif // CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_H_ | 236 #endif // CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_H_ |
| OLD | NEW |