[wasm] [fuzzer] Avoid 'using namespace'
This violates the style guide, and causes problems for jumbo builds. R=ahaas@chromium.org CC=mostynb@opera.com Bug: chromium:746958 Change-Id: Ic583c41b94bfd9ecdb31a9ccadb2e842861fe7f4 Reviewed-on: https://chromium-review.googlesource.com/647710 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#47774}
This commit is contained in:
parent
57375079cd
commit
bf9196493f
@ -18,20 +18,12 @@
|
||||
#include "test/common/wasm/wasm-module-runner.h"
|
||||
#include "test/fuzzer/fuzzer-support.h"
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wheader-hygiene"
|
||||
#endif
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
class WasmModuleObject;
|
||||
|
||||
using namespace v8::internal;
|
||||
using namespace v8::internal::wasm;
|
||||
using namespace v8::internal::wasm::testing;
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
namespace wasm {
|
||||
namespace fuzzer {
|
||||
|
||||
#define ASSIGN(type, var, expr) \
|
||||
v8::Local<type> var; \
|
||||
@ -44,12 +36,6 @@ using namespace v8::internal::wasm::testing;
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
class WasmModuleObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
// We need this helper function because we cannot use
|
||||
// Handle<WasmModuleObject>::cast here. To use this function we would have to
|
||||
@ -59,44 +45,43 @@ Handle<WasmModuleObject> ToWasmModuleObjectUnchecked(Handle<Object> that) {
|
||||
}
|
||||
}
|
||||
|
||||
void InstantiateCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
void InstantiateCallback(const FunctionCallbackInfo<Value>& args) {
|
||||
DCHECK_GE(args.Length(), 1);
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::MicrotasksScope does_not_run_microtasks(
|
||||
MicrotasksScope does_not_run_microtasks(
|
||||
isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
|
||||
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
v8::Local<v8::Value> module = args[0];
|
||||
Local<v8::Value> module = args[0];
|
||||
|
||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||
|
||||
ScheduledErrorThrower thrower(i_isolate, "WebAssembly Instantiation");
|
||||
|
||||
i::Handle<i::WasmModuleObject> module_obj = ToWasmModuleObjectUnchecked(
|
||||
v8::Utils::OpenHandle(v8::Object::Cast(*module)));
|
||||
i::MaybeHandle<WasmInstanceObject> maybe_instance =
|
||||
i::wasm::SyncInstantiate(i_isolate, &thrower, module_obj,
|
||||
Handle<JSReceiver>::null(), // imports
|
||||
MaybeHandle<JSArrayBuffer>()); // memory
|
||||
Handle<WasmModuleObject> module_obj =
|
||||
ToWasmModuleObjectUnchecked(Utils::OpenHandle(v8::Object::Cast(*module)));
|
||||
MaybeHandle<WasmInstanceObject> maybe_instance =
|
||||
SyncInstantiate(i_isolate, &thrower, module_obj,
|
||||
Handle<JSReceiver>::null(), // imports
|
||||
MaybeHandle<JSArrayBuffer>()); // memory
|
||||
Handle<WasmInstanceObject> instance;
|
||||
if (!maybe_instance.ToHandle(&instance)) {
|
||||
return;
|
||||
}
|
||||
RunWasmModuleForTesting(i_isolate, instance, 0, nullptr);
|
||||
testing::RunWasmModuleForTesting(i_isolate, instance, 0, nullptr);
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
v8::internal::FlagScope<bool> turn_on_async_compile(
|
||||
FlagScope<bool> turn_on_async_compile(
|
||||
&v8::internal::FLAG_wasm_async_compilation, true);
|
||||
v8::internal::FlagScope<uint32_t> max_mem_flag_scope(
|
||||
&v8::internal::FLAG_wasm_max_mem_pages, 32);
|
||||
v8::internal::FlagScope<uint32_t> max_table_size_scope(
|
||||
FlagScope<uint32_t> max_mem_flag_scope(&v8::internal::FLAG_wasm_max_mem_pages,
|
||||
32);
|
||||
FlagScope<uint32_t> max_table_size_scope(
|
||||
&v8::internal::FLAG_wasm_max_table_size, 100);
|
||||
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
|
||||
v8::Isolate* isolate = support->GetIsolate();
|
||||
v8::internal::Isolate* i_isolate =
|
||||
reinterpret_cast<v8::internal::Isolate*>(isolate);
|
||||
i::Isolate* i_isolate = reinterpret_cast<v8::internal::Isolate*>(isolate);
|
||||
|
||||
// Clear any pending exceptions from a prior run.
|
||||
if (i_isolate->has_pending_exception()) {
|
||||
@ -105,30 +90,35 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
|
||||
v8::Isolate::Scope isolate_scope(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
HandleScope internal_scope(i_isolate);
|
||||
i::HandleScope internal_scope(i_isolate);
|
||||
v8::Context::Scope context_scope(support->GetContext());
|
||||
v8::TryCatch try_catch(isolate);
|
||||
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
|
||||
TryCatch try_catch(isolate);
|
||||
testing::SetupIsolateForWasmModule(i_isolate);
|
||||
|
||||
// Get the promise for async compilation.
|
||||
ASSIGN(v8::Promise::Resolver, resolver,
|
||||
v8::Promise::Resolver::New(support->GetContext()));
|
||||
v8::Local<v8::Promise> promise = resolver->GetPromise();
|
||||
ASSIGN(Promise::Resolver, resolver,
|
||||
Promise::Resolver::New(support->GetContext()));
|
||||
Local<Promise> promise = resolver->GetPromise();
|
||||
|
||||
AsyncCompile(i_isolate, v8::Utils::OpenHandle(*promise),
|
||||
AsyncCompile(i_isolate, Utils::OpenHandle(*promise),
|
||||
ModuleWireBytes(data, data + size));
|
||||
|
||||
ASSIGN(v8::Function, instantiate_impl,
|
||||
v8::Function::New(support->GetContext(), &InstantiateCallback,
|
||||
v8::Undefined(isolate)));
|
||||
ASSIGN(Function, instantiate_impl,
|
||||
Function::New(support->GetContext(), &InstantiateCallback,
|
||||
Undefined(isolate)));
|
||||
|
||||
ASSIGN(v8::Promise, result,
|
||||
ASSIGN(Promise, result,
|
||||
promise->Then(support->GetContext(), instantiate_impl));
|
||||
|
||||
// Wait for the promise to resolve.
|
||||
while (result->State() == v8::Promise::kPending) {
|
||||
support->PumpMessageLoop(v8::platform::MessageLoopBehavior::kWaitForWork);
|
||||
while (result->State() == Promise::kPending) {
|
||||
support->PumpMessageLoop(platform::MessageLoopBehavior::kWaitForWork);
|
||||
isolate->RunMicrotasks();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace fuzzer
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -21,20 +21,10 @@
|
||||
#define MAX_NUM_FUNCTIONS 3
|
||||
#define MAX_NUM_PARAMS 3
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wheader-hygiene"
|
||||
#endif
|
||||
|
||||
using namespace v8::internal;
|
||||
using namespace v8::internal::wasm;
|
||||
using namespace v8::internal::wasm::fuzzer;
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
namespace wasm {
|
||||
namespace fuzzer {
|
||||
|
||||
class WasmCallFuzzer : public WasmExecutionFuzzer {
|
||||
template <typename V>
|
||||
@ -43,17 +33,16 @@ class WasmCallFuzzer : public WasmExecutionFuzzer {
|
||||
// that a value of type V can be read without problems.
|
||||
*ok &= (*size > sizeof(V));
|
||||
if (!(*ok)) return 0;
|
||||
V result = v8::internal::ReadLittleEndianValue<V>(*data);
|
||||
V result = ReadLittleEndianValue<V>(*data);
|
||||
*data += sizeof(V);
|
||||
*size -= sizeof(V);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void add_argument(
|
||||
v8::internal::Isolate* isolate, ValueType type,
|
||||
WasmValue* interpreter_args,
|
||||
v8::internal::Handle<v8::internal::Object>* compiler_args, int* argc,
|
||||
const uint8_t** data, size_t* size, bool* ok) {
|
||||
static void add_argument(Isolate* isolate, ValueType type,
|
||||
WasmValue* interpreter_args,
|
||||
Handle<Object>* compiler_args, int* argc,
|
||||
const uint8_t** data, size_t* size, bool* ok) {
|
||||
if (!(*ok)) return;
|
||||
switch (type) {
|
||||
case kWasmF32: {
|
||||
@ -112,8 +101,7 @@ class WasmCallFuzzer : public WasmExecutionFuzzer {
|
||||
compiler_args.get(), &num_args, &data, &size, &ok);
|
||||
}
|
||||
}
|
||||
v8::internal::wasm::WasmFunctionBuilder* f =
|
||||
builder.AddFunction(sig_builder.Build());
|
||||
WasmFunctionBuilder* f = builder.AddFunction(sig_builder.Build());
|
||||
uint32_t code_size = static_cast<uint32_t>(size / num_functions);
|
||||
f->EmitCode(data, code_size);
|
||||
uint8_t end_opcode = kExprEnd;
|
||||
@ -121,7 +109,7 @@ class WasmCallFuzzer : public WasmExecutionFuzzer {
|
||||
data += code_size;
|
||||
size -= code_size;
|
||||
if (fun == 0) {
|
||||
builder.AddExport(v8::internal::CStrVector("main"), f);
|
||||
builder.AddExport(CStrVector("main"), f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,3 +127,8 @@ class WasmCallFuzzer : public WasmExecutionFuzzer {
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
return WasmCallFuzzer().FuzzWasmModule(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzer
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -13,20 +13,10 @@
|
||||
#include "test/common/wasm/test-signatures.h"
|
||||
#include "test/fuzzer/wasm-fuzzer-common.h"
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wheader-hygiene"
|
||||
#endif
|
||||
|
||||
using namespace v8::internal;
|
||||
using namespace v8::internal::wasm;
|
||||
using namespace v8::internal::wasm::fuzzer;
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
namespace wasm {
|
||||
namespace fuzzer {
|
||||
|
||||
class WasmCodeFuzzer : public WasmExecutionFuzzer {
|
||||
virtual bool GenerateModule(
|
||||
@ -58,3 +48,8 @@ class WasmCodeFuzzer : public WasmExecutionFuzzer {
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
return WasmCodeFuzzer().FuzzWasmModule(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzer
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -23,20 +23,10 @@
|
||||
|
||||
typedef uint8_t byte;
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wheader-hygiene"
|
||||
#endif
|
||||
|
||||
using namespace v8::internal;
|
||||
using namespace v8::internal::wasm;
|
||||
using namespace v8::internal::wasm::fuzzer;
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
namespace wasm {
|
||||
namespace fuzzer {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -123,7 +113,7 @@ class WasmGenerator {
|
||||
}
|
||||
|
||||
public:
|
||||
WasmGenerator(v8::internal::wasm::WasmFunctionBuilder* fn) : builder_(fn) {}
|
||||
WasmGenerator(WasmFunctionBuilder* fn) : builder_(fn) {}
|
||||
|
||||
void Generate(ValueType type, DataRange data);
|
||||
|
||||
@ -138,7 +128,7 @@ class WasmGenerator {
|
||||
}
|
||||
|
||||
private:
|
||||
v8::internal::wasm::WasmFunctionBuilder* builder_;
|
||||
WasmFunctionBuilder* builder_;
|
||||
std::vector<ValueType> blocks_;
|
||||
};
|
||||
|
||||
@ -319,15 +309,14 @@ class WasmCompileFuzzer : public WasmExecutionFuzzer {
|
||||
|
||||
WasmModuleBuilder builder(zone);
|
||||
|
||||
v8::internal::wasm::WasmFunctionBuilder* f =
|
||||
builder.AddFunction(sigs.i_iii());
|
||||
WasmFunctionBuilder* f = builder.AddFunction(sigs.i_iii());
|
||||
|
||||
WasmGenerator gen(f);
|
||||
gen.Generate<kWasmI32>(DataRange(data, static_cast<uint32_t>(size)));
|
||||
|
||||
uint8_t end_opcode = kExprEnd;
|
||||
f->EmitCode(&end_opcode, 1);
|
||||
builder.AddExport(v8::internal::CStrVector("main"), f);
|
||||
builder.AddExport(CStrVector("main"), f);
|
||||
|
||||
builder.SetMaxMemorySize(32);
|
||||
builder.WriteTo(buffer);
|
||||
@ -346,3 +335,8 @@ class WasmCompileFuzzer : public WasmExecutionFuzzer {
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
return WasmCompileFuzzer().FuzzWasmModule(data, size);
|
||||
}
|
||||
|
||||
} // namespace fuzzer
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -16,30 +16,18 @@
|
||||
|
||||
#define WASM_CODE_FUZZER_HASH_SEED 83
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wheader-hygiene"
|
||||
#endif
|
||||
|
||||
using namespace v8::internal;
|
||||
using namespace v8::internal::wasm;
|
||||
using namespace v8::internal::wasm::fuzzer;
|
||||
|
||||
#if __clang__
|
||||
// TODO(mostynb@opera.com): remove the using statements and these pragmas.
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
namespace wasm {
|
||||
namespace fuzzer {
|
||||
|
||||
static const char* kNameString = "name";
|
||||
static const size_t kNameStringLength = 4;
|
||||
|
||||
int v8::internal::wasm::fuzzer::FuzzWasmSection(SectionCode section,
|
||||
const uint8_t* data,
|
||||
size_t size) {
|
||||
int FuzzWasmSection(SectionCode section, const uint8_t* data, size_t size) {
|
||||
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
|
||||
v8::Isolate* isolate = support->GetIsolate();
|
||||
v8::internal::Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
||||
i::Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
||||
|
||||
// Clear any pending exceptions from a prior run.
|
||||
if (i_isolate->has_pending_exception()) {
|
||||
@ -79,7 +67,6 @@ int v8::internal::wasm::fuzzer::FuzzWasmSection(SectionCode section,
|
||||
}
|
||||
|
||||
int WasmExecutionFuzzer::FuzzWasmModule(
|
||||
|
||||
const uint8_t* data, size_t size) {
|
||||
// Save the flag so that we can change it and restore it later.
|
||||
bool generate_test = FLAG_wasm_code_fuzzer_gen_test;
|
||||
@ -104,7 +91,7 @@ int WasmExecutionFuzzer::FuzzWasmModule(
|
||||
}
|
||||
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
|
||||
v8::Isolate* isolate = support->GetIsolate();
|
||||
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
||||
i::Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
||||
|
||||
// Clear any pending exceptions from a prior run.
|
||||
if (i_isolate->has_pending_exception()) {
|
||||
@ -129,7 +116,7 @@ int WasmExecutionFuzzer::FuzzWasmModule(
|
||||
return 0;
|
||||
}
|
||||
|
||||
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
|
||||
testing::SetupIsolateForWasmModule(i_isolate);
|
||||
|
||||
ErrorThrower interpreter_thrower(i_isolate, "Interpreter");
|
||||
ModuleWireBytes wire_bytes(buffer.begin(), buffer.end());
|
||||
@ -155,7 +142,7 @@ int WasmExecutionFuzzer::FuzzWasmModule(
|
||||
os << "})();" << std::endl;
|
||||
}
|
||||
|
||||
bool validates = wasm::SyncValidate(i_isolate, wire_bytes);
|
||||
bool validates = SyncValidate(i_isolate, wire_bytes);
|
||||
|
||||
if (compiles != validates) {
|
||||
uint32_t hash = StringHasher::HashSequentialString(
|
||||
@ -220,3 +207,8 @@ int WasmExecutionFuzzer::FuzzWasmModule(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace fuzzer
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
Loading…
Reference in New Issue
Block a user