diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-10-24 20:57:42 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-10-24 20:57:42 +0000 |
commit | c5004d3a1de0ee69df89d6fcbb232877d4e61572 (patch) | |
tree | c26c99eb013ba19c0764cdfee36e3c9d1b1dab12 /src/native/windows | |
parent | 7f9d22ae943b45f698c45c2a649b4ec799fd4073 (diff) | |
download | jitsi-c5004d3a1de0ee69df89d6fcbb232877d4e61572.zip jitsi-c5004d3a1de0ee69df89d6fcbb232877d4e61572.tar.gz jitsi-c5004d3a1de0ee69df89d6fcbb232877d4e61572.tar.bz2 |
In Jitsi's run.exe:
- Applies Ingo Bauersachs' fix for a crash related to an invalid calling convention upon trying to call JNI_CreateJavaVM.
- Fixes a failure to load the JRE runtime library because of unreachable dependencies which are actually available in the bin directory.
Diffstat (limited to 'src/native/windows')
-rw-r--r-- | src/native/windows/run/run.c | 119 |
1 files changed, 111 insertions, 8 deletions
diff --git a/src/native/windows/run/run.c b/src/native/windows/run/run.c index 4592437..ca129bc 100644 --- a/src/native/windows/run/run.c +++ b/src/native/windows/run/run.c @@ -40,6 +40,7 @@ static LPSTR Run_cmdLine = NULL; */
static BOOL Run_launch = TRUE;
+static DWORD Run_addPath(LPCTSTR path);
static DWORD Run_callStaticVoidMain(JNIEnv *jniEnv, BOOL *searchForJava);
static int Run_displayMessageBoxFromString(DWORD textId, DWORD_PTR *textArgs, LPCTSTR caption, UINT type);
static DWORD Run_equalsParentProcessExecutableFilePath(LPCTSTR executableFilePath, BOOL *equals);
@@ -62,10 +63,52 @@ static DWORD Run_runJavaExe(LPCTSTR javaExe, BOOL searchPath, BOOL *searchForJav static DWORD Run_runJavaFromEnvVar(LPCTSTR envVar, BOOL *searchForJava);
static DWORD Run_runJavaFromJavaHome(LPCTSTR javaHome, BOOL searchForRuntimeLib, BOOL *searchForJava);
static DWORD Run_runJavaFromRegKey(HKEY key, BOOL *searchForJava);
-static DWORD Run_runJavaFromRuntimeLib(LPCTSTR runtimeLib, BOOL *searchForJava);
+static DWORD Run_runJavaFromRuntimeLib(LPCTSTR runtimeLib, LPCTSTR javaHome, BOOL *searchForJava);
static LPSTR Run_skipWhitespace(LPSTR str);
static DWORD
+Run_addPath(LPCTSTR path)
+{
+ LPCTSTR envVarName = _T("PATH");
+ TCHAR envVar[4096];
+ DWORD envVarCapacity = sizeof(envVar) / sizeof(TCHAR);
+ DWORD envVarLength
+ = GetEnvironmentVariable(envVarName, envVar, envVarCapacity);
+ DWORD error;
+
+ if (envVarLength)
+ {
+ if (envVarLength >= envVarCapacity)
+ error = ERROR_NOT_ENOUGH_MEMORY;
+ else
+ {
+ DWORD pathLength = _tcslen(path);
+
+ if (envVarLength + 1 + pathLength + 1 > envVarCapacity)
+ error = ERROR_NOT_ENOUGH_MEMORY;
+ else
+ {
+ LPTSTR str = envVar + envVarLength;
+
+ *str = _T(';');
+ str++;
+ _tcsncpy(str, path, pathLength);
+ str += pathLength;
+ *str = 0;
+
+ if (SetEnvironmentVariable(envVarName, envVar))
+ error = ERROR_SUCCESS;
+ else
+ error = GetLastError();
+ }
+ }
+ }
+ else
+ error = GetLastError();
+ return error;
+}
+
+static DWORD
Run_callStaticVoidMain(JNIEnv *jniEnv, BOOL *searchForJava)
{
LPTSTR mainClassName;
@@ -1306,14 +1349,19 @@ Run_runJavaFromJavaHome( if (searchForRuntimeLib)
{
_tcscpy(path + javaHomeLength, _T("\\bin\\client\\jvm.dll"));
- error = Run_runJavaFromRuntimeLib(path, searchForJava);
+ error
+ = Run_runJavaFromRuntimeLib(path, javaHome, searchForJava);
if ((ERROR_SUCCESS != error) || *searchForJava)
{
_tcscpy(
path + javaHomeLength,
_T("\\bin\\server\\jvm.dll"));
- error = Run_runJavaFromRuntimeLib(path, searchForJava);
+ error
+ = Run_runJavaFromRuntimeLib(
+ path,
+ javaHome,
+ searchForJava);
}
}
@@ -1368,7 +1416,11 @@ Run_runJavaFromRegKey(HKEY key, BOOL *searchForJava) {
if (runtimeLib)
{
- error = Run_runJavaFromRuntimeLib(runtimeLib, searchForJava);
+ error
+ = Run_runJavaFromRuntimeLib(
+ runtimeLib,
+ javaHome,
+ searchForJava);
free(runtimeLib);
}
if (javaHome)
@@ -1388,15 +1440,66 @@ Run_runJavaFromRegKey(HKEY key, BOOL *searchForJava) }
static DWORD
-Run_runJavaFromRuntimeLib(LPCTSTR runtimeLib, BOOL *searchForJava)
+Run_runJavaFromRuntimeLib
+ (LPCTSTR runtimeLib, LPCTSTR javaHome, BOOL *searchForJava)
{
- HMODULE hRuntimeLib
- = Run_isFile(runtimeLib) ? LoadLibrary(runtimeLib) : NULL;
+ HMODULE hRuntimeLib;
DWORD error;
+ if (Run_isFile(runtimeLib))
+ {
+ /*
+ * It turns out that the bin directory in javaHome may contain
+ * dependencies of the runtimeLib so add it to the PATH. Well, it may
+ * not be standard but it happens to our private JRE.
+ */
+ if (javaHome && Run_isDirectory(javaHome))
+ {
+ size_t javaHomeLength = _tcslen(javaHome);
+ LPTSTR javaHomeBin;
+
+ /*
+ * Drop the last file name separator if any because we will be
+ * adding one later on.
+ */
+ while (javaHomeLength >= 1)
+ {
+ TCHAR ch = *(javaHome + (javaHomeLength - 1));
+
+ if ((_T('\\') == ch) || (_T('/') == ch))
+ javaHomeLength--;
+ else
+ break;
+ }
+
+ javaHomeBin
+ = malloc(
+ sizeof(TCHAR) * (javaHomeLength + 4 /* "\\bin" */ + 1));
+ if (javaHomeBin)
+ {
+ LPTSTR str = javaHomeBin;
+
+ _tcsncpy(str, javaHome, javaHomeLength);
+ str += javaHomeLength;
+ _tcsncpy(str, _T("\\bin"), 4);
+ str += 4;
+ *str = 0;
+
+ if (Run_isDirectory(javaHomeBin))
+ Run_addPath(javaHomeBin);
+
+ free(javaHomeBin);
+ }
+ }
+
+ hRuntimeLib = LoadLibrary(runtimeLib);
+ }
+ else
+ hRuntimeLib = NULL;
+
if (hRuntimeLib)
{
- typedef jint (*JNICreateJavaVMFunc)(JavaVM **, void **, void *);
+ typedef jint (JNICALL *JNICreateJavaVMFunc)(JavaVM **, void **, void *);
JNICreateJavaVMFunc jniCreateJavaVM
= (JNICreateJavaVMFunc)
GetProcAddress(hRuntimeLib, "JNI_CreateJavaVM");
|