From: Alex Bennée <email address hidden>
This adds a test to make sure we fail properly for a 0 length mmap. There are most likely other failure conditions we should also check.
Signed-off-by: Alex Bennée <email address hidden> Reviewed-by: Richard Henderson <email address hidden> Cc: umarcor <email address hidden> Message-Id: <email address hidden> Signed-off-by: Laurent Vivier <email address hidden> --- tests/tcg/multiarch/test-mmap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/tests/tcg/multiarch/test-mmap.c b/tests/tcg/multiarch/test-mmap.c index 5c0afe6e49..11d0e777b1 100644 --- a/tests/tcg/multiarch/test-mmap.c +++ b/tests/tcg/multiarch/test-mmap.c @@ -27,7 +27,7 @@ #include <stdint.h> #include <string.h> #include <unistd.h> - +#include <errno.h> #include <sys/mman.h>
#define D(x) @@ -435,6 +435,25 @@ void checked_write(int fd, const void *buf, size_t count) fail_unless(rc == count); }
+void check_invalid_mmaps(void) +{ + unsigned char *addr; + + /* Attempt to map a zero length page. */ + addr = mmap(NULL, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + fprintf(stdout, "%s addr=%p", __func__, (void *)addr); + fail_unless(addr == MAP_FAILED); + fail_unless(errno == EINVAL); + + /* Attempt to map a over length page. */ + addr = mmap(NULL, -4, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + fprintf(stdout, "%s addr=%p", __func__, (void *)addr); + fail_unless(addr == MAP_FAILED); + fail_unless(errno == ENOMEM); + + fprintf(stdout, " passed\n"); +} + int main(int argc, char **argv) { char tempname[] = "/tmp/.cmmapXXXXXX"; @@ -476,6 +495,7 @@ int main(int argc, char **argv) check_file_fixed_mmaps(); check_file_fixed_eof_mmaps(); check_file_unfixed_eof_mmaps(); + check_invalid_mmaps();
/* Fails at the moment. */ /* check_aligned_anonymous_fixed_mmaps_collide_with_host(); */ -- 2.17.1
From: Alex Bennée <email address hidden>
This adds a test to make sure we fail properly for a 0 length mmap.
There are most likely other failure conditions we should also check.
Signed-off-by: Alex Bennée <email address hidden> tcg/multiarch/ test-mmap. c | 22 +++++++ +++++++ +++++++ -
Reviewed-by: Richard Henderson <email address hidden>
Cc: umarcor <email address hidden>
Message-Id: <email address hidden>
Signed-off-by: Laurent Vivier <email address hidden>
---
tests/
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/tests/ tcg/multiarch/ test-mmap. c b/tests/ tcg/multiarch/ test-mmap. c .11d0e777b1 100644 tcg/multiarch/ test-mmap. c tcg/multiarch/ test-mmap. c
index 5c0afe6e49.
--- a/tests/
+++ b/tests/
@@ -27,7 +27,7 @@
#include <stdint.h>
#include <string.h>
#include <unistd.h>
-
+#include <errno.h>
#include <sys/mman.h>
#define D(x)
@@ -435,6 +435,25 @@ void checked_write(int fd, const void *buf, size_t count)
fail_unless(rc == count);
}
+void check_invalid_ mmaps(void) cmmapXXXXXX" ; file_fixed_ mmaps() ; file_fixed_ eof_mmaps( ); file_unfixed_ eof_mmaps( ); mmaps() ;
+{
+ unsigned char *addr;
+
+ /* Attempt to map a zero length page. */
+ addr = mmap(NULL, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ fprintf(stdout, "%s addr=%p", __func__, (void *)addr);
+ fail_unless(addr == MAP_FAILED);
+ fail_unless(errno == EINVAL);
+
+ /* Attempt to map a over length page. */
+ addr = mmap(NULL, -4, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ fprintf(stdout, "%s addr=%p", __func__, (void *)addr);
+ fail_unless(addr == MAP_FAILED);
+ fail_unless(errno == ENOMEM);
+
+ fprintf(stdout, " passed\n");
+}
+
int main(int argc, char **argv)
{
char tempname[] = "/tmp/.
@@ -476,6 +495,7 @@ int main(int argc, char **argv)
check_
check_
check_
+ check_invalid_
/* Fails at the moment. */ anonymous_ fixed_mmaps_ collide_ with_host( ); */
/* check_aligned_
--
2.17.1