mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +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
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
|
@ -36,6 +36,7 @@ import java.util.Optional;
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.javac.Restricted;
|
||||
import jdk.internal.reflect.CallerSensitive;
|
||||
import jdk.internal.reflect.Reflection;
|
||||
|
||||
|
@ -828,14 +829,19 @@ public class Runtime {
|
|||
* 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#getRuntime()
|
||||
* @see java.lang.SecurityException
|
||||
* @see java.lang.SecurityManager#checkLink(java.lang.String)
|
||||
*/
|
||||
@CallerSensitive
|
||||
@Restricted
|
||||
public void load(String filename) {
|
||||
load0(Reflection.getCallerClass(), filename);
|
||||
Class<?> caller = Reflection.getCallerClass();
|
||||
Reflection.ensureNativeAccess(caller, Runtime.class, "load", false);
|
||||
load0(caller, filename);
|
||||
}
|
||||
|
||||
void load0(Class<?> fromClass, String filename) {
|
||||
|
@ -894,13 +900,18 @@ public class Runtime {
|
|||
* 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.SecurityException
|
||||
* @see java.lang.SecurityManager#checkLink(java.lang.String)
|
||||
*/
|
||||
@CallerSensitive
|
||||
@Restricted
|
||||
public void loadLibrary(String libname) {
|
||||
loadLibrary0(Reflection.getCallerClass(), libname);
|
||||
Class<?> caller = Reflection.getCallerClass();
|
||||
Reflection.ensureNativeAccess(caller, Runtime.class, "loadLibrary", false);
|
||||
loadLibrary0(caller, libname);
|
||||
}
|
||||
|
||||
void loadLibrary0(Class<?> fromClass, String libname) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue