From 95c320143c66ccad9ccfdb716397a59ee552360e Mon Sep 17 00:00:00 2001 From: Pekka Enberg <penberg@cloudius-systems.com> Date: Mon, 7 Oct 2013 11:53:06 +0300 Subject: [PATCH] tst-mmap.so: Fix mincore() stack and malloc tests Linux requires mincore() addresses to be page aligned. Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com> --- tests/tst-mmap.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/tst-mmap.cc b/tests/tst-mmap.cc index 0bd746cb7..240170ccc 100644 --- a/tests/tst-mmap.cc +++ b/tests/tst-mmap.cc @@ -69,6 +69,12 @@ static bool try_read(void *addr) return (!caught_segv()); } +static void* align_page_down(void *x) +{ + uintptr_t addr = reinterpret_cast<uintptr_t>(x); + + return reinterpret_cast<void*>(addr & ~4095UL); +} int main(int argc, char **argv) { @@ -248,9 +254,9 @@ int main(int argc, char **argv) // While msync() only works on mmapped memory, mincore() should also // succeed on non-mmapped memory, such as stack variables and malloc(). char x; - assert(mincore(&x, 1, vec) == 0); + assert(mincore(align_page_down(&x), 1, vec) == 0); void *y = malloc(1); - assert(mincore(y, 1, vec) == 0); + assert(mincore(align_page_down(y), 1, vec) == 0); free(y); // TODO: verify that mmapping more than available physical memory doesn't -- GitLab