root/user/uw-testbin/vm-crash3/vm-crash3.c

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

DEFINITIONS

This source file includes following definitions.
  1. write_to_code
  2. write_data
  3. read_data
  4. main

   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 #include <string.h>
   4 
   5 #if defined(__mips__)
   6 #define INSN_TYPE unsigned int
   7 #define INVAL_INSN  0x0000003f
   8 #else
   9 #error "Please fix this"
  10 #endif
  11 
  12 void write_to_code(void);
  13 void read_data(void);
  14 void write_data(void);
  15 
  16 void
  17 write_to_code(void)
  18 {
  19   extern int func_150();
  20   /* picking a code page that should no longer be in the TLB */
  21         INSN_TYPE *x = (INSN_TYPE *) func_150;
  22         *x = INVAL_INSN;
  23 
  24         printf("IF THIS PRINTS THE TEST FAILED\n");
  25 }
  26 
  27 extern void     call_all(void);
  28 
  29 #define PAGE_SIZE (4096)
  30 #define PAGES     (128)
  31 #define SIZE      (PAGE_SIZE * PAGES / sizeof(int))
  32 #define NUM_REFS  (2)
  33 
  34 unsigned int array[SIZE];
  35 
  36 void
  37 write_data(void)
  38 {
  39         unsigned int refs = 0;
  40         unsigned int i = 0;
  41 
  42         for (refs = 0; refs < NUM_REFS-1; refs++) {
  43                 for (i=0; i<SIZE; i+= PAGE_SIZE) {
  44                         array[i] = i;
  45                 }
  46         }
  47 }
  48 
  49 void
  50 read_data(void)
  51 {
  52         unsigned int i = 0;
  53 
  54         for (i=0; i<SIZE; i+= PAGE_SIZE) {
  55                 if (array[i] != i) {
  56                         printf("FAILED array[%d] = %u != %d\n", i, array[i], i);
  57                         exit(1);
  58                 }
  59         }
  60 }
  61 
  62 
  63 int
  64 main()
  65 {
  66         unsigned int i = 0;
  67 
  68         for (i=0; i<5; i++) {
  69           call_all();
  70           write_data();
  71           call_all();
  72           read_data();
  73         }
  74 
  75         /* This won't hopefully return becasue it crashes */
  76         write_to_code();
  77         exit(0);
  78 }

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