emscripten-core / emscripten-core/emscripten

munmap fails if file has been closed

Open
#20,459 4 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

In linux, you can do:

1) open file
2) memory map a region of the file (`mmap`)
3) close file
4) do stuff with the memory mapped region
5) `munmap` region

In emscripten, it mostly works, but munmap returns -1 if the file is closed.

test.c
```
#include
#include
#include
#include

int main()
{
int fd;
char *addr;
int result;

fd=open("test-unmap.c",O_RDONLY);
addr=mmap(NULL,64,PROT_READ,MAP_SHARED,fd,0);
close(fd);
// this call should succeed, but actually fails
result=munmap(addr,64);
printf("%d\n",result);
}
```

To reproduce:
`emcc test-unmap.c -lnodefs.js -lnoderawfs.js`

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.