Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: tools/mac/exception_port_tool.cc

Issue 1381023007: mac: Don’t leak send rights from ExceptionPorts::GetExceptionPorts() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/simulate_crash_mac.cc ('k') | util/mach/exception_ports.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ~MachSendRightPool() { 67 ~MachSendRightPool() {
68 for (mach_port_t send_right : send_rights_) { 68 for (mach_port_t send_right : send_rights_) {
69 kern_return_t kr = mach_port_deallocate(mach_task_self(), send_right); 69 kern_return_t kr = mach_port_deallocate(mach_task_self(), send_right);
70 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; 70 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_deallocate";
71 } 71 }
72 } 72 }
73 73
74 //! \brief Adds a send right to the pool. 74 //! \brief Adds a send right to the pool.
75 //! 75 //!
76 //! \param[in] send_right The send right to be added. The pool object takes 76 //! \param[in] send_right The send right to be added. The pool object takes
77 //! ownership of the send right, which remains valid until the pool object 77 //! its own reference to the send right, which remains valid until the
78 //! is destroyed. 78 //! pool object is destroyed. The caller remains responsible for its
79 //! reference to the send right.
79 //! 80 //!
80 //! It is possible and in fact likely that one pool will wind up owning the 81 //! It is possible and in fact likely that one pool will wind up owning the
81 //! same send right multiple times. This is acceptable, because send rights 82 //! same send right multiple times. This is acceptable, because send rights
82 //! are reference-counted. 83 //! are reference-counted.
83 void AddSendRight(mach_port_t send_right) { 84 void AddSendRight(mach_port_t send_right) {
85 kern_return_t kr = mach_port_mod_refs(mach_task_self(),
86 send_right,
87 MACH_PORT_RIGHT_SEND,
88 1);
89 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_port_mod_refs";
90
84 send_rights_.push_back(send_right); 91 send_rights_.push_back(send_right);
85 } 92 }
86 93
87 private: 94 private:
88 std::vector<mach_port_t> send_rights_; 95 std::vector<mach_port_t> send_rights_;
89 96
90 DISALLOW_COPY_AND_ASSIGN(MachSendRightPool); 97 DISALLOW_COPY_AND_ASSIGN(MachSendRightPool);
91 }; 98 };
92 99
93 struct ExceptionHandlerDescription { 100 struct ExceptionHandlerDescription {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // value, which can then be associated with handlers shown by 188 // value, which can then be associated with handlers shown by
182 // ShowExceptionPorts(). Any send rights obtained by this function are added to 189 // ShowExceptionPorts(). Any send rights obtained by this function are added to
183 // |mach_send_right_pool|. 190 // |mach_send_right_pool|.
184 void ShowBootstrapService(const std::string& service_name, 191 void ShowBootstrapService(const std::string& service_name,
185 MachSendRightPool* mach_send_right_pool) { 192 MachSendRightPool* mach_send_right_pool) {
186 base::mac::ScopedMachSendRight service_port(BootstrapLookUp(service_name)); 193 base::mac::ScopedMachSendRight service_port(BootstrapLookUp(service_name));
187 if (service_port == kMachPortNull) { 194 if (service_port == kMachPortNull) {
188 return; 195 return;
189 } 196 }
190 197
198 mach_send_right_pool->AddSendRight(service_port);
199
191 printf("service %s %#x\n", service_name.c_str(), service_port.get()); 200 printf("service %s %#x\n", service_name.c_str(), service_port.get());
192
193 mach_send_right_pool->AddSendRight(service_port.release());
194 } 201 }
195 202
196 // Prints information about all exception ports known for |exception_ports|. If 203 // Prints information about all exception ports known for |exception_ports|. If
197 // |numeric| is true, all information is printed in numeric form, otherwise, it 204 // |numeric| is true, all information is printed in numeric form, otherwise, it
198 // will be converted to symbolic constants where possible by 205 // will be converted to symbolic constants where possible by
199 // SymbolicConstantsMach. If |is_new| is true, information will be presented as 206 // SymbolicConstantsMach. If |is_new| is true, information will be presented as
200 // “new exception ports”, indicating that they show the state of the exception 207 // “new exception ports”, indicating that they show the state of the exception
201 // ports after SetExceptionPort() has been called. Any send rights obtained by 208 // ports after SetExceptionPort() has been called. Any send rights obtained by
202 // this function are added to |mach_send_right_pool|. 209 // this function are added to |mach_send_right_pool|.
203 void ShowExceptionPorts(const ExceptionPorts& exception_ports, 210 void ShowExceptionPorts(const ExceptionPorts& exception_ports,
204 bool numeric, 211 bool numeric,
205 bool is_new, 212 bool is_new,
206 MachSendRightPool* mach_send_right_pool) { 213 MachSendRightPool* mach_send_right_pool) {
207 const char* target_name = exception_ports.TargetTypeName(); 214 const char* target_name = exception_ports.TargetTypeName();
208 215
209 std::vector<ExceptionPorts::ExceptionHandler> handlers; 216 ExceptionPorts::ExceptionHandlerVector handlers;
210 if (!exception_ports.GetExceptionPorts(ExcMaskValid(), &handlers)) { 217 if (!exception_ports.GetExceptionPorts(ExcMaskValid(), &handlers)) {
211 return; 218 return;
212 } 219 }
213 220
214 const char* age_name = is_new ? "new " : ""; 221 const char* age_name = is_new ? "new " : "";
215 222
216 if (handlers.size() == 0) { 223 if (handlers.empty()) {
217 printf("no %s%s exception ports\n", age_name, target_name); 224 printf("no %s%s exception ports\n", age_name, target_name);
218 } 225 }
219 226
220 for (size_t port_index = 0; port_index < handlers.size(); ++port_index) { 227 for (size_t port_index = 0; port_index < handlers.size(); ++port_index) {
221 mach_send_right_pool->AddSendRight(handlers[port_index].port); 228 mach_send_right_pool->AddSendRight(handlers[port_index].port);
222 229
223 if (numeric) { 230 if (numeric) {
224 printf( 231 printf(
225 "%s%s exception port %zu, mask %#x, port %#x, " 232 "%s%s exception port %zu, mask %#x, port %#x, "
226 "behavior %#x, flavor %u\n", 233 "behavior %#x, flavor %u\n",
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 582
576 return kExitSuccess; 583 return kExitSuccess;
577 } 584 }
578 585
579 } // namespace 586 } // namespace
580 } // namespace crashpad 587 } // namespace crashpad
581 588
582 int main(int argc, char* argv[]) { 589 int main(int argc, char* argv[]) {
583 return crashpad::ExceptionPortToolMain(argc, argv); 590 return crashpad::ExceptionPortToolMain(argc, argv);
584 } 591 }
OLDNEW
« no previous file with comments | « client/simulate_crash_mac.cc ('k') | util/mach/exception_ports.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698