2016-06-14 21:38:21 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/assembler-inl.h"
|
|
|
|
#include "src/objects-inl.h"
|
2016-06-14 21:38:21 +00:00
|
|
|
#include "src/v8.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#include "test/cctest/compiler/c-signature.h"
|
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2016-06-14 21:38:21 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2017-09-21 03:29:52 +00:00
|
|
|
namespace test_run_wasm_relocation {
|
2016-06-14 21:38:21 +00:00
|
|
|
|
2017-10-25 12:46:43 +00:00
|
|
|
WASM_COMPILED_EXEC_TEST(RunPatchWasmContext) {
|
|
|
|
WasmRunner<uint32_t, uint32_t> r(execution_mode);
|
2017-10-16 08:49:45 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2016-06-14 21:38:21 +00:00
|
|
|
|
2017-10-16 08:49:45 +00:00
|
|
|
r.builder().AddGlobal<uint32_t>();
|
|
|
|
r.builder().AddGlobal<uint32_t>();
|
|
|
|
|
|
|
|
BUILD(r, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_GET_GLOBAL(0));
|
|
|
|
CHECK_EQ(1, r.builder().CodeTableLength());
|
|
|
|
|
|
|
|
// Run with the old global data.
|
|
|
|
CHECK_EQ(113, r.Call(113));
|
2016-06-14 21:38:21 +00:00
|
|
|
|
2017-10-16 08:49:45 +00:00
|
|
|
WasmContext* old_wasm_context =
|
|
|
|
r.builder().instance_object()->wasm_context()->get();
|
|
|
|
Address old_wasm_context_address =
|
|
|
|
reinterpret_cast<Address>(old_wasm_context);
|
|
|
|
|
|
|
|
uint32_t new_global_data[3] = {0, 0, 0};
|
2017-12-15 19:47:29 +00:00
|
|
|
WasmContext new_wasm_context;
|
|
|
|
new_wasm_context.globals_start = reinterpret_cast<byte*>(new_global_data);
|
2017-10-16 08:49:45 +00:00
|
|
|
|
2017-11-06 15:52:24 +00:00
|
|
|
{
|
|
|
|
// TODO(6792): No longer needed once WebAssembly code is off heap.
|
|
|
|
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
|
|
|
|
|
|
|
|
// Patch in a new WasmContext that points to the new global data.
|
|
|
|
int filter = 1 << RelocInfo::WASM_CONTEXT_REFERENCE;
|
|
|
|
bool patched = false;
|
|
|
|
Handle<Code> code = r.GetWrapperCode();
|
|
|
|
for (RelocIterator it(*code, filter); !it.done(); it.next()) {
|
|
|
|
CHECK_EQ(old_wasm_context_address, it.rinfo()->wasm_context_reference());
|
|
|
|
it.rinfo()->set_wasm_context_reference(
|
|
|
|
isolate, reinterpret_cast<Address>(&new_wasm_context));
|
|
|
|
patched = true;
|
|
|
|
}
|
|
|
|
CHECK(patched);
|
|
|
|
Assembler::FlushICache(isolate, code->instruction_start(),
|
|
|
|
code->instruction_size());
|
2017-10-16 08:49:45 +00:00
|
|
|
}
|
2017-09-01 12:57:34 +00:00
|
|
|
|
2017-10-16 08:49:45 +00:00
|
|
|
// Run with the new global data.
|
|
|
|
CHECK_EQ(115, r.Call(115));
|
|
|
|
CHECK_EQ(115, new_global_data[0]);
|
|
|
|
}
|
2017-09-08 13:59:05 +00:00
|
|
|
|
2017-09-21 03:29:52 +00:00
|
|
|
} // namespace test_run_wasm_relocation
|
2017-09-01 12:57:34 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|