diff --git a/AstSemantics.md b/AstSemantics.md index 47dc81de..8b051b0a 100644 --- a/AstSemantics.md +++ b/AstSemantics.md @@ -71,7 +71,7 @@ be an untyped array of bytes, and it is unspecified how embedders map this array into their process' own [virtual memory][]. The linear memory is sandboxed; it does not alias the execution engine's internal data structures, the execution stack, local variables, or other process memory. The initial state of linear -memory is specified by the [module](Modules.md#initial-state-of-linear-memory). +memory is specified by the [module](Modules.md#linear-memory-section). [virtual memory]: https://en.wikipedia.org/wiki/Virtual_memory diff --git a/BinaryEncoding.md b/BinaryEncoding.md index f9276310..1e80f716 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -103,8 +103,9 @@ Yes: - A sequence of byte ranges within the binary and corresponding addresses in the linear memory -All strings are encoded as null-terminated UTF8. -Data segments represent initialized data that is loaded directly from the binary into the linear memory when the program starts (see [modules](Modules.md#initial-state-of-linear-memory)). +All strings are encoded as null-terminated UTF8. Data segments represent +initialized data that is loaded directly from the binary into the linear memory +when the program starts (see [modules](Modules.md#linear-memory-section)). ## Serialized AST diff --git a/Modules.md b/Modules.md index 1bcbe45c..ead86eb8 100644 --- a/Modules.md +++ b/Modules.md @@ -8,7 +8,7 @@ is determined by the module it was loaded from. A module contains: * a set of [imports and exports](Modules.md#imports-and-exports); -* a section defining the [initial state of linear memory](Modules.md#initial-state-of-linear-memory); +* a section defining [linear memory](Modules.md#linear-memory-section); * a section containing [code](Modules.md#code-section); * after the MVP, sections containing [debugging/symbol information](Tooling.md) or a reference to separate files containing them; and @@ -122,12 +122,23 @@ shared `malloc` and coordinated global address ranges). Instead, the [dynamic linking future feature](DynamicLinking.md) is intended to allow *explicitly* injecting multiple modules into the same instance. -## Initial state of linear memory +## Linear memory section -A module will contain a section declaring the linear memory size (initial and -maximum size allowed by [`grow_memory`](AstSemantics.md#resizing) and the -initial contents of memory, analogous to `.data`, `.rodata`, `.bss` sections in -native executables (see [binary encoding](BinaryEncoding.md#global-structure)). +A module may contain an optional section declaring the use of linear memory +by the module. If the section is absent, the linear memory operators +`load`, `store`, `memory_size`, and `grow_memory` may not be used in the module. + +The linear memory section declares the initial [memory size](AstSemantics.md#linear-memory) +(which may be subsequently increased by [`grow_memory`](AstSemantics.md#resizing)). + +The initial contents of linear memory are zero by default. However, the memory +section contains a possibly-empty array of *segments* (analogous to `.data`) +which can specify the initial contents of fixed `(offset, length)` ranges of +memory. + +The linear memory section may also contain an optional hint declaring the expected +maximum heap usage. This hint is not semantically visible but can help a +WebAssembly engine to optimize `grow_memory`. ## Code section diff --git a/Rationale.md b/Rationale.md index 7920ebd7..0bb56bad 100644 --- a/Rationale.md +++ b/Rationale.md @@ -112,6 +112,11 @@ to communicate their own implementation details in a useful manner to the developer. +## Linear memory disabled if no linear memory section + +See [#107](https://github.com/WebAssembly/spec/pull/107). + + ## Control Flow See [#299](https://github.com/WebAssembly/design/pull/299).