-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
munmap fails if file has been closed #20459
Comments
Yep, our current implementation of mmap is completely incorrect. Failing when the mapped file is closed is not even the worst thing that can happen. If the mapped file is closed and another file is subsequently opened and assigned the same file descriptor, then munmap will write the original file's contents to the other file! |
Looking at this, it feels like the easiest way to fix would be:
Does that make sense? Is there anything I'm missing? It looks to me like file deletion is likely to break things? |
Yes, that sounds like the correct direction. In addition, it would be nice to make the file systems aware of the mapping so that the read and write syscalls could access the mapped buffer so their view of the data would be consistent with directly accessing the buffer. |
@joemarshall is there some reason you need / want to depend on the fake mmap support in emscripten? For most programs its better to build them as if mmap is not available. This should reduce code size and increase match between what the program wants to do and what emscirpten can actually provide. Do you have the ability to build with something like |
In linux, you can do:
mmap
)munmap
regionIn emscripten, it mostly works, but munmap returns -1 if the file is closed.
test.c
To reproduce:
emcc test-unmap.c -lnodefs.js -lnoderawfs.js
The text was updated successfully, but these errors were encountered: