Skip to content

Report load/store address and memory size on out-of-bounds memory traps #3120

@fitzgen

Description

@fitzgen

Feature

When a Wasm program traps due to an out-of-bounds memory access, report the address that the Wasm attempted to access and the memory size, eg:

wasm trap: out of bounds memory access
    memory size (bytes) = 65536
    trap address = 999999

Benefit

This will make debugging such bugs much easier.

Implementation

We can get the faulting address via si_addr which I thiiiink is all we need. Wasm can't access two different memories with the same native address (or else what should have been a trap for one memory might accidentally succeed in accessing a different memory) so guard pages should always be associated with one particular memory. We just have to grab the current instance, iterate over its memories and find which one this guard page is associated with. Once we have that, we do a little arithmetic to translate the native address to a Wasm address.

Hopefully mach ports give us similar info. Completely unsure about windows. This seems like the kind of thing where it isn't the end of the world if we only get this info on some platforms, since it is just a debugging helper.

When we are using explicit bounds checks, it seems like we can just emit code to embed this data into the trap directly.

Alternatives

Build valgrind-esque tooling into Wasmtime? Add a mode to trace all heap accesses before we actually do the access and potentially trap?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions