Skip to content

Remove sbrk from MVP, add mmap&friends to AstSemantics #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 25 additions & 4 deletions AstSemantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ memory storage indexed by the effective address, and extending for the number
of bytes implied by the memory type attribute of the access.

If any of the accessed bytes are beyond `memory_size`, the access is considered
*out-of-bounds*. A module may optionally define that out-of-bounds includes
small effective addresses close to `0`
(see [discussion](https://github.com/WebAssembly/design/issues/204)).
The semantics of out-of-bounds accesses are discussed
*out-of-bounds*. The semantics of out-of-bounds accesses are discussed
[below](AstSemantics.md#out-of-bounds).

The use of infinite-precision in the effective address computation means that
Expand All @@ -154,6 +151,30 @@ by [available resources](Nondeterminism.md)). In the future, to support
[>4GiB linear memory](FutureFeatures.md#heaps-bigger-than-4gib), support for
indices with type `int64` will be added.

### Adjusting memory size and permissions: `mmap`

In the MVP the size of linear memory is fixed: The initial size of linear
memory will remain unchanged for the life of that WebAssembly module. Later,
Copy link
Member

Choose a reason for hiding this comment

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

How is the size specified?

Copy link
Member Author

Choose a reason for hiding this comment

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

How as in "where" or "what units", or something else?

I assume the current docs imply it is specified in the wasm binary somewhere, "total memory is 4MB".

Copy link
Member

Choose a reason for hiding this comment

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

What I suggested in #227 for "removing magic" was that it's specified by developer's code, typically in _start, using mmap. We can heavily restrict mmap so that it's not super capable in MVP, but I'd really like to avoid magical number in the binary that wasm implementations have to effectively translate to mmap for the rest of time. That gets weird when we do add mmap later!

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the wasm binary is going to have a data segment, and that has to be written in after memory is set up. It seems like that means that if the user has manual control of mmap for the initial size of memory, that they would also need to have manual control of copying the data into memory, so that they can do so afterwards. Do we actually want that?

Copy link
Member

Choose a reason for hiding this comment

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

The loader would handle those, with mmap. I guess there still is magic, but it's regular and familiar so I like it.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean by "loader" here?

Copy link
Member

Choose a reason for hiding this comment

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

The wasm equivalent of ld. The part that maps the initial address space and code, and does relocations. I'm assuming it'll also trigger the JIT-compilation, perform code caching, ...

we will support a limited form of `mmap` which can:

* Allocate pages of memory, in order to increase or decrease
the amount of available memory to the WebAssembly module.
* Adjust the permissions of a page of memory, for example to make
small effective addresses close to `0` behave as if they are
[out-of-bounds](AstSemantics.md#out-of-bounds)
(see [discussion](https://github.com/WebAssembly/design/issues/204)).

In addition to the `mmap` operation, applications will also have access to

* `munmap`, to unmap `mmap`ed pages, and
* `mmap_get_page_size`, to detect the system page size (this may not
provide accurate information about the underlying system, but it
should be good enough for purposes of calling `mmap`).

In the future,
[further `mmap` functionality](FutureFeatures.md#finer-grained-control-over-memory)
may be added.

### Alignment

Each linear memory access operation also has an immediate positive integer power
Expand Down
1 change: 0 additions & 1 deletion MVP.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ isomorphic to the [binary format](BinaryEncoding.md).
necessary for two WebAssembly modules to share the same linear memory.
* Modules can specify memory size and initialization data (`data`, `rodata`,
`bss`) in the [memory-initialization section](MVP.md#module-structure).
* Modules can specify whether memory is growable (via `sbrk`).
* Modules can optionally export memory, allowing it to be aliased by the
embedder, such as JavaScript:
* JavaScript sees the exported memory as an `ArrayBuffer`.
Expand Down