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/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 {

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

@ -215,25 +215,7 @@ class ReentrancySentinel {
std::map<DWORD, const char*>* 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

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

@ -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 <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 glue
} // namespace mozilla