From 5f614c31f5490d14213c4d662f8ae89e85cfdcd3 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Tue, 2 Jun 2020 12:01:59 -0400 Subject: [PATCH] Correct loader URI reporting - Check address is in the range of the mapped file. - Correct calculation of offset within the file. Change-Id: I848a3ead4422698c2ef1c140bc8ae5e000a717f7 --- runtime/hsa-runtime/core/runtime/amd_hsa_loader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/amd_hsa_loader.cpp b/runtime/hsa-runtime/core/runtime/amd_hsa_loader.cpp index 9663dfa540..263a4deaa3 100644 --- a/runtime/hsa-runtime/core/runtime/amd_hsa_loader.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_hsa_loader.cpp @@ -141,7 +141,7 @@ std::string CodeObjectReaderWrapper::GetUriFromMemory( } uint64_t MyAddress = reinterpret_cast(Mem); - if (!(MyAddress >= LowAddress && MyAddress <= HighAddress)) { + if (!(MyAddress >= LowAddress && (MyAddress + Size) <= HighAddress)) { continue; } @@ -157,9 +157,11 @@ std::string CodeObjectReaderWrapper::GetUriFromMemory( return GetUriFromMemoryBasic(Mem, Size); } + uint64_t UriOffset = Offset + MyAddress - LowAddress; + std::ostringstream UriStream; UriStream << EncodePathname(Pathname.c_str()); - UriStream << "#offset=" << Offset; + UriStream << "#offset=" << UriOffset; if (Size) { UriStream << "&size=" << Size; }