664 |
*/ |
*/ |
665 |
public void load(String filename) |
public void load(String filename) |
666 |
{ |
{ |
667 |
|
SecurityManager sm = securityManager; // Be thread-safe! |
668 |
|
if (sm != null) |
669 |
|
sm.checkLink(filename); |
670 |
if (loadLib(filename) == 0) |
if (loadLib(filename) == 0) |
671 |
throw new UnsatisfiedLinkError("Could not load library " + filename); |
throw new UnsatisfiedLinkError("Could not load library " + filename); |
672 |
} |
} |
673 |
|
|
674 |
// Private version of load(String) that doesn't throw Exception on |
/** |
675 |
// load error, but it does do security checks (which can throw |
* Do a security check on the filename and then load the native library. |
676 |
// SecurityExceptions). Convenience method for early bootstrap |
* |
677 |
// process. |
* @param filename the file to load |
678 |
private int loadLib(String filename) |
* @return 0 on failure, nonzero on success |
679 |
|
* @throws SecurityException if file read permission is denied |
680 |
|
*/ |
681 |
|
private static int loadLib(String filename) |
682 |
{ |
{ |
683 |
SecurityManager sm = securityManager; // Be thread-safe! |
SecurityManager sm = securityManager; // Be thread-safe! |
684 |
if (sm != null) |
if (sm != null) |
685 |
sm.checkLink(filename); |
sm.checkRead(filename); |
686 |
return VMRuntime.nativeLoad(filename); |
return VMRuntime.nativeLoad(filename); |
687 |
} |
} |
688 |
|
|
708 |
*/ |
*/ |
709 |
public void loadLibrary(String libname) |
public void loadLibrary(String libname) |
710 |
{ |
{ |
711 |
|
SecurityManager sm = securityManager; // Be thread-safe! |
712 |
|
if (sm != null) |
713 |
|
sm.checkLink(libname); |
714 |
|
|
715 |
String filename; |
String filename; |
716 |
ClassLoader cl = VMSecurityManager.currentClassLoader(); |
ClassLoader cl = VMSecurityManager.currentClassLoader(); |
717 |
if (cl != null) |
if (cl != null) |
719 |
filename = cl.findLibrary(libname); |
filename = cl.findLibrary(libname); |
720 |
if (filename != null) |
if (filename != null) |
721 |
{ |
{ |
|
// Use loadLib so no UnsatisfiedLinkError are thrown. |
|
722 |
if (loadLib(filename) != 0) |
if (loadLib(filename) != 0) |
723 |
return; |
return; |
724 |
|
else |
725 |
|
throw new UnsatisfiedLinkError("Could not load library " + filename); |
726 |
} |
} |
727 |
} |
} |
728 |
|
|
729 |
filename = System.mapLibraryName(libname); |
filename = System.mapLibraryName(libname); |
730 |
for (int i = 0; i < libpath.length; i++) |
for (int i = 0; i < libpath.length; i++) |
|
// Use loadLib so no UnsatisfiedLinkError are thrown. |
|
731 |
if (loadLib(libpath[i] + filename) != 0) |
if (loadLib(libpath[i] + filename) != 0) |
732 |
return; |
return; |
733 |
|
|