Sharing memory query

Hello All
I want to share a portion of memory between the user mode application & the
kernel mode driver.The application allocates the memory buffer and then
issues an IOCTL to the driver to provide the buffer pointer to it.The driver
implements METHOD_DIRECT for sharing memory.The driver then returns a
STATUS_PENDING code to the application.The driver then fills the buffer with
some data at a later stage.If the application is to access the data then
which of the following methods should I implement ?

1.The driver generates a notification event to the application to read the
data.I do not want to complete the IOCTL request with STATUS_SUCCESS because
I want to re-use the same buffer again.Can the application access the buffer
in this case?Does the buffer remain locked by the IO manager for the period
the request is not completed with STATUS_SUCCESS?

2.Complete the IOCTL request with STATUS_SUCCESS & have another request from
the application to gain another pointer from it.

Any help on this would be greatly appreciated.

Regards,
Sachin Anvekar

Use the event method. When, and not until, you complete the IOCTL the
operating system will unlock the buffer. Note that ‘locked’ does not
mean you can’t access the buffer, (from either user mode or kernel
mode,) it means that the pages of virtual memory associated with the
buffer are not going to page-out until the buffer is unlocked.

You can include the event in the ‘input buffer’ portion of the IOCTL as
a handle value, and use the ‘output buffer’ portion of the IOCTL as the
shared memory buffer. Use the correct value for METHOD_X_DIRECT to keep
everyone happy. You will have to convert the event handle to a waitable
object, but there are documented apis for doing this.

=====================
Mark Roddy
Windows XP/2000/NT Consultant, Microsoft MVP
Hollis Technology Solutions 603-321-1032
www.hollistech.com
xxxxx@hollistech.com
For Windows Device Driver Training: see www.azius.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Sachin
Sent: Monday, August 05, 2002 1:37 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing memory query

Hello All
I want to share a portion of memory between the user
mode application & the kernel mode driver.The application
allocates the memory buffer and then issues an IOCTL to the
driver to provide the buffer pointer to it.The driver
implements METHOD_DIRECT for sharing memory.The driver then
returns a STATUS_PENDING code to the application.The driver
then fills the buffer with some data at a later stage.If the
application is to access the data then which of the following
methods should I implement ?

1.The driver generates a notification event to the
application to read the data.I do not want to complete the
IOCTL request with STATUS_SUCCESS because I want to re-use
the same buffer again.Can the application access the buffer
in this case?Does the buffer remain locked by the IO manager
for the period the request is not completed with STATUS_SUCCESS?

2.Complete the IOCTL request with STATUS_SUCCESS & have
another request from the application to gain another pointer from it.

Any help on this would be greatly appreciated.

Regards,
Sachin Anvekar


You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
%%email.unsub%%

Be aware to validate the contents of your share memory segment in your
ioctl dispatch routine. A rogue application could send the same ioctl down
to your driver and potentially crash your driver. Remember that you have to
capture the contents of the buffer once and validate the captured values and
used the captured values. Otherwise a rogue application can keep changing
the values while your driver accesses them. I think you should use
METHOD_OUT_DIRECT for your problem.


Nar Ganapathy
Windows Core OS group
This posting is provided “AS IS” with no warranties, and confers no rights.

“Mark Roddy” wrote in message news:xxxxx@ntdev…
>
> Use the event method. When, and not until, you complete the IOCTL the
> operating system will unlock the buffer. Note that ‘locked’ does not
> mean you can’t access the buffer, (from either user mode or kernel
> mode,) it means that the pages of virtual memory associated with the
> buffer are not going to page-out until the buffer is unlocked.
>
> You can include the event in the ‘input buffer’ portion of the IOCTL as
> a handle value, and use the ‘output buffer’ portion of the IOCTL as the
> shared memory buffer. Use the correct value for METHOD_X_DIRECT to keep
> everyone happy. You will have to convert the event handle to a waitable
> object, but there are documented apis for doing this.
>
> =====================
> Mark Roddy
> Windows XP/2000/NT Consultant, Microsoft MVP
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
> xxxxx@hollistech.com
> For Windows Device Driver Training: see www.azius.com
>
>
>
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Sachin
> > Sent: Monday, August 05, 2002 1:37 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] Sharing memory query
> >
> >
> > Hello All
> > I want to share a portion of memory between the user
> > mode application & the kernel mode driver.The application
> > allocates the memory buffer and then issues an IOCTL to the
> > driver to provide the buffer pointer to it.The driver
> > implements METHOD_DIRECT for sharing memory.The driver then
> > returns a STATUS_PENDING code to the application.The driver
> > then fills the buffer with some data at a later stage.If the
> > application is to access the data then which of the following
> > methods should I implement ?
> >
> > 1.The driver generates a notification event to the
> > application to read the data.I do not want to complete the
> > IOCTL request with STATUS_SUCCESS because I want to re-use
> > the same buffer again.Can the application access the buffer
> > in this case?Does the buffer remain locked by the IO manager
> > for the period the request is not completed with STATUS_SUCCESS?
> >
> > 2.Complete the IOCTL request with STATUS_SUCCESS & have
> > another request from the application to gain another pointer from it.
> >
> > Any help on this would be greatly appreciated.
> >
> > Regards,
> > Sachin Anvekar
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@hollistech.com To unsubscribe send a blank email to
> > %%email.unsub%%
> >
> >
>
>
>
>

If you use this approach, you will have to implement a cancel routine
for the IOCTL so that if the user-mode process exits, you will be able
to cleanup properly (complete the IRP - unlocking the pages, & drop the
reference on the event object).
Ravi

This posting is provided “AS IS” with no warranties, and confers no
rights.

-----Original Message-----
From: Mark Roddy [mailto:xxxxx@hollistech.com]
Sent: Monday, August 05, 2002 4:57 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Sharing memory query

Use the event method. When, and not until, you complete the IOCTL the
operating system will unlock the buffer. Note that ‘locked’ does not
mean you can’t access the buffer, (from either user mode or kernel
mode,) it means that the pages of virtual memory associated with the
buffer are not going to page-out until the buffer is unlocked.

You can include the event in the ‘input buffer’ portion of the IOCTL as
a handle value, and use the ‘output buffer’ portion of the IOCTL as the
shared memory buffer. Use the correct value for METHOD_X_DIRECT to keep
everyone happy. You will have to convert the event handle to a waitable
object, but there are documented apis for doing this.

=====================
Mark Roddy
Windows XP/2000/NT Consultant, Microsoft MVP
Hollis Technology Solutions 603-321-1032
www.hollistech.com
xxxxx@hollistech.com
For Windows Device Driver Training: see www.azius.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Sachin
Sent: Monday, August 05, 2002 1:37 AM
To: NT Developers Interest List
Subject: [ntdev] Sharing memory query

Hello All
I want to share a portion of memory between the user
mode application & the kernel mode driver.The application
allocates the memory buffer and then issues an IOCTL to the
driver to provide the buffer pointer to it.The driver
implements METHOD_DIRECT for sharing memory.The driver then
returns a STATUS_PENDING code to the application.The driver
then fills the buffer with some data at a later stage.If the
application is to access the data then which of the following
methods should I implement ?

1.The driver generates a notification event to the
application to read the data.I do not want to complete the
IOCTL request with STATUS_SUCCESS because I want to re-use
the same buffer again.Can the application access the buffer
in this case?Does the buffer remain locked by the IO manager
for the period the request is not completed with STATUS_SUCCESS?

2.Complete the IOCTL request with STATUS_SUCCESS & have
another request from the application to gain another pointer from it.

Any help on this would be greatly appreciated.

Regards,
Sachin Anvekar


You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
%%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to %%email.unsub%%