diff --git a/browser/app/winlauncher/freestanding/DllBlocklist.cpp b/browser/app/winlauncher/freestanding/DllBlocklist.cpp index 04c755b1addb..7c81920d54ea 100644 --- a/browser/app/winlauncher/freestanding/DllBlocklist.cpp +++ b/browser/app/winlauncher/freestanding/DllBlocklist.cpp @@ -11,6 +11,7 @@ #include "mozilla/Types.h" #include "mozilla/WindowsDllBlocklist.h" +#include "CrashAnnotations.h" #include "DllBlocklist.h" #include "LoaderPrivateAPI.h" #include "ModuleLoadFrame.h" @@ -40,6 +41,8 @@ DLL_BLOCKLIST_DEFINITIONS_BEGIN DLL_BLOCKLIST_DEFINITIONS_END #endif +using WritableBuffer = mozilla::glue::detail::WritableBuffer<1024>; + class MOZ_STATIC_CLASS MOZ_TRIVIAL_CTOR_DTOR NativeNtBlockSet final { struct NativeNtBlockSetEntry { NativeNtBlockSetEntry() = default; @@ -58,7 +61,7 @@ class MOZ_STATIC_CLASS MOZ_TRIVIAL_CTOR_DTOR NativeNtBlockSet final { ~NativeNtBlockSet() = default; void Add(const UNICODE_STRING& aName, uint64_t aVersion); - void Write(HANDLE aFile); + void Write(WritableBuffer& buffer); private: static NativeNtBlockSetEntry* NewEntry(const UNICODE_STRING& aName, @@ -95,10 +98,9 @@ void NativeNtBlockSet::Add(const UNICODE_STRING& aName, uint64_t aVersion) { } } -void NativeNtBlockSet::Write(HANDLE aFile) { +void NativeNtBlockSet::Write(WritableBuffer& aBuffer) { // NB: If this function is called, it is long after kernel32 is initialized, // so it is safe to use Win32 calls here. - DWORD nBytes; char buf[MAX_PATH]; // It would be nicer to use RAII here. However, its destructor @@ -117,26 +119,24 @@ void NativeNtBlockSet::Write(HANDLE aFile) { } // write name[,v.v.v.v]; - if (!WriteFile(aFile, buf, convOk, &nBytes, nullptr)) { - continue; - } + aBuffer.Write(buf, convOk); if (entry->mVersion != DllBlockInfo::ALL_VERSIONS) { - WriteFile(aFile, ",", 1, &nBytes, nullptr); + aBuffer.Write(",", 1); uint16_t parts[4]; parts[0] = entry->mVersion >> 48; parts[1] = (entry->mVersion >> 32) & 0xFFFF; parts[2] = (entry->mVersion >> 16) & 0xFFFF; parts[3] = entry->mVersion & 0xFFFF; for (size_t p = 0; p < mozilla::ArrayLength(parts); ++p) { - ltoa(parts[p], buf, 10); - WriteFile(aFile, buf, strlen(buf), &nBytes, nullptr); + _ltoa_s(parts[p], buf, sizeof(buf), 10); + aBuffer.Write(buf, strlen(buf)); if (p != mozilla::ArrayLength(parts) - 1) { - WriteFile(aFile, ".", 1, &nBytes, nullptr); + aBuffer.Write(".", 1); } } } - WriteFile(aFile, ";", 1, &nBytes, nullptr); + aBuffer.Write(";", 1); } } MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {} @@ -146,8 +146,12 @@ void NativeNtBlockSet::Write(HANDLE aFile) { static NativeNtBlockSet gBlockSet; -extern "C" void MOZ_EXPORT NativeNtBlockSet_Write(HANDLE aHandle) { - gBlockSet.Write(aHandle); +extern "C" void MOZ_EXPORT +NativeNtBlockSet_Write(CrashReporter::AnnotationWriter& aWriter) { + WritableBuffer buffer; + gBlockSet.Write(buffer); + aWriter.Write(CrashReporter::Annotation::BlockedDllList, buffer.Data(), + buffer.Length()); } enum class BlockAction { diff --git a/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp b/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp index 645ee1cda3fe..cbff4f14b57f 100644 --- a/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp +++ b/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp @@ -215,25 +215,7 @@ class ReentrancySentinel { std::map* ReentrancySentinel::sThreadMap; -class WritableBuffer { - public: - WritableBuffer() : mBuffer{0}, mLen(0) {} - - void Write(const char* aData, size_t aLen) { - size_t writable_len = std::min(aLen, Available()); - memcpy(mBuffer + mLen, aData, writable_len); - mLen += writable_len; - } - - size_t const Length() { return mLen; } - const char* Data() { return mBuffer; } - - private: - size_t const Available() { return sizeof(mBuffer) - mLen; } - - char mBuffer[1024]; - size_t mLen; -}; +using WritableBuffer = mozilla::glue::detail::WritableBuffer<1024>; /** * This is a linked list of DLLs that have been blocked. It doesn't use diff --git a/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.h b/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.h index 475c5a34a56e..d645a75d0dc7 100644 --- a/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.h +++ b/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.h @@ -39,11 +39,31 @@ MFBT_API bool DllBlocklist_CheckStatus(); MFBT_API void DllBlocklist_Shutdown(); # endif // DEBUG -// Forward declaration namespace mozilla { namespace glue { namespace detail { +// Forward declaration class DllServicesBase; + +template +class WritableBuffer { + char mBuffer[N]; + size_t mLen; + + size_t Available() const { return sizeof(mBuffer) - mLen; } + + public: + WritableBuffer() : mBuffer{0}, mLen(0) {} + + void Write(const char* aData, size_t aLen) { + size_t writable_len = std::min(aLen, Available()); + memcpy(mBuffer + mLen, aData, writable_len); + mLen += writable_len; + } + + size_t Length() const { return mLen; } + const char* Data() const { return mBuffer; } +}; } // namespace detail } // namespace glue } // namespace mozilla