8344086: Remove security manager dependency in FFM
Reviewed-by: mcimadamore, rriggs, jvernee
This commit is contained in:
parent
916694f2c1
commit
bd3fec3075
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,6 +23,7 @@
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
package jdk.internal.foreign;
|
||||
|
||||
import jdk.internal.foreign.abi.fallback.FallbackLinker;
|
||||
@ -31,7 +32,6 @@ import jdk.internal.util.OperatingSystem;
|
||||
import jdk.internal.util.StaticProperty;
|
||||
|
||||
import static java.lang.foreign.ValueLayout.ADDRESS;
|
||||
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
|
||||
|
||||
public enum CABI {
|
||||
SYS_V,
|
||||
@ -50,7 +50,7 @@ public enum CABI {
|
||||
private static final CABI CURRENT = computeCurrent();
|
||||
|
||||
private static CABI computeCurrent() {
|
||||
String abi = privilegedGetProperty("jdk.internal.foreign.CABI");
|
||||
String abi = System.getProperty("jdk.internal.foreign.CABI");
|
||||
if (abi != null) {
|
||||
return CABI.valueOf(abi);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import jdk.internal.misc.ScopedMemoryAccess;
|
||||
import jdk.internal.util.Architecture;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
import sun.security.action.GetIntegerAction;
|
||||
|
||||
import java.lang.foreign.MemorySegment;
|
||||
|
||||
@ -293,7 +292,7 @@ public final class SegmentBulkOperations {
|
||||
|
||||
// The returned value is in the interval [0, 2^30]
|
||||
static int powerOfPropertyOr(String name, int defaultPower) {
|
||||
final int power = GetIntegerAction.privilegedGetProperty(PROPERTY_PATH + name, defaultPower);
|
||||
final int power = Integer.getInteger(PROPERTY_PATH + name, defaultPower);
|
||||
return 1 << Math.clamp(power, 0, Integer.SIZE - 2);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -29,7 +29,6 @@ import jdk.internal.access.JavaLangAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.foreign.abi.SharedUtils;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import java.lang.foreign.MemorySegment;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -29,14 +29,12 @@ import java.lang.foreign.*;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import jdk.internal.loader.NativeLibrary;
|
||||
import jdk.internal.loader.RawNativeLibraries;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import static java.lang.foreign.ValueLayout.ADDRESS;
|
||||
|
||||
@ -60,7 +58,7 @@ public final class SystemLookup implements SymbolLookup {
|
||||
|
||||
private static SymbolLookup makeSystemLookup() {
|
||||
try {
|
||||
if (Utils.IS_WINDOWS) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
return makeWindowsLookup();
|
||||
} else {
|
||||
return libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
|
||||
@ -74,24 +72,12 @@ public final class SystemLookup implements SymbolLookup {
|
||||
}
|
||||
|
||||
private static SymbolLookup makeWindowsLookup() {
|
||||
@SuppressWarnings("removal")
|
||||
String systemRoot = AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public String run() {
|
||||
return System.getenv("SystemRoot");
|
||||
}
|
||||
});
|
||||
String systemRoot = System.getenv("SystemRoot");
|
||||
Path system32 = Path.of(systemRoot, "System32");
|
||||
Path ucrtbase = system32.resolve("ucrtbase.dll");
|
||||
Path msvcrt = system32.resolve("msvcrt.dll");
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
boolean useUCRT = AccessController.doPrivileged(new PrivilegedAction<>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
return Files.exists(ucrtbase);
|
||||
}
|
||||
});
|
||||
boolean useUCRT = Files.exists(ucrtbase);
|
||||
Path stdLib = useUCRT ? ucrtbase : msvcrt;
|
||||
SymbolLookup lookup = libLookup(libs -> libs.load(stdLib));
|
||||
|
||||
@ -139,8 +125,8 @@ public final class SystemLookup implements SymbolLookup {
|
||||
* Returns the path of the given library name from JDK
|
||||
*/
|
||||
private static Path jdkLibraryPath(String name) {
|
||||
Path javahome = Path.of(GetPropertyAction.privilegedGetProperty("java.home"));
|
||||
String lib = Utils.IS_WINDOWS ? "bin" : "lib";
|
||||
Path javahome = Path.of(System.getProperty("java.home"));
|
||||
String lib = OperatingSystem.isWindows() ? "bin" : "lib";
|
||||
String libname = System.mapLibraryName(name);
|
||||
return javahome.resolve(lib).resolve(libname);
|
||||
}
|
||||
|
@ -48,15 +48,11 @@ import jdk.internal.misc.Unsafe;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
import sun.invoke.util.Wrapper;
|
||||
|
||||
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
|
||||
|
||||
/**
|
||||
* This class contains misc helper functions to support creation of memory segments.
|
||||
*/
|
||||
public final class Utils {
|
||||
|
||||
public static final boolean IS_WINDOWS = privilegedGetProperty("os.name").startsWith("Windows");
|
||||
|
||||
// Suppresses default constructor, ensuring non-instantiability.
|
||||
private Utils() {}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.foreign.abi;
|
||||
|
||||
import java.lang.classfile.Annotation;
|
||||
@ -48,9 +49,6 @@ import jdk.internal.foreign.abi.Binding.ShiftRight;
|
||||
import jdk.internal.foreign.abi.Binding.VMLoad;
|
||||
import jdk.internal.foreign.abi.Binding.VMStore;
|
||||
import jdk.internal.vm.annotation.ForceInline;
|
||||
import sun.security.action.GetBooleanAction;
|
||||
import sun.security.action.GetIntegerAction;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
|
||||
@ -78,11 +76,11 @@ import static jdk.internal.constant.ConstantUtils.*;
|
||||
|
||||
public class BindingSpecializer {
|
||||
private static final String DUMP_CLASSES_DIR
|
||||
= GetPropertyAction.privilegedGetProperty("jdk.internal.foreign.abi.Specializer.DUMP_CLASSES_DIR");
|
||||
= System.getProperty("jdk.internal.foreign.abi.Specializer.DUMP_CLASSES_DIR");
|
||||
private static final boolean PERFORM_VERIFICATION
|
||||
= GetBooleanAction.privilegedGetProperty("jdk.internal.foreign.abi.Specializer.PERFORM_VERIFICATION");
|
||||
= Boolean.getBoolean("jdk.internal.foreign.abi.Specializer.PERFORM_VERIFICATION");
|
||||
private static final int SCOPE_DEDUP_DEPTH
|
||||
= GetIntegerAction.privilegedGetProperty("jdk.internal.foreign.abi.Specializer.SCOPE_DEDUP_DEPTH", 2);
|
||||
= Integer.getInteger("jdk.internal.foreign.abi.Specializer.SCOPE_DEDUP_DEPTH", 2);
|
||||
|
||||
// Bunch of helper constants
|
||||
private static final int CLASSFILE_VERSION = ClassFileFormatVersion.latest().major();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,6 +22,7 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.foreign.abi;
|
||||
|
||||
import jdk.internal.foreign.Utils;
|
||||
@ -38,7 +39,6 @@ import jdk.internal.foreign.abi.Binding.ShiftLeft;
|
||||
import jdk.internal.foreign.abi.Binding.ShiftRight;
|
||||
import jdk.internal.foreign.abi.Binding.VMLoad;
|
||||
import jdk.internal.foreign.abi.Binding.VMStore;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import java.lang.foreign.FunctionDescriptor;
|
||||
import java.lang.foreign.MemoryLayout;
|
||||
@ -54,7 +54,7 @@ import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class CallingSequenceBuilder {
|
||||
private static final boolean VERIFY_BINDINGS = Boolean.parseBoolean(
|
||||
GetPropertyAction.privilegedGetProperty("java.lang.foreign.VERIFY_BINDINGS", "true"));
|
||||
System.getProperty("java.lang.foreign.VERIFY_BINDINGS", "true"));
|
||||
|
||||
private final ABIDescriptor abi;
|
||||
private final LinkerOptions linkerOptions;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,9 +22,10 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.foreign.abi;
|
||||
|
||||
import jdk.internal.foreign.Utils;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.lang.foreign.MemoryLayout;
|
||||
import java.lang.foreign.StructLayout;
|
||||
@ -35,8 +36,8 @@ import java.util.stream.Stream;
|
||||
import static java.lang.foreign.ValueLayout.JAVA_INT;
|
||||
|
||||
public enum CapturableState {
|
||||
GET_LAST_ERROR ("GetLastError", JAVA_INT, 1 << 0, Utils.IS_WINDOWS),
|
||||
WSA_GET_LAST_ERROR("WSAGetLastError", JAVA_INT, 1 << 1, Utils.IS_WINDOWS),
|
||||
GET_LAST_ERROR ("GetLastError", JAVA_INT, 1 << 0, OperatingSystem.isWindows()),
|
||||
WSA_GET_LAST_ERROR("WSAGetLastError", JAVA_INT, 1 << 1, OperatingSystem.isWindows()),
|
||||
ERRNO ("errno", JAVA_INT, 1 << 2, true);
|
||||
|
||||
public static final StructLayout LAYOUT = MemoryLayout.structLayout(
|
||||
|
@ -22,12 +22,12 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package jdk.internal.foreign.abi;
|
||||
|
||||
import jdk.internal.access.JavaLangInvokeAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.invoke.MhUtil;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import java.lang.foreign.AddressLayout;
|
||||
import java.lang.foreign.Arena;
|
||||
@ -52,7 +52,7 @@ import static java.lang.invoke.MethodType.methodType;
|
||||
|
||||
public class DowncallLinker {
|
||||
private static final boolean USE_SPEC = Boolean.parseBoolean(
|
||||
GetPropertyAction.privilegedGetProperty("jdk.internal.foreign.DowncallLinker.USE_SPEC", "true"));
|
||||
System.getProperty("jdk.internal.foreign.DowncallLinker.USE_SPEC", "true"));
|
||||
|
||||
private static final JavaLangInvokeAccess JLIA = SharedSecrets.getJavaLangInvokeAccess();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,7 +26,6 @@
|
||||
package jdk.internal.foreign.abi;
|
||||
|
||||
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
import java.lang.foreign.Arena;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
@ -43,13 +42,12 @@ import static java.lang.invoke.MethodHandles.exactInvoker;
|
||||
import static java.lang.invoke.MethodHandles.insertArguments;
|
||||
import static java.lang.invoke.MethodHandles.lookup;
|
||||
import static java.lang.invoke.MethodType.methodType;
|
||||
import static sun.security.action.GetBooleanAction.privilegedGetProperty;
|
||||
|
||||
public class UpcallLinker {
|
||||
private static final boolean DEBUG =
|
||||
privilegedGetProperty("jdk.internal.foreign.UpcallLinker.DEBUG");
|
||||
Boolean.getBoolean("jdk.internal.foreign.UpcallLinker.DEBUG");
|
||||
private static final boolean USE_SPEC = Boolean.parseBoolean(
|
||||
GetPropertyAction.privilegedGetProperty("jdk.internal.foreign.UpcallLinker.USE_SPEC", "true"));
|
||||
System.getProperty("jdk.internal.foreign.UpcallLinker.USE_SPEC", "true"));
|
||||
|
||||
private static final MethodHandle MH_invokeInterpBindings;
|
||||
|
||||
|
@ -36,23 +36,18 @@ final class LibFallback {
|
||||
|
||||
static final boolean SUPPORTED = tryLoadLibrary();
|
||||
|
||||
@SuppressWarnings({"removal", "restricted"})
|
||||
@SuppressWarnings({"restricted"})
|
||||
private static boolean tryLoadLibrary() {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<>() {
|
||||
public Boolean run() {
|
||||
try {
|
||||
System.loadLibrary("fallbackLinker");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
return false;
|
||||
}
|
||||
if (!init()) {
|
||||
// library failed to initialize. Do not silently mark as unsupported
|
||||
throw new ExceptionInInitializerError("Fallback library failed to initialize");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
try {
|
||||
System.loadLibrary("fallbackLinker");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
return false;
|
||||
}
|
||||
if (!init()) {
|
||||
// library failed to initialize. Do not silently mark as unsupported
|
||||
throw new ExceptionInInitializerError("Fallback library failed to initialize");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int defaultABI() { return NativeConstants.DEFAULT_ABI; }
|
||||
|
Loading…
Reference in New Issue
Block a user