1 //===-- IRMemoryMap.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Core/DataBufferHeap.h" 11 #include "lldb/Core/DataExtractor.h" 12 #include "lldb/Core/Error.h" 13 #include "lldb/Core/Log.h" 14 #include "lldb/Core/Scalar.h" 15 #include "lldb/Expression/IRMemoryMap.h" 16 #include "lldb/Target/Process.h" 17 #include "lldb/Target/Target.h" 18 19 using namespace lldb_private; 20 21 IRMemoryMap::IRMemoryMap (lldb::TargetSP target_sp) : 22 m_target_wp(target_sp) 23 { 24 if (target_sp) 25 m_process_wp = target_sp->GetProcessSP(); 26 } 27 28 IRMemoryMap::~IRMemoryMap () 29 { 30 lldb::ProcessSP process_sp = m_process_wp.lock(); 31 32 if (process_sp) 33 { 34 AllocationMap::iterator iter; 35 36 Error err; 37 38 while ((iter = m_allocations.begin()) != m_allocations.end()) 39 { 40 err.Clear(); 41 if (iter->second.m_leak) 42 m_allocations.erase(iter); 43 else 44 Free(iter->first, err); 45 } 46 } 47 } 48 49 lldb::addr_t 50 IRMemoryMap::FindSpace (size_t size) 51 { 52 lldb::TargetSP target_sp = m_target_wp.lock(); 53 lldb::ProcessSP process_sp = m_process_wp.lock(); 54 55 lldb::addr_t ret = LLDB_INVALID_ADDRESS; 56 57 if (process_sp && process_sp->CanJIT() && process_sp->IsAlive()) 58 { 59 Error alloc_error; 60 61 ret = process_sp->AllocateMemory(size, lldb::ePermissionsReadable | lldb::ePermissionsWritable, alloc_error); 62 63 if (!alloc_error.Success()) 64 return LLDB_INVALID_ADDRESS; 65 else 66 return ret; 67 } 68 69 for (int iterations = 0; iterations < 16; ++iterations) 70 { 71 lldb::addr_t candidate = LLDB_INVALID_ADDRESS; 72 73 switch (target_sp->GetArchitecture().GetAddressByteSize()) 74 { 75 case 4: 76 { 77 uint32_t random_data = rand(); 78 candidate = random_data; 79 candidate &= ~0xfffull; 80 break; 81 } 82 case 8: 83 { 84 uint32_t random_low = rand(); 85 uint32_t random_high = rand(); 86 candidate = random_high; 87 candidate <<= 32ull; 88 candidate |= random_low; 89 candidate &= ~0xfffull; 90 break; 91 } 92 } 93 94 if (IntersectsAllocation(candidate, size)) 95 continue; 96 97 ret = candidate; 98 99 return ret; 100 } 101 102 return ret; 103 } 104 105 IRMemoryMap::AllocationMap::iterator 106 IRMemoryMap::FindAllocation (lldb::addr_t addr, size_t size) 107 { 108 if (addr == LLDB_INVALID_ADDRESS) 109 return m_allocations.end(); 110 111 AllocationMap::iterator iter = m_allocations.lower_bound (addr); 112 113 if (iter == m_allocations.end() || 114 iter->first > addr) 115 { 116 if (iter == m_allocations.begin()) 117 return m_allocations.end(); 118 iter--; 119 } 120 121 if (iter->first <= addr && iter->first + iter->second.m_size >= addr + size) 122 return iter; 123 124 return m_allocations.end(); 125 } 126 127 bool 128 IRMemoryMap::IntersectsAllocation (lldb::addr_t addr, size_t size) const 129 { 130 if (addr == LLDB_INVALID_ADDRESS) 131 return false; 132 133 AllocationMap::const_iterator iter = m_allocations.lower_bound (addr); 134 135 // Since we only know that the returned interval begins at a location greater than or 136 // equal to where the given interval begins, it's possible that the given interval 137 // intersects either the returned interval or the previous interval. Thus, we need to 138 // check both. Note that we only need to check these two intervals. Since all intervals 139 // are disjoint it is not possible that an adjacent interval does not intersect, but a 140 // non-adjacent interval does intersect. 141 if (iter != m_allocations.end()) { 142 if (AllocationsIntersect(addr, size, iter->second.m_process_start, iter->second.m_size)) 143 return true; 144 } 145 146 if (iter != m_allocations.begin()) { 147 --iter; 148 if (AllocationsIntersect(addr, size, iter->second.m_process_start, iter->second.m_size)) 149 return true; 150 } 151 152 return false; 153 } 154 155 bool 156 IRMemoryMap::AllocationsIntersect(lldb::addr_t addr1, size_t size1, lldb::addr_t addr2, size_t size2) { 157 // Given two half open intervals [A, B) and [X, Y), the only 6 permutations that satisfy 158 // A<B and X<Y are the following: 159 // A B X Y 160 // A X B Y (intersects) 161 // A X Y B (intersects) 162 // X A B Y (intersects) 163 // X A Y B (intersects) 164 // X Y A B 165 // The first is B <= X, and the last is Y <= A. 166 // So the condition is !(B <= X || Y <= A)), or (X < B && A < Y) 167 return (addr2 < (addr1 + size1)) && (addr1 < (addr2 + size2)); 168 } 169 170 lldb::ByteOrder 171 IRMemoryMap::GetByteOrder() 172 { 173 lldb::ProcessSP process_sp = m_process_wp.lock(); 174 175 if (process_sp) 176 return process_sp->GetByteOrder(); 177 178 lldb::TargetSP target_sp = m_target_wp.lock(); 179 180 if (target_sp) 181 return target_sp->GetArchitecture().GetByteOrder(); 182 183 return lldb::eByteOrderInvalid; 184 } 185 186 uint32_t 187 IRMemoryMap::GetAddressByteSize() 188 { 189 lldb::ProcessSP process_sp = m_process_wp.lock(); 190 191 if (process_sp) 192 return process_sp->GetAddressByteSize(); 193 194 lldb::TargetSP target_sp = m_target_wp.lock(); 195 196 if (target_sp) 197 return target_sp->GetArchitecture().GetAddressByteSize(); 198 199 return UINT32_MAX; 200 } 201 202 ExecutionContextScope * 203 IRMemoryMap::GetBestExecutionContextScope() const 204 { 205 lldb::ProcessSP process_sp = m_process_wp.lock(); 206 207 if (process_sp) 208 return process_sp.get(); 209 210 lldb::TargetSP target_sp = m_target_wp.lock(); 211 212 if (target_sp) 213 return target_sp.get(); 214 215 return NULL; 216 } 217 218 IRMemoryMap::Allocation::Allocation (lldb::addr_t process_alloc, 219 lldb::addr_t process_start, 220 size_t size, 221 uint32_t permissions, 222 uint8_t alignment, 223 AllocationPolicy policy) : 224 m_process_alloc (process_alloc), 225 m_process_start (process_start), 226 m_size (size), 227 m_permissions (permissions), 228 m_alignment (alignment), 229 m_policy (policy), 230 m_leak (false) 231 { 232 switch (policy) 233 { 234 default: 235 assert (0 && "We cannot reach this!"); 236 case eAllocationPolicyHostOnly: 237 m_data.SetByteSize(size); 238 memset(m_data.GetBytes(), 0, size); 239 break; 240 case eAllocationPolicyProcessOnly: 241 break; 242 case eAllocationPolicyMirror: 243 m_data.SetByteSize(size); 244 memset(m_data.GetBytes(), 0, size); 245 break; 246 } 247 } 248 249 lldb::addr_t 250 IRMemoryMap::Malloc (size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, Error &error) 251 { 252 lldb_private::Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 253 error.Clear(); 254 255 lldb::ProcessSP process_sp; 256 lldb::addr_t allocation_address = LLDB_INVALID_ADDRESS; 257 lldb::addr_t aligned_address = LLDB_INVALID_ADDRESS; 258 259 size_t alignment_mask = alignment - 1; 260 size_t allocation_size; 261 262 if (size == 0) 263 allocation_size = alignment; 264 else 265 allocation_size = (size & alignment_mask) ? ((size + alignment) & (~alignment_mask)) : size; 266 267 switch (policy) 268 { 269 default: 270 error.SetErrorToGenericError(); 271 error.SetErrorString("Couldn't malloc: invalid allocation policy"); 272 return LLDB_INVALID_ADDRESS; 273 case eAllocationPolicyHostOnly: 274 allocation_address = FindSpace(allocation_size); 275 if (allocation_address == LLDB_INVALID_ADDRESS) 276 { 277 error.SetErrorToGenericError(); 278 error.SetErrorString("Couldn't malloc: address space is full"); 279 return LLDB_INVALID_ADDRESS; 280 } 281 break; 282 case eAllocationPolicyMirror: 283 process_sp = m_process_wp.lock(); 284 if (log) 285 log->Printf ("IRMemoryMap::%s process_sp=0x%" PRIx64 ", process_sp->CanJIT()=%s, process_sp->IsAlive()=%s", __FUNCTION__, (lldb::addr_t) process_sp.get (), process_sp && process_sp->CanJIT () ? "true" : "false", process_sp && process_sp->IsAlive () ? "true" : "false"); 286 if (process_sp && process_sp->CanJIT() && process_sp->IsAlive()) 287 { 288 allocation_address = process_sp->AllocateMemory(allocation_size, permissions, error); 289 if (!error.Success()) 290 return LLDB_INVALID_ADDRESS; 291 } 292 else 293 { 294 if (log) 295 log->Printf ("IRMemoryMap::%s switching to eAllocationPolicyHostOnly due to failed condition (see previous expr log message)", __FUNCTION__); 296 policy = eAllocationPolicyHostOnly; 297 allocation_address = FindSpace(allocation_size); 298 if (allocation_address == LLDB_INVALID_ADDRESS) 299 { 300 error.SetErrorToGenericError(); 301 error.SetErrorString("Couldn't malloc: address space is full"); 302 return LLDB_INVALID_ADDRESS; 303 } 304 } 305 break; 306 case eAllocationPolicyProcessOnly: 307 process_sp = m_process_wp.lock(); 308 if (process_sp) 309 { 310 if (process_sp->CanJIT() && process_sp->IsAlive()) 311 { 312 allocation_address = process_sp->AllocateMemory(allocation_size, permissions, error); 313 if (!error.Success()) 314 return LLDB_INVALID_ADDRESS; 315 } 316 else 317 { 318 error.SetErrorToGenericError(); 319 error.SetErrorString("Couldn't malloc: process doesn't support allocating memory"); 320 return LLDB_INVALID_ADDRESS; 321 } 322 } 323 else 324 { 325 error.SetErrorToGenericError(); 326 error.SetErrorString("Couldn't malloc: process doesn't exist, and this memory must be in the process"); 327 return LLDB_INVALID_ADDRESS; 328 } 329 break; 330 } 331 332 333 lldb::addr_t mask = alignment - 1; 334 aligned_address = (allocation_address + mask) & (~mask); 335 336 m_allocations[aligned_address] = Allocation(allocation_address, 337 aligned_address, 338 allocation_size, 339 permissions, 340 alignment, 341 policy); 342 343 if (log) 344 { 345 const char * policy_string; 346 347 switch (policy) 348 { 349 default: 350 policy_string = "<invalid policy>"; 351 break; 352 case eAllocationPolicyHostOnly: 353 policy_string = "eAllocationPolicyHostOnly"; 354 break; 355 case eAllocationPolicyProcessOnly: 356 policy_string = "eAllocationPolicyProcessOnly"; 357 break; 358 case eAllocationPolicyMirror: 359 policy_string = "eAllocationPolicyMirror"; 360 break; 361 } 362 363 log->Printf("IRMemoryMap::Malloc (%" PRIu64 ", 0x%" PRIx64 ", 0x%" PRIx64 ", %s) -> 0x%" PRIx64, 364 (uint64_t)allocation_size, 365 (uint64_t)alignment, 366 (uint64_t)permissions, 367 policy_string, 368 aligned_address); 369 } 370 371 return aligned_address; 372 } 373 374 void 375 IRMemoryMap::Leak (lldb::addr_t process_address, Error &error) 376 { 377 error.Clear(); 378 379 AllocationMap::iterator iter = m_allocations.find(process_address); 380 381 if (iter == m_allocations.end()) 382 { 383 error.SetErrorToGenericError(); 384 error.SetErrorString("Couldn't leak: allocation doesn't exist"); 385 return; 386 } 387 388 Allocation &allocation = iter->second; 389 390 allocation.m_leak = true; 391 } 392 393 void 394 IRMemoryMap::Free (lldb::addr_t process_address, Error &error) 395 { 396 error.Clear(); 397 398 AllocationMap::iterator iter = m_allocations.find(process_address); 399 400 if (iter == m_allocations.end()) 401 { 402 error.SetErrorToGenericError(); 403 error.SetErrorString("Couldn't free: allocation doesn't exist"); 404 return; 405 } 406 407 Allocation &allocation = iter->second; 408 409 switch (allocation.m_policy) 410 { 411 default: 412 case eAllocationPolicyHostOnly: 413 { 414 lldb::ProcessSP process_sp = m_process_wp.lock(); 415 if (process_sp) 416 { 417 if (process_sp->CanJIT() && process_sp->IsAlive()) 418 process_sp->DeallocateMemory(allocation.m_process_alloc); // FindSpace allocated this for real 419 } 420 421 break; 422 } 423 case eAllocationPolicyMirror: 424 case eAllocationPolicyProcessOnly: 425 { 426 lldb::ProcessSP process_sp = m_process_wp.lock(); 427 if (process_sp) 428 process_sp->DeallocateMemory(allocation.m_process_alloc); 429 } 430 } 431 432 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)) 433 { 434 log->Printf("IRMemoryMap::Free (0x%" PRIx64 ") freed [0x%" PRIx64 "..0x%" PRIx64 ")", 435 (uint64_t)process_address, 436 iter->second.m_process_start, 437 iter->second.m_process_start + iter->second.m_size); 438 } 439 440 m_allocations.erase(iter); 441 } 442 443 void 444 IRMemoryMap::WriteMemory (lldb::addr_t process_address, const uint8_t *bytes, size_t size, Error &error) 445 { 446 error.Clear(); 447 448 AllocationMap::iterator iter = FindAllocation(process_address, size); 449 450 if (iter == m_allocations.end()) 451 { 452 lldb::ProcessSP process_sp = m_process_wp.lock(); 453 454 if (process_sp) 455 { 456 process_sp->WriteMemory(process_address, bytes, size, error); 457 return; 458 } 459 460 error.SetErrorToGenericError(); 461 error.SetErrorString("Couldn't write: no allocation contains the target range and the process doesn't exist"); 462 return; 463 } 464 465 Allocation &allocation = iter->second; 466 467 uint64_t offset = process_address - allocation.m_process_start; 468 469 lldb::ProcessSP process_sp; 470 471 switch (allocation.m_policy) 472 { 473 default: 474 error.SetErrorToGenericError(); 475 error.SetErrorString("Couldn't write: invalid allocation policy"); 476 return; 477 case eAllocationPolicyHostOnly: 478 if (!allocation.m_data.GetByteSize()) 479 { 480 error.SetErrorToGenericError(); 481 error.SetErrorString("Couldn't write: data buffer is empty"); 482 return; 483 } 484 ::memcpy (allocation.m_data.GetBytes() + offset, bytes, size); 485 break; 486 case eAllocationPolicyMirror: 487 if (!allocation.m_data.GetByteSize()) 488 { 489 error.SetErrorToGenericError(); 490 error.SetErrorString("Couldn't write: data buffer is empty"); 491 return; 492 } 493 ::memcpy (allocation.m_data.GetBytes() + offset, bytes, size); 494 process_sp = m_process_wp.lock(); 495 if (process_sp) 496 { 497 process_sp->WriteMemory(process_address, bytes, size, error); 498 if (!error.Success()) 499 return; 500 } 501 break; 502 case eAllocationPolicyProcessOnly: 503 process_sp = m_process_wp.lock(); 504 if (process_sp) 505 { 506 process_sp->WriteMemory(process_address, bytes, size, error); 507 if (!error.Success()) 508 return; 509 } 510 break; 511 } 512 513 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)) 514 { 515 log->Printf("IRMemoryMap::WriteMemory (0x%" PRIx64 ", 0x%" PRIx64 ", 0x%" PRId64 ") went to [0x%" PRIx64 "..0x%" PRIx64 ")", 516 (uint64_t)process_address, 517 (uint64_t)bytes, 518 (uint64_t)size, 519 (uint64_t)allocation.m_process_start, 520 (uint64_t)allocation.m_process_start + (uint64_t)allocation.m_size); 521 } 522 } 523 524 void 525 IRMemoryMap::WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Error &error) 526 { 527 error.Clear(); 528 529 if (size == UINT32_MAX) 530 size = scalar.GetByteSize(); 531 532 if (size > 0) 533 { 534 uint8_t buf[32]; 535 const size_t mem_size = scalar.GetAsMemoryData (buf, size, GetByteOrder(), error); 536 if (mem_size > 0) 537 { 538 return WriteMemory(process_address, buf, mem_size, error); 539 } 540 else 541 { 542 error.SetErrorToGenericError(); 543 error.SetErrorString ("Couldn't write scalar: failed to get scalar as memory data"); 544 } 545 } 546 else 547 { 548 error.SetErrorToGenericError(); 549 error.SetErrorString ("Couldn't write scalar: its size was zero"); 550 } 551 return; 552 } 553 554 void 555 IRMemoryMap::WritePointerToMemory (lldb::addr_t process_address, lldb::addr_t address, Error &error) 556 { 557 error.Clear(); 558 559 Scalar scalar(address); 560 561 WriteScalarToMemory(process_address, scalar, GetAddressByteSize(), error); 562 } 563 564 void 565 IRMemoryMap::ReadMemory (uint8_t *bytes, lldb::addr_t process_address, size_t size, Error &error) 566 { 567 error.Clear(); 568 569 AllocationMap::iterator iter = FindAllocation(process_address, size); 570 571 if (iter == m_allocations.end()) 572 { 573 lldb::ProcessSP process_sp = m_process_wp.lock(); 574 575 if (process_sp) 576 { 577 process_sp->ReadMemory(process_address, bytes, size, error); 578 return; 579 } 580 581 lldb::TargetSP target_sp = m_target_wp.lock(); 582 583 if (target_sp) 584 { 585 Address absolute_address(process_address); 586 target_sp->ReadMemory(absolute_address, false, bytes, size, error); 587 return; 588 } 589 590 error.SetErrorToGenericError(); 591 error.SetErrorString("Couldn't read: no allocation contains the target range, and neither the process nor the target exist"); 592 return; 593 } 594 595 Allocation &allocation = iter->second; 596 597 uint64_t offset = process_address - allocation.m_process_start; 598 599 if (offset > allocation.m_size) 600 { 601 error.SetErrorToGenericError(); 602 error.SetErrorString("Couldn't read: data is not in the allocation"); 603 return; 604 } 605 606 lldb::ProcessSP process_sp; 607 608 switch (allocation.m_policy) 609 { 610 default: 611 error.SetErrorToGenericError(); 612 error.SetErrorString("Couldn't read: invalid allocation policy"); 613 return; 614 case eAllocationPolicyHostOnly: 615 if (!allocation.m_data.GetByteSize()) 616 { 617 error.SetErrorToGenericError(); 618 error.SetErrorString("Couldn't read: data buffer is empty"); 619 return; 620 } 621 if (allocation.m_data.GetByteSize() < offset + size) 622 { 623 error.SetErrorToGenericError(); 624 error.SetErrorString("Couldn't read: not enough underlying data"); 625 return; 626 } 627 628 ::memcpy (bytes, allocation.m_data.GetBytes() + offset, size); 629 break; 630 case eAllocationPolicyMirror: 631 process_sp = m_process_wp.lock(); 632 if (process_sp) 633 { 634 process_sp->ReadMemory(process_address, bytes, size, error); 635 if (!error.Success()) 636 return; 637 } 638 else 639 { 640 if (!allocation.m_data.GetByteSize()) 641 { 642 error.SetErrorToGenericError(); 643 error.SetErrorString("Couldn't read: data buffer is empty"); 644 return; 645 } 646 ::memcpy (bytes, allocation.m_data.GetBytes() + offset, size); 647 } 648 break; 649 case eAllocationPolicyProcessOnly: 650 process_sp = m_process_wp.lock(); 651 if (process_sp) 652 { 653 process_sp->ReadMemory(process_address, bytes, size, error); 654 if (!error.Success()) 655 return; 656 } 657 break; 658 } 659 660 if (lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)) 661 { 662 log->Printf("IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIx64 ", 0x%" PRId64 ") came from [0x%" PRIx64 "..0x%" PRIx64 ")", 663 (uint64_t)process_address, 664 (uint64_t)bytes, 665 (uint64_t)size, 666 (uint64_t)allocation.m_process_start, 667 (uint64_t)allocation.m_process_start + (uint64_t)allocation.m_size); 668 } 669 } 670 671 void 672 IRMemoryMap::ReadScalarFromMemory (Scalar &scalar, lldb::addr_t process_address, size_t size, Error &error) 673 { 674 error.Clear(); 675 676 if (size > 0) 677 { 678 DataBufferHeap buf(size, 0); 679 ReadMemory(buf.GetBytes(), process_address, size, error); 680 681 if (!error.Success()) 682 return; 683 684 DataExtractor extractor(buf.GetBytes(), buf.GetByteSize(), GetByteOrder(), GetAddressByteSize()); 685 686 lldb::offset_t offset = 0; 687 688 switch (size) 689 { 690 default: 691 error.SetErrorToGenericError(); 692 error.SetErrorStringWithFormat("Couldn't read scalar: unsupported size %" PRIu64, (uint64_t)size); 693 return; 694 case 1: scalar = extractor.GetU8(&offset); break; 695 case 2: scalar = extractor.GetU16(&offset); break; 696 case 4: scalar = extractor.GetU32(&offset); break; 697 case 8: scalar = extractor.GetU64(&offset); break; 698 } 699 } 700 else 701 { 702 error.SetErrorToGenericError(); 703 error.SetErrorString ("Couldn't read scalar: its size was zero"); 704 } 705 return; 706 } 707 708 void 709 IRMemoryMap::ReadPointerFromMemory (lldb::addr_t *address, lldb::addr_t process_address, Error &error) 710 { 711 error.Clear(); 712 713 Scalar pointer_scalar; 714 ReadScalarFromMemory(pointer_scalar, process_address, GetAddressByteSize(), error); 715 716 if (!error.Success()) 717 return; 718 719 *address = pointer_scalar.ULongLong(); 720 721 return; 722 } 723 724 void 725 IRMemoryMap::GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Error &error) 726 { 727 error.Clear(); 728 729 if (size > 0) 730 { 731 AllocationMap::iterator iter = FindAllocation(process_address, size); 732 733 if (iter == m_allocations.end()) 734 { 735 error.SetErrorToGenericError(); 736 error.SetErrorStringWithFormat("Couldn't find an allocation containing [0x%" PRIx64 "..0x%" PRIx64 ")", process_address, process_address + size); 737 return; 738 } 739 740 Allocation &allocation = iter->second; 741 742 switch (allocation.m_policy) 743 { 744 default: 745 error.SetErrorToGenericError(); 746 error.SetErrorString("Couldn't get memory data: invalid allocation policy"); 747 return; 748 case eAllocationPolicyProcessOnly: 749 error.SetErrorToGenericError(); 750 error.SetErrorString("Couldn't get memory data: memory is only in the target"); 751 return; 752 case eAllocationPolicyMirror: 753 { 754 lldb::ProcessSP process_sp = m_process_wp.lock(); 755 756 if (!allocation.m_data.GetByteSize()) 757 { 758 error.SetErrorToGenericError(); 759 error.SetErrorString("Couldn't get memory data: data buffer is empty"); 760 return; 761 } 762 if (process_sp) 763 { 764 process_sp->ReadMemory(allocation.m_process_start, allocation.m_data.GetBytes(), allocation.m_data.GetByteSize(), error); 765 if (!error.Success()) 766 return; 767 uint64_t offset = process_address - allocation.m_process_start; 768 extractor = DataExtractor(allocation.m_data.GetBytes() + offset, size, GetByteOrder(), GetAddressByteSize()); 769 return; 770 } 771 } 772 case eAllocationPolicyHostOnly: 773 if (!allocation.m_data.GetByteSize()) 774 { 775 error.SetErrorToGenericError(); 776 error.SetErrorString("Couldn't get memory data: data buffer is empty"); 777 return; 778 } 779 uint64_t offset = process_address - allocation.m_process_start; 780 extractor = DataExtractor(allocation.m_data.GetBytes() + offset, size, GetByteOrder(), GetAddressByteSize()); 781 return; 782 } 783 } 784 else 785 { 786 error.SetErrorToGenericError(); 787 error.SetErrorString ("Couldn't get memory data: its size was zero"); 788 return; 789 } 790 } 791 792 793