root/user/uw-testbin/romemwrite/romemwrite.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   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 
  16 #include <stdio.h>
  17 #include <stdlib.h>
  18 
  19 #define INVAL_INSN  0x0000003f
  20 
  21 int
  22 main()
  23 {
  24   unsigned int *x = (unsigned int *) main;
  25 
  26   printf("Trying to write to the text segment\n");
  27   printf("This program should fail if the text segment is read-only.\n");
  28   printf("However, the kernel should not crash...\n");
  29 
  30   *x = INVAL_INSN;
  31 
  32   printf("IF THIS PRINTS, THE TEST FAILED\n");
  33   exit(1);
  34 }

/* [<][>][^][v][top][bottom][index][help] */