Bug 1740569 - NativeNtBlockSet_Write needs to receive AnnotationWriter. r=gsvelto

Bug 1420363 changed the type of `WriterFn`'s parameter from `HANDLE` to
`AnnotationWriter&` and rewrote `InternalWriteNotes` in mozglue.dll, but
it didn't update `NativeNtBlockSet_Write` in firefox.exe, which is used
when the launcher process is enabled.

This patch applies a part of D46848 to `NativeNtBlockSet_Write`.

Differential Revision: https://phabricator.services.mozilla.com/D130921
This commit is contained in:
Toshihito Kikuchi 2021-11-11 17:50:48 +00:00
Родитель dc3e72b026
Коммит 52751d5a3f
3 изменённых файлов: 39 добавлений и 33 удалений

Просмотреть файл

@ -11,6 +11,7 @@
#include "mozilla/Types.h" #include "mozilla/Types.h"
#include "mozilla/WindowsDllBlocklist.h" #include "mozilla/WindowsDllBlocklist.h"
#include "CrashAnnotations.h"
#include "DllBlocklist.h" #include "DllBlocklist.h"
#include "LoaderPrivateAPI.h" #include "LoaderPrivateAPI.h"
#include "ModuleLoadFrame.h" #include "ModuleLoadFrame.h"
@ -40,6 +41,8 @@ DLL_BLOCKLIST_DEFINITIONS_BEGIN
DLL_BLOCKLIST_DEFINITIONS_END DLL_BLOCKLIST_DEFINITIONS_END
#endif #endif
using WritableBuffer = mozilla::glue::detail::WritableBuffer<1024>;
class MOZ_STATIC_CLASS MOZ_TRIVIAL_CTOR_DTOR NativeNtBlockSet final { class MOZ_STATIC_CLASS MOZ_TRIVIAL_CTOR_DTOR NativeNtBlockSet final {
struct NativeNtBlockSetEntry { struct NativeNtBlockSetEntry {
NativeNtBlockSetEntry() = default; NativeNtBlockSetEntry() = default;
@ -58,7 +61,7 @@ class MOZ_STATIC_CLASS MOZ_TRIVIAL_CTOR_DTOR NativeNtBlockSet final {
~NativeNtBlockSet() = default; ~NativeNtBlockSet() = default;
void Add(const UNICODE_STRING& aName, uint64_t aVersion); void Add(const UNICODE_STRING& aName, uint64_t aVersion);
void Write(HANDLE aFile); void Write(WritableBuffer& buffer);
private: private:
static NativeNtBlockSetEntry* NewEntry(const UNICODE_STRING& aName, 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, // NB: If this function is called, it is long after kernel32 is initialized,
// so it is safe to use Win32 calls here. // so it is safe to use Win32 calls here.
DWORD nBytes;
char buf[MAX_PATH]; char buf[MAX_PATH];
// It would be nicer to use RAII here. However, its destructor // 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]; // write name[,v.v.v.v];
if (!WriteFile(aFile, buf, convOk, &nBytes, nullptr)) { aBuffer.Write(buf, convOk);
continue;
}
if (entry->mVersion != DllBlockInfo::ALL_VERSIONS) { if (entry->mVersion != DllBlockInfo::ALL_VERSIONS) {
WriteFile(aFile, ",", 1, &nBytes, nullptr); aBuffer.Write(",", 1);
uint16_t parts[4]; uint16_t parts[4];
parts[0] = entry->mVersion >> 48; parts[0] = entry->mVersion >> 48;
parts[1] = (entry->mVersion >> 32) & 0xFFFF; parts[1] = (entry->mVersion >> 32) & 0xFFFF;
parts[2] = (entry->mVersion >> 16) & 0xFFFF; parts[2] = (entry->mVersion >> 16) & 0xFFFF;
parts[3] = entry->mVersion & 0xFFFF; parts[3] = entry->mVersion & 0xFFFF;
for (size_t p = 0; p < mozilla::ArrayLength(parts); ++p) { for (size_t p = 0; p < mozilla::ArrayLength(parts); ++p) {
ltoa(parts[p], buf, 10); _ltoa_s(parts[p], buf, sizeof(buf), 10);
WriteFile(aFile, buf, strlen(buf), &nBytes, nullptr); aBuffer.Write(buf, strlen(buf));
if (p != mozilla::ArrayLength(parts) - 1) { 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) {} MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {}
@ -146,8 +146,12 @@ void NativeNtBlockSet::Write(HANDLE aFile) {
static NativeNtBlockSet gBlockSet; static NativeNtBlockSet gBlockSet;
extern "C" void MOZ_EXPORT NativeNtBlockSet_Write(HANDLE aHandle) { extern "C" void MOZ_EXPORT
gBlockSet.Write(aHandle); NativeNtBlockSet_Write(CrashReporter::AnnotationWriter& aWriter) {
WritableBuffer buffer;
gBlockSet.Write(buffer);
aWriter.Write(CrashReporter::Annotation::BlockedDllList, buffer.Data(),
buffer.Length());
} }
enum class BlockAction { enum class BlockAction {

Просмотреть файл

@ -215,25 +215,7 @@ class ReentrancySentinel {
std::map<DWORD, const char*>* ReentrancySentinel::sThreadMap; std::map<DWORD, const char*>* ReentrancySentinel::sThreadMap;
class WritableBuffer { using WritableBuffer = mozilla::glue::detail::WritableBuffer<1024>;
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;
};
/** /**
* This is a linked list of DLLs that have been blocked. It doesn't use * This is a linked list of DLLs that have been blocked. It doesn't use

Просмотреть файл

@ -39,11 +39,31 @@ MFBT_API bool DllBlocklist_CheckStatus();
MFBT_API void DllBlocklist_Shutdown(); MFBT_API void DllBlocklist_Shutdown();
# endif // DEBUG # endif // DEBUG
// Forward declaration
namespace mozilla { namespace mozilla {
namespace glue { namespace glue {
namespace detail { namespace detail {
// Forward declaration
class DllServicesBase; class DllServicesBase;
template <size_t N>
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 detail
} // namespace glue } // namespace glue
} // namespace mozilla } // namespace mozilla