emscripten-core / emscripten-core/emscripten

PROXYFS has a bug

Open
#16,857 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.8 (3ff7eff373d31d8c0179895165462019221f192e)
clang version 15.0.0 (https://github.com/llvm/llvm-project 80ec0ebfdc5692a58e0832125f2c6a991df9d63f)
Target: wasm32-unknown-emscripten
Thread model: posix

**Failing command line in full:**
```c++
// a.cpp
#include
#include
int main() {
struct stat st;
int res = stat("/another_fs/shm/not_a_file", &st);
printf("%d\n", res);
}
```

```html


Demo




const ModuleA = await MA()
const ModuleB = await MB({
'onRuntimeInitialized': (function () {
this.FS.mkdir('/another_fs')
this.FS.mount(this.PROXYFS, {
root: "/",
fs: ModuleA.FS
}, "/another_fs")
})
})

```

command:
```shell
emcc a.cpp -o a1.js -sMODULARIZE -sEXPORTED_RUNTIME_METHODS=FS,PROXYFS -lproxyfs.js -sEXPORT_NAME='MA'
emcc a.cpp -o a2.js -sMODULARIZE -sEXPORTED_RUNTIME_METHODS=FS,PROXYFS -lproxyfs.js -sEXPORT_NAME='MB'
```

The output is:
```
-1 a1.js:2097
```
But the correct output is:
```
-1 a1.js:2097
-1 a2.js:2097
```

The bug is caused by the function ___syscall_stat64 in a2.js(and any other js file):
```js
function ___syscall_stat64(path, buf) {
try {

path = SYSCALLS.getStr(path);
return SYSCALLS.doStat(FS.stat, path, buf);
} catch (e) {
if (typeof FS == 'undefined' || !(e instanceof FS.ErrnoError)) throw e;
return -e.errno;
}
}
```
The error e is throwed in MA(because '/another_fs/shm' is belong to MA.FS), so the e.\_\_proto\_\_ is the MA.FS.ErrnoError. But this function is in MB, so the value of e instanceof FS.ErrnoError is false.

I only test the stat function in PROXYFS, but I think all syscall in shared FS that include e instanceof FS.ErrnoError have common bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.