From 2c701ca62babb38a7aa3fbcebef7e2ff45ffbdbd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 22 Aug 2017 15:04:45 -0400 Subject: [PATCH] Port fix: don't round mmap offset to next page MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs-src/data-stream-file.c | 13 +++++-------- plugins/ctf/fs-src/data-stream-file.h | 5 +---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index bae0bd14..2fddc39d 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -50,7 +50,7 @@ static inline size_t remaining_mmap_bytes(struct ctf_fs_ds_file *ds_file) { - return ds_file->mmap_valid_len - ds_file->request_offset; + return ds_file->mmap_len - ds_file->request_offset; } static @@ -93,23 +93,20 @@ enum bt_ctf_notif_iter_medium_status ds_file_mmap_next( } /* - * mmap_valid_len is guaranteed to be page-aligned except on the + * mmap_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->mmap_offset += ds_file->mmap_len; ds_file->request_offset = 0; } - ds_file->mmap_valid_len = MIN(ds_file->file->size - ds_file->mmap_offset, + ds_file->mmap_len = MIN(ds_file->file->size - ds_file->mmap_offset, ds_file->mmap_max_len); - if (ds_file->mmap_valid_len == 0) { + if (ds_file->mmap_len == 0) { ret = BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF; goto end; } - /* Round up to next page, assuming page size being a power of 2. */ - ds_file->mmap_len = (ds_file->mmap_valid_len + page_size - 1) - & ~(page_size - 1); /* Map new region */ assert(ds_file->mmap_len); ds_file->mmap_addr = bt_mmap((void *) 0, ds_file->mmap_len, diff --git a/plugins/ctf/fs-src/data-stream-file.h b/plugins/ctf/fs-src/data-stream-file.h index 56397dff..1d3e51e6 100644 --- a/plugins/ctf/fs-src/data-stream-file.h +++ b/plugins/ctf/fs-src/data-stream-file.h @@ -105,12 +105,9 @@ struct ctf_fs_ds_file { */ size_t mmap_max_len; - /* Length of the current mapping. */ + /* Length of the current mapping. Never exceeds the file's length. */ size_t mmap_len; - /* Length of the current mapping which *exists* in the backing file. */ - size_t mmap_valid_len; - /* Offset in the file where the current mapping starts. */ off_t mmap_offset; -- 2.34.1