int test_copy_exception(void) { int page_size; static char *p, *q; unsigned long src, dst, len; page_size = getpagesize(); p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { perror("mmap"); exit(1); } memset(p, 0, page_size); setup_segv_handler(); if (mprotect(p + page_size, page_size, PROT_NONE)) { perror("mprotect"); exit(1); } q = p + page_size - MAX_LEN; for (src = 0; src < MAX_LEN; src++) { for (dst = 0; dst < MAX_LEN; dst++) { for (len = 0; len < MAX_LEN+1; len++) { // printf("from=%p to=%p len=%ld\n", q+dst, q+src, len); do_one_test(q+dst, q+src, len); } } } printf("Totals:\n"); printf(" Pass: %d\n", total_passed); printf(" Fail: %d\n", total_failed); return 0; }
static int test_body(void) { unsigned long i; page_size = getpagesize(); mem_region = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); FAIL_IF(mem_region == MAP_FAILED); for (i = 0; i < page_size; i++) mem_region[i] = i; memset(mem_region+page_size, 0, page_size); setup_segv_handler(); for (i = 0; i < page_size; i++) FAIL_IF(do_one_test(mem_region+i, i)); FAIL_IF(segv_error); return 0; }