diff options
| author | M.Amin Rayej <m.amin.rayej@gmail.com> | 2024-07-07 17:38:41 +0330 |
|---|---|---|
| committer | M.Amin Rayej <m.amin.rayej@gmail.com> | 2024-07-07 17:38:41 +0330 |
| commit | 91007341c30b9ba992179b5256ff6cbce1ad6c7d (patch) | |
| tree | c43164a7261904b3299429375ba5559de6f417fc | |
| parent | 91644a6ef4e3e0a0eeeeb547a1eabaf1cf808847 (diff) | |
sync after unmap and add prot check
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | libc-bottom-half/mman/mman.c | 16 |
2 files changed, 19 insertions, 0 deletions
@@ -21,6 +21,9 @@ additional extensions: - pipe and event support (`pipe`, `event` ) - DNS resolution support (`resolve` ) +# NOTES +- Memory mapping is currently not compatible with threads + # WASI(X) Extensions Spec [WASIX](https://wasix.org) is maintained by wasix.org [here](https://github.com/wasix-org/wasix-witx) diff --git a/libc-bottom-half/mman/mman.c b/libc-bottom-half/mman/mman.c index 511b379..e4ae27d 100644 --- a/libc-bottom-half/mman/mman.c +++ b/libc-bottom-half/mman/mman.c @@ -117,6 +117,7 @@ void *mmap(void *addr, size_t length, int prot, int flags, body += (size_t)nread; } } else { + map->fd = -1; memset(addr, 0, length); } @@ -135,6 +136,16 @@ int munmap(void *addr, size_t length) { // Release the memory. free(map); + // Write the data back to the backing file and close + // the file handle + if (map->fd != -1) { + if ((map->prot & PROT_WRITE) != 0) { + msync(addr, length, MS_SYNC); + } + + close(map->fd); + } + // Success! return 0; } @@ -151,6 +162,11 @@ int msync (void *addr, size_t length, int flags) { return -1; } + if ((map->prot & PROT_WRITE) != 0) { + errno = EINVAL; + return -1; + } + if ((map_flags & MAP_ANON) == 0) { char *body = (char *)addr; |
