So once we have reference types we can use those types for fd but currently we can also enforce nearly the same behavior as if we had reference types by annotating functions. This would enable the host system to enforce the integrity of fd across module instances.
For example lets say we have to have 2 wasm instances (a, b) that share no memory or tables but instance a imports some exported functions from instance b. If those exported functions expected fd in its augments, those augments would be annotated in a custom section so that when a called b the host would enforce that values were valid fd.
The custom sections could looks something like the following
LANGUAGE_TYPES = {
'i32': 0x7f,
'i64': 0x7e,
'f32': 0x7d,
'f64': 0x7c,
'fd': 0x7b,
'anyFunc': 0x70,
'func': 0x60,
'block_type': 0x40,
}
The custom section has a name of "wasi.type".
The typeMap section maps the custom types to functions. And is encoded as follows
| Field |
Type |
Description |
| count |
varuint32 |
count of type entries to follow |
| entries |
map* |
repeated type entries mapping a function to a custom type |
And a map is Encoded as follows and named "wasi.typeMap".
| Field |
Type |
Description |
| function |
varuint32 |
the index of the function using the custom type |
| type |
varuint32 |
the index of the custom type |
Lastly the custom type information for globals are encoded as follows. The section name is "wasi.globals"
| Field |
Type |
Description |
| index |
varuint32 |
the index of the global |
| type |
varuint32 |
the type of the global |
So once we have reference types we can use those types for
fdbut currently we can also enforce nearly the same behavior as if we had reference types by annotating functions. This would enable the host system to enforce the integrity offdacross module instances.For example lets say we have to have 2 wasm instances (a, b) that share no memory or tables but instance
aimports some exported functions from instanceb. If those exported functions expectedfdin its augments, those augments would be annotated in a custom section so that whenacalledbthe host would enforce that values were validfd.The custom sections could looks something like the following
The custom section has a name of "wasi.type".
The typeMap section maps the custom types to functions. And is encoded as follows
varuint32map*And a map is Encoded as follows and named "wasi.typeMap".
varuint32varuint32Lastly the custom type information for globals are encoded as follows. The section name is "wasi.globals"
varuint32varuint32