Skip to content

Commit

Permalink
8314260: Unable to load system libraries on Windows when using a Secu…
Browse files Browse the repository at this point in the history
…rityManager

Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Reviewed-by: jvernee
  • Loading branch information
minborg and JornVernee committed Sep 7, 2023
1 parent 726c9c9 commit b408a82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/java.base/share/classes/jdk/internal/foreign/SystemLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
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;
Expand Down Expand Up @@ -72,11 +74,24 @@ private static SymbolLookup makeSystemLookup() {
}

private static SymbolLookup makeWindowsLookup() {
Path system32 = Path.of(System.getenv("SystemRoot"), "System32");
@SuppressWarnings("removal")
String systemRoot = AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return System.getenv("SystemRoot");
}
});
Path system32 = Path.of(systemRoot, "System32");
Path ucrtbase = system32.resolve("ucrtbase.dll");
Path msvcrt = system32.resolve("msvcrt.dll");

boolean useUCRT = Files.exists(ucrtbase);
@SuppressWarnings("removal")
boolean useUCRT = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return Files.exists(ucrtbase);
}
});
Path stdLib = useUCRT ? ucrtbase : msvcrt;
SymbolLookup lookup = libLookup(libs -> libs.load(stdLib));

Expand Down
2 changes: 2 additions & 0 deletions test/jdk/java/foreign/TestLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* @requires jdk.foreign.linker != "UNSUPPORTED"
* @modules java.base/jdk.internal.foreign
* @run testng TestLinker
* @run testng/othervm/policy=security.policy
* -Djava.security.manager=default TestLinker
*/

import jdk.internal.foreign.CABI;
Expand Down
7 changes: 7 additions & 0 deletions test/jdk/java/foreign/security.policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
grant codeBase "file:${test.classes}/*" {
// Permissions needed to run the test
permission java.util.PropertyPermission "os.name", "read";
permission java.util.PropertyPermission "NativeTestHelper.DEFAULT_RANDOM.seed", "read";
permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.foreign";
};

1 comment on commit b408a82

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.