@@ -138,7 +138,8 @@ CrashInfo::EnumMemoryRegion(
138138 /* [in] */ CLRDATA_ADDRESS address,
139139 /* [in] */ ULONG32 size)
140140{
141- m_enumMemoryPagesAdded += InsertMemoryRegion ((ULONG_PTR)address, size);
141+ address = CONVERT_FROM_SIGN_EXTENDED (address);
142+ m_enumMemoryPagesAdded += InsertMemoryRegion (address, size);
142143 return S_OK;
143144}
144145
@@ -449,21 +450,23 @@ CrashInfo::EnumerateManagedModules()
449450 DacpGetModuleData moduleData;
450451 if (SUCCEEDED (hr = moduleData.Request (pClrDataModule.GetPtr ())))
451452 {
452- TRACE (" MODULE: %" PRIA PRIx64 " dyn %d inmem %d file %d pe %" PRIA PRIx64 " pdb %" PRIA PRIx64, (uint64_t )moduleData.LoadedPEAddress , moduleData.IsDynamic ,
453+ uint64_t loadedPEAddress = CONVERT_FROM_SIGN_EXTENDED (moduleData.LoadedPEAddress );
454+
455+ TRACE (" MODULE: %" PRIA PRIx64 " dyn %d inmem %d file %d pe %" PRIA PRIx64 " pdb %" PRIA PRIx64, loadedPEAddress, moduleData.IsDynamic ,
453456 moduleData.IsInMemory , moduleData.IsFileLayout , (uint64_t )moduleData.PEAssembly , (uint64_t )moduleData.InMemoryPdbAddress );
454457
455- if (!moduleData.IsDynamic && moduleData. LoadedPEAddress != 0 )
458+ if (!moduleData.IsDynamic && loadedPEAddress != 0 )
456459 {
457460 ArrayHolder<WCHAR> wszUnicodeName = new WCHAR[MAX_LONGPATH + 1 ];
458461 if (SUCCEEDED (hr = pClrDataModule->GetFileName (MAX_LONGPATH, nullptr , wszUnicodeName)))
459462 {
460463 std::string moduleName = ConvertString (wszUnicodeName.GetPtr ());
461464
462465 // Change the module mapping name
463- AddOrReplaceModuleMapping (moduleData. LoadedPEAddress , moduleData.LoadedPESize , moduleName);
466+ AddOrReplaceModuleMapping (loadedPEAddress , moduleData.LoadedPESize , moduleName);
464467
465468 // Add managed module info
466- AddModuleInfo (true , moduleData. LoadedPEAddress , pClrDataModule, moduleName);
469+ AddModuleInfo (true , loadedPEAddress , pClrDataModule, moduleName);
467470 }
468471 else {
469472 TRACE (" \n Module.GetFileName FAILED %08x\n " , hr);
@@ -517,21 +520,21 @@ CrashInfo::UnwindAllThreads()
517520// Replace an existing module mapping with one with a different name.
518521//
519522void
520- CrashInfo::AddOrReplaceModuleMapping (CLRDATA_ADDRESS baseAddress, ULONG64 size, const std::string& name)
523+ CrashInfo::AddOrReplaceModuleMapping (uint64_t baseAddress, uint64_t size, const std::string& name)
521524{
522525 // Round to page boundary (single-file managed assemblies are not page aligned)
523- ULONG_PTR start = ((ULONG_PTR) baseAddress) & PAGE_MASK;
526+ uint64_t start = baseAddress & PAGE_MASK;
524527 assert (start > 0 );
525528
526529 // Round up to page boundary
527- ULONG_PTR end = ((baseAddress + size) + (PAGE_SIZE - 1 )) & PAGE_MASK;
530+ uint64_t end = ((baseAddress + size) + (PAGE_SIZE - 1 )) & PAGE_MASK;
528531 assert (end > 0 );
529532
530- uint32_t flags = GetMemoryRegionFlags ((ULONG_PTR) baseAddress);
533+ uint32_t flags = GetMemoryRegionFlags (baseAddress);
531534
532- // Make sure that the page containing the PE header for the managed asseblies is in the dump
535+ // Make sure that the page containing the PE header for the managed assemblies is in the dump
533536 // especially on MacOS where they are added artificially.
534- MemoryRegion header (flags, start, start + PAGE_SIZE);
537+ ModuleRegion header (flags, start, start + PAGE_SIZE);
535538 InsertMemoryRegion (header);
536539
537540 // Add or change the module mapping for this PE image. The managed assembly images may already
@@ -541,7 +544,7 @@ CrashInfo::AddOrReplaceModuleMapping(CLRDATA_ADDRESS baseAddress, ULONG64 size,
541544 if (found == m_moduleMappings.end ())
542545 {
543546 // On MacOS the assemblies are always added.
544- MemoryRegion newRegion (flags, start, end, 0 , name);
547+ ModuleRegion newRegion (flags, start, end, 0 , name);
545548 m_moduleMappings.insert (newRegion);
546549 m_cbModuleMappings += newRegion.Size ();
547550
@@ -552,7 +555,7 @@ CrashInfo::AddOrReplaceModuleMapping(CLRDATA_ADDRESS baseAddress, ULONG64 size,
552555 else if (found->FileName ().compare (name) != 0 )
553556 {
554557 // Create the new memory region with the managed assembly name.
555- MemoryRegion newRegion (*found, name);
558+ ModuleRegion newRegion (*found, name);
556559
557560 // Remove and cleanup the old one
558561 m_moduleMappings.erase (found);
@@ -648,15 +651,15 @@ CrashInfo::AddModuleInfo(bool isManaged, uint64_t baseAddress, IXCLRDataModule*
648651 if (isManaged)
649652 {
650653 IMAGE_DOS_HEADER dosHeader;
651- if (ReadMemory (( void *) baseAddress, &dosHeader, sizeof (dosHeader)))
654+ if (ReadMemory (baseAddress, &dosHeader, sizeof (dosHeader)))
652655 {
653656 WORD magic;
654- if (ReadMemory (( void *)( baseAddress + dosHeader.e_lfanew + offsetof (IMAGE_NT_HEADERS, OptionalHeader.Magic ) ), &magic, sizeof (magic)))
657+ if (ReadMemory (baseAddress + dosHeader.e_lfanew + offsetof (IMAGE_NT_HEADERS, OptionalHeader.Magic ), &magic, sizeof (magic)))
655658 {
656659 if (magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
657660 {
658661 IMAGE_NT_HEADERS32 header;
659- if (ReadMemory (( void *)( baseAddress + dosHeader.e_lfanew ) , &header, sizeof (header)))
662+ if (ReadMemory (baseAddress + dosHeader.e_lfanew , &header, sizeof (header)))
660663 {
661664 imageSize = header.OptionalHeader .SizeOfImage ;
662665 timeStamp = header.FileHeader .TimeDateStamp ;
@@ -665,7 +668,7 @@ CrashInfo::AddModuleInfo(bool isManaged, uint64_t baseAddress, IXCLRDataModule*
665668 else if (magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
666669 {
667670 IMAGE_NT_HEADERS64 header;
668- if (ReadMemory (( void *)( baseAddress + dosHeader.e_lfanew ) , &header, sizeof (header)))
671+ if (ReadMemory (baseAddress + dosHeader.e_lfanew , &header, sizeof (header)))
669672 {
670673 imageSize = header.OptionalHeader .SizeOfImage ;
671674 timeStamp = header.FileHeader .TimeDateStamp ;
@@ -694,15 +697,15 @@ CrashInfo::AddModuleInfo(bool isManaged, uint64_t baseAddress, IXCLRDataModule*
694697// ReadMemory from target and add to memory regions list
695698//
696699bool
697- CrashInfo::ReadMemory (void * address, void * buffer, size_t size)
700+ CrashInfo::ReadMemory (uint64_t address, void * buffer, size_t size)
698701{
699702 size_t read = 0 ;
700703 if (!ReadProcessMemory (address, buffer, size, &read))
701704 {
702705 return false ;
703706 }
704707 assert (read == size);
705- InsertMemoryRegion (reinterpret_cast < uint64_t >( address) , read);
708+ InsertMemoryRegion (address, read);
706709 return true ;
707710}
708711
@@ -712,6 +715,7 @@ CrashInfo::ReadMemory(void* address, void* buffer, size_t size)
712715int
713716CrashInfo::InsertMemoryRegion (uint64_t address, size_t size)
714717{
718+ assert (address == CONVERT_FROM_SIGN_EXTENDED (address));
715719 assert (size < UINT_MAX);
716720
717721 // Round to page boundary
@@ -831,7 +835,7 @@ CrashInfo::PageCanBeRead(uint64_t start)
831835{
832836 BYTE buffer[1 ];
833837 size_t read;
834- return ReadProcessMemory (( void *) start, buffer, 1 , &read);
838+ return ReadProcessMemory (start, buffer, 1 , &read);
835839}
836840
837841//
@@ -889,6 +893,23 @@ CrashInfo::CombineMemoryRegions()
889893 }
890894}
891895
896+ //
897+ // Searches for a module region for a given address.
898+ //
899+ const ModuleRegion*
900+ CrashInfo::SearchModuleRegions (const ModuleRegion& search)
901+ {
902+ std::set<ModuleRegion>::iterator found = m_moduleMappings.find (search);
903+ for (; found != m_moduleMappings.end (); found++)
904+ {
905+ if (search.StartAddress () >= found->StartAddress () && search.StartAddress () < found->EndAddress ())
906+ {
907+ return &*found;
908+ }
909+ }
910+ return nullptr ;
911+ }
912+
892913//
893914// Searches for a memory region given an address.
894915//
0 commit comments