title: Mac 64-bit syscall
body: <p>How to execute a <strong>64-bit</strong> <code>syscall</code> on Mac in C++.</p>
  
  <p>I need the below to work:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;sys/syscall.h&gt;
  #include &lt;sys/types.h&gt;
  
  int main() {
    long* addr = (long*) syscall(SYS_mmap, 0, 100, 1 | 2, 2 | 4096, -1, 0);
  }
  </code></pre>
  
  <p>The problem is that <code>addr</code> below should be 64-bit as it is a pointer, but it truncates the result to 32-bit value.</p>
  
  <p>I compile with:</p>
  
  <pre><code>g++ ./mmap.cc -o ./mmap 
  </code></pre>
  
  <p>P.S. I know there exists <code>mmap</code> function, the above is just an example, I need to get <code>syscall</code> function to work.</p>
  
  <p>P.P.S. The problem is that on 64-bit systems <code>syscall</code> should return 64-bit value, but in Mac <code>unistd.h</code> it is defined as <code>int</code>:</p>
  
  <pre><code>int  syscall(int, ...);
  </code></pre>
  
  <p>Is that a bug? The <code>mmap</code> system call return correctly <code>void*</code>:</p>
  
  <pre><code>void *  mmap(void *, size_t, int, int, int, off_t) __DARWIN_ALIAS(mmap);
  </code></pre>
  
  <p>How is <code>mmap</code> actually implemented?</p>
  
  <p>P.P.P.S.</p>
  
  <p>On Linux it is defined correctly as long:</p>
  
  <pre><code>long syscall(long number, ...);
  </code></pre>