os161-1.99
 All Data Structures
romemwrite.c
00001 /*
00002  *  romemwrite.c
00003  *
00004  *  This program attempts to write into its own text segment,
00005  *  which ought to be read-only.
00006  *
00007  *  This code is borrowed from the crash.c program, which is
00008  *   more general than this one in that it will generate lots
00009  *   of other kinds of improper memory accesses.
00010  *
00011  *  The only advantage of this program is that it does not
00012  *  require argument passing, so it can be used even if argument
00013  *  passing is not implemented.
00014  */ 
00015 
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 
00019 #define INVAL_INSN  0x0000003f
00020 
00021 int
00022 main()
00023 {
00024   unsigned int *x = (unsigned int *) main;
00025 
00026   printf("Trying to write to the text segment\n");
00027   printf("This program should fail if the text segment is read-only.\n");
00028   printf("However, the kernel should not crash...\n");
00029 
00030   *x = INVAL_INSN;
00031 
00032   printf("IF THIS PRINTS, THE TEST FAILED\n");
00033   exit(1);
00034 }
 All Data Structures