Skip to content

Memory size and consistency issues #889

Closed

Description

@saambarati

Here are a few issues I'm running into when implementing the spec.

  • During instantiation, what if memory.size is less than the module's declared min size

  • During instantiation, what if memory.size is greater than the module's declared max size

  • During instantiation, what if memory.maxSize is greater than the module's declared max size
    and related to this:
    What if we grow a memory past one of its instances' module's declared maximum.

  • What if “initial” > “maximum” inside WebAssembly.Memory constructor.

  • What if a module declares more than 1 memory import

  • What if a module has no memory import and it declares functions that use loads/stores

Some related links:
Instantiation and how it handles memory:
https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-constructor

Memory construction:
https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemory-constructor

Memory growth:
https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemoryprototypegrow

Activity

  1. rossberg commented on Dec 8, 2016

    @rossberg
    Member
  2. rossberg commented on Dec 8, 2016

    @rossberg
    Member

    Adding missing tests in WebAssembly/spec#395.

  3. rossberg commented on Dec 8, 2016

    @rossberg
    Member

    PR #890 should address the omission specific to JS.md.

  4. saambarati commented on Dec 8, 2016

    @saambarati
    Author

    @rossberg-chromium
    Thanks for sharing https://github.com/WebAssembly/spec/blob/master/interpreter/spec/eval.ml#L380, it addresses my concerns.

    On a related note, it seems sketchy to me that spec that is expected to throw JavaScript exceptions calls into some ML code that does the validation (and does some kind of error raising). I think this validation and exception throwing should be explicit in the JavaScript portion of the spec. Specifically, I think the import loop inside Instance creation should do the consistency checks in JS and throw specified JS exceptions.

  5. dschuff commented on Dec 8, 2016

    @dschuff
    Member

    There are 2 answers, if I'm understanding your question right. First, the JS spec is somewhat separate from the wasm spec proper. The core wasm spec says what conditions should result in validation failure, or runtime trap, etc, but doesn't say how the embedding environment (e.g. JS) should handle those. JS.md says what a JS environment should do, but an embedding of wasm into a non-JS environment should still be able to implement the core spec.
    Also spec interpreter is intended to express e.g. the conditions that cause validation failures or traps, but nobody has to call into that particular ML code. Browsers or other wasm engines just implement the same behavior (and additionally implement the JS exceptions as specified in the JS.md text). Eventually (soon, we hope) we will also have a text version of the core wasm spec which will have the same level of detail as the spec interpreter.

  6. saambarati commented on Dec 8, 2016

    @saambarati
    Author

    @dschuff Ok, thanks for clarifying. This is how I've been approaching the JS/interpreter separation. However, I guess I'm somewhat annoyed many validation errors inside the interpreter have no corresponding exception in the JS API. I think the JS API should be fully specified in which exceptions it throws. Right now, this isn't even close to how the spec is written.

  7. rossberg commented on Dec 9, 2016

    @rossberg
    Member

    @saambarati, what @dschuff is saying is that there is a factorisation. The core spec defines validation (and other semantics), while JS.md only defines the behaviour specific to the JS embedding. It wouldn't be good to duplicate parts of the specification.

    Wrt validation errors, in a JS embedding they all manifest as a CompileError exception during compilation, see the description of the WebAssembly.Module constructor in JS.md.

  8. saambarati commented on Dec 9, 2016

    @saambarati
    Author

    @rossberg-chromium I'm specifically talking about Instance construction, not Module construction. I believe there needs to be some text saying what happens for validation errors inside Instance construction inside JS.md.

  9. rossberg commented on Dec 9, 2016

    @rossberg
    Member

    @saambarati, there are no validation errors during instance construction. You only get RuntimeErrors at that point. Those are likewise part of the core semantics.

  10. saambarati commented on Dec 9, 2016

    @saambarati
    Author

    @rossberg-chromium I think we're talking past each other at this point. Let me be very specific in my question: I'm a JS embedding, when I find a contradiction during Instance creation for when an imported Memory doesn't meet the requirements of the declared import, which JavaScript exception do I throw?

    If the answer to this question is look at the ML interpreter, we at the very least need the text to correspond various ML errors with actual JS errors.

  11. rossberg commented on Dec 9, 2016

    @rossberg
    Member

    @saambarati, I see. I agree that this isn't really specified in JS.md but should be.

    @lukewagner, WDYT? Some initialisation failures (e.g. from data sections) are stated to cause a RangeError. Import type mismatches could throw a TypeError. Both seems a bit ad-hoc. Is that okay or should we perhaps introduce a dedicated LinkError exception, to mirror CompileError and RuntimeError, and distinguish from JS level errors?

    I think V8 currently raises RuntimeError in the missing cases, but that may not be ideal, since that is intended for traps (but may arise from executing the start function).

  12. saambarati commented on Dec 9, 2016

    @saambarati
    Author

    My vote is for something like a WebAssembly.LinkError

  13. lukewagner commented on Dec 9, 2016

    @lukewagner
    Member

    We also currently throw both TypeError and RangeError during instantiation. Converting all these to WebAssembly.LinkErrors sgtm. This might also be useful to distinguish instantiation errors from errors thrown by the call to the start function at the end.

  14. rossberg commented on Dec 12, 2016

    @rossberg
    Member

    Okay, cool. See #901 for a PR.

  15. jfbastien commented on Dec 15, 2016

    @jfbastien
    Member

    Is this resolved now that we have WebAssembly.LinkError?

  16. rossberg commented on Dec 16, 2016

    @rossberg
    Member

    I would think so. @saambarati, anything missing?

  17. saambarati commented on Jan 3, 2017

    @saambarati
    Author

    LGTM. I'm closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions