Bug 603592 - Report mapping to crash reporter, r=ted a=blocking-fennec

This commit is contained in:
Michael Wu 2010-10-20 20:44:03 -04:00
Родитель 7c96c0ef20
Коммит eca11b20b3
6 изменённых файлов: 135 добавлений и 7 удалений

Просмотреть файл

@ -48,12 +48,15 @@
#include <unistd.h>
#include <zlib.h>
#include "dlfcn.h"
#include "APKOpen.h"
/* compression methods */
#define STORE 0
#define DEFLATE 8
#define LZMA 14
#define NS_EXPORT __attribute__ ((visibility("default")))
struct local_file_header {
uint32_t signature;
uint16_t min_version;
@ -106,6 +109,7 @@ struct cdir_end {
static size_t zip_size;
static int zip_fd;
NS_EXPORT struct mapping_info * lib_mapping;
static void * map_file (const char *file)
{
@ -173,8 +177,6 @@ static uint32_t simple_write(int fd, const void *buf, uint32_t count)
return out_offset;
}
#define NS_EXPORT __attribute__ ((visibility("default")))
#define SHELL_WRAPPER0(name) \
typedef void (*name ## _t)(JNIEnv *, jclass); \
static name ## _t f_ ## name; \
@ -393,15 +395,58 @@ static void * mozload(const char * path, void *zip,
return handle;
}
static void *
extractBuf(const char * path, void *zip,
struct cdir_entry *cdir_start, uint16_t cdir_entries)
{
struct cdir_entry *entry = find_cdir_entry(cdir_start, cdir_entries, path);
struct local_file_header *file = (struct local_file_header *)(zip + letoh32(entry->offset));
void * data = ((void *)&file->data) + letoh16(file->filename_size) + letoh16(file->extra_field_size);
void * buf = malloc(letoh32(entry->uncompressed_size));
if (buf == (void *)-1) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't alloc decompression buffer for %s", path);
return NULL;
}
if (letoh16(file->compression) == DEFLATE)
extractLib(entry, data, buf);
else
memcpy(buf, data, letoh32(entry->uncompressed_size));
return buf;
}
static int mapping_count = 0;
static char *file_ids = NULL;
#define MAX_MAPPING_INFO 32
extern "C" void
report_mapping(char *name, void *base, uint32_t len, uint32_t offset)
{
if (!file_ids || mapping_count >= MAX_MAPPING_INFO)
return;
struct mapping_info *info = &lib_mapping[mapping_count++];
info->name = strdup(name);
info->base = (uintptr_t)base;
info->len = len;
info->offset = offset;
char * entry = strstr(file_ids, name);
if (entry)
info->file_id = strndup(entry + strlen(name) + 1, 32);
}
extern "C" void simple_linker_init(void);
static void
loadLibs(const char *apkName)
{
simple_linker_init();
chdir("/data/data/org.mozilla.fennec");
simple_linker_init();
struct stat status;
if (!stat(apkName, &status))
apk_mtime = status.st_mtime;
@ -426,6 +471,11 @@ loadLibs(const char *apkName)
struct cdir_entry *cdir_start = (struct cdir_entry *)(zip + cdir_offset);
#ifdef MOZ_CRASHREPORTER
lib_mapping = (struct mapping_info *)calloc(MAX_MAPPING_INFO, sizeof(*lib_mapping));
file_ids = (char *)extractBuf("lib.id", zip, cdir_start, cdir_entries);
#endif
#define MOZLOAD(name) mozload("lib/lib" name ".so", zip, cdir_start, cdir_entries)
MOZLOAD("mozalloc");
MOZLOAD("nspr4");
@ -445,6 +495,11 @@ loadLibs(const char *apkName)
close(zip_fd);
#ifdef MOZ_CRASHREPORTER
free(file_ids);
file_ids = NULL;
#endif
if (!xul_handle)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libxul!");
@ -459,7 +514,6 @@ loadLibs(const char *apkName)
GETFUNC(callObserver);
GETFUNC(removeObserver);
#undef GETFUNC
#ifdef DEBUG
gettimeofday(&t1, 0);
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "spent %d total",

Просмотреть файл

@ -0,0 +1,50 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Android code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Wu <mwu@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef APKOpen_h
#define APKOpen_h
struct mapping_info {
char * name;
char * file_id;
uintptr_t base;
size_t len;
size_t offset;
};
extern struct mapping_info * lib_mapping;
#endif /* APKOpen_h */

Просмотреть файл

@ -69,6 +69,8 @@ CSRCS = \
rt.c \
$(NULL)
EXPORTS = APKOpen.h
EXTRA_DSO_LDOPTS += $(ZLIB_LIBS)
WRAP_MALLOC_LIB =

Просмотреть файл

@ -82,6 +82,8 @@
* having a hard limit (64)
*/
/* Implemented in APKOpen */
extern void report_mapping(char *name, void *base, uint32_t len, uint32_t offset);
static int link_image(soinfo *si, unsigned wr_offset);
@ -135,6 +137,7 @@ unsigned bitmask[4096];
#define PT_ARM_EXIDX 0x70000001 /* .ARM.exidx segment */
#endif
#ifndef MOZ_LINKER
#define HOODLUM(name, ret, ...) \
ret name __VA_ARGS__ \
{ \
@ -146,6 +149,7 @@ HOODLUM(malloc, void *, (size_t size));
HOODLUM(free, void, (void *ptr));
HOODLUM(realloc, void *, (void *ptr, size_t size));
HOODLUM(calloc, void *, (size_t cnt, size_t size));
#endif
static char tmp_err_buf[768];
static char __linker_dl_err_buf[768];
@ -945,6 +949,8 @@ load_segments(int fd, size_t offset, void *header, soinfo *si)
goto fail;
}
report_mapping(si->name, pbase, len, phdr->p_offset & (~PAGE_MASK));
/* If 'len' didn't end on page boundary, and it's a writable
* segment, zero-fill the rest. */
if ((len & PAGE_MASK) && (phdr->p_flags & PF_W))

Просмотреть файл

@ -170,6 +170,7 @@ DIST_FILES = \
modules \
res \
lib \
lib.id \
extensions \
application.ini \
platform.ini \
@ -200,6 +201,11 @@ INNER_MAKE_PACKAGE = \
mkdir -p lib/armeabi && \
cp lib*.so lib && \
mv lib/libmozutils.so lib/armeabi && \
rm -f lib.id && \
for SOMELIB in lib/*.so ; \
do \
printf "`basename $$SOMELIB`:`$(_ABS_DIST)/host/bin/file_id $$SOMELIB`\n" >> lib.id ; \
done && \
$(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ $(DIST_FILES) -x $(NON_DIST_FILES) ) && \
rm -f $(_ABS_DIST)/gecko.apk && \
$(APKBUILDER) $(_ABS_DIST)/gecko.apk -v $(APKBUILDER_FLAGS) -z $(_ABS_DIST)/gecko.ap_ -f $(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH)/classes.dex && \

Просмотреть файл

@ -52,6 +52,8 @@
#include "nsILocalFile.h"
#include "nsAppRunner.h"
#include "AndroidBridge.h"
#include "APKOpen.h"
#include "nsExceptionHandler.h"
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args)
@ -72,6 +74,15 @@ struct AutoAttachJavaThread {
static void*
GeckoStart(void *data)
{
#ifdef MOZ_CRASHREPORTER
struct mapping_info *info = lib_mapping;
while (info->name) {
CrashReporter::AddLibraryMapping(info->name, info->file_id, info->base,
info->len, info->offset);
info++;
}
#endif
AutoAttachJavaThread attacher;
if (!attacher.attached)
return 0;
@ -109,7 +120,6 @@ GeckoStart(void *data)
appData->xreDirectory = xreDir.get();
nsTArray<char *> targs;
char *arg = strtok(static_cast<char *>(data), " ");
while (arg) {