作者:dmcm0008 | 来源:互联网 | 2023-09-12 19:44
IhaveaWindowsapplicationthatHAStorunas32-bits(becauseofotherlimitationsoutofmycont
I have a Windows application that HAS to run as 32-bits (because of other limitations out of my control). However, my application has to call and access a driver which may be 32-bits or 64-bits depending on the system where it is installed.
我有一个Windows应用程序,它可以作为32位运行(由于我的控制之外的其他限制)。但是,我的应用程序必须调用和访问可能是32位或64位的驱动程序,具体取决于安装它的系统。
I access the driver through DeviceIoControl() calls, exchanging data structures declared in an include file. Data structures contains fields declared as "DWORD_PTR" (the include file I don't control either).
我通过DeviceIoControl()调用访问驱动程序,交换在include文件中声明的数据结构。数据结构包含声明为“DWORD_PTR”的字段(我不控制的包含文件)。
My problem is that on a 64-bits system, the driver expects the structures to contain 64-bits integer (because of DWORD_PTR declaration). However, my 32-bits program sees those DWORD_PTR as 32-bits integers. I then have a data mismatch between my program version of the data structures and the driver understanding of those structures.
我的问题是在64位系统上,驱动程序期望结构包含64位整数(因为DWORD_PTR声明)。但是,我的32位程序将那些DWORD_PTR视为32位整数。然后,我的数据结构的程序版本与驱动程序对这些结构的理解之间存在数据不匹配。
DeviceIoControl() ends-up failing with ERROR_INSUFFICIENT_BUFFER (The data area passed to a system call is too small). I confirmed that I don't get this error if I pass a 64-bits version of the structs to the driver.
DeviceIoControl()以ERROR_INSUFFICIENT_BUFFER结束失败(传递给系统调用的数据区域太小)。我确认如果我将64位版本的结构传递给驱动程序,我不会收到此错误。
I have a few ugly options out of this mess. But I wonder if anyone has some nicer suggestions?
我有一些丑陋的选择。但我想知道是否有人有更好的建议?
Solution:
- Declare a new copy of the shared structures with REAL 64-bits data fields (__int64)
使用REAL 64位数据字段(__int64)声明共享结构的新副本
- Dynamically check the OS architecture (32/64)
动态检查OS体系结构(32/64)
- Use the 32-bits or 64-bits version of the structures for the DeviceIoControl() calls.
使用32位或64位版本的结构进行DeviceIoControl()调用。
Drawbacks:
My other solutions are variation of this one, but they ALWAYS involve maintaining some copy of the structures definition (for example in an IDL for COM servers option).
我的其他解决方案是这个的变体,但它们总是涉及维护结构定义的一些副本(例如,在COML for COM服务器选项中)。
Edit: This is a Microsoft driver and it seems it does not use IoIs32bitsProcess(irp)!
编辑:这是一个Microsoft驱动程序,似乎它不使用IoIs32bitsProcess(irp)!
2 个解决方案