39 |
package java.lang; |
package java.lang; |
40 |
|
|
41 |
import gnu.classpath.SystemProperties; |
import gnu.classpath.SystemProperties; |
|
import gnu.classpath.VMStackWalker; |
|
42 |
|
|
43 |
import java.io.File; |
import java.io.File; |
44 |
import java.io.IOException; |
import java.io.IOException; |
628 |
* before the final ".so" if the VM was invoked by the name "java_g". There |
* before the final ".so" if the VM was invoked by the name "java_g". There |
629 |
* may be a security check, of <code>checkLink</code>. |
* may be a security check, of <code>checkLink</code>. |
630 |
* |
* |
|
* <p> |
|
|
* The library is loaded using the class loader associated with the |
|
|
* class associated with the invoking method. |
|
|
* |
|
631 |
* @param filename the file to load |
* @param filename the file to load |
632 |
* @throws SecurityException if permission is denied |
* @throws SecurityException if permission is denied |
633 |
* @throws UnsatisfiedLinkError if the library is not found |
* @throws UnsatisfiedLinkError if the library is not found |
634 |
*/ |
*/ |
635 |
public void load(String filename) |
public void load(String filename) |
636 |
{ |
{ |
|
load(filename, VMStackWalker.getCallingClassLoader()); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Same as <code>load(String)</code> but using the given loader. |
|
|
* |
|
|
* @param filename the file to load |
|
|
* @param loader class loader, or <code>null</code> for the boot loader |
|
|
* @throws SecurityException if permission is denied |
|
|
* @throws UnsatisfiedLinkError if the library is not found |
|
|
*/ |
|
|
void load(String filename, ClassLoader loader) |
|
|
{ |
|
637 |
SecurityManager sm = SecurityManager.current; // Be thread-safe! |
SecurityManager sm = SecurityManager.current; // Be thread-safe! |
638 |
if (sm != null) |
if (sm != null) |
639 |
sm.checkLink(filename); |
sm.checkLink(filename); |
640 |
if (loadLib(filename, loader) == 0) |
if (loadLib(filename) == 0) |
641 |
throw new UnsatisfiedLinkError("Could not load library " + filename); |
throw new UnsatisfiedLinkError("Could not load library " + filename); |
642 |
} |
} |
643 |
|
|
645 |
* Do a security check on the filename and then load the native library. |
* Do a security check on the filename and then load the native library. |
646 |
* |
* |
647 |
* @param filename the file to load |
* @param filename the file to load |
|
* @param loader class loader, or <code>null</code> for the boot loader |
|
648 |
* @return 0 on failure, nonzero on success |
* @return 0 on failure, nonzero on success |
649 |
* @throws SecurityException if file read permission is denied |
* @throws SecurityException if file read permission is denied |
650 |
*/ |
*/ |
651 |
private static int loadLib(String filename, ClassLoader loader) |
private static int loadLib(String filename) |
652 |
{ |
{ |
653 |
SecurityManager sm = SecurityManager.current; // Be thread-safe! |
SecurityManager sm = SecurityManager.current; // Be thread-safe! |
654 |
if (sm != null) |
if (sm != null) |
655 |
sm.checkRead(filename); |
sm.checkRead(filename); |
656 |
return VMRuntime.nativeLoad(filename, loader); |
return VMRuntime.nativeLoad(filename); |
657 |
} |
} |
658 |
|
|
659 |
/** |
/** |
668 |
* <code>System.mapLibraryName(libname)</code>. There may be a security |
* <code>System.mapLibraryName(libname)</code>. There may be a security |
669 |
* check, of <code>checkLink</code>. |
* check, of <code>checkLink</code>. |
670 |
* |
* |
|
* <p> |
|
|
* The library is loaded using the class loader associated with the |
|
|
* class associated with the invoking method. |
|
|
* |
|
671 |
* @param libname the library to load |
* @param libname the library to load |
672 |
* |
* |
673 |
* @throws SecurityException if permission is denied |
* @throws SecurityException if permission is denied |
678 |
*/ |
*/ |
679 |
public void loadLibrary(String libname) |
public void loadLibrary(String libname) |
680 |
{ |
{ |
|
loadLibrary(libname, VMStackWalker.getCallingClassLoader()); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Same as <code>loadLibrary(String)</code> but using the given loader. |
|
|
* |
|
|
* @param libname the library to load |
|
|
* @param loader class loader, or <code>null</code> for the boot loader |
|
|
* @throws SecurityException if permission is denied |
|
|
* @throws UnsatisfiedLinkError if the library is not found |
|
|
*/ |
|
|
void loadLibrary(String libname, ClassLoader loader) |
|
|
{ |
|
681 |
SecurityManager sm = SecurityManager.current; // Be thread-safe! |
SecurityManager sm = SecurityManager.current; // Be thread-safe! |
682 |
if (sm != null) |
if (sm != null) |
683 |
sm.checkLink(libname); |
sm.checkLink(libname); |
684 |
|
|
685 |
String filename; |
String filename; |
686 |
if (loader != null && (filename = loader.findLibrary(libname)) != null) |
ClassLoader cl = VMSecurityManager.currentClassLoader(); |
687 |
|
if (cl != null) |
688 |
{ |
{ |
689 |
if (loadLib(filename, loader) != 0) |
filename = cl.findLibrary(libname); |
690 |
return; |
if (filename != null) |
691 |
} |
{ |
692 |
else |
if (loadLib(filename) != 0) |
693 |
{ |
return; |
694 |
filename = VMRuntime.mapLibraryName(libname); |
else |
695 |
for (int i = 0; i < libpath.length; i++) |
throw new UnsatisfiedLinkError("Could not load library " + filename); |
696 |
if (loadLib(libpath[i] + filename, loader) != 0) |
} |
|
return; |
|
697 |
} |
} |
698 |
throw new UnsatisfiedLinkError("Native library `" + libname |
|
699 |
+ "' not found (as file `" + filename + "')"); |
filename = VMRuntime.mapLibraryName(libname); |
700 |
|
for (int i = 0; i < libpath.length; i++) |
701 |
|
if (loadLib(libpath[i] + filename) != 0) |
702 |
|
return; |
703 |
|
|
704 |
|
throw new UnsatisfiedLinkError("Could not find library " + libname + "."); |
705 |
} |
} |
706 |
|
|
707 |
/** |
/** |