E.2. Function pointers

WebAssembly modules have an optional Table known section, which is a typed array of references, like functions, that can’t be stored in memory as raw bytes for security reasons. If the addresses were stored in the module’s memory, there would be a chance that a malicious module would try to modify an address to access data that it shouldn’t have access to.

When a module’s code wants to access the data referenced in the Table section, it asks for the WebAssembly framework to operate on the item at a specific index in the table. The WebAssembly framework then reads the address stored at that index and performs the action.

The Table section is defined with an s-expression that starts with a label using the word table, followed ...

Get WebAssembly in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.