diff options
| author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
|---|---|---|
| committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
| commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
| tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/tools | |
| parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) | |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/tools')
| -rwxr-xr-x | SD-VBS/tools/preload | bin | 0 -> 17416 bytes | |||
| -rw-r--r-- | SD-VBS/tools/preload.c | 70 |
2 files changed, 70 insertions, 0 deletions
diff --git a/SD-VBS/tools/preload b/SD-VBS/tools/preload new file mode 100755 index 0000000..b2e70fc --- /dev/null +++ b/SD-VBS/tools/preload | |||
| Binary files differ | |||
diff --git a/SD-VBS/tools/preload.c b/SD-VBS/tools/preload.c new file mode 100644 index 0000000..24cf428 --- /dev/null +++ b/SD-VBS/tools/preload.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | #include "stdio.h" | ||
| 2 | #include "stdlib.h" | ||
| 3 | #include "unistd.h" | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include <sys/stat.h> | ||
| 6 | #include <sys/mman.h> | ||
| 7 | #include <signal.h> | ||
| 8 | |||
| 9 | |||
| 10 | static void sig_int(int signo){ | ||
| 11 | return; | ||
| 12 | } | ||
| 13 | int main(int argc, char* argv[]){ | ||
| 14 | if(argc < 2){ | ||
| 15 | printf("Too few arguments!\n"); | ||
| 16 | exit(1); | ||
| 17 | } | ||
| 18 | int fd = open(argv[1], O_RDONLY); | ||
| 19 | if(fd < 0){ | ||
| 20 | printf("open failure\n"); | ||
| 21 | exit(1); | ||
| 22 | } | ||
| 23 | |||
| 24 | struct stat st; | ||
| 25 | if(fstat(fd, &st) < 0){ | ||
| 26 | printf("stat error\n"); | ||
| 27 | exit(1); | ||
| 28 | } | ||
| 29 | int len = st.st_size; | ||
| 30 | printf("size = %d\n", len); | ||
| 31 | void* pmap; | ||
| 32 | pmap = mmap(0, len, PROT_READ,MAP_SHARED | MAP_POPULATE,fd, 0); | ||
| 33 | |||
| 34 | printf("pmap = 0x%016x\n", pmap); | ||
| 35 | if(!pmap){ | ||
| 36 | printf("map error\n"); | ||
| 37 | close(fd); | ||
| 38 | exit(1); | ||
| 39 | } | ||
| 40 | |||
| 41 | |||
| 42 | for(int i = 0; i < len;i++){ | ||
| 43 | char c = ((char*)pmap)[i]; | ||
| 44 | } | ||
| 45 | printf("pinning pages...\n"); | ||
| 46 | if(mlock(pmap, len) == -1){ | ||
| 47 | printf("mlock error"); | ||
| 48 | close(fd); | ||
| 49 | exit(1); | ||
| 50 | } | ||
| 51 | |||
| 52 | printf("done pinning...\n"); | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | sigset_t set; | ||
| 57 | sigemptyset(&set); | ||
| 58 | sigaddset(&set,SIGINT); | ||
| 59 | int sig; | ||
| 60 | signal(SIGINT, sig_int); | ||
| 61 | sigwait(&set, &sig); | ||
| 62 | printf("unpinning pages...\n"); | ||
| 63 | |||
| 64 | if(munlock(pmap, len) < 0){ | ||
| 65 | printf("munlock error\n"); | ||
| 66 | } | ||
| 67 | munmap(pmap, len); | ||
| 68 | close(fd); | ||
| 69 | return 0; | ||
| 70 | } | ||
