95cdb3c573
As Wasm module can live longer than the isolate that initially created them, it generally makes sense to use the WasmEngine's accounting allocator for the decoded WasmModule. Instead of passing that allocator through many functions, we can just get it directly from the one global WasmEngine when we need it. R=ahaas@chromium.org Change-Id: I552f8e19072f2305a3186b821c2f5b3969eac83f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4071464 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#84611}
78 lines
2.9 KiB
C++
78 lines
2.9 KiB
C++
// Copyright 2020 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 "src/objects/objects-inl.h"
|
|
#include "src/wasm/module-decoder.h"
|
|
#include "src/wasm/wasm-engine.h"
|
|
#include "src/wasm/wasm-features.h"
|
|
#include "src/wasm/wasm-limits.h"
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace wasm {
|
|
namespace module_decoder_unittest {
|
|
|
|
#define EXPECT_OK(result) \
|
|
do { \
|
|
if (!result.ok()) { \
|
|
GTEST_NONFATAL_FAILURE_(result.error().message().c_str()); \
|
|
return; \
|
|
} \
|
|
} while (false)
|
|
|
|
class Memory64DecodingTest : public TestWithIsolateAndZone {
|
|
public:
|
|
ModuleResult DecodeModule(std::initializer_list<uint8_t> module_body_bytes) {
|
|
// Add the wasm magic and version number automatically.
|
|
std::vector<uint8_t> module_bytes{WASM_MODULE_HEADER};
|
|
module_bytes.insert(module_bytes.end(), module_body_bytes);
|
|
static constexpr WasmFeatures kEnabledFeatures{
|
|
WasmFeature::kFeature_memory64};
|
|
return DecodeWasmModule(kEnabledFeatures, base::VectorOf(module_bytes),
|
|
false, kWasmOrigin);
|
|
}
|
|
};
|
|
|
|
TEST_F(Memory64DecodingTest, MemoryLimitLEB64) {
|
|
// 2 bytes LEB (32-bit range), no maximum.
|
|
ModuleResult result = DecodeModule(
|
|
{SECTION(Memory, ENTRY_COUNT(1), kMemory64NoMaximum, U32V_2(5))});
|
|
EXPECT_OK(result);
|
|
EXPECT_EQ(5u, result.value()->initial_pages);
|
|
EXPECT_EQ(false, result.value()->has_maximum_pages);
|
|
|
|
// 2 bytes LEB (32-bit range), with maximum.
|
|
result = DecodeModule({SECTION(Memory, ENTRY_COUNT(1), kMemory64WithMaximum,
|
|
U32V_2(7), U32V_2(47))});
|
|
EXPECT_OK(result);
|
|
EXPECT_EQ(7u, result.value()->initial_pages);
|
|
EXPECT_EQ(true, result.value()->has_maximum_pages);
|
|
EXPECT_EQ(47u, result.value()->maximum_pages);
|
|
|
|
// 10 bytes LEB, 32-bit range, no maximum.
|
|
result = DecodeModule(
|
|
{SECTION(Memory, ENTRY_COUNT(1), kMemory64NoMaximum, U64V_10(2))});
|
|
EXPECT_OK(result);
|
|
EXPECT_EQ(2u, result.value()->initial_pages);
|
|
EXPECT_EQ(false, result.value()->has_maximum_pages);
|
|
|
|
// 10 bytes LEB, 32-bit range, with maximum.
|
|
result = DecodeModule({SECTION(Memory, ENTRY_COUNT(1), kMemory64WithMaximum,
|
|
U64V_10(2), U64V_10(6))});
|
|
EXPECT_OK(result);
|
|
EXPECT_EQ(2u, result.value()->initial_pages);
|
|
EXPECT_EQ(true, result.value()->has_maximum_pages);
|
|
EXPECT_EQ(6u, result.value()->maximum_pages);
|
|
|
|
// TODO(clemensb): Test numbers outside the 32-bit range once that's
|
|
// supported.
|
|
}
|
|
|
|
} // namespace module_decoder_unittest
|
|
} // namespace wasm
|
|
} // namespace internal
|
|
} // namespace v8
|