title: How to get c code to execute hex machine code?
body: <p>I want a simple C method to be able to run hex bytecode on a Linux 64 bit machine.  Here's the C program that I have:</p>
  
  <pre><code>char code[] = "\x48\x31\xc0";
  #include &lt;stdio.h&gt;
  int main(int argc, char **argv)
  {
          int (*func) ();
          func = (int (*)()) code;
          (int)(*func)();
          printf("%s\n","DONE");
  }
  </code></pre>
  
  <p>The code that I am trying to run (<code>"\x48\x31\xc0"</code>) I obtained by writting this simple assembly program (it's not supposed to really do anything)</p>
  
  <pre><code>.text
  .globl _start
  _start:
          xorq %rax, %rax
  </code></pre>
  
  <p>and then compiling and objdump-ing it to obtain the bytecode.</p>
  
  <p>However, when I run my C program I get a segmentation fault.  Any ideas?</p>