2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2010-10-29 23:22:28 +04:00
|
|
|
/*
|
|
|
|
* This custom library loading code is only meant to be called
|
|
|
|
* during initialization. As a result, it takes no special
|
|
|
|
* precautions to be threadsafe. Any of the library loading functions
|
|
|
|
* like mozload should not be available to other code.
|
|
|
|
*/
|
|
|
|
|
2010-10-15 22:27:57 +04:00
|
|
|
#include <jni.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mman.h>
|
2010-10-29 23:22:28 +04:00
|
|
|
#include <sys/limits.h>
|
2010-10-15 22:27:57 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2010-10-29 23:22:28 +04:00
|
|
|
#include <stdlib.h>
|
2010-10-15 22:27:57 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <zlib.h>
|
|
|
|
#include "dlfcn.h"
|
2010-10-21 04:44:03 +04:00
|
|
|
#include "APKOpen.h"
|
2011-01-13 00:08:28 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
2012-01-11 14:11:02 +04:00
|
|
|
#include "Zip.h"
|
2012-01-20 00:19:56 +04:00
|
|
|
#include "sqlite3.h"
|
|
|
|
#include "SQLiteBridge.h"
|
2012-03-08 22:25:44 +04:00
|
|
|
#include "NSSBridge.h"
|
2012-01-20 12:49:07 +04:00
|
|
|
#include "ElfLoader.h"
|
2012-02-22 11:12:15 +04:00
|
|
|
#include "application.ini.h"
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2011-11-18 11:54:17 +04:00
|
|
|
/* Android headers don't define RUSAGE_THREAD */
|
|
|
|
#ifndef RUSAGE_THREAD
|
|
|
|
#define RUSAGE_THREAD 1
|
|
|
|
#endif
|
|
|
|
|
2012-03-13 12:49:18 +04:00
|
|
|
extern "C" {
|
|
|
|
/*
|
|
|
|
* To work around http://code.google.com/p/android/issues/detail?id=23203
|
|
|
|
* we don't link with the crt objects. In some configurations, this means
|
|
|
|
* a lack of the __dso_handle symbol because it is defined there, and
|
|
|
|
* depending on the android platform and ndk versions used, it may or may
|
|
|
|
* not be defined in libc.so. In the latter case, we fail to link. Defining
|
|
|
|
* it here as weak makes us provide the symbol when it's not provided by
|
|
|
|
* the crt objects, making the change transparent for future NDKs that
|
|
|
|
* would fix the original problem. On older NDKs, it is not a problem
|
|
|
|
* either because the way __dso_handle was used was already broken (and
|
|
|
|
* the custom linker works around it).
|
|
|
|
*/
|
|
|
|
NS_EXPORT __attribute__((weak)) void *__dso_handle;
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
typedef int mozglueresult;
|
2012-06-19 11:16:33 +04:00
|
|
|
typedef int64_t MOZTime;
|
2012-03-08 22:25:44 +04:00
|
|
|
|
2011-11-18 11:54:37 +04:00
|
|
|
enum StartupEvent {
|
|
|
|
#define mozilla_StartupTimeline_Event(ev, z) ev,
|
|
|
|
#include "StartupTimeline.h"
|
|
|
|
#undef mozilla_StartupTimeline_Event
|
2012-06-18 20:06:59 +04:00
|
|
|
MAX_STARTUP_EVENT_ID
|
2011-11-18 11:54:37 +04:00
|
|
|
};
|
|
|
|
|
2012-02-13 18:49:45 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-06-19 11:16:33 +04:00
|
|
|
static MOZTime MOZ_Now()
|
2011-11-18 11:54:37 +04:00
|
|
|
{
|
2012-06-19 11:16:33 +04:00
|
|
|
struct timeval tm;
|
|
|
|
gettimeofday(&tm, 0);
|
|
|
|
return (((MOZTime)tm.tv_sec * 1000000LL) + (MOZTime)tm.tv_usec);
|
2011-11-18 11:54:37 +04:00
|
|
|
}
|
|
|
|
|
2011-05-26 00:54:30 +04:00
|
|
|
static struct mapping_info * lib_mapping = NULL;
|
2010-10-29 23:22:28 +04:00
|
|
|
|
|
|
|
NS_EXPORT const struct mapping_info *
|
|
|
|
getLibraryMapping()
|
|
|
|
{
|
|
|
|
return lib_mapping;
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
void
|
|
|
|
JNI_Throw(JNIEnv* jenv, const char* classname, const char* msg)
|
|
|
|
{
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Throw\n");
|
|
|
|
jclass cls = jenv->FindClass(classname);
|
|
|
|
if (cls == NULL) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't find exception class (or exception pending) %s\n", classname);
|
|
|
|
exit(FAILURE);
|
|
|
|
}
|
|
|
|
int rc = jenv->ThrowNew(cls, msg);
|
|
|
|
if (rc < 0) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Error throwing exception %s\n", msg);
|
|
|
|
exit(FAILURE);
|
|
|
|
}
|
|
|
|
jenv->DeleteLocalRef(cls);
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:37:06 +04:00
|
|
|
#define JNI_STUBS
|
|
|
|
#include "jni-stubs.inc"
|
|
|
|
#undef JNI_STUBS
|
2010-10-15 22:27:57 +04:00
|
|
|
|
|
|
|
static void * xul_handle = NULL;
|
2012-01-20 00:19:56 +04:00
|
|
|
static void * sqlite_handle = NULL;
|
2012-03-08 22:25:44 +04:00
|
|
|
static void * nss_handle = NULL;
|
|
|
|
static void * nspr_handle = NULL;
|
|
|
|
static void * plc_handle = NULL;
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2012-06-22 04:18:37 +04:00
|
|
|
template <typename T> inline void
|
|
|
|
xul_dlsym(const char *symbolName, T *value)
|
|
|
|
{
|
|
|
|
*value = (T) (uintptr_t) __wrap_dlsym(xul_handle, symbolName);
|
|
|
|
}
|
|
|
|
|
2013-01-03 11:43:26 +04:00
|
|
|
#if defined(MOZ_CRASHREPORTER)
|
2010-10-15 22:27:57 +04:00
|
|
|
static void
|
2012-01-11 14:11:02 +04:00
|
|
|
extractLib(Zip::Stream &s, void * dest)
|
2010-10-15 22:27:57 +04:00
|
|
|
{
|
|
|
|
z_stream strm = {
|
2012-01-11 14:11:02 +04:00
|
|
|
next_in: (Bytef *)s.GetBuffer(),
|
|
|
|
avail_in: s.GetSize(),
|
2010-10-15 22:27:57 +04:00
|
|
|
total_in: 0,
|
|
|
|
|
|
|
|
next_out: (Bytef *)dest,
|
2012-01-11 14:11:02 +04:00
|
|
|
avail_out: s.GetUncompressedSize(),
|
2010-10-15 22:27:57 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
ret = inflate(&strm, Z_SYNC_FLUSH);
|
|
|
|
if (ret != Z_STREAM_END)
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflate failed: %s", strm.msg);
|
|
|
|
|
|
|
|
ret = inflateEnd(&strm);
|
|
|
|
if (ret != Z_OK)
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "inflateEnd failed: %s", strm.msg);
|
|
|
|
|
2012-01-11 14:11:02 +04:00
|
|
|
if (strm.total_out != s.GetUncompressedSize())
|
2012-02-25 06:49:56 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "File not fully uncompressed! %lu / %d", strm.total_out, s.GetUncompressedSize());
|
2010-10-15 22:27:57 +04:00
|
|
|
}
|
2012-02-25 06:49:56 +04:00
|
|
|
#endif
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2010-10-29 23:22:28 +04:00
|
|
|
static struct lib_cache_info *cache_mapping = NULL;
|
|
|
|
|
|
|
|
NS_EXPORT const struct lib_cache_info *
|
|
|
|
getLibraryCache()
|
|
|
|
{
|
|
|
|
return cache_mapping;
|
|
|
|
}
|
|
|
|
|
2012-01-20 12:49:07 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-10-21 04:44:03 +04:00
|
|
|
static void *
|
2012-01-11 14:11:02 +04:00
|
|
|
extractBuf(const char * path, Zip *zip)
|
2010-10-21 04:44:03 +04:00
|
|
|
{
|
2012-01-11 14:11:02 +04:00
|
|
|
Zip::Stream s;
|
|
|
|
if (!zip->GetStream(path, &s))
|
|
|
|
return NULL;
|
2010-10-21 04:44:03 +04:00
|
|
|
|
2012-11-13 23:21:08 +04:00
|
|
|
// allocate space for a trailing null byte
|
|
|
|
void * buf = malloc(s.GetUncompressedSize() + 1);
|
2010-10-21 04:44:03 +04:00
|
|
|
if (buf == (void *)-1) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't alloc decompression buffer for %s", path);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-11 14:11:02 +04:00
|
|
|
if (s.GetType() == Zip::Stream::DEFLATE)
|
|
|
|
extractLib(s, buf);
|
2010-10-21 04:44:03 +04:00
|
|
|
else
|
2012-01-11 14:11:02 +04:00
|
|
|
memcpy(buf, s.GetBuffer(), s.GetUncompressedSize());
|
2010-10-21 04:44:03 +04:00
|
|
|
|
2012-11-13 23:21:08 +04:00
|
|
|
// null terminate it
|
|
|
|
((unsigned char*) buf)[s.GetUncompressedSize()] = 0;
|
|
|
|
|
2010-10-21 04:44:03 +04:00
|
|
|
return buf;
|
|
|
|
}
|
2012-01-20 12:49:07 +04:00
|
|
|
#endif
|
2010-10-21 04:44:03 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
static mozglueresult
|
2012-01-20 00:19:56 +04:00
|
|
|
loadGeckoLibs(const char *apkName)
|
2010-10-15 22:27:57 +04:00
|
|
|
{
|
2011-02-08 07:40:42 +03:00
|
|
|
chdir(getenv("GRE_HOME"));
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2012-06-19 11:16:33 +04:00
|
|
|
MOZTime t0 = MOZ_Now();
|
2011-01-13 00:08:28 +03:00
|
|
|
struct rusage usage1;
|
2011-11-18 11:54:17 +04:00
|
|
|
getrusage(RUSAGE_THREAD, &usage1);
|
2011-12-21 23:05:23 +04:00
|
|
|
|
2012-02-13 18:49:45 +04:00
|
|
|
RefPtr<Zip> zip = new Zip(apkName);
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2011-05-26 00:54:30 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-01-11 14:11:02 +04:00
|
|
|
file_ids = (char *)extractBuf("lib.id", zip);
|
2010-10-21 04:44:03 +04:00
|
|
|
#endif
|
|
|
|
|
2012-01-20 12:49:07 +04:00
|
|
|
char *file = new char[strlen(apkName) + sizeof("!/libxpcom.so")];
|
|
|
|
sprintf(file, "%s!/libxpcom.so", apkName);
|
|
|
|
__wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
|
|
|
|
// libxul.so is pulled from libxpcom.so, so we don't need to give the full path
|
|
|
|
xul_handle = __wrap_dlopen("libxul.so", RTLD_GLOBAL | RTLD_LAZY);
|
|
|
|
delete[] file;
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2010-10-21 04:44:03 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
free(file_ids);
|
|
|
|
file_ids = NULL;
|
|
|
|
#endif
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
if (!xul_handle) {
|
2010-10-15 22:27:57 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libxul!");
|
2012-03-08 22:25:44 +04:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2013-02-07 18:37:06 +04:00
|
|
|
#define JNI_BINDINGS
|
|
|
|
#include "jni-stubs.inc"
|
|
|
|
#undef JNI_BINDINGS
|
2012-06-22 04:18:37 +04:00
|
|
|
|
|
|
|
void (*XRE_StartupTimelineRecord)(int, MOZTime);
|
|
|
|
xul_dlsym("XRE_StartupTimelineRecord", &XRE_StartupTimelineRecord);
|
|
|
|
|
2012-06-19 11:16:33 +04:00
|
|
|
MOZTime t1 = MOZ_Now();
|
2011-01-13 00:08:28 +03:00
|
|
|
struct rusage usage2;
|
2011-11-18 11:54:17 +04:00
|
|
|
getrusage(RUSAGE_THREAD, &usage2);
|
2012-06-22 04:18:37 +04:00
|
|
|
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Loaded libs in %lldms total, %ldms user, %ldms system, %ld faults",
|
2012-06-19 11:16:33 +04:00
|
|
|
(t1 - t0) / 1000,
|
2011-06-17 10:59:39 +04:00
|
|
|
(usage2.ru_utime.tv_sec - usage1.ru_utime.tv_sec)*1000 + (usage2.ru_utime.tv_usec - usage1.ru_utime.tv_usec)/1000,
|
|
|
|
(usage2.ru_stime.tv_sec - usage1.ru_stime.tv_sec)*1000 + (usage2.ru_stime.tv_usec - usage1.ru_stime.tv_usec)/1000,
|
2011-01-13 00:08:28 +03:00
|
|
|
usage2.ru_majflt-usage1.ru_majflt);
|
2011-11-18 11:54:37 +04:00
|
|
|
|
2012-06-19 11:16:33 +04:00
|
|
|
XRE_StartupTimelineRecord(LINKER_INITIALIZED, t0);
|
|
|
|
XRE_StartupTimelineRecord(LIBRARIES_LOADED, t1);
|
2012-03-08 22:25:44 +04:00
|
|
|
return SUCCESS;
|
2010-10-15 22:27:57 +04:00
|
|
|
}
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
static int loadSQLiteLibs(const char *apkName)
|
2012-01-20 00:19:56 +04:00
|
|
|
{
|
|
|
|
chdir(getenv("GRE_HOME"));
|
|
|
|
|
2012-02-13 18:49:45 +04:00
|
|
|
RefPtr<Zip> zip = new Zip(apkName);
|
2012-03-08 22:25:44 +04:00
|
|
|
if (!lib_mapping) {
|
|
|
|
lib_mapping = (struct mapping_info *)calloc(MAX_MAPPING_INFO, sizeof(*lib_mapping));
|
|
|
|
}
|
2012-01-20 00:19:56 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
file_ids = (char *)extractBuf("lib.id", zip);
|
|
|
|
#endif
|
|
|
|
|
2012-01-23 11:37:56 +04:00
|
|
|
char *file = new char[strlen(apkName) + sizeof("!/libmozsqlite3.so")];
|
|
|
|
sprintf(file, "%s!/libmozsqlite3.so", apkName);
|
2012-01-21 23:25:09 +04:00
|
|
|
sqlite_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
|
2012-01-20 12:49:07 +04:00
|
|
|
delete [] file;
|
2012-01-20 00:19:56 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
free(file_ids);
|
|
|
|
file_ids = NULL;
|
|
|
|
#endif
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
if (!sqlite_handle) {
|
2012-01-20 00:19:56 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libmozsqlite3!");
|
2012-03-08 22:25:44 +04:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2012-01-20 00:19:56 +04:00
|
|
|
|
|
|
|
setup_sqlite_functions(sqlite_handle);
|
2012-03-08 22:25:44 +04:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mozglueresult
|
|
|
|
loadNSSLibs(const char *apkName)
|
|
|
|
{
|
|
|
|
chdir(getenv("GRE_HOME"));
|
|
|
|
|
2012-03-13 22:59:53 +04:00
|
|
|
RefPtr<Zip> zip = new Zip(apkName);
|
2012-03-08 22:25:44 +04:00
|
|
|
if (!lib_mapping) {
|
|
|
|
lib_mapping = (struct mapping_info *)calloc(MAX_MAPPING_INFO, sizeof(*lib_mapping));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
file_ids = (char *)extractBuf("lib.id", zip);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char *file = new char[strlen(apkName) + sizeof("!/libnss3.so")];
|
|
|
|
sprintf(file, "%s!/libnss3.so", apkName);
|
|
|
|
nss_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
|
|
|
|
delete [] file;
|
|
|
|
|
|
|
|
file = new char[strlen(apkName) + sizeof("!/libnspr4.so")];
|
|
|
|
sprintf(file, "%s!/libnspr4.so", apkName);
|
|
|
|
nspr_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
|
|
|
|
delete [] file;
|
|
|
|
|
|
|
|
file = new char[strlen(apkName) + sizeof("!/libplc4.so")];
|
|
|
|
sprintf(file, "%s!/libplc4.so", apkName);
|
|
|
|
plc_handle = __wrap_dlopen(file, RTLD_GLOBAL | RTLD_LAZY);
|
|
|
|
delete [] file;
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
free(file_ids);
|
|
|
|
file_ids = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!nss_handle) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libnss3!");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nspr_handle) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libnspr4!");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!plc_handle) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libplc4!");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return setup_nss_functions(nss_handle, nspr_handle, plc_handle);
|
2012-01-20 00:19:56 +04:00
|
|
|
}
|
|
|
|
|
2010-10-15 22:27:57 +04:00
|
|
|
extern "C" NS_EXPORT void JNICALL
|
2013-02-07 18:37:06 +04:00
|
|
|
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadGeckoLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName)
|
2010-10-15 22:27:57 +04:00
|
|
|
{
|
2012-01-20 00:19:56 +04:00
|
|
|
const char* str;
|
|
|
|
// XXX: java doesn't give us true UTF8, we should figure out something
|
|
|
|
// better to do here
|
|
|
|
str = jenv->GetStringUTFChars(jApkName, NULL);
|
|
|
|
if (str == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
int res = loadGeckoLibs(str);
|
|
|
|
if (res != SUCCESS) {
|
|
|
|
JNI_Throw(jenv, "java/lang/Exception", "Error loading gecko libraries");
|
|
|
|
}
|
2012-01-20 00:19:56 +04:00
|
|
|
jenv->ReleaseStringUTFChars(jApkName, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT void JNICALL
|
2013-02-07 18:37:06 +04:00
|
|
|
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadSQLiteLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jboolean jShouldExtract) {
|
2012-03-17 23:32:44 +04:00
|
|
|
if (jShouldExtract) {
|
|
|
|
putenv("MOZ_LINKER_EXTRACT=1");
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
const char* str;
|
|
|
|
// XXX: java doesn't give us true UTF8, we should figure out something
|
|
|
|
// better to do here
|
|
|
|
str = jenv->GetStringUTFChars(jApkName, NULL);
|
|
|
|
if (str == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Load sqlite start\n");
|
|
|
|
mozglueresult rv = loadSQLiteLibs(str);
|
|
|
|
if (rv != SUCCESS) {
|
|
|
|
JNI_Throw(jenv, "java/lang/Exception", "Error loading sqlite libraries");
|
2012-01-20 12:49:07 +04:00
|
|
|
}
|
2012-03-08 22:25:44 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Load sqlite done\n");
|
|
|
|
jenv->ReleaseStringUTFChars(jApkName, str);
|
|
|
|
}
|
2011-01-07 05:02:07 +03:00
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
extern "C" NS_EXPORT void JNICALL
|
2013-02-07 18:37:06 +04:00
|
|
|
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadNSSLibsNative(JNIEnv *jenv, jclass jGeckoAppShellClass, jstring jApkName, jboolean jShouldExtract) {
|
2012-03-17 23:32:44 +04:00
|
|
|
if (jShouldExtract) {
|
|
|
|
putenv("MOZ_LINKER_EXTRACT=1");
|
|
|
|
}
|
|
|
|
|
2010-10-15 22:27:57 +04:00
|
|
|
const char* str;
|
2012-01-20 00:19:56 +04:00
|
|
|
// XXX: java doesn't give us true UTF8, we should figure out something
|
2010-10-15 22:27:57 +04:00
|
|
|
// better to do here
|
|
|
|
str = jenv->GetStringUTFChars(jApkName, NULL);
|
|
|
|
if (str == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Load nss start\n");
|
|
|
|
mozglueresult rv = loadNSSLibs(str);
|
|
|
|
if (rv != SUCCESS) {
|
|
|
|
JNI_Throw(jenv, "java/lang/Exception", "Error loading nss libraries");
|
|
|
|
}
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Load nss done\n");
|
2010-10-15 22:27:57 +04:00
|
|
|
jenv->ReleaseStringUTFChars(jApkName, str);
|
|
|
|
}
|
|
|
|
|
2012-02-22 11:12:15 +04:00
|
|
|
typedef void (*GeckoStart_t)(void *, const nsXREAppData *);
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT void JNICALL
|
2013-02-07 18:37:06 +04:00
|
|
|
Java_org_mozilla_gecko_mozglue_GeckoLoader_nativeRun(JNIEnv *jenv, jclass jc, jstring jargs)
|
2012-02-22 11:12:15 +04:00
|
|
|
{
|
2012-06-22 04:18:37 +04:00
|
|
|
GeckoStart_t GeckoStart;
|
|
|
|
xul_dlsym("GeckoStart", &GeckoStart);
|
2012-02-22 11:12:15 +04:00
|
|
|
if (GeckoStart == NULL)
|
|
|
|
return;
|
|
|
|
// XXX: java doesn't give us true UTF8, we should figure out something
|
|
|
|
// better to do here
|
|
|
|
int len = jenv->GetStringUTFLength(jargs);
|
|
|
|
// GeckoStart needs to write in the args buffer, so we need a copy.
|
|
|
|
char *args = (char *) malloc(len + 1);
|
|
|
|
jenv->GetStringUTFRegion(jargs, 0, len, args);
|
|
|
|
args[len] = '\0';
|
|
|
|
GeckoStart(args, &sAppData);
|
|
|
|
free(args);
|
|
|
|
}
|
|
|
|
|
2010-10-15 22:27:57 +04:00
|
|
|
typedef int GeckoProcessType;
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
extern "C" NS_EXPORT mozglueresult
|
2010-10-15 22:27:57 +04:00
|
|
|
ChildProcessInit(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < (argc - 1); i++) {
|
2011-02-25 14:53:36 +03:00
|
|
|
if (strcmp(argv[i], "-greomni"))
|
2010-10-15 22:27:57 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
i = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
if (loadNSSLibs(argv[i]) != SUCCESS) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
if (loadSQLiteLibs(argv[i]) != SUCCESS) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
if (loadGeckoLibs(argv[i]) != SUCCESS) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2010-10-15 22:27:57 +04:00
|
|
|
|
2010-10-29 23:22:28 +04:00
|
|
|
// don't pass the last arg - it's only recognized by the lib cache
|
|
|
|
argc--;
|
|
|
|
|
2012-06-22 04:18:37 +04:00
|
|
|
GeckoProcessType (*fXRE_StringToChildProcessType)(char*);
|
|
|
|
xul_dlsym("XRE_StringToChildProcessType", &fXRE_StringToChildProcessType);
|
|
|
|
|
|
|
|
mozglueresult (*fXRE_InitChildProcess)(int, char**, GeckoProcessType);
|
|
|
|
xul_dlsym("XRE_InitChildProcess", &fXRE_InitChildProcess);
|
2010-10-15 22:27:57 +04:00
|
|
|
|
|
|
|
GeckoProcessType proctype = fXRE_StringToChildProcessType(argv[--argc]);
|
|
|
|
|
2012-03-08 22:25:44 +04:00
|
|
|
return fXRE_InitChildProcess(argc, argv, proctype);
|
2010-10-15 22:27:57 +04:00
|
|
|
}
|
|
|
|
|