static jboolean LoadMSVCRT() { // Only do this once static int loaded = 0; char crtpath[MAXPATHLEN]; if (!loaded) { /* * The Microsoft C Runtime Library needs to be loaded first. A copy is * assumed to be present in the "JRE path" directory. If it is not found * there (or "JRE path" fails to resolve), skip the explicit load and let * nature take its course, which is likely to be a failure to execute. * The makefiles will provide the correct lib contained in quotes in the * macro MSVCR_DLL_NAME. */ #ifdef MSVCR_DLL_NAME if (GetJREPath(crtpath, MAXPATHLEN)) { if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") + JLI_StrLen(MSVCR_DLL_NAME) >= MAXPATHLEN) { JLI_ReportErrorMessage(JRE_ERROR11); return JNI_FALSE; } (void)JLI_StrCat(crtpath, "\\bin\\" MSVCR_DLL_NAME); /* Add crt dll */ JLI_TraceLauncher("CRT path is %s\n", crtpath); if (_access(crtpath, 0) == 0) { if (LoadLibrary(crtpath) == 0) { JLI_ReportErrorMessage(DLL_ERROR4, crtpath); return JNI_FALSE; } } } #endif /* MSVCR_DLL_NAME */ #ifdef MSVCP_DLL_NAME if (GetJREPath(crtpath, MAXPATHLEN)) { if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") + JLI_StrLen(MSVCP_DLL_NAME) >= MAXPATHLEN) { JLI_ReportErrorMessage(JRE_ERROR11); return JNI_FALSE; } (void)JLI_StrCat(crtpath, "\\bin\\" MSVCP_DLL_NAME); /* Add prt dll */ JLI_TraceLauncher("PRT path is %s\n", crtpath); if (_access(crtpath, 0) == 0) { if (LoadLibrary(crtpath) == 0) { JLI_ReportErrorMessage(DLL_ERROR4, crtpath); return JNI_FALSE; } } } #endif /* MSVCP_DLL_NAME */ loaded = 1; } return JNI_TRUE; }
static jboolean LoadMSVCRT() { // Only do this once static int loaded = 0; char crtpath[MAXPATHLEN]; if (!loaded) { /* * The Microsoft C Runtime Library needs to be loaded first. A copy is * assumed to be present in the "JRE path" directory. If it is not found * there (or "JRE path" fails to resolve), skip the explicit load and let * nature take its course, which is likely to be a failure to execute. */ if (GetJREPath(crtpath, MAXPATHLEN)) { (void)strcat(crtpath, "\\bin\\" CRT_DLL); /* Add crt dll */ if (_launcher_debug) { printf("CRT path is %s\n", crtpath); } if (_access(crtpath, 0) == 0) { if (LoadLibrary(crtpath) == 0) { ReportErrorMessage2("Error loading: %s", crtpath, JNI_TRUE); return JNI_FALSE; } } } loaded = 1; } return JNI_TRUE; }
void* SplashProcAddress(const char* name) { if (!hSplashLib) { int ret; char jrePath[MAXPATHLEN]; char splashPath[MAXPATHLEN]; if (!GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE)) { JLI_ReportErrorMessage(JRE_ERROR1); return NULL; } ret = JLI_Snprintf(splashPath, sizeof(splashPath), "%s/lib/%s/%s", jrePath, GetArch(), SPLASHSCREEN_SO); if (ret >= (int) sizeof(splashPath)) { JLI_ReportErrorMessage(JRE_ERROR11); return NULL; } if (ret < 0) { JLI_ReportErrorMessage(JRE_ERROR13); return NULL; } hSplashLib = dlopen(splashPath, RTLD_LAZY | RTLD_GLOBAL); JLI_TraceLauncher("Info: loaded %s\n", splashPath); } if (hSplashLib) { void* sym = dlsym(hSplashLib, name); return sym; } else { return NULL; } }
void CreateExecutionEnvironment(int *_argc, char ***_argv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath, char **original_argv) { char * jvmtype; int i = 0; char** pargv = *_argv; int running = CURRENT_DATA_MODEL; int wanted = running; for (i = 0; i < *_argc ; i++) { if (strcmp(pargv[i], "-J-d64") == 0 || strcmp(pargv[i], "-d64") == 0) { wanted = 64; continue; } if (strcmp(pargv[i], "-J-d32") == 0 || strcmp(pargv[i], "-d32") == 0) { wanted = 32; continue; } } if (running != wanted) { fprintf(stderr, "This Java instance does not support a %d-bit JVM.\nPlease install the desired version.\n", wanted); exit(1); } /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath)) { ReportErrorMessage("Error: could not find Java 2 Runtime Environment.", JNI_TRUE); exit(2); } /* Find the specified JVM type */ if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) { ReportErrorMessage("Error: no known VMs. (check for corrupt jvm.cfg file)", JNI_TRUE); exit(1); } jvmtype = CheckJvmType(_argc, _argv, JNI_FALSE); jvmpath[0] = '\0'; if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) { char * message=NULL; const char * format = "Error: no `%s' JVM at `%s'."; message = (char *)JLI_MemAlloc((strlen(format)+strlen(jvmtype)+ strlen(jvmpath)) * sizeof(char)); sprintf(message,format, jvmtype, jvmpath); ReportErrorMessage(message, JNI_TRUE); exit(4); } /* If we got here, jvmpath has been correctly initialized. */ }
/* * Load a jvm from "jvmpath" and initialize the invocation functions. */ jboolean LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn) { HINSTANCE handle; char crtpath[MAXPATHLEN]; if (_launcher_debug) { printf("JVM path is %s\n", jvmpath); } /* * The Microsoft C Runtime Library needs to be loaded first. A copy is * assumed to be present in the "JRE path" directory. If it is not found * there (or "JRE path" fails to resolve), skip the explicit load and let * nature take its course, which is likely to be a failure to execute. */ if (GetJREPath(crtpath, MAXPATHLEN)) { (void)strcat(crtpath, "\\bin\\" CRT_DLL); /* Add crt dll */ if (_launcher_debug) { printf("CRT path is %s\n", crtpath); } if (_access(crtpath, 0) == 0) { if (LoadLibrary(crtpath) == 0) { ReportErrorMessage2("Error loading: %s", crtpath, JNI_TRUE); return JNI_FALSE; } } } /* Load the Java VM DLL */ if ((handle = LoadLibrary(jvmpath)) == 0) { ReportErrorMessage2("Error loading: %s", (char *)jvmpath, JNI_TRUE); return JNI_FALSE; } /* Now get the function addresses */ ifn->CreateJavaVM = (void *)GetProcAddress(handle, "JNI_CreateJavaVM"); ifn->GetDefaultJavaVMInitArgs = (void *)GetProcAddress(handle, "JNI_GetDefaultJavaVMInitArgs"); if (ifn->CreateJavaVM == 0 || ifn->GetDefaultJavaVMInitArgs == 0) { ReportErrorMessage2("Error: can't find JNI interfaces in: %s", (char *)jvmpath, JNI_TRUE); return JNI_FALSE; } return JNI_TRUE; }
static jboolean LoadMSVCRT() { // Only do this once static int loaded = 0; char crtpath[MAXPATHLEN]; if (!loaded) { /* * The Microsoft C Runtime Library needs to be loaded first. A copy is * assumed to be present in the "JRE path" directory. If it is not found * there (or "JRE path" fails to resolve), skip the explicit load and let * nature take its course, which is likely to be a failure to execute. * This is clearly completely specific to the exact compiler version * which isn't very nice, but its hardly the only place. * No attempt to look for compiler versions in between 2003 and 2010 * as we aren't supporting building with those. */ #ifdef _MSC_VER #if _MSC_VER < 1400 #define CRT_DLL "msvcr71.dll" #endif #if _MSC_VER >= 1600 #define CRT_DLL "msvcr100.dll" #endif #ifdef CRT_DLL if (GetJREPath(crtpath, MAXPATHLEN)) { if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") + JLI_StrLen(CRT_DLL) >= MAXPATHLEN) { JLI_ReportErrorMessage(JRE_ERROR11); return JNI_FALSE; } (void)JLI_StrCat(crtpath, "\\bin\\" CRT_DLL); /* Add crt dll */ JLI_TraceLauncher("CRT path is %s\n", crtpath); if (_access(crtpath, 0) == 0) { if (LoadLibrary(crtpath) == 0) { JLI_ReportErrorMessage(DLL_ERROR4, crtpath); return JNI_FALSE; } } } #endif /* CRT_DLL */ #endif /* _MSC_VER */ loaded = 1; } return JNI_TRUE; }
void* SplashProcAddress(const char* name) { char libraryPath[MAXPATHLEN]; /* some extra space for strcat'ing SPLASHSCREEN_SO */ if (!GetJREPath(libraryPath, MAXPATHLEN)) { return NULL; } if (strlen(libraryPath)+strlen(SPLASHSCREEN_SO) >= MAXPATHLEN) { return NULL; } strcat(libraryPath, SPLASHSCREEN_SO); if (!hSplashLib) { hSplashLib = LoadLibrary(libraryPath); } if (hSplashLib) { return GetProcAddress(hSplashLib, name); } else { return NULL; } }
void CreateExecutionEnvironment(int *_argc, char ***_argv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath, char **_jvmtype, char **original_argv) { char *execname = NULL; int original_argc = *_argc; /* Compute the name of the executable */ execname = SetExecname(*_argc, *_argv); /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath)) { fprintf(stderr, "Error: could not find Java 2 Runtime Environment.\n"); exit(2); } /* Find the specified JVM type */ if (ReadKnownVMs(jrepath) < 1) { fprintf(stderr, "Error: no known VMs. (check for corrupt jvm.cfg file)\n"); exit(1); } *_jvmtype = CheckJvmType(_argc, _argv); jvmpath[0] = '\0'; if (!GetJVMPath(jrepath, *_jvmtype, jvmpath, so_jvmpath)) { fprintf(stderr, "Error: no `%s' JVM at `%s'.\n", *_jvmtype, jvmpath); exit(4); } /* If we got here, jvmpath has been correctly initialized. */ /* Set the LD_LIBRARY_PATH environment variable, check data model flags, and exec process, if needed */ SetLibraryPath(_argc, _argv, original_argc, original_argv, execname, jrepath, jvmpath); }
void* SplashProcAddress(const char* name) { if (!hSplashLib) { char jrePath[PATH_MAX]; if (!GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE)) { JLI_ReportErrorMessage(JRE_ERROR1); return NULL; } char splashPath[PATH_MAX]; const int ret = JLI_Snprintf(splashPath, sizeof(splashPath), "%s/lib/%s", jrePath, SPLASHSCREEN_SO); if (ret >= (int)sizeof(splashPath)) { JLI_ReportErrorMessage(JRE_ERROR11); return NULL; } if (ret < 0) { JLI_ReportErrorMessage(JRE_ERROR13); return NULL; } hSplashLib = dlopen(splashPath, RTLD_LAZY | RTLD_GLOBAL); // It's OK if dlopen() fails. The splash screen library binary file // might have been stripped out from the JRE image to reduce its size // (e.g. on embedded platforms). if (hSplashLib) { if (!SetJavaVMValue()) { dlclose(hSplashLib); hSplashLib = NULL; } } } if (hSplashLib) { void* sym = dlsym(hSplashLib, name); return sym; } else { return NULL; } }
int CreateExecutionEnvironment(int *_argc, char ***_argv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath, char **original_argv) { char * jvmtype; /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath)) { ReportErrorMessage("Could not find a suitable Java 2 Runtime Environment.", JNI_TRUE); return 1; } /* Find the specified JVM type */ if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) { ReportErrorMessage("Error: no known VMs. (check for corrupt jvm.cfg file)", JNI_TRUE); return 1; } jvmtype = CheckJvmType(_argc, _argv, JNI_FALSE); jvmpath[0] = '\0'; if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) { char * message=NULL; const char * format = "Error: no `%s' JVM at `%s'."; message = (char *)MemAlloc((strlen(format)+strlen(jvmtype)+ strlen(jvmpath)) * sizeof(char)); sprintf(message,format, jvmtype, jvmpath); ReportErrorMessage(message, JNI_TRUE); return 1; } /* If we got here, jvmpath has been correctly initialized. */ return 0; }
static InvocationFunctions *GetExportedJNIFunctions() { if (sExportedJNIFunctions != NULL) return sExportedJNIFunctions; char jrePath[PATH_MAX]; jboolean gotJREPath = GetJREPath(jrePath, sizeof(jrePath), GetArch(), JNI_FALSE); if (!gotJREPath) { JLI_ReportErrorMessage("Failed to GetJREPath()"); return NULL; } char *preferredJVM = sPreferredJVMType; if (preferredJVM == NULL) { #if defined(__i386__) preferredJVM = "client"; #elif defined(__x86_64__) preferredJVM = "server"; #else #error "Unknown architecture - needs definition" #endif } char jvmPath[PATH_MAX]; jboolean gotJVMPath = GetJVMPath(jrePath, preferredJVM, jvmPath, sizeof(jvmPath), GetArch(), CURRENT_DATA_MODEL); if (!gotJVMPath) { JLI_ReportErrorMessage("Failed to GetJVMPath()"); return NULL; } InvocationFunctions *fxns = malloc(sizeof(InvocationFunctions)); jboolean vmLoaded = LoadJavaVM(jvmPath, fxns); if (!vmLoaded) { JLI_ReportErrorMessage("Failed to LoadJavaVM()"); return NULL; } return sExportedJNIFunctions = fxns; }
int main(int argc, const char* argv[]) { //simpleLog_init(NULL, false, LOG_LEVEL_DEBUG, false); static const size_t path_sizeMax = 1024; char path[path_sizeMax]; bool found = GetJREPath(path, path_sizeMax, NULL, NULL); if (found) { printf("JRE found: %s\n", path); static const size_t jvmPath_sizeMax = 1024; char jvmPath[jvmPath_sizeMax]; bool jvmFound = GetJVMPath(path, "client", jvmPath, jvmPath_sizeMax, NULL); if (jvmFound) { printf("JVM found: %s\n", jvmPath); } else { printf("JVM not found.\n"); } } else { printf("JRE not found.\n"); } return 0; }
void CreateExecutionEnvironment(int *_argc, char ***_argv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath, char **original_argv) { #ifndef GAMMA char * jvmtype; /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath)) { ReportErrorMessage("Error: could not find Java SE Runtime Environment.", JNI_TRUE); exit(2); } /* Do this before we read jvm.cfg */ EnsureJreInstallation(jrepath); /* Find the specified JVM type */ if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) { ReportErrorMessage("Error: no known VMs. (check for corrupt jvm.cfg file)", JNI_TRUE); exit(1); } jvmtype = CheckJvmType(_argc, _argv, JNI_FALSE); jvmpath[0] = '\0'; if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) { char * message=NULL; const char * format = "Error: no `%s' JVM at `%s'."; message = (char *)JLI_MemAlloc((strlen(format)+strlen(jvmtype)+ strlen(jvmpath)) * sizeof(char)); sprintf(message,format, jvmtype, jvmpath); ReportErrorMessage(message, JNI_TRUE); exit(4); } /* If we got here, jvmpath has been correctly initialized. */ #else /* ifndef GAMMA */ /* * gamma launcher is simpler in that it doesn't handle VM flavors, data * model, etc. Assuming everything is set-up correctly * all we need to do here is to return correct path names. See also * GetJVMPath() and GetApplicationHome(). */ { if (!GetJREPath(jrepath, so_jrepath) ) { ReportErrorMessage("Error: could not find Java SE Runtime Environment.", JNI_TRUE); exit(2); } if (!GetJVMPath(jrepath, NULL, jvmpath, so_jvmpath)) { char * message=NULL; const char * format = "Error: no JVM at `%s'."; message = (char *)JLI_MemAlloc((strlen(format)+ strlen(jvmpath)) * sizeof(char)); sprintf(message, format, jvmpath); ReportErrorMessage(message, JNI_TRUE); exit(4); } } #endif /* ifndef GAMMA */ }
void CreateExecutionEnvironment(int *pargc, char ***pargv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath, char jvmcfg[], jint so_jvmcfg) { /* * First, determine if we are running the desired data model. If we * are running the desired data model, all the error messages * associated with calling GetJREPath, ReadKnownVMs, etc. should be * output. However, if we are not running the desired data model, * some of the errors should be suppressed since it is more * informative to issue an error message based on whether or not the * os/processor combination has dual mode capabilities. */ jboolean jvmpathExists; /* Compute/set the name of the executable */ SetExecname(*pargv); /* Check data model flags, and exec process, if needed */ { char *arch = (char *)GetArch(); /* like sparc or sparcv9 */ char * jvmtype = NULL; int argc = *pargc; char **argv = *pargv; int running = CURRENT_DATA_MODEL; int wanted = running; /* What data mode is being asked for? Current model is fine unless another model is asked for */ char** newargv = NULL; int newargc = 0; /* * Starting in 1.5, all unix platforms accept the -d32 and -d64 * options. On platforms where only one data-model is supported * (e.g. ia-64 Linux), using the flag for the other data model is * an error and will terminate the program. */ { /* open new scope to declare local variables */ int i; newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*)); newargv[newargc++] = argv[0]; /* scan for data model arguments and remove from argument list; last occurrence determines desired data model */ for (i=1; i < argc; i++) { if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) { wanted = 64; continue; } if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) { wanted = 32; continue; } newargv[newargc++] = argv[i]; if (IsJavaArgs()) { if (argv[i][0] != '-') continue; } else { if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) { i++; if (i >= argc) break; newargv[newargc++] = argv[i]; continue; } if (argv[i][0] != '-') { i++; break; } } } /* copy rest of args [i .. argc) */ while (i < argc) { newargv[newargc++] = argv[i++]; } newargv[newargc] = NULL; /* * newargv has all proper arguments here */ argc = newargc; argv = newargv; } /* If the data model is not changing, it is an error if the jvmpath does not exist */ if (wanted == running) { /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { JLI_ReportErrorMessage(JRE_ERROR1); exit(2); } JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg", jrepath, FILESEP, FILESEP, "", ""); /* Find the specified JVM type */ if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) { JLI_ReportErrorMessage(CFG_ERROR7); exit(1); } jvmpath[0] = '\0'; jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE); if (JLI_StrCmp(jvmtype, "ERROR") == 0) { JLI_ReportErrorMessage(CFG_ERROR9); exit(4); } if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, wanted)) { JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); exit(4); } /* * Mac OS X requires the Cocoa event loop to be run on the "main" * thread. Spawn off a new thread to run main() and pass * this thread off to the Cocoa event loop. */ MacOSXStartup(argc, argv); /* * we seem to have everything we need, so without further ado * we return back, otherwise proceed to set the environment. */ return; } else { /* do the same speculatively or exit */ #if defined(DUAL_MODE) if (running != wanted) { /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) { /* give up and let other code report error message */ JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); } JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg", jrepath, FILESEP, FILESEP, "", ""); /* * Read in jvm.cfg for target data model and process vm * selection options. */ if (ReadKnownVMs(jvmcfg, JNI_TRUE) < 1) { /* give up and let other code report error message */ JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); } jvmpath[0] = '\0'; jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE); if (JLI_StrCmp(jvmtype, "ERROR") == 0) { JLI_ReportErrorMessage(CFG_ERROR9); exit(4); } /* exec child can do error checking on the existence of the path */ jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted), wanted); } #else /* ! DUAL_MODE */ JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); #endif /* DUAL_MODE */ } { char *newexec = execname; JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); (void) fflush(stdout); (void) fflush(stderr); /* * Use posix_spawn() instead of execv() on Mac OS X. * This allows us to choose which architecture the child process * should run as. */ { posix_spawnattr_t attr; size_t unused_size; pid_t unused_pid; #if defined(__i386__) || defined(__x86_64__) cpu_type_t cpu_type[] = { (wanted == 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86, (running== 64) ? CPU_TYPE_X86_64 : CPU_TYPE_X86 }; #else cpu_type_t cpu_type[] = { CPU_TYPE_ANY }; #endif /* __i386 .. */ posix_spawnattr_init(&attr); posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC); posix_spawnattr_setbinpref_np(&attr, sizeof(cpu_type) / sizeof(cpu_type_t), cpu_type, &unused_size); posix_spawn(&unused_pid, newexec, NULL, &attr, argv, environ); } JLI_ReportErrorMessageSys(JRE_ERROR4, newexec); #if defined(DUAL_MODE) if (running != wanted) { JLI_ReportErrorMessage(JRE_ERROR5, wanted, running); } #endif /* DUAL_MODE */ } exit(1); } }
void CreateExecutionEnvironment(int *pargc, char ***pargv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath) { /* * First, determine if we are running the desired data model. If we * are running the desired data model, all the error messages * associated with calling GetJREPath, ReadKnownVMs, etc. should be * output. However, if we are not running the desired data model, * some of the errors should be suppressed since it is more * informative to issue an error message based on whether or not the * os/processor combination has dual mode capabilities. */ jboolean jvmpathExists; /* Compute/set the name of the executable */ SetExecname(*pargv); /* Check data model flags, and exec process, if needed */ { char *arch = (char *)GetArch(); /* like sparc or sparcv9 */ char * jvmtype = NULL; int argc = *pargc; char **argv = *pargv; int running = CURRENT_DATA_MODEL; int wanted = running; /* What data mode is being asked for? Current model is fine unless another model is asked for */ #ifdef SETENV_REQUIRED jboolean mustsetenv = JNI_FALSE; char *runpath = NULL; /* existing effective LD_LIBRARY_PATH setting */ char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */ char* newpath = NULL; /* path on new LD_LIBRARY_PATH */ char* lastslash = NULL; char** newenvp = NULL; /* current environment */ #ifdef __solaris__ char* dmpath = NULL; /* data model specific LD_LIBRARY_PATH, Solaris only */ #endif /* __solaris__ */ #endif /* SETENV_REQUIRED */ char** newargv = NULL; int newargc = 0; /* * Starting in 1.5, all unix platforms accept the -d32 and -d64 * options. On platforms where only one data-model is supported * (e.g. ia-64 Linux), using the flag for the other data model is * an error and will terminate the program. */ { /* open new scope to declare local variables */ int i; newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*)); newargv[newargc++] = argv[0]; /* scan for data model arguments and remove from argument list; last occurrence determines desired data model */ for (i=1; i < argc; i++) { if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) { wanted = 64; continue; } if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) { wanted = 32; continue; } newargv[newargc++] = argv[i]; if (IsJavaArgs()) { if (argv[i][0] != '-') continue; } else { if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) { i++; if (i >= argc) break; newargv[newargc++] = argv[i]; continue; } if (argv[i][0] != '-') { i++; break; } } } /* copy rest of args [i .. argc) */ while (i < argc) { newargv[newargc++] = argv[i++]; } newargv[newargc] = NULL; /* * newargv has all proper arguments here */ argc = newargc; argv = newargv; } /* If the data model is not changing, it is an error if the jvmpath does not exist */ if (wanted == running) { /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { JLI_ReportErrorMessage(JRE_ERROR1); exit(2); } /* Find the specified JVM type */ if (ReadKnownVMs(jrepath, arch, JNI_FALSE) < 1) { JLI_ReportErrorMessage(CFG_ERROR7); exit(1); } jvmpath[0] = '\0'; jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE); if (JLI_StrCmp(jvmtype, "ERROR") == 0) { JLI_ReportErrorMessage(CFG_ERROR9); exit(4); } if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) { JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); exit(4); } /* * we seem to have everything we need, so without further ado * we return back, otherwise proceed to set the environment. */ #ifdef SETENV_REQUIRED mustsetenv = RequiresSetenv(wanted, jvmpath); JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE"); if (mustsetenv == JNI_FALSE) { return; } #else return; #endif /* SETENV_REQUIRED */ } else { /* do the same speculatively or exit */ #ifdef DUAL_MODE if (running != wanted) { /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) { /* give up and let other code report error message */ JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); } /* * Read in jvm.cfg for target data model and process vm * selection options. */ if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) { /* give up and let other code report error message */ JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); } jvmpath[0] = '\0'; jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE); if (JLI_StrCmp(jvmtype, "ERROR") == 0) { JLI_ReportErrorMessage(CFG_ERROR9); exit(4); } /* exec child can do error checking on the existence of the path */ jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted)); #ifdef SETENV_REQUIRED mustsetenv = RequiresSetenv(wanted, jvmpath); #endif /* SETENV_REQUIRED */ } #else JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); #endif } #ifdef SETENV_REQUIRED if (mustsetenv) { /* * We will set the LD_LIBRARY_PATH as follows: * * o $JVMPATH (directory portion only) * o $JRE/lib/$LIBARCHNAME * o $JRE/../lib/$LIBARCHNAME * * followed by the user's previous effective LD_LIBRARY_PATH, if * any. */ #ifdef __solaris__ /* * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH * variables: * * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if * data-model specific variables are not set. * * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH * for 64-bit binaries. * * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH * for 32-bit binaries. * * The vm uses LD_LIBRARY_PATH to set the java.library.path system * property. To shield the vm from the complication of multiple * LD_LIBRARY_PATH variables, if the appropriate data model * specific variable is set, we will act as if LD_LIBRARY_PATH had * the value of the data model specific variant and the data model * specific variant will be unset. Note that the variable for the * *wanted* data model must be used (if it is set), not simply the * current running data model. */ switch (wanted) { case 0: if (running == 32) { dmpath = getenv("LD_LIBRARY_PATH_32"); wanted = 32; } else { dmpath = getenv("LD_LIBRARY_PATH_64"); wanted = 64; } break; case 32: dmpath = getenv("LD_LIBRARY_PATH_32"); break; case 64: dmpath = getenv("LD_LIBRARY_PATH_64"); break; default: JLI_ReportErrorMessage(JRE_ERROR3, __LINE__); exit(1); /* unknown value in wanted */ break; } /* * If dmpath is NULL, the relevant data model specific variable is * not set and normal LD_LIBRARY_PATH should be used. */ if (dmpath == NULL) { runpath = getenv("LD_LIBRARY_PATH"); } else { runpath = dmpath; } #else /* * If not on Solaris, assume only a single LD_LIBRARY_PATH * variable. */ runpath = getenv("LD_LIBRARY_PATH"); #endif /* __solaris__ */ /* runpath contains current effective LD_LIBRARY_PATH setting */ jvmpath = JLI_StringDup(jvmpath); new_runpath = JLI_MemAlloc(((runpath != NULL) ? JLI_StrLen(runpath) : 0) + 2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) + JLI_StrLen(jvmpath) + 52); newpath = new_runpath + JLI_StrLen("LD_LIBRARY_PATH="); /* * Create desired LD_LIBRARY_PATH value for target data model. */ { /* remove the name of the .so from the JVM path */ lastslash = JLI_StrRChr(jvmpath, '/'); if (lastslash) *lastslash = '\0'; sprintf(new_runpath, "LD_LIBRARY_PATH=" "%s:" "%s/lib/%s:" "%s/../lib/%s", jvmpath, #ifdef DUAL_MODE jrepath, GetArchPath(wanted), jrepath, GetArchPath(wanted) #else jrepath, arch, jrepath, arch #endif ); /* * Check to make sure that the prefix of the current path is the * desired environment variable setting, though the RequiresSetenv * checks if the desired runpath exists, this logic does a more * comprehensive check. */ if (runpath != NULL && JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 && (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') && (running == wanted) /* data model does not have to be changed */ #ifdef __solaris__ && (dmpath == NULL) /* data model specific variables not set */ #endif ) { return; } } /* * Place the desired environment setting onto the prefix of * LD_LIBRARY_PATH. Note that this prevents any possible infinite * loop of execv() because we test for the prefix, above. */ if (runpath != 0) { JLI_StrCat(new_runpath, ":"); JLI_StrCat(new_runpath, runpath); } if (putenv(new_runpath) != 0) { exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set properly */ } /* * Unix systems document that they look at LD_LIBRARY_PATH only * once at startup, so we have to re-exec the current executable * to get the changed environment variable to have an effect. */ #ifdef __solaris__ /* * If dmpath is not NULL, remove the data model specific string * in the environment for the exec'ed child. */ if (dmpath != NULL) (void)UnsetEnv((wanted == 32) ? "LD_LIBRARY_PATH_32" : "LD_LIBRARY_PATH_64"); #endif newenvp = environ; } #endif /* SETENV_REQUIRED */ { char *newexec = execname; #ifdef DUAL_MODE /* * If the data model is being changed, the path to the * executable must be updated accordingly; the executable name * and directory the executable resides in are separate. In the * case of 32 => 64, the new bits are assumed to reside in, e.g. * "olddir/LIBARCH64NAME/execname"; in the case of 64 => 32, * the bits are assumed to be in "olddir/../execname". For example, * * olddir/sparcv9/execname * olddir/amd64/execname * * for Solaris SPARC and Linux amd64, respectively. */ if (running != wanted) { char *oldexec = JLI_StrCpy(JLI_MemAlloc(JLI_StrLen(execname) + 1), execname); char *olddir = oldexec; char *oldbase = JLI_StrRChr(oldexec, '/'); newexec = JLI_MemAlloc(JLI_StrLen(execname) + 20); *oldbase++ = 0; sprintf(newexec, "%s/%s/%s", olddir, ((wanted == 64) ? LIBARCH64NAME : ".."), oldbase); argv[0] = newexec; } #endif /* DUAL_MODE */ JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); (void) fflush(stdout); (void) fflush(stderr); #ifdef SETENV_REQUIRED if (mustsetenv) { execve(newexec, argv, newenvp); } else { execv(newexec, argv); } #else execv(newexec, argv); #endif /* SETENV_REQUIRED */ JLI_ReportErrorMessageSys(JRE_ERROR4, newexec); #ifdef DUAL_MODE if (running != wanted) { JLI_ReportErrorMessage(JRE_ERROR5, wanted, running); #ifdef __solaris__ #ifdef __sparc JLI_ReportErrorMessage(JRE_ERROR6); #else JLI_ReportErrorMessage(JRE_ERROR7); #endif /* __sparc */ } #endif /* __solaris__ */ #endif /* DUAL_MODE */ } exit(1); } }
bool java_initStatic(int _interfaceId, const struct SAIInterfaceCallback* _callback) { interfaceId = _interfaceId; callback = _callback; // Read the jvm properties config file jvmCfgProps = (struct Properties*) malloc(sizeof(struct Properties)); java_readJvmCfgFile(jvmCfgProps); skirmishAIId_sizeMax = callback->SkirmishAIs_getSize(interfaceId); skirmishAiImpl_sizeMax = skirmishAIId_sizeMax; skirmishAiImpl_size = 0; skirmishAIId_skirmishAiImpl = (size_t*) calloc(skirmishAIId_sizeMax, sizeof(size_t)); size_t t; for (t = 0; t < skirmishAIId_sizeMax; ++t) { skirmishAIId_skirmishAiImpl[t] = 999999; } skirmishAiImpl_className = (char**) calloc(skirmishAiImpl_sizeMax, sizeof(char*)); skirmishAiImpl_instance = (jobject*) calloc(skirmishAiImpl_sizeMax, sizeof(jobject)); skirmishAiImpl_classLoader = (jobject*) calloc(skirmishAiImpl_sizeMax, sizeof(jobject)); size_t sai; for (sai = 0; sai < skirmishAiImpl_sizeMax; ++sai) { skirmishAiImpl_className[sai] = NULL; skirmishAiImpl_instance[sai] = NULL; skirmishAiImpl_classLoader[sai] = NULL; } // dynamically load the JVM char* jreLocationFile = callback->DataDirs_allocatePath(interfaceId, JRE_LOCATION_FILE, false, false, false, false); static const size_t jrePath_sizeMax = 1024; char jrePath[jrePath_sizeMax]; bool jreFound = GetJREPath(jrePath, jrePath_sizeMax, jreLocationFile, NULL); if (!jreFound) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed locating a JRE installation" ", you may specify the JAVA_HOME env var."); return false; } FREE(jreLocationFile); #if defined __arch64__ static const char* defJvmType = "server"; #else static const char* defJvmType = "client"; #endif const char* jvmType = java_getValueByKey(jvmCfgProps, "jvm.type"); if (jvmType == NULL) { jvmType = defJvmType; } static const size_t jvmLibPath_sizeMax = 1024; char jvmLibPath[jvmLibPath_sizeMax]; bool jvmLibFound = GetJVMPath(jrePath, jvmType, jvmLibPath, jvmLibPath_sizeMax, NULL); if (!jvmLibFound) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed locating the %s version of the JVM, please contact spring devs.", jvmType); return false; } jvmSharedLib = sharedLib_load(jvmLibPath); if (!sharedLib_isLoaded(jvmSharedLib)) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed to load the JVM at \"%s\".", jvmLibPath); return false; } else { simpleLog_logL(SIMPLELOG_LEVEL_NORMAL, "Successfully loaded the JVM shared library at \"%s\".", jvmLibPath); JNI_GetDefaultJavaVMInitArgs_f = (JNI_GetDefaultJavaVMInitArgs_t*) sharedLib_findAddress(jvmSharedLib, "JNI_GetDefaultJavaVMInitArgs"); if (JNI_GetDefaultJavaVMInitArgs_f == NULL) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed to load the JVM, function \"%s\" not exported.", "JNI_GetDefaultJavaVMInitArgs"); return false; } JNI_CreateJavaVM_f = (JNI_CreateJavaVM_t*) sharedLib_findAddress(jvmSharedLib, "JNI_CreateJavaVM"); if (JNI_CreateJavaVM_f == NULL) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed to load the JVM, function \"%s\" not exported.", "JNI_CreateJavaVM"); return false; } JNI_GetCreatedJavaVMs_f = (JNI_GetCreatedJavaVMs_t*) sharedLib_findAddress(jvmSharedLib, "JNI_GetCreatedJavaVMs"); if (JNI_GetCreatedJavaVMs_f == NULL) { simpleLog_logL(SIMPLELOG_LEVEL_ERROR, "Failed to load the JVM, function \"%s\" not exported.", "JNI_GetCreatedJavaVMs"); return false; } } java_establishJavaEnv(); JNIEnv* env = java_getJNIEnv(); bool success = (env != NULL); if (success) { const int res = eventsJniBridge_initStatic(env, skirmishAIId_sizeMax); success = (res == 0); } java_establishSpringEnv(); return success; }
void CreateExecutionEnvironment(int *pargc, char ***pargv, char *jrepath, jint so_jrepath, char *jvmpath, jint so_jvmpath) { char * jvmtype; int i = 0; int running = CURRENT_DATA_MODEL; int wanted = running; char** argv = *pargv; for (i = 0; i < *pargc ; i++) { if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) { wanted = 64; continue; } if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) { wanted = 32; continue; } } if (running != wanted) { JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); } /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath)) { JLI_ReportErrorMessage(JRE_ERROR1); exit(2); } /* Find the specified JVM type */ if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) { JLI_ReportErrorMessage(CFG_ERROR7); exit(1); } jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE); if (JLI_StrCmp(jvmtype, "ERROR") == 0) { JLI_ReportErrorMessage(CFG_ERROR9); exit(4); } jvmpath[0] = '\0'; if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) { JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); exit(4); } /* If we got here, jvmpath has been correctly initialized. */ /* Check if we need preload AWT */ #ifdef ENABLE_AWT_PRELOAD argv = *pargv; for (i = 0; i < *pargc ; i++) { /* Tests the "turn on" parameter only if not set yet. */ if (awtPreloadD3D < 0) { if (GetBoolParamValue(PARAM_PRELOAD_D3D, argv[i]) == 1) { awtPreloadD3D = 1; } } /* Test parameters which can disable preloading if not already disabled. */ if (awtPreloadD3D != 0) { if (GetBoolParamValue(PARAM_NODDRAW, argv[i]) == 1 || GetBoolParamValue(PARAM_D3D, argv[i]) == 0 || GetBoolParamValue(PARAM_OPENGL, argv[i]) == 1) { awtPreloadD3D = 0; /* no need to test the rest of the parameters */ break; } } } #endif /* ENABLE_AWT_PRELOAD */ }
/* * Starts AWT preloading */ int AWTPreload(const char *funcName) { int result = -1; /* load AWT library once (if several preload function should be called) */ if (hPreloadAwt == NULL) { /* awt.dll is not loaded yet */ char libraryPath[MAXPATHLEN]; int jrePathLen = 0; HMODULE hJava = NULL; HMODULE hVerify = NULL; while (1) { /* awt.dll depends on jvm.dll & java.dll; * jvm.dll is already loaded, so we need only java.dll; * java.dll depends on MSVCRT lib & verify.dll. */ if (!GetJREPath(libraryPath, MAXPATHLEN)) { break; } /* save path length */ jrePathLen = JLI_StrLen(libraryPath); /* load msvcrt 1st */ LoadMSVCRT(); /* load verify.dll */ JLI_StrCat(libraryPath, "\\bin\\verify.dll"); hVerify = LoadLibrary(libraryPath); if (hVerify == NULL) { break; } /* restore jrePath */ libraryPath[jrePathLen] = 0; /* load java.dll */ JLI_StrCat(libraryPath, "\\bin\\" JAVA_DLL); hJava = LoadLibrary(libraryPath); if (hJava == NULL) { break; } /* restore jrePath */ libraryPath[jrePathLen] = 0; /* load awt.dll */ JLI_StrCat(libraryPath, "\\bin\\awt.dll"); hPreloadAwt = LoadLibrary(libraryPath); if (hPreloadAwt == NULL) { break; } /* get "preloadStop" func ptr */ fnPreloadStop = (FnPreloadStop *)GetProcAddress(hPreloadAwt, "preloadStop"); break; } } if (hPreloadAwt != NULL) { FnPreloadStart *fnInit = (FnPreloadStart *)GetProcAddress(hPreloadAwt, funcName); if (fnInit != NULL) { /* don't forget to stop preloading */ awtPreloaded = 1; result = fnInit(); } } return result; }
void CreateExecutionEnvironment(int *pargc, char ***pargv, char jrepath[], jint so_jrepath, char jvmpath[], jint so_jvmpath, char jvmcfg[], jint so_jvmcfg) { /* * First, determine if we are running the desired data model. If we * are running the desired data model, all the error messages * associated with calling GetJREPath, ReadKnownVMs, etc. should be * output, otherwise we simply exit with an error, as we no longer * support dual data models. */ jboolean jvmpathExists; /* Compute/set the name of the executable */ SetExecname(*pargv); /* Check data model flags, and exec process, if needed */ { char *arch = LIBARCHNAME; /* like sparc or sparcv9 */ char * jvmtype = NULL; int argc = *pargc; char **argv = *pargv; int running = CURRENT_DATA_MODEL; /* * As of jdk9, there is no support for dual mode operations, however * for legacy error reporting purposes and until -d options are supported * we need this. */ int wanted = running; #ifdef SETENV_REQUIRED jboolean mustsetenv = JNI_FALSE; char *runpath = NULL; /* existing effective LD_LIBRARY_PATH setting */ char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */ char* newpath = NULL; /* path on new LD_LIBRARY_PATH */ char* lastslash = NULL; char** newenvp = NULL; /* current environment */ size_t new_runpath_size; #ifdef __solaris__ char* dmpath = NULL; /* data model specific LD_LIBRARY_PATH, Solaris only */ #endif /* __solaris__ */ #endif /* SETENV_REQUIRED */ char** newargv = NULL; int newargc = 0; /* * Starting in 1.5, all unix platforms accept the -d32 and -d64 * options. On platforms where only one data-model is supported * (e.g. ia-64 Linux), using the flag for the other data model is * an error and will terminate the program. */ { /* open new scope to declare local variables */ int i; newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*)); newargv[newargc++] = argv[0]; /* scan for data model arguments and remove from argument list; last occurrence determines desired data model */ for (i=1; i < argc; i++) { if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) { wanted = 64; continue; } if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) { wanted = 32; continue; } newargv[newargc++] = argv[i]; if (IsJavaArgs()) { if (argv[i][0] != '-') continue; } else { if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) { i++; if (i >= argc) break; newargv[newargc++] = argv[i]; continue; } if (argv[i][0] != '-') { i++; break; } } } /* copy rest of args [i .. argc) */ while (i < argc) { newargv[newargc++] = argv[i++]; } newargv[newargc] = NULL; /* * newargv has all proper arguments here */ argc = newargc; argv = newargv; } /* If the data model is not changing, it is an error if the jvmpath does not exist */ if (wanted == running) { /* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { JLI_ReportErrorMessage(JRE_ERROR1); exit(2); } JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg", jrepath, FILESEP, FILESEP, arch, FILESEP); /* Find the specified JVM type */ if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) { JLI_ReportErrorMessage(CFG_ERROR7); exit(1); } jvmpath[0] = '\0'; jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE); if (JLI_StrCmp(jvmtype, "ERROR") == 0) { JLI_ReportErrorMessage(CFG_ERROR9); exit(4); } if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, 0 )) { JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); exit(4); } /* * we seem to have everything we need, so without further ado * we return back, otherwise proceed to set the environment. */ #ifdef SETENV_REQUIRED mustsetenv = RequiresSetenv(jvmpath); JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE"); if (mustsetenv == JNI_FALSE) { JLI_MemFree(newargv); return; } #else JLI_MemFree(newargv); return; #endif /* SETENV_REQUIRED */ } else { /* do the same speculatively or exit */ JLI_ReportErrorMessage(JRE_ERROR2, wanted); exit(1); } #ifdef SETENV_REQUIRED if (mustsetenv) { /* * We will set the LD_LIBRARY_PATH as follows: * * o $JVMPATH (directory portion only) * o $JRE/lib/$LIBARCHNAME * o $JRE/../lib/$LIBARCHNAME * * followed by the user's previous effective LD_LIBRARY_PATH, if * any. */ #ifdef __solaris__ /* * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH * variables: * * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if * data-model specific variables are not set. * * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH * for 64-bit binaries. * The vm uses LD_LIBRARY_PATH to set the java.library.path system * property. To shield the vm from the complication of multiple * LD_LIBRARY_PATH variables, if the appropriate data model * specific variable is set, we will act as if LD_LIBRARY_PATH had * the value of the data model specific variant and the data model * specific variant will be unset. Note that the variable for the * *wanted* data model must be used (if it is set), not simply the * current running data model. */ switch (wanted) { case 0: case 64: dmpath = getenv("LD_LIBRARY_PATH_64"); wanted = 64; break; default: JLI_ReportErrorMessage(JRE_ERROR3, __LINE__); exit(1); /* unknown value in wanted */ break; } /* * If dmpath is NULL, the relevant data model specific variable is * not set and normal LD_LIBRARY_PATH should be used. */ if (dmpath == NULL) { runpath = getenv("LD_LIBRARY_PATH"); } else { runpath = dmpath; } #else /* ! __solaris__ */ /* * If not on Solaris, assume only a single LD_LIBRARY_PATH * variable. */ runpath = getenv(LD_LIBRARY_PATH); #endif /* __solaris__ */ /* runpath contains current effective LD_LIBRARY_PATH setting */ jvmpath = JLI_StringDup(jvmpath); new_runpath_size = ((runpath != NULL) ? JLI_StrLen(runpath) : 0) + 2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) + #ifdef AIX /* On AIX we additionally need 'jli' in the path because ld doesn't support $ORIGIN. */ JLI_StrLen(jrepath) + JLI_StrLen(arch) + JLI_StrLen("/lib//jli:") + #endif JLI_StrLen(jvmpath) + 52; new_runpath = JLI_MemAlloc(new_runpath_size); newpath = new_runpath + JLI_StrLen(LD_LIBRARY_PATH "="); /* * Create desired LD_LIBRARY_PATH value for target data model. */ { /* remove the name of the .so from the JVM path */ lastslash = JLI_StrRChr(jvmpath, '/'); if (lastslash) *lastslash = '\0'; sprintf(new_runpath, LD_LIBRARY_PATH "=" "%s:" "%s/lib/%s:" #ifdef AIX "%s/lib/%s/jli:" /* Needed on AIX because ld doesn't support $ORIGIN. */ #endif "%s/../lib/%s", jvmpath, jrepath, arch, #ifdef AIX jrepath, arch, #endif jrepath, arch ); /* * Check to make sure that the prefix of the current path is the * desired environment variable setting, though the RequiresSetenv * checks if the desired runpath exists, this logic does a more * comprehensive check. */ if (runpath != NULL && JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 && (runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') && (running == wanted) /* data model does not have to be changed */ #ifdef __solaris__ && (dmpath == NULL) /* data model specific variables not set */ #endif /* __solaris__ */ ) { JLI_MemFree(newargv); JLI_MemFree(new_runpath); return; } } /* * Place the desired environment setting onto the prefix of * LD_LIBRARY_PATH. Note that this prevents any possible infinite * loop of execv() because we test for the prefix, above. */ if (runpath != 0) { /* ensure storage for runpath + colon + NULL */ if ((JLI_StrLen(runpath) + 1 + 1) > new_runpath_size) { JLI_ReportErrorMessageSys(JRE_ERROR11); exit(1); } JLI_StrCat(new_runpath, ":"); JLI_StrCat(new_runpath, runpath); } if (putenv(new_runpath) != 0) { exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set properly */ } /* * Unix systems document that they look at LD_LIBRARY_PATH only * once at startup, so we have to re-exec the current executable * to get the changed environment variable to have an effect. */ #ifdef __solaris__ /* * If dmpath is not NULL, remove the data model specific string * in the environment for the exec'ed child. */ if (dmpath != NULL) (void)UnsetEnv("LD_LIBRARY_PATH_64"); #endif /* __solaris */ newenvp = environ; } #endif /* SETENV_REQUIRED */ { char *newexec = execname; JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); (void) fflush(stdout); (void) fflush(stderr); #ifdef SETENV_REQUIRED if (mustsetenv) { execve(newexec, argv, newenvp); } else { execv(newexec, argv); } #else /* !SETENV_REQUIRED */ execv(newexec, argv); #endif /* SETENV_REQUIRED */ JLI_ReportErrorMessageSys(JRE_ERROR4, newexec); } exit(1); } }
BOOL createJVM() { JavaVMInitArgs vm_args; jint res; char classpath[MAX_CLASSPATH_LEN]; char userdir[MAXPATHLEN]; char jvmpath[MAXPATHLEN]; char jrepath[MAXPATHLEN]; char apppath[2*MAXPATHLEN]; HINSTANCE handle; if (installDir == NULL || strlen(installDir) > MAXPATHLEN) return FALSE; if (GetJREPath(jrepath, sizeof jrepath) == FALSE) { logServiceMessage(_T("Can't find Java VM path"), EVENTLOG_ERROR_TYPE); return FALSE; } if (GetJVMPath(jrepath, "server", jvmpath, sizeof jvmpath) == FALSE) { if (GetJVMPath(jrepath, "client", jvmpath, sizeof jvmpath) == FALSE) { logServiceMessage(_T("Can't find neither server nor client Java VM path"), EVENTLOG_ERROR_TYPE); return FALSE; } } // Load the Java VM DLL if ((handle = LoadLibrary(jvmpath)) == 0) { logServiceMessage(_T("Error loading JVM"), EVENTLOG_ERROR_TYPE); return JNI_FALSE; } // IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond FARPROC jni_create_java_vm = GetProcAddress(handle, "JNI_CreateJavaVM"); FARPROC jni_get_default_java_vm_init_args = GetProcAddress(handle, "JNI_GetDefaultJavaVMInitArgs"); if(jni_create_java_vm && jni_get_default_java_vm_init_args == NULL) { return JNI_FALSE; } // find extra JVM parameters int narg = 0; char *pc = jvmArgs; if (jvmArgs) { while(*pc) { if (*pc == '\n') { narg++; *pc = 0; } *pc++; } } narg += 2; JavaVMOption *options = new JavaVMOption[narg]; vm_args.version = JNI_VERSION_1_4; vm_args.nOptions = narg; vm_args.options = options; vm_args.ignoreUnrecognized = JNI_TRUE; if (mainClass) sprintf_s(apppath, "%c%s\\lib\\app.jar%c%s\\app.jar", PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir); else *apppath = 0; // Append USER_CLASSPATH to the end of default system class path if (customCP) sprintf_s(classpath, sizeof classpath, "-Djava.class.path=%s\\webserver.jar%c%s\\lib\\webserver.jar%c" "%s\\servlet.jar%c%s\\lib\\servlet.jar%c%s\\war.jar%c%s\\lib\\war.jar%c%s\\lib\\wskt.jar%c%s\\lib\\class-scanner.jar%c%s\\lib\\javax.websocket-client-api.jar%c%s\\lib\\javax.websocket-server-api.jar%c%s%s", installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir , PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, customCP, apppath); else sprintf_s(classpath, sizeof classpath, "-Djava.class.path=%s\\webserver.jar%c%s\\lib\\webserver.jar%c" "%s\\servlet.jar%c%s\\lib\\servlet.jar%c%s\\war.jar%c%s\\lib\\war.jar%c%s\\lib\\wskt.jar%c%s\\lib\\class-scanner.jar%c%s\\lib\\javax.websocket-client-api.jar%c%s\\lib\\javax.websocket-server-api.jar%s", installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir , PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir, PATH_SEPARATOR, installDir,apppath); options[0].optionString = classpath; sprintf_s(userdir, sizeof userdir, "-Duser.dir=%s", installDir); options[1].optionString = userdir; pc = jvmArgs; for (int ia=2; ia<narg; ia++) { options[ia].optionString = pc; options[ia].extraInfo = NULL; pc += strlen(pc)+sizeof(char); } //logServiceMessage(userdir); // Create the Java VM res = ((jint (JNICALL *)(JavaVM **, void **, void *))jni_create_java_vm)(&jvm,(LPVOID*)&env,&vm_args); if (res < 0) { logServiceMessage(_T("Can't create Java VM"), EVENTLOG_ERROR_TYPE); return FALSE; } return TRUE; }