java_md.c revision 795
/*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
#include <windows.h>
#include <io.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <wtypes.h>
#include <commctrl.h>
#include <jni.h>
#include "java.h"
#include "version_comp.h"
#define JVM_DLL "jvm.dll"
#define JAVA_DLL "java.dll"
/*
* Prototypes.
*/
IsJavaw()
{
return _isjavaw;
}
/*
* Returns the arch path, to get the current arch use the
* macro GetArch, nbits here is ignored for now.
*/
const char *
GetArchPath(int nbits)
{
#ifdef _M_AMD64
return "amd64";
return "ia64";
#else
return "i386";
#endif
}
/*
*
*/
void
char ***_argv,
char jrepath[],
char jvmpath[],
char **original_argv) {
char * jvmtype;
int i = 0;
int running = CURRENT_DATA_MODEL;
for (i = 0; i < *_argc ; i++) {
wanted = 64;
continue;
}
wanted = 32;
continue;
}
}
exit(1);
}
/* Find out where the JRE is that we will be using. */
exit(2);
}
/* Find the specified JVM type */
exit(1);
}
jvmpath[0] = '\0';
exit(4);
}
/* If we got here, jvmpath has been correctly initialized. */
}
/*
* Find path to JRE based on .exe's location or registry settings.
*/
{
char javadll[MAXPATHLEN];
struct stat s;
/* Is JRE co-located with the application? */
goto found;
}
/* Does this app ship a private JRE in <apphome>\jre directory? */
goto found;
}
}
/* Look for a public JRE on this machine. */
goto found;
}
return JNI_FALSE;
return JNI_TRUE;
}
/*
* Given a JRE location and a JVM type, construct what the name the
* JVM shared library will be. Return true, if such a library
* exists, false otherwise.
*/
static jboolean
{
struct stat s;
} else {
}
return JNI_TRUE;
} else {
return JNI_FALSE;
}
}
/*
* Load a jvm from "jvmpath" and initialize the invocation functions.
*/
{
char crtpath[MAXPATHLEN];
/*
* 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.
*
* (NOTE: the above statement is only true for Visual Studio 2003 and
* msvcr71.dll.)
*/
#ifdef _MSC_VER
#if _MSC_VER < 1400
#define CRT_DLL "msvcr71.dll"
#endif
#ifdef CRT_DLL
if (LoadLibrary(crtpath) == 0) {
return JNI_FALSE;
}
}
}
#endif /* CRT_DLL */
#endif /* _MSC_VER */
/* Load the Java VM DLL */
return JNI_FALSE;
}
/* Now get the function addresses */
ifn->CreateJavaVM =
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* If app is "c:\foo\bin\javac", then put "c:\foo" into buf.
*/
{
char *cp;
/* This happens if the application is in a drive root, and
* there is no bin directory. */
buf[0] = '\0';
return JNI_FALSE;
}
return JNI_TRUE;
}
/*
* Helpers to look in the registry for a public JRE.
*/
/* Same for 1.5.0, 1.5.1, 1.5.2 etc. */
#define JRE_KEY "Software\\JavaSoft\\Java Runtime Environment"
static jboolean
{
return JNI_TRUE;
}
}
return JNI_FALSE;
}
static jboolean
{
char version[MAXPATHLEN];
/*
* Note: There is a very similar implementation of the following
* registry reading code in the Windows java control panel (javacp.cpl).
* If there are bugs here, a similar bug probably exists there. Hence,
* changes here require inspection there.
*/
/* Find the current version of the JRE */
return JNI_FALSE;
}
return JNI_FALSE;
}
);
return JNI_FALSE;
}
/* Find directory where the current version is installed. */
return JNI_FALSE;
}
return JNI_FALSE;
}
if (JLI_IsTraceLauncher()) {
char micro[MAXPATHLEN];
sizeof(micro))) {
printf("Warning: Can't read MicroVersion\n");
micro[0] = '\0';
}
}
return JNI_TRUE;
}
/*
* Support for doing cheap, accurate interval timing.
*/
static LARGE_INTEGER counterFrequency;
{
if (!counterInitialized) {
}
if (!counterAvailable) {
return 0;
}
}
{
if (!counterAvailable || !counterInitialized) {
return 0;
}
}
void
JLI_ReportErrorMessage(const char* fmt, ...) {
if (IsJavaw()) {
char *message;
/* get the length of the string we need */
message[n]='\0';
} else {
}
}
/*
* Just like JLI_ReportErrorMessage, except that it concatenates the system
* error message if any, its upto the calling routine to correctly
* format the separation of the messages.
*/
void
JLI_ReportErrorMessageSys(const char *fmt, ...)
{
int save_errno = errno;
int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
errtext = "";
n = 0;
} else {
if (n > 2) { /* Drop final CR, LF */
errtext[n] = '\0';
}
}
} else { /* C runtime error that has no corresponding DOS error code */
}
if (IsJavaw()) {
char *message;
int mlen;
/* get the length of the string we need */
if (freeit) {
}
if (freeit) {
}
} else {
if (freeit) {
}
}
if (freeit) {
}
}
if (IsJavaw()) {
/*
* This code should be replaced by code which opens a window with
* the exception detail message, for now atleast put a dialog up.
*/
} else {
}
}
}
/*
* Determine if there is an acceptable JRE in the registry directory top_key.
* Upon locating the "best" one, return a fully qualified path to it.
* "Best" is defined as the most advanced JRE meeting the constraints
* contained in the manifest_info. If no JRE in this directory meets the
* constraints, return NULL.
*
* It doesn't matter if we get an error reading the registry, or we just
* don't find anything interesting in the directory. We just return NULL
* in either case.
*/
static char *
char name[MAXNAMELEN];
int len;
/*
* searching for the best available version.
*/
index++;
}
}
/*
* Extract "JavaHome" from the "best" registry directory and return
* that path. If no appropriate version was located, or there is an
* error in extracting the "JavaHome" string, return null.
*/
return (NULL);
else {
!= ERROR_SUCCESS) {
return (NULL);
}
len = MAXNAMELEN;
!= ERROR_SUCCESS) {
return (NULL);
}
return (JLI_StringDup(name));
}
}
/*
* This is the global entry point. It examines the host for the optimal
* JRE to be used by scanning a set of registry entries. This set of entries
* is hardwired on Windows as "Software\JavaSoft\Java Runtime Environment"
* under the set of roots "{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }".
*
* This routine simply opens each of these registry directories before passing
* control onto ProcessDir().
*/
char *
char *path;
int key_index;
== ERROR_SUCCESS)
return (path);
}
}
return NULL;
}
/*
* Local helper routine to isolate a single token (option or argument)
* from the command line.
*
* This routine accepts a pointer to a character pointer. The first
* token (as defined by MSDN command-line argument syntax) is isolated
* from that string.
*
* Upon return, the input character pointer pointed to by the parameter s
* is updated to point to the remainding, unscanned, portion of the string,
* or to a null character if the entire string has been consummed.
*
* This function returns a pointer to a null-terminated string which
* contains the isolated first token, or to the null character if no
* token could be isolated.
*
* Note the side effect of modifying the input string s by the insertion
* of a null character, making it two strings.
*
* See "Parsing C Command-Line Arguments" in the MSDN Library for the
* parsing rule details. The rule summary from that specification is:
*
* * Arguments are delimited by white space, which is either a space or a tab.
*
* * A string surrounded by double quotation marks is interpreted as a single
* argument, regardless of white space contained within. A quoted string can
* be embedded in an argument. Note that the caret (^) is not recognized as
* an escape character or delimiter.
*
* * A double quotation mark preceded by a backslash, \", is interpreted as a
* literal double quotation mark (").
*
* * Backslashes are interpreted literally, unless they immediately precede a
* double quotation mark.
*
* * If an even number of backslashes is followed by a double quotation mark,
* then one backslash (\) is placed in the argv array for every pair of
* backslashes (\\), and the double quotation mark (") is interpreted as a
* string delimiter.
*
* * If an odd number of backslashes is followed by a double quotation mark,
* then one backslash (\) is placed in the argv array for every pair of
* backslashes (\\) and the double quotation mark is interpreted as an
* escape sequence by the remaining backslash, causing a literal double
* quotation mark (") to be placed in argv.
*/
static char*
nextarg(char** s) {
char *p = *s;
char *head;
int slashes = 0;
int inquote = 0;
/*
* Strip leading whitespace, which MSDN defines as only space or tab.
* (Hence, no locale specific "isspace" here.)
*/
while (*p != (char)0 && (*p == ' ' || *p == '\t'))
p++;
head = p; /* Save the start of the token to return */
/*
* Isolate a token from the command line.
*/
p++;
else if (*p == '"')
}
/*
* If the token isolated isn't already terminated in a "char zero",
* then replace the whitespace character with one and move to the
* next character.
*/
if (*p != (char)0)
*p++ = (char)0;
/*
* Update the parameter to point to the head of the remaining string
* reflecting the command line and return a pointer to the leading
* token which was isolated from the command line.
*/
*s = p;
return (head);
}
/*
* Local helper routine to return a string equivalent to the input string
* s, but with quotes removed so the result is a string as would be found
* in argv[]. The returned string should be freed by a call to JLI_MemFree().
*
* The rules for quoting (and escaped quotes) are:
*
* 1 A double quotation mark preceded by a backslash, \", is interpreted as a
* literal double quotation mark (").
*
* 2 Backslashes are interpreted literally, unless they immediately precede a
* double quotation mark.
*
* 3 If an even number of backslashes is followed by a double quotation mark,
* then one backslash (\) is placed in the argv array for every pair of
* backslashes (\\), and the double quotation mark (") is interpreted as a
* string delimiter.
*
* 4 If an odd number of backslashes is followed by a double quotation mark,
* then one backslash (\) is placed in the argv array for every pair of
* backslashes (\\) and the double quotation mark is interpreted as an
* escape sequence by the remaining backslash, causing a literal double
* quotation mark (") to be placed in argv.
*/
static char*
unquote(const char *s) {
const char *p = s; /* Pointer to the tail of the original string */
while (*p != '\0') {
if (*p == '"') {
p++;
} else if (*p == '\\') {
const char *q = p + JLI_StrSpn(p,"\\");
if (*q == '"')
do {
*pun++ = '\\';
p += 2;
} while (*p == '\\' && p < q);
else
while (p < q)
*pun++ = *p++;
} else {
*pun++ = *p++;
}
}
*pun = '\0';
return un;
}
/*
* Given a path to a jre to execute, this routine checks if this process
* is indeed that jre. If not, it exec's that jre.
*
* We want to actually check the paths rather than just the version string
* built into the executable, so that given version specification will yield
* the exact same Java environment, regardless of the version of the arbitrary
* launcher we start with.
*/
void
int len;
const char *progname = GetProgramName();
/*
* Resolve the real path to the currently running launcher.
*/
exit(1);
}
/*
* If the path to the selected JRE directory is a match to the initial
* portion of the path to the currently executing JRE, we have a winner!
* If so, just return.
*/
return; /* I am the droid you were looking for */
/*
* If this isn't the selected version, exec the selected version.
*/
/*
* Although Windows has an execv() entrypoint, it doesn't actually
* overlay a process: it can only create a new process and terminate
* the old process. Therefore, any processes waiting on the initial
* process wake up and they shouldn't. Hence, a chain of pseudo-zombie
* processes must be retained to maintain the proper wait semantics.
* Fortunately the image size of the launcher isn't too large at this
* time.
*
* If it weren't for this semantic flaw, the code below would be ...
*
* execv(path, argv);
* JLI_ReportErrorMessage("Error: Exec of %s failed\n", path);
* exit(1);
*
* The incorrect exec semantics could be addressed by:
*
* exit((int)spawnv(_P_WAIT, path, argv));
*
* this from completely working. All the Windows POSIX process creation
* interfaces are implemented as wrappers around the native Windows
* function CreateProcess(). CreateProcess() takes a single string
* to specify command line options and arguments, so the POSIX routine
* wrappers build a single string from the argv[] array and in the
* process, any quoting information is lost.
*
* The solution to this to get the original command line, to process it
* to remove the new multiple JRE options (if any) as was done for argv
* in the common SelectVersion() routine and finally to pass it directly
* to the native CreateProcess() Windows process control interface.
*/
{
char *cmdline;
char *p;
char *np;
char *ocl;
char *ccl;
char *unquoted;
/*
* The following code block gets and processes the original command
* line, replacing the argv[0] equivalent in the command line with
* the path to the new executable and removing the appropriate
* Multiple JRE support options. Note that similar logic exists
* in the platform independent SelectVersion routine, but is
* replicated here due to the syntax of CreateProcess().
*
* The magic "+ 4" characters added to the command line length are
* 2 possible quotes around the path (argv[0]), a space after the
* path and a terminating null character.
*/
ocl = GetCommandLine();
else
while (*np != (char)0) { /* While more command-line */
if (*p != (char)0) { /* If a token was isolated */
if (*p != (char)0) /* If a token was isolated */
}
} else { /* End of options */
JLI_MemFree((void *)unquoted);
break;
}
JLI_MemFree((void *)unquoted);
}
}
JLI_MemFree((void *)ccl);
if (JLI_IsTraceLauncher()) {
JLI_MemFree((void *)ccl);
}
/*
* The following code is modeled after a model presented in the
* Microsoft Technical Article "Moving Unix Applications to
* Windows NT" (March 6, 1994) and "Creating Processes" on MSDN
* (Februrary 2005). It approximates UNIX spawn semantics with
* the parent waiting for termination of the child.
*/
(DWORD)0, /* creation flags */
exit(1);
}
exitCode = 1;
} else {
exitCode = 1;
}
}
}
/*
* Wrapper for platform dependent unsetenv function.
*/
int
{
int ret;
return (ret);
}
/* --- Splash Screen shared library support --- */
static const char* SPLASHSCREEN_SO = "\\bin\\splashscreen.dll";
void* SplashProcAddress(const char* name) {
return NULL;
}
return NULL;
}
if (!hSplashLib) {
}
if (hSplashLib) {
} else {
return NULL;
}
}
void SplashFreeLibrary() {
if (hSplashLib) {
hSplashLib = NULL;
}
}
const char *
return "%I64d";
}
/*
* Block current thread and continue execution in a new thread
*/
int
int rslt = 0;
unsigned thread_id;
#define STACK_SIZE_PARAM_IS_A_RESERVATION (0x10000)
#endif
/*
* STACK_SIZE_PARAM_IS_A_RESERVATION is what we want, but it's not
* supported on older version of Windows. Try first with the flag; and
* if that fails try again without the flag. See MSDN document or HotSpot
* source (os_win32.cpp) for details.
*/
(unsigned)stack_size,
args,
&thread_id);
if (thread_handle == NULL) {
(unsigned)stack_size,
args,
0,
&thread_id);
}
if (thread_handle) {
} else {
}
return rslt;
}
/* Unix only, empty on windows. */
void SetJavaLauncherPlatformProps() {}
/*
* The implementation for finding classes from the bootstrap
* class loader, refer to java.h
*/
#ifdef _M_AMD64
#define JVM_BCLOADER "JVM_FindClassFromClassLoader"
#else
#define JVM_BCLOADER "_JVM_FindClassFromClassLoader@20"
#endif /* _M_AMD64 */
{
if (findBootClass == NULL) {
/* need to use the demangled entry point */
if (findBootClass == NULL) {
return NULL;
}
}
}
void
{
/*
* Required for javaw mode MessageBox output as well as for
* HotSpot -XX:+ShowMessageBoxOnError in java mode, an empty
* flag field is sufficient to perform the basic UI initialization.
*/
}