runtime_loader: Always map program image at random position
This commit is contained in:
@@ -505,7 +505,7 @@ load_image(char const* name, image_type type, const char* rpath,
|
|||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = map_image(fd, path, image, type == B_APP_IMAGE);
|
status = map_image(fd, path, image);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
FATAL("%s: Could not map image: %s\n", image->path, strerror(status));
|
FATAL("%s: Could not map image: %s\n", image->path, strerror(status));
|
||||||
status = B_ERROR;
|
status = B_ERROR;
|
||||||
|
|||||||
@@ -166,9 +166,9 @@ topological_sort(image_t* image, uint32 slot, image_t** initList,
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
get_image_region_load_address(image_t* image, uint32 index, long lastDelta,
|
get_image_region_load_address(image_t* image, uint32 index, long lastDelta,
|
||||||
bool fixed, addr_t& loadAddress, uint32& addressSpecifier)
|
addr_t& loadAddress, uint32& addressSpecifier)
|
||||||
{
|
{
|
||||||
if (image->dynamic_ptr != 0 && !fixed) {
|
if (image->dynamic_ptr != 0) {
|
||||||
// relocatable image... we can afford to place wherever
|
// relocatable image... we can afford to place wherever
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
// but only the first segment gets a free ride
|
// but only the first segment gets a free ride
|
||||||
@@ -283,7 +283,7 @@ put_image(image_t* image)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
map_image(int fd, char const* path, image_t* image, bool fixed)
|
map_image(int fd, char const* path, image_t* image)
|
||||||
{
|
{
|
||||||
// cut the file name from the path as base name for the created areas
|
// cut the file name from the path as base name for the created areas
|
||||||
const char* baseName = strrchr(path, '/');
|
const char* baseName = strrchr(path, '/');
|
||||||
@@ -301,16 +301,10 @@ map_image(int fd, char const* path, image_t* image, bool fixed)
|
|||||||
uint32 addressSpecifier = B_RANDOMIZED_ANY_ADDRESS;
|
uint32 addressSpecifier = B_RANDOMIZED_ANY_ADDRESS;
|
||||||
|
|
||||||
for (uint32 i = 0; i < image->num_regions; i++) {
|
for (uint32 i = 0; i < image->num_regions; i++) {
|
||||||
// for BeOS compatibility: if we load an old BeOS executable, we
|
|
||||||
// have to relocate it, if possible - we recognize it because the
|
|
||||||
// vmstart is set to 0 (hopefully always)
|
|
||||||
if (fixed && image->regions[i].vmstart == 0)
|
|
||||||
fixed = false;
|
|
||||||
|
|
||||||
uint32 regionAddressSpecifier;
|
uint32 regionAddressSpecifier;
|
||||||
get_image_region_load_address(image, i,
|
get_image_region_load_address(image, i,
|
||||||
i > 0 ? loadAddress - image->regions[i - 1].vmstart : 0,
|
i > 0 ? loadAddress - image->regions[i - 1].vmstart : 0,
|
||||||
fixed, loadAddress, regionAddressSpecifier);
|
loadAddress, regionAddressSpecifier);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
reservedAddress = loadAddress;
|
reservedAddress = loadAddress;
|
||||||
addressSpecifier = regionAddressSpecifier;
|
addressSpecifier = regionAddressSpecifier;
|
||||||
@@ -342,7 +336,7 @@ map_image(int fd, char const* path, image_t* image, bool fixed)
|
|||||||
baseName, i, (image->regions[i].flags & RFLAG_RW) ? "rw" : "ro");
|
baseName, i, (image->regions[i].flags & RFLAG_RW) ? "rw" : "ro");
|
||||||
|
|
||||||
get_image_region_load_address(image, i,
|
get_image_region_load_address(image, i,
|
||||||
i > 0 ? image->regions[i - 1].delta : 0, fixed, loadAddress,
|
i > 0 ? image->regions[i - 1].delta : 0, loadAddress,
|
||||||
addressSpecifier);
|
addressSpecifier);
|
||||||
|
|
||||||
// If the image position is arbitrary, we must let it point to the start
|
// If the image position is arbitrary, we must let it point to the start
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void delete_image_struct(image_t* image);
|
|||||||
void delete_image(image_t* image);
|
void delete_image(image_t* image);
|
||||||
void put_image(image_t* image);
|
void put_image(image_t* image);
|
||||||
|
|
||||||
status_t map_image(int fd, char const* path, image_t* image, bool fixed);
|
status_t map_image(int fd, char const* path, image_t* image);
|
||||||
void unmap_image(image_t* image);
|
void unmap_image(image_t* image);
|
||||||
void remap_images();
|
void remap_images();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user