阅读:1189回复:2
地址转换的问题,如何将驱动层的地址转换为WIN32应用程序的地址
做了一个测试发现用DEVICEIOCONTROL到驱动读数值,传进去的入
参发生了变换,本来是传一个地址为0x00867654 进去就变成了 其他值,所以如果要取某程序传到驱动的一个地址参数,肯定要 经过转换才能得到该参数在此程序中的虚拟地址,不过不知道怎么 转换还请多多指教。 |
|
沙发#
发布于:2003-07-11 11:16
下面的程序是用DS做的,可以的。你是用DS做的吗?
KMemoryToProcessMap* MemRegion;//定义到XXXDevice类的头文件中。 NTSTATUS SX5933Device::IOCTL_MEM_Handler(KIrp I) { NTSTATUS status = STATUS_SUCCESS; t << \"Entering SX5933Device::IOCTL_MEM_Handler, \" << I << EOL; // TODO: Verify that the input parameters are correct // If not, return STATUS_INVALID_PARAMETER // TODO: Handle the the IOCTL_MEM request, or // defer the processing of the IRP (i.e. by queuing) and set // status to STATUS_PENDING. ULONG Address=Phy_Address.LowPart; MemRegion = new (NonPagedPool) KMemoryToProcessMap(Address, // peripheral memory address mem_length, // number of bytes (HANDLE)-1, // current process FALSE, // don\'t do kernel mapping NULL, // any address ViewShare); // view inherit if ( !MemRegion||!NT_SUCCESS( MemRegion->ConstructorStatus() ) ) { // insufficient memory I.Information() = 0; return FALSE; } ((Mem_Param*)I.IoctlBuffer())->mdr_PhysicalAddress=Address; ((Mem_Param*)I.IoctlBuffer())->mdr_LinearAddress=MemRegion->ProcessAddress(); // TODO: Assuming that the request was handled here. Set I.Information // to indicate how much data to copy back to the user. I.Information() = sizeof(ULONGLONG); return status; } 用完了别忘了UNMAP一下:( NTSTATUS SX5933Device::IOCTL_UNMEM_Handler(KIrp I) { NTSTATUS status = STATUS_SUCCESS; t << \"Entering SX5933Device::IOCTL_UNMEM_Handler, \" << I << EOL; // TODO: Verify that the input parameters are correct // If not, return STATUS_INVALID_PARAMETER // TODO: Handle the the IOCTL_UNMEM request, or // defer the processing of the IRP (i.e. by queuing) and set // status to STATUS_PENDING. delete MemRegion; // TODO: Assuming that the request was handled here. Set I.Information // to indicate how much data to copy back to the user. I.Information() = 0; return status; } |
|
|
板凳#
发布于:2003-07-11 16:11
我是用DDK做的用 ,先谢过了:)
回去试一下 |
|