vm-stackgrow.c 579 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define PAGE_SIZE (4096)
  4. #define SIZE (PAGE_SIZE / sizeof(int))
  5. #define MAX_LEVEL (50)
  6. void stacker(int level);
  7. int
  8. main()
  9. {
  10. stacker(1);
  11. printf("\nSUCCEEDED\n");
  12. exit(0);
  13. }
  14. void
  15. stacker(int level)
  16. {
  17. unsigned int array[SIZE];
  18. unsigned int i = 0;
  19. for (i=0; i<SIZE; i++) {
  20. array[i] = i;
  21. }
  22. for (i=0; i<SIZE; i++) {
  23. if (array[i] != i) {
  24. printf("Level: %d: FAILED array[%d] = %u != %d\n", level, i, array[i], i);
  25. exit(1);
  26. }
  27. }
  28. printf("%d ",level);
  29. if (level < MAX_LEVEL) {
  30. stacker(level+1);
  31. }
  32. return;
  33. }