title: mmap: Operation not permitted
body: <p>I am trying to use mmap in user space to read the physical memory where 'mem_map' starts. It's an array that contains all the physical pages. This is a i386 machine running 3.0 kernel. </p>
  
  <p>The code is like this:</p>
  
  <pre><code>....
  
  //define page size
  //
  #define PAGE_SIZE 0x1000 //4096 bytes
  #define PAGE_MASK (PAGE_SIZE - 1)
  
  ....
  
    /* open /dev/mem file*/
    if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
          printf("/dev/mem could not be opened.\n");
      perror("open");
          exit(1);
    } else {
      printf("/dev/mem opened.\n");
    }
  
    /* Map one page */
    printf(" mem_map is at physical addr: 0x%x\n", mem_map_phy_addr);
  
    map_base = mmap(0, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, (mem_map_phy_addr &amp; ~PAGE_MASK)); //mem_map_phy_addr is at 0x356f2000
  
    if(map_base == (void *) -1) {
      printf("Memory map failed. err num = %d\n",errno);
      perror("mmap"); //failed here
    } else {
      printf("Memory mapped at address %p.\n", map_base);
    }
  </code></pre>
  
  <p>I ran this as a root. The output is:</p>
  
  <pre><code>/dev/mem opened.
   mem_map is at physical addr: 0x356f2000
  Memory map failed. err num = 1
  mmap: Operation not permitted
  </code></pre>
  
  <p>To be sure, I googled the problem and added the following line to my /etc/sysctl.conf file:</p>
  
  <pre><code>vm.mmap_min_addr = 0
  </code></pre>
  
  <p>But this doesn't work either.</p>
  
  <p>Anyone knows why mem_map operation like this is not permitted and how I can get around it?</p>
  
  <p>Thanks.</p>