large-mmap.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <sys/mman.h>
  6. #include <sys/types.h>
  7. #define TEST_LENGTH 0x10000f000
  8. #define TEST_LENGTH2 0x8000f000
  9. int main() {
  10. FILE*fp=fopen("testfile","a+");
  11. if (!fp) { perror("fopen"); return 1; }
  12. int rv = ftruncate(fileno(fp), TEST_LENGTH);
  13. if (rv) {perror ("ftruncate"); return 1;}
  14. else
  15. printf("large-mmap: ftruncate OK\n");
  16. void* a=mmap(NULL, TEST_LENGTH2, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
  17. if (a==MAP_FAILED) { perror("mmap 1"); return 1; }
  18. ((char*)a)[0x80000000]=0xff;
  19. printf("large-mmap: mmap 1 completed OK\n");
  20. rv = munmap(a, TEST_LENGTH2);
  21. if (rv) { perror("mumap"); return 1; }
  22. a=mmap(NULL, TEST_LENGTH, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(fp), 0);
  23. if (a==MAP_FAILED) { perror("mmap 2"); return 1; }
  24. ((char*)a)[0x100000000]=0xff;
  25. printf("large-mmap: mmap 2 completed OK\n");
  26. return 0;
  27. }