v8/test/common/assembler-tester.h
Andreas Haas 3d2bc5d041 Reland: [wasm] Add more unit tests for trap handler
The problem were missing V8_EXPORT_PRIVATE and V8_EXPORT.

The unittests test if the trap handler only handles those traps it
is supposed to handle:
* Only handle traps when the thread-in-wasm flag is set.
* Only handle traps of the right type, i.e. memory access violations.
* Only handle traps at recorded instructions.

The tests also test the consistency of the thread-in-wasm flag. I made
one change in the trap handler where that consistency could be
violated.

All tests are executed with the default trap handler provided by V8,
and with the trap handler callback installed in a test signal/exception
handler.

Patchset 1 is the original CL.

R=mstarzinger@chromium.org

Change-Id: I172d94f24cdba4c3a1f7f344825b059dbb59da79
Reviewed-on: https://chromium-review.googlesource.com/c/1351024
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57947}
2018-11-29 16:33:10 +00:00

63 lines
2.4 KiB
C++

// Copyright 2018 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.
#ifndef V8_TEST_COMMON_ASSEMBLER_TESTER_H_
#define V8_TEST_COMMON_ASSEMBLER_TESTER_H_
#include "src/assembler.h"
namespace v8 {
namespace internal {
static inline uint8_t* AllocateAssemblerBuffer(
size_t* allocated,
size_t requested = v8::internal::AssemblerBase::kMinimalBufferSize,
void* address = nullptr) {
size_t page_size = v8::internal::AllocatePageSize();
size_t alloc_size = RoundUp(requested, page_size);
void* result = AllocatePages(GetPlatformPageAllocator(), address, alloc_size,
page_size, v8::PageAllocator::kReadWrite);
CHECK(result);
*allocated = alloc_size;
return static_cast<uint8_t*>(result);
}
static inline void FreeAssemblerBuffer(uint8_t* buffer, size_t size) {
CHECK(FreePages(GetPlatformPageAllocator(), buffer, size));
}
static inline void MakeAssemblerBufferExecutable(uint8_t* buffer,
size_t allocated) {
// Flush the instruction cache as part of making the buffer executable.
// Note: we do this before setting permissions to ReadExecute because on
// some older ARM kernels there is a bug which causes an access error on
// cache flush instructions to trigger access error on non-writable memory.
// See https://bugs.chromium.org/p/v8/issues/detail?id=8157
Assembler::FlushICache(buffer, allocated);
bool result = SetPermissions(GetPlatformPageAllocator(), buffer, allocated,
v8::PageAllocator::kReadExecute);
CHECK(result);
}
static inline void MakeAssemblerBufferWritable(uint8_t* buffer,
size_t allocated) {
bool result = SetPermissions(GetPlatformPageAllocator(), buffer, allocated,
v8::PageAllocator::kReadWrite);
CHECK(result);
}
// TODO(wasm): Only needed for the "test-jump-table-assembler.cc" tests.
static inline void MakeAssemblerBufferWritableAndExecutable(uint8_t* buffer,
size_t allocated) {
bool result = SetPermissions(GetPlatformPageAllocator(), buffer, allocated,
v8::PageAllocator::kReadWriteExecute);
CHECK(result);
}
} // namespace internal
} // namespace v8
#endif // V8_TEST_COMMON_ASSEMBLER_TESTER_H_