当cpu写入特定地址时,是否可以设置中断? [英] Is that possible to set interrupt that breaks when cpu write to an specific address?

查看:29
本文介绍了当cpu写入特定地址时,是否可以设置中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在写入特定地址时使 x86 cpu 中断?

Is it possible to make x86 cpu interrupt when specific address is being written?

我想要一个硬件机制来监控一些地址的变化.

I want a hardware mechanism to monitor some address's changing.

推荐答案

我想知道是否可以在写入特定地址时使x86 cpu中断??

I would like to know if it is possible to make x86 cpu intrrupt when specific address is being written??

这是可能的.

您可以将调试寄存器之一(DR0DR4)设置为要监视的地址,然后在 DR7<中配置相应的标志/code> 作为全局断点,仅在数据写入时中断,1 字节大小".一旦完成,该 CPU 完成的任何正常数据写入都将触发调试异常(中断 1),并且调试异常处理程序可以弄清楚发生了什么并执行您想要的任何操作(例如向用户报告写入?).

You'd set one of the debug registers (DR0 to DR4) to the address you want to monitor, then configure the corresponding flags in DR7 as "global breakpoint, break on data write only, 1-byte size". Once that's done, any normal data write done by that CPU will trigger a Debug Exception (interrupt 1), and the Debug Exception handler can figure out what happened and do whatever actions you wanted (e.g. report the write to the user?).

然而,有一些限制——你不能在用户空间自己做这件事,需要依赖内核的支持;内核的支持希望包括在任务切换期间保存/恢复调试寄存器(这样当您的任务在另一个 CPU 上运行时,您的断点不会停止工作,并且您的断点不会导致其他任务出现问题).因此(除非您完全控制计算机/CPU - 例如您正在编写自己的内核)通常您必须依赖操作系统提供的任何 API.

However, there are restrictions - you can't just do this yourself in user-space and would need to rely on kernel's support; and kernel's support would want to include saving/restoring debug registers during task switches (so that your breakpoints don't stop working when your task is run on another CPU, and so that your breakpoints don't cause problems for other tasks). Because of that (unless you have full control of the computer/CPU - e.g. you're writing your own kernel) normally you'd have to rely on whatever API the OS provides.

如果其他东西修改了内存(例如磁盘控制器或网卡),它也不会工作.

It also won't work if something else modifies the memory (e.g. a disk controller or network card).

这篇关于当cpu写入特定地址时,是否可以设置中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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