Skip to content

Commit

Permalink
Bug 648407 - Support loading the folded library on Android. r=blassey
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Mar 17, 2013
1 parent 4fbe923 commit 34ea330
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 26 additions & 2 deletions mozglue/android/APKOpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ JNI_Throw(JNIEnv* jenv, const char* classname, const char* msg)
#undef JNI_STUBS

static void * xul_handle = NULL;
#ifndef MOZ_FOLD_LIBS
static void * sqlite_handle = NULL;
static void * nss_handle = NULL;
static void * nspr_handle = NULL;
static void * plc_handle = NULL;
#else
#define sqlite_handle nss_handle
#define nspr_handle nss_handle
#define plc_handle nss_handle
#endif
static void * nss_handle = NULL;

template <typename T> inline void
xul_dlsym(const char *symbolName, T *value)
Expand Down Expand Up @@ -257,8 +263,18 @@ loadGeckoLibs(const char *apkName)
return SUCCESS;
}

static int loadSQLiteLibs(const char *apkName)
static mozglueresult loadNSSLibs(const char *apkName);

static mozglueresult
loadSQLiteLibs(const char *apkName)
{
if (sqlite_handle)
return SUCCESS;

#ifdef MOZ_FOLD_LIBS
if (loadNSSLibs(apkName) != SUCCESS)
return FAILURE;
#else
chdir(getenv("GRE_HOME"));

RefPtr<Zip> zip = ZipCollection::GetZip(apkName);
Expand All @@ -284,6 +300,7 @@ static int loadSQLiteLibs(const char *apkName)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libmozsqlite3!");
return FAILURE;
}
#endif

setup_sqlite_functions(sqlite_handle);
return SUCCESS;
Expand All @@ -292,6 +309,9 @@ static int loadSQLiteLibs(const char *apkName)
static mozglueresult
loadNSSLibs(const char *apkName)
{
if (nss_handle && nspr_handle && plc_handle)
return SUCCESS;

chdir(getenv("GRE_HOME"));

RefPtr<Zip> zip = ZipCollection::GetZip(apkName);
Expand All @@ -308,6 +328,7 @@ loadNSSLibs(const char *apkName)
nss_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
delete [] file;

#ifndef MOZ_FOLD_LIBS
file = new char[strlen(apkName) + sizeof("!/libnspr4.so")];
sprintf(file, "%s!/libnspr4.so", apkName);
nspr_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
Expand All @@ -317,6 +338,7 @@ loadNSSLibs(const char *apkName)
sprintf(file, "%s!/libplc4.so", apkName);
plc_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
delete [] file;
#endif

#ifdef MOZ_CRASHREPORTER
free(file_ids);
Expand All @@ -328,6 +350,7 @@ loadNSSLibs(const char *apkName)
return FAILURE;
}

#ifndef MOZ_FOLD_LIBS
if (!nspr_handle) {
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libnspr4!");
return FAILURE;
Expand All @@ -337,6 +360,7 @@ loadNSSLibs(const char *apkName)
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libplc4!");
return FAILURE;
}
#endif

return setup_nss_functions(nss_handle, nspr_handle, plc_handle);
}
Expand Down
4 changes: 4 additions & 0 deletions mozglue/android/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ DEFINES += \
-DANDROID_PACKAGE_NAME='"$(ANDROID_PACKAGE_NAME)"' \
$(NULL)

ifdef MOZ_FOLD_LIBS
DEFINES += -DMOZ_FOLD_LIBS
endif

CPPSRCS = \
nsGeckoUtils.cpp \
APKOpen.cpp \
Expand Down

0 comments on commit 34ea330

Please sign in to comment.