Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Mielott futatnad
- // dd if=/dev/zero of=mmap bs=1M count=1k
- // make mmaper
- // ./mmaper # Na mot nezeged a topot, us entert, hogy lass mozgast
- // erdemes VIRT szerint rendezni shift+F o
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/mman.h>
- #include <stdio.h>
- int main()
- {
- int fd;
- struct stat s;
- off_t c;
- int sum=42;
- char* addr;
- fd=open ("mmap", O_RDONLY);
- fstat(fd,&s);
- addr=(char*) mmap(NULL,s.st_size, PROT_READ,MAP_PRIVATE,fd,0);
- if (addr==(void*)-1)
- {
- fprintf(stderr,"fuck");
- return 1;
- }
- getchar();
- for (c=0;c<s.st_size;c+=4096)
- {
- sum+=addr[c];
- }
- printf("%d\n",sum);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment