我坐在Intel MacOSX 10.6上并使用GCC 4.2.1。我试图做的是分配一个缓冲区,用机器指令填充它,然后运行它。全部在一个程序中。
例如,
typedef unsigned char byte_t;
int main(int argc, char** argv) {
byte_t* code = new byte_t[3];
code[0] = 0x90; // NOP
code[1] = 0xC9; // LEAVE - tried also without this.
code[2] = 0xCB; // RET far - tried also 0xC3, the near return.
((void (*)(void)) code)();
return 0;
}
因总线错误消息而失败。我在这里做错了什么?