Skip to content

Commit 89e24c1

Browse files
rmacnak-googleCommit Queue
authored and
Commit Queue
committed
[vm] Fix assertions in Windows ARM64 feature detection.
TEST=ci (forthcoming) Change-Id: I3d34ab3af721267f9c586f4a9becdd374455cc76 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313182 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 70c186d commit 89e24c1

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

runtime/vm/cpuinfo_win.cc

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
2020
const char* CpuInfo::fields_[kCpuInfoMax] = {};
2121

2222
void CpuInfo::Init() {
23+
#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
2324
method_ = kCpuInfoCpuId;
2425

2526
// Initialize the CpuId information.
@@ -30,28 +31,55 @@ void CpuInfo::Init() {
3031
fields_[kCpuInfoHardware] = "Hardware";
3132
fields_[kCpuInfoFeatures] = "Features";
3233
fields_[kCpuInfoArchitecture] = nullptr;
34+
#elif defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64)
35+
// We only rely on the base ARM64 version, so we don't need dynamic feature
36+
// detection.
37+
method_ = kCpuInfoNone;
38+
#else
39+
#error Unrecognized target architecture
40+
#endif
3341
}
3442

3543
void CpuInfo::Cleanup() {
36-
CpuId::Cleanup();
44+
if (method_ == kCpuInfoCpuId) {
45+
CpuId::Cleanup();
46+
} else {
47+
ASSERT(method_ == kCpuInfoNone);
48+
}
3749
}
3850

3951
bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
40-
ASSERT(method_ != kCpuInfoDefault);
41-
return strstr(CpuId::field(idx), search_string);
52+
if (method_ == kCpuInfoCpuId) {
53+
return CpuId::field(idx);
54+
} else {
55+
UNREACHABLE();
56+
}
4257
}
4358

4459
const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
45-
ASSERT(method_ != kCpuInfoDefault);
46-
return CpuId::field(idx);
60+
if (method_ == kCpuInfoCpuId) {
61+
return CpuId::field(idx);
62+
} else if (method_ == kCpuInfoNone) {
63+
if (idx == kCpuInfoHardware) {
64+
return "Generic ARM64";
65+
}
66+
UNREACHABLE();
67+
} else {
68+
UNREACHABLE();
69+
}
4770
}
4871

4972
bool CpuInfo::HasField(const char* field) {
50-
ASSERT(method_ != kCpuInfoDefault);
51-
return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) ||
52-
(strcmp(field, fields_[kCpuInfoModel]) == 0) ||
53-
(strcmp(field, fields_[kCpuInfoHardware]) == 0) ||
54-
(strcmp(field, fields_[kCpuInfoFeatures]) == 0);
73+
if (method_ == kCpuInfoCpuId) {
74+
return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) ||
75+
(strcmp(field, fields_[kCpuInfoModel]) == 0) ||
76+
(strcmp(field, fields_[kCpuInfoHardware]) == 0) ||
77+
(strcmp(field, fields_[kCpuInfoFeatures]) == 0);
78+
} else if (method_ == kCpuInfoNone) {
79+
return false;
80+
} else {
81+
UNREACHABLE();
82+
}
5583
}
5684

5785
} // namespace dart

0 commit comments

Comments
 (0)