int main(int argc, char **argv) { macosx_init_exception_handler(); printf("Allocating test pages:\n"); normal_page = malloc_pages(MPAGE_SIZE, MPAGE_SIZE); printf(" ... normal page at %p\n", normal_page); big_page = malloc_pages(BPAGE_SIZE, MPAGE_SIZE); printf(" ... big page at %p\n", big_page); printf("Setting protection on test pages\n"); protect_pages(normal_page, MPAGE_SIZE, 0); printf(" ... normal page %p set\n", normal_page); protect_pages(big_page, MPAGE_SIZE, 0); printf(" ... big page %p set\n", big_page); printf("Writing to test pages\n"); normal_page[2] = 'A'; big_page[2] = 'A'; printf("Reading from test pages:\n"); printf(" ... normal_page %p's second byte is %c\n", normal_page, normal_page[2]); printf(" ... big_page %p's second byte is %c\n", big_page, big_page[2]); printf("Freeing test pages:\n"); free_pages(normal_page, MPAGE_SIZE); printf(" ... freed normal page\n"); free_pages(big_page, MPAGE_SIZE); printf(" ... freed big page\n"); }
int designate_modified(void *p) { if((p >= normal_page) && (p < (normal_page + MPAGE_SIZE))) { protect_pages(p, MPAGE_SIZE, 1); return 1; } if((p >= big_page) && (p < (big_page + BPAGE_SIZE))) { protect_pages(p, BPAGE_SIZE, 1); return 1; } printf("Unrecognized write: %p\n", p); return 0; }
static void flush_protect_page_ranges(int writeable) { Range *work; compact_page_ranges(&protect_range); for (work = protect_range.range_start; work; work = work->next) { protect_pages((void *)work->start, work->len, writeable); } reset_page_ranges(&protect_range); }