2ab3eeab1cf6d7ec757e74596a9db3a9cf65d230
[pintos-anon] / grading / vm / mmap-unmap.c
1 #include <stdio.h>
2 #include <string.h>
3 #ifdef PINTOS
4 #include <syscall.h>
5 #else
6 #include "posix-compat.h"
7 #endif
8 #include "sample.inc"
9
10 #define ACTUAL ((void *) 0x10000000)
11
12 int
13 main (void) 
14 {
15   int fd;
16
17   printf ("(mmap-unmap) begin\n");
18
19   fd = open ("sample.txt");
20   if (fd < 0) 
21     {
22       printf ("(mmap-unmap) open() failed\n");
23       return 1;
24     }
25
26   if (!mmap (fd, ACTUAL, strlen (sample)))
27     {
28       printf ("(mmap-unmap) mmap() failed\n");
29       return 1;
30     }
31
32   munmap (ACTUAL, strlen (sample));
33
34   printf ("(mmap-unmap) FAIL: unmapped memory is readable (%d)\n",
35           *(int *) ACTUAL);
36   
37   /* Done. */
38   printf ("(mmap-unmap) end\n");
39
40   return 0;
41 }