mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8331671: Implement JEP 472: Prepare to Restrict the Use of JNI
Reviewed-by: jpai, prr, ihse, kcr, alanb
This commit is contained in:
parent
ce83f6af64
commit
20d8f58c92
107 changed files with 551 additions and 182 deletions
|
@ -69,6 +69,7 @@ import java.util.function.Supplier;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.internal.javac.Restricted;
|
||||
import jdk.internal.logger.LoggerFinderLoader.TemporaryLoggerFinder;
|
||||
import jdk.internal.misc.Blocker;
|
||||
import jdk.internal.misc.CarrierThreadLocal;
|
||||
|
@ -355,7 +356,7 @@ public final class System {
|
|||
= Collections.synchronizedMap(new WeakHashMap<>());
|
||||
}
|
||||
|
||||
private static URL codeSource(Class<?> clazz) {
|
||||
static URL codeSource(Class<?> clazz) {
|
||||
PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain;
|
||||
@SuppressWarnings("removal")
|
||||
CodeSource cs = AccessController.doPrivileged(pa).getCodeSource();
|
||||
|
@ -2017,14 +2018,19 @@ public final class System {
|
|||
* linked with the VM, or the library cannot be mapped to
|
||||
* a native library image by the host system.
|
||||
* @throws NullPointerException if {@code filename} is {@code null}
|
||||
* @throws IllegalCallerException if the caller is in a module that
|
||||
* does not have native access enabled.
|
||||
*
|
||||
* @spec jni/index.html Java Native Interface Specification
|
||||
* @see java.lang.Runtime#load(java.lang.String)
|
||||
* @see java.lang.SecurityManager#checkLink(java.lang.String)
|
||||
*/
|
||||
@CallerSensitive
|
||||
@Restricted
|
||||
public static void load(String filename) {
|
||||
Runtime.getRuntime().load0(Reflection.getCallerClass(), filename);
|
||||
Class<?> caller = Reflection.getCallerClass();
|
||||
Reflection.ensureNativeAccess(caller, System.class, "load", false);
|
||||
Runtime.getRuntime().load0(caller, filename);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2055,14 +2061,19 @@ public final class System {
|
|||
* linked with the VM, or the library cannot be mapped to a
|
||||
* native library image by the host system.
|
||||
* @throws NullPointerException if {@code libname} is {@code null}
|
||||
* @throws IllegalCallerException if the caller is in a module that
|
||||
* does not have native access enabled.
|
||||
*
|
||||
* @spec jni/index.html Java Native Interface Specification
|
||||
* @see java.lang.Runtime#loadLibrary(java.lang.String)
|
||||
* @see java.lang.SecurityManager#checkLink(java.lang.String)
|
||||
*/
|
||||
@CallerSensitive
|
||||
@Restricted
|
||||
public static void loadLibrary(String libname) {
|
||||
Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname);
|
||||
Class<?> caller = Reflection.getCallerClass();
|
||||
Reflection.ensureNativeAccess(caller, System.class, "loadLibrary", false);
|
||||
Runtime.getRuntime().loadLibrary0(caller, libname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2539,8 +2550,8 @@ public final class System {
|
|||
public void addEnableNativeAccessToAllUnnamed() {
|
||||
Module.implAddEnableNativeAccessToAllUnnamed();
|
||||
}
|
||||
public void ensureNativeAccess(Module m, Class<?> owner, String methodName, Class<?> currentClass) {
|
||||
m.ensureNativeAccess(owner, methodName, currentClass);
|
||||
public void ensureNativeAccess(Module m, Class<?> owner, String methodName, Class<?> currentClass, boolean jni) {
|
||||
m.ensureNativeAccess(owner, methodName, currentClass, jni);
|
||||
}
|
||||
public ServicesCatalog getServicesCatalog(ModuleLayer layer) {
|
||||
return layer.getServicesCatalog();
|
||||
|
@ -2645,7 +2656,7 @@ public final class System {
|
|||
|
||||
@Override
|
||||
public long findNative(ClassLoader loader, String entry) {
|
||||
return ClassLoader.findNative(loader, entry);
|
||||
return ClassLoader.findNativeInternal(loader, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue