@@ -241,6 +241,24 @@ An `elem_expr` is like an `init_expr`, but can only contain expressions of the f
241
241
242
242
TODO: coordinate with other proposals to determine the binary encoding for ` ref.null ` and ` ref.func ` .
243
243
244
+ ### Segment Initialization
245
+
246
+ In the MVP, segments are initialized during module instantiation. If any segment
247
+ would be initialized out-of-bounds, then the memory or table instance is not
248
+ modified.
249
+
250
+ This behavior is changed in the bulk memory proposal.
251
+
252
+ Each active segment is initialized in module-definition order. For each
253
+ segment, each byte in the data segment is copied into the memory, in order of
254
+ lowest to highest addresses. If, for a given byte, the copy is out-of-bounds,
255
+ instantiation fails and no further bytes in this segment nor further segments
256
+ are copied. Bytes written before this point stay written.
257
+
258
+ The behavior of element segment initialization is changed similarly, with the
259
+ difference that elements are copied from element segments into tables, instead
260
+ of bytes being copied from data segments into memories.
261
+
244
262
### ` memory.init ` instruction
245
263
246
264
The ` memory.init ` instruction copies data from a given passive segment into a target
@@ -252,12 +270,6 @@ The instruction has the signature `[i32 i32 i32] -> []`. The parameters are, in
252
270
- top-1: offset into the source segment
253
271
- top-0: size of memory region in bytes
254
272
255
- When ` memory.init ` is executed, its behavior matches the steps described in
256
- step 11 of
257
- [ instantiation] ( https://webassembly.github.io/spec/exec/modules.html#instantiation ) ,
258
- but it behaves as though the segment were specified with the source offset,
259
- target offset, and length as given by the ` memory.init ` operands.
260
-
261
273
It is a validation error to use ` memory.init ` with an out-of-bounds segment index.
262
274
263
275
A trap occurs if:
0 commit comments