Bug 725231 - Stop reporting library mappings to the crash reporter. r=snorp

This is a rebase of a 7-year-old patch that was r=taras. Back then it
was waiting for breakpad changes that never were reviewed. However,
since then, bug 1486524 made the linker always map uncompressed files
directly, making it less necessary to report the library mappings to
the crash reporter, and bug 1291377 disabled the linker altogether on
Android 6.0+, which makes report_mapping unused at all in that case.

Differential Revision: https://phabricator.services.mozilla.com/D81025
This commit is contained in:
Mike Hommey 2020-07-06 14:38:29 +00:00
parent bcdae74a2f
commit 200194bccd
2 changed files with 11 additions and 78 deletions

View File

@ -18,18 +18,6 @@ using namespace Elf;
/* TODO: Fill ElfLoader::Singleton.lastError on errors. */
/* Function used to report library mappings from the custom linker to Gecko
* crash reporter */
#ifdef ANDROID
extern "C" {
void report_mapping(char* name, void* base, uint32_t len, uint32_t offset);
void delete_mapping(const char* name);
}
#else
# define report_mapping(...)
# define delete_mapping(...)
#endif
const Ehdr* Ehdr::validate(const void* buf) {
if (!buf || buf == MAP_FAILED) return nullptr;
@ -207,9 +195,6 @@ already_AddRefed<LibHandle> CustomElf::Load(Mappable* mappable,
/* We're not going to mmap anymore */
mappable->finalize();
report_mapping(const_cast<char*>(elf->GetName()), elf->base,
(max_vaddr + PAGE_SIZE - 1) & PAGE_MASK, 0);
elf->l_addr = elf->base;
elf->l_name = elf->GetPath();
elf->l_ld = elf->GetPtr<Dyn>(dyn->p_vaddr);
@ -257,7 +242,6 @@ CustomElf::~CustomElf() {
* calls destructors once, so call it in all cases. */
ElfLoader::__wrap_cxa_finalize(this);
ElfLoader::Singleton.Forget(this);
delete_mapping(GetName());
}
void* CustomElf::GetSymbolPtrInDeps(const char* symbol) const {

View File

@ -241,55 +241,11 @@ class _MappableBuffer : public MappedPtr {
*/
static _MappableBuffer* Create(const char* name, size_t length) {
AutoCloseFD fd;
const char* ident;
#ifdef ANDROID
/* On Android, initialize an ashmem region with the given length */
fd = mozilla::android::ashmem_create(name, length);
/* The Gecko crash reporter is confused by adjacent memory mappings of
* the same file and chances are we're going to map from the same file
* descriptor right away. To avoid problems with the crash reporter,
* create an empty anonymous page before or after the ashmem mapping,
* depending on how mappings grow in the address space.
*/
# if defined(__arm__)
// Address increases on ARM.
void* buf = ::mmap(nullptr, length + PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (buf != MAP_FAILED) {
::mmap(AlignedEndPtr(reinterpret_cast<char*>(buf) + length, PAGE_SIZE),
PAGE_SIZE, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1,
0);
DEBUG_LOG("Decompression buffer of size 0x%" PRIxPTR
" in ashmem \"%s\", mapped @%p",
length, name, buf);
return new _MappableBuffer(fd.forget(), buf, length);
}
# elif defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
// Address decreases on x86, x86-64, and AArch64.
size_t anon_mapping_length = length + PAGE_SIZE;
void* buf = ::mmap(nullptr, anon_mapping_length, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf != MAP_FAILED) {
char* first_page = reinterpret_cast<char*>(buf);
char* map_page = first_page + PAGE_SIZE;
void* actual_buf = ::mmap(map_page, length, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_SHARED, fd, 0);
if (actual_buf == MAP_FAILED) {
::munmap(buf, anon_mapping_length);
DEBUG_LOG("Fixed allocation of decompression buffer at %p failed",
map_page);
return nullptr;
}
DEBUG_LOG("Decompression buffer of size 0x%" PRIxPTR
" in ashmem \"%s\", mapped @%p",
length, name, actual_buf);
return new _MappableBuffer(fd.forget(), actual_buf, length);
}
# else
# error need to add a case for your CPU
# endif
ident = name;
#else
/* On Linux, use /dev/shm as base directory for temporary files, assuming
* it's on tmpfs */
@ -300,15 +256,21 @@ class _MappableBuffer : public MappedPtr {
if (fd == -1) return nullptr;
unlink(path);
ftruncate(fd, length);
ident = path;
#endif
void* buf =
::mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buf != MAP_FAILED) {
DEBUG_LOG("Decompression buffer of size %ld in \"%s\", mapped @%p",
length, path, buf);
DEBUG_LOG("Decompression buffer of size 0x%" PRIxPTR " in "
#ifdef ANDROID
"ashmem "
#endif
"\"%s\", mapped @%p",
length, ident, buf);
return new _MappableBuffer(fd.forget(), buf, length);
}
#endif
return nullptr;
}
@ -326,19 +288,6 @@ class _MappableBuffer : public MappedPtr {
return ::mmap(const_cast<void*>(addr), length, prot, flags, fd, offset);
}
#ifdef ANDROID
~_MappableBuffer() {
/* Free the additional page we allocated. See _MappableBuffer::Create */
# if defined(__arm__)
::munmap(AlignedEndPtr(*this + GetLength(), PAGE_SIZE), PAGE_SIZE);
# elif defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
::munmap(*this - PAGE_SIZE, GetLength() + PAGE_SIZE);
# else
# error need to add a case for your CPU
# endif
}
#endif
private:
_MappableBuffer(int fd, void* buf, size_t length)
: MappedPtr(buf, length), fd(fd) {}