title: mmap() returns EINVAL
body: <p>I can't get the <strong>mmap</strong> function to work. It returns the <em>EINVAL</em> error code.</p>
  
  <pre><code>void* mapped = 
          mmap((void*)(map_addr + slide),
               map_size,
               PROT_WRITE | PROT_READ,
               MAP_PRIVATE | MAP_ANON,
               bprm-&gt;file,
               map_offset);
  </code></pre>
  
  <p>I've checked the documentation for this function on my platform (<strong>Darwin</strong>) and there doesn't seem to be anything wrong. The man page for mmap presents four cases under which EINVAL would be returned.</p>
  
  <pre><code> [EINVAL]           MAP_FIXED was specified and the addr argument was not page
                      aligned, or part of the desired address space resides out of the
                      valid address space for a user process.
  </code></pre>
  
  <p>MAP_FIXED isn't specified so it isn't this.</p>
  
  <pre><code> [EINVAL]           flags does not include either MAP_PRIVATE or MAP_SHARED.
  </code></pre>
  
  <p>MAP_PRIVATE is present.</p>
  
  <pre><code> [EINVAL]           The len argument was negative.
  </code></pre>
  
  <p>The len (map_size) argument at the time of the call is 8192.</p>
  
  <pre><code> [EINVAL]           The offset argument was not page-aligned based on the page size as
                      returned by getpagesize(3).
  </code></pre>
  
  <p>The offset argument (map_offset) is 0 so it must be page aligned. (maybe I'm wrong?)</p>