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