summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKeith Winstein <208955+keithw@users.noreply.github.com>2024-11-08 07:45:07 -0800
committerGitHub <noreply@github.com>2024-11-08 07:45:07 -0800
commit765b47d02aac894da80b74284263d1b487415aa0 (patch)
tree9e7275ddf2f8f3326c3a779e30a3aa963159ffa7 /include
parentc1d97e9c75c687faa81fe0ab4f1ac77c30487f47 (diff)
downloadwabt-765b47d02aac894da80b74284263d1b487415aa0.tar.gz
wabt-765b47d02aac894da80b74284263d1b487415aa0.tar.bz2
wabt-765b47d02aac894da80b74284263d1b487415aa0.zip
Add support for the custom-page-sizes proposal (#2502)
This adds support in the binary/text parsers and writers, the validator and interpreter, and objdump (but not wasm2c).
Diffstat (limited to 'include')
-rw-r--r--include/wabt/binary-reader-logging.h7
-rw-r--r--include/wabt/binary-reader-nop.h7
-rw-r--r--include/wabt/binary-reader.h7
-rw-r--r--include/wabt/binary.h7
-rw-r--r--include/wabt/common.h20
-rw-r--r--include/wabt/feature.def1
-rw-r--r--include/wabt/interp/interp-inl.h7
-rw-r--r--include/wabt/interp/interp.h3
-rw-r--r--include/wabt/ir.h1
-rw-r--r--include/wabt/shared-validator.h2
-rw-r--r--include/wabt/token.def1
-rw-r--r--include/wabt/wast-parser.h1
12 files changed, 44 insertions, 20 deletions
diff --git a/include/wabt/binary-reader-logging.h b/include/wabt/binary-reader-logging.h
index fee211f9..fd166011 100644
--- a/include/wabt/binary-reader-logging.h
+++ b/include/wabt/binary-reader-logging.h
@@ -74,7 +74,8 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
std::string_view module_name,
std::string_view field_name,
Index memory_index,
- const Limits* page_limits) override;
+ const Limits* page_limits,
+ uint32_t page_size) override;
Result OnImportGlobal(Index import_index,
std::string_view module_name,
std::string_view field_name,
@@ -102,7 +103,9 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result BeginMemorySection(Offset size) override;
Result OnMemoryCount(Index count) override;
- Result OnMemory(Index index, const Limits* limits) override;
+ Result OnMemory(Index index,
+ const Limits* limits,
+ uint32_t page_size) override;
Result EndMemorySection() override;
Result BeginGlobalSection(Offset size) override;
diff --git a/include/wabt/binary-reader-nop.h b/include/wabt/binary-reader-nop.h
index c7ec78b1..85906062 100644
--- a/include/wabt/binary-reader-nop.h
+++ b/include/wabt/binary-reader-nop.h
@@ -89,7 +89,8 @@ class BinaryReaderNop : public BinaryReaderDelegate {
std::string_view module_name,
std::string_view field_name,
Index memory_index,
- const Limits* page_limits) override {
+ const Limits* page_limits,
+ uint32_t page_size) override {
return Result::Ok;
}
Result OnImportGlobal(Index import_index,
@@ -130,7 +131,9 @@ class BinaryReaderNop : public BinaryReaderDelegate {
/* Memory section */
Result BeginMemorySection(Offset size) override { return Result::Ok; }
Result OnMemoryCount(Index count) override { return Result::Ok; }
- Result OnMemory(Index index, const Limits* limits) override {
+ Result OnMemory(Index index,
+ const Limits* limits,
+ uint32_t page_size) override {
return Result::Ok;
}
Result EndMemorySection() override { return Result::Ok; }
diff --git a/include/wabt/binary-reader.h b/include/wabt/binary-reader.h
index 3d48f574..90161264 100644
--- a/include/wabt/binary-reader.h
+++ b/include/wabt/binary-reader.h
@@ -125,7 +125,8 @@ class BinaryReaderDelegate {
std::string_view module_name,
std::string_view field_name,
Index memory_index,
- const Limits* page_limits) = 0;
+ const Limits* page_limits,
+ uint32_t page_size) = 0;
virtual Result OnImportGlobal(Index import_index,
std::string_view module_name,
std::string_view field_name,
@@ -156,7 +157,9 @@ class BinaryReaderDelegate {
/* Memory section */
virtual Result BeginMemorySection(Offset size) = 0;
virtual Result OnMemoryCount(Index count) = 0;
- virtual Result OnMemory(Index index, const Limits* limits) = 0;
+ virtual Result OnMemory(Index index,
+ const Limits* limits,
+ uint32_t page_size) = 0;
virtual Result EndMemorySection() = 0;
/* Global section */
diff --git a/include/wabt/binary.h b/include/wabt/binary.h
index ecf11a79..98575f96 100644
--- a/include/wabt/binary.h
+++ b/include/wabt/binary.h
@@ -24,7 +24,12 @@
#define WABT_BINARY_LIMITS_HAS_MAX_FLAG 0x1
#define WABT_BINARY_LIMITS_IS_SHARED_FLAG 0x2
#define WABT_BINARY_LIMITS_IS_64_FLAG 0x4
-#define WABT_BINARY_LIMITS_ALL_FLAGS \
+#define WABT_BINARY_LIMITS_HAS_CUSTOM_PAGE_SIZE_FLAG 0x8
+#define WABT_BINARY_LIMITS_ALL_MEMORY_FLAGS \
+ (WABT_BINARY_LIMITS_HAS_MAX_FLAG | WABT_BINARY_LIMITS_IS_SHARED_FLAG | \
+ WABT_BINARY_LIMITS_IS_64_FLAG | \
+ WABT_BINARY_LIMITS_HAS_CUSTOM_PAGE_SIZE_FLAG)
+#define WABT_BINARY_LIMITS_ALL_TABLE_FLAGS \
(WABT_BINARY_LIMITS_HAS_MAX_FLAG | WABT_BINARY_LIMITS_IS_SHARED_FLAG | \
WABT_BINARY_LIMITS_IS_64_FLAG)
diff --git a/include/wabt/common.h b/include/wabt/common.h
index 12b2eb09..6962f06d 100644
--- a/include/wabt/common.h
+++ b/include/wabt/common.h
@@ -44,14 +44,18 @@
#define WABT_USE(x) static_cast<void>(x)
// 64k
-#define WABT_PAGE_SIZE 0x10000
-// # of pages that fit in 32-bit address space
-#define WABT_MAX_PAGES32 0x10000
-// # of pages that fit in 64-bit address space
-#define WABT_MAX_PAGES64 0x1000000000000
-#define WABT_BYTES_TO_PAGES(x) ((x) >> 16)
-#define WABT_ALIGN_UP_TO_PAGE(x) \
- (((x) + WABT_PAGE_SIZE - 1) & ~(WABT_PAGE_SIZE - 1))
+#define WABT_DEFAULT_PAGE_SIZE 0x10000
+
+inline uint64_t WABT_BYTES_TO_MIN_PAGES(uint64_t num_bytes,
+ uint32_t page_size) {
+ if ((page_size == 0) ||
+ (page_size & (page_size - 1))) { // malformed page sizes
+ WABT_UNREACHABLE;
+ return 0;
+ }
+ uint64_t num_pages = num_bytes / page_size;
+ return (page_size * num_pages == num_bytes) ? num_pages : num_pages + 1;
+}
#define WABT_ENUM_COUNT(name) \
(static_cast<int>(name::Last) - static_cast<int>(name::First) + 1)
diff --git a/include/wabt/feature.def b/include/wabt/feature.def
index 00a4e7f2..ac96377b 100644
--- a/include/wabt/feature.def
+++ b/include/wabt/feature.def
@@ -40,3 +40,4 @@ WABT_FEATURE(memory64, "memory64", false, "64-bit me
WABT_FEATURE(multi_memory, "multi-memory", false, "Multi-memory")
WABT_FEATURE(extended_const, "extended-const", false, "Extended constant expressions")
WABT_FEATURE(relaxed_simd, "relaxed-simd", false, "Relaxed SIMD")
+WABT_FEATURE(custom_page_sizes, "custom-page-sizes", false, "Custom page sizes")
diff --git a/include/wabt/interp/interp-inl.h b/include/wabt/interp/interp-inl.h
index 1f3402c6..a9ac4a34 100644
--- a/include/wabt/interp/interp-inl.h
+++ b/include/wabt/interp/interp-inl.h
@@ -64,11 +64,12 @@ inline bool MemoryType::classof(const ExternType* type) {
return type->kind == skind;
}
-inline MemoryType::MemoryType(Limits limits)
- : ExternType(ExternKind::Memory), limits(limits) {
+inline MemoryType::MemoryType(Limits limits, uint32_t page_size)
+ : ExternType(ExternKind::Memory), limits(limits), page_size(page_size) {
// Always set max.
if (!limits.has_max) {
- this->limits.max = limits.is_64 ? WABT_MAX_PAGES64 : WABT_MAX_PAGES32;
+ this->limits.max = WABT_BYTES_TO_MIN_PAGES(
+ (limits.is_64 ? UINT64_MAX : UINT32_MAX), page_size);
}
}
diff --git a/include/wabt/interp/interp.h b/include/wabt/interp/interp.h
index 069bedaa..821a5391 100644
--- a/include/wabt/interp/interp.h
+++ b/include/wabt/interp/interp.h
@@ -206,7 +206,7 @@ struct MemoryType : ExternType {
static const ExternKind skind = ExternKind::Memory;
static bool classof(const ExternType* type);
- explicit MemoryType(Limits);
+ explicit MemoryType(Limits, uint32_t);
std::unique_ptr<ExternType> Clone() const override;
@@ -215,6 +215,7 @@ struct MemoryType : ExternType {
std::string* out_msg);
Limits limits;
+ uint32_t page_size;
};
struct GlobalType : ExternType {
diff --git a/include/wabt/ir.h b/include/wabt/ir.h
index 80e1c2a8..e300b66c 100644
--- a/include/wabt/ir.h
+++ b/include/wabt/ir.h
@@ -947,6 +947,7 @@ struct Memory {
std::string name;
Limits page_limits;
+ uint32_t page_size;
};
struct DataSegment {
diff --git a/include/wabt/shared-validator.h b/include/wabt/shared-validator.h
index 32add012..df02b594 100644
--- a/include/wabt/shared-validator.h
+++ b/include/wabt/shared-validator.h
@@ -75,7 +75,7 @@ class SharedValidator {
Result OnFunction(const Location&, Var sig_var);
Result OnTable(const Location&, Type elem_type, const Limits&);
- Result OnMemory(const Location&, const Limits&);
+ Result OnMemory(const Location&, const Limits&, uint32_t page_size);
Result OnGlobalImport(const Location&, Type type, bool mutable_);
Result OnGlobal(const Location&, Type type, bool mutable_);
Result OnTag(const Location&, Var sig_var);
diff --git a/include/wabt/token.def b/include/wabt/token.def
index 1fd3d0e5..53d1fabb 100644
--- a/include/wabt/token.def
+++ b/include/wabt/token.def
@@ -57,6 +57,7 @@ WABT_TOKEN(NanArithmetic, "nan:arithmetic")
WABT_TOKEN(NanCanonical, "nan:canonical")
WABT_TOKEN(Offset, "offset")
WABT_TOKEN(Output, "output")
+WABT_TOKEN(PageSize, "pagesize")
WABT_TOKEN(Param, "param")
WABT_TOKEN(Ref, "ref")
WABT_TOKEN(Quote, "quote")
diff --git a/include/wabt/wast-parser.h b/include/wabt/wast-parser.h
index 36447c58..8ba71e47 100644
--- a/include/wabt/wast-parser.h
+++ b/include/wabt/wast-parser.h
@@ -147,6 +147,7 @@ class WastParser {
Result ParseMemidx(Location loc, Var* memidx);
Result ParseLimitsIndex(Limits*);
Result ParseLimits(Limits*);
+ Result ParsePageSize(uint32_t*);
Result ParseNat(uint64_t*, bool is_64);
Result ParseModuleFieldList(Module*);