« C/C++ を wasm に clang を使用してコンパイル、JavaScript から呼び出す | メイン | WebAssembly がデフォルトで有効化されるのはいつ? »

2017年02月12日

WebAssembly:: wasm に clang を使った場合に C 内で関数呼び出しする場合に出るエラー

    

extern void print( const char*, int );
int stringLength( const char* s ) {
  int len = 0;
  while( s[len] ) { len++; }
  return len;
}
int c=0;
int count(){
  const char* text = "Hello world!";
  print( text, stringLength(text) );
  return c++;
}

このように JavaScript から count() を読んで、その中で stringLength() を呼ぶようなプログラムを書くと "Uncaught RuntimeError: memory access out of bounds" などと出てうまく動かない。
ソースコードに何か問題があるのか?と言うとそうではなく、コンパイル時にスタックの指定が必要とのこと。
具体的には――

s2wasm count.s -o sample.wast --allocate-stack 1024

のように --allocate-stack オプションが必要になる。


投稿者 Takenori : 2017年02月12日 18:28




comments powered by Disqus
Total : Today : Yesterday : なかのひと