From e84b16339c00a23c38c7d8b5b20da2d2232068ee Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 14 Nov 2005 10:24:45 +0000 Subject: [PATCH] Fixed loading of modules whose text and data segments have a little space inbetween. The segments can be in inverse order now, too. The same should be done in the kernel, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14907 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/boot/loader/elf.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/system/boot/loader/elf.cpp b/src/system/boot/loader/elf.cpp index 3017540b91..ca23b91759 100644 --- a/src/system/boot/loader/elf.cpp +++ b/src/system/boot/loader/elf.cpp @@ -213,18 +213,36 @@ elf_load_image(int fd, preloaded_image *image) region->start, region->size, region->delta)); } + // get the segment order + elf_region *firstRegion; + elf_region *secondRegion; + if (image->text_region.start < image->data_region.start) { + firstRegion = &image->text_region; + secondRegion = &image->data_region; + } else { + firstRegion = &image->data_region; + secondRegion = &image->text_region; + } + + // Check whether the segments have an unreasonable amount of unused space + // inbetween. + totalSize = secondRegion->start + secondRegion->size - firstRegion->start; + if (totalSize > image->text_region.size + image->data_region.size + + 8 * 1024) { + status = B_BAD_DATA; + goto error1; + } + // if image->text_region.start == NULL (image is relocatable), // platform_allocate_region() automatically allocates an address - totalSize = image->text_region.size + image->data_region.size; - if (platform_allocate_region((void **)&image->text_region.start, totalSize, + if (platform_allocate_region((void **)&firstRegion->start, totalSize, B_READ_AREA | B_WRITE_AREA) < B_OK) { status = B_NO_MEMORY; goto error1; } // initialize the region pointers to the allocated region - // (text region comes first) - image->data_region.start = image->text_region.start + image->text_region.size; + secondRegion->start += firstRegion->start + firstRegion->delta; image->data_region.delta += image->data_region.start; image->text_region.delta += image->text_region.start;