OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "snapshot/win/capture_context_memory.h" |
| 16 |
| 17 #include <stdint.h> |
| 18 |
| 19 #include <limits> |
| 20 |
| 21 #include "snapshot/win/memory_snapshot_win.h" |
| 22 #include "snapshot/win/process_reader_win.h" |
| 23 |
| 24 namespace crashpad { |
| 25 namespace internal { |
| 26 |
| 27 namespace { |
| 28 |
| 29 void MaybeCaptureMemoryAround(ProcessReaderWin* process_reader, |
| 30 WinVMAddress address, |
| 31 PointerVector<MemorySnapshotWin>* into) { |
| 32 const WinVMAddress non_address_offset = 0x10000; |
| 33 if (address < non_address_offset) |
| 34 return; |
| 35 if (process_reader->Is64Bit()) { |
| 36 if (address >= std::numeric_limits<uint64_t>::max() - non_address_offset) |
| 37 return; |
| 38 } else { |
| 39 if (address >= std::numeric_limits<uint32_t>::max() - non_address_offset) |
| 40 return; |
| 41 } |
| 42 |
| 43 const WinVMSize kRegisterByteOffset = 32; |
| 44 const WinVMAddress target = address - kRegisterByteOffset; |
| 45 const WinVMSize size = 128; |
| 46 auto ranges = process_reader->GetProcessInfo().GetReadableRanges( |
| 47 CheckedRange<WinVMAddress, WinVMSize>(target, size)); |
| 48 for (const auto& range : ranges) { |
| 49 internal::MemorySnapshotWin* snapshot = new internal::MemorySnapshotWin(); |
| 50 snapshot->Initialize(process_reader, range.base(), range.size()); |
| 51 into->push_back(snapshot); |
| 52 } |
| 53 } |
| 54 |
| 55 } // namespace |
| 56 |
| 57 void CaptureMemoryPointedToByContext(const CPUContext& context, |
| 58 ProcessReaderWin* process_reader, |
| 59 const ProcessReaderWin::Thread& thread, |
| 60 PointerVector<MemorySnapshotWin>* into) { |
| 61 #if defined(ARCH_CPU_X86_64) |
| 62 if (context.architecture == kCPUArchitectureX86_64) { |
| 63 MaybeCaptureMemoryAround(process_reader, context.x86_64->rax, into); |
| 64 MaybeCaptureMemoryAround(process_reader, context.x86_64->rbx, into); |
| 65 MaybeCaptureMemoryAround(process_reader, context.x86_64->rcx, into); |
| 66 MaybeCaptureMemoryAround(process_reader, context.x86_64->rdx, into); |
| 67 MaybeCaptureMemoryAround(process_reader, context.x86_64->rdi, into); |
| 68 MaybeCaptureMemoryAround(process_reader, context.x86_64->rsi, into); |
| 69 if (context.x86_64->rbp < thread.stack_region_address || |
| 70 context.x86_64->rbp >= |
| 71 thread.stack_region_address + thread.stack_region_size) { |
| 72 MaybeCaptureMemoryAround(process_reader, context.x86_64->rbp, into); |
| 73 } |
| 74 MaybeCaptureMemoryAround(process_reader, context.x86_64->r8, into); |
| 75 MaybeCaptureMemoryAround(process_reader, context.x86_64->r9, into); |
| 76 MaybeCaptureMemoryAround(process_reader, context.x86_64->r10, into); |
| 77 MaybeCaptureMemoryAround(process_reader, context.x86_64->r11, into); |
| 78 MaybeCaptureMemoryAround(process_reader, context.x86_64->r12, into); |
| 79 MaybeCaptureMemoryAround(process_reader, context.x86_64->r13, into); |
| 80 MaybeCaptureMemoryAround(process_reader, context.x86_64->r14, into); |
| 81 MaybeCaptureMemoryAround(process_reader, context.x86_64->r15, into); |
| 82 MaybeCaptureMemoryAround(process_reader, context.x86_64->rip, into); |
| 83 } else { |
| 84 #endif |
| 85 MaybeCaptureMemoryAround(process_reader, context.x86->eax, into); |
| 86 MaybeCaptureMemoryAround(process_reader, context.x86->ebx, into); |
| 87 MaybeCaptureMemoryAround(process_reader, context.x86->ecx, into); |
| 88 MaybeCaptureMemoryAround(process_reader, context.x86->edx, into); |
| 89 MaybeCaptureMemoryAround(process_reader, context.x86->edi, into); |
| 90 MaybeCaptureMemoryAround(process_reader, context.x86->esi, into); |
| 91 if (context.x86->ebp < thread.stack_region_address || |
| 92 context.x86->ebp >= |
| 93 thread.stack_region_address + thread.stack_region_size) { |
| 94 MaybeCaptureMemoryAround(process_reader, context.x86->ebp, into); |
| 95 } |
| 96 MaybeCaptureMemoryAround(process_reader, context.x86->eip, into); |
| 97 #if defined(ARCH_CPU_X86_64) |
| 98 } |
| 99 #endif |
| 100 } |
| 101 |
| 102 } // namespace internal |
| 103 } // namespace crashpad |
OLD | NEW |