qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

tests: add check_invalid_maps to test-mmap

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 <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Cc: umarcor <1783362@bugs.launchpad.net>
Message-Id: <20180730134321.19898-3-alex.bennee@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>

authored by

Alex Bennée and committed by
Laurent Vivier
28cbb997 38138fab

+21 -1
+21 -1
tests/tcg/multiarch/test-mmap.c
··· 27 27 #include <stdint.h> 28 28 #include <string.h> 29 29 #include <unistd.h> 30 - 30 + #include <errno.h> 31 31 #include <sys/mman.h> 32 32 33 33 #define D(x) ··· 435 435 fail_unless(rc == count); 436 436 } 437 437 438 + void check_invalid_mmaps(void) 439 + { 440 + unsigned char *addr; 441 + 442 + /* Attempt to map a zero length page. */ 443 + addr = mmap(NULL, 0, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 444 + fprintf(stdout, "%s addr=%p", __func__, (void *)addr); 445 + fail_unless(addr == MAP_FAILED); 446 + fail_unless(errno == EINVAL); 447 + 448 + /* Attempt to map a over length page. */ 449 + addr = mmap(NULL, -4, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 450 + fprintf(stdout, "%s addr=%p", __func__, (void *)addr); 451 + fail_unless(addr == MAP_FAILED); 452 + fail_unless(errno == ENOMEM); 453 + 454 + fprintf(stdout, " passed\n"); 455 + } 456 + 438 457 int main(int argc, char **argv) 439 458 { 440 459 char tempname[] = "/tmp/.cmmapXXXXXX"; ··· 476 495 check_file_fixed_mmaps(); 477 496 check_file_fixed_eof_mmaps(); 478 497 check_file_unfixed_eof_mmaps(); 498 + check_invalid_mmaps(); 479 499 480 500 /* Fails at the moment. */ 481 501 /* check_aligned_anonymous_fixed_mmaps_collide_with_host(); */