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

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

问题描述

我正在开发一个实现一些流密码算法的宠物开源项目,但我遇到了一个错误,只有当我在 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/alignment 中启用该行为,请参阅 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天全站免登陆