title: How to call machine code stored in char array?
body: <p>I'm trying to call native machine-language code. Here's what I have so far (it gets a bus error):</p>
  
  <pre><code>char prog[] = {'\xc3'}; // x86 ret instruction
  
  int main()
  {
      typedef double (*dfunc)();
  
      dfunc d = (dfunc)(&amp;prog[0]);
      (*d)();
      return 0;
  }
  </code></pre>
  
  <p>It does correctly call the function and it gets to the ret instruction.  But when it tries to execute the ret instruction, it has a SIGBUS error.  Is it because I'm executing code on a page that is not cleared for execution or something like that?</p>
  
  <p>So what am I doing wrong here? </p>