如何捕获未对齐的内存访问? [英] How to trap unaligned memory access?

查看:308
本文介绍了如何捕获未对齐的内存访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作实现一些流密码算法的宠物开源项目,我有一个bug麻烦才会触发,当我在ARM处理器上运行。我甚至试图在运行qemu下的的x86二进制ARM,但错误没有被触发那里。

I am working on a pet open-source project that implements some stream cipher algorithms and I am having trouble with a bug triggered only when I run it on an ARM processor. I have even tried running the ARM binary in x86 under qemu, but the bug isn't triggered there.

错误的具体机制仍不清楚,但我最好的拍摄是认为它是由我的程序进行未对齐的内存访问尝试引起的,即由QEMU实现,但在我的发展默默的真实ARM处理器忽略板。

The specifics mechanisms of the bug remains elusive, but my best shot is to believe that it is caused by unaligned memory access attempt made in my program, that is fulfilled by qemu, but silently ignored by the real ARM processor in my development board.

所以,因为这个问题正显示出非常难以诊断,我想知道是否有任何工具,我可以用它来我的正在运行的程序做出陷阱对齐的内存访问,这样我可以清楚地看到哪里问题发生。

So, since the problem is showing to be very hard to diagnose, I would like to know if there is any tool that I could use to trap unaligned memory access made by my running program, so that I can see exactly where the problem happens.

我还可以使用能够以某种方式,在我的ARM开发板,一些信号(SIGBUS,也许?)将发行,如果这个过程违反了内存对齐限制,就像我们访问映射的内存地址时,得到SIGSEGV。它是运行Linux 2.6.32。

I could also use some way of enabling, on my ARM development board, some signal (SIGBUS, maybe?) to be issued if the process violates memory alignment restrictions, like we get SIGSEGV when accessing unmapped memory address. It is running Linux 2.6.32.

推荐答案

Linux可以做修正为你或警告的机会。

Linux can do the fixup for you or warn about the access.

您可以启用在/ proc / CPU /对齐行为,请参阅http://www.mjmwired.net/kernel/Documentation/arm/mem_alignment为不同的值的说明

You can enable the behavior in /proc/cpu/alignment, see http://www.mjmwired.net/kernel/Documentation/arm/mem_alignment for an explanation of the different values.

0 - Do nothing (default behavior)
1 - Warning in kernel-log with PC and Memory-Address printed.
2 - Fixup error
3 - Warn and Fixup
4 - Send a SIGBUS to the process
5 - Send SIGBUS and output Warning

这篇关于如何捕获未对齐的内存访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆