ExecutableAllocationFuzz.cpp [plain text]
#include "config.h"
#include "ExecutableAllocationFuzz.h"
#include "TestRunnerUtils.h"
#include <wtf/Atomics.h>
#include <wtf/DataLog.h>
namespace JSC {
static Atomic<unsigned> s_numberOfExecutableAllocationFuzzChecks;
unsigned numberOfExecutableAllocationFuzzChecks()
{
return s_numberOfExecutableAllocationFuzzChecks.load();
}
ExecutableAllocationFuzzResult doExecutableAllocationFuzzing()
{
ASSERT(Options::enableExecutableAllocationFuzz());
unsigned oldValue;
unsigned newValue;
do {
oldValue = s_numberOfExecutableAllocationFuzzChecks.load();
newValue = oldValue + 1;
} while (!s_numberOfExecutableAllocationFuzzChecks.compareExchangeWeak(oldValue, newValue));
if (newValue == Options::fireExecutableAllocationFuzzAt()) {
if (Options::verboseExecutableAllocationFuzz()) {
dataLog("Will pretend to fail executable allocation.\n");
WTFReportBacktrace();
}
return PretendToFailExecutableAllocation;
}
if (Options::fireExecutableAllocationFuzzAtOrAfter()
&& newValue >= Options::fireExecutableAllocationFuzzAtOrAfter()) {
if (Options::verboseExecutableAllocationFuzz()) {
dataLog("Will pretend to fail executable allocation.\n");
WTFReportBacktrace();
}
return PretendToFailExecutableAllocation;
}
return AllowNormalExecutableAllocation;
}
}