我正在编写一个需要分配非分页内存池的驱动程序,并且出于性能考虑,该内存必须可以从用户模式程序直接访问。
在驱动程序条目中,我使用这两种类型的方法分配了一些内存:
pMdl = IoAllocateMdl(NULL,
4096,
FALSE,
FALSE,
NULL);
if(!pMdl) {
DbgPrintEx(DPFLTR_IHVVIDEO_ID, DPFLTR_INFO_LEVEL, "Error on IoAllocateMdl. Returning from driver early.\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
MmBuildMdlForNonPagedPool(pMdl);
userMemory = (void *)MmMapLockedPagesSpecifyCache(pMdl, UserMode, MmWriteCombined, NULL, FALSE, LowPagePriority);
Run Code Online (Sandbox Code Playgroud)
和
userMemory = ExAllocatePoolWithTag(
NonPagedPool,
4096,
POOL_TAG);
Run Code Online (Sandbox Code Playgroud)
现在我不想每次需要从该内存写入/读取时都发出 DeviceIoControl,而是想做这样的事情:
char* sharedMem;
.....
transactionResult = DeviceIoControl ( hDevice,
(DWORD) IOCTL_MMAP,
NULL,
0,
sharedMem,
sizeof(int),
&bRetur,
NULL
);
.....
sharedMem[0]='c';
Run Code Online (Sandbox Code Playgroud)
使用DeviceIoControl获取内核内存中的地址,然后直接使用它,就像Linux下的mmap一样。
在 Windows 中是否有某种方法可以做到这一点?
我已经这样做了:
hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // Read/write access
TRUE,
"Global\\SharedMemory"); // Name of mapping object …Run Code Online (Sandbox Code Playgroud) 我正在调用EXPECT_CALL一个模拟函数display(),但它返回运行时错误
Actual function call count doesn't match EXPECT_CALL(*mock, display())...
./GTest_static_example.tst
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from GTest_static_example
[ RUN ] GTest_static_example.case1
inside the GTEST_static_class:: display
display called from GTest_static_example
package/web/webscr/GTest_static_example.cpp:70: Failure
Actual function call count doesn't match EXPECT_CALL(*mock, display())...
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] GTest_static_example.case1 (0 ms)
[----------] 1 test from GTest_static_example (0 ms …Run Code Online (Sandbox Code Playgroud)