icesword
驱动牛犊
驱动牛犊
  • 注册日期2002-06-03
  • 最后登录2009-10-10
  • 粉丝0
  • 关注0
  • 积分3分
  • 威望52点
  • 贡献值0点
  • 好评度22点
  • 原创分0分
  • 专家分0分
阅读:1127回复:2

地址转换的问题,如何将驱动层的地址转换为WIN32应用程序的地址

楼主#
更多 发布于:2003-07-11 10:52
做了一个测试发现用DEVICEIOCONTROL到驱动读数值,传进去的入
参发生了变换,本来是传一个地址为0x00867654 进去就变成了
其他值,所以如果要取某程序传到驱动的一个地址参数,肯定要
经过转换才能得到该参数在此程序中的虚拟地址,不过不知道怎么
转换还请多多指教。
Dragon2008
驱动中牛
驱动中牛
  • 注册日期2002-04-01
  • 最后登录2006-03-13
  • 粉丝0
  • 关注0
  • 积分31分
  • 威望5点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
沙发#
发布于: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;
}
我姓龙,我属龙,我叫龙。。。
icesword
驱动牛犊
驱动牛犊
  • 注册日期2002-06-03
  • 最后登录2009-10-10
  • 粉丝0
  • 关注0
  • 积分3分
  • 威望52点
  • 贡献值0点
  • 好评度22点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-07-11 16:11
我是用DDK做的用 ,先谢过了:)
回去试一下
游客

返回顶部