Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/bin/java_md.c
32285 views
/*1* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <windows.h>26#include <io.h>27#include <process.h>28#include <stdlib.h>29#include <stdio.h>30#include <stdarg.h>31#include <string.h>32#include <sys/types.h>33#include <sys/stat.h>34#include <wtypes.h>35#include <commctrl.h>3637#include <jni.h>38#include "java.h"39#include "version_comp.h"4041#define JVM_DLL "jvm.dll"42#define JAVA_DLL "java.dll"4344/*45* Prototypes.46*/47static jboolean GetPublicJREHome(char *path, jint pathsize);48static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,49char *jvmpath, jint jvmpathsize);50static jboolean GetJREPath(char *path, jint pathsize);5152/* We supports warmup for UI stack that is performed in parallel53* to VM initialization.54* This helps to improve startup of UI application as warmup phase55* might be long due to initialization of OS or hardware resources.56* It is not CPU bound and therefore it does not interfere with VM init.57* Obviously such warmup only has sense for UI apps and therefore it needs58* to be explicitly requested by passing -Dsun.awt.warmup=true property59* (this is always the case for plugin/javaws).60*61* Implementation launches new thread after VM starts and use it to perform62* warmup code (platform dependent).63* This thread is later reused as AWT toolkit thread as graphics toolkit64* often assume that they are used from the same thread they were launched on.65*66* At the moment we only support warmup for D3D. It only possible on windows67* and only if other flags do not prohibit this (e.g. OpenGL support requested).68*/69#undef ENABLE_AWT_PRELOAD70#ifndef JAVA_ARGS /* turn off AWT preloading for javac, jar, etc */71/* CR6999872: fastdebug crashes if awt library is loaded before JVM is72* initialized*/73#if !defined(DEBUG)74#define ENABLE_AWT_PRELOAD75#endif76#endif7778#ifdef ENABLE_AWT_PRELOAD79/* "AWT was preloaded" flag;80* turned on by AWTPreload().81*/82int awtPreloaded = 0;8384/* Calls a function with the name specified85* the function must be int(*fn)(void).86*/87int AWTPreload(const char *funcName);88/* stops AWT preloading */89void AWTPreloadStop();9091/* D3D preloading */92/* -1: not initialized; 0: OFF, 1: ON */93int awtPreloadD3D = -1;94/* command line parameter to swith D3D preloading on */95#define PARAM_PRELOAD_D3D "-Dsun.awt.warmup"96/* D3D/OpenGL management parameters */97#define PARAM_NODDRAW "-Dsun.java2d.noddraw"98#define PARAM_D3D "-Dsun.java2d.d3d"99#define PARAM_OPENGL "-Dsun.java2d.opengl"100/* funtion in awt.dll (src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp) */101#define D3D_PRELOAD_FUNC "preloadD3D"102103/* Extracts value of a parameter with the specified name104* from command line argument (returns pointer in the argument).105* Returns NULL if the argument does not contains the parameter.106* e.g.:107* GetParamValue("theParam", "theParam=value") returns pointer to "value".108*/109const char * GetParamValue(const char *paramName, const char *arg) {110int nameLen = JLI_StrLen(paramName);111if (JLI_StrNCmp(paramName, arg, nameLen) == 0) {112/* arg[nameLen] is valid (may contain final NULL) */113if (arg[nameLen] == '=') {114return arg + nameLen + 1;115}116}117return NULL;118}119120/* Checks if commandline argument contains property specified121* and analyze it as boolean property (true/false).122* Returns -1 if the argument does not contain the parameter;123* Returns 1 if the argument contains the parameter and its value is "true";124* Returns 0 if the argument contains the parameter and its value is "false".125*/126int GetBoolParamValue(const char *paramName, const char *arg) {127const char * paramValue = GetParamValue(paramName, arg);128if (paramValue != NULL) {129if (JLI_StrCaseCmp(paramValue, "true") == 0) {130return 1;131}132if (JLI_StrCaseCmp(paramValue, "false") == 0) {133return 0;134}135}136return -1;137}138#endif /* ENABLE_AWT_PRELOAD */139140141static jboolean _isjavaw = JNI_FALSE;142143144jboolean145IsJavaw()146{147return _isjavaw;148}149150/*151* Returns the arch path, to get the current arch use the152* macro GetArch, nbits here is ignored for now.153*/154const char *155GetArchPath(int nbits)156{157#ifdef _M_AMD64158return "amd64";159#elif defined(_M_IA64)160return "ia64";161#else162return "i386";163#endif164}165166/*167*168*/169void170CreateExecutionEnvironment(int *pargc, char ***pargv,171char *jrepath, jint so_jrepath,172char *jvmpath, jint so_jvmpath,173char *jvmcfg, jint so_jvmcfg) {174char * jvmtype;175int i = 0;176int running = CURRENT_DATA_MODEL;177178int wanted = running;179180char** argv = *pargv;181for (i = 1; i < *pargc ; i++) {182if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {183wanted = 64;184continue;185}186if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {187wanted = 32;188continue;189}190191if (IsJavaArgs() && argv[i][0] != '-')192continue;193if (argv[i][0] != '-')194break;195}196if (running != wanted) {197JLI_ReportErrorMessage(JRE_ERROR2, wanted);198exit(1);199}200201/* Find out where the JRE is that we will be using. */202if (!GetJREPath(jrepath, so_jrepath)) {203JLI_ReportErrorMessage(JRE_ERROR1);204exit(2);205}206207JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg",208jrepath, FILESEP, FILESEP, (char*)GetArch(), FILESEP);209210/* Find the specified JVM type */211if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {212JLI_ReportErrorMessage(CFG_ERROR7);213exit(1);214}215216jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);217if (JLI_StrCmp(jvmtype, "ERROR") == 0) {218JLI_ReportErrorMessage(CFG_ERROR9);219exit(4);220}221222jvmpath[0] = '\0';223if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {224JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);225exit(4);226}227/* If we got here, jvmpath has been correctly initialized. */228229/* Check if we need preload AWT */230#ifdef ENABLE_AWT_PRELOAD231argv = *pargv;232for (i = 0; i < *pargc ; i++) {233/* Tests the "turn on" parameter only if not set yet. */234if (awtPreloadD3D < 0) {235if (GetBoolParamValue(PARAM_PRELOAD_D3D, argv[i]) == 1) {236awtPreloadD3D = 1;237}238}239/* Test parameters which can disable preloading if not already disabled. */240if (awtPreloadD3D != 0) {241if (GetBoolParamValue(PARAM_NODDRAW, argv[i]) == 1242|| GetBoolParamValue(PARAM_D3D, argv[i]) == 0243|| GetBoolParamValue(PARAM_OPENGL, argv[i]) == 1)244{245awtPreloadD3D = 0;246/* no need to test the rest of the parameters */247break;248}249}250}251#endif /* ENABLE_AWT_PRELOAD */252}253254255static jboolean256LoadMSVCRT()257{258// Only do this once259static int loaded = 0;260char crtpath[MAXPATHLEN];261262if (!loaded) {263/*264* The Microsoft C Runtime Library needs to be loaded first. A copy is265* assumed to be present in the "JRE path" directory. If it is not found266* there (or "JRE path" fails to resolve), skip the explicit load and let267* nature take its course, which is likely to be a failure to execute.268* The makefiles will provide the correct lib contained in quotes in the269* macro MSVCR_DLL_NAME.270*/271#ifdef MSVCR_DLL_NAME272if (GetJREPath(crtpath, MAXPATHLEN)) {273if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") +274JLI_StrLen(MSVCR_DLL_NAME) >= MAXPATHLEN) {275JLI_ReportErrorMessage(JRE_ERROR11);276return JNI_FALSE;277}278(void)JLI_StrCat(crtpath, "\\bin\\" MSVCR_DLL_NAME); /* Add crt dll */279JLI_TraceLauncher("CRT path is %s\n", crtpath);280if (_access(crtpath, 0) == 0) {281if (LoadLibrary(crtpath) == 0) {282JLI_ReportErrorMessage(DLL_ERROR4, crtpath);283return JNI_FALSE;284}285}286}287#endif /* MSVCR_DLL_NAME */288#ifdef MSVCP_DLL_NAME289if (GetJREPath(crtpath, MAXPATHLEN)) {290if (JLI_StrLen(crtpath) + JLI_StrLen("\\bin\\") +291JLI_StrLen(MSVCP_DLL_NAME) >= MAXPATHLEN) {292JLI_ReportErrorMessage(JRE_ERROR11);293return JNI_FALSE;294}295(void)JLI_StrCat(crtpath, "\\bin\\" MSVCP_DLL_NAME); /* Add prt dll */296JLI_TraceLauncher("PRT path is %s\n", crtpath);297if (_access(crtpath, 0) == 0) {298if (LoadLibrary(crtpath) == 0) {299JLI_ReportErrorMessage(DLL_ERROR4, crtpath);300return JNI_FALSE;301}302}303}304#endif /* MSVCP_DLL_NAME */305loaded = 1;306}307return JNI_TRUE;308}309310311/*312* Find path to JRE based on .exe's location or registry settings.313*/314jboolean315GetJREPath(char *path, jint pathsize)316{317char javadll[MAXPATHLEN];318struct stat s;319320if (GetApplicationHome(path, pathsize)) {321/* Is JRE co-located with the application? */322JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);323if (stat(javadll, &s) == 0) {324JLI_TraceLauncher("JRE path is %s\n", path);325return JNI_TRUE;326}327/* ensure storage for path + \jre + NULL */328if ((JLI_StrLen(path) + 4 + 1) > pathsize) {329JLI_TraceLauncher("Insufficient space to store JRE path\n");330return JNI_FALSE;331}332/* Does this app ship a private JRE in <apphome>\jre directory? */333JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);334if (stat(javadll, &s) == 0) {335JLI_StrCat(path, "\\jre");336JLI_TraceLauncher("JRE path is %s\n", path);337return JNI_TRUE;338}339}340341/* Look for a public JRE on this machine. */342if (GetPublicJREHome(path, pathsize)) {343JLI_TraceLauncher("JRE path is %s\n", path);344return JNI_TRUE;345}346347JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);348return JNI_FALSE;349350}351352/*353* Given a JRE location and a JVM type, construct what the name the354* JVM shared library will be. Return true, if such a library355* exists, false otherwise.356*/357static jboolean358GetJVMPath(const char *jrepath, const char *jvmtype,359char *jvmpath, jint jvmpathsize)360{361struct stat s;362if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) {363JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype);364} else {365JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL,366jrepath, jvmtype);367}368if (stat(jvmpath, &s) == 0) {369return JNI_TRUE;370} else {371return JNI_FALSE;372}373}374375/*376* Load a jvm from "jvmpath" and initialize the invocation functions.377*/378jboolean379LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)380{381HINSTANCE handle;382383JLI_TraceLauncher("JVM path is %s\n", jvmpath);384385/*386* The Microsoft C Runtime Library needs to be loaded first. A copy is387* assumed to be present in the "JRE path" directory. If it is not found388* there (or "JRE path" fails to resolve), skip the explicit load and let389* nature take its course, which is likely to be a failure to execute.390*391*/392LoadMSVCRT();393394/* Load the Java VM DLL */395if ((handle = LoadLibrary(jvmpath)) == 0) {396JLI_ReportErrorMessage(DLL_ERROR4, (char *)jvmpath);397return JNI_FALSE;398}399400/* Now get the function addresses */401ifn->CreateJavaVM =402(void *)GetProcAddress(handle, "JNI_CreateJavaVM");403ifn->GetDefaultJavaVMInitArgs =404(void *)GetProcAddress(handle, "JNI_GetDefaultJavaVMInitArgs");405if (ifn->CreateJavaVM == 0 || ifn->GetDefaultJavaVMInitArgs == 0) {406JLI_ReportErrorMessage(JNI_ERROR1, (char *)jvmpath);407return JNI_FALSE;408}409410return JNI_TRUE;411}412413/*414* If app is "c:\foo\bin\javac", then put "c:\foo" into buf.415*/416jboolean417GetApplicationHome(char *buf, jint bufsize)418{419char *cp;420GetModuleFileName(0, buf, bufsize);421*JLI_StrRChr(buf, '\\') = '\0'; /* remove .exe file name */422if ((cp = JLI_StrRChr(buf, '\\')) == 0) {423/* This happens if the application is in a drive root, and424* there is no bin directory. */425buf[0] = '\0';426return JNI_FALSE;427}428*cp = '\0'; /* remove the bin\ part */429return JNI_TRUE;430}431432/*433* Helpers to look in the registry for a public JRE.434*/435/* Same for 1.5.0, 1.5.1, 1.5.2 etc. */436#define JRE_KEY "Software\\JavaSoft\\Java Runtime Environment"437438static jboolean439GetStringFromRegistry(HKEY key, const char *name, char *buf, jint bufsize)440{441DWORD type, size;442443if (RegQueryValueEx(key, name, 0, &type, 0, &size) == 0444&& type == REG_SZ445&& (size < (unsigned int)bufsize)) {446if (RegQueryValueEx(key, name, 0, 0, buf, &size) == 0) {447return JNI_TRUE;448}449}450return JNI_FALSE;451}452453static jboolean454GetPublicJREHome(char *buf, jint bufsize)455{456HKEY key, subkey;457char version[MAXPATHLEN];458459/*460* Note: There is a very similar implementation of the following461* registry reading code in the Windows java control panel (javacp.cpl).462* If there are bugs here, a similar bug probably exists there. Hence,463* changes here require inspection there.464*/465466/* Find the current version of the JRE */467if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_KEY, 0, KEY_READ, &key) != 0) {468JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY);469return JNI_FALSE;470}471472if (!GetStringFromRegistry(key, "CurrentVersion",473version, sizeof(version))) {474JLI_ReportErrorMessage(REG_ERROR2, JRE_KEY);475RegCloseKey(key);476return JNI_FALSE;477}478479if (JLI_StrCmp(version, GetDotVersion()) != 0) {480JLI_ReportErrorMessage(REG_ERROR3, JRE_KEY, version, GetDotVersion()481);482RegCloseKey(key);483return JNI_FALSE;484}485486/* Find directory where the current version is installed. */487if (RegOpenKeyEx(key, version, 0, KEY_READ, &subkey) != 0) {488JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY, version);489RegCloseKey(key);490return JNI_FALSE;491}492493if (!GetStringFromRegistry(subkey, "JavaHome", buf, bufsize)) {494JLI_ReportErrorMessage(REG_ERROR4, JRE_KEY, version);495RegCloseKey(key);496RegCloseKey(subkey);497return JNI_FALSE;498}499500if (JLI_IsTraceLauncher()) {501char micro[MAXPATHLEN];502if (!GetStringFromRegistry(subkey, "MicroVersion", micro,503sizeof(micro))) {504printf("Warning: Can't read MicroVersion\n");505micro[0] = '\0';506}507printf("Version major.minor.micro = %s.%s\n", version, micro);508}509510RegCloseKey(key);511RegCloseKey(subkey);512return JNI_TRUE;513}514515/*516* Support for doing cheap, accurate interval timing.517*/518static jboolean counterAvailable = JNI_FALSE;519static jboolean counterInitialized = JNI_FALSE;520static LARGE_INTEGER counterFrequency;521522jlong CounterGet()523{524LARGE_INTEGER count;525526if (!counterInitialized) {527counterAvailable = QueryPerformanceFrequency(&counterFrequency);528counterInitialized = JNI_TRUE;529}530if (!counterAvailable) {531return 0;532}533QueryPerformanceCounter(&count);534return (jlong)(count.QuadPart);535}536537jlong Counter2Micros(jlong counts)538{539if (!counterAvailable || !counterInitialized) {540return 0;541}542return (counts * 1000 * 1000)/counterFrequency.QuadPart;543}544/*545* windows snprintf does not guarantee a null terminator in the buffer,546* if the computed size is equal to or greater than the buffer size,547* as well as error conditions. This function guarantees a null terminator548* under all these conditions. An unreasonable buffer or size will return549* an error value. Under all other conditions this function will return the550* size of the bytes actually written minus the null terminator, similar551* to ansi snprintf api. Thus when calling this function the caller must552* ensure storage for the null terminator.553*/554int555JLI_Snprintf(char* buffer, size_t size, const char* format, ...) {556int rc;557va_list vl;558if (size == 0 || buffer == NULL)559return -1;560buffer[0] = '\0';561va_start(vl, format);562rc = vsnprintf(buffer, size, format, vl);563va_end(vl);564/* force a null terminator, if something is amiss */565if (rc < 0) {566/* apply ansi semantics */567buffer[size - 1] = '\0';568return size;569} else if (rc == size) {570/* force a null terminator */571buffer[size - 1] = '\0';572}573return rc;574}575576void577JLI_ReportErrorMessage(const char* fmt, ...) {578va_list vl;579va_start(vl,fmt);580581if (IsJavaw()) {582char *message;583584/* get the length of the string we need */585int n = _vscprintf(fmt, vl);586587message = (char *)JLI_MemAlloc(n + 1);588_vsnprintf(message, n, fmt, vl);589message[n]='\0';590MessageBox(NULL, message, "Java Virtual Machine Launcher",591(MB_OK|MB_ICONSTOP|MB_APPLMODAL));592JLI_MemFree(message);593} else {594vfprintf(stderr, fmt, vl);595fprintf(stderr, "\n");596}597va_end(vl);598}599600/*601* Just like JLI_ReportErrorMessage, except that it concatenates the system602* error message if any, its upto the calling routine to correctly603* format the separation of the messages.604*/605void606JLI_ReportErrorMessageSys(const char *fmt, ...)607{608va_list vl;609610int save_errno = errno;611DWORD errval;612jboolean freeit = JNI_FALSE;613char *errtext = NULL;614615va_start(vl, fmt);616617if ((errval = GetLastError()) != 0) { /* Platform SDK / DOS Error */618int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|619FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,620NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);621if (errtext == NULL || n == 0) { /* Paranoia check */622errtext = "";623n = 0;624} else {625freeit = JNI_TRUE;626if (n > 2) { /* Drop final CR, LF */627if (errtext[n - 1] == '\n') n--;628if (errtext[n - 1] == '\r') n--;629errtext[n] = '\0';630}631}632} else { /* C runtime error that has no corresponding DOS error code */633errtext = strerror(save_errno);634}635636if (IsJavaw()) {637char *message;638int mlen;639/* get the length of the string we need */640int len = mlen = _vscprintf(fmt, vl) + 1;641if (freeit) {642mlen += (int)JLI_StrLen(errtext);643}644645message = (char *)JLI_MemAlloc(mlen);646_vsnprintf(message, len, fmt, vl);647message[len]='\0';648649if (freeit) {650JLI_StrCat(message, errtext);651}652653MessageBox(NULL, message, "Java Virtual Machine Launcher",654(MB_OK|MB_ICONSTOP|MB_APPLMODAL));655656JLI_MemFree(message);657} else {658vfprintf(stderr, fmt, vl);659if (freeit) {660fprintf(stderr, "%s", errtext);661}662}663if (freeit) {664(void)LocalFree((HLOCAL)errtext);665}666va_end(vl);667}668669void JLI_ReportExceptionDescription(JNIEnv * env) {670if (IsJavaw()) {671/*672* This code should be replaced by code which opens a window with673* the exception detail message, for now atleast put a dialog up.674*/675MessageBox(NULL, "A Java Exception has occurred.", "Java Virtual Machine Launcher",676(MB_OK|MB_ICONSTOP|MB_APPLMODAL));677} else {678(*env)->ExceptionDescribe(env);679}680}681682jboolean683ServerClassMachine() {684return (GetErgoPolicy() == ALWAYS_SERVER_CLASS) ? JNI_TRUE : JNI_FALSE;685}686687/*688* Determine if there is an acceptable JRE in the registry directory top_key.689* Upon locating the "best" one, return a fully qualified path to it.690* "Best" is defined as the most advanced JRE meeting the constraints691* contained in the manifest_info. If no JRE in this directory meets the692* constraints, return NULL.693*694* It doesn't matter if we get an error reading the registry, or we just695* don't find anything interesting in the directory. We just return NULL696* in either case.697*/698static char *699ProcessDir(manifest_info* info, HKEY top_key) {700DWORD index = 0;701HKEY ver_key;702char name[MAXNAMELEN];703int len;704char *best = NULL;705706/*707* Enumerate "<top_key>/SOFTWARE/JavaSoft/Java Runtime Environment"708* searching for the best available version.709*/710while (RegEnumKey(top_key, index, name, MAXNAMELEN) == ERROR_SUCCESS) {711index++;712if (JLI_AcceptableRelease(name, info->jre_version))713if ((best == NULL) || (JLI_ExactVersionId(name, best) > 0)) {714if (best != NULL)715JLI_MemFree(best);716best = JLI_StringDup(name);717}718}719720/*721* Extract "JavaHome" from the "best" registry directory and return722* that path. If no appropriate version was located, or there is an723* error in extracting the "JavaHome" string, return null.724*/725if (best == NULL)726return (NULL);727else {728if (RegOpenKeyEx(top_key, best, 0, KEY_READ, &ver_key)729!= ERROR_SUCCESS) {730JLI_MemFree(best);731if (ver_key != NULL)732RegCloseKey(ver_key);733return (NULL);734}735JLI_MemFree(best);736len = MAXNAMELEN;737if (RegQueryValueEx(ver_key, "JavaHome", NULL, NULL, (LPBYTE)name, &len)738!= ERROR_SUCCESS) {739if (ver_key != NULL)740RegCloseKey(ver_key);741return (NULL);742}743if (ver_key != NULL)744RegCloseKey(ver_key);745return (JLI_StringDup(name));746}747}748749/*750* This is the global entry point. It examines the host for the optimal751* JRE to be used by scanning a set of registry entries. This set of entries752* is hardwired on Windows as "Software\JavaSoft\Java Runtime Environment"753* under the set of roots "{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }".754*755* This routine simply opens each of these registry directories before passing756* control onto ProcessDir().757*/758char *759LocateJRE(manifest_info* info) {760HKEY key = NULL;761char *path;762int key_index;763HKEY root_keys[2] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE };764765for (key_index = 0; key_index <= 1; key_index++) {766if (RegOpenKeyEx(root_keys[key_index], JRE_KEY, 0, KEY_READ, &key)767== ERROR_SUCCESS)768if ((path = ProcessDir(info, key)) != NULL) {769if (key != NULL)770RegCloseKey(key);771return (path);772}773if (key != NULL)774RegCloseKey(key);775}776return NULL;777}778779/*780* Local helper routine to isolate a single token (option or argument)781* from the command line.782*783* This routine accepts a pointer to a character pointer. The first784* token (as defined by MSDN command-line argument syntax) is isolated785* from that string.786*787* Upon return, the input character pointer pointed to by the parameter s788* is updated to point to the remainding, unscanned, portion of the string,789* or to a null character if the entire string has been consummed.790*791* This function returns a pointer to a null-terminated string which792* contains the isolated first token, or to the null character if no793* token could be isolated.794*795* Note the side effect of modifying the input string s by the insertion796* of a null character, making it two strings.797*798* See "Parsing C Command-Line Arguments" in the MSDN Library for the799* parsing rule details. The rule summary from that specification is:800*801* * Arguments are delimited by white space, which is either a space or a tab.802*803* * A string surrounded by double quotation marks is interpreted as a single804* argument, regardless of white space contained within. A quoted string can805* be embedded in an argument. Note that the caret (^) is not recognized as806* an escape character or delimiter.807*808* * A double quotation mark preceded by a backslash, \", is interpreted as a809* literal double quotation mark (").810*811* * Backslashes are interpreted literally, unless they immediately precede a812* double quotation mark.813*814* * If an even number of backslashes is followed by a double quotation mark,815* then one backslash (\) is placed in the argv array for every pair of816* backslashes (\\), and the double quotation mark (") is interpreted as a817* string delimiter.818*819* * If an odd number of backslashes is followed by a double quotation mark,820* then one backslash (\) is placed in the argv array for every pair of821* backslashes (\\) and the double quotation mark is interpreted as an822* escape sequence by the remaining backslash, causing a literal double823* quotation mark (") to be placed in argv.824*/825static char*826nextarg(char** s) {827char *p = *s;828char *head;829int slashes = 0;830int inquote = 0;831832/*833* Strip leading whitespace, which MSDN defines as only space or tab.834* (Hence, no locale specific "isspace" here.)835*/836while (*p != (char)0 && (*p == ' ' || *p == '\t'))837p++;838head = p; /* Save the start of the token to return */839840/*841* Isolate a token from the command line.842*/843while (*p != (char)0 && (inquote || !(*p == ' ' || *p == '\t'))) {844if (*p == '\\' && *(p+1) == '"' && slashes % 2 == 0)845p++;846else if (*p == '"')847inquote = !inquote;848slashes = (*p++ == '\\') ? slashes + 1 : 0;849}850851/*852* If the token isolated isn't already terminated in a "char zero",853* then replace the whitespace character with one and move to the854* next character.855*/856if (*p != (char)0)857*p++ = (char)0;858859/*860* Update the parameter to point to the head of the remaining string861* reflecting the command line and return a pointer to the leading862* token which was isolated from the command line.863*/864*s = p;865return (head);866}867868/*869* Local helper routine to return a string equivalent to the input string870* s, but with quotes removed so the result is a string as would be found871* in argv[]. The returned string should be freed by a call to JLI_MemFree().872*873* The rules for quoting (and escaped quotes) are:874*875* 1 A double quotation mark preceded by a backslash, \", is interpreted as a876* literal double quotation mark (").877*878* 2 Backslashes are interpreted literally, unless they immediately precede a879* double quotation mark.880*881* 3 If an even number of backslashes is followed by a double quotation mark,882* then one backslash (\) is placed in the argv array for every pair of883* backslashes (\\), and the double quotation mark (") is interpreted as a884* string delimiter.885*886* 4 If an odd number of backslashes is followed by a double quotation mark,887* then one backslash (\) is placed in the argv array for every pair of888* backslashes (\\) and the double quotation mark is interpreted as an889* escape sequence by the remaining backslash, causing a literal double890* quotation mark (") to be placed in argv.891*/892static char*893unquote(const char *s) {894const char *p = s; /* Pointer to the tail of the original string */895char *un = (char*)JLI_MemAlloc(JLI_StrLen(s) + 1); /* Ptr to unquoted string */896char *pun = un; /* Pointer to the tail of the unquoted string */897898while (*p != '\0') {899if (*p == '"') {900p++;901} else if (*p == '\\') {902const char *q = p + JLI_StrSpn(p,"\\");903if (*q == '"')904do {905*pun++ = '\\';906p += 2;907} while (*p == '\\' && p < q);908else909while (p < q)910*pun++ = *p++;911} else {912*pun++ = *p++;913}914}915*pun = '\0';916return un;917}918919/*920* Given a path to a jre to execute, this routine checks if this process921* is indeed that jre. If not, it exec's that jre.922*923* We want to actually check the paths rather than just the version string924* built into the executable, so that given version specification will yield925* the exact same Java environment, regardless of the version of the arbitrary926* launcher we start with.927*/928void929ExecJRE(char *jre, char **argv) {930jint len;931char path[MAXPATHLEN + 1];932933const char *progname = GetProgramName();934935/*936* Resolve the real path to the currently running launcher.937*/938len = GetModuleFileName(NULL, path, MAXPATHLEN + 1);939if (len == 0 || len > MAXPATHLEN) {940JLI_ReportErrorMessageSys(JRE_ERROR9, progname);941exit(1);942}943944JLI_TraceLauncher("ExecJRE: old: %s\n", path);945JLI_TraceLauncher("ExecJRE: new: %s\n", jre);946947/*948* If the path to the selected JRE directory is a match to the initial949* portion of the path to the currently executing JRE, we have a winner!950* If so, just return.951*/952if (JLI_StrNCaseCmp(jre, path, JLI_StrLen(jre)) == 0)953return; /* I am the droid you were looking for */954955/*956* If this isn't the selected version, exec the selected version.957*/958JLI_Snprintf(path, sizeof(path), "%s\\bin\\%s.exe", jre, progname);959960/*961* Although Windows has an execv() entrypoint, it doesn't actually962* overlay a process: it can only create a new process and terminate963* the old process. Therefore, any processes waiting on the initial964* process wake up and they shouldn't. Hence, a chain of pseudo-zombie965* processes must be retained to maintain the proper wait semantics.966* Fortunately the image size of the launcher isn't too large at this967* time.968*969* If it weren't for this semantic flaw, the code below would be ...970*971* execv(path, argv);972* JLI_ReportErrorMessage("Error: Exec of %s failed\n", path);973* exit(1);974*975* The incorrect exec semantics could be addressed by:976*977* exit((int)spawnv(_P_WAIT, path, argv));978*979* Unfortunately, a bug in Windows spawn/exec impementation prevents980* this from completely working. All the Windows POSIX process creation981* interfaces are implemented as wrappers around the native Windows982* function CreateProcess(). CreateProcess() takes a single string983* to specify command line options and arguments, so the POSIX routine984* wrappers build a single string from the argv[] array and in the985* process, any quoting information is lost.986*987* The solution to this to get the original command line, to process it988* to remove the new multiple JRE options (if any) as was done for argv989* in the common SelectVersion() routine and finally to pass it directly990* to the native CreateProcess() Windows process control interface.991*/992{993char *cmdline;994char *p;995char *np;996char *ocl;997char *ccl;998char *unquoted;999DWORD exitCode;1000STARTUPINFO si;1001PROCESS_INFORMATION pi;10021003/*1004* The following code block gets and processes the original command1005* line, replacing the argv[0] equivalent in the command line with1006* the path to the new executable and removing the appropriate1007* Multiple JRE support options. Note that similar logic exists1008* in the platform independent SelectVersion routine, but is1009* replicated here due to the syntax of CreateProcess().1010*1011* The magic "+ 4" characters added to the command line length are1012* 2 possible quotes around the path (argv[0]), a space after the1013* path and a terminating null character.1014*/1015ocl = GetCommandLine();1016np = ccl = JLI_StringDup(ocl);1017p = nextarg(&np); /* Discard argv[0] */1018cmdline = (char *)JLI_MemAlloc(JLI_StrLen(path) + JLI_StrLen(np) + 4);1019if (JLI_StrChr(path, (int)' ') == NULL && JLI_StrChr(path, (int)'\t') == NULL)1020cmdline = JLI_StrCpy(cmdline, path);1021else1022cmdline = JLI_StrCat(JLI_StrCat(JLI_StrCpy(cmdline, "\""), path), "\"");10231024while (*np != (char)0) { /* While more command-line */1025p = nextarg(&np);1026if (*p != (char)0) { /* If a token was isolated */1027unquoted = unquote(p);1028if (*unquoted == '-') { /* Looks like an option */1029if (JLI_StrCmp(unquoted, "-classpath") == 0 ||1030JLI_StrCmp(unquoted, "-cp") == 0) { /* Unique cp syntax */1031cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);1032p = nextarg(&np);1033if (*p != (char)0) /* If a token was isolated */1034cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);1035} else if (JLI_StrNCmp(unquoted, "-version:", 9) != 0 &&1036JLI_StrCmp(unquoted, "-jre-restrict-search") != 0 &&1037JLI_StrCmp(unquoted, "-no-jre-restrict-search") != 0) {1038cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);1039}1040} else { /* End of options */1041cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);1042cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), np);1043JLI_MemFree((void *)unquoted);1044break;1045}1046JLI_MemFree((void *)unquoted);1047}1048}1049JLI_MemFree((void *)ccl);10501051if (JLI_IsTraceLauncher()) {1052np = ccl = JLI_StringDup(cmdline);1053p = nextarg(&np);1054printf("ReExec Command: %s (%s)\n", path, p);1055printf("ReExec Args: %s\n", np);1056JLI_MemFree((void *)ccl);1057}1058(void)fflush(stdout);1059(void)fflush(stderr);10601061/*1062* The following code is modeled after a model presented in the1063* Microsoft Technical Article "Moving Unix Applications to1064* Windows NT" (March 6, 1994) and "Creating Processes" on MSDN1065* (Februrary 2005). It approximates UNIX spawn semantics with1066* the parent waiting for termination of the child.1067*/1068memset(&si, 0, sizeof(si));1069si.cb =sizeof(STARTUPINFO);1070memset(&pi, 0, sizeof(pi));10711072if (!CreateProcess((LPCTSTR)path, /* executable name */1073(LPTSTR)cmdline, /* command line */1074(LPSECURITY_ATTRIBUTES)NULL, /* process security attr. */1075(LPSECURITY_ATTRIBUTES)NULL, /* thread security attr. */1076(BOOL)TRUE, /* inherits system handles */1077(DWORD)0, /* creation flags */1078(LPVOID)NULL, /* environment block */1079(LPCTSTR)NULL, /* current directory */1080(LPSTARTUPINFO)&si, /* (in) startup information */1081(LPPROCESS_INFORMATION)&pi)) { /* (out) process information */1082JLI_ReportErrorMessageSys(SYS_ERROR1, path);1083exit(1);1084}10851086if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) {1087if (GetExitCodeProcess(pi.hProcess, &exitCode) == FALSE)1088exitCode = 1;1089} else {1090JLI_ReportErrorMessage(SYS_ERROR2);1091exitCode = 1;1092}10931094CloseHandle(pi.hThread);1095CloseHandle(pi.hProcess);10961097exit(exitCode);1098}1099}11001101/*1102* Wrapper for platform dependent unsetenv function.1103*/1104int1105UnsetEnv(char *name)1106{1107int ret;1108char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);1109buf = JLI_StrCat(JLI_StrCpy(buf, name), "=");1110ret = _putenv(buf);1111JLI_MemFree(buf);1112return (ret);1113}11141115/* --- Splash Screen shared library support --- */11161117static const char* SPLASHSCREEN_SO = "\\bin\\splashscreen.dll";11181119static HMODULE hSplashLib = NULL;11201121void* SplashProcAddress(const char* name) {1122char libraryPath[MAXPATHLEN]; /* some extra space for JLI_StrCat'ing SPLASHSCREEN_SO */11231124if (!GetJREPath(libraryPath, MAXPATHLEN)) {1125return NULL;1126}1127if (JLI_StrLen(libraryPath)+JLI_StrLen(SPLASHSCREEN_SO) >= MAXPATHLEN) {1128return NULL;1129}1130JLI_StrCat(libraryPath, SPLASHSCREEN_SO);11311132if (!hSplashLib) {1133hSplashLib = LoadLibrary(libraryPath);1134}1135if (hSplashLib) {1136return GetProcAddress(hSplashLib, name);1137} else {1138return NULL;1139}1140}11411142void SplashFreeLibrary() {1143if (hSplashLib) {1144FreeLibrary(hSplashLib);1145hSplashLib = NULL;1146}1147}11481149const char *1150jlong_format_specifier() {1151return "%I64d";1152}11531154/*1155* Block current thread and continue execution in a new thread1156*/1157int1158ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {1159int rslt = 0;1160unsigned thread_id;11611162#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION1163#define STACK_SIZE_PARAM_IS_A_RESERVATION (0x10000)1164#endif11651166/*1167* STACK_SIZE_PARAM_IS_A_RESERVATION is what we want, but it's not1168* supported on older version of Windows. Try first with the flag; and1169* if that fails try again without the flag. See MSDN document or HotSpot1170* source (os_win32.cpp) for details.1171*/1172HANDLE thread_handle =1173(HANDLE)_beginthreadex(NULL,1174(unsigned)stack_size,1175continuation,1176args,1177STACK_SIZE_PARAM_IS_A_RESERVATION,1178&thread_id);1179if (thread_handle == NULL) {1180thread_handle =1181(HANDLE)_beginthreadex(NULL,1182(unsigned)stack_size,1183continuation,1184args,11850,1186&thread_id);1187}11881189/* AWT preloading (AFTER main thread start) */1190#ifdef ENABLE_AWT_PRELOAD1191/* D3D preloading */1192if (awtPreloadD3D != 0) {1193char *envValue;1194/* D3D routines checks env.var J2D_D3D if no appropriate1195* command line params was specified1196*/1197envValue = getenv("J2D_D3D");1198if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {1199awtPreloadD3D = 0;1200}1201/* Test that AWT preloading isn't disabled by J2D_D3D_PRELOAD env.var */1202envValue = getenv("J2D_D3D_PRELOAD");1203if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {1204awtPreloadD3D = 0;1205}1206if (awtPreloadD3D < 0) {1207/* If awtPreloadD3D is still undefined (-1), test1208* if it is turned on by J2D_D3D_PRELOAD env.var.1209* By default it's turned OFF.1210*/1211awtPreloadD3D = 0;1212if (envValue != NULL && JLI_StrCaseCmp(envValue, "true") == 0) {1213awtPreloadD3D = 1;1214}1215}1216}1217if (awtPreloadD3D) {1218AWTPreload(D3D_PRELOAD_FUNC);1219}1220#endif /* ENABLE_AWT_PRELOAD */12211222if (thread_handle) {1223WaitForSingleObject(thread_handle, INFINITE);1224GetExitCodeThread(thread_handle, &rslt);1225CloseHandle(thread_handle);1226} else {1227rslt = continuation(args);1228}12291230#ifdef ENABLE_AWT_PRELOAD1231if (awtPreloaded) {1232AWTPreloadStop();1233}1234#endif /* ENABLE_AWT_PRELOAD */12351236return rslt;1237}12381239/* Unix only, empty on windows. */1240void SetJavaLauncherPlatformProps() {}12411242/*1243* The implementation for finding classes from the bootstrap1244* class loader, refer to java.h1245*/1246static FindClassFromBootLoader_t *findBootClass = NULL;12471248jclass FindBootStrapClass(JNIEnv *env, const char *classname)1249{1250HMODULE hJvm;12511252if (findBootClass == NULL) {1253hJvm = GetModuleHandle(JVM_DLL);1254if (hJvm == NULL) return NULL;1255/* need to use the demangled entry point */1256findBootClass = (FindClassFromBootLoader_t *)GetProcAddress(hJvm,1257"JVM_FindClassFromBootLoader");1258if (findBootClass == NULL) {1259JLI_ReportErrorMessage(DLL_ERROR4, "JVM_FindClassFromBootLoader");1260return NULL;1261}1262}1263return findBootClass(env, classname);1264}12651266void1267InitLauncher(boolean javaw)1268{1269INITCOMMONCONTROLSEX icx;12701271/*1272* Required for javaw mode MessageBox output as well as for1273* HotSpot -XX:+ShowMessageBoxOnError in java mode, an empty1274* flag field is sufficient to perform the basic UI initialization.1275*/1276memset(&icx, 0, sizeof(INITCOMMONCONTROLSEX));1277icx.dwSize = sizeof(INITCOMMONCONTROLSEX);1278InitCommonControlsEx(&icx);1279_isjavaw = javaw;1280JLI_SetTraceLauncher();1281}128212831284/* ============================== */1285/* AWT preloading */1286#ifdef ENABLE_AWT_PRELOAD12871288typedef int FnPreloadStart(void);1289typedef void FnPreloadStop(void);1290static FnPreloadStop *fnPreloadStop = NULL;1291static HMODULE hPreloadAwt = NULL;12921293/*1294* Starts AWT preloading1295*/1296int AWTPreload(const char *funcName)1297{1298int result = -1;1299/* load AWT library once (if several preload function should be called) */1300if (hPreloadAwt == NULL) {1301/* awt.dll is not loaded yet */1302char libraryPath[MAXPATHLEN];1303int jrePathLen = 0;1304HMODULE hJava = NULL;1305HMODULE hVerify = NULL;13061307while (1) {1308/* awt.dll depends on jvm.dll & java.dll;1309* jvm.dll is already loaded, so we need only java.dll;1310* java.dll depends on MSVCRT lib & verify.dll.1311*/1312if (!GetJREPath(libraryPath, MAXPATHLEN)) {1313break;1314}13151316/* save path length */1317jrePathLen = JLI_StrLen(libraryPath);13181319if (jrePathLen + JLI_StrLen("\\bin\\verify.dll") >= MAXPATHLEN) {1320/* jre path is too long, the library path will not fit there;1321* report and abort preloading1322*/1323JLI_ReportErrorMessage(JRE_ERROR11);1324break;1325}13261327/* load msvcrt 1st */1328LoadMSVCRT();13291330/* load verify.dll */1331JLI_StrCat(libraryPath, "\\bin\\verify.dll");1332hVerify = LoadLibrary(libraryPath);1333if (hVerify == NULL) {1334break;1335}13361337/* restore jrePath */1338libraryPath[jrePathLen] = 0;1339/* load java.dll */1340JLI_StrCat(libraryPath, "\\bin\\" JAVA_DLL);1341hJava = LoadLibrary(libraryPath);1342if (hJava == NULL) {1343break;1344}13451346/* restore jrePath */1347libraryPath[jrePathLen] = 0;1348/* load awt.dll */1349JLI_StrCat(libraryPath, "\\bin\\awt.dll");1350hPreloadAwt = LoadLibrary(libraryPath);1351if (hPreloadAwt == NULL) {1352break;1353}13541355/* get "preloadStop" func ptr */1356fnPreloadStop = (FnPreloadStop *)GetProcAddress(hPreloadAwt, "preloadStop");13571358break;1359}1360}13611362if (hPreloadAwt != NULL) {1363FnPreloadStart *fnInit = (FnPreloadStart *)GetProcAddress(hPreloadAwt, funcName);1364if (fnInit != NULL) {1365/* don't forget to stop preloading */1366awtPreloaded = 1;13671368result = fnInit();1369}1370}13711372return result;1373}13741375/*1376* Terminates AWT preloading1377*/1378void AWTPreloadStop() {1379if (fnPreloadStop != NULL) {1380fnPreloadStop();1381}1382}13831384#endif /* ENABLE_AWT_PRELOAD */13851386int1387JVMInit(InvocationFunctions* ifn, jlong threadStackSize,1388int argc, char **argv,1389int mode, char *what, int ret)1390{1391ShowSplashScreen();1392return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);1393}13941395void1396PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)1397{1398// stubbed out for windows and *nixes.1399}14001401void1402RegisterThread()1403{1404// stubbed out for windows and *nixes.1405}14061407/*1408* on windows, we return a false to indicate this option is not applicable1409*/1410jboolean1411ProcessPlatformOption(const char *arg)1412{1413return JNI_FALSE;1414}14151416int1417filterArgs(StdArg *stdargs, const int nargc, StdArg **pargv) {1418StdArg* argv = NULL;1419int nargs = 0;1420int i;14211422/* Copy the non-vm args */1423for (i = 0; i < nargc ; i++) {1424const char *arg = stdargs[i].arg;1425if (arg[0] == '-' && arg[1] == 'J')1426continue;1427argv = (StdArg*) JLI_MemRealloc(argv, (nargs+1) * sizeof(StdArg));1428argv[nargs].arg = JLI_StringDup(arg);1429argv[nargs].has_wildcard = stdargs[i].has_wildcard;1430nargs++;1431}1432*pargv = argv;1433return nargs;1434}14351436/*1437* At this point we have the arguments to the application, and we need to1438* check with original stdargs in order to compare which of these truly1439* needs expansion. cmdtoargs will specify this if it finds a bare1440* (unquoted) argument containing a glob character(s) ie. * or ?1441*/1442jobjectArray1443CreateApplicationArgs(JNIEnv *env, char **strv, int argc)1444{1445int i, j, idx, tlen;1446jobjectArray outArray, inArray;1447char *ostart, *astart, **nargv;1448jboolean needs_expansion = JNI_FALSE;1449jmethodID mid;1450int filteredargc, stdargc;1451StdArg *stdargs;1452StdArg *filteredargs;1453jclass cls = GetLauncherHelperClass(env);1454NULL_CHECK0(cls);14551456if (argc == 0) {1457return NewPlatformStringArray(env, strv, argc);1458}1459// the holy grail we need to compare with.1460stdargs = JLI_GetStdArgs();1461stdargc = JLI_GetStdArgc();14621463filteredargc = filterArgs(stdargs, stdargc, &filteredargs);14641465// sanity check, this should never happen1466if (argc > stdargc) {1467JLI_TraceLauncher("Warning: app args is larger than the original, %d %d\n", argc, stdargc);1468JLI_TraceLauncher("passing arguments as-is.\n");1469return NewPlatformStringArray(env, strv, argc);1470}14711472// sanity check, match the args we have, to the holy grail1473idx = filteredargc - argc;1474ostart = filteredargs[idx].arg;1475astart = strv[0];1476// sanity check, ensure that the first argument of the arrays are the same1477if (JLI_StrCmp(ostart, astart) != 0) {1478// some thing is amiss the args don't match1479JLI_TraceLauncher("Warning: app args parsing error\n");1480JLI_TraceLauncher("passing arguments as-is\n");1481return NewPlatformStringArray(env, strv, argc);1482}14831484// make a copy of the args which will be expanded in java if required.1485nargv = (char **)JLI_MemAlloc(argc * sizeof(char*));1486for (i = 0, j = idx; i < argc; i++, j++) {1487jboolean arg_expand = (JLI_StrCmp(filteredargs[j].arg, strv[i]) == 0)1488? filteredargs[j].has_wildcard1489: JNI_FALSE;1490if (needs_expansion == JNI_FALSE)1491needs_expansion = arg_expand;14921493// indicator char + String + NULL terminator, the java method will strip1494// out the first character, the indicator character, so no matter what1495// we add the indicator1496tlen = 1 + JLI_StrLen(strv[i]) + 1;1497nargv[i] = (char *) JLI_MemAlloc(tlen);1498if (JLI_Snprintf(nargv[i], tlen, "%c%s", arg_expand ? 'T' : 'F',1499strv[i]) < 0) {1500return NULL;1501}1502JLI_TraceLauncher("%s\n", nargv[i]);1503}15041505if (!needs_expansion) {1506// clean up any allocated memory and return back the old arguments1507for (i = 0 ; i < argc ; i++) {1508JLI_MemFree(nargv[i]);1509}1510JLI_MemFree(nargv);1511return NewPlatformStringArray(env, strv, argc);1512}1513NULL_CHECK0(mid = (*env)->GetStaticMethodID(env, cls,1514"expandArgs",1515"([Ljava/lang/String;)[Ljava/lang/String;"));15161517// expand the arguments that require expansion, the java method will strip1518// out the indicator character.1519inArray = NewPlatformStringArray(env, nargv, argc);1520outArray = (*env)->CallStaticObjectMethod(env, cls, mid, inArray);1521for (i = 0; i < argc; i++) {1522JLI_MemFree(nargv[i]);1523}1524JLI_MemFree(nargv);1525JLI_MemFree(filteredargs);1526return outArray;1527}152815291530