1 /*
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
498 }
499 #endif
500
501 char *realPathToSelf = realpath(selfInfo.dli_fname, path);
502 if (realPathToSelf != path) {
503 return JNI_FALSE;
504 }
505
506 size_t pathLen = strlen(realPathToSelf);
507 if (pathLen == 0) {
508 return JNI_FALSE;
509 }
510
511 const char lastPathComponent[] = "/lib/libjli.dylib";
512 size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
513 if (pathLen < sizeOfLastPathComponent) {
514 return JNI_FALSE;
515 }
516
517 size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
518 if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent - 1)) {
519 realPathToSelf[indexOfLastPathComponent + 1] = '\0';
520 return JNI_TRUE;
521 }
522
523 if (!speculative)
524 JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
525 return JNI_FALSE;
526 }
527
528 jboolean
529 LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
530 {
531 Dl_info dlinfo;
532 void *libjvm;
533
534 JLI_TraceLauncher("JVM path is %s\n", jvmpath);
535
536 #ifndef STATIC_BUILD
537 libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
538 #else
539 libjvm = dlopen(NULL, RTLD_FIRST);
540 #endif
541 if (libjvm == NULL) {
542 JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
|
1 /*
2 * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
498 }
499 #endif
500
501 char *realPathToSelf = realpath(selfInfo.dli_fname, path);
502 if (realPathToSelf != path) {
503 return JNI_FALSE;
504 }
505
506 size_t pathLen = strlen(realPathToSelf);
507 if (pathLen == 0) {
508 return JNI_FALSE;
509 }
510
511 const char lastPathComponent[] = "/lib/libjli.dylib";
512 size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
513 if (pathLen < sizeOfLastPathComponent) {
514 return JNI_FALSE;
515 }
516
517 size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
518 if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent)) {
519 realPathToSelf[indexOfLastPathComponent + 1] = '\0';
520 return JNI_TRUE;
521 }
522
523 // If libjli.dylib is loaded from a macos bundle MacOS dir, find the JRE dir
524 // in ../Home.
525 const char altLastPathComponent[] = "/MacOS/libjli.dylib";
526 size_t sizeOfAltLastPathComponent = sizeof(altLastPathComponent) - 1;
527 if (pathLen < sizeOfLastPathComponent) {
528 return JNI_FALSE;
529 }
530
531 size_t indexOfAltLastPathComponent = pathLen - sizeOfAltLastPathComponent;
532 if (0 == strncmp(realPathToSelf + indexOfAltLastPathComponent, altLastPathComponent, sizeOfAltLastPathComponent)) {
533 JLI_Snprintf(realPathToSelf + indexOfAltLastPathComponent, sizeOfAltLastPathComponent, "%s", "/Home");
534 if (access(realPathToSelf, F_OK) == 0) {
535 return JNI_TRUE;
536 }
537 }
538
539 if (!speculative)
540 JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
541 return JNI_FALSE;
542 }
543
544 jboolean
545 LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
546 {
547 Dl_info dlinfo;
548 void *libjvm;
549
550 JLI_TraceLauncher("JVM path is %s\n", jvmpath);
551
552 #ifndef STATIC_BUILD
553 libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
554 #else
555 libjvm = dlopen(NULL, RTLD_FIRST);
556 #endif
557 if (libjvm == NULL) {
558 JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
|