chunk: Optionally clear mmap'd chunk before unmapping

This is mostly for the non-mmap case as with mmap available, access to the
unmapped memory isn't easily possible (e.g. opening the same area with
MAP_ANONYMOUS | MAP_UNINITIALIZED is usually prevented by the missing
CONFIG_MMAP_ALLOW_UNINITIALIZED option in most kernels).
This commit is contained in:
Tobias Brunner
2021-10-04 11:30:03 +02:00
parent b9aafa7ebf
commit e2e21f2486
3 changed files with 81 additions and 5 deletions
+16 -3
View File
@@ -114,7 +114,7 @@ bool chunk_write(chunk_t chunk, char *path, mode_t mask, bool force);
bool chunk_from_fd(int fd, chunk_t *chunk);
/**
* mmap() a file to a chunk
* mmap() a file to a chunk.
*
* The returned chunk structure is allocated from heap, but it must be freed
* through chunk_unmap(). A user may alter the chunk ptr or len, but must pass
@@ -129,16 +129,29 @@ bool chunk_from_fd(int fd, chunk_t *chunk);
chunk_t *chunk_map(char *path, bool wr);
/**
* munmap() a chunk previously mapped with chunk_map()
* munmap() a chunk previously mapped with chunk_map().
*
* When unmapping a writeable map, the return value should be checked to
* ensure changes landed on disk.
*
* @param chunk pointer returned from chunk_map()
* @return TRUE of changes written back to file
* @return TRUE if changes written back to file
*/
bool chunk_unmap(chunk_t *chunk);
/**
* munmap() a chunk previously mapped with chunk_map() after clearing it.
*
* @note Writable maps (i.e. created with wr = TRUE) are NOT cleared.
*
* When unmapping a writeable map, the return value should be checked to
* ensure changes landed on disk.
*
* @param chunk pointer returned from chunk_map()
* @return TRUE if changes written back to file
*/
bool chunk_unmap_clear(chunk_t *chunk);
/**
* Convert a chunk of data to hex encoding.
*