diff options
author | Alex Light <allight@google.com> | 2021-01-12 13:57:42 +0000 |
---|---|---|
committer | Treehugger Robot <treehugger-gerrit@google.com> | 2021-01-13 14:05:16 +0000 |
commit | 1a0e292b9bb60be76a666ca86046db1492a345d4 (patch) | |
tree | 5ba5d147ecb1733073e12ca040366aaa893d9d2f /openjdkjvmti | |
parent | f8567b535dcc4618f0ee76e5b8716d296681197b (diff) |
Revert^2 "Add disable/get/set_hidden_api_enforcement_policy extensions"
This reverts commit 46d6fc0e16d65468aa259fadf27ddfeef72987b7.
The test, 2038, is incompatible with redefine stress due to class
redefinition disabling most hidden-api checks. This adds the
appropriate skips to knownfailures.json.
Reason for revert: Add 2038 to redefine-stress knownfailures.json
Test: ./test.py --host --redefine-host
Bug: 175329755
Change-Id: I6c8f0f6fc468db85368ecc9fbb2372677b529383
Diffstat (limited to 'openjdkjvmti')
-rw-r--r-- | openjdkjvmti/ti_class.cc | 35 | ||||
-rw-r--r-- | openjdkjvmti/ti_class.h | 4 | ||||
-rw-r--r-- | openjdkjvmti/ti_extension.cc | 52 |
3 files changed, 91 insertions, 0 deletions
diff --git a/openjdkjvmti/ti_class.cc b/openjdkjvmti/ti_class.cc index c22f38f576..924a0d84d7 100644 --- a/openjdkjvmti/ti_class.cc +++ b/openjdkjvmti/ti_class.cc @@ -56,6 +56,7 @@ #include "gc/heap.h" #include "gc_root.h" #include "handle.h" +#include "hidden_api.h" #include "jni/jni_env_ext-inl.h" #include "jni/jni_internal.h" #include "mirror/array-alloc-inl.h" @@ -1137,4 +1138,38 @@ jvmtiError ClassUtil::GetSourceDebugExtension(jvmtiEnv* env, return OK; } +jvmtiError ClassUtil::DisableHiddenApiEnforcementPolicy(jvmtiEnv* env) { + return SetHiddenApiEnforcementPolicy( + env, static_cast<jint>(art::hiddenapi::EnforcementPolicy::kDisabled)); +} + +jvmtiError ClassUtil::GetHiddenApiEnforcementPolicy(jvmtiEnv* env, jint* policy) { + if (env == nullptr) { + return ERR(INVALID_ENVIRONMENT); + } else if (art::Thread::Current() == nullptr) { + return ERR(UNATTACHED_THREAD); + } else if (policy == nullptr) { + return ERR(NULL_POINTER); + } + *policy = static_cast<jint>(art::Runtime::Current()->GetHiddenApiEnforcementPolicy()); + return OK; +} + +jvmtiError ClassUtil::SetHiddenApiEnforcementPolicy(jvmtiEnv* env, jint policy) { + if (env == nullptr) { + return ERR(INVALID_ENVIRONMENT); + } else if (art::Thread::Current() == nullptr) { + return ERR(UNATTACHED_THREAD); + } else if (policy < static_cast<jint>(art::hiddenapi::EnforcementPolicy::kDisabled) || + policy > static_cast<jint>(art::hiddenapi::EnforcementPolicy::kMax)) { + JVMTI_LOG(INFO, env) << "Bad policy: " << policy << ", must be between " + << static_cast<jint>(art::hiddenapi::EnforcementPolicy::kDisabled) + << " and " << static_cast<jint>(art::hiddenapi::EnforcementPolicy::kMax); + return ERR(ILLEGAL_ARGUMENT); + } + art::Runtime::Current()->SetHiddenApiEnforcementPolicy( + static_cast<art::hiddenapi::EnforcementPolicy>(policy)); + return OK; +} + } // namespace openjdkjvmti diff --git a/openjdkjvmti/ti_class.h b/openjdkjvmti/ti_class.h index 7e427a06f2..229a6ce546 100644 --- a/openjdkjvmti/ti_class.h +++ b/openjdkjvmti/ti_class.h @@ -93,6 +93,10 @@ class ClassUtil { static jvmtiError GetSourceDebugExtension(jvmtiEnv* env, jclass klass, char** source_debug_extension_ptr); + + static jvmtiError DisableHiddenApiEnforcementPolicy(jvmtiEnv* env); + static jvmtiError GetHiddenApiEnforcementPolicy(jvmtiEnv* env, jint* policy); + static jvmtiError SetHiddenApiEnforcementPolicy(jvmtiEnv* env, jint policy); }; } // namespace openjdkjvmti diff --git a/openjdkjvmti/ti_extension.cc b/openjdkjvmti/ti_extension.cc index dd68533523..10ea43a1ee 100644 --- a/openjdkjvmti/ti_extension.cc +++ b/openjdkjvmti/ti_extension.cc @@ -509,6 +509,58 @@ jvmtiError ExtensionUtil::GetExtensionFunctions(jvmtiEnv* env, if (error != ERR(NONE)) { return error; } + // GetHiddenApiEnforcementPolicy + error = add_extension( + reinterpret_cast<jvmtiExtensionFunction>(ClassUtil::GetHiddenApiEnforcementPolicy), + "com.android.art.misc.get_hidden_api_enforcement_policy", + "Gets the current hiddenapi enforcement policy. Policy values are defined in" + " `frameworks/base/core/java/android/content/pm/ApplicationInfo.java` as the" + " HIDDEN_API_ENFORCEMENT_ static fields. See the comments in `art/runtime/hidden_api.h` for" + " more information. This should be used with" + " `com.android.art.misc.set_hidden_api_enforcement_policy` in order to restore the" + " hidden-api state after temporarily toggling it.", + { + { "policy", JVMTI_KIND_OUT, JVMTI_TYPE_JINT, false }, + }, + { + ERR(NULL_POINTER), + }); + if (error != ERR(NONE)) { + return error; + } + // SetHiddenApiEnforcementPolicy + error = add_extension( + reinterpret_cast<jvmtiExtensionFunction>(ClassUtil::SetHiddenApiEnforcementPolicy), + "com.android.art.misc.set_hidden_api_enforcement_policy", + "Sets the hiddenapi enforcement policy to the given value. Policy values are defined in" + " `frameworks/base/core/java/android/content/pm/ApplicationInfo.java` as the" + " HIDDEN_API_ENFORCEMENT_ static fields. See the comments in `art/runtime/hidden_api.h` for" + " more information. This API should always be used sparingly and in conjunction with" + " `com.android.art.misc.get_hidden_api_enforcement_policy` to temporarily toggle" + " hidden-api on and off as changes are required.", + { + { "policy", JVMTI_KIND_IN, JVMTI_TYPE_JINT, false }, + }, + { + ERR(ILLEGAL_ARGUMENT), + }); + if (error != ERR(NONE)) { + return error; + } + // DisableHiddenApiEnforcementPolicy + error = add_extension( + reinterpret_cast<jvmtiExtensionFunction>(ClassUtil::DisableHiddenApiEnforcementPolicy), + "com.android.art.misc.disable_hidden_api_enforcement_policy", + "Sets the hiddenapi enforcement policy to disabled. This API should always be" + " used sparingly and in conjunction with" + " `com.android.art.misc.get_hidden_api_enforcement_policy` and" + " `com.android.art.misc.set_hidden_api_enforcement_policy` to temporarily" + " toggle hidden-api on and off as changes are required.", + {}, + {}); + if (error != ERR(NONE)) { + return error; + } // Copy into output buffer. |