romemwrite.c 848 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * romemwrite.c
  3. *
  4. * This program attempts to write into its own text segment,
  5. * which ought to be read-only.
  6. *
  7. * This code is borrowed from the crash.c program, which is
  8. * more general than this one in that it will generate lots
  9. * of other kinds of improper memory accesses.
  10. *
  11. * The only advantage of this program is that it does not
  12. * require argument passing, so it can be used even if argument
  13. * passing is not implemented.
  14. */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #define INVAL_INSN 0x0000003f
  18. int
  19. main()
  20. {
  21. unsigned int *x = (unsigned int *) main;
  22. printf("Trying to write to the text segment\n");
  23. printf("This program should fail if the text segment is read-only.\n");
  24. printf("However, the kernel should not crash...\n");
  25. *x = INVAL_INSN;
  26. printf("IF THIS PRINTS, THE TEST FAILED\n");
  27. exit(1);
  28. }