aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Stancek <jstancek@redhat.com>2012-12-10 12:01:37 +0100
committerEric Munson <emunson@bert.(none)>2013-02-23 15:21:55 -0500
commitee00e3102ec8354175b2ce99eb5350d7026fd67c (patch)
tree2953bfcdc48ca21f602dbd282ce33cf58e0cabf5
parent7b6346cce4215df8ef3e66231a35fdbb0c5b296c (diff)
downloadlibhugetlbfs-ee00e3102ec8354175b2ce99eb5350d7026fd67c.tar.gz
avoid calling munmap with zero length
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 <jstancek@redhat.com> Signed-off-by: Eric Munson <emunson@bert.(none)>
-rw-r--r--tests/mremap-fixed-huge-near-normal.c20
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;
}