Implement load at fixed address feature

Bug: http://b/24683631
Change-Id: I3a39ab526c8f9e213339b60e135e5459d0f41381
This commit is contained in:
Dmitriy Ivanov
2015-10-07 16:34:20 -07:00
parent 6a4ddeb56e
commit 126af757c6
4 changed files with 77 additions and 3 deletions

View File

@@ -1995,12 +1995,20 @@ soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo,
DL_ERR("invalid extended flags to android_dlopen_ext: 0x%" PRIx64, extinfo->flags);
return nullptr;
}
if ((extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) == 0 &&
(extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET) != 0) {
DL_ERR("invalid extended flag combination (ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET without "
"ANDROID_DLEXT_USE_LIBRARY_FD): 0x%" PRIx64, extinfo->flags);
return nullptr;
}
if ((extinfo->flags & ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS) != 0 &&
(extinfo->flags & (ANDROID_DLEXT_RESERVED_ADDRESS | ANDROID_DLEXT_RESERVED_ADDRESS_HINT)) != 0) {
DL_ERR("invalid extended flag combination: ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS is not "
"compatible with ANDROID_DLEXT_RESERVED_ADDRESS/ANDROID_DLEXT_RESERVED_ADDRESS_HINT");
return nullptr;
}
}
ProtectedDataGuard guard;

View File

@@ -386,8 +386,9 @@ bool ElfReader::ReserveAddressSpace(const android_dlextinfo* extinfo) {
void* start;
size_t reserved_size = 0;
bool reserved_hint = true;
bool strict_hint = false;
// Assume position independent executable by default.
uint8_t* mmap_hint = nullptr;
void* mmap_hint = nullptr;
if (extinfo != nullptr) {
if (extinfo->flags & ANDROID_DLEXT_RESERVED_ADDRESS) {
@@ -397,8 +398,11 @@ bool ElfReader::ReserveAddressSpace(const android_dlextinfo* extinfo) {
reserved_size = extinfo->reserved_size;
}
if ((extinfo->flags & ANDROID_DLEXT_FORCE_FIXED_VADDR) != 0) {
if (addr != nullptr && (extinfo->flags & ANDROID_DLEXT_FORCE_FIXED_VADDR) != 0) {
mmap_hint = addr;
} else if ((extinfo->flags & ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS) != 0) {
mmap_hint = extinfo->reserved_addr;
strict_hint = true;
}
}
@@ -414,6 +418,12 @@ bool ElfReader::ReserveAddressSpace(const android_dlextinfo* extinfo) {
DL_ERR("couldn't reserve %zd bytes of address space for \"%s\"", load_size_, name_.c_str());
return false;
}
if (strict_hint && (start != mmap_hint)) {
munmap(start, load_size_);
DL_ERR("couldn't reserve %zd bytes of address space at %p for \"%s\"",
load_size_, mmap_hint, name_.c_str());
return false;
}
} else {
start = extinfo->reserved_addr;
}