1 /*
2 * Copyright (c) 1996, 2014, 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
476 JNIEXPORT jlong JNICALL
477 Java_java_lang_ClassLoader_00024NativeLibrary_find
478 (JNIEnv *env, jobject this, jstring name)
479 {
480 jlong handle;
481 const char *cname;
482 jlong res;
483
484 if (!initIDs(env))
485 return jlong_zero;
486
487 handle = (*env)->GetLongField(env, this, handleID);
488 cname = (*env)->GetStringUTFChars(env, name, 0);
489 if (cname == 0)
490 return jlong_zero;
491 res = ptr_to_jlong(JVM_FindLibraryEntry(jlong_to_ptr(handle), cname));
492 (*env)->ReleaseStringUTFChars(env, name, cname);
493 return res;
494 }
495 /*
496 * Class: java_lang_ClassLoader_NativeLibrary
497 * Method: findBuiltinLib
498 * Signature: (Ljava/lang/String;)Ljava/lang/String;
499 */
500 JNIEXPORT jstring JNICALL
501 Java_java_lang_ClassLoader_00024NativeLibrary_findBuiltinLib
502 (JNIEnv *env, jclass cls, jstring name)
503 {
504 const char *cname;
505 char *libName;
506 int prefixLen = (int) strlen(JNI_LIB_PREFIX);
507 int suffixLen = (int) strlen(JNI_LIB_SUFFIX);
508 int len;
509 jstring lib;
510 void *ret;
511 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
512
513 if (name == NULL) {
514 JNU_ThrowInternalError(env, "NULL filename for native library");
515 return NULL;
516 }
517 // Can't call initIDs because it will recurse into NativeLibrary via
518 // FindClass to check context so set prochandle here as well.
519 procHandle = getProcessHandle();
520 cname = JNU_GetStringPlatformChars(env, name, 0);
521 if (cname == NULL) {
522 JNU_ThrowOutOfMemoryError(env, NULL);
523 return NULL;
524 }
525 // Copy name Skipping PREFIX
526 len = strlen(cname);
527 if (len <= (prefixLen+suffixLen)) {
528 JNU_ReleaseStringPlatformChars(env, name, cname);
529 return NULL;
530 }
531 libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
532 if (libName == NULL) {
533 JNU_ReleaseStringPlatformChars(env, name, cname);
534 JNU_ThrowOutOfMemoryError(env, NULL);
535 return NULL;
536 }
537 if (len > prefixLen) {
538 strcpy(libName, cname+prefixLen);
|
1 /*
2 * Copyright (c) 1996, 2015, 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
476 JNIEXPORT jlong JNICALL
477 Java_java_lang_ClassLoader_00024NativeLibrary_find
478 (JNIEnv *env, jobject this, jstring name)
479 {
480 jlong handle;
481 const char *cname;
482 jlong res;
483
484 if (!initIDs(env))
485 return jlong_zero;
486
487 handle = (*env)->GetLongField(env, this, handleID);
488 cname = (*env)->GetStringUTFChars(env, name, 0);
489 if (cname == 0)
490 return jlong_zero;
491 res = ptr_to_jlong(JVM_FindLibraryEntry(jlong_to_ptr(handle), cname));
492 (*env)->ReleaseStringUTFChars(env, name, cname);
493 return res;
494 }
495 /*
496 * Class: java_lang_ClassLoader
497 * Method: findBuiltinLib
498 * Signature: (Ljava/lang/String;)Ljava/lang/String;
499 */
500 JNIEXPORT jstring JNICALL
501 Java_java_lang_ClassLoader_findBuiltinLib
502 (JNIEnv *env, jclass cls, jstring name)
503 {
504 const char *cname;
505 char *libName;
506 int prefixLen = (int) strlen(JNI_LIB_PREFIX);
507 int suffixLen = (int) strlen(JNI_LIB_SUFFIX);
508 int len;
509 jstring lib;
510 void *ret;
511 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS;
512
513 if (name == NULL) {
514 JNU_ThrowInternalError(env, "NULL filename for native library");
515 return NULL;
516 }
517 procHandle = getProcessHandle();
518 cname = JNU_GetStringPlatformChars(env, name, 0);
519 if (cname == NULL) {
520 JNU_ThrowOutOfMemoryError(env, NULL);
521 return NULL;
522 }
523 // Copy name Skipping PREFIX
524 len = strlen(cname);
525 if (len <= (prefixLen+suffixLen)) {
526 JNU_ReleaseStringPlatformChars(env, name, cname);
527 return NULL;
528 }
529 libName = malloc(len + 1); //+1 for null if prefix+suffix == 0
530 if (libName == NULL) {
531 JNU_ReleaseStringPlatformChars(env, name, cname);
532 JNU_ThrowOutOfMemoryError(env, NULL);
533 return NULL;
534 }
535 if (len > prefixLen) {
536 strcpy(libName, cname+prefixLen);
|