From 2f5a009b5615db990687d0775038fdc82bbe8071 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 22 Aug 2017 14:35:13 -0400 Subject: [PATCH] Port fix: Windows does not allow read-only mappings > file's size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reported-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- include/babeltrace/compat/mman-internal.h | 4 ++++ plugins/ctf/fs-src/data-stream-file.c | 5 +++++ plugins/ctf/fs-src/data-stream-file.h | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) 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. */ -- 2.34.1