访问前 "kernel memory check" 的 C++ 函数

C++ function for "kernel memory check" before accessing

我正在开发一个简单的设备驱动程序以供学习。通过大量测试,我创建了很多错误,最终导致我的计算机出现蓝屏。我确定这是内存崩溃的原因。所以现在我想在继续之前检查我的代码是否可以访问内核内存。 我的问题是什么函数可以检查它在内核内存中是否可访问。例如,有一个包含两个字段的指针结构,我想访问第一个字段,它也是一个指针,但现在知道它是否真的具有可访问的值或只是垃圾值。 在这个给定的上下文中,我需要检查它以确保我没有出现蓝屏。 提前致谢!

这对于内核内存来说是不可能的。您必须确切地知道内核地址是否有效并且在访问期间有效。如果你从用户模式获取地址 - 你可以而且必须使用 ProbeForRead or ProbeForWrite. but this is only for user-mode buffer. for any kernel memory (even valid and resident) this function just raise exception. from invalid access to kernel memory address no any protection. try - except handler not help here - you just got PAGE_FAULT_IN_NONPAGED_AREA bug check

For instance, there is a pointer structure with two fields and I want to access the first field which is also a pointer but do now know whether it really has an accessible value or just trash value.

你从哪里得到这个指针的?谁来填补这个结构?你不能检查。您必须在开始时就知道该指针是有效的,并且结构的上下文在您使用它期间将是有效的。否则你的代码已经是错误的和错误的