From 4dafcc3b3b2af1f9c2f5d29d24fa3dedc4dc87d0 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 4 Feb 2010 19:01:11 +0000 Subject: [PATCH] Since we potentially split segments into different regions, we need to consider that when filling in the text and data ranges of the image info. This fixes #5361 and #5351, caused by libtracker.so not finding its own image. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35407 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/runtime_loader/images.cpp | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/system/runtime_loader/images.cpp b/src/system/runtime_loader/images.cpp index 516fad1284..2f1d0a4f3b 100644 --- a/src/system/runtime_loader/images.cpp +++ b/src/system/runtime_loader/images.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include #include @@ -449,11 +451,41 @@ register_image(image_t* image, int fd, const char* path) info.node = -1; } + // We may have split segments into separate regions. Compute the correct + // segments for the image info. + addr_t textBase = 0; + addr_t textEnd = 0; + addr_t dataBase = 0; + addr_t dataEnd = 0; + for (uint32 i= 0; i < image->num_regions; i++) { + addr_t base = image->regions[i].vmstart; + addr_t end = base + image->regions[i].vmsize; + if (image->regions[i].flags & RFLAG_RW) { + // data + if (dataBase == 0) { + dataBase = base; + dataEnd = end; + } else { + dataBase = std::min(dataBase, base); + dataEnd = std::max(dataEnd, end); + } + } else { + // text + if (textBase == 0) { + textBase = base; + textEnd = end; + } else { + textBase = std::min(textBase, base); + textEnd = std::max(textEnd, end); + } + } + } + strlcpy(info.name, path, sizeof(info.name)); - info.text = (void *)image->regions[0].vmstart; - info.text_size = image->regions[0].vmsize; - info.data = (void *)image->regions[1].vmstart; - info.data_size = image->regions[1].vmsize; + info.text = (void*)textBase; + info.text_size = textEnd - textBase; + info.data = (void*)dataBase; + info.data_size = dataEnd - dataBase; info.api_version = image->api_version; info.abi = image->abi; image->id = _kern_register_image(&info, sizeof(image_info));