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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 //! `EXCEPTION_STATE_IDENTITY`, possibly combined with | 78 //! `EXCEPTION_STATE_IDENTITY`, possibly combined with |
79 //! `MACH_EXCEPTION_CODES`. | 79 //! `MACH_EXCEPTION_CODES`. |
80 exception_behavior_t behavior; | 80 exception_behavior_t behavior; |
81 | 81 |
82 //! \brief The thread state flavor that the exception handler at \a port | 82 //! \brief The thread state flavor that the exception handler at \a port |
83 //! will receive and possibly modify. This member has no effect for \a | 83 //! will receive and possibly modify. This member has no effect for \a |
84 //! \a behavior values that indicate a “default” behavior. | 84 //! \a behavior values that indicate a “default” behavior. |
85 thread_state_flavor_t flavor; | 85 thread_state_flavor_t flavor; |
86 }; | 86 }; |
87 | 87 |
| 88 //! \brief Wraps `std::vector<ExceptionHandler>`, providing proper cleanup of |
| 89 //! the send rights contained in each element’s ExceptionHandler::port. |
| 90 //! |
| 91 //! Upon destruction or clear(), an object of this class will deallocate all |
| 92 //! send rights it contains. Otherwise, it is an interface-compatible drop-in |
| 93 //! replacement for `std::vector<ExceptionHandler>`. Note that non-`const` |
| 94 //! mutators are not provided to avoid accidental Mach right leaks. |
| 95 class ExceptionHandlerVector { |
| 96 public: |
| 97 using VectorType = std::vector<ExceptionHandler>; |
| 98 |
| 99 ExceptionHandlerVector(); |
| 100 ~ExceptionHandlerVector(); |
| 101 |
| 102 VectorType::const_iterator begin() const { return vector_.begin(); } |
| 103 VectorType::const_iterator end() const { return vector_.end(); } |
| 104 VectorType::size_type size() const { return vector_.size(); } |
| 105 bool empty() const { return vector_.empty(); } |
| 106 VectorType::const_reference operator[](VectorType::size_type index) const { |
| 107 return vector_[index]; |
| 108 } |
| 109 void push_back(VectorType::value_type& value) { vector_.push_back(value); } |
| 110 void clear(); |
| 111 |
| 112 private: |
| 113 void Deallocate(); |
| 114 |
| 115 VectorType vector_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerVector); |
| 118 }; |
| 119 |
88 //! \brief Constructs an interface object to get or set exception ports on a | 120 //! \brief Constructs an interface object to get or set exception ports on a |
89 //! host, task, or thread port. | 121 //! host, task, or thread port. |
90 //! | 122 //! |
91 //! \param[in] target_type The type of target on which the exception ports are | 123 //! \param[in] target_type The type of target on which the exception ports are |
92 //! to be get or set: #kTargetTypeHost, #kTargetTypeTask, or or | 124 //! to be get or set: #kTargetTypeHost, #kTargetTypeTask, or or |
93 //! #kTargetTypeThread. The correct functions for | 125 //! #kTargetTypeThread. The correct functions for |
94 //! `*_get_exception_ports()` and `*_set_exception_ports()` will be used. | 126 //! `*_get_exception_ports()` and `*_set_exception_ports()` will be used. |
95 //! \param[in] target_port The target on which to call | 127 //! \param[in] target_port The target on which to call |
96 //! `*_get_exception_ports()` or `*_set_exception_ports()`. The target | 128 //! `*_get_exception_ports()` or `*_set_exception_ports()`. The target |
97 //! port must be a send right to a port of the type specified in \a | 129 //! port must be a send right to a port of the type specified in \a |
98 //! target_type. In this case, ownership of \a target_port is not given to | 130 //! target_type. In this case, ownership of \a target_port is not given to |
99 //! the new ExceptionPorts object. \a target_port may also be | 131 //! the new ExceptionPorts object. \a target_port may also be |
100 //! `HOST_NULL`, `TASK_NULL`, or `THREAD_NULL`, in which case | 132 //! `HOST_NULL`, `TASK_NULL`, or `THREAD_NULL`, in which case |
101 //! `mach_host_self()`, `mach_task_self()`, or `mach_thread_self()` will | 133 //! `mach_host_self()`, `mach_task_self()`, or `mach_thread_self()` will |
102 //! be used as the target port depending on the value of \a target_type. | 134 //! be used as the target port depending on the value of \a target_type. |
103 //! In this case, ownership of the target port will be managed | 135 //! In this case, ownership of the target port will be managed |
104 //! appropriately for \a target_type. | 136 //! appropriately for \a target_type. |
105 ExceptionPorts(TargetType target_type, mach_port_t target_port); | 137 ExceptionPorts(TargetType target_type, mach_port_t target_port); |
106 | 138 |
107 ~ExceptionPorts(); | 139 ~ExceptionPorts(); |
108 | 140 |
109 //! \brief Calls `*_get_exception_ports()` on the target. | 141 //! \brief Calls `*_get_exception_ports()` on the target. |
110 //! | 142 //! |
111 //! \param[in] mask The exception mask, containing the `EXC_MASK_*` values to | 143 //! \param[in] mask The exception mask, containing the `EXC_MASK_*` values to |
112 //! be looked up and returned in \a handlers. | 144 //! be looked up and returned in \a handlers. |
113 //! \param[out] handlers The exception handlers registered for \a target_port | 145 //! \param[out] handlers The exception handlers registered for \a target_port |
114 //! to handle exceptions indicated in \a mask. The caller must take | 146 //! to handle exceptions indicated in \a mask. If no execption port is |
115 //! ownership of the \a port members of the returned ExceptionHandler | 147 //! registered for a bit in \a mask, \a handlers will not contain an entry |
116 //! objects. If no execption port is registered for a bit in \a mask, \a | 148 //! corresponding to that bit. This is a departure from the |
117 //! handlers will not contain an entry corresponding to that bit. This is | 149 //! `*_get_exception_ports()` functions, which may return a handler whose |
118 //! a departure from the `*_get_exception_ports()` functions, which may | 150 //! port is set to `EXCEPTION_PORT_NULL` in this case. On failure, this |
119 //! return a handler whose port is set to `EXCEPTION_PORT_NULL` in this | 151 //! argument is untouched. |
120 //! case. On failure, this argument is untouched. | |
121 //! | 152 //! |
122 //! \return `true` if `*_get_exception_ports()` returned `KERN_SUCCESS`, with | 153 //! \return `true` if `*_get_exception_ports()` returned `KERN_SUCCESS`, with |
123 //! \a handlers set appropriately. `false` otherwise, with an appropriate | 154 //! \a handlers set appropriately. `false` otherwise, with an appropriate |
124 //! message logged. | 155 //! message logged. |
125 bool GetExceptionPorts(exception_mask_t mask, | 156 bool GetExceptionPorts(exception_mask_t mask, |
126 std::vector<ExceptionHandler>* handlers) const; | 157 ExceptionHandlerVector* handlers) const; |
127 | 158 |
128 //! \brief Calls `*_set_exception_ports()` on the target. | 159 //! \brief Calls `*_set_exception_ports()` on the target. |
129 //! | 160 //! |
130 //! \param[in] mask A mask specifying the exception types to direct to \a | 161 //! \param[in] mask A mask specifying the exception types to direct to \a |
131 //! port, containing `EXC_MASK_*` values. | 162 //! port, containing `EXC_MASK_*` values. |
132 //! \param[in] port A send right to a Mach port that will handle exceptions | 163 //! \param[in] port A send right to a Mach port that will handle exceptions |
133 //! sustained by \a target_port of the types indicated in \a mask. The | 164 //! sustained by \a target_port of the types indicated in \a mask. The |
134 //! send right is copied, not consumed, by this call. | 165 //! send right is copied, not consumed, by this call. |
135 //! \param[in] behavior The “behavior” that the exception handler at \a port | 166 //! \param[in] behavior The “behavior” that the exception handler at \a port |
136 //! implements: `EXCEPTION_DEFAULT`, `EXCEPTION_STATE`, or | 167 //! implements: `EXCEPTION_DEFAULT`, `EXCEPTION_STATE`, or |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // even with a TASK_NULL target_port, because it is incorrect to deallocate | 209 // even with a TASK_NULL target_port, because it is incorrect to deallocate |
179 // the result of mach_task_self(). | 210 // the result of mach_task_self(). |
180 bool dealloc_target_port_; | 211 bool dealloc_target_port_; |
181 | 212 |
182 DISALLOW_COPY_AND_ASSIGN(ExceptionPorts); | 213 DISALLOW_COPY_AND_ASSIGN(ExceptionPorts); |
183 }; | 214 }; |
184 | 215 |
185 } // namespace crashpad | 216 } // namespace crashpad |
186 | 217 |
187 #endif // CRASHPAD_UTIL_MACH_EXCEPTION_PORTS_H_ | 218 #endif // CRASHPAD_UTIL_MACH_EXCEPTION_PORTS_H_ |
OLD | NEW |