C++ 共享内存执行得这么快?
我试图在内核中执行的操作:C++ 共享内存执行得这么快?,c++,c,windows,kernel,shared-memory,C++,C,Windows,Kernel,Shared Memory,我试图在内核中执行的操作: while (TRUE) { //DbgPrintEx(0, 0, "First loop is running \n"); ReadSharedMemory(); if (!(PCHAR)SharedSection == NULL && strcmp((PCHAR)SharedSection, "Read") == 0) { DbgPrintEx(0, 0, "Read lo
while (TRUE)
{
//DbgPrintEx(0, 0, "First loop is running \n");
ReadSharedMemory();
if (!(PCHAR)SharedSection == NULL && strcmp((PCHAR)SharedSection, "Read") == 0)
{
DbgPrintEx(0, 0, "Read looping \n");
RtlZeroMemory(SharedSection, sizeof(SharedSection));
break;
}
else if (!(PCHAR)SharedSection == NULL && strcmp((PCHAR)SharedSection, "Write") == 0)
{
DbgPrintEx(0, 0, "Write looping \n");
RtlZeroMemory(SharedSection, sizeof(SharedSection));
break;
}
LARGE_INTEGER Timeout;
Timeout.QuadPart = RELATIVE(SECONDS(1));
KeDelayExecutionThread(KernelMode, FALSE, &Timeout);
}
在用户模式下:
auto pBufW = (char*)MapViewOfFile(hMapFileW, FILE_MAP_WRITE, 0, 0, 4096);
RtlCopyMemory(pBufW, "Read", 4);
printf("message has been sent to kernel! \n");
UnmapViewOfFile(pBufW);
Sleep(10);
auto pBfW = (char*)MapViewOfFile(hMapFileW, FILE_MAP_WRITE, 0, 0, 4096);
RtlCopyMemory(pBfW, "Write", 5);
printf("message has been sent to kernel! \n");
UnmapViewOfFile(pBfW);
我不明白为什么我叫读写。只写执行我已经尝试了多次,它总是这样做+我试图添加睡眠(1);在我的用户模式下(认为它执行得非常快)
基本上,我只需要它们正常执行,就像读应该先执行然后写一样。有人帮了我,这就是我所做的
while ( memcmp( pBufW, "Read", 4) == 0 )
{
Sleep(1);
}
UnmapViewOfFile(pBufW);
简单的检查,现在可以正常工作了:D有人帮了我,我就是这么做的
while ( memcmp( pBufW, "Read", 4) == 0 )
{
Sleep(1);
}
UnmapViewOfFile(pBufW);
简单的检查,现在就可以正常工作了:D如果你的意思是
If(SharedSection!=nullptr)
那么请这样写…另外,strcmp
需要一个以NUL结尾的字符串,而你没有提供…@Ben VoigtRtlCopyMemory(pBfW,“write”,5)代码>我是,请看“写”是6个字符,包括空终止符我做5?你能解释一下,如果我用错误的方法做这件事,我该怎么做吗?你到底用了什么MapViewOfFile
?这有什么意义?@RbMm用于向我的驱动程序发送字符串以与之通信?如果你的意思是If(SharedSection!=nullptr)
那么请这样写…另外,strcmp
需要以NUL结尾的字符串,而你没有提供…@Ben VoigtRtlCopyMemory(pBfW,“write”,5)代码>我是,请看“写”是6个字符,包括空终止符我做5?你能解释一下,如果我用错误的方法做这件事,我该怎么做吗?你到底用了什么MapViewOfFile
?这有什么意义?@RbMm发送字符串给我的驱动程序与之通信?