From 2e5990a6b0c35934b99a0a776762fab8f643599b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xerxes=20R=C3=A5nby?= Date: Sun, 26 Oct 2014 21:46:09 +0100 Subject: [PATCH] OpenJDK: Implement JVM_FindClassFromCaller 8015256: Better class accessibility Summary: Improve protection domain check in forName() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xerxes RĂ„nby --- openjdk.ld | 1 + src/classpath-openjdk.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/openjdk.ld b/openjdk.ld index ac767806e5..3c17a160b2 100644 --- a/openjdk.ld +++ b/openjdk.ld @@ -88,6 +88,7 @@ SUNWprivate_1.1 { JVM_EnableCompiler; JVM_Exit; JVM_FillInStackTrace; + JVM_FindClassFromCaller; JVM_FindClassFromClass; JVM_FindClassFromClassLoader; JVM_FindClassFromBootLoader; diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 82f24173a1..6247eda6ca 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -4237,6 +4237,49 @@ extern "C" AVIAN_EXPORT void JNICALL run(t, jvmResolveClass, arguments); } +uint64_t jvmFindClassFromCaller(Thread* t, uintptr_t* arguments) +{ + const char* name = reinterpret_cast(arguments[0]); + jboolean init = arguments[1]; + jobject loader = reinterpret_cast(arguments[2]); + // jclass caller = reinterpret_cast(arguments[3]); + + /* XXX The caller's protection domain should be used during + the resolveClass but there is no specification or + unit-test in OpenJDK documenting the desired effect */ + + GcClass* c = resolveClass( + t, + loader ? cast(t, *loader) : roots(t)->bootLoader(), + name, + true, + static_cast(GcClassNotFoundException::Type)); + + if (init) { + PROTECT(t, c); + + initClass(t, c); + } + + return reinterpret_cast(makeLocalReference(t, getJClass(t, c))); +} + +extern "C" AVIAN_EXPORT jclass JNICALL + EXPORT(JVM_FindClassFromCaller)(Thread* t, + const char* name, + jboolean init, + jobject loader, + jclass caller) +{ + uintptr_t arguments[] = {reinterpret_cast(name), + init, + reinterpret_cast(loader), + reinterpret_cast(caller)}; + + return reinterpret_cast( + run(t, jvmFindClassFromCaller, arguments)); +} + uint64_t jvmFindClassFromClassLoader(Thread* t, uintptr_t* arguments) { const char* name = reinterpret_cast(arguments[0]);