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
This commit is contained in:
Ingo Weinhold 2005-11-14 10:24:45 +00:00
parent d2718b5d34
commit e84b16339c

View File

@ -213,18 +213,36 @@ elf_load_image(int fd, preloaded_image *image)
region->start, region->size, region->delta)); 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), // if image->text_region.start == NULL (image is relocatable),
// platform_allocate_region() automatically allocates an address // platform_allocate_region() automatically allocates an address
totalSize = image->text_region.size + image->data_region.size; if (platform_allocate_region((void **)&firstRegion->start, totalSize,
if (platform_allocate_region((void **)&image->text_region.start, totalSize,
B_READ_AREA | B_WRITE_AREA) < B_OK) { B_READ_AREA | B_WRITE_AREA) < B_OK) {
status = B_NO_MEMORY; status = B_NO_MEMORY;
goto error1; goto error1;
} }
// initialize the region pointers to the allocated region // initialize the region pointers to the allocated region
// (text region comes first) secondRegion->start += firstRegion->start + firstRegion->delta;
image->data_region.start = image->text_region.start + image->text_region.size;
image->data_region.delta += image->data_region.start; image->data_region.delta += image->data_region.start;
image->text_region.delta += image->text_region.start; image->text_region.delta += image->text_region.start;