Skip to content

Dynamic Asyncify Data End #49

Open

Description

@nerfZael

Asyncify currently has a fixed data end pointer.
It should be a dynamic one that changes based on the built modules ASYNCIFY_STACK_SIZE.

export class AsyncWasmInstance {
  public static requiredExports: readonly string[] = [
    "asyncify_start_unwind",
    "asyncify_stop_unwind",
    "asyncify_start_rewind",
    "asyncify_stop_rewind",
    "asyncify_get_state",
  ];

  private static _dataAddr = 16;
  private static _dataStart = AsyncWasmInstance._dataAddr + 8;
  private static _dataEnd = 24576;

Activity

  1. dOrgJelli commented on Jun 26, 2023

    @dOrgJelli
    Contributor

    Two ways I can think of doing this (one more preferred IMO than the other).

    Preferred: extract this value from the binary. We're already doing this when trying to determine the initial memory page size here.

    We'll need to analyze the wasm binary to find the best way to do this. I'd recommend the following approach:

    • build module "foo" twice, with two different ASYNCIFY_STACK_SIZEs
    • convert both to WAT
    • diff, and see where the stack size is stored (most likely in the "length" property of a global buffer instance)

    If we can extract this stack size in a deterministic way with all asyncify-compiled modules, then we should continue with this approach.

    Fallback: Inject a getter into the wasm binary upon compilation. Maybe something like _wrap_compiler_config which returns a tuple of (version, config). In the initial implementation, version would be 0x01 and config would be a single value $ASYNCIFY_STACK_SIZE.

  2. dOrgJelli commented on Jun 26, 2023

    @dOrgJelli
    Contributor

    EDIT! before proceeding with the above, we should probably revisit this code here:

    new Int32Array(memory.buffer, AsyncWasmInstance._dataAddr).set([
    AsyncWasmInstance._dataStart,
    AsyncWasmInstance._dataEnd,
    ]);

    It could actually be the case that we're overwriting existing values in the wasm module with our hard-coded ones in JS.

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