Skip to content

undefined asyncify_get_state #7317

@andrewmd5

Description

@andrewmd5

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

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