tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2cacd6b77836fdf766ba6779c134387a69f3513c
parent 748f63a92260451e5d8f92c7acc81302877bfd6c
Author: Greg Stoll <gstoll@mozilla.com>
Date:   Thu, 30 Oct 2025 14:57:15 +0000

Bug 1906827 part 2 - add tests and make all cppunittests pass on ARM64 r=yjuglaret

Differential Revision: https://phabricator.services.mozilla.com/D269396

Diffstat:
Mtoolkit/xre/dllservices/tests/TestArm64Disassembler.cpp | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mtoolkit/xre/dllservices/tests/TestDllInterceptor.cpp | 8+++++---
Mtoolkit/xre/dllservices/tests/moz.build | 5+++--
3 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/toolkit/xre/dllservices/tests/TestArm64Disassembler.cpp b/toolkit/xre/dllservices/tests/TestArm64Disassembler.cpp @@ -26,11 +26,13 @@ using namespace mozilla; using namespace mozilla::interceptor::arm64; +constexpr uintptr_t kExamplePCValue = 0x7ff959a7ea80; + bool TestCheckForPCRelAdrp() { // A real-world example from bug 1964688 comment 5: // 00007ff9`59a7ea80 d0dfff11 adrp xip1,00007ff9`19a60000 Result<LoadOrBranch, PCRelCheckError> result = - CheckForPCRel(0x7ff959a7ea80, 0xd0dfff11); + CheckForPCRel(kExamplePCValue, 0xd0dfff11); if (result.isErr()) { auto error = result.unwrapErr(); TEST_FAILED( @@ -65,7 +67,7 @@ bool TestCheckForPCRelAdr() { // Fictional example with adr: // 00007ff959a7ea80 50dfff11 adr x17, #0x7ff959a3ea62 Result<LoadOrBranch, PCRelCheckError> result = - CheckForPCRel(0x7ff959a7ea80, 0x50dfff11); + CheckForPCRel(kExamplePCValue, 0x50dfff11); // For the moment we expect to recognize adr instructions but we don't have // a decoder @@ -90,8 +92,56 @@ bool TestCheckForPCRelAdr() { return true; } +bool TestCheckForPCRelBlr() { + // blr x16 + Result<LoadOrBranch, PCRelCheckError> result = + CheckForPCRel(kExamplePCValue, 0xd63f0200); + + if (!result.isErr()) { + TEST_FAILED( + "Unexpectedly recognized blr as a PC-relative instruction with a " + "decoder. If you have implemented a decoder for this instruction, " + "please update TestArm64Disassembler.cpp.\n"); + } + + auto error = result.unwrapErr(); + if (error != PCRelCheckError::NoDecoderAvailable) { + TEST_FAILED( + "Failed to recognize blr as a PC-relative instruction, got " + "PCRelCheckError %d.\n", + error); + } + + TEST_PASS( + "Properly recognized blr as a PC-relative instruction without a " + "decoder.\n"); + return true; +} + +bool TestCheckForPCRelBr() { + // br x16 + Result<LoadOrBranch, PCRelCheckError> result = + CheckForPCRel(kExamplePCValue, 0xd61f0200); + + if (result.isErr()) { + auto error = result.unwrapErr(); + if (error != PCRelCheckError::InstructionNotPCRel) { + TEST_FAILED( + "Failed to recognize br as a non-PC-relative instruction, got " + "PCRelCheckError %d.\n", + error); + } + } else { + TEST_FAILED("Incorrectly recognized br as a PC-relative instruction.\n"); + } + + TEST_PASS("Properly recognized br as a non-PC-relative instruction.\n"); + return true; +} + int wmain(int argc, wchar_t* argv[]) { - if (!TestCheckForPCRelAdrp() || !TestCheckForPCRelAdr()) { + if (!TestCheckForPCRelAdrp() || !TestCheckForPCRelAdr() || + !TestCheckForPCRelBlr() || !TestCheckForPCRelBr()) { return -1; } return 0; diff --git a/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp b/toolkit/xre/dllservices/tests/TestDllInterceptor.cpp @@ -848,10 +848,10 @@ MOZ_GLOBINIT struct TestCase { TestCase("LockPrefix", NoStubAddressCheck), TestCase("LooksLikeLockPrefix", NoStubAddressCheck), # endif -# if !defined(DEBUG) +# if !defined(_M_ARM64) && !defined(DEBUG) // Skip on Debug build because it hits MOZ_ASSERT_UNREACHABLE. TestCase("UnsupportedOp", ExpectedFail), -# endif // !defined(DEBUG) +# endif // !defined(_M_ARM64) && !defined(DEBUG) #endif // defined(__clang__) }; @@ -892,7 +892,9 @@ bool TestAssemblyFunctions() { DetourResultCode::DETOUR_PATCHER_CREATE_TRAMPOLINE_ERROR) { printf( "TEST-FAILED | WindowsDllInterceptor | " - "A wrong detour errorcode was set on detour error.\n"); + "A wrong detour errorcode was set on detour error for %s. (got " + "%d)\n", + testCase.mFunctionName, maybeError.ref().mErrorCode); return false; } #endif // defined(NIGHTLY_BUILD) diff --git a/toolkit/xre/dllservices/tests/moz.build b/toolkit/xre/dllservices/tests/moz.build @@ -8,7 +8,6 @@ GeckoCppUnitTests( [ "TestDllBlocklistAssumptions", "TestDllInterceptor", - "TestIATPatcher", "TestMMPolicy", "TestOleAut32Initialization", ], @@ -16,10 +15,12 @@ GeckoCppUnitTests( ) if CONFIG["TARGET_CPU"] in ("x86", "x86_64"): - # Cross-process interceptors not yet supported on aarch64 GeckoCppUnitTests( [ + # Cross-process interceptors not yet supported on aarch64 "TestDllInterceptorCrossProcess", + # Requires administrator permission on aarch64 + "TestIATPatcher", ], linkage=None, )