Path: blob/master/src/java.base/share/native/launcher/main.c
41149 views
/*1* Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526/*27* This file contains the main entry point into the launcher code28* this is the only file which will be repeatedly compiled by other29* tools. The rest of the files will be linked in.30*/3132#include "defines.h"33#include "jli_util.h"34#include "jni.h"3536#ifdef _MSC_VER37#if _MSC_VER > 1400 && _MSC_VER < 16003839/*40* When building for Microsoft Windows, main has a dependency on msvcr??.dll.41*42* When using Visual Studio 2005 or 2008, that must be recorded in43* the [java,javaw].exe.manifest file.44*45* As of VS2010 (ver=1600), the runtimes again no longer need manifests.46*47* Reference:48* C:/Program Files/Microsoft SDKs/Windows/v6.1/include/crtdefs.h49*/50#include <crtassem.h>51#ifdef _M_IX865253#pragma comment(linker,"/manifestdependency:\"type='win32' " \54"name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' " \55"version='" _CRT_ASSEMBLY_VERSION "' " \56"processorArchitecture='x86' " \57"publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")5859#endif /* _M_IX86 */6061//This may not be necessary yet for the Windows 64-bit build, but it62//will be when that build environment is updated. Need to test to see63//if it is harmless:64#ifdef _M_AMD646566#pragma comment(linker,"/manifestdependency:\"type='win32' " \67"name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' " \68"version='" _CRT_ASSEMBLY_VERSION "' " \69"processorArchitecture='amd64' " \70"publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")7172#endif /* _M_AMD64 */73#endif /* _MSC_VER > 1400 && _MSC_VER < 1600 */74#endif /* _MSC_VER */7576/*77* Entry point.78*/79#ifdef JAVAW8081char **__initenv;8283int WINAPI84WinMain(HINSTANCE inst, HINSTANCE previnst, LPSTR cmdline, int cmdshow)85{86int margc;87char** margv;88int jargc;89char** jargv;90const jboolean const_javaw = JNI_TRUE;9192__initenv = _environ;9394#else /* JAVAW */95JNIEXPORT int96main(int argc, char **argv)97{98int margc;99char** margv;100int jargc;101char** jargv;102const jboolean const_javaw = JNI_FALSE;103#endif /* JAVAW */104{105int i, main_jargc, extra_jargc;106JLI_List list;107108main_jargc = (sizeof(const_jargs) / sizeof(char *)) > 1109? sizeof(const_jargs) / sizeof(char *)110: 0; // ignore the null terminator index111112extra_jargc = (sizeof(const_extra_jargs) / sizeof(char *)) > 1113? sizeof(const_extra_jargs) / sizeof(char *)114: 0; // ignore the null terminator index115116if (main_jargc > 0 && extra_jargc > 0) { // combine extra java args117jargc = main_jargc + extra_jargc;118list = JLI_List_new(jargc + 1);119120for (i = 0 ; i < extra_jargc; i++) {121JLI_List_add(list, JLI_StringDup(const_extra_jargs[i]));122}123124for (i = 0 ; i < main_jargc ; i++) {125JLI_List_add(list, JLI_StringDup(const_jargs[i]));126}127128// terminate the list129JLI_List_add(list, NULL);130jargv = list->elements;131} else if (extra_jargc > 0) { // should never happen132fprintf(stderr, "EXTRA_JAVA_ARGS defined without JAVA_ARGS");133abort();134} else { // no extra args, business as usual135jargc = main_jargc;136jargv = (char **) const_jargs;137}138}139140JLI_InitArgProcessing(jargc > 0, const_disable_argfile);141142#ifdef _WIN32143{144int i = 0;145if (getenv(JLDEBUG_ENV_ENTRY) != NULL) {146printf("Windows original main args:\n");147for (i = 0 ; i < __argc ; i++) {148printf("wwwd_args[%d] = %s\n", i, __argv[i]);149}150}151}152JLI_CmdToArgs(GetCommandLine());153margc = JLI_GetStdArgc();154// add one more to mark the end155margv = (char **)JLI_MemAlloc((margc + 1) * (sizeof(char *)));156{157int i = 0;158StdArg *stdargs = JLI_GetStdArgs();159for (i = 0 ; i < margc ; i++) {160margv[i] = stdargs[i].arg;161}162margv[i] = NULL;163}164#else /* *NIXES */165{166// accommodate the NULL at the end167JLI_List args = JLI_List_new(argc + 1);168int i = 0;169170// Add first arg, which is the app name171JLI_List_add(args, JLI_StringDup(argv[0]));172// Append JDK_JAVA_OPTIONS173if (JLI_AddArgsFromEnvVar(args, JDK_JAVA_OPTIONS)) {174// JLI_SetTraceLauncher is not called yet175// Show _JAVA_OPTIONS content along with JDK_JAVA_OPTIONS to aid diagnosis176if (getenv(JLDEBUG_ENV_ENTRY)) {177char *tmp = getenv("_JAVA_OPTIONS");178if (NULL != tmp) {179JLI_ReportMessage(ARG_INFO_ENVVAR, "_JAVA_OPTIONS", tmp);180}181}182}183// Iterate the rest of command line184for (i = 1; i < argc; i++) {185JLI_List argsInFile = JLI_PreprocessArg(argv[i], JNI_TRUE);186if (NULL == argsInFile) {187JLI_List_add(args, JLI_StringDup(argv[i]));188} else {189int cnt, idx;190cnt = argsInFile->size;191for (idx = 0; idx < cnt; idx++) {192JLI_List_add(args, argsInFile->elements[idx]);193}194// Shallow free, we reuse the string to avoid copy195JLI_MemFree(argsInFile->elements);196JLI_MemFree(argsInFile);197}198}199margc = args->size;200// add the NULL pointer at argv[argc]201JLI_List_add(args, NULL);202margv = args->elements;203}204#endif /* WIN32 */205return JLI_Launch(margc, margv,206jargc, (const char**) jargv,2070, NULL,208VERSION_STRING,209DOT_VERSION,210(const_progname != NULL) ? const_progname : *margv,211(const_launcher != NULL) ? const_launcher : *margv,212jargc > 0,213const_cpwildcard, const_javaw, 0);214}215216217