Do not overwrite hidden access flags for intrinsics
Deduplicating warnings works by overwriting the runtime access flags
of a method/field to move it from a greylist to the whitelist. This
triggers a CHECK when attempted on an intrinsic as their ordinal bits
clash with the hidden API access flags. Do not attempt to deduplicate
for those.
Bug: 78574586
Test: (cd cts/tests/signature ; ./runSignatureTests.sh)
Change-Id: I39e555a0f4cd5f662eea348baf4ef72a5827306d
diff --git a/runtime/hidden_api.cc b/runtime/hidden_api.cc
index bc6a8f2..e8918e7 100644
--- a/runtime/hidden_api.cc
+++ b/runtime/hidden_api.cc
@@ -171,6 +171,23 @@
log_maker.Record();
}
+static ALWAYS_INLINE bool CanUpdateMemberAccessFlags(ArtField*) {
+ return true;
+}
+
+static ALWAYS_INLINE bool CanUpdateMemberAccessFlags(ArtMethod* method) {
+ return !method->IsIntrinsic();
+}
+
+template<typename T>
+static ALWAYS_INLINE void MaybeWhitelistMember(Runtime* runtime, T* member)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ if (CanUpdateMemberAccessFlags(member) && runtime->ShouldDedupeHiddenApiWarnings()) {
+ member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
+ member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist));
+ }
+}
+
template<typename T>
Action GetMemberActionImpl(T* member,
HiddenApiAccessFlags::ApiList api_list,
@@ -195,10 +212,7 @@
// Avoid re-examining the exemption list next time.
// Note this results in no warning for the member, which seems like what one would expect.
// Exemptions effectively adds new members to the whitelist.
- if (runtime->ShouldDedupeHiddenApiWarnings()) {
- member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
- member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist));
- }
+ MaybeWhitelistMember(runtime, member);
return kAllow;
}
@@ -230,10 +244,7 @@
if (access_method != kNone) {
// Depending on a runtime flag, we might move the member into whitelist and
// skip the warning the next time the member is accessed.
- if (runtime->ShouldDedupeHiddenApiWarnings()) {
- member->SetAccessFlags(HiddenApiAccessFlags::EncodeForRuntime(
- member->GetAccessFlags(), HiddenApiAccessFlags::kWhitelist));
- }
+ MaybeWhitelistMember(runtime, member);
// If this action requires a UI warning, set the appropriate flag.
if (action == kAllowButWarnAndToast || runtime->ShouldAlwaysSetHiddenApiWarningFlag()) {