Revert^2 "hidden_api: Call back into libcore on hidden api detection""
This reverts commit bbe60d58496991c16e2943e174e26ab8a096b3d0.
This CL deviates from the approach of the original change. Instead of
calling back every time ShouldBlock.. was called, we explicitly call
back in cases where it's safe to do so.
Note that we only call back on reflective accesses for now, and not
link time accesses. Coverage for the latter will be added in a follow up
change.
Bug: 73896556
Test: test-art-host
Test: art/test.py --host -t test-art-host-run-test-debug-prebuild-\
interpreter-no-relocate-ntrace-gcstress-checkjni-picimage-pictest-\
ndebuggable-no-jvmti-cdex-fast-674-hiddenapi64
(cherry picked from commit e453a8dd87731f4b37b86a1284f7655d86c2a809)
Merged-In: Ie99ac268a083af167accbdf955639da068bea950
Change-Id: I76860519d40b87032dbb8db38b04fcf79ef09723
diff --git a/runtime/hidden_api.h b/runtime/hidden_api.h
index cc6c146..ffdeacb 100644
--- a/runtime/hidden_api.h
+++ b/runtime/hidden_api.h
@@ -58,7 +58,7 @@
kLinking,
};
-inline Action GetMemberAction(uint32_t access_flags) {
+inline Action GetActionFromAccessFlags(uint32_t access_flags) {
EnforcementPolicy policy = Runtime::Current()->GetHiddenApiEnforcementPolicy();
if (policy == EnforcementPolicy::kNoChecks) {
// Exit early. Nothing to enforce.
@@ -108,9 +108,7 @@
};
template<typename T>
-bool ShouldBlockAccessToMemberImpl(T* member,
- Action action,
- AccessMethod access_method)
+Action GetMemberActionImpl(T* member, Action action, AccessMethod access_method)
REQUIRES_SHARED(Locks::mutator_lock_);
// Returns true if the caller is either loaded by the boot strap class loader or comes from
@@ -138,28 +136,28 @@
// return true if the caller is located in the platform.
// This function might print warnings into the log if the member is hidden.
template<typename T>
-inline bool ShouldBlockAccessToMember(T* member,
- Thread* self,
- std::function<bool(Thread*)> fn_caller_in_platform,
- AccessMethod access_method)
+inline Action GetMemberAction(T* member,
+ Thread* self,
+ std::function<bool(Thread*)> fn_caller_in_platform,
+ AccessMethod access_method)
REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK(member != nullptr);
- Action action = GetMemberAction(member->GetAccessFlags());
+ Action action = GetActionFromAccessFlags(member->GetAccessFlags());
if (action == kAllow) {
// Nothing to do.
- return false;
+ return action;
}
// Member is hidden. Invoke `fn_caller_in_platform` and find the origin of the access.
// This can be *very* expensive. Save it for last.
if (fn_caller_in_platform(self)) {
// Caller in the platform. Exit.
- return false;
+ return kAllow;
}
// Member is hidden and caller is not in the platform.
- return detail::ShouldBlockAccessToMemberImpl(member, action, access_method);
+ return detail::GetMemberActionImpl(member, action, access_method);
}
inline bool IsCallerInPlatformDex(ObjPtr<mirror::Class> caller)
@@ -172,18 +170,26 @@
// `caller_class_loader`.
// This function might print warnings into the log if the member is hidden.
template<typename T>
-inline bool ShouldBlockAccessToMember(T* member,
- ObjPtr<mirror::ClassLoader> caller_class_loader,
- ObjPtr<mirror::DexCache> caller_dex_cache,
- AccessMethod access_method)
+inline Action GetMemberAction(T* member,
+ ObjPtr<mirror::ClassLoader> caller_class_loader,
+ ObjPtr<mirror::DexCache> caller_dex_cache,
+ AccessMethod access_method)
REQUIRES_SHARED(Locks::mutator_lock_) {
bool caller_in_platform = detail::IsCallerInPlatformDex(caller_class_loader, caller_dex_cache);
- return ShouldBlockAccessToMember(member,
- /* thread */ nullptr,
- [caller_in_platform] (Thread*) { return caller_in_platform; },
- access_method);
+ return GetMemberAction(member,
+ /* thread */ nullptr,
+ [caller_in_platform] (Thread*) { return caller_in_platform; },
+ access_method);
}
+// Calls back into managed code to notify VMRuntime.nonSdkApiUsageConsumer that
+// |member| was accessed. This is usually called when an API is on the black,
+// dark grey or light grey lists. Given that the callback can execute arbitrary
+// code, a call to this method can result in thread suspension.
+template<typename T> void NotifyHiddenApiListener(T* member)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
+
} // namespace hiddenapi
} // namespace art