Bug 732069 - Remove library extraction from APKOpen. r=glandium,blassey

This commit is contained in:
Wes Johnston 2012-03-08 10:25:44 -08:00
parent e2aba562a7
commit 9a38d7ae94
3 changed files with 4 additions and 134 deletions

View File

@ -140,7 +140,7 @@ public class GeckoAppShell
public static native void callObserver(String observerKey, String topic, String data);
public static native void removeObserver(String observerKey);
public static native void loadGeckoLibsNative(String apkName);
public static native void loadSQLiteLibsNative(String apkName, boolean shouldExtract);
public static native void loadSQLiteLibsNative(String apkName);
public static native void onChangeNetworkLinkStatus(String status);
public static void reportJavaCrash(Throwable e) {
@ -256,15 +256,6 @@ public class GeckoAppShell
File cacheFile = getCacheDir(context);
putenv("GRE_HOME=" + getGREDir(context).getPath());
File[] files = cacheFile.listFiles();
if (files != null) {
Iterator<File> cacheFiles = Arrays.asList(files).iterator();
while (cacheFiles.hasNext()) {
File libFile = cacheFiles.next();
if (libFile.getName().endsWith(".so"))
libFile.delete();
}
}
// setup the libs cache
String linkerCache = System.getenv("MOZ_LINKER_CACHE");
@ -356,7 +347,8 @@ public class GeckoAppShell
return;
loadMozGlue();
// the extract libs parameter is being removed in bug 732069
loadSQLiteLibsNative(apkName, false);
loadLibsSetup(context);
loadSQLiteLibsNative(apkName);
sSQLiteLibsLoaded = true;
}
}

View File

@ -313,79 +313,6 @@ SHELL_WRAPPER3(notifyReadingMessageListFailed, jint, jint, jlong)
static void * xul_handle = NULL;
static void * sqlite_handle = NULL;
#ifdef MOZ_OLD_LINKER
static time_t apk_mtime = 0;
#ifdef DEBUG
extern "C" int extractLibs = 1;
#else
extern "C" int extractLibs = 0;
#endif
static void
extractFile(const char * path, Zip::Stream &s)
{
uint32_t size = s.GetUncompressedSize();
struct stat status;
if (!stat(path, &status) &&
status.st_size == size &&
apk_mtime < status.st_mtime)
return;
int fd = open(path, O_CREAT | O_NOATIME | O_TRUNC | O_RDWR, S_IRWXU);
if (fd == -1) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't open %s to decompress library", path);
return;
}
if (ftruncate(fd, size) == -1) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't ftruncate %s to decompress library", path);
close(fd);
return;
}
void * buf = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (buf == (void *)-1) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't mmap decompression buffer");
close(fd);
return;
}
z_stream strm = {
next_in: (Bytef *)s.GetBuffer(),
avail_in: s.GetSize(),
total_in: 0,
next_out: (Bytef *)buf,
avail_out: size,
total_out: 0
};
int ret;
ret = inflateInit2(&strm, -MAX_WBITS);
if (ret != Z_OK)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflateInit failed: %s", strm.msg);
if (inflate(&strm, Z_FINISH) != Z_STREAM_END)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflate failed: %s", strm.msg);
if (strm.total_out != size)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "extracted %d, expected %d!", strm.total_out, size);
ret = inflateEnd(&strm);
if (ret != Z_OK)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflateEnd failed: %s", strm.msg);
close(fd);
#ifdef ANDROID_ARM_LINKER
/* We just extracted data that is going to be executed in the future.
* We thus need to ensure Instruction and Data cache coherency. */
cacheflush((unsigned) buf, (unsigned) buf + size, 0);
#endif
munmap(buf, size);
}
#endif
#if defined(MOZ_CRASHREPORTER) || defined(MOZ_OLD_LINKER)
static void
@ -510,25 +437,6 @@ static void * mozload(const char * path, Zip *zip)
if (!zip->GetStream(path, &s))
return NULL;
if (extractLibs) {
char fullpath[PATH_MAX];
snprintf(fullpath, PATH_MAX, "%s/%s", getenv("MOZ_LINKER_CACHE"), path);
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "resolved %s to %s", path, fullpath);
extractFile(fullpath, s);
handle = __wrap_dlopen(fullpath, RTLD_LAZY);
if (!handle)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't load %s because %s", fullpath, __wrap_dlerror());
#ifdef DEBUG
gettimeofday(&t1, 0);
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "%s: spent %d", path,
(((long long)t1.tv_sec * 1000000LL) +
(long long)t1.tv_usec) -
(((long long)t0.tv_sec * 1000000LL) +
(long long)t0.tv_usec));
#endif
return handle;
}
bool skipLibCache = false;
int fd;
void * buf = NULL;
@ -646,12 +554,6 @@ loadGeckoLibs(const char *apkName)
{
chdir(getenv("GRE_HOME"));
#ifdef MOZ_OLD_LINKER
struct stat status;
if (!stat(apkName, &status))
apk_mtime = status.st_mtime;
#endif
struct timeval t0, t1;
gettimeofday(&t0, 0);
struct rusage usage1;
@ -746,10 +648,6 @@ static void loadSQLiteLibs(const char *apkName)
#ifdef MOZ_OLD_LINKER
simple_linker_init();
struct stat status;
if (!stat(apkName, &status))
apk_mtime = status.st_mtime;
#endif
RefPtr<Zip> zip = new Zip(apkName);
@ -797,14 +695,7 @@ Java_org_mozilla_gecko_GeckoAppShell_loadGeckoLibsNative(JNIEnv *jenv, jclass jG
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_loadSQLiteLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jboolean jShouldExtract) {
if (jShouldExtract) {
#ifdef MOZ_OLD_LINKER
extractLibs = 1;
#else
putenv("MOZ_LINKER_EXTRACT=1");
#endif
}
putenv("MOZ_LINKER_EXTRACT=1");
const char* str;
// XXX: java doesn't give us true UTF8, we should figure out something
// better to do here

View File

@ -43,7 +43,6 @@ static const char *dl_errors[] = {
#define unlikely(expr) __builtin_expect (expr, 0)
static pthread_mutex_t dl_lock = PTHREAD_MUTEX_INITIALIZER;
extern int extractLibs;
static void set_dlerror(int err)
{
@ -54,9 +53,6 @@ static void set_dlerror(int err)
void *__wrap_dlopen(const char *filename, int flag)
{
if (extractLibs)
return dlopen(filename, flag);
soinfo *ret;
pthread_mutex_lock(&dl_lock);
@ -88,9 +84,6 @@ void *moz_mapped_dlopen(const char *filename, int flag,
const char *__wrap_dlerror(void)
{
if (extractLibs)
return dlerror();
const char *tmp = dl_err_str;
dl_err_str = NULL;
return (const char *)tmp;
@ -98,9 +91,6 @@ const char *__wrap_dlerror(void)
void *__wrap_dlsym(void *handle, const char *symbol)
{
if (extractLibs)
return dlsym(handle, symbol);
soinfo *found;
Elf32_Sym *sym;
unsigned bind;
@ -183,9 +173,6 @@ int __wrap_dladdr(void *addr, Dl_info *info)
int __wrap_dlclose(void *handle)
{
if (extractLibs)
return dlclose(handle);
pthread_mutex_lock(&dl_lock);
(void)unload_library((soinfo*)handle);
pthread_mutex_unlock(&dl_lock);