malloc1GiB.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * This file is part of Jehanne.
  3. *
  4. * Copyright (C) 2015 Giacomo Tesio <giacomo@tesio.it>
  5. *
  6. * Jehanne is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * Jehanne is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <u.h>
  19. #include <lib9.h>
  20. #define GiB 1024*1024*1024
  21. void
  22. main(void)
  23. {
  24. char *p, *q, *e;
  25. p = malloc(GiB);
  26. if(p == nil){
  27. fprint(2, "FAIL: malloc(GiB)\n");
  28. exits("FAIL");
  29. }
  30. e = p + GiB;
  31. for(q = p;
  32. q < e;
  33. q += 512){
  34. if((q - p) % (32*1024*1024) == 0)
  35. fprint(2, "setting %#p (off %d, %d MiB)\n", q, q - p, (q - p) / (1024*1024));
  36. *q = 1;
  37. }
  38. for(q = p;
  39. q < e;
  40. q += 512){
  41. if(*q != 1){
  42. fprint(2, "FAIL: memory check\n");
  43. exits("FAIL");
  44. }
  45. }
  46. print("PASS\n");
  47. exits("PASS");
  48. }