Skip to content

Commit ad7e8a0

Browse files
committed
Bug 1906827 part 2 - add tests and make all cppunittests pass on ARM64 r=yjuglaret
Differential Revision: https://phabricator.services.mozilla.com/D269396
1 parent 803b433 commit ad7e8a0

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

toolkit/xre/dllservices/tests/TestArm64Disassembler.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
using namespace mozilla;
2727
using namespace mozilla::interceptor::arm64;
2828

29+
constexpr uintptr_t kExamplePCValue = 0x7ff959a7ea80;
30+
2931
bool TestCheckForPCRelAdrp() {
3032
// A real-world example from bug 1964688 comment 5:
3133
// 00007ff9`59a7ea80 d0dfff11 adrp xip1,00007ff9`19a60000
3234
Result<LoadOrBranch, PCRelCheckError> result =
33-
CheckForPCRel(0x7ff959a7ea80, 0xd0dfff11);
35+
CheckForPCRel(kExamplePCValue, 0xd0dfff11);
3436
if (result.isErr()) {
3537
auto error = result.unwrapErr();
3638
TEST_FAILED(
@@ -65,7 +67,7 @@ bool TestCheckForPCRelAdr() {
6567
// Fictional example with adr:
6668
// 00007ff959a7ea80 50dfff11 adr x17, #0x7ff959a3ea62
6769
Result<LoadOrBranch, PCRelCheckError> result =
68-
CheckForPCRel(0x7ff959a7ea80, 0x50dfff11);
70+
CheckForPCRel(kExamplePCValue, 0x50dfff11);
6971

7072
// For the moment we expect to recognize adr instructions but we don't have
7173
// a decoder
@@ -90,8 +92,56 @@ bool TestCheckForPCRelAdr() {
9092
return true;
9193
}
9294

95+
bool TestCheckForPCRelBlr() {
96+
// blr x16
97+
Result<LoadOrBranch, PCRelCheckError> result =
98+
CheckForPCRel(kExamplePCValue, 0xd63f0200);
99+
100+
if (!result.isErr()) {
101+
TEST_FAILED(
102+
"Unexpectedly recognized blr as a PC-relative instruction with a "
103+
"decoder. If you have implemented a decoder for this instruction, "
104+
"please update TestArm64Disassembler.cpp.\n");
105+
}
106+
107+
auto error = result.unwrapErr();
108+
if (error != PCRelCheckError::NoDecoderAvailable) {
109+
TEST_FAILED(
110+
"Failed to recognize blr as a PC-relative instruction, got "
111+
"PCRelCheckError %d.\n",
112+
error);
113+
}
114+
115+
TEST_PASS(
116+
"Properly recognized blr as a PC-relative instruction without a "
117+
"decoder.\n");
118+
return true;
119+
}
120+
121+
bool TestCheckForPCRelBr() {
122+
// br x16
123+
Result<LoadOrBranch, PCRelCheckError> result =
124+
CheckForPCRel(kExamplePCValue, 0xd61f0200);
125+
126+
if (result.isErr()) {
127+
auto error = result.unwrapErr();
128+
if (error != PCRelCheckError::InstructionNotPCRel) {
129+
TEST_FAILED(
130+
"Failed to recognize br as a non-PC-relative instruction, got "
131+
"PCRelCheckError %d.\n",
132+
error);
133+
}
134+
} else {
135+
TEST_FAILED("Incorrectly recognized br as a PC-relative instruction.\n");
136+
}
137+
138+
TEST_PASS("Properly recognized br as a non-PC-relative instruction.\n");
139+
return true;
140+
}
141+
93142
int wmain(int argc, wchar_t* argv[]) {
94-
if (!TestCheckForPCRelAdrp() || !TestCheckForPCRelAdr()) {
143+
if (!TestCheckForPCRelAdrp() || !TestCheckForPCRelAdr() ||
144+
!TestCheckForPCRelBlr() || !TestCheckForPCRelBr()) {
95145
return -1;
96146
}
97147
return 0;

toolkit/xre/dllservices/tests/TestDllInterceptor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,10 @@ MOZ_GLOBINIT struct TestCase {
848848
TestCase("LockPrefix", NoStubAddressCheck),
849849
TestCase("LooksLikeLockPrefix", NoStubAddressCheck),
850850
# endif
851-
# if !defined(DEBUG)
851+
# if !defined(_M_ARM64) && !defined(DEBUG)
852852
// Skip on Debug build because it hits MOZ_ASSERT_UNREACHABLE.
853853
TestCase("UnsupportedOp", ExpectedFail),
854-
# endif // !defined(DEBUG)
854+
# endif // !defined(_M_ARM64) && !defined(DEBUG)
855855
#endif // defined(__clang__)
856856
};
857857

@@ -892,7 +892,9 @@ bool TestAssemblyFunctions() {
892892
DetourResultCode::DETOUR_PATCHER_CREATE_TRAMPOLINE_ERROR) {
893893
printf(
894894
"TEST-FAILED | WindowsDllInterceptor | "
895-
"A wrong detour errorcode was set on detour error.\n");
895+
"A wrong detour errorcode was set on detour error for %s. (got "
896+
"%d)\n",
897+
testCase.mFunctionName, maybeError.ref().mErrorCode);
896898
return false;
897899
}
898900
#endif // defined(NIGHTLY_BUILD)

toolkit/xre/dllservices/tests/moz.build

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ GeckoCppUnitTests(
88
[
99
"TestDllBlocklistAssumptions",
1010
"TestDllInterceptor",
11-
"TestIATPatcher",
1211
"TestMMPolicy",
1312
"TestOleAut32Initialization",
1413
],
1514
linkage=None,
1615
)
1716

1817
if CONFIG["TARGET_CPU"] in ("x86", "x86_64"):
19-
# Cross-process interceptors not yet supported on aarch64
2018
GeckoCppUnitTests(
2119
[
20+
# Cross-process interceptors not yet supported on aarch64
2221
"TestDllInterceptorCrossProcess",
22+
# Requires administrator permission on aarch64
23+
"TestIATPatcher",
2324
],
2425
linkage=None,
2526
)

0 commit comments

Comments
 (0)