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-Url: http://drtracing.org/?a=commitdiff_plain;h=2f5a009b5615db990687d0775038fdc82bbe8071;p=deliverable%2Fbabeltrace.git 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 5e4ac9231..fdbfd2cf0 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 76ea9ad50..bae0bd14b 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 8b2d7247f..56397dff4 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. */