Watch a memory location/install 'data breakpoint' from code?

前端 未结 5 1088
迷失自我
迷失自我 2020-12-21 04:37

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem hap

5条回答
  •  难免孤独
    2020-12-21 05:09

    If you can control the location of the variable then you can allocate it on a dedicated page and set the permissions of the page to allow reads only using VirtualProtect (on Windows ... not sure for Linux).

    This way you will get an access violation when someone tries to write to it. With an exception translator function you could treat this as a callback.

    Even if you can't move the variable directly (eg. it is a class member), maybe you could add sufficient padding around the variable to ensure it is on a dedicated page and use the same approach.

提交回复
热议问题