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 15 matching lines...) Expand all Loading... |
26 #include <vector> | 26 #include <vector> |
27 | 27 |
28 #include "base/basictypes.h" | 28 #include "base/basictypes.h" |
29 #include "base/mac/mach_logging.h" | 29 #include "base/mac/mach_logging.h" |
30 #include "base/mac/scoped_mach_port.h" | 30 #include "base/mac/scoped_mach_port.h" |
31 #include "base/strings/stringprintf.h" | 31 #include "base/strings/stringprintf.h" |
32 #include "tools/tool_support.h" | 32 #include "tools/tool_support.h" |
33 #include "util/mach/exception_ports.h" | 33 #include "util/mach/exception_ports.h" |
34 #include "util/mach/mach_extensions.h" | 34 #include "util/mach/mach_extensions.h" |
35 #include "util/mach/symbolic_constants_mach.h" | 35 #include "util/mach/symbolic_constants_mach.h" |
| 36 #include "util/mach/task_for_pid.h" |
36 #include "util/stdlib/string_number_conversion.h" | 37 #include "util/stdlib/string_number_conversion.h" |
37 | 38 |
38 namespace crashpad { | 39 namespace crashpad { |
39 namespace { | 40 namespace { |
40 | 41 |
41 //! \brief Manages a pool of Mach send rights, deallocating all send rights upon | 42 //! \brief Manages a pool of Mach send rights, deallocating all send rights upon |
42 //! destruction. | 43 //! destruction. |
43 //! | 44 //! |
44 //! This class effectively implements what a vector of | 45 //! This class effectively implements what a vector of |
45 //! base::mac::ScopedMachSendRight objects would be. | 46 //! base::mac::ScopedMachSendRight objects would be. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 313 |
313 void Usage(const std::string& me) { | 314 void Usage(const std::string& me) { |
314 fprintf(stderr, | 315 fprintf(stderr, |
315 "Usage: %s [OPTION]... [COMMAND [ARG]...]\n" | 316 "Usage: %s [OPTION]... [COMMAND [ARG]...]\n" |
316 "View and change Mach exception ports, and run COMMAND if supplied.\n" | 317 "View and change Mach exception ports, and run COMMAND if supplied.\n" |
317 "\n" | 318 "\n" |
318 " -s, --set_handler=DESCRIPTION set an exception port to DESCRIPTION, see belo
w\n" | 319 " -s, --set_handler=DESCRIPTION set an exception port to DESCRIPTION, see belo
w\n" |
319 " --show_bootstrap=SERVICE look up and display a service registered with\
n" | 320 " --show_bootstrap=SERVICE look up and display a service registered with\
n" |
320 " the bootstrap server\n" | 321 " the bootstrap server\n" |
321 " -p, --pid=PID operate on PID instead of the current task\n" | 322 " -p, --pid=PID operate on PID instead of the current task\n" |
322 " (must be superuser or permitted by taskgated)\
n" | |
323 " -h, --show_host display original host exception ports\n" | 323 " -h, --show_host display original host exception ports\n" |
324 " -t, --show_task display original task exception ports\n" | 324 " -t, --show_task display original task exception ports\n" |
325 " --show_thread display original thread exception ports\n" | 325 " --show_thread display original thread exception ports\n" |
326 " -H, --show_new_host display modified host exception ports\n" | 326 " -H, --show_new_host display modified host exception ports\n" |
327 " -T, --show_new_task display modified task exception ports\n" | 327 " -T, --show_new_task display modified task exception ports\n" |
328 " --show_new_thread display modified thread exception ports\n" | 328 " --show_new_thread display modified thread exception ports\n" |
329 " -n, --numeric display values numerically, not symbolically\n
" | 329 " -n, --numeric display values numerically, not symbolically\n
" |
330 " --help display this help and exit\n" | 330 " --help display this help and exit\n" |
331 " --version output version information and exit\n" | 331 " --version output version information and exit\n" |
332 "\n" | 332 "\n" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 return kExitFailure; | 489 return kExitFailure; |
490 } | 490 } |
491 | 491 |
492 base::mac::ScopedMachSendRight alternate_task_owner; | 492 base::mac::ScopedMachSendRight alternate_task_owner; |
493 if (options.pid) { | 493 if (options.pid) { |
494 if (argc) { | 494 if (argc) { |
495 ToolSupport::UsageHint(me, "cannot combine -p with COMMAND"); | 495 ToolSupport::UsageHint(me, "cannot combine -p with COMMAND"); |
496 return kExitFailure; | 496 return kExitFailure; |
497 } | 497 } |
498 | 498 |
499 // This is only expected to work as root or if taskgated approves. | 499 options.alternate_task = TaskForPID(options.pid); |
500 // taskgated does not normally approve. | 500 if (options.alternate_task == TASK_NULL) { |
501 kern_return_t kr = | |
502 task_for_pid(mach_task_self(), options.pid, &options.alternate_task); | |
503 if (kr != KERN_SUCCESS) { | |
504 MACH_LOG(ERROR, kr) << "task_for_pid"; | |
505 return kExitFailure; | 501 return kExitFailure; |
506 } | 502 } |
507 alternate_task_owner.reset(options.alternate_task); | 503 alternate_task_owner.reset(options.alternate_task); |
508 } | 504 } |
509 | 505 |
510 MachSendRightPool mach_send_right_pool; | 506 MachSendRightPool mach_send_right_pool; |
511 | 507 |
512 // Show bootstrap services requested. | 508 // Show bootstrap services requested. |
513 for (const char* service : options.show_bootstrap) { | 509 for (const char* service : options.show_bootstrap) { |
514 ShowBootstrapService(service, &mach_send_right_pool); | 510 ShowBootstrapService(service, &mach_send_right_pool); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 580 |
585 return kExitSuccess; | 581 return kExitSuccess; |
586 } | 582 } |
587 | 583 |
588 } // namespace | 584 } // namespace |
589 } // namespace crashpad | 585 } // namespace crashpad |
590 | 586 |
591 int main(int argc, char* argv[]) { | 587 int main(int argc, char* argv[]) { |
592 return crashpad::ExceptionPortToolMain(argc, argv); | 588 return crashpad::ExceptionPortToolMain(argc, argv); |
593 } | 589 } |
OLD | NEW |