Getting a bus error in Assembly in-line programming x86

江枫思渺然 提交于 2019-12-12 00:13:55

问题


I stumbled upon an assembly programming challenge where I need to find why the following code gives a Bus Error when trying to run it. After much googling, I still can't figure out why.. My understanding of assembly x86 not great, any tips on finding the solution would be very appreciated.

Here is the code:

#include <stdlib.h>
int main(void) {
  asm("pushf\n"
      "orl $ 0x40000, (%esp)\n"
      "popf\n");

  *((int*) (((char*) malloc(5)) + 1)) = 23; // This line causes the Bus Error


  return 0;
}

回答1:


Essentially you are setting a flag in the flags register. Flag 0x40000, aka bit 18 which according to http://en.wikipedia.org/wiki/FLAGS_register_%28computing%29 is

18 AC Alignment check (486SX+ only) X

If you search for "flag alignment check" you find amongst others:

http://forum.soft32.com/linux2/Turn-x86-Alignment-Check-ftopict12003.html

I hope this sets you on the right track. But do you really have a 486SX?



来源:https://stackoverflow.com/questions/10322394/getting-a-bus-error-in-assembly-in-line-programming-x86

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!