You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
close fd before calling munmap will cause the write failure #15140
When using emcc to compile wasm, I try to use mmap to write the file, but if you close fd before calling munmap, the written content will be lost.
Here is the example.
int len = string.size();
int fd = open("test-shared.txt", O_RDWR | O_CREAT, 00777);
lseek(fd, len - 1, SEEK_END);
write(fd, " ", 1);
char* buffer = (char*) mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
memcpy(buffer, string.data(), len);
// close(fd); // open it will lose all content, but it's ok in the linux environment.
munmap(buffer, len);
close(fd); // it's fine.
changed the title [-]close fd before calling mmap will cause the write failure[/-][+]close fd before calling munmap will cause the write failure[/+]on Sep 28, 2021
Activity
[-]close fd before calling mmap will cause the write failure[/-][+]close fd before calling munmap will cause the write failure[/+]mere-human commentedon Jan 25, 2023
I've seen the same problem in my project.