From: Jérémie Galarneau Date: Tue, 22 Aug 2017 18:35:13 +0000 (-0400) Subject: Port fix: Windows does not allow read-only mappings > file's size X-Git-Tag: v2.0.0-pre4~115 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=7b7d809115c61ddae2dcaeae2c36ee4cafc4d8b4 Port fix: Windows does not allow read-only mappings > file's size Reported-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/compat/mman-internal.h b/include/babeltrace/compat/mman-internal.h index 5e4ac923..fdbfd2cf 100644 --- a/include/babeltrace/compat/mman-internal.h +++ b/include/babeltrace/compat/mman-internal.h @@ -43,6 +43,10 @@ #define MAP_ANON MAP_ANONYMOUS #define MAP_FAILED ((void *) -1) +/* + * Note that some platforms (e.g. Windows) do not allow read-only + * mappings to exceed the file's size (even within a page). + */ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index 76ea9ad5..bae0bd14 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -92,6 +92,11 @@ enum bt_ctf_notif_iter_medium_status ds_file_mmap_next( goto error; } + /* + * mmap_valid_len is guaranteed to be page-aligned except on the + * last mapping where it may not be possible (since the file's + * size itself may not be a page multiple). + */ ds_file->mmap_offset += ds_file->mmap_valid_len; ds_file->request_offset = 0; } diff --git a/plugins/ctf/fs-src/data-stream-file.h b/plugins/ctf/fs-src/data-stream-file.h index 8b2d7247..56397dff 100644 --- a/plugins/ctf/fs-src/data-stream-file.h +++ b/plugins/ctf/fs-src/data-stream-file.h @@ -99,7 +99,10 @@ struct ctf_fs_ds_file { void *mmap_addr; - /* Max length of chunk to mmap() when updating the current mapping. */ + /* + * Max length of chunk to mmap() when updating the current mapping. + * This value must be page-aligned. + */ size_t mmap_max_len; /* Length of the current mapping. */