【发布时间】:2019-08-08 05:23:33
【问题描述】:
我想在内核中做什么:
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);
当我调用 Read 和 Write 时,我无法弄清楚为什么。只有写执行我已经尝试过多次并且它总是这样做+我试图添加一个睡眠(1);在我的用户模式下(认为它执行得非常快)。
基本上我只需要它们像 Read 应该先执行然后 Write 一样正常执行。
【问题讨论】:
-
如果你的意思是
if (SharedSection != nullptr),那么请这样写... -
另外,
strcmp需要一个 NUL-terminated 字符串,而您没有提供... -
@Ben Voigt
RtlCopyMemory(pBfW, "Write", 5);我是,看到“写”是 6 个字符,包括空终止符我做 5?你能解释一下如果我用错误的方式做那我该怎么做吗? -
你用
MapViewOfFile做什么?这有什么意义? -
@RbMm 用于向我的驱动程序发送字符串以与之通信?
标签: c++ c windows kernel shared-memory