< prev index next >

src/java.base/share/classes/java/nicl/NativeLibrary.java

Print this page

        

*** 31,40 **** --- 31,41 ---- import jdk.internal.nicl.types.LayoutTypeImpl; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; import java.nicl.types.LayoutType; + import java.util.Objects; public final class NativeLibrary { private static final Errno ERRNO = Errno.platformHasErrno() ? new Errno() : null; // don't create
*** 122,149 **** public static MethodHandle lookupNativeMethod(Library lib, String symbolName, MethodType methodType, boolean isVarArgs) throws NoSuchMethodException, IllegalAccessException { return lookupNativeMethod(new Library[] { lib }, symbolName, methodType, isVarArgs); } ! public static Library loadLibrary(String name) { SecurityManager security = System.getSecurityManager(); if (security != null) { ! security.checkLink(name); } ! return NativeLibraryImpl.loadLibrary(name); } ! public static Library loadLibraryFile(String name) { SecurityManager security = System.getSecurityManager(); if (security != null) { ! security.checkLink(name); } ! if (!(new File(name).isAbsolute())) { throw new UnsatisfiedLinkError( ! "Expecting an absolute path of the library: " + name); } ! return NativeLibraryImpl.loadLibraryFile(name); } public static Library getDefaultLibrary() { SecurityManager security = System.getSecurityManager(); if (security != null) { --- 123,194 ---- public static MethodHandle lookupNativeMethod(Library lib, String symbolName, MethodType methodType, boolean isVarArgs) throws NoSuchMethodException, IllegalAccessException { return lookupNativeMethod(new Library[] { lib }, symbolName, methodType, isVarArgs); } ! /** ! * Loads the native library specified by the <code>libname</code> ! * argument. The <code>libname</code> argument must not contain any platform ! * specific prefix, file extension or path. ! * ! * Otherwise, the libname argument is loaded from a system library ! * location and mapped to a native library image in an implementation- ! * dependent manner. ! * <p> ! * ! * @param libname the name of the library. ! * @exception SecurityException if a security manager exists and its ! * <code>checkLink</code> method doesn't allow ! * loading of the specified dynamic library ! * @exception UnsatisfiedLinkError if either the libname argument ! * contains a file path, the native library is not statically ! * linked with the VM, or the library cannot be mapped to a ! * native library image by the host system. ! * @exception NullPointerException if <code>libname</code> is ! * <code>null</code> ! * @see java.lang.SecurityManager#checkLink(java.lang.String) ! */ ! public static Library loadLibrary(String filename) { ! Objects.requireNonNull(filename); SecurityManager security = System.getSecurityManager(); if (security != null) { ! security.checkLink(filename); ! } ! if (filename.indexOf(File.separatorChar) != -1) { ! throw new UnsatisfiedLinkError( ! "Directory separator should not appear in library name: " + filename); } ! return NativeLibraryImpl.loadLibrary(filename); } ! /** ! * Loads the native library specified by the filename argument. The filename ! * argument must be an absolute path name. ! * ! * @param filename the file to load. ! * @exception SecurityException if a security manager exists and its ! * <code>checkLink</code> method doesn't allow ! * loading of the specified dynamic library ! * @exception UnsatisfiedLinkError if either the filename is not an ! * absolute path name, the native library is not statically ! * linked with the VM, or the library cannot be mapped to ! * a native library image by the host system. ! * @exception NullPointerException if <code>filename</code> is ! * <code>null</code> ! * @see java.lang.SecurityManager#checkLink(java.lang.String) ! */ ! public static Library load(String filename) { ! Objects.requireNonNull(filename); SecurityManager security = System.getSecurityManager(); if (security != null) { ! security.checkLink(filename); } ! if (!(new File(filename).isAbsolute())) { throw new UnsatisfiedLinkError( ! "Expecting an absolute path of the library: " + filename); } ! return NativeLibraryImpl.load(filename); } public static Library getDefaultLibrary() { SecurityManager security = System.getSecurityManager(); if (security != null) {
< prev index next >