emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.83k stars 3.31k forks source link

msync() on anonymous mapping fails with TypeError: Cannot read property 'stream_ops' of undefined #16350

Closed tiran closed 2 years ago

tiran commented 2 years ago

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.2 (a77b559a8b40b7e89fc8c17e41034128df9543e4)
clang version 14.0.0 (https://github.com/llvm/llvm-project 782c0dd1a1c235afb09a34e7da4a1267ead14765)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin

Failing command line in full: Calling msync on an anonymous mmap results in a JS type error and abort. msync of an anonymous mappings is a no-op. It should verify the argument (address is multiple of page size, flags are correct) and return with an error.

#include <sys/mman.h>
#include <string.h>
#include <assert.h>

int main(void)
{
    size_t map_size = 1 << 16;

    void *map = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    assert(map != MAP_FAILED);

    memset(map, 0, map_size);

    assert(msync(map, map_size, MS_SYNC) != -1);

    assert(munmap(map, map_size) != -1);
    return 0;
}
$ gcc -o msync msync.c && ./msync

$ emcc -sNODERAWFS -o msync.js msync.c && node msync.js
/python-wasm/cpython/builddir/msync.js:147
      throw ex;
      ^

TypeError: Cannot read property 'stream_ops' of undefined
    at Object.msync (/python-wasm/cpython/builddir/msync.js:2842:20)
    at Object.msync (/python-wasm/cpython/builddir/msync.js:4828:103)
    at Object.doMsync (/python-wasm/cpython/builddir/msync.js:4478:12)
    at ___syscall_msync (/python-wasm/cpython/builddir/msync.js:4611:16)
    at <anonymous>:wasm-function[12]:0x5bc
    at <anonymous>:wasm-function[6]:0x2fc
    at main (<anonymous>:wasm-function[7]:0x3b7)
    at /python-wasm/cpython/builddir/msync.js:1544:22
    at callMain (/python-wasm/cpython/builddir/msync.js:5191:15)
    at doRun (/python-wasm/cpython/builddir/msync.js:5248:23)
kripken commented 2 years ago

Adding the wasmfs label here because if we don't get around to fixing this in the old FS, we may want to make sure the new FS fixes this before we enable it by default.

sbc100 commented 2 years ago

It looks like this is already fixed in 3.1.5 (I could reproduce in 3.1.4 but not in 3.1.5).