Skip to content

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

Description

@tiran

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)

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions