Click here to Skip to main content
16,017,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
kernel mode :

<pre>VOID DriverLoop() {

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



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 .

What I have tried:

i have tried to add a sleep of 1 and 10 seconds and it didn't work idk what i am doing wrong here.
Posted
Updated 17-Mar-19 16:15pm

1 solution

What you are doing wrong is hoping that two processes in different execution rings can coordinate themselves by pure luck.

As I have written to you before, you need to use a signalling mechanism. This can be a simple counter that the processes watch for a change or it could be an event (or two) that is/are signalled when work needs to be done and when it is complete. There are certainly many more possibilities but those are two that are quite simple to implement.
 
Share this answer
 
Comments
Member 14130865 18-Mar-19 12:06pm    
@Rick York could you link some of them , because i don't know how to share a mutex or an event between kernel and user mode . btw i don't want to use any system threads or DevicIocontrol . :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900