Skip to content

Need help with accessing WASI API #2396

Closed

Description

@adityaprasadv1
  • Node.js Version: 13.5.0
  • OS: Windows 10
  • Module: WASI

In the given example, can we get the source code of the wasm file.

Activity

  1. gireeshpunathil commented on Jan 7, 2020

    @gireeshpunathil
    Member

    cc @nodejs/wasi

  2. gengjiawen commented on Jan 7, 2020

    @gengjiawen
    Member

    You can try the wasm files here: nodejs/node@09b1228#diff-5a38107d7dabcebcb78af5059b242974.

    Change the related name should work.

  3. adityaprasadv1 commented on Jan 7, 2020

    @adityaprasadv1
    Author

    We compiled the following C code using WasmExplorer

    #include <assert.h>
    #include <stdio.h>
    #include <string.h>
    
    static char* message = "hello, file!";
    
    int main() {
      FILE* file = fopen("C:/test.txt", "w");
      assert(file != NULL);
    
      int nwritten = fprintf(file, "%s", message);
      assert(nwritten == strlen(message));
      int r = fclose(file);
      assert(r == 0);
    }
    

    index.js

    const fs = require('fs');
    const { WASI } = require('wasi');
    const wasi = new WASI({
      args: process.argv,
      env: process.env,
      preopens: {
        '/sandbox': '.'
      }
    });
    const importObject = { wasi_unstable: wasi.wasiImport };
    
    (async () => {
      const wasm = await WebAssembly.compile(fs.readFileSync('./test.wasm'));
      const instance = await WebAssembly.instantiate(wasm, importObject);
    
      wasi.start(instance);
    })();
    

    We get the following error,

    > node --experimental-wasi-unstable-preview0 --experimental-wasm-bigint index.js
    
    npm[7056]: c:\ws\src\node_wasi.cc:92: Assertion `(uvwasi_init(&uvw_, options)) == (0)' failed.
     1: 00007FF7F21CDCDF napi_wrap+126063
     2: 00007FF7F216D156 v8::base::CPU::has_sse+36198
     3: 00007FF7F216D473 v8::base::CPU::has_sse+36995
     4: 00007FF7F20F9B46 v8::internal::wasm::JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit+10886
     5: 00007FF7F20FEEE0 v8::internal::wasm::JSToWasmWrapperCompilationUnit::~JSToWasmWrapperCompilationUnit+32288
     6: 00007FF7F2948360 v8::internal::Builtins::builtin_handle+326608
     7: 00007FF7F294751C v8::internal::Builtins::builtin_handle+322956
     8: 00007FF7F2947BB2 v8::internal::Builtins::builtin_handle+324642
     9: 00007FF7F29479EE v8::internal::Builtins::builtin_handle+324190
    10: 00007FF7F2DDECAD v8::internal::SetupIsolateDelegate::SetupHeap+517677
    11: 00007FF7F2D66331 v8::internal::SetupIsolateDelegate::SetupHeap+23729
    12: 00007FF7F2E4A32B v8::internal::SetupIsolateDelegate::SetupHeap+957611
    13: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    14: 00007FF7F2D66237 v8::internal::SetupIsolateDelegate::SetupHeap+23479
    15: 00007FF7F2E4A32B v8::internal::SetupIsolateDelegate::SetupHeap+957611
    16: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    17: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    18: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    19: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    20: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    21: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    22: 00007FF7F2D6A4EB v8::internal::SetupIsolateDelegate::SetupHeap+40555
    23: 00007FF7F2D6804E v8::internal::SetupIsolateDelegate::SetupHeap+31182
    24: 00007FF7F2D67C3C v8::internal::SetupIsolateDelegate::SetupHeap+30140
    25: 00007FF7F28A0402 v8::internal::Execution::CallWasm+1410
    26: 00007FF7F289FD79 v8::internal::Execution::Call+185
    27: 00007FF7F2973860 v8::Function::Call+608
    28: 00007FF7F2195411 node::Start+1153
    29: 00007FF7F2195647 node::Start+1719
    30: 00007FF7F219463A node::LoadEnvironment+26
    31: 00007FF7F2138392 v8::internal::AsmJsScanner::GetIdentifierString+29458
    32: 00007FF7F21950B0 node::Start+288
    33: 00007FF7F2046ABC RC4_options+340412
    34: 00007FF7F2E9C5D8 v8::internal::SetupIsolateDelegate::SetupHeap+1294168
    35: 00007FFED36A7BD4 BaseThreadInitThunk+20
    36: 00007FFED382CED1 RtlUserThreadStart+33
    npm ERR! code ELIFECYCLE
    npm ERR! errno 134
    npm ERR! node-wasi-example@1.0.0 start: `node --experimental-wasi-unstable-preview0 --experimental-wasm-bigint index.js`npm ERR! Exit status 134
    npm ERR!
    npm ERR! Failed at the node-wasi-example@1.0.0 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm WARN Local package.json exists, but node_modules missing, did you mean to install?
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\Aditya\AppData\Roaming\npm-cache\_logs\2020-01-07T14_16_56_915Z-debug.log
    

    Thank you.

  4. legendecas commented on Jan 7, 2020

    @legendecas
    Member

    AFAICT, WasmExplorer doesn't emit wasm that using WASI APIs. And the assertion is related to nodejs/node#31076, which has not yet been released.

  5. legendecas commented on Jan 7, 2020

    @legendecas
    Member

    Note that you could try toolchains provided in https://github.com/CraneStation/wasi-sdk to compile a C/C++ project to wasm-wasi target, which can be used with Node.js wasi module.

  6. gengjiawen commented on Jan 7, 2020

    @gengjiawen
    Member

    you need absolute path in preopens

  7. PoojaDurgad commented on Sep 29, 2020

    @PoojaDurgad

    ping , @adityaprasadv1 - were you able to follow the suggestions? or still outstanding?

  8. gireeshpunathil commented on Nov 7, 2020

    @gireeshpunathil
    Member

    answered, closing. feel free to re-open if it is outstanding

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