简体   繁体   中英

Shared memory is executing so fast?

what i am trying to do in kernel :

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);
}

and in user mode :

    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);

i can't figure it out why when i call Read and Write . only Write execute i have tried it multiple times and its always doing this + i have tried to add a sleep(1); in my user mode (thought it was executing real fast).

basically i just need them to execute normally like Read should be executed first then Write .

someone helped me with it , this is what i did

  while ( memcmp( pBufW, "Read", 4) == 0 )
    {
           Sleep(1);
    }
UnmapViewOfFile(pBufW);

simple check and it works fine now :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM