feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
90
jdkSrc/jdk8/launcher/defines.h
Normal file
90
jdkSrc/jdk8/launcher/defines.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _DEFINES_H
|
||||
#define _DEFINES_H
|
||||
|
||||
#include "java.h"
|
||||
|
||||
/*
|
||||
* This file contains commonly defined constants used only by main.c
|
||||
* and should not be included by another file.
|
||||
*/
|
||||
#ifndef FULL_VERSION
|
||||
/* make sure the compilation fails */
|
||||
#error "FULL_VERSION must be defined"
|
||||
#endif
|
||||
|
||||
#if defined(JDK_MAJOR_VERSION) && defined(JDK_MINOR_VERSION)
|
||||
#define DOT_VERSION JDK_MAJOR_VERSION "." JDK_MINOR_VERSION
|
||||
#else
|
||||
/* make sure the compilation fails */
|
||||
#error "JDK_MAJOR_VERSION and JDK_MINOR_VERSION must be defined"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef JAVA_ARGS
|
||||
static const char* const_progname = "java";
|
||||
static const char* const_jargs[] = JAVA_ARGS;
|
||||
/*
|
||||
* ApplicationHome is prepended to each of these entries; the resulting
|
||||
* strings are concatenated (separated by PATH_SEPARATOR) and used as the
|
||||
* value of -cp option to the launcher.
|
||||
*/
|
||||
#ifndef APP_CLASSPATH
|
||||
#define APP_CLASSPATH { "/lib/tools.jar", "/classes" }
|
||||
#endif /* APP_CLASSPATH */
|
||||
static const char* const_appclasspath[] = APP_CLASSPATH;
|
||||
#else /* !JAVA_ARGS */
|
||||
#ifdef PROGNAME
|
||||
static const char* const_progname = PROGNAME;
|
||||
#else
|
||||
static char* const_progname = NULL;
|
||||
#endif
|
||||
static const char** const_jargs = NULL;
|
||||
static const char** const_appclasspath = NULL;
|
||||
#endif /* JAVA_ARGS */
|
||||
|
||||
#ifdef LAUNCHER_NAME
|
||||
static const char* const_launcher = LAUNCHER_NAME;
|
||||
#else /* LAUNCHER_NAME */
|
||||
static char* const_launcher = NULL;
|
||||
#endif /* LAUNCHER_NAME */
|
||||
|
||||
#ifdef EXPAND_CLASSPATH_WILDCARDS
|
||||
static const jboolean const_cpwildcard = JNI_TRUE;
|
||||
#else
|
||||
static const jboolean const_cpwildcard = JNI_FALSE;
|
||||
#endif /* EXPAND_CLASSPATH_WILDCARDS */
|
||||
|
||||
#if defined(NEVER_ACT_AS_SERVER_CLASS_MACHINE)
|
||||
static const jint const_ergo_class = NEVER_SERVER_CLASS;
|
||||
#elif defined(ALWAYS_ACT_AS_SERVER_CLASS_MACHINE)
|
||||
static const jint const_ergo_class = ALWAYS_SERVER_CLASS;
|
||||
#else
|
||||
static const jint const_ergo_class = DEFAULT_POLICY;
|
||||
#endif /* NEVER_ACT_AS_SERVER_CLASS_MACHINE */
|
||||
|
||||
#endif /*_DEFINES_H */
|
||||
107
jdkSrc/jdk8/launcher/emessages.h
Normal file
107
jdkSrc/jdk8/launcher/emessages.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file primarily consists of all the error and warning messages, that
|
||||
* are used in JLI_ReportErrorMessage. All message must be defined here, in
|
||||
* order to help with localizing the messages.
|
||||
*/
|
||||
|
||||
#ifndef _EMESSAGES_H
|
||||
#define _EMESSAGES_H
|
||||
|
||||
#define GEN_ERROR "Error: A fatal exception has occurred. Program will exit."
|
||||
#define JNI_ERROR "Error: A JNI error has occurred, please check your installation and try again"
|
||||
#define JNI_ERROR1 "Error: can't find JNI interfaces in: %s"
|
||||
|
||||
#define ARG_WARN "Warning: %s option is no longer supported."
|
||||
|
||||
#define ARG_ERROR1 "Error: %s requires class path specification"
|
||||
#define ARG_ERROR2 "Error: %s requires jar file specification"
|
||||
#define ARG_ERROR3 "Error: The -J option should not be followed by a space."
|
||||
|
||||
#define JVM_ERROR1 "Error: Could not create the Java Virtual Machine.\n" GEN_ERROR
|
||||
#define JVM_ERROR2 "Error: Could not detach main thread.\n" JNI_ERROR
|
||||
#define JVM_ERROR3 "Error: SPARC V8 processor detected; Required V9 processors or better.\nUse JDK5 client compiler for V8 processors.\n" JVM_ERROR1
|
||||
|
||||
#define JAR_ERROR1 "Error: Failed to load Main-Class manifest attribute from\n%s\n%s"
|
||||
#define JAR_ERROR2 "Error: Unable to access jarfile %s"
|
||||
#define JAR_ERROR3 "Error: Invalid or corrupt jarfile %s"
|
||||
|
||||
#define CLS_ERROR1 "Error: Could not find the main class %s.\n" JNI_ERROR
|
||||
#define CLS_ERROR2 "Error: Failed to load Main Class: %s\n%s"
|
||||
#define CLS_ERROR3 "Error: No main method found in specified class.\n" GEN_ERROR
|
||||
#define CLS_ERROR4 "Error: Main method not public\n" GEN_ERROR
|
||||
#define CLS_ERROR5 "Error: main-class: attribute exceeds system limits of %d bytes\n" GEN_ERROR
|
||||
|
||||
#define CFG_WARN1 "Warning: %s VM not supported; %s VM will be used"
|
||||
#define CFG_WARN2 "Warning: No leading - on line %d of `%s'"
|
||||
#define CFG_WARN3 "Warning: Missing VM type on line %d of `%s'"
|
||||
#define CFG_WARN4 "Warning: Missing server class VM on line %d of `%s'"
|
||||
#define CFG_WARN5 "Warning: Unknown VM type on line %d of `%s'"
|
||||
|
||||
#define CFG_ERROR1 "Error: Corrupt jvm.cfg file; cycle in alias list."
|
||||
#define CFG_ERROR2 "Error: Unable to resolve VM alias %s"
|
||||
#define CFG_ERROR3 "Error: %s VM not supported"
|
||||
#define CFG_ERROR4 "Error: Unable to locate JRE meeting specification \"%s\""
|
||||
#define CFG_ERROR5 "Error: Could not determine application home."
|
||||
#define CFG_ERROR6 "Error: could not open `%s'"
|
||||
#define CFG_ERROR7 "Error: no known VMs. (check for corrupt jvm.cfg file)"
|
||||
#define CFG_ERROR8 "Error: missing `%s' JVM at `%s'.\nPlease install or use the JRE or JDK that contains these missing components."
|
||||
#define CFG_ERROR9 "Error: could not determine JVM type."
|
||||
|
||||
|
||||
#define SPC_ERROR1 "Error: Syntax error in version specification \"%s\""
|
||||
|
||||
#define JRE_ERROR1 "Error: Could not find Java SE Runtime Environment."
|
||||
#define JRE_ERROR2 "Error: This Java instance does not support a %d-bit JVM.\nPlease install the desired version."
|
||||
#define JRE_ERROR3 "Error: Improper value at line %d."
|
||||
#define JRE_ERROR4 "Error: trying to exec %s.\nCheck if file exists and permissions are set correctly."
|
||||
#define JRE_ERROR5 "Error: Failed to start a %d-bit JVM process from a %d-bit JVM."
|
||||
#define JRE_ERROR6 "Error: Verify all necessary Java SE components have been installed.\n(Solaris SPARC 64-bit components must be installed after 32-bit components.)"
|
||||
#define JRE_ERROR7 "Error: Either 64-bit processes are not supported by this platform\nor the 64-bit components have not been installed."
|
||||
#define JRE_ERROR8 "Error: could not find "
|
||||
#define JRE_ERROR9 "Error: Unable to resolve %s"
|
||||
#define JRE_ERROR10 "Error: Unable to resolve current executable"
|
||||
#define JRE_ERROR11 "Error: Path length exceeds maximum length (PATH_MAX)"
|
||||
#define JRE_ERROR12 "Error: Exec of %s failed"
|
||||
#define JRE_ERROR13 "Error: String processing operation failed"
|
||||
|
||||
#define DLL_ERROR1 "Error: dl failure on line %d"
|
||||
#define DLL_ERROR2 "Error: failed %s, because %s"
|
||||
#define DLL_ERROR3 "Error: could not find executable %s"
|
||||
#define DLL_ERROR4 "Error: loading: %s"
|
||||
|
||||
#define REG_ERROR1 "Error: opening registry key '%s'"
|
||||
#define REG_ERROR2 "Error: Failed reading value of registry key:\n\t%s\\CurrentVersion"
|
||||
#define REG_ERROR3 "Error: Registry key '%s'\\CurrentVersion'\nhas value '%s', but '%s' is required."
|
||||
#define REG_ERROR4 "Failed reading value of registry key:\n\t%s\\%s\\JavaHome"
|
||||
|
||||
#define SYS_ERROR1 "Error: CreateProcess(%s, ...) failed:"
|
||||
#define SYS_ERROR2 "Error: WaitForSingleObject() failed."
|
||||
|
||||
|
||||
|
||||
#endif /* _EMESSAGES_H */
|
||||
2106
jdkSrc/jdk8/launcher/java.c
Normal file
2106
jdkSrc/jdk8/launcher/java.c
Normal file
File diff suppressed because it is too large
Load Diff
309
jdkSrc/jdk8/launcher/java.h
Normal file
309
jdkSrc/jdk8/launcher/java.h
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _JAVA_H_
|
||||
#define _JAVA_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvm.h>
|
||||
|
||||
/*
|
||||
* Get system specific defines.
|
||||
*/
|
||||
#include "emessages.h"
|
||||
#include "java_md.h"
|
||||
#include "jli_util.h"
|
||||
|
||||
#include "manifest_info.h"
|
||||
#include "version_comp.h"
|
||||
#include "wildcard.h"
|
||||
#include "splashscreen.h"
|
||||
|
||||
# define KB (1024UL)
|
||||
# define MB (1024UL * KB)
|
||||
# define GB (1024UL * MB)
|
||||
|
||||
#define CURRENT_DATA_MODEL (CHAR_BIT * sizeof(void*))
|
||||
|
||||
/*
|
||||
* The following environment variable is used to influence the behavior
|
||||
* of the jre exec'd through the SelectVersion routine. The command line
|
||||
* options which specify the version are not passed to the exec'd version,
|
||||
* because that jre may be an older version which wouldn't recognize them.
|
||||
* This environment variable is known to this (and later) version and serves
|
||||
* to suppress the version selection code. This is not only for efficiency,
|
||||
* but also for correctness, since any command line options have been
|
||||
* removed which would cause any value found in the manifest to be used.
|
||||
* This would be incorrect because the command line options are defined
|
||||
* to take precedence.
|
||||
*
|
||||
* The value associated with this environment variable is the MainClass
|
||||
* name from within the executable jar file (if any). This is strictly a
|
||||
* performance enhancement to avoid re-reading the jar file manifest.
|
||||
*
|
||||
*/
|
||||
#define ENV_ENTRY "_JAVA_VERSION_SET"
|
||||
|
||||
#define SPLASH_FILE_ENV_ENTRY "_JAVA_SPLASH_FILE"
|
||||
#define SPLASH_JAR_ENV_ENTRY "_JAVA_SPLASH_JAR"
|
||||
|
||||
/*
|
||||
* Pointers to the needed JNI invocation API, initialized by LoadJavaVM.
|
||||
*/
|
||||
typedef jint (JNICALL *CreateJavaVM_t)(JavaVM **pvm, void **env, void *args);
|
||||
typedef jint (JNICALL *GetDefaultJavaVMInitArgs_t)(void *args);
|
||||
typedef jint (JNICALL *GetCreatedJavaVMs_t)(JavaVM **vmBuf, jsize bufLen, jsize *nVMs);
|
||||
|
||||
typedef struct {
|
||||
CreateJavaVM_t CreateJavaVM;
|
||||
GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs;
|
||||
GetCreatedJavaVMs_t GetCreatedJavaVMs;
|
||||
} InvocationFunctions;
|
||||
|
||||
int
|
||||
JLI_Launch(int argc, char ** argv, /* main argc, argc */
|
||||
int jargc, const char** jargv, /* java args */
|
||||
int appclassc, const char** appclassv, /* app classpath */
|
||||
const char* fullversion, /* full version defined */
|
||||
const char* dotversion, /* dot version defined */
|
||||
const char* pname, /* program name */
|
||||
const char* lname, /* launcher name */
|
||||
jboolean javaargs, /* JAVA_ARGS */
|
||||
jboolean cpwildcard, /* classpath wildcard */
|
||||
jboolean javaw, /* windows-only javaw */
|
||||
jint ergo_class /* ergnomics policy */
|
||||
);
|
||||
|
||||
/*
|
||||
* Prototypes for launcher functions in the system specific java_md.c.
|
||||
*/
|
||||
|
||||
jboolean
|
||||
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn);
|
||||
|
||||
void
|
||||
GetXUsagePath(char *buf, jint bufsize);
|
||||
|
||||
jboolean
|
||||
GetApplicationHome(char *buf, jint bufsize);
|
||||
|
||||
#define GetArch() GetArchPath(CURRENT_DATA_MODEL)
|
||||
|
||||
/*
|
||||
* Different platforms will implement this, here
|
||||
* pargc is a pointer to the original argc,
|
||||
* pargv is a pointer to the original argv,
|
||||
* jrepath is an accessible path to the jre as determined by the call
|
||||
* so_jrepath is the length of the buffer jrepath
|
||||
* jvmpath is an accessible path to the jvm as determined by the call
|
||||
* so_jvmpath is the length of the buffer jvmpath
|
||||
*/
|
||||
void CreateExecutionEnvironment(int *argc, char ***argv,
|
||||
char *jrepath, jint so_jrepath,
|
||||
char *jvmpath, jint so_jvmpath,
|
||||
char *jvmcfg, jint so_jvmcfg);
|
||||
|
||||
/* Reports an error message to stderr or a window as appropriate. */
|
||||
void JLI_ReportErrorMessage(const char * message, ...);
|
||||
|
||||
/* Reports a system error message to stderr or a window */
|
||||
void JLI_ReportErrorMessageSys(const char * message, ...);
|
||||
|
||||
/* Reports an error message only to stderr. */
|
||||
void JLI_ReportMessage(const char * message, ...);
|
||||
|
||||
/*
|
||||
* Reports an exception which terminates the vm to stderr or a window
|
||||
* as appropriate.
|
||||
*/
|
||||
void JLI_ReportExceptionDescription(JNIEnv * env);
|
||||
void PrintMachineDependentOptions();
|
||||
|
||||
const char *jlong_format_specifier();
|
||||
|
||||
/*
|
||||
* Block current thread and continue execution in new thread
|
||||
*/
|
||||
int ContinueInNewThread0(int (JNICALL *continuation)(void *),
|
||||
jlong stack_size, void * args);
|
||||
|
||||
/* sun.java.launcher.* platform properties. */
|
||||
void SetJavaLauncherPlatformProps(void);
|
||||
void SetJavaCommandLineProp(char* what, int argc, char** argv);
|
||||
void SetJavaLauncherProp(void);
|
||||
|
||||
/*
|
||||
* Functions defined in java.c and used in java_md.c.
|
||||
*/
|
||||
jint ReadKnownVMs(const char *jvmcfg, jboolean speculative);
|
||||
char *CheckJvmType(int *argc, char ***argv, jboolean speculative);
|
||||
void AddOption(char *str, void *info);
|
||||
|
||||
enum ergo_policy {
|
||||
DEFAULT_POLICY = 0,
|
||||
NEVER_SERVER_CLASS,
|
||||
ALWAYS_SERVER_CLASS
|
||||
};
|
||||
|
||||
const char* GetProgramName();
|
||||
const char* GetDotVersion();
|
||||
const char* GetFullVersion();
|
||||
jboolean IsJavaArgs();
|
||||
jboolean IsJavaw();
|
||||
jint GetErgoPolicy();
|
||||
|
||||
jboolean ServerClassMachine();
|
||||
|
||||
int ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
|
||||
int argc, char** argv,
|
||||
int mode, char *what, int ret);
|
||||
|
||||
int JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
|
||||
int argc, char** argv,
|
||||
int mode, char *what, int ret);
|
||||
|
||||
/*
|
||||
* Initialize platform specific settings
|
||||
*/
|
||||
void InitLauncher(jboolean javaw);
|
||||
|
||||
/*
|
||||
* For MacOSX and Windows/Unix compatibility we require these
|
||||
* entry points, some of them may be stubbed out on Windows/Unixes.
|
||||
*/
|
||||
void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm);
|
||||
void ShowSplashScreen();
|
||||
void RegisterThread();
|
||||
/*
|
||||
* this method performs additional platform specific processing and
|
||||
* should return JNI_TRUE to indicate the argument has been consumed,
|
||||
* otherwise returns JNI_FALSE to allow the calling logic to further
|
||||
* process the option.
|
||||
*/
|
||||
jboolean ProcessPlatformOption(const char *arg);
|
||||
|
||||
/*
|
||||
* This allows for finding classes from the VM's bootstrap class loader directly,
|
||||
* FindClass uses the application class loader internally, this will cause
|
||||
* unnecessary searching of the classpath for the required classes.
|
||||
*
|
||||
*/
|
||||
typedef jclass (JNICALL FindClassFromBootLoader_t(JNIEnv *env,
|
||||
const char *name));
|
||||
jclass FindBootStrapClass(JNIEnv *env, const char *classname);
|
||||
|
||||
jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc);
|
||||
jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
|
||||
jclass GetLauncherHelperClass(JNIEnv *env);
|
||||
|
||||
int JNICALL JavaMain(void * args); /* entry point */
|
||||
|
||||
enum LaunchMode { // cf. sun.launcher.LauncherHelper
|
||||
LM_UNKNOWN = 0,
|
||||
LM_CLASS,
|
||||
LM_JAR
|
||||
};
|
||||
|
||||
static const char *launchModeNames[]
|
||||
= { "Unknown", "Main class", "JAR file" };
|
||||
|
||||
typedef struct {
|
||||
int argc;
|
||||
char **argv;
|
||||
int mode;
|
||||
char *what;
|
||||
InvocationFunctions ifn;
|
||||
} JavaMainArgs;
|
||||
|
||||
#define NULL_CHECK_RETURN_VALUE(NCRV_check_pointer, NCRV_return_value) \
|
||||
do { \
|
||||
if ((NCRV_check_pointer) == NULL) { \
|
||||
JLI_ReportErrorMessage(JNI_ERROR); \
|
||||
return NCRV_return_value; \
|
||||
} \
|
||||
} while (JNI_FALSE)
|
||||
|
||||
#define NULL_CHECK0(NC0_check_pointer) \
|
||||
NULL_CHECK_RETURN_VALUE(NC0_check_pointer, 0)
|
||||
|
||||
#define NULL_CHECK(NC_check_pointer) \
|
||||
NULL_CHECK_RETURN_VALUE(NC_check_pointer, )
|
||||
|
||||
#define CHECK_EXCEPTION_RETURN() \
|
||||
do { \
|
||||
if ((*env)->ExceptionOccurred(env)) { \
|
||||
return; \
|
||||
} \
|
||||
} while (JNI_FALSE)
|
||||
|
||||
/*
|
||||
* For JNI calls :
|
||||
* - check for thrown exceptions
|
||||
* - check for null return
|
||||
*
|
||||
* JNI calls can return null and/or throw an exception. Check for these.
|
||||
*
|
||||
* : CHECK_JNI_RETURN_EXCEPTION()
|
||||
* return the specified RETURNVALUE if exception was generated
|
||||
* : CHECK_JNI_RETURN_0(JNISTATEMENT) : check if JNISTATEMENT was successful, return 0 if not
|
||||
* : CHECK_JNI_RETURN_VOID(JNISTATEMENT) : check if JNISTATEMENT was successful, return void if not
|
||||
* : CHECK_JNI_RETURN_VALUE(JNISTATEMENT,n) : check if JNISTATEMENT was successful, return n if not
|
||||
*
|
||||
* These macros need at least one parameter, the JNI statement [ JNISTATEMENT ].
|
||||
*
|
||||
* E.G.: check the JNI statement, and specify a value to return if a failure was detected.
|
||||
*
|
||||
* CHECK_JNI_RETURN_VALUE(str = (*env)->CallStaticObjectMethod(env, cls,
|
||||
* makePlatformStringMID, USE_STDERR, ary), -1);
|
||||
*/
|
||||
|
||||
#define RETURNVOID return
|
||||
#define RETURN0 return 0
|
||||
#define RETURN(N) return (N)
|
||||
|
||||
#define CHECK_JNI_RETURN_EXCEPTION(RETURNVALUE) \
|
||||
if ((((*env)->ExceptionOccurred(env))!=NULL)) { \
|
||||
RETURNVALUE; \
|
||||
}
|
||||
|
||||
#define CHECK_JNI_RETURN_0(JNISTATEMENT) \
|
||||
CHECK_JNI_RETURN_EXCEPTION(RETURN0); \
|
||||
NULL_CHECK0(JNISTATEMENT);
|
||||
|
||||
#define CHECK_JNI_RETURN_VOID(JNISTATEMENT) \
|
||||
CHECK_JNI_RETURN_EXCEPTION(RETURNVOID); \
|
||||
NULL_CHECK(JNISTATEMENT);
|
||||
|
||||
#define CHECK_JNI_RETURN_VALUE(JNISTATEMENT, NCRV_return_value) \
|
||||
CHECK_JNI_RETURN_EXCEPTION(RETURN(NCRV_return_value)); \
|
||||
NULL_CHECK_RETURN_VALUE(JNISTATEMENT, NCRV_return_value);
|
||||
|
||||
|
||||
#endif /* _JAVA_H_ */
|
||||
1545
jdkSrc/jdk8/launcher/java_md.c
Normal file
1545
jdkSrc/jdk8/launcher/java_md.c
Normal file
File diff suppressed because it is too large
Load Diff
57
jdkSrc/jdk8/launcher/java_md.h
Normal file
57
jdkSrc/jdk8/launcher/java_md.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef JAVA_MD_H
|
||||
#define JAVA_MD_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include "manifest_info.h"
|
||||
#include "jli_util.h"
|
||||
|
||||
#define PATH_SEPARATOR ';'
|
||||
#define FILESEP "\\"
|
||||
#define FILE_SEPARATOR '\\'
|
||||
#define IS_FILE_SEPARATOR(c) ((c) == '\\' || (c) == '/')
|
||||
#define MAXPATHLEN MAX_PATH
|
||||
#define MAXNAMELEN MAX_PATH
|
||||
|
||||
|
||||
/*
|
||||
* Support for doing cheap, accurate interval timing.
|
||||
*/
|
||||
extern jlong CounterGet(void);
|
||||
extern jlong Counter2Micros(jlong counts);
|
||||
|
||||
|
||||
/*
|
||||
* Function prototypes.
|
||||
*/
|
||||
char *LocateJRE(manifest_info *info);
|
||||
void ExecJRE(char *jre, char **argv);
|
||||
int UnsetEnv(char *name);
|
||||
|
||||
#endif /* JAVA_MD_H */
|
||||
121
jdkSrc/jdk8/launcher/jli_util.c
Normal file
121
jdkSrc/jdk8/launcher/jli_util.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include "jli_util.h"
|
||||
|
||||
/*
|
||||
* Returns a pointer to a block of at least 'size' bytes of memory.
|
||||
* Prints error message and exits if the memory could not be allocated.
|
||||
*/
|
||||
void *
|
||||
JLI_MemAlloc(size_t size)
|
||||
{
|
||||
void *p = malloc(size);
|
||||
if (p == 0) {
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Equivalent to realloc(size).
|
||||
* Prints error message and exits if the memory could not be reallocated.
|
||||
*/
|
||||
void *
|
||||
JLI_MemRealloc(void *ptr, size_t size)
|
||||
{
|
||||
void *p = realloc(ptr, size);
|
||||
if (p == 0) {
|
||||
perror("realloc");
|
||||
exit(1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wrapper over strdup(3C) which prints an error message and exits if memory
|
||||
* could not be allocated.
|
||||
*/
|
||||
char *
|
||||
JLI_StringDup(const char *s1)
|
||||
{
|
||||
char *s = strdup(s1);
|
||||
if (s == NULL) {
|
||||
perror("strdup");
|
||||
exit(1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Very equivalent to free(ptr).
|
||||
* Here to maintain pairing with the above routines.
|
||||
*/
|
||||
void
|
||||
JLI_MemFree(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* debug helpers we use
|
||||
*/
|
||||
static jboolean _launcher_debug = JNI_FALSE;
|
||||
|
||||
void
|
||||
JLI_TraceLauncher(const char* fmt, ...)
|
||||
{
|
||||
va_list vl;
|
||||
if (_launcher_debug != JNI_TRUE) return;
|
||||
va_start(vl, fmt);
|
||||
vprintf(fmt,vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void
|
||||
JLI_SetTraceLauncher()
|
||||
{
|
||||
if (getenv(JLDEBUG_ENV_ENTRY) != 0) {
|
||||
_launcher_debug = JNI_TRUE;
|
||||
JLI_TraceLauncher("----%s----\n", JLDEBUG_ENV_ENTRY);
|
||||
}
|
||||
}
|
||||
|
||||
jboolean
|
||||
JLI_IsTraceLauncher()
|
||||
{
|
||||
return _launcher_debug;
|
||||
}
|
||||
|
||||
int
|
||||
JLI_StrCCmp(const char *s1, const char* s2)
|
||||
{
|
||||
return JLI_StrNCmp(s1, s2, JLI_StrLen(s2));
|
||||
}
|
||||
104
jdkSrc/jdk8/launcher/jli_util.h
Normal file
104
jdkSrc/jdk8/launcher/jli_util.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _JLI_UTIL_H
|
||||
#define _JLI_UTIL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <jni.h>
|
||||
#define JLDEBUG_ENV_ENTRY "_JAVA_LAUNCHER_DEBUG"
|
||||
|
||||
void *JLI_MemAlloc(size_t size);
|
||||
void *JLI_MemRealloc(void *ptr, size_t size);
|
||||
char *JLI_StringDup(const char *s1);
|
||||
void JLI_MemFree(void *ptr);
|
||||
int JLI_StrCCmp(const char *s1, const char* s2);
|
||||
|
||||
typedef struct {
|
||||
char *arg;
|
||||
jboolean has_wildcard;
|
||||
} StdArg;
|
||||
|
||||
StdArg *JLI_GetStdArgs();
|
||||
int JLI_GetStdArgc();
|
||||
|
||||
#define JLI_StrLen(p1) strlen((p1))
|
||||
#define JLI_StrChr(p1, p2) strchr((p1), (p2))
|
||||
#define JLI_StrRChr(p1, p2) strrchr((p1), (p2))
|
||||
#define JLI_StrCmp(p1, p2) strcmp((p1), (p2))
|
||||
#define JLI_StrNCmp(p1, p2, p3) strncmp((p1), (p2), (p3))
|
||||
#define JLI_StrCat(p1, p2) strcat((p1), (p2))
|
||||
#define JLI_StrCpy(p1, p2) strcpy((p1), (p2))
|
||||
#define JLI_StrNCpy(p1, p2, p3) strncpy((p1), (p2), (p3))
|
||||
#define JLI_StrStr(p1, p2) strstr((p1), (p2))
|
||||
#define JLI_StrSpn(p1, p2) strspn((p1), (p2))
|
||||
#define JLI_StrCSpn(p1, p2) strcspn((p1), (p2))
|
||||
#define JLI_StrPBrk(p1, p2) strpbrk((p1), (p2))
|
||||
|
||||
/* On Windows lseek() is in io.h rather than the location dictated by POSIX. */
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#define JLI_StrCaseCmp(p1, p2) stricmp((p1), (p2))
|
||||
#define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3))
|
||||
int JLI_Snprintf(char *buffer, size_t size, const char *format, ...);
|
||||
void JLI_CmdToArgs(char *cmdline);
|
||||
#define JLI_Lseek _lseeki64
|
||||
#define JLI_PutEnv _putenv
|
||||
#define JLI_GetPid _getpid
|
||||
#else /* NIXES */
|
||||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
#define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2))
|
||||
#define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3))
|
||||
#define JLI_Snprintf snprintf
|
||||
#define JLI_PutEnv putenv
|
||||
#define JLI_GetPid getpid
|
||||
#ifdef __solaris__
|
||||
#define JLI_Lseek llseek
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#define _LARGFILE64_SOURCE
|
||||
#define JLI_Lseek lseek64
|
||||
#endif
|
||||
#ifdef MACOSX
|
||||
#define JLI_Lseek lseek
|
||||
#endif
|
||||
#ifdef _AIX
|
||||
#define JLI_Lseek lseek
|
||||
#endif
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/*
|
||||
* Make launcher spit debug output.
|
||||
*/
|
||||
void JLI_TraceLauncher(const char* fmt, ...);
|
||||
void JLI_SetTraceLauncher();
|
||||
jboolean JLI_IsTraceLauncher();
|
||||
|
||||
#endif /* _JLI_UTIL_H */
|
||||
134
jdkSrc/jdk8/launcher/main.c
Normal file
134
jdkSrc/jdk8/launcher/main.c
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This file contains the main entry point into the launcher code
|
||||
* this is the only file which will be repeatedly compiled by other
|
||||
* tools. The rest of the files will be linked in.
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER > 1400 && _MSC_VER < 1600
|
||||
|
||||
/*
|
||||
* When building for Microsoft Windows, main has a dependency on msvcr??.dll.
|
||||
*
|
||||
* When using Visual Studio 2005 or 2008, that must be recorded in
|
||||
* the [java,javaw].exe.manifest file.
|
||||
*
|
||||
* As of VS2010 (ver=1600), the runtimes again no longer need manifests.
|
||||
*
|
||||
* Reference:
|
||||
* C:/Program Files/Microsoft SDKs/Windows/v6.1/include/crtdefs.h
|
||||
*/
|
||||
#include <crtassem.h>
|
||||
#ifdef _M_IX86
|
||||
|
||||
#pragma comment(linker,"/manifestdependency:\"type='win32' " \
|
||||
"name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' " \
|
||||
"version='" _CRT_ASSEMBLY_VERSION "' " \
|
||||
"processorArchitecture='x86' " \
|
||||
"publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")
|
||||
|
||||
#endif /* _M_IX86 */
|
||||
|
||||
//This may not be necessary yet for the Windows 64-bit build, but it
|
||||
//will be when that build environment is updated. Need to test to see
|
||||
//if it is harmless:
|
||||
#ifdef _M_AMD64
|
||||
|
||||
#pragma comment(linker,"/manifestdependency:\"type='win32' " \
|
||||
"name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' " \
|
||||
"version='" _CRT_ASSEMBLY_VERSION "' " \
|
||||
"processorArchitecture='amd64' " \
|
||||
"publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")
|
||||
|
||||
#endif /* _M_AMD64 */
|
||||
#endif /* _MSC_VER > 1400 && _MSC_VER < 1600 */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/*
|
||||
* Entry point.
|
||||
*/
|
||||
#ifdef JAVAW
|
||||
|
||||
char **__initenv;
|
||||
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)
|
||||
{
|
||||
int margc;
|
||||
char** margv;
|
||||
const jboolean const_javaw = JNI_TRUE;
|
||||
|
||||
__initenv = _environ;
|
||||
|
||||
#else /* JAVAW */
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int margc;
|
||||
char** margv;
|
||||
const jboolean const_javaw = JNI_FALSE;
|
||||
#endif /* JAVAW */
|
||||
#ifdef _WIN32
|
||||
{
|
||||
int i = 0;
|
||||
if (getenv(JLDEBUG_ENV_ENTRY) != NULL) {
|
||||
printf("Windows original main args:\n");
|
||||
for (i = 0 ; i < __argc ; i++) {
|
||||
printf("wwwd_args[%d] = %s\n", i, __argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
JLI_CmdToArgs(GetCommandLine());
|
||||
margc = JLI_GetStdArgc();
|
||||
// add one more to mark the end
|
||||
margv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *)));
|
||||
{
|
||||
int i = 0;
|
||||
StdArg *stdargs = JLI_GetStdArgs();
|
||||
for (i = 0 ; i < margc ; i++) {
|
||||
margv[i] = stdargs[i].arg;
|
||||
}
|
||||
margv[i] = NULL;
|
||||
}
|
||||
#else /* *NIXES */
|
||||
margc = argc;
|
||||
margv = argv;
|
||||
#endif /* WIN32 */
|
||||
return JLI_Launch(margc, margv,
|
||||
sizeof(const_jargs) / sizeof(char *), const_jargs,
|
||||
sizeof(const_appclasspath) / sizeof(char *), const_appclasspath,
|
||||
FULL_VERSION,
|
||||
DOT_VERSION,
|
||||
(const_progname != NULL) ? const_progname : *margv,
|
||||
(const_launcher != NULL) ? const_launcher : *margv,
|
||||
(const_jargs != NULL) ? JNI_TRUE : JNI_FALSE,
|
||||
const_cpwildcard, const_javaw, const_ergo_class);
|
||||
}
|
||||
187
jdkSrc/jdk8/launcher/manifest_info.h
Normal file
187
jdkSrc/jdk8/launcher/manifest_info.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _MANIFEST_INFO_H
|
||||
#define _MANIFEST_INFO_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* Zip file header signatures
|
||||
*/
|
||||
#define SIGSIZ 4 /* size of all header signatures */
|
||||
#define LOCSIG 0x04034b50L /* "PK\003\004" */
|
||||
#define EXTSIG 0x08074b50L /* "PK\007\008" */
|
||||
#define CENSIG 0x02014b50L /* "PK\001\002" */
|
||||
#define ENDSIG 0x06054b50L /* "PK\005\006" */
|
||||
|
||||
#define ZIP64_ENDSIG 0x06064b50L /* "PK\006\006" */
|
||||
#define ZIP64_LOCSIG 0x07064b50L /* "PK\006\007" */
|
||||
/*
|
||||
* Header sizes including signatures
|
||||
*/
|
||||
#define LOCHDR 30
|
||||
#define EXTHDR 16
|
||||
#define CENHDR 46
|
||||
#define ENDHDR 22
|
||||
|
||||
#define ZIP64_ENDHDR 56 // ZIP64 end header size
|
||||
#define ZIP64_LOCHDR 20 // ZIP64 end loc header size
|
||||
#define ZIP64_EXTHDR 24 // EXT header size
|
||||
#define ZIP64_EXTID 1 // Extra field Zip64 header ID
|
||||
|
||||
#define ZIP64_MAGICVAL 0xffffffffLL
|
||||
#define ZIP64_MAGICCOUNT 0xffff
|
||||
|
||||
/*
|
||||
* Header field access macros
|
||||
*/
|
||||
#define CH(b, n) (((unsigned char *)(b))[n])
|
||||
#define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8))
|
||||
#define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL)
|
||||
#define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32))
|
||||
#define GETSIG(b) LG(b, 0)
|
||||
|
||||
/*
|
||||
* Macros for getting local file (LOC) header fields
|
||||
*/
|
||||
#define LOCVER(b) SH(b, 4) /* version needed to extract */
|
||||
#define LOCFLG(b) SH(b, 6) /* general purpose bit flags */
|
||||
#define LOCHOW(b) SH(b, 8) /* compression method */
|
||||
#define LOCTIM(b) LG(b, 10) /* modification time */
|
||||
#define LOCCRC(b) LG(b, 14) /* crc of uncompressed data */
|
||||
#define LOCSIZ(b) LG(b, 18) /* compressed data size */
|
||||
#define LOCLEN(b) LG(b, 22) /* uncompressed data size */
|
||||
#define LOCNAM(b) SH(b, 26) /* filename length */
|
||||
#define LOCEXT(b) SH(b, 28) /* extra field length */
|
||||
|
||||
/*
|
||||
* Macros for getting extra local (EXT) header fields
|
||||
*/
|
||||
#define EXTCRC(b) LG(b, 4) /* crc of uncompressed data */
|
||||
#define EXTSIZ(b) LG(b, 8) /* compressed size */
|
||||
#define EXTLEN(b) LG(b, 12) /* uncompressed size */
|
||||
|
||||
/*
|
||||
* Macros for getting central directory header (CEN) fields
|
||||
*/
|
||||
#define CENVEM(b) SH(b, 4) /* version made by */
|
||||
#define CENVER(b) SH(b, 6) /* version needed to extract */
|
||||
#define CENFLG(b) SH(b, 8) /* general purpose bit flags */
|
||||
#define CENHOW(b) SH(b, 10) /* compression method */
|
||||
#define CENTIM(b) LG(b, 12) /* modification time */
|
||||
#define CENCRC(b) LG(b, 16) /* crc of uncompressed data */
|
||||
#define CENSIZ(b) LG(b, 20) /* compressed size */
|
||||
#define CENLEN(b) LG(b, 24) /* uncompressed size */
|
||||
#define CENNAM(b) SH(b, 28) /* length of filename */
|
||||
#define CENEXT(b) SH(b, 30) /* length of extra field */
|
||||
#define CENCOM(b) SH(b, 32) /* file comment length */
|
||||
#define CENDSK(b) SH(b, 34) /* disk number start */
|
||||
#define CENATT(b) SH(b, 36) /* internal file attributes */
|
||||
#define CENATX(b) LG(b, 38) /* external file attributes */
|
||||
#define CENOFF(b) LG(b, 42) /* offset of local header */
|
||||
|
||||
/*
|
||||
* Macros for getting end of central directory header (END) fields
|
||||
*/
|
||||
#define ENDSUB(b) SH(b, 8) /* number of entries on this disk */
|
||||
#define ENDTOT(b) SH(b, 10) /* total number of entries */
|
||||
#define ENDSIZ(b) LG(b, 12) /* central directory size */
|
||||
#define ENDOFF(b) LG(b, 16) /* central directory offset */
|
||||
#define ENDCOM(b) SH(b, 20) /* size of zip file comment */
|
||||
|
||||
/*
|
||||
* Macros for getting Zip64 end of central directory header fields
|
||||
*/
|
||||
#define ZIP64_ENDLEN(b) LL(b, 4) /* size of zip64 end of central dir */
|
||||
#define ZIP64_ENDVEM(b) SH(b, 12) /* version made by */
|
||||
#define ZIP64_ENDVER(b) SH(b, 14) /* version needed to extract */
|
||||
#define ZIP64_ENDNMD(b) LG(b, 16) /* number of this disk */
|
||||
#define ZIP64_ENDDSK(b) LG(b, 20) /* disk number of start */
|
||||
#define ZIP64_ENDTOD(b) LL(b, 24) /* total number of entries on this disk */
|
||||
#define ZIP64_ENDTOT(b) LL(b, 32) /* total number of entries */
|
||||
#define ZIP64_ENDSIZ(b) LL(b, 40) /* central directory size in bytes */
|
||||
#define ZIP64_ENDOFF(b) LL(b, 48) /* offset of first CEN header */
|
||||
|
||||
/*
|
||||
* Macros for getting Zip64 end of central directory locator fields
|
||||
*/
|
||||
#define ZIP64_LOCDSK(b) LG(b, 4) /* disk number start */
|
||||
#define ZIP64_LOCOFF(b) LL(b, 8) /* offset of zip64 end */
|
||||
#define ZIP64_LOCTOT(b) LG(b, 16) /* total number of disks */
|
||||
|
||||
/*
|
||||
* A comment of maximum length of 64kb can follow the END record. This
|
||||
* is the furthest the END record can be from the end of the file.
|
||||
*/
|
||||
#define END_MAXLEN (0xFFFF + ENDHDR)
|
||||
|
||||
/*
|
||||
* Supported compression methods.
|
||||
*/
|
||||
#define STORED 0
|
||||
#define DEFLATED 8
|
||||
|
||||
/*
|
||||
* Information from the CEN entry to inflate a file.
|
||||
*/
|
||||
typedef struct zentry { /* Zip file entry */
|
||||
size_t isize; /* size of inflated data */
|
||||
size_t csize; /* size of compressed data (zero if uncompressed) */
|
||||
jlong offset; /* position of compressed data */
|
||||
int how; /* compression method (if any) */
|
||||
} zentry;
|
||||
|
||||
/*
|
||||
* Information returned from the Manifest file by the ParseManifest() routine.
|
||||
* Certainly (much) more could be returned, but this is the information
|
||||
* currently of interest to the C based Java utilities (particularly the
|
||||
* Java launcher).
|
||||
*/
|
||||
typedef struct manifest_info { /* Interesting fields from the Manifest */
|
||||
char *manifest_version; /* Manifest-Version string */
|
||||
char *main_class; /* Main-Class entry */
|
||||
char *jre_version; /* Appropriate J2SE release spec */
|
||||
char jre_restrict_search; /* Restricted JRE search */
|
||||
char *splashscreen_image_file_name; /* splashscreen image file */
|
||||
} manifest_info;
|
||||
|
||||
/*
|
||||
* Attribute closure to provide to manifest_iterate.
|
||||
*/
|
||||
typedef void (*attribute_closure)(const char *name, const char *value,
|
||||
void *user_data);
|
||||
|
||||
/*
|
||||
* Function prototypes.
|
||||
*/
|
||||
int JLI_ParseManifest(char *jarfile, manifest_info *info);
|
||||
void *JLI_JarUnpackFile(const char *jarfile, const char *filename,
|
||||
int *size);
|
||||
void JLI_FreeManifest(void);
|
||||
int JLI_ManifestIterate(const char *jarfile, attribute_closure ac,
|
||||
void *user_data);
|
||||
|
||||
#endif /* _MANIFEST_INFO_H */
|
||||
698
jdkSrc/jdk8/launcher/parse_manifest.c
Normal file
698
jdkSrc/jdk8/launcher/parse_manifest.c
Normal file
@@ -0,0 +1,698 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jli_util.h"
|
||||
|
||||
#include <zlib.h>
|
||||
#include "manifest_info.h"
|
||||
|
||||
static char *manifest;
|
||||
|
||||
static const char *manifest_name = "META-INF/MANIFEST.MF";
|
||||
|
||||
/*
|
||||
* Inflate the manifest file (or any file for that matter).
|
||||
*
|
||||
* fd: File descriptor of the jar file.
|
||||
* entry: Contains the information necessary to perform the inflation
|
||||
* (the compressed and uncompressed sizes and the offset in
|
||||
* the file where the compressed data is located).
|
||||
* size_out: Returns the size of the inflated file.
|
||||
*
|
||||
* Upon success, it returns a pointer to a NUL-terminated malloc'd buffer
|
||||
* containing the inflated manifest file. When the caller is done with it,
|
||||
* this buffer should be released by a call to free(). Upon failure,
|
||||
* returns NULL.
|
||||
*/
|
||||
static char *
|
||||
inflate_file(int fd, zentry *entry, int *size_out)
|
||||
{
|
||||
char *in;
|
||||
char *out;
|
||||
z_stream zs;
|
||||
|
||||
if (entry->csize == (size_t) -1 || entry->isize == (size_t) -1 )
|
||||
return (NULL);
|
||||
if (JLI_Lseek(fd, entry->offset, SEEK_SET) < (jlong)0)
|
||||
return (NULL);
|
||||
if ((in = malloc(entry->csize + 1)) == NULL)
|
||||
return (NULL);
|
||||
if ((size_t)(read(fd, in, (unsigned int)entry->csize)) != entry->csize) {
|
||||
free(in);
|
||||
return (NULL);
|
||||
}
|
||||
if (entry->how == STORED) {
|
||||
*(char *)((size_t)in + entry->csize) = '\0';
|
||||
if (size_out) {
|
||||
*size_out = (int)entry->csize;
|
||||
}
|
||||
return (in);
|
||||
} else if (entry->how == DEFLATED) {
|
||||
zs.zalloc = (alloc_func)Z_NULL;
|
||||
zs.zfree = (free_func)Z_NULL;
|
||||
zs.opaque = (voidpf)Z_NULL;
|
||||
zs.next_in = (Byte*)in;
|
||||
zs.avail_in = (uInt)entry->csize;
|
||||
if (inflateInit2(&zs, -MAX_WBITS) < 0) {
|
||||
free(in);
|
||||
return (NULL);
|
||||
}
|
||||
if ((out = malloc(entry->isize + 1)) == NULL) {
|
||||
free(in);
|
||||
return (NULL);
|
||||
}
|
||||
zs.next_out = (Byte*)out;
|
||||
zs.avail_out = (uInt)entry->isize;
|
||||
if (inflate(&zs, Z_PARTIAL_FLUSH) < 0) {
|
||||
free(in);
|
||||
free(out);
|
||||
return (NULL);
|
||||
}
|
||||
*(char *)((size_t)out + entry->isize) = '\0';
|
||||
free(in);
|
||||
if (inflateEnd(&zs) < 0) {
|
||||
free(out);
|
||||
return (NULL);
|
||||
}
|
||||
if (size_out) {
|
||||
*size_out = (int)entry->isize;
|
||||
}
|
||||
return (out);
|
||||
}
|
||||
free(in);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static jboolean zip64_present = JNI_FALSE;
|
||||
|
||||
/*
|
||||
* Checks to see if we have ZIP64 archive, and save
|
||||
* the check for later use
|
||||
*/
|
||||
static int
|
||||
haveZIP64(Byte *p) {
|
||||
jlong cenlen, cenoff, centot;
|
||||
cenlen = ENDSIZ(p);
|
||||
cenoff = ENDOFF(p);
|
||||
centot = ENDTOT(p);
|
||||
zip64_present = (cenlen == ZIP64_MAGICVAL ||
|
||||
cenoff == ZIP64_MAGICVAL ||
|
||||
centot == ZIP64_MAGICCOUNT);
|
||||
return zip64_present;
|
||||
}
|
||||
|
||||
static jlong
|
||||
find_end64(int fd, Byte *ep, jlong pos)
|
||||
{
|
||||
jlong end64pos;
|
||||
jlong bytes;
|
||||
if ((end64pos = JLI_Lseek(fd, pos - ZIP64_LOCHDR, SEEK_SET)) < (jlong)0)
|
||||
return -1;
|
||||
if ((bytes = read(fd, ep, ZIP64_LOCHDR)) < 0)
|
||||
return -1;
|
||||
if (GETSIG(ep) == ZIP64_LOCSIG)
|
||||
return end64pos;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* A very little used routine to handle the case that zip file has
|
||||
* a comment at the end. Believe it or not, the only way to find the
|
||||
* END record is to walk backwards, byte by bloody byte looking for
|
||||
* the END record signature.
|
||||
*
|
||||
* fd: File descriptor of the jar file.
|
||||
* eb: Pointer to a buffer to receive a copy of the END header.
|
||||
*
|
||||
* Returns the offset of the END record in the file on success,
|
||||
* -1 on failure.
|
||||
*/
|
||||
static jlong
|
||||
find_end(int fd, Byte *eb)
|
||||
{
|
||||
jlong len;
|
||||
jlong pos;
|
||||
jlong flen;
|
||||
int bytes;
|
||||
Byte *cp;
|
||||
Byte *endpos;
|
||||
Byte *buffer;
|
||||
|
||||
/*
|
||||
* 99.44% (or more) of the time, there will be no comment at the
|
||||
* end of the zip file. Try reading just enough to read the END
|
||||
* record from the end of the file, at this time we should also
|
||||
* check to see if we have a ZIP64 archive.
|
||||
*/
|
||||
if ((pos = JLI_Lseek(fd, -ENDHDR, SEEK_END)) < (jlong)0)
|
||||
return (-1);
|
||||
if ((bytes = read(fd, eb, ENDHDR)) < 0)
|
||||
return (-1);
|
||||
if (GETSIG(eb) == ENDSIG) {
|
||||
return haveZIP64(eb) ? find_end64(fd, eb, pos) : pos;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shucky-Darn,... There is a comment at the end of the zip file.
|
||||
*
|
||||
* Allocate and fill a buffer with enough of the zip file
|
||||
* to meet the specification for a maximal comment length.
|
||||
*/
|
||||
if ((flen = JLI_Lseek(fd, 0, SEEK_END)) < (jlong)0)
|
||||
return (-1);
|
||||
len = (flen < END_MAXLEN) ? flen : END_MAXLEN;
|
||||
if (JLI_Lseek(fd, -len, SEEK_END) < (jlong)0)
|
||||
return (-1);
|
||||
if ((buffer = malloc(END_MAXLEN)) == NULL)
|
||||
return (-1);
|
||||
if ((bytes = read(fd, buffer, len)) < 0) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Search backwards from the end of file stopping when the END header
|
||||
* signature is found. (The first condition of the "if" is just a
|
||||
* fast fail, because the GETSIG macro isn't always cheap. The
|
||||
* final condition protects against false positives.)
|
||||
*/
|
||||
endpos = &buffer[bytes];
|
||||
for (cp = &buffer[bytes - ENDHDR]; cp >= &buffer[0]; cp--)
|
||||
if ((*cp == (ENDSIG & 0xFF)) && (GETSIG(cp) == ENDSIG) &&
|
||||
(cp + ENDHDR + ENDCOM(cp) == endpos)) {
|
||||
(void) memcpy(eb, cp, ENDHDR);
|
||||
free(buffer);
|
||||
pos = flen - (endpos - cp);
|
||||
return haveZIP64(eb) ? find_end64(fd, eb, pos) : pos;
|
||||
}
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#define BUFSIZE (3 * 65536 + CENHDR + SIGSIZ)
|
||||
#define MINREAD 1024
|
||||
|
||||
/*
|
||||
* Computes and positions at the start of the CEN header, ie. the central
|
||||
* directory, this will also return the offset if there is a zip file comment
|
||||
* at the end of the archive, for most cases this would be 0.
|
||||
*/
|
||||
static jlong
|
||||
compute_cen(int fd, Byte *bp)
|
||||
{
|
||||
int bytes;
|
||||
Byte *p;
|
||||
jlong base_offset;
|
||||
jlong offset;
|
||||
Byte buffer[MINREAD];
|
||||
p = buffer;
|
||||
/*
|
||||
* Read the END Header, which is the starting point for ZIP files.
|
||||
* (Clearly designed to make writing a zip file easier than reading
|
||||
* one. Now isn't that precious...)
|
||||
*/
|
||||
if ((base_offset = find_end(fd, bp)) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
p = bp;
|
||||
/*
|
||||
* There is a historical, but undocumented, ability to allow for
|
||||
* additional "stuff" to be prepended to the zip/jar file. It seems
|
||||
* that this has been used to prepend an actual java launcher
|
||||
* executable to the jar on Windows. Although this is just another
|
||||
* form of statically linking a small piece of the JVM to the
|
||||
* application, we choose to continue to support it. Note that no
|
||||
* guarantees have been made (or should be made) to the customer that
|
||||
* this will continue to work.
|
||||
*
|
||||
* Therefore, calculate the base offset of the zip file (within the
|
||||
* expanded file) by assuming that the central directory is followed
|
||||
* immediately by the end record.
|
||||
*/
|
||||
if (zip64_present) {
|
||||
if ((offset = ZIP64_LOCOFF(p)) < (jlong)0) {
|
||||
return -1;
|
||||
}
|
||||
if (JLI_Lseek(fd, offset, SEEK_SET) < (jlong) 0) {
|
||||
return (-1);
|
||||
}
|
||||
if ((bytes = read(fd, buffer, MINREAD)) < 0) {
|
||||
return (-1);
|
||||
}
|
||||
if (GETSIG(buffer) != ZIP64_ENDSIG) {
|
||||
return -1;
|
||||
}
|
||||
if ((offset = ZIP64_ENDOFF(buffer)) < (jlong)0) {
|
||||
return -1;
|
||||
}
|
||||
if (JLI_Lseek(fd, offset, SEEK_SET) < (jlong)0) {
|
||||
return (-1);
|
||||
}
|
||||
p = buffer;
|
||||
base_offset = base_offset - ZIP64_ENDSIZ(p) - ZIP64_ENDOFF(p) - ZIP64_ENDHDR;
|
||||
} else {
|
||||
base_offset = base_offset - ENDSIZ(p) - ENDOFF(p);
|
||||
/*
|
||||
* The END Header indicates the start of the Central Directory
|
||||
* Headers. Remember that the desired Central Directory Header (CEN)
|
||||
* will almost always be the second one and the first one is a small
|
||||
* directory entry ("META-INF/"). Keep the code optimized for
|
||||
* that case.
|
||||
*
|
||||
* Seek to the beginning of the Central Directory.
|
||||
*/
|
||||
if (JLI_Lseek(fd, base_offset + ENDOFF(p), SEEK_SET) < (jlong) 0) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return base_offset;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate the manifest file with the zip/jar file.
|
||||
*
|
||||
* fd: File descriptor of the jar file.
|
||||
* entry: To be populated with the information necessary to perform
|
||||
* the inflation (the compressed and uncompressed sizes and
|
||||
* the offset in the file where the compressed data is located).
|
||||
*
|
||||
* Returns zero upon success. Returns a negative value upon failure.
|
||||
*
|
||||
* The buffer for reading the Central Directory if the zip/jar file needs
|
||||
* to be large enough to accommodate the largest possible single record
|
||||
* and the signature of the next record which is:
|
||||
*
|
||||
* 3*2**16 + CENHDR + SIGSIZ
|
||||
*
|
||||
* Each of the three variable sized fields (name, comment and extension)
|
||||
* has a maximum possible size of 64k.
|
||||
*
|
||||
* Typically, only a small bit of this buffer is used with bytes shuffled
|
||||
* down to the beginning of the buffer. It is one thing to allocate such
|
||||
* a large buffer and another thing to actually start faulting it in.
|
||||
*
|
||||
* In most cases, all that needs to be read are the first two entries in
|
||||
* a typical jar file (META-INF and META-INF/MANIFEST.MF). Keep this factoid
|
||||
* in mind when optimizing this code.
|
||||
*/
|
||||
static int
|
||||
find_file(int fd, zentry *entry, const char *file_name)
|
||||
{
|
||||
int bytes;
|
||||
int res;
|
||||
int entry_size;
|
||||
int read_size;
|
||||
jlong base_offset;
|
||||
Byte *p;
|
||||
Byte *bp;
|
||||
Byte *buffer;
|
||||
Byte locbuf[LOCHDR];
|
||||
|
||||
if ((buffer = (Byte*)malloc(BUFSIZE)) == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
bp = buffer;
|
||||
base_offset = compute_cen(fd, bp);
|
||||
if (base_offset == -1) {
|
||||
free(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((bytes = read(fd, bp, MINREAD)) < 0) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
p = bp;
|
||||
/*
|
||||
* Loop through the Central Directory Headers. Note that a valid zip/jar
|
||||
* must have an ENDHDR (with ENDSIG) after the Central Directory.
|
||||
*/
|
||||
while (GETSIG(p) == CENSIG) {
|
||||
|
||||
/*
|
||||
* If a complete header isn't in the buffer, shift the contents
|
||||
* of the buffer down and refill the buffer. Note that the check
|
||||
* for "bytes < CENHDR" must be made before the test for the entire
|
||||
* size of the header, because if bytes is less than CENHDR, the
|
||||
* actual size of the header can't be determined. The addition of
|
||||
* SIGSIZ guarantees that the next signature is also in the buffer
|
||||
* for proper loop termination.
|
||||
*/
|
||||
if (bytes < CENHDR) {
|
||||
p = memmove(bp, p, bytes);
|
||||
if ((res = read(fd, bp + bytes, MINREAD)) <= 0) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
bytes += res;
|
||||
}
|
||||
entry_size = CENHDR + CENNAM(p) + CENEXT(p) + CENCOM(p);
|
||||
if (bytes < entry_size + SIGSIZ) {
|
||||
if (p != bp)
|
||||
p = memmove(bp, p, bytes);
|
||||
read_size = entry_size - bytes + SIGSIZ;
|
||||
read_size = (read_size < MINREAD) ? MINREAD : read_size;
|
||||
if ((res = read(fd, bp + bytes, read_size)) <= 0) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
bytes += res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the name is the droid we are looking for; the jar file
|
||||
* manifest. If so, build the entry record from the data found in
|
||||
* the header located and return success.
|
||||
*/
|
||||
if ((size_t)CENNAM(p) == JLI_StrLen(file_name) &&
|
||||
memcmp((p + CENHDR), file_name, JLI_StrLen(file_name)) == 0) {
|
||||
if (JLI_Lseek(fd, base_offset + CENOFF(p), SEEK_SET) < (jlong)0) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
if (read(fd, locbuf, LOCHDR) < 0) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
if (GETSIG(locbuf) != LOCSIG) {
|
||||
free(buffer);
|
||||
return (-1);
|
||||
}
|
||||
entry->isize = CENLEN(p);
|
||||
entry->csize = CENSIZ(p);
|
||||
entry->offset = base_offset + CENOFF(p) + LOCHDR +
|
||||
LOCNAM(locbuf) + LOCEXT(locbuf);
|
||||
entry->how = CENHOW(p);
|
||||
free(buffer);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Point to the next entry and decrement the count of valid remaining
|
||||
* bytes.
|
||||
*/
|
||||
bytes -= entry_size;
|
||||
p += entry_size;
|
||||
}
|
||||
free(buffer);
|
||||
return (-1); /* Fell off the end the loop without a Manifest */
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a Manifest file header entry into a distinct "name" and "value".
|
||||
* Continuation lines are joined into a single "value". The documented
|
||||
* syntax for a header entry is:
|
||||
*
|
||||
* header: name ":" value
|
||||
*
|
||||
* name: alphanum *headerchar
|
||||
*
|
||||
* value: SPACE *otherchar newline *continuation
|
||||
*
|
||||
* continuation: SPACE *otherchar newline
|
||||
*
|
||||
* newline: CR LF | LF | CR (not followed by LF)
|
||||
*
|
||||
* alphanum: {"A"-"Z"} | {"a"-"z"} | {"0"-"9"}
|
||||
*
|
||||
* headerchar: alphanum | "-" | "_"
|
||||
*
|
||||
* otherchar: any UTF-8 character except NUL, CR and LF
|
||||
*
|
||||
* Note that a manifest file may be composed of multiple sections,
|
||||
* each of which may contain multiple headers.
|
||||
*
|
||||
* section: *header +newline
|
||||
*
|
||||
* nonempty-section: +header +newline
|
||||
*
|
||||
* (Note that the point of "nonempty-section" is unclear, because it isn't
|
||||
* referenced elsewhere in the full specification for the Manifest file.)
|
||||
*
|
||||
* Arguments:
|
||||
* lp pointer to a character pointer which points to the start
|
||||
* of a valid header.
|
||||
* name pointer to a character pointer which will be set to point
|
||||
* to the name portion of the header (nul terminated).
|
||||
* value pointer to a character pointer which will be set to point
|
||||
* to the value portion of the header (nul terminated).
|
||||
*
|
||||
* Returns:
|
||||
* 1 Successful parsing of an NV pair. lp is updated to point to the
|
||||
* next character after the terminating newline in the string
|
||||
* representing the Manifest file. name and value are updated to
|
||||
* point to the strings parsed.
|
||||
* 0 A valid end of section indicator was encountered. lp, name, and
|
||||
* value are not modified.
|
||||
* -1 lp does not point to a valid header. Upon return, the values of
|
||||
* lp, name, and value are undefined.
|
||||
*/
|
||||
static int
|
||||
parse_nv_pair(char **lp, char **name, char **value)
|
||||
{
|
||||
char *nl;
|
||||
char *cp;
|
||||
|
||||
/*
|
||||
* End of the section - return 0. The end of section condition is
|
||||
* indicated by either encountering a blank line or the end of the
|
||||
* Manifest "string" (EOF).
|
||||
*/
|
||||
if (**lp == '\0' || **lp == '\n' || **lp == '\r')
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Getting to here, indicates that *lp points to an "otherchar".
|
||||
* Turn the "header" into a string on its own.
|
||||
*/
|
||||
nl = JLI_StrPBrk(*lp, "\n\r");
|
||||
if (nl == NULL) {
|
||||
nl = JLI_StrChr(*lp, (int)'\0');
|
||||
} else {
|
||||
cp = nl; /* For merging continuation lines */
|
||||
if (*nl == '\r' && *(nl+1) == '\n')
|
||||
*nl++ = '\0';
|
||||
*nl++ = '\0';
|
||||
|
||||
/*
|
||||
* Process any "continuation" line(s), by making them part of the
|
||||
* "header" line. Yes, I know that we are "undoing" the NULs we
|
||||
* just placed here, but continuation lines are the fairly rare
|
||||
* case, so we shouldn't unnecessarily complicate the code above.
|
||||
*
|
||||
* Note that an entire continuation line is processed each iteration
|
||||
* through the outer while loop.
|
||||
*/
|
||||
while (*nl == ' ') {
|
||||
nl++; /* First character to be moved */
|
||||
while (*nl != '\n' && *nl != '\r' && *nl != '\0')
|
||||
*cp++ = *nl++; /* Shift string */
|
||||
if (*nl == '\0')
|
||||
return (-1); /* Error: newline required */
|
||||
*cp = '\0';
|
||||
if (*nl == '\r' && *(nl+1) == '\n')
|
||||
*nl++ = '\0';
|
||||
*nl++ = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Separate the name from the value;
|
||||
*/
|
||||
cp = JLI_StrChr(*lp, (int)':');
|
||||
if (cp == NULL)
|
||||
return (-1);
|
||||
*cp++ = '\0'; /* The colon terminates the name */
|
||||
if (*cp != ' ')
|
||||
return (-1);
|
||||
*cp++ = '\0'; /* Eat the required space */
|
||||
*name = *lp;
|
||||
*value = cp;
|
||||
*lp = nl;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the manifest from the specified jar file and fill in the manifest_info
|
||||
* structure with the information found within.
|
||||
*
|
||||
* Error returns are as follows:
|
||||
* 0 Success
|
||||
* -1 Unable to open jarfile
|
||||
* -2 Error accessing the manifest from within the jarfile (most likely
|
||||
* a manifest is not present, or this isn't a valid zip/jar file).
|
||||
*/
|
||||
int
|
||||
JLI_ParseManifest(char *jarfile, manifest_info *info)
|
||||
{
|
||||
int fd;
|
||||
zentry entry;
|
||||
char *lp;
|
||||
char *name;
|
||||
char *value;
|
||||
int rc;
|
||||
char *splashscreen_name = NULL;
|
||||
|
||||
if ((fd = open(jarfile, O_RDONLY
|
||||
#ifdef O_LARGEFILE
|
||||
| O_LARGEFILE /* large file mode */
|
||||
#endif
|
||||
#ifdef O_BINARY
|
||||
| O_BINARY /* use binary mode on windows */
|
||||
#endif
|
||||
)) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
info->manifest_version = NULL;
|
||||
info->main_class = NULL;
|
||||
info->jre_version = NULL;
|
||||
info->jre_restrict_search = 0;
|
||||
info->splashscreen_image_file_name = NULL;
|
||||
if (rc = find_file(fd, &entry, manifest_name) != 0) {
|
||||
close(fd);
|
||||
return (-2);
|
||||
}
|
||||
manifest = inflate_file(fd, &entry, NULL);
|
||||
if (manifest == NULL) {
|
||||
close(fd);
|
||||
return (-2);
|
||||
}
|
||||
lp = manifest;
|
||||
while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) {
|
||||
if (JLI_StrCaseCmp(name, "Manifest-Version") == 0)
|
||||
info->manifest_version = value;
|
||||
else if (JLI_StrCaseCmp(name, "Main-Class") == 0)
|
||||
info->main_class = value;
|
||||
else if (JLI_StrCaseCmp(name, "JRE-Version") == 0)
|
||||
info->jre_version = value;
|
||||
else if (JLI_StrCaseCmp(name, "JRE-Restrict-Search") == 0) {
|
||||
if (JLI_StrCaseCmp(value, "true") == 0)
|
||||
info->jre_restrict_search = 1;
|
||||
} else if (JLI_StrCaseCmp(name, "Splashscreen-Image") == 0) {
|
||||
info->splashscreen_image_file_name = value;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (rc == 0)
|
||||
return (0);
|
||||
else
|
||||
return (-2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Opens the jar file and unpacks the specified file from its contents.
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
void *
|
||||
JLI_JarUnpackFile(const char *jarfile, const char *filename, int *size) {
|
||||
int fd;
|
||||
zentry entry;
|
||||
void *data = NULL;
|
||||
|
||||
if ((fd = open(jarfile, O_RDONLY
|
||||
#ifdef O_LARGEFILE
|
||||
| O_LARGEFILE /* large file mode */
|
||||
#endif
|
||||
#ifdef O_BINARY
|
||||
| O_BINARY /* use binary mode on windows */
|
||||
#endif
|
||||
)) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (find_file(fd, &entry, filename) == 0) {
|
||||
data = inflate_file(fd, &entry, size);
|
||||
}
|
||||
close(fd);
|
||||
return (data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Specialized "free" function.
|
||||
*/
|
||||
void
|
||||
JLI_FreeManifest()
|
||||
{
|
||||
if (manifest)
|
||||
free(manifest);
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate over the manifest of the specified jar file and invoke the provided
|
||||
* closure function for each attribute encountered.
|
||||
*
|
||||
* Error returns are as follows:
|
||||
* 0 Success
|
||||
* -1 Unable to open jarfile
|
||||
* -2 Error accessing the manifest from within the jarfile (most likely
|
||||
* this means a manifest is not present, or it isn't a valid zip/jar file).
|
||||
*/
|
||||
int
|
||||
JLI_ManifestIterate(const char *jarfile, attribute_closure ac, void *user_data)
|
||||
{
|
||||
int fd;
|
||||
zentry entry;
|
||||
char *mp; /* manifest pointer */
|
||||
char *lp; /* pointer into manifest, updated during iteration */
|
||||
char *name;
|
||||
char *value;
|
||||
int rc;
|
||||
|
||||
if ((fd = open(jarfile, O_RDONLY
|
||||
#ifdef O_LARGEFILE
|
||||
| O_LARGEFILE /* large file mode */
|
||||
#endif
|
||||
#ifdef O_BINARY
|
||||
| O_BINARY /* use binary mode on windows */
|
||||
#endif
|
||||
)) == -1) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (rc = find_file(fd, &entry, manifest_name) != 0) {
|
||||
close(fd);
|
||||
return (-2);
|
||||
}
|
||||
|
||||
mp = inflate_file(fd, &entry, NULL);
|
||||
if (mp == NULL) {
|
||||
close(fd);
|
||||
return (-2);
|
||||
}
|
||||
|
||||
lp = mp;
|
||||
while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) {
|
||||
(*ac)(name, value, user_data);
|
||||
}
|
||||
free(mp);
|
||||
close(fd);
|
||||
return (rc == 0) ? 0 : -2;
|
||||
}
|
||||
34
jdkSrc/jdk8/launcher/splashscreen.h
Normal file
34
jdkSrc/jdk8/launcher/splashscreen.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
void DoSplashLoadMemory(void* pdata, int size); /* requires preloading the file */
|
||||
void DoSplashLoadFile(const char* filename);
|
||||
void DoSplashInit(void);
|
||||
void DoSplashClose(void);
|
||||
void DoSplashSetFileJarName(const char* fileName, const char* jarName);
|
||||
void DoSplashSetScaleFactor(float scaleFactor);
|
||||
char* DoSplashGetScaledImageName(const char* jarName, const char* fileName,
|
||||
float* scaleFactor);
|
||||
90
jdkSrc/jdk8/launcher/splashscreen_stubs.c
Normal file
90
jdkSrc/jdk8/launcher/splashscreen_stubs.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "splashscreen.h"
|
||||
|
||||
extern void* SplashProcAddress(const char* name); /* in java_md.c */
|
||||
|
||||
/*
|
||||
* Prototypes of pointers to functions in splashscreen shared lib
|
||||
*/
|
||||
typedef int (*SplashLoadMemory_t)(void* pdata, int size);
|
||||
typedef int (*SplashLoadFile_t)(const char* filename);
|
||||
typedef void (*SplashInit_t)(void);
|
||||
typedef void (*SplashClose_t)(void);
|
||||
typedef void (*SplashSetFileJarName_t)(const char* fileName,
|
||||
const char* jarName);
|
||||
typedef void (*SplashSetScaleFactor_t)(float scaleFactor);
|
||||
typedef char* (*SplashGetScaledImageName_t)(const char* fileName,
|
||||
const char* jarName, float* scaleFactor);
|
||||
|
||||
/*
|
||||
* This macro invokes a function from the shared lib.
|
||||
* it locates a function with SplashProcAddress on demand.
|
||||
* if SplashProcAddress fails, def value is returned.
|
||||
*
|
||||
* it is further wrapped with INVOKEV (works with functions which return
|
||||
* void and INVOKE (for all other functions). INVOKEV looks a bit ugly,
|
||||
* that's due being unable to return a value of type void in C. INVOKEV
|
||||
* works around this by using semicolon instead of return operator.
|
||||
*/
|
||||
#define _INVOKE(name,def,ret) \
|
||||
static void* proc = NULL; \
|
||||
if (!proc) { proc = SplashProcAddress(#name); } \
|
||||
if (!proc) { return def; } \
|
||||
ret ((name##_t)proc)
|
||||
|
||||
#define INVOKE(name,def) _INVOKE(name,def,return)
|
||||
#define INVOKEV(name) _INVOKE(name, ,;)
|
||||
|
||||
void DoSplashLoadMemory(void* pdata, int size) {
|
||||
INVOKEV(SplashLoadMemory)(pdata, size);
|
||||
}
|
||||
|
||||
void DoSplashLoadFile(const char* filename) {
|
||||
INVOKEV(SplashLoadFile)(filename);
|
||||
}
|
||||
|
||||
void DoSplashInit(void) {
|
||||
INVOKEV(SplashInit)();
|
||||
}
|
||||
|
||||
void DoSplashClose(void) {
|
||||
INVOKEV(SplashClose)();
|
||||
}
|
||||
|
||||
void DoSplashSetFileJarName(const char* fileName, const char* jarName) {
|
||||
INVOKEV(SplashSetFileJarName)(fileName, jarName);
|
||||
}
|
||||
|
||||
void DoSplashSetScaleFactor(float scaleFactor) {
|
||||
INVOKEV(SplashSetScaleFactor)(scaleFactor);
|
||||
}
|
||||
|
||||
char* DoSplashGetScaledImageName(const char* fileName, const char* jarName,
|
||||
float* scaleFactor) {
|
||||
INVOKE(SplashGetScaledImageName, NULL)(fileName, jarName, scaleFactor);
|
||||
}
|
||||
357
jdkSrc/jdk8/launcher/version_comp.c
Normal file
357
jdkSrc/jdk8/launcher/version_comp.c
Normal file
@@ -0,0 +1,357 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "jni.h"
|
||||
#include "jli_util.h"
|
||||
#include "version_comp.h"
|
||||
|
||||
/*
|
||||
* A collection of useful strings. One should think of these as #define
|
||||
* entries, but actual strings can be more efficient (with many compilers).
|
||||
*/
|
||||
static const char *separators = ".-_";
|
||||
static const char *zero_string = "0";
|
||||
|
||||
/*
|
||||
* Validate a string as parsable as a "Java int". If so parsable,
|
||||
* return true (non-zero) and store the numeric value at the address
|
||||
* passed in as "value"; otherwise return false (zero).
|
||||
*
|
||||
* Note that the maximum allowable value is 2147483647 as defined by
|
||||
* the "Java Language Specification" which precludes the use of native
|
||||
* conversion routines which may have other limits.
|
||||
*
|
||||
* Also note that we don't have to worry about the alternate maximum
|
||||
* allowable value of 2147483648 because it is only allowed after
|
||||
* the unary negation operator and this grammar doesn't have one
|
||||
* of those.
|
||||
*
|
||||
* Finally, note that a value which exceeds the maximum jint value will
|
||||
* return false (zero). This results in the otherwise purely numeric
|
||||
* string being compared as a string of characters (as per the spec.)
|
||||
*/
|
||||
static int
|
||||
isjavaint(const char *s, jint *value)
|
||||
{
|
||||
jlong sum = 0;
|
||||
jint digit;
|
||||
while (*s != '\0')
|
||||
if (isdigit(*s)) {
|
||||
digit = (jint)((int)(*s++) - (int)('0'));
|
||||
sum = (sum * 10) + digit;
|
||||
if (sum > 2147483647)
|
||||
return (0); /* Overflows jint (but not jlong) */
|
||||
} else
|
||||
return (0);
|
||||
*value = (jint)sum;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Modeled after strcmp(), compare two strings (as in the grammar defined
|
||||
* in Appendix A of JSR 56). If both strings can be interpreted as
|
||||
* Java ints, do a numeric comparison, else it is strcmp().
|
||||
*/
|
||||
static int
|
||||
comp_string(const char *s1, const char *s2)
|
||||
{
|
||||
jint v1, v2;
|
||||
if (isjavaint(s1, &v1) && isjavaint(s2, &v2))
|
||||
return ((int)(v1 - v2));
|
||||
else
|
||||
return (JLI_StrCmp(s1, s2));
|
||||
}
|
||||
|
||||
/*
|
||||
* Modeled after strcmp(), compare two version-ids for a Prefix
|
||||
* Match as defined in JSR 56.
|
||||
*/
|
||||
int
|
||||
JLI_PrefixVersionId(const char *id1, char *id2)
|
||||
{
|
||||
char *s1 = JLI_StringDup(id1);
|
||||
char *s2 = JLI_StringDup(id2);
|
||||
char *m1 = s1;
|
||||
char *m2 = s2;
|
||||
char *end1 = NULL;
|
||||
char *end2 = NULL;
|
||||
int res = 0;
|
||||
|
||||
do {
|
||||
|
||||
if ((s1 != NULL) && ((end1 = JLI_StrPBrk(s1, ".-_")) != NULL))
|
||||
*end1 = '\0';
|
||||
if ((s2 != NULL) && ((end2 = JLI_StrPBrk(s2, ".-_")) != NULL))
|
||||
*end2 = '\0';
|
||||
|
||||
res = comp_string(s1, s2);
|
||||
|
||||
if (end1 != NULL)
|
||||
s1 = end1 + 1;
|
||||
else
|
||||
s1 = NULL;
|
||||
if (end2 != NULL)
|
||||
s2 = end2 + 1;
|
||||
else
|
||||
s2 = NULL;
|
||||
|
||||
} while (res == 0 && ((s1 != NULL) && (s2 != NULL)));
|
||||
|
||||
JLI_MemFree(m1);
|
||||
JLI_MemFree(m2);
|
||||
return (res);
|
||||
}
|
||||
|
||||
/*
|
||||
* Modeled after strcmp(), compare two version-ids for an Exact
|
||||
* Match as defined in JSR 56.
|
||||
*/
|
||||
int
|
||||
JLI_ExactVersionId(const char *id1, char *id2)
|
||||
{
|
||||
char *s1 = JLI_StringDup(id1);
|
||||
char *s2 = JLI_StringDup(id2);
|
||||
char *m1 = s1;
|
||||
char *m2 = s2;
|
||||
char *end1 = NULL;
|
||||
char *end2 = NULL;
|
||||
int res = 0;
|
||||
|
||||
do {
|
||||
|
||||
if ((s1 != NULL) && ((end1 = JLI_StrPBrk(s1, separators)) != NULL))
|
||||
*end1 = '\0';
|
||||
if ((s2 != NULL) && ((end2 = JLI_StrPBrk(s2, separators)) != NULL))
|
||||
*end2 = '\0';
|
||||
|
||||
if ((s1 != NULL) && (s2 == NULL))
|
||||
res = comp_string(s1, zero_string);
|
||||
else if ((s1 == NULL) && (s2 != NULL))
|
||||
res = comp_string(zero_string, s2);
|
||||
else
|
||||
res = comp_string(s1, s2);
|
||||
|
||||
if (end1 != NULL)
|
||||
s1 = end1 + 1;
|
||||
else
|
||||
s1 = NULL;
|
||||
if (end2 != NULL)
|
||||
s2 = end2 + 1;
|
||||
else
|
||||
s2 = NULL;
|
||||
|
||||
} while (res == 0 && ((s1 != NULL) || (s2 != NULL)));
|
||||
|
||||
JLI_MemFree(m1);
|
||||
JLI_MemFree(m2);
|
||||
return (res);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if this simple-element (as defined in JSR 56) forms
|
||||
* an acceptable match.
|
||||
*
|
||||
* JSR 56 is modified by the Java Web Start <rel> Developer Guide
|
||||
* where it is stated "... Java Web Start will not consider an installed
|
||||
* non-FCS (i.e., milestone) JRE as a match. ... a JRE from Sun
|
||||
* Microsystems, Inc., is by convention a non-FCS (milestone) JRE
|
||||
* if there is a dash (-) in the version string."
|
||||
*
|
||||
* An undocumented caveat to the above is that an exact match with a
|
||||
* hyphen is accepted as a development extension.
|
||||
*
|
||||
* These modifications are addressed by the specific comparisons
|
||||
* for releases with hyphens.
|
||||
*/
|
||||
static int
|
||||
acceptable_simple_element(const char *release, char *simple_element)
|
||||
{
|
||||
char *modifier;
|
||||
modifier = simple_element + JLI_StrLen(simple_element) - 1;
|
||||
if (*modifier == '*') {
|
||||
*modifier = '\0';
|
||||
if (JLI_StrChr(release, '-'))
|
||||
return ((JLI_StrCmp(release, simple_element) == 0)?1:0);
|
||||
return ((JLI_PrefixVersionId(release, simple_element) == 0)?1:0);
|
||||
} else if (*modifier == '+') {
|
||||
*modifier = '\0';
|
||||
if (JLI_StrChr(release, '-'))
|
||||
return ((JLI_StrCmp(release, simple_element) == 0)?1:0);
|
||||
return ((JLI_ExactVersionId(release, simple_element) >= 0)?1:0);
|
||||
} else {
|
||||
return ((JLI_ExactVersionId(release, simple_element) == 0)?1:0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if this element (as defined in JSR 56) forms
|
||||
* an acceptable match. An element is the intersection (and)
|
||||
* of multiple simple-elements.
|
||||
*/
|
||||
static int
|
||||
acceptable_element(const char *release, char *element)
|
||||
{
|
||||
char *end;
|
||||
do {
|
||||
if ((end = JLI_StrChr(element, '&')) != NULL)
|
||||
*end = '\0';
|
||||
if (!acceptable_simple_element(release, element))
|
||||
return (0);
|
||||
if (end != NULL)
|
||||
element = end + 1;
|
||||
} while (end != NULL);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if release is acceptable by the specification version-string.
|
||||
* Return true if this version-string (as defined in JSR 56) forms
|
||||
* an acceptable match. A version-string is the union (or) of multiple
|
||||
* elements.
|
||||
*/
|
||||
int
|
||||
JLI_AcceptableRelease(const char *release, char *version_string)
|
||||
{
|
||||
char *vs;
|
||||
char *m1;
|
||||
char *end;
|
||||
m1 = vs = JLI_StringDup(version_string);
|
||||
do {
|
||||
if ((end = JLI_StrChr(vs, ' ')) != NULL)
|
||||
*end = '\0';
|
||||
if (acceptable_element(release, vs)) {
|
||||
JLI_MemFree(m1);
|
||||
return (1);
|
||||
}
|
||||
if (end != NULL)
|
||||
vs = end + 1;
|
||||
} while (end != NULL);
|
||||
JLI_MemFree(m1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if this is a valid simple-element (as defined in JSR 56).
|
||||
*
|
||||
* The official grammar for a simple-element is:
|
||||
*
|
||||
* simple-element ::= version-id | version-id modifier
|
||||
* modifier ::= '+' | '*'
|
||||
* version-id ::= string ( separator string )*
|
||||
* string ::= char ( char )*
|
||||
* char ::= Any ASCII character except a space, an
|
||||
* ampersand, a separator or a modifier
|
||||
* separator ::= '.' | '-' | '_'
|
||||
*
|
||||
* However, for efficiency, it is time to abandon the top down parser
|
||||
* implementation. After deleting the potential trailing modifier, we
|
||||
* are left with a version-id.
|
||||
*
|
||||
* Note that a valid version-id has three simple properties:
|
||||
*
|
||||
* 1) Doesn't contain a space, an ampersand or a modifier.
|
||||
*
|
||||
* 2) Doesn't begin or end with a separator.
|
||||
*
|
||||
* 3) Doesn't contain two adjacent separators.
|
||||
*
|
||||
* Any other line noise constitutes a valid version-id.
|
||||
*/
|
||||
static int
|
||||
valid_simple_element(char *simple_element)
|
||||
{
|
||||
char *last;
|
||||
size_t len;
|
||||
|
||||
if ((simple_element == NULL) || ((len = JLI_StrLen(simple_element)) == 0))
|
||||
return (0);
|
||||
last = simple_element + len - 1;
|
||||
if (*last == '*' || *last == '+') {
|
||||
if (--len == 0)
|
||||
return (0);
|
||||
*last-- = '\0';
|
||||
}
|
||||
if (JLI_StrPBrk(simple_element, " &+*") != NULL) /* Property #1 */
|
||||
return (0);
|
||||
if ((JLI_StrChr(".-_", *simple_element) != NULL) || /* Property #2 */
|
||||
(JLI_StrChr(".-_", *last) != NULL))
|
||||
return (0);
|
||||
for (; simple_element != last; simple_element++) /* Property #3 */
|
||||
if ((JLI_StrChr(".-_", *simple_element) != NULL) &&
|
||||
(JLI_StrChr(".-_", *(simple_element + 1)) != NULL))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if this is a valid element (as defined in JSR 56).
|
||||
* An element is the intersection (and) of multiple simple-elements.
|
||||
*/
|
||||
static int
|
||||
valid_element(char *element)
|
||||
{
|
||||
char *end;
|
||||
if ((element == NULL) || (JLI_StrLen(element) == 0))
|
||||
return (0);
|
||||
do {
|
||||
if ((end = JLI_StrChr(element, '&')) != NULL)
|
||||
*end = '\0';
|
||||
if (!valid_simple_element(element))
|
||||
return (0);
|
||||
if (end != NULL)
|
||||
element = end + 1;
|
||||
} while (end != NULL);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validates a version string by the extended JSR 56 grammar.
|
||||
*/
|
||||
int
|
||||
JLI_ValidVersionString(char *version_string)
|
||||
{
|
||||
char *vs;
|
||||
char *m1;
|
||||
char *end;
|
||||
if ((version_string == NULL) || (JLI_StrLen(version_string) == 0))
|
||||
return (0);
|
||||
m1 = vs = JLI_StringDup(version_string);
|
||||
do {
|
||||
if ((end = JLI_StrChr(vs, ' ')) != NULL)
|
||||
*end = '\0';
|
||||
if (!valid_element(vs)) {
|
||||
JLI_MemFree(m1);
|
||||
return (0);
|
||||
}
|
||||
if (end != NULL)
|
||||
vs = end + 1;
|
||||
} while (end != NULL);
|
||||
JLI_MemFree(m1);
|
||||
return (1);
|
||||
}
|
||||
37
jdkSrc/jdk8/launcher/version_comp.h
Normal file
37
jdkSrc/jdk8/launcher/version_comp.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef _VERSION_COMP_H
|
||||
#define _VERSION_COMP_H
|
||||
|
||||
/*
|
||||
* Function prototypes.
|
||||
*/
|
||||
int JLI_ExactVersionId(const char *id1, char *id2);
|
||||
int JLI_PrefixVersionId(const char *id1, char *id2);
|
||||
int JLI_AcceptableRelease(const char *release, char *version_string);
|
||||
int JLI_ValidVersionString(char *version_string);
|
||||
|
||||
#endif /* _VERSION_COMP_H */
|
||||
501
jdkSrc/jdk8/launcher/wildcard.c
Normal file
501
jdkSrc/jdk8/launcher/wildcard.c
Normal file
@@ -0,0 +1,501 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Class-Path Wildcards
|
||||
*
|
||||
* The syntax for wildcards is a single asterisk. The class path
|
||||
* foo/"*", e.g., loads all jar files in the directory named foo.
|
||||
* (This requires careful quotation when used in shell scripts.)
|
||||
*
|
||||
* Only files whose names end in .jar or .JAR are matched.
|
||||
* Files whose names end in .zip, or which have a particular
|
||||
* magic number, regardless of filename extension, are not
|
||||
* matched.
|
||||
*
|
||||
* Files are considered regardless of whether or not they are
|
||||
* "hidden" in the UNIX sense, i.e., have names beginning with '.'.
|
||||
*
|
||||
* A wildcard only matches jar files, not class files in the same
|
||||
* directory. If you want to load both class files and jar files from
|
||||
* a single directory foo then you can say foo:foo/"*", or foo/"*":foo
|
||||
* if you want the jar files to take precedence.
|
||||
*
|
||||
* Subdirectories are not searched recursively, i.e., foo/"*" only
|
||||
* looks for jar files in foo, not in foo/bar, foo/baz, etc.
|
||||
*
|
||||
* Expansion of wildcards is done early, prior to the invocation of a
|
||||
* program's main method, rather than late, during the class-loading
|
||||
* process itself. Each element of the input class path containing a
|
||||
* wildcard is replaced by the (possibly empty) sequence of elements
|
||||
* generated by enumerating the jar files in the named directory. If
|
||||
* the directory foo contains a.jar, b.jar, and c.jar,
|
||||
* e.g., then the class path foo/"*" is expanded into
|
||||
* foo/a.jar:foo/b.jar:foo/c.jar, and that string would be the value
|
||||
* of the system property java.class.path.
|
||||
*
|
||||
* The order in which the jar files in a directory are enumerated in
|
||||
* the expanded class path is not specified and may vary from platform
|
||||
* to platform and even from moment to moment on the same machine. A
|
||||
* well-constructed application should not depend upon any particular
|
||||
* order. If a specific order is required then the jar files can be
|
||||
* enumerated explicitly in the class path.
|
||||
*
|
||||
* The CLASSPATH environment variable is not treated any differently
|
||||
* from the -classpath (equiv. -cp) command-line option,
|
||||
* i.e. wildcards are honored in all these cases.
|
||||
*
|
||||
* Class-path wildcards are not honored in the Class-Path jar-manifest
|
||||
* header.
|
||||
*
|
||||
* Class-path wildcards are honored not only by the Java launcher but
|
||||
* also by most other command-line tools that accept class paths, and
|
||||
* in particular by javac and javadoc.
|
||||
*
|
||||
* Class-path wildcards are not honored in any other kind of path, and
|
||||
* especially not in the bootstrap class path, which is a mere
|
||||
* artifact of our implementation and not something that developers
|
||||
* should use.
|
||||
*
|
||||
* Classpath wildcards are only expanded in the Java launcher code,
|
||||
* supporting the use of wildcards on the command line and in the
|
||||
* CLASSPATH environment variable. We do not support the use of
|
||||
* wildcards by applications that embed the JVM.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "java.h" /* Strictly for PATH_SEPARATOR/FILE_SEPARATOR */
|
||||
#include "jli_util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else /* Unix */
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#endif /* Unix */
|
||||
|
||||
static int
|
||||
exists(const char* filename)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _access(filename, 0) == 0;
|
||||
#else
|
||||
return access(filename, F_OK) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define NEW_(TYPE) ((TYPE) JLI_MemAlloc(sizeof(struct TYPE##_)))
|
||||
|
||||
/*
|
||||
* Wildcard directory iteration.
|
||||
* WildcardIterator_for(wildcard) returns an iterator.
|
||||
* Each call to that iterator's next() method returns the basename
|
||||
* of an entry in the wildcard's directory. The basename's memory
|
||||
* belongs to the iterator. The caller is responsible for prepending
|
||||
* the directory name and file separator, if necessary.
|
||||
* When done with the iterator, call the close method to clean up.
|
||||
*/
|
||||
typedef struct WildcardIterator_* WildcardIterator;
|
||||
|
||||
#ifdef _WIN32
|
||||
struct WildcardIterator_
|
||||
{
|
||||
HANDLE handle;
|
||||
char *firstFile; /* Stupid FindFirstFile...FindNextFile */
|
||||
};
|
||||
// since this is used repeatedly we keep it here.
|
||||
static WIN32_FIND_DATA find_data;
|
||||
static WildcardIterator
|
||||
WildcardIterator_for(const char *wildcard)
|
||||
{
|
||||
WildcardIterator it = NEW_(WildcardIterator);
|
||||
HANDLE handle = FindFirstFile(wildcard, &find_data);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
JLI_MemFree(it);
|
||||
return NULL;
|
||||
}
|
||||
it->handle = handle;
|
||||
it->firstFile = find_data.cFileName;
|
||||
return it;
|
||||
}
|
||||
|
||||
static char *
|
||||
WildcardIterator_next(WildcardIterator it)
|
||||
{
|
||||
if (it->firstFile != NULL) {
|
||||
char *firstFile = it->firstFile;
|
||||
it->firstFile = NULL;
|
||||
return firstFile;
|
||||
}
|
||||
return FindNextFile(it->handle, &find_data)
|
||||
? find_data.cFileName : NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
WildcardIterator_close(WildcardIterator it)
|
||||
{
|
||||
if (it) {
|
||||
FindClose(it->handle);
|
||||
JLI_MemFree(it->firstFile);
|
||||
JLI_MemFree(it);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* Unix */
|
||||
struct WildcardIterator_
|
||||
{
|
||||
DIR *dir;
|
||||
};
|
||||
|
||||
static WildcardIterator
|
||||
WildcardIterator_for(const char *wildcard)
|
||||
{
|
||||
DIR *dir;
|
||||
int wildlen = JLI_StrLen(wildcard);
|
||||
if (wildlen < 2) {
|
||||
dir = opendir(".");
|
||||
} else {
|
||||
char *dirname = JLI_StringDup(wildcard);
|
||||
dirname[wildlen - 1] = '\0';
|
||||
dir = opendir(dirname);
|
||||
JLI_MemFree(dirname);
|
||||
}
|
||||
if (dir == NULL)
|
||||
return NULL;
|
||||
else {
|
||||
WildcardIterator it = NEW_(WildcardIterator);
|
||||
it->dir = dir;
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
WildcardIterator_next(WildcardIterator it)
|
||||
{
|
||||
struct dirent* dirp = readdir(it->dir);
|
||||
return dirp ? dirp->d_name : NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
WildcardIterator_close(WildcardIterator it)
|
||||
{
|
||||
if (it) {
|
||||
closedir(it->dir);
|
||||
JLI_MemFree(it);
|
||||
}
|
||||
}
|
||||
#endif /* Unix */
|
||||
|
||||
static int
|
||||
equal(const char *s1, const char *s2)
|
||||
{
|
||||
return JLI_StrCmp(s1, s2) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* FileList ADT - a dynamic list of C filenames
|
||||
*/
|
||||
struct FileList_
|
||||
{
|
||||
char **files;
|
||||
int size;
|
||||
int capacity;
|
||||
};
|
||||
typedef struct FileList_ *FileList;
|
||||
|
||||
static FileList
|
||||
FileList_new(int capacity)
|
||||
{
|
||||
FileList fl = NEW_(FileList);
|
||||
fl->capacity = capacity;
|
||||
fl->files = (char **) JLI_MemAlloc(capacity * sizeof(fl->files[0]));
|
||||
fl->size = 0;
|
||||
return fl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
FileList_free(FileList fl)
|
||||
{
|
||||
if (fl) {
|
||||
if (fl->files) {
|
||||
int i;
|
||||
for (i = 0; i < fl->size; i++)
|
||||
JLI_MemFree(fl->files[i]);
|
||||
JLI_MemFree(fl->files);
|
||||
}
|
||||
JLI_MemFree(fl);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
FileList_ensureCapacity(FileList fl, int capacity)
|
||||
{
|
||||
if (fl->capacity < capacity) {
|
||||
while (fl->capacity < capacity)
|
||||
fl->capacity *= 2;
|
||||
fl->files = JLI_MemRealloc(fl->files,
|
||||
fl->capacity * sizeof(fl->files[0]));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
FileList_add(FileList fl, char *file)
|
||||
{
|
||||
FileList_ensureCapacity(fl, fl->size+1);
|
||||
fl->files[fl->size++] = file;
|
||||
}
|
||||
|
||||
static void
|
||||
FileList_addSubstring(FileList fl, const char *beg, int len)
|
||||
{
|
||||
char *filename = (char *) JLI_MemAlloc(len+1);
|
||||
memcpy(filename, beg, len);
|
||||
filename[len] = '\0';
|
||||
FileList_ensureCapacity(fl, fl->size+1);
|
||||
fl->files[fl->size++] = filename;
|
||||
}
|
||||
|
||||
static char *
|
||||
FileList_join(FileList fl, char sep)
|
||||
{
|
||||
int i;
|
||||
int size;
|
||||
char *path;
|
||||
char *p;
|
||||
for (i = 0, size = 1; i < fl->size; i++)
|
||||
size += (int)JLI_StrLen(fl->files[i]) + 1;
|
||||
|
||||
path = JLI_MemAlloc(size);
|
||||
|
||||
for (i = 0, p = path; i < fl->size; i++) {
|
||||
int len = (int)JLI_StrLen(fl->files[i]);
|
||||
if (i > 0) *p++ = sep;
|
||||
memcpy(p, fl->files[i], len);
|
||||
p += len;
|
||||
}
|
||||
*p = '\0';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static FileList
|
||||
FileList_split(const char *path, char sep)
|
||||
{
|
||||
const char *p, *q;
|
||||
int len = (int)JLI_StrLen(path);
|
||||
int count;
|
||||
FileList fl;
|
||||
for (count = 1, p = path; p < path + len; p++)
|
||||
count += (*p == sep);
|
||||
fl = FileList_new(count);
|
||||
for (p = path;;) {
|
||||
for (q = p; q <= path + len; q++) {
|
||||
if (*q == sep || *q == '\0') {
|
||||
FileList_addSubstring(fl, p, q - p);
|
||||
if (*q == '\0')
|
||||
return fl;
|
||||
p = q + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
isJarFileName(const char *filename)
|
||||
{
|
||||
int len = (int)JLI_StrLen(filename);
|
||||
return (len >= 4) &&
|
||||
(filename[len - 4] == '.') &&
|
||||
(equal(filename + len - 3, "jar") ||
|
||||
equal(filename + len - 3, "JAR")) &&
|
||||
/* Paranoia: Maybe filename is "DIR:foo.jar" */
|
||||
(JLI_StrChr(filename, PATH_SEPARATOR) == NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
wildcardConcat(const char *wildcard, const char *basename)
|
||||
{
|
||||
int wildlen = (int)JLI_StrLen(wildcard);
|
||||
int baselen = (int)JLI_StrLen(basename);
|
||||
char *filename = (char *) JLI_MemAlloc(wildlen + baselen);
|
||||
/* Replace the trailing '*' with basename */
|
||||
memcpy(filename, wildcard, wildlen-1);
|
||||
memcpy(filename+wildlen-1, basename, baselen+1);
|
||||
return filename;
|
||||
}
|
||||
|
||||
static FileList
|
||||
wildcardFileList(const char *wildcard)
|
||||
{
|
||||
const char *basename;
|
||||
FileList fl = FileList_new(16);
|
||||
WildcardIterator it = WildcardIterator_for(wildcard);
|
||||
|
||||
if (it == NULL)
|
||||
{
|
||||
FileList_free(fl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((basename = WildcardIterator_next(it)) != NULL)
|
||||
if (isJarFileName(basename))
|
||||
FileList_add(fl, wildcardConcat(wildcard, basename));
|
||||
WildcardIterator_close(it);
|
||||
return fl;
|
||||
}
|
||||
|
||||
static int
|
||||
isWildcard(const char *filename)
|
||||
{
|
||||
int len = (int)JLI_StrLen(filename);
|
||||
return (len > 0) &&
|
||||
(filename[len - 1] == '*') &&
|
||||
(len == 1 || IS_FILE_SEPARATOR(filename[len - 2])) &&
|
||||
(! exists(filename));
|
||||
}
|
||||
|
||||
static void
|
||||
FileList_expandWildcards(FileList fl)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < fl->size; i++) {
|
||||
if (isWildcard(fl->files[i])) {
|
||||
FileList expanded = wildcardFileList(fl->files[i]);
|
||||
if (expanded != NULL && expanded->size > 0) {
|
||||
JLI_MemFree(fl->files[i]);
|
||||
FileList_ensureCapacity(fl, fl->size + expanded->size);
|
||||
for (j = fl->size - 1; j >= i+1; j--)
|
||||
fl->files[j+expanded->size-1] = fl->files[j];
|
||||
for (j = 0; j < expanded->size; j++)
|
||||
fl->files[i+j] = expanded->files[j];
|
||||
i += expanded->size - 1;
|
||||
fl->size += expanded->size - 1;
|
||||
/* fl expropriates expanded's elements. */
|
||||
expanded->size = 0;
|
||||
}
|
||||
FileList_free(expanded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
JLI_WildcardExpandClasspath(const char *classpath)
|
||||
{
|
||||
char *expanded;
|
||||
FileList fl;
|
||||
|
||||
if (JLI_StrChr(classpath, '*') == NULL)
|
||||
return classpath;
|
||||
fl = FileList_split(classpath, PATH_SEPARATOR);
|
||||
FileList_expandWildcards(fl);
|
||||
expanded = FileList_join(fl, PATH_SEPARATOR);
|
||||
FileList_free(fl);
|
||||
if (getenv(JLDEBUG_ENV_ENTRY) != 0)
|
||||
printf("Expanded wildcards:\n"
|
||||
" before: \"%s\"\n"
|
||||
" after : \"%s\"\n",
|
||||
classpath, expanded);
|
||||
return expanded;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_WILDCARD
|
||||
static void
|
||||
FileList_print(FileList fl)
|
||||
{
|
||||
int i;
|
||||
putchar('[');
|
||||
for (i = 0; i < fl->size; i++) {
|
||||
if (i > 0) printf(", ");
|
||||
printf("\"%s\"",fl->files[i]);
|
||||
}
|
||||
putchar(']');
|
||||
}
|
||||
|
||||
static void
|
||||
wildcardExpandArgv(const char ***argv)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; (*argv)[i]; i++) {
|
||||
if (equal((*argv)[i], "-cp") ||
|
||||
equal((*argv)[i], "-classpath")) {
|
||||
i++;
|
||||
(*argv)[i] = wildcardExpandClasspath((*argv)[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
debugPrintArgv(char *argv[])
|
||||
{
|
||||
int i;
|
||||
putchar('[');
|
||||
for (i = 0; argv[i]; i++) {
|
||||
if (i > 0) printf(", ");
|
||||
printf("\"%s\"", argv[i]);
|
||||
}
|
||||
printf("]\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
argv[0] = "java";
|
||||
wildcardExpandArgv((const char***)&argv);
|
||||
debugPrintArgv(argv);
|
||||
/* execvp("java", argv); */
|
||||
return 0;
|
||||
}
|
||||
#endif /* DEBUG_WILDCARD */
|
||||
|
||||
/* Cute little perl prototype implementation....
|
||||
|
||||
my $sep = ($^O =~ /^(Windows|cygwin)/) ? ";" : ":";
|
||||
|
||||
sub expand($) {
|
||||
opendir DIR, $_[0] or return $_[0];
|
||||
join $sep, map {"$_[0]/$_"} grep {/\.(jar|JAR)$/} readdir DIR;
|
||||
}
|
||||
|
||||
sub munge($) {
|
||||
join $sep,
|
||||
map {(! -r $_ and s/[\/\\]+\*$//) ? expand $_ : $_} split $sep, $_[0];
|
||||
}
|
||||
|
||||
for (my $i = 0; $i < @ARGV - 1; $i++) {
|
||||
$ARGV[$i+1] = munge $ARGV[$i+1] if $ARGV[$i] =~ /^-c(p|lasspath)$/;
|
||||
}
|
||||
|
||||
$ENV{CLASSPATH} = munge $ENV{CLASSPATH} if exists $ENV{CLASSPATH};
|
||||
@ARGV = ("java", @ARGV);
|
||||
print "@ARGV\n";
|
||||
exec @ARGV;
|
||||
|
||||
*/
|
||||
31
jdkSrc/jdk8/launcher/wildcard.h
Normal file
31
jdkSrc/jdk8/launcher/wildcard.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
#ifndef WILDCARD_H_
|
||||
#define WILDCARD_H_
|
||||
|
||||
const char *JLI_WildcardExpandClasspath(const char *classpath);
|
||||
|
||||
#endif /* include guard */
|
||||
Reference in New Issue
Block a user