зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1495871 - use C++11 statics for Faulty instance; r=decoder
C++11 provides guaranteed thread-safe static initialization, so we can use that instead of ipc's baroque Singleton class.
This commit is contained in:
Родитель
ab6a71a3de
Коммит
e2d2f91d22
|
@ -539,28 +539,28 @@ void Pickle::EndWrite(uint32_t length) {
|
|||
|
||||
bool Pickle::WriteBool(bool value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzBool(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzBool(&value);
|
||||
#endif
|
||||
return WriteInt(value ? 1 : 0);
|
||||
}
|
||||
|
||||
bool Pickle::WriteInt16(int16_t value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzInt16(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzInt16(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteUInt16(uint16_t value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzUInt16(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzUInt16(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteInt(int value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzInt(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzInt(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ bool Pickle::WriteLong(long value) {
|
|||
// Always written as a 64-bit value since the size for this type can
|
||||
// differ between architectures.
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzLong(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzLong(&value);
|
||||
#endif
|
||||
return WriteInt64(int64_t(value));
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ bool Pickle::WriteULong(unsigned long value) {
|
|||
// Always written as a 64-bit value since the size for this type can
|
||||
// differ between architectures.
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzULong(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzULong(&value);
|
||||
#endif
|
||||
return WriteUInt64(uint64_t(value));
|
||||
}
|
||||
|
@ -587,42 +587,42 @@ bool Pickle::WriteSize(size_t value) {
|
|||
// Always written as a 64-bit value since the size for this type can
|
||||
// differ between architectures.
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzSize(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzSize(&value);
|
||||
#endif
|
||||
return WriteUInt64(uint64_t(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteInt32(int32_t value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzInt(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzInt(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteUInt32(uint32_t value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzUInt32(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzUInt32(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteInt64(int64_t value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzInt64(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzInt64(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteUInt64(uint64_t value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzUInt64(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzUInt64(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
||||
bool Pickle::WriteDouble(double value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzDouble(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzDouble(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
@ -635,7 +635,7 @@ bool Pickle::WriteIntPtr(intptr_t value) {
|
|||
|
||||
bool Pickle::WriteUnsignedChar(unsigned char value) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzUChar(&value);
|
||||
mozilla::ipc::Faulty::instance().FuzzUChar(&value);
|
||||
#endif
|
||||
return WriteBytes(&value, sizeof(value));
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ bool Pickle::WriteBytes(const void* data, uint32_t data_len, uint32_t alignment)
|
|||
bool Pickle::WriteString(const std::string& value) {
|
||||
#ifdef FUZZING
|
||||
std::string v(value);
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzString(v);
|
||||
mozilla::ipc::Faulty::instance().FuzzString(v);
|
||||
if (!WriteInt(static_cast<int>(v.size())))
|
||||
return false;
|
||||
|
||||
|
@ -681,7 +681,7 @@ bool Pickle::WriteString(const std::string& value) {
|
|||
bool Pickle::WriteWString(const std::wstring& value) {
|
||||
#ifdef FUZZING
|
||||
std::wstring v(value);
|
||||
Singleton<mozilla::ipc::Faulty>::get()->FuzzWString(v);
|
||||
mozilla::ipc::Faulty::instance().FuzzWString(v);
|
||||
if (!WriteInt(static_cast<int>(v.size())))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -618,7 +618,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
|
|||
// more outgoing messages.
|
||||
while (!output_queue_.empty()) {
|
||||
#ifdef FUZZING
|
||||
Singleton<mozilla::ipc::Faulty>::get()->MaybeCollectAndClosePipe(pipe_);
|
||||
mozilla::ipc::Faulty::instance().MaybeCollectAndClosePipe(pipe_);
|
||||
#endif
|
||||
Message* msg = output_queue_.front();
|
||||
|
||||
|
@ -782,7 +782,7 @@ bool Channel::ChannelImpl::Send(Message* message) {
|
|||
#endif
|
||||
|
||||
#ifdef FUZZING
|
||||
message = Singleton<mozilla::ipc::Faulty>::get()->MutateIPCMessage("Channel::ChannelImpl::Send", message);
|
||||
message = mozilla::ipc::Faulty::instance().MutateIPCMessage("Channel::ChannelImpl::Send", message);
|
||||
#endif
|
||||
|
||||
// If the channel has been closed, ProcessOutgoingMessages() is never going
|
||||
|
|
|
@ -351,6 +351,14 @@ Faulty::MutationFactor()
|
|||
return sPropValue;
|
||||
}
|
||||
|
||||
// static
|
||||
Faulty&
|
||||
Faulty::instance()
|
||||
{
|
||||
static Faulty faulty;
|
||||
return faulty;
|
||||
}
|
||||
|
||||
//
|
||||
// Strategy: Pipes
|
||||
//
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include "base/string16.h"
|
||||
#include "base/singleton.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -44,6 +43,8 @@ class Faulty
|
|||
static nsresult ReadFile(const char* aPathname, nsTArray<nsCString> &aArray);
|
||||
static void CopyFDs(IPC::Message* aDstMsg, IPC::Message* aSrcMsg);
|
||||
|
||||
static Faulty& instance();
|
||||
|
||||
// Fuzzing methods for Pickle.
|
||||
void FuzzBool(bool* aValue, unsigned int aProbability=sDefaultProbability);
|
||||
void FuzzChar(char* aValue, unsigned int aProbability=sDefaultProbability);
|
||||
|
@ -92,7 +93,6 @@ class Faulty
|
|||
static const bool sIsLoggingEnabled;
|
||||
|
||||
Faulty();
|
||||
friend struct DefaultSingletonTraits<Faulty>;
|
||||
DISALLOW_EVIL_CONSTRUCTORS(Faulty);
|
||||
|
||||
static bool IsValidProcessType(void);
|
||||
|
|
Загрузка…
Ссылка в новой задаче