Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASMFS OPFS not working with ASYNCIFY=1 #23133

Open
irfan2502 opened this issue Dec 12, 2024 · 0 comments
Open

WASMFS OPFS not working with ASYNCIFY=1 #23133

irfan2502 opened this issue Dec 12, 2024 · 0 comments

Comments

@irfan2502
Copy link

Please include the following in your bug report:

Version of emscripten/emsdk:
clang version 19.0.0git (https:/github.com/llvm/llvm-project 7cfffe74eeb68fbb3fb9706ac7071f8caeeb6520)
Target: wasm32-unknown-emscripten
Thread model: posix

Failing command line in full:
NA

Full link command and output with -v appended:
emcc fs.cpp -o fs.html -sWASMFS -g -sASYNCIFY=1 -O3

I am trying to compile below code with ASYNCIFY=1. But, I am getting the error shown below. With JSPI (ASYNCIFY=2), the same code works perfectly. The same code works perfectly with -pthread -sPROXY_TO_PTHREAD option as well. It doesn't work only with ASYNCIFY=1

fs.js:50 Uncaught RuntimeError: unreachable
    at fs.wasm.(anonymous namespace)::OPFSDirectory::getChild(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>> const&) (http://localhost:2502/fs.wasm:wasm-function[1878]:0x51b36)
    at fs.wasm.wasmfs::Directory::Handle::getChild(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>> const&) (http://localhost:2502/fs.wasm:wasm-function[1986]:0x57a06)
    at fs.wasm.doOpen(wasmfs::path::ParsedParent, int, unsigned int, wasmfs::Backend*, OpenReturnMode) (http://localhost:2502/fs.wasm:wasm-function[2032]:0x60f8b)
    at fs.wasm.__syscall_openat (http://localhost:2502/fs.wasm:wasm-function[2038]:0x626f8)
    at fs.wasm.fopen (http://localhost:2502/fs.wasm:wasm-function[93]:0x622d)
    at fs.wasm.std::__2::basic_filebuf<char, std::__2::char_traits<char>>::open(char const*, unsigned int) (http://localhost:2502/fs.wasm:wasm-function[281]:0xbe26)
    at fs.wasm.__original_main (http://localhost:2502/fs.wasm:wasm-function[43]:0x1a33)
    at fs.wasm.main (http://localhost:2502/fs.wasm:wasm-function[49]:0x2a00)
    at ret.<computed> (http://localhost:2502/fs.js:1994:24)
    at Module._main (http://localhost:2502/fs.js:2275:90)
#include <iostream>
#include <fstream>

#include <emscripten/wasmfs.h>

int main() {
    try {
        backend_t opfs = wasmfs_create_opfs_backend();
        std::cout << "created OPFS backend\n";

        auto err = wasmfs_create_directory("/opfs", 0777, opfs);
        std::cout << "mounted OPFS root directory with error code " << err << "\n";

        // File path to write in OPFS
        std::string path = "/opfs/example.txt";

        std::ofstream outfile(path);
        outfile << "Sample content" << std::endl;
        outfile.close();

        // Read the file
        std::ifstream infile(path);
        std::string content((std::istreambuf_iterator<char>(infile)),
                            std::istreambuf_iterator<char>());
        std::cout << "File content: " << content << std::endl;
        
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant