title: Basic mmap(2) call fails
body: <p>I've been pulling my hairs out for hours on this very basic piece of code and I haven't managed to understand why mmap(2) was failing.</p>
  
  <pre><code>#include &lt;sys/mman.h&gt;
  #include &lt;sys/user.h&gt;
  #include &lt;err.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define NPAGES      50
  #define SLABSIZE    (PAGE_SIZE * NPAGES)      // 200 kB
  
  int
  main(int argc, char *argv[])
  {
          char *slab;
  
          printf("DEBUG: mmap(%#x, %u, %#x, %#x, %d, %u)\n",
              NULL, SLABSIZE, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
          slab = mmap(NULL, SLABSIZE, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
          if (slab == MAP_FAILED)
                  err(1, "mmap");
  }
  </code></pre>
  
  <p>But when I run it:</p>
  
  <pre><code>$ make mmap
  cc     mmap.c   -o mmap
  $ ./mmap 
  DEBUG: mmap(0, 204800, 0x3, 0x20, -1, 0)
  mmap: mmap: Invalid argument
  </code></pre>
  
  <p>I checked and re-checked mmap(2)'s manpage [1], and it seems that all requirements are OK but I must be missing something.
  I'm running Linux kernel 4.8.13.</p>
  
  <p>Thanks.
  -- Jeremie</p>
  
  <p>[1] <a href="http://man7.org/linux/man-pages/man2/mmap.2.html" rel="nofollow noreferrer">http://man7.org/linux/man-pages/man2/mmap.2.html</a></p>