Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AstSemantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions BinaryEncoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 17 additions & 6 deletions Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what purpose this serves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually summarizing a previous spec PR which forgot to update design repo to match.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you mention this in Rationale.md?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean adding a link to the spec PR or copying the summary from the spec PR to Rationale.md?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other places in Rationale.md link to GH, so I'll do the former.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, was hanging out with @sunfishcode :-)
I just meant to explain why you can't validate memory operations when you don't have memory declared.


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

Expand Down
5 changes: 5 additions & 0 deletions Rationale.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, the PR explains things pretty well :-)



## Control Flow

See [#299](https://github.com/WebAssembly/design/pull/299).
Expand Down