This is quite simple:
if( Buffer != NULL )
{
// Build a MDL which will describe the buffer
Irp->MdlAddress = IoAllocateMdl(Buffer, Length, FALSE, FALSE, NULL);
if( Irp->MdlAddress == NULL )
{
// Allocation failed
IoFreeIrp(Irp);
ExFreePool(Srb);
return STATUS_INSUFFICIENT_RESOURCES;
}
// Probe and lock the MDL
__try
{
MmProbeAndLockPages(Irp->MdlAddress, KernelMode,
Write ? IoReadAccess : IoWriteAccess);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
// Probe failed - invalid address
IoFreeMdl(Irp->MdlAddress);
IoFreeIrp(Irp);
ExFreePool(Srb);
return GetExceptionCode();
}
}
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roddy, Mark
Sent: Tuesday, December 11, 2001 9:45 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Pointers in IOControl
It isn’t illegal, it is however unusual and not the normal NT practice.
You have to guarantee that all accesses to the buffer will be in the
calling process context at less than dispatch level, and you have to
contain any access faults so that the system does not crash, or you have
to do everything that the operating system would do to map and lock the
pages and describe them with an MDL… The effort involved in doing this
correctly generally exceeds the effort required to re-work your
application to ‘do things the NT way’, and consequently it is generally
a waste of time and money.
If you use DIRECT_IO there is no copying of user data. There is the
overhead of locking down the user data pages, but if you are actually
going to access all of these pages anyway, the cost is more the length
of time that you have the pages locked rather than the cost of paging
the data into memory. DIRECT_IO operations are generally limited to less
than 64MB.
-----Original Message-----
From: Nachum Kanovsky [mailto:xxxxx@yahoo.com]
Sent: Tuesday, December 11, 2001 11:50 AM
To: NT Developers Interest List
Subject: [ntdev] Pointers in IOControl
I have an ioctl that allows the user to write a buffer to device memory.
My question is whether it is legal to receive a pointer from user space,
and use that pointer in the driver to write to the device memory?
If it is not legal, what is the best way to allow a user to write more
than a limited copied buffer to the device, if I don’t want to map it to
the user, and I still want to use the ioctl albeit modified a bit?
thanx
Nachum Kanovsky
Driver Development Team
xxxxx@mangodsp.com
02 5328706
011 972 2 532 8706
You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com