8344086: Remove security manager dependency in FFM

Reviewed-by: mcimadamore, rriggs, jvernee
This commit is contained in:
Per Minborg 2024-11-13 16:42:48 +00:00
parent 916694f2c1
commit bd3fec3075
11 changed files with 39 additions and 67 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,7 @@
* questions. * questions.
* *
*/ */
package jdk.internal.foreign; package jdk.internal.foreign;
import jdk.internal.foreign.abi.fallback.FallbackLinker; import jdk.internal.foreign.abi.fallback.FallbackLinker;
@ -31,7 +32,6 @@ import jdk.internal.util.OperatingSystem;
import jdk.internal.util.StaticProperty; import jdk.internal.util.StaticProperty;
import static java.lang.foreign.ValueLayout.ADDRESS; import static java.lang.foreign.ValueLayout.ADDRESS;
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
public enum CABI { public enum CABI {
SYS_V, SYS_V,
@ -50,7 +50,7 @@ public enum CABI {
private static final CABI CURRENT = computeCurrent(); private static final CABI CURRENT = computeCurrent();
private static CABI computeCurrent() { private static CABI computeCurrent() {
String abi = privilegedGetProperty("jdk.internal.foreign.CABI"); String abi = System.getProperty("jdk.internal.foreign.CABI");
if (abi != null) { if (abi != null) {
return CABI.valueOf(abi); return CABI.valueOf(abi);
} }

View File

@ -29,7 +29,6 @@ import jdk.internal.misc.ScopedMemoryAccess;
import jdk.internal.util.Architecture; import jdk.internal.util.Architecture;
import jdk.internal.util.ArraysSupport; import jdk.internal.util.ArraysSupport;
import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.ForceInline;
import sun.security.action.GetIntegerAction;
import java.lang.foreign.MemorySegment; import java.lang.foreign.MemorySegment;
@ -293,7 +292,7 @@ public final class SegmentBulkOperations {
// The returned value is in the interval [0, 2^30] // The returned value is in the interval [0, 2^30]
static int powerOfPropertyOr(String name, int defaultPower) { 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); return 1 << Math.clamp(power, 0, Integer.SIZE - 2);
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.access.SharedSecrets;
import jdk.internal.foreign.abi.SharedUtils; import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.util.ArraysSupport; import jdk.internal.util.ArraysSupport;
import sun.security.action.GetPropertyAction;
import java.lang.foreign.MemorySegment; import java.lang.foreign.MemorySegment;
import java.nio.charset.Charset; import java.nio.charset.Charset;

View File

@ -29,14 +29,12 @@ import java.lang.foreign.*;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import jdk.internal.loader.NativeLibrary; import jdk.internal.loader.NativeLibrary;
import jdk.internal.loader.RawNativeLibraries; import jdk.internal.loader.RawNativeLibraries;
import sun.security.action.GetPropertyAction; import jdk.internal.util.OperatingSystem;
import static java.lang.foreign.ValueLayout.ADDRESS; import static java.lang.foreign.ValueLayout.ADDRESS;
@ -60,7 +58,7 @@ public final class SystemLookup implements SymbolLookup {
private static SymbolLookup makeSystemLookup() { private static SymbolLookup makeSystemLookup() {
try { try {
if (Utils.IS_WINDOWS) { if (OperatingSystem.isWindows()) {
return makeWindowsLookup(); return makeWindowsLookup();
} else { } else {
return libLookup(libs -> libs.load(jdkLibraryPath("syslookup"))); return libLookup(libs -> libs.load(jdkLibraryPath("syslookup")));
@ -74,24 +72,12 @@ public final class SystemLookup implements SymbolLookup {
} }
private static SymbolLookup makeWindowsLookup() { private static SymbolLookup makeWindowsLookup() {
@SuppressWarnings("removal") String systemRoot = System.getenv("SystemRoot");
String systemRoot = AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public String run() {
return System.getenv("SystemRoot");
}
});
Path system32 = Path.of(systemRoot, "System32"); Path system32 = Path.of(systemRoot, "System32");
Path ucrtbase = system32.resolve("ucrtbase.dll"); Path ucrtbase = system32.resolve("ucrtbase.dll");
Path msvcrt = system32.resolve("msvcrt.dll"); Path msvcrt = system32.resolve("msvcrt.dll");
@SuppressWarnings("removal") boolean useUCRT = Files.exists(ucrtbase);
boolean useUCRT = AccessController.doPrivileged(new PrivilegedAction<>() {
@Override
public Boolean run() {
return Files.exists(ucrtbase);
}
});
Path stdLib = useUCRT ? ucrtbase : msvcrt; Path stdLib = useUCRT ? ucrtbase : msvcrt;
SymbolLookup lookup = libLookup(libs -> libs.load(stdLib)); 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 * Returns the path of the given library name from JDK
*/ */
private static Path jdkLibraryPath(String name) { private static Path jdkLibraryPath(String name) {
Path javahome = Path.of(GetPropertyAction.privilegedGetProperty("java.home")); Path javahome = Path.of(System.getProperty("java.home"));
String lib = Utils.IS_WINDOWS ? "bin" : "lib"; String lib = OperatingSystem.isWindows() ? "bin" : "lib";
String libname = System.mapLibraryName(name); String libname = System.mapLibraryName(name);
return javahome.resolve(lib).resolve(libname); return javahome.resolve(lib).resolve(libname);
} }

View File

@ -48,15 +48,11 @@ import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.ForceInline;
import sun.invoke.util.Wrapper; import sun.invoke.util.Wrapper;
import static sun.security.action.GetPropertyAction.privilegedGetProperty;
/** /**
* This class contains misc helper functions to support creation of memory segments. * This class contains misc helper functions to support creation of memory segments.
*/ */
public final class Utils { public final class Utils {
public static final boolean IS_WINDOWS = privilegedGetProperty("os.name").startsWith("Windows");
// Suppresses default constructor, ensuring non-instantiability. // Suppresses default constructor, ensuring non-instantiability.
private Utils() {} private Utils() {}

View File

@ -22,6 +22,7 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package jdk.internal.foreign.abi; package jdk.internal.foreign.abi;
import java.lang.classfile.Annotation; 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.VMLoad;
import jdk.internal.foreign.abi.Binding.VMStore; import jdk.internal.foreign.abi.Binding.VMStore;
import jdk.internal.vm.annotation.ForceInline; 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.io.IOException;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute; import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
@ -78,11 +76,11 @@ import static jdk.internal.constant.ConstantUtils.*;
public class BindingSpecializer { public class BindingSpecializer {
private static final String DUMP_CLASSES_DIR 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 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 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 // Bunch of helper constants
private static final int CLASSFILE_VERSION = ClassFileFormatVersion.latest().major(); private static final int CLASSFILE_VERSION = ClassFileFormatVersion.latest().major();

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package jdk.internal.foreign.abi; package jdk.internal.foreign.abi;
import jdk.internal.foreign.Utils; 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.ShiftRight;
import jdk.internal.foreign.abi.Binding.VMLoad; import jdk.internal.foreign.abi.Binding.VMLoad;
import jdk.internal.foreign.abi.Binding.VMStore; import jdk.internal.foreign.abi.Binding.VMStore;
import sun.security.action.GetPropertyAction;
import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemoryLayout;
@ -54,7 +54,7 @@ import static java.lang.invoke.MethodType.methodType;
public class CallingSequenceBuilder { public class CallingSequenceBuilder {
private static final boolean VERIFY_BINDINGS = Boolean.parseBoolean( 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 ABIDescriptor abi;
private final LinkerOptions linkerOptions; private final LinkerOptions linkerOptions;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package jdk.internal.foreign.abi; package jdk.internal.foreign.abi;
import jdk.internal.foreign.Utils; import jdk.internal.util.OperatingSystem;
import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemoryLayout;
import java.lang.foreign.StructLayout; import java.lang.foreign.StructLayout;
@ -35,8 +36,8 @@ import java.util.stream.Stream;
import static java.lang.foreign.ValueLayout.JAVA_INT; import static java.lang.foreign.ValueLayout.JAVA_INT;
public enum CapturableState { public enum CapturableState {
GET_LAST_ERROR ("GetLastError", JAVA_INT, 1 << 0, Utils.IS_WINDOWS), GET_LAST_ERROR ("GetLastError", JAVA_INT, 1 << 0, OperatingSystem.isWindows()),
WSA_GET_LAST_ERROR("WSAGetLastError", JAVA_INT, 1 << 1, Utils.IS_WINDOWS), WSA_GET_LAST_ERROR("WSAGetLastError", JAVA_INT, 1 << 1, OperatingSystem.isWindows()),
ERRNO ("errno", JAVA_INT, 1 << 2, true); ERRNO ("errno", JAVA_INT, 1 << 2, true);
public static final StructLayout LAYOUT = MemoryLayout.structLayout( public static final StructLayout LAYOUT = MemoryLayout.structLayout(

View File

@ -22,12 +22,12 @@
* or visit www.oracle.com if you need additional information or have any * or visit www.oracle.com if you need additional information or have any
* questions. * questions.
*/ */
package jdk.internal.foreign.abi; package jdk.internal.foreign.abi;
import jdk.internal.access.JavaLangInvokeAccess; import jdk.internal.access.JavaLangInvokeAccess;
import jdk.internal.access.SharedSecrets; import jdk.internal.access.SharedSecrets;
import jdk.internal.invoke.MhUtil; import jdk.internal.invoke.MhUtil;
import sun.security.action.GetPropertyAction;
import java.lang.foreign.AddressLayout; import java.lang.foreign.AddressLayout;
import java.lang.foreign.Arena; import java.lang.foreign.Arena;
@ -52,7 +52,7 @@ import static java.lang.invoke.MethodType.methodType;
public class DowncallLinker { public class DowncallLinker {
private static final boolean USE_SPEC = Boolean.parseBoolean( 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(); private static final JavaLangInvokeAccess JLIA = SharedSecrets.getJavaLangInvokeAccess();

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package jdk.internal.foreign.abi; package jdk.internal.foreign.abi;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory; import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import sun.security.action.GetPropertyAction;
import java.lang.foreign.Arena; import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment; 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.insertArguments;
import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.lookup;
import static java.lang.invoke.MethodType.methodType; import static java.lang.invoke.MethodType.methodType;
import static sun.security.action.GetBooleanAction.privilegedGetProperty;
public class UpcallLinker { public class UpcallLinker {
private static final boolean DEBUG = 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( 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; private static final MethodHandle MH_invokeInterpBindings;

View File

@ -36,23 +36,18 @@ final class LibFallback {
static final boolean SUPPORTED = tryLoadLibrary(); static final boolean SUPPORTED = tryLoadLibrary();
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings({"restricted"})
private static boolean tryLoadLibrary() { private static boolean tryLoadLibrary() {
return java.security.AccessController.doPrivileged( try {
new java.security.PrivilegedAction<>() { System.loadLibrary("fallbackLinker");
public Boolean run() { } catch (UnsatisfiedLinkError ule) {
try { return false;
System.loadLibrary("fallbackLinker"); }
} catch (UnsatisfiedLinkError ule) { if (!init()) {
return false; // library failed to initialize. Do not silently mark as unsupported
} throw new ExceptionInInitializerError("Fallback library failed to initialize");
if (!init()) { }
// library failed to initialize. Do not silently mark as unsupported return true;
throw new ExceptionInInitializerError("Fallback library failed to initialize");
}
return true;
}
});
} }
static int defaultABI() { return NativeConstants.DEFAULT_ABI; } static int defaultABI() { return NativeConstants.DEFAULT_ABI; }