Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 30092f1

Browse files
alexcrichtonbinji
authored andcommitted
Update binary encoding to use varuint32 for flags (#35)
This commit fixes #34 by specifying that the flags field (which indicates if a segment is passive) is a `varuint32` instead of a `uint8`. It was discovered in #34 that the memory index located at that position today is a `varuint32`, which can be validly encoded as `0x80 0x00` in addition to `0x00` (in addition to a number of other encodings). This means that if the first field were repurposed as a single byte of flags, it would break these existing modules that work today. It's not currently known how many modules in the wild actually take advantage of such an encoding, but it's probably better to be safe than sorry! Closes #34
1 parent b73c079 commit 30092f1

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

proposals/bulk-memory-operations/Overview.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,12 @@ currently has a collection of segments, each of which has a memory index, an
168168
initializer expression for its offset, and its raw data.
169169

170170
Since WebAssembly currently does not allow for multiple memories, the memory
171-
index of each segment must be zero, which when represented as a `varuint32` is
172-
a single zero byte. We can repurpose this byte as a flags field.
171+
index of each segment must be zero. We can repurpose this 32-bit integer as a
172+
flags field where new meaning is attached to nonzero values.
173173

174-
When the least-significant bit of this new flags field is `1`, this segment is
175-
_passive_. A passive segment will not be automatically copied into the
176-
memory or table on instantiation, and must instead be applied manually using
177-
the following new instructions:
174+
When the new flags field is `1`, this segment is _passive_. A passive segment
175+
will not be automatically copied into the memory or table on instantiation, and
176+
must instead be applied manually using the following new instructions:
178177

179178
* `memory.init`: copy a region from a data segment
180179
* `table.init`: copy a region from an element segment
@@ -195,7 +194,7 @@ The new encoding of a data segment is now:
195194

196195
| Field | Type | Description |
197196
|------|-------|-------------|
198-
| flags | `uint8` | Flags for passive and presence of fields below, only values of 0, 1, and 2 are valid |
197+
| flags | `varuint32` | Flags for passive and presence of fields below, only values of 0, 1, and 2 are valid |
199198
| index | `varuint32`? | Memory index this segment is for, only present if `flags` is 2, otherwise the index is implicitly 0 |
200199
| offset | `init_expr`? | an `i32` initializer expression for offset, not present if `flags & 0x1` is set |
201200
| size | `varuint32` | size of `data` (in bytes) |

0 commit comments

Comments
 (0)