Last reprinted a blog has introduced the drive layer to actively send data to the application layer method, one of the methods described below is somewhat different, the last time you created the event object at the application layer, creating MDL (Memory Descriptor) at the driver layer to implement synchronous communication, and this time creating virtual memory at the application tier, The driver translates the virtual address into a physical address and then turns it into a virtual address that the driver can access, as well as the purpose of memory sharing.
Driver Layer Part Code
Switch (IoControlCode)
{case
2001: //Incoming shared memory
{
buff = (Uchar *) irp-> AssociatedIrp.SystemBuffer;
Memmove (&a,&buff[4],4);
output= (char*) Mmmapiospace (Mmgetphysicaladdress ((void*) a), 256,0);
break;
Case 2002: //Get semaphore
{
buff = (Uchar *) Irp->associatedirp.systembuffer;
Memmove (&appevent,&buff[0],4);
Memmove (&sysevent,&buff[4],4);
Obreferenceobjectbyhandle (appevent,generic_all,null,kernelmode,&appeventobject,null);
Obreferenceobjectbyhandle (sysevent,generic_all,null,kernelmode,&syseventobject,null);
break;
...
}
The above is the application layer through the corresponding control code incoming events and shared memory, the next driver layer to actively relax the content to the application layer
Memmove (&output[0],&a,4);
KeSetEvent ((prkevent) appeventobject,0,0);
KeWaitForSingleObject ((prkevent) syseventobject,executive,kernelmode,0,0);
Keresetevent ((prkevent) syseventobject);
Memmove (&a,&output[4],4);