WebAssembly / WebAssembly/binaryen

undefined asyncify_get_state

Open
#7,317 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

Is there currently a recommended way to go about calling asyncify_get_state from inside native code? To manage this with other methods currently I'm doing:

#ifndef ASYNCJMP_SUPPORT_ASYNCIFY_H
#define ASYNCJMP_SUPPORT_ASYNCIFY_H

__attribute__((import_module("asyncify"), import_name("start_unwind"))) void asyncify_start_unwind(void *buf);
#define asyncify_start_unwind(buf)         \
    do                                     \
    {                                      \
        extern void *pl_asyncify_unwind_buf; \
        pl_asyncify_unwind_buf = (buf);      \
        asyncify_start_unwind((buf));      \
    } while (0)

__attribute__((import_module("asyncify"), import_name("stop_unwind"))) void asyncify_stop_unwind(void);
#define asyncify_stop_unwind()             \
    do                                     \
    {                                      \
        extern void *pl_asyncify_unwind_buf; \
        pl_asyncify_unwind_buf = NULL;       \
        asyncify_stop_unwind();            \
    } while (0)

__attribute__((import_module("asyncify"), import_name("start_rewind"))) void asyncify_start_rewind(void *buf);

__attribute__((import_module("asyncify"), import_name("stop_rewind"))) void asyncify_stop_rewind(void);

__attribute__((import_module("asyncify"), import_name("get_state"))) int asyncify_get_state(void);

#endif

Which all get successfully turned into exports. But for asyncify_get_state the pass raises an error:

 "/opt/wasm-opt" zeroperl_unopt -O3 -o zeroperl_unopt
Fatal: call to unidenfied asyncify import: get_state

What I'm trying to achieve:

__attribute__((noinline))
ssize_t __wrap_read(int fd, void *buf, size_t count) {
    if (asyncify_get_state() == 2) {
        asyncify_stop_rewind();
        if (have_saved_result) {
            have_saved_result = false; 
            return saved_result;
        }
        return -1;
    }

    ssize_t r = sfs_read(fd, buf, count);
    if (r >= 0) {
        return r; // Fast path succeeded
    }
    
    
    ssize_t real_val = __real_read(fd, buf, count);

        if (asyncify_get_state() == 1) {
            saved_result     = real_val;
            have_saved_result = true;

            asyncify_stop_unwind();

            return real_val;
        }


        return real_val;

}

I'm using binaryen-version_121

edit:

looking at the pass more closely I can see get_state is missing from here & here, but the documentation says that it should be there

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the Asyncify pass handling referenced at src/passes/Asyncify.cpp lines 562-573 and 610-629 with the documentation around line 172. Reproduce the failure using the shown native declarations and wasm-opt with binaryen-version_121. Done means asyncify_get_state is handled consistently with the documented interface and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, wasm
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.