From 9877158679484f8c2c8210d0c37c6e1d6af0c8d0 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Sun, 28 May 2023 11:56:24 -1000 Subject: [PATCH] Fixes for recording/replaying on windows (#969) --- gfx/thebes/gfxDWriteFontList.cpp | 26 ++++++++++++++++++++- intl/icu/source/i18n/numfmt.cpp | 9 ++++++- mozglue/dllservices/WindowsDllBlocklist.cpp | 4 ++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gfx/thebes/gfxDWriteFontList.cpp b/gfx/thebes/gfxDWriteFontList.cpp index 88d7e6db72c7f..1387f9afa42c8 100644 --- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -2456,11 +2456,19 @@ class BundledFontFileEnumerator : public IDWriteFontFileEnumerator { BundledFontFileEnumerator::BundledFontFileEnumerator(IDWriteFactory* aFactory, nsIFile* aFontDir) : mFactory(aFactory), mFontDir(aFontDir) { - mFontDir->GetDirectoryEntries(getter_AddRefs(mEntries)); + if (mFontDir) { + mFontDir->GetDirectoryEntries(getter_AddRefs(mEntries)); + } } IFACEMETHODIMP BundledFontFileEnumerator::MoveNext(BOOL* aHasCurrentFile) { + // Watch out for missing fonts when replaying. + if (recordreplay::IsReplaying()) { + return S_OK; + } + recordreplay::AutoPassThroughThreadEvents pt; + bool hasMore = false; if (mEntries) { if (NS_SUCCEEDED(mEntries->HasMoreElements(&hasMore)) && hasMore) { @@ -2475,6 +2483,12 @@ BundledFontFileEnumerator::MoveNext(BOOL* aHasCurrentFile) { IFACEMETHODIMP BundledFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** aFontFile) { + // Watch out for missing fonts when replaying. + if (recordreplay::IsReplaying()) { + return S_OK; + } + recordreplay::AutoPassThroughThreadEvents pt; + nsCOMPtr file = do_QueryInterface(mCurrent); if (!file) { return E_FAIL; @@ -2511,6 +2525,16 @@ BundledFontLoader::CreateEnumeratorFromKey( IDWriteFactory* aFactory, const void* aCollectionKey, UINT32 aCollectionKeySize, IDWriteFontFileEnumerator** aFontFileEnumerator) { + // The collection key's contents will be recorded/replayed and we can't dereference + // embedded pointers within it. Workaround this by creating a dummy enumerator when + // we're replaying. + if (recordreplay::IsReplaying()) { + *aFontFileEnumerator = new BundledFontFileEnumerator(aFactory, nullptr); + NS_ADDREF(*aFontFileEnumerator); + return S_OK; + } + recordreplay::AutoPassThroughThreadEvents pt; + nsIFile* fontDir = *(nsIFile**)aCollectionKey; *aFontFileEnumerator = new BundledFontFileEnumerator(aFactory, fontDir); NS_ADDREF(*aFontFileEnumerator); diff --git a/intl/icu/source/i18n/numfmt.cpp b/intl/icu/source/i18n/numfmt.cpp index bd2bc30cd9495..ed2891ad504d4 100644 --- a/intl/icu/source/i18n/numfmt.cpp +++ b/intl/icu/source/i18n/numfmt.cpp @@ -57,6 +57,8 @@ #include "number_decimalquantity.h" #include "number_utils.h" +#include "mozilla/RecordReplay.h" + //#define FMT_DEBUG #ifdef FMT_DEBUG @@ -1407,7 +1409,12 @@ NumberFormat::makeInstance(const Locale& desiredLocale, ns->getName(), gFormatCldrStyles[style], status); - pattern = UnicodeString(TRUE, patternPtr, -1); + + // Record/replay string length to workaround the length differing when + // replaying for an unknown reason. + int len = mozilla::recordreplay::RecordReplayValue("NumberFormat::makeInstance", u_strlen(patternPtr)); + + pattern = UnicodeString(TRUE, patternPtr, len); } if (U_FAILURE(status)) { return NULL; diff --git a/mozglue/dllservices/WindowsDllBlocklist.cpp b/mozglue/dllservices/WindowsDllBlocklist.cpp index cee5834ceb688..a5cb078751166 100644 --- a/mozglue/dllservices/WindowsDllBlocklist.cpp +++ b/mozglue/dllservices/WindowsDllBlocklist.cpp @@ -16,6 +16,7 @@ #include "nsWindowsDllInterceptor.h" #include "mozilla/CmdLineAndEnvUtils.h" #include "mozilla/DebugOnly.h" +#include "mozilla/RecordReplay.h" #include "mozilla/StackWalk_windows.h" #include "mozilla/TimeStamp.h" #include "mozilla/UniquePtr.h" @@ -353,6 +354,9 @@ static wchar_t* lastslash(wchar_t* s, int len) { static NTSTATUS NTAPI patched_LdrLoadDll(PWCHAR filePath, PULONG flags, PUNICODE_STRING moduleFileName, PHANDLE handle) { + // This code only runs when recording. + recordreplay::AutoPassThroughThreadEvents pt; + // We have UCS2 (UTF16?), we want ASCII, but we also just want the filename // portion #define DLLNAME_MAX 128