如何从 OSX 上的用户空间写入 x86 调试寄存器?

发布于 2024-08-28 01:21:14 字数 284 浏览 7 评论 0原文

我想在我的 OSX 用户空间程序中使用 x86 规范 (DR0-7) 中定义的调试 MSR。不幸的是,这些需要 CPL == 0(又名环 0)。我翻阅了 OSX 系统调用,除了 kernel_debug 之外,没有什么真正跳出来作为访问这些系统调用的方法。

可能情况是,它们只能通过一些更高级别的接口(如kernel_debug)使用,但我不清楚是否是这种情况,或者我只是还没有找到访问它们的魔法调用。

我的最终目标是访问这些寄存器的功能,而不是寄存器本身。有谁知道如何做设置硬件断点之类的事情?

I'd like to play around with the debug MSRs defined in the x86 spec (DR0-7) from my OSX user-space program. Unfortunately, these require CPL == 0 (aka ring 0). I've thumbed through the OSX syscalls and with the exception of kernel_debug nothing really jumps out as a way to access these.

It may be the case that they are only available via some higher level interface like kernel_debug, but it's unclear to me if that's the case or if I just haven't found the magic invocation to get to them.

My end goal is accessing the functionality of these registers, not the registers themselves. Does anyone have insight on how to do things like set hardware breakpoints?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

渡你暖光 2024-09-04 01:21:14

事实证明 thread_get_state/thread_set_state 就是答案。

#include <mach/mach_types.h>

thread_t target = get_target_thread();
struct x86_debug_state dr;
mach_msg_type_number_t dr_count = x86_DEBUG_STATE_COUNT;

kern_return_t rc = thread_get_state(target, x86_DEBUG_STATE, &dr, &dr_count);    
printf("DR0: 0x%08x\n", dr.uds.ds32.__dr0);
printf("DR1: 0x%08x\n", dr.uds.ds32.__dr1);
printf("DR2: 0x%08x\n", dr.uds.ds32.__dr2);
printf("DR3: 0x%08x\n", dr.uds.ds32.__dr3);
printf("DR4: 0x%08x\n", dr.uds.ds32.__dr4);
printf("DR5: 0x%08x\n", dr.uds.ds32.__dr5);
printf("DR6: 0x%08x\n", dr.uds.ds32.__dr6);
printf("DR7: 0x%08x\n", dr.uds.ds32.__dr7);

It turns out thread_get_state/thread_set_state is the answer.

#include <mach/mach_types.h>

thread_t target = get_target_thread();
struct x86_debug_state dr;
mach_msg_type_number_t dr_count = x86_DEBUG_STATE_COUNT;

kern_return_t rc = thread_get_state(target, x86_DEBUG_STATE, &dr, &dr_count);    
printf("DR0: 0x%08x\n", dr.uds.ds32.__dr0);
printf("DR1: 0x%08x\n", dr.uds.ds32.__dr1);
printf("DR2: 0x%08x\n", dr.uds.ds32.__dr2);
printf("DR3: 0x%08x\n", dr.uds.ds32.__dr3);
printf("DR4: 0x%08x\n", dr.uds.ds32.__dr4);
printf("DR5: 0x%08x\n", dr.uds.ds32.__dr5);
printf("DR6: 0x%08x\n", dr.uds.ds32.__dr6);
printf("DR7: 0x%08x\n", dr.uds.ds32.__dr7);
給妳壹絲溫柔 2024-09-04 01:21:14

这几乎就是ring 0 指令的要点。 它们无法从用户空间访问

That's pretty much the point of ring 0 instructions. They are not accessible from userspace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文