| 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 #include "util/mac/process_reader.h" | 15 #include "util/mac/process_reader.h" |
| 16 | 16 |
| 17 #include <AvailabilityMacros.h> | 17 #include <AvailabilityMacros.h> |
| 18 #include <mach/mach_vm.h> | 18 #include <mach/mach_vm.h> |
| 19 #include <mach-o/loader.h> | 19 #include <mach-o/loader.h> |
| 20 | 20 |
| 21 #include <algorithm> | 21 #include <algorithm> |
| 22 | 22 |
| 23 #include "base/logging.h" | 23 #include "base/logging.h" |
| 24 #include "base/mac/mach_logging.h" | 24 #include "base/mac/mach_logging.h" |
| 25 #include "base/mac/scoped_mach_port.h" | 25 #include "base/mac/scoped_mach_port.h" |
| 26 #include "base/mac/scoped_mach_vm.h" | 26 #include "base/mac/scoped_mach_vm.h" |
| 27 #include "util/misc/scoped_forbid_return.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 void MachTimeValueToTimeval(const time_value& mach, timeval* tv) { | 31 void MachTimeValueToTimeval(const time_value& mach, timeval* tv) { |
| 31 tv->tv_sec = mach.seconds; | 32 tv->tv_sec = mach.seconds; |
| 32 tv->tv_usec = mach.microseconds; | 33 tv->tv_usec = mach.microseconds; |
| 33 } | 34 } |
| 34 | 35 |
| 35 kern_return_t MachVMRegionRecurseDeepest(mach_port_t task, | 36 kern_return_t MachVMRegionRecurseDeepest(mach_port_t task, |
| 36 mach_vm_address_t* address, | 37 mach_vm_address_t* address, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 kern_return_t kr = task_threads(task_, &threads, &thread_count); | 215 kern_return_t kr = task_threads(task_, &threads, &thread_count); |
| 215 if (kr != KERN_SUCCESS) { | 216 if (kr != KERN_SUCCESS) { |
| 216 MACH_LOG(WARNING, kr) << "task_threads"; | 217 MACH_LOG(WARNING, kr) << "task_threads"; |
| 217 return; | 218 return; |
| 218 } | 219 } |
| 219 | 220 |
| 220 // The send rights in the |threads| array won’t have their send rights managed | 221 // The send rights in the |threads| array won’t have their send rights managed |
| 221 // by anything until they’re added to |threads_| by the loop below. Any early | 222 // by anything until they’re added to |threads_| by the loop below. Any early |
| 222 // return (or exception) that happens between here and the completion of the | 223 // return (or exception) that happens between here and the completion of the |
| 223 // loop below will leak thread port send rights. | 224 // loop below will leak thread port send rights. |
| 225 ScopedForbidReturn threads_need_owners; |
| 224 | 226 |
| 225 base::mac::ScopedMachVM threads_vm( | 227 base::mac::ScopedMachVM threads_vm( |
| 226 reinterpret_cast<vm_address_t>(threads), | 228 reinterpret_cast<vm_address_t>(threads), |
| 227 mach_vm_round_page(thread_count * sizeof(*threads))); | 229 mach_vm_round_page(thread_count * sizeof(*threads))); |
| 228 | 230 |
| 229 for (size_t index = 0; index < thread_count; ++index) { | 231 for (size_t index = 0; index < thread_count; ++index) { |
| 230 ProcessReaderThread thread; | 232 ProcessReaderThread thread; |
| 231 thread.port = threads[index]; | 233 thread.port = threads[index]; |
| 232 | 234 |
| 233 #if defined(ARCH_CPU_X86_FAMILY) | 235 #if defined(ARCH_CPU_X86_FAMILY) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 mach_vm_address_t stack_pointer = Is64Bit() | 335 mach_vm_address_t stack_pointer = Is64Bit() |
| 334 ? thread.thread_context.t64.__rsp | 336 ? thread.thread_context.t64.__rsp |
| 335 : thread.thread_context.t32.__esp; | 337 : thread.thread_context.t32.__esp; |
| 336 #endif | 338 #endif |
| 337 | 339 |
| 338 thread.stack_region_address = | 340 thread.stack_region_address = |
| 339 CalculateStackRegion(stack_pointer, &thread.stack_region_size); | 341 CalculateStackRegion(stack_pointer, &thread.stack_region_size); |
| 340 | 342 |
| 341 threads_.push_back(thread); | 343 threads_.push_back(thread); |
| 342 } | 344 } |
| 345 |
| 346 threads_need_owners.Disarm(); |
| 343 } | 347 } |
| 344 | 348 |
| 345 void ProcessReader::InitializeModules() { | 349 void ProcessReader::InitializeModules() { |
| 346 DCHECK(!initialized_modules_); | 350 DCHECK(!initialized_modules_); |
| 347 DCHECK(modules_.empty()); | 351 DCHECK(modules_.empty()); |
| 348 | 352 |
| 349 initialized_modules_ = true; | 353 initialized_modules_ = true; |
| 350 | 354 |
| 351 // TODO(mark): Complete this implementation. The implementation depends on | 355 // TODO(mark): Complete this implementation. The implementation depends on |
| 352 // process_types, which cannot land yet because it depends on this file, | 356 // process_types, which cannot land yet because it depends on this file, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // The red zone would go lower into another region in memory, but no | 524 // The red zone would go lower into another region in memory, but no |
| 521 // region was found. Memory can only be captured to an address as low as | 525 // region was found. Memory can only be captured to an address as low as |
| 522 // the base address of the region already found. | 526 // the base address of the region already found. |
| 523 *start_address = *region_base; | 527 *start_address = *region_base; |
| 524 } | 528 } |
| 525 } | 529 } |
| 526 #endif | 530 #endif |
| 527 } | 531 } |
| 528 | 532 |
| 529 } // namespace crashpad | 533 } // namespace crashpad |
| OLD | NEW |