1 #include <errno.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <sys/wait.h> 5 #include <unistd.h> 6 7 #include <OS.h> 8 9 10 static const int kAreaPagesCount = 4 * 1024; // 16 MB 11 12 13 int 14 main() 15 { 16 while (true) { 17 uint8* address; 18 area_id area = create_area("test area", (void**)&address, B_ANY_ADDRESS, 19 kAreaPagesCount * B_PAGE_SIZE, B_NO_LOCK, 20 B_READ_AREA | B_WRITE_AREA); 21 if (area < 0) { 22 fprintf(stderr, "Creating the area failed: %s", strerror(area)); 23 exit(1); 24 } 25 26 // touch half of the pages 27 for (int i = 0; i < kAreaPagesCount / 2; i++) 28 address[i * B_PAGE_SIZE] = 42; 29 30 // fork 31 pid_t child = fork(); 32 if (child < 0) { 33 perror("fork() failed"); 34 exit(1); 35 } 36 37 if (child == 0) { 38 // child 39 40 // delete the copied area 41 delete_area(area_for(address)); 42 43 exit(0); 44 } 45 46 // parent 47 48 // touch the other half of the pages 49 for (int i = kAreaPagesCount / 2; i < kAreaPagesCount; i++) 50 address[i * B_PAGE_SIZE] = 42; 51 52 int status; 53 while (wait(&status) != child); 54 55 delete_area(area); 56 } 57 58 return 0; 59 } 60