Skip to content

Commit d6d2c1f

Browse files
authored
Add new DataCount section (WebAssembly#42)
1 parent 1276e58 commit d6d2c1f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

proposals/bulk-memory-operations/Overview.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,47 @@ instr ::= ...
360360
| `table.init` | `0xfc 0x0c` | `table:0x00`, `segment:varuint32` | :thinking: copy from a passive element segment to a table |
361361
| `table.drop` | `0xfc 0x0d` | `segment:varuint32` | :thinking: prevent further use of a passive element segment |
362362
| `table.copy` | `0xfc 0x0e` | `table:0x00` | :thinking: copy from one region of a table to another region |
363+
364+
### `DataCount` section
365+
366+
The WebAssembly binary format is designed to be validated in a single pass. If
367+
a section requires information to validate, it is guaranteed that this
368+
information will be present in a previous section.
369+
370+
The `memory.{init,drop}` instructions break this guarantee. Both of these
371+
instructions are used in the `Code` section. They each have a data segment
372+
index immediate, but the vector of data segments is not available until the
373+
`Data` section is parsed, which occurs after the `Code` section.
374+
375+
To keep single-pass validation, the number of data segments defined in the
376+
`Data` section must be available before the `Code` section. This information is
377+
provided in a new `DataCount` section with the code `12`.
378+
379+
Like all sections, the `DataCount` section is optional. If present, it must
380+
appear in the following order:
381+
382+
| Section Name | Code | Description |
383+
| ------------ | ---- | ----------- |
384+
| Type | `1` | Function signature declarations |
385+
| Import | `2` | Import declarations |
386+
| Function | `3` | Function declarations |
387+
| Table | `4` | Indirect function table and other tables |
388+
| Memory | `5` | Memory attributes |
389+
| Global | `6` | Global declarations |
390+
| Export | `7` | Exports |
391+
| Start | `8` | Start function declaration |
392+
| Element | `9` | Elements section |
393+
| DataCount | `13` | Data segment count |
394+
| Code | `10` | Function bodies (code) |
395+
| Data | `11` | Data segments |
396+
397+
The `DataCount` section has just one field that specifies the number of data
398+
segments in the `Data` section:
399+
400+
| Field | Type | Description |
401+
| ----- | ---- | ----------- |
402+
| count | `varuint32` | count of data segments in `Data` section |
403+
404+
It is a validation error if `count` is not equal to the number of data segments
405+
in the `Data` section. It is also a validation error if the `DataCount` section
406+
is omitted and a `memory.init` or `memory.drop` instruction is used.

0 commit comments

Comments
 (0)