Machine code: Difference between revisions

→‎{{header|C}}: Do the whole task
(C code)
(→‎{{header|C}}: Do the whole task)
Line 32:
char code[] = {0x8B, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xC3};
void *buf;
int c;
/* copy code to executable buffer */
buf = mmap (0,sizeof(code),PROT_READ|PROT_WRITE|PROT_EXEC,
Line 38 ⟶ 39:
memcpy (buf, code, sizeof(code));
/* run code */
returnc = ((int (*) (int, int))buf)(a, b);
/* free buffer */
munmap (buf, sizeof(code));
return c;
}
 
Anonymous user