Prohibit unaligned memory accesses on x86/x86_64

前端 未结 3 1732
长情又很酷
长情又很酷 2020-12-14 04:06

I want to emulate the system with prohibited unaligned memory accesses on the x86/x86_64. Is there some debugging tool or special mode to do this?

I want to run many

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 04:42

    It's tricky and I haven't done it personally, but I think you can do it in the following way:

    x86_64 CPUs (specifically I've checked Intel Corei7 but I guess others as well) have a performance counter MISALIGN_MEM_REF which counter misaligned memory references.

    So first of all, you can run your program and use "perf" tool under Linux to get a count of the number of misaligned access your code has done.

    A more tricky and interesting hack would be to write a kernel module that programs the performance counter to generate an interrupt on overflow and get it to overflow the first unaligned load/store. Respond to this interrupt in your kernel module but sending a signal to your process.

    This will, in effect, turn the x86_64 into a core that doesn't support unaligned access.

    This wont be simple though - beside your code, the system libraries also use unaligned accesses, so it will be tricky to separate them from your own code.

提交回复
热议问题