mremap-fixed-huge-near-normal testcase mmaps 4*hpage_size - getpagesize() of anon shared memory. Then it finds area of 3 huge pages aligned to hpage_size and munmaps lower and upper areas:
lower +----- 3*hpage_size -----+ upper / \/ \/ \ |--------|--------|--------|--------|--------| p q | p+xsize q+size If initial mmap will place whole area in such way, that lower or upper area size is zero, munmap fails with EINVAL and testcase fails. mmap(2): EINVAL (since Linux 2.6.12) length was 0. Signed-off-by: Jan Stancek <jstan...@redhat.com> --- tests/mremap-fixed-huge-near-normal.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/mremap-fixed-huge-near-normal.c b/tests/mremap-fixed-huge-near-normal.c index 2c41813..e0f2ae4 100644 --- a/tests/mremap-fixed-huge-near-normal.c +++ b/tests/mremap-fixed-huge-near-normal.c @@ -87,6 +87,7 @@ void do_remap(int fd, void *target) void *map_align(size_t size, size_t align) { unsigned long xsize = size + align - getpagesize(); + size_t t; void *p, *q; int rc; @@ -97,14 +98,19 @@ void *map_align(size_t size, size_t align) q = PALIGN(p, align); - rc = munmap(p, q-p); - if (rc != 0) - FAIL("munmap(lower aligning): %s", strerror(errno)); - - rc = munmap(q + size, p + xsize - (q + size)); - if (rc != 0) - FAIL("munmap(upper aligning): %s", strerror(errno)); + t = q - p; + if (t) { + rc = munmap(p, t); + if (rc != 0) + FAIL("munmap(lower aligning): %s", strerror(errno)); + } + t = p + xsize - (q + size); + if (t) { + rc = munmap(q + size, t); + if (rc != 0) + FAIL("munmap(upper aligning): %s", strerror(errno)); + } return q; } -- 1.7.1 ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel