memory mapping in display driver

Can I map the system memory allocated in display driver to the virtual
space of the user mode process? i.e. mapping the meomry block in upper
2GB space to the lower 2GB space. I saw that miniport driver can do
memory mapping. But it could only deal with the physical memory.

Thanks,

Lei

Yes, you can do this but not in the display driver,
rather, send an IOCTL along with the buffer to the
miniport driver, let the miniport do the mapping. You
will have to call IoXxx/MmXxx routines since video
port doesn’t expose such ability to miniports.

Our of curiosity, what graphics HW are you working on?

HTH,
Calvin

Calvin Guan Windows DDK MVP
Staff SW Engineer, NetXtreme MINIPORT
Enterprise Network Controller Engineering
Broadcom Corporation www.broadcom.com

— Lei Zhang wrote:

> Can I map the system memory allocated in display
> driver to the virtual
> space of the user mode process? i.e. mapping the
> meomry block in upper
> 2GB space to the lower 2GB space. I saw that
> miniport driver can do
> memory mapping. But it could only deal with the
> physical memory.
>
> Thanks,
>
> Lei
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown
> lmsubst tag argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Thanks. I am working on a mirror driver. Could you tell me how to call
IoXxx/MmXxx routines? I don’t know how to do it. I think the miniport
driver cannot include ntddk.h.

Lei
On 6/1/05, Calvin Guan wrote:
> Yes, you can do this but not in the display driver,
> rather, send an IOCTL along with the buffer to the
> miniport driver, let the miniport do the mapping. You
> will have to call IoXxx/MmXxx routines since video
> port doesn’t expose such ability to miniports.
>
> Our of curiosity, what graphics HW are you working on?
>
>
> HTH,
> Calvin
> –
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
>
> — Lei Zhang wrote:
>
> > Can I map the system memory allocated in display
> > driver to the virtual
> > space of the user mode process? i.e. mapping the
> > meomry block in upper
> > 2GB space to the lower 2GB space. I saw that
> > miniport driver can do
> > memory mapping. But it could only deal with the
> > physical memory.
> >
> > Thanks,
> >
> > Lei
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown
> > lmsubst tag argument: ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

You isolate all functions referencing kernel routines into a file and
include ntddk.h in that file.
The pseudo code may look like:
PVOID
MapBufferToUserMode(buffer)
{
PVOID address = NULL;
// allocate mdl for the buffer
mdl = IoAllocateMdl();
if ( NULL==mdl ) return NULL;
if (buffer is from paged pool) {
try {

MmProbeAndLockPages(mdl,UserMode,IoModifyAccess);

}except (EXCEPTION_EXECUTE_HANDLER){
// bail out
IoFreeMdl(mdl);
return NULL;
}
} else {
// buffer is from NpagedPool
MmBuildMdlForNonPagedPool(mdl);
}

try {

address = MmMapLockedPagesSpecifyCache(mdl,UserMode,…);

} except (EXCEPTION_EXECUTE_HANDLER) {
// bail…
if (Buffer from paged pool) {
MmUnmapLockedPages(buffer,mdl);
}
IoFreeMdl(mdl);
return NULL;
}
return address;
}

The tricky part is you must unmap the memory upon the target process
termination, otherwise system bugchecks when it frees the process address
space. Unfortunately, you can’t handle IRP_MJ_CLEANUP in a video miniport
driver. There’s at least one reliable way to catch process termination event
from the display driver side (GDI) but I don’t remember how to do it. Too
bad I must have left my work log somewhere in Toronto-:(.

Bottom line is, don’t use mapping until you figure out how to unmap. You’ve
been warned-:slight_smile:

HTH, at least partially


Calvin Guan Windows DDK MVP
Staff SW Engineer, NetXtreme MINIPORT
Enterprise Network Controller Engineering
Broadcom Corporation www.broadcom.com

----- Original Message -----
From: “Lei Zhang”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, June 01, 2005 6:39 PM
Subject: Re: [ntdev] memory mapping in display driver

Thanks. I am working on a mirror driver. Could you tell me how to call
IoXxx/MmXxx routines? I don’t know how to do it. I think the miniport
driver cannot include ntddk.h.

Lei
On 6/1/05, Calvin Guan wrote:
> Yes, you can do this but not in the display driver,
> rather, send an IOCTL along with the buffer to the
> miniport driver, let the miniport do the mapping. You
> will have to call IoXxx/MmXxx routines since video
> port doesn’t expose such ability to miniports.
>
> Our of curiosity, what graphics HW are you working on?
>
>
> HTH,
> Calvin
> –
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
>
> — Lei Zhang wrote:
>
> > Can I map the system memory allocated in display
> > driver to the virtual
> > space of the user mode process? i.e. mapping the
> > meomry block in upper
> > 2GB space to the lower 2GB space. I saw that
> > miniport driver can do
> > memory mapping. But it could only deal with the
> > physical memory.
> >
> > Thanks,
> >
> > Lei
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown
> > lmsubst tag argument: ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

You information is very helpful.
Is there any docments that tells how to catch that event? :slight_smile:

Lei

On 6/1/05, Calvin Guan wrote:
> You isolate all functions referencing kernel routines into a file and
> include ntddk.h in that file.
> The pseudo code may look like:
> PVOID
> MapBufferToUserMode(buffer)
> {
> PVOID address = NULL;
> // allocate mdl for the buffer
> mdl = IoAllocateMdl();
> if ( NULL==mdl ) return NULL;
> if (buffer is from paged pool) {
> try {
>
> MmProbeAndLockPages(mdl,UserMode,IoModifyAccess);
>
> }except (EXCEPTION_EXECUTE_HANDLER){
> // bail out
> IoFreeMdl(mdl);
> return NULL;
> }
> } else {
> // buffer is from NpagedPool
> MmBuildMdlForNonPagedPool(mdl);
> }
>
> try {
>
> address = MmMapLockedPagesSpecifyCache(mdl,UserMode,…);
>
> } except (EXCEPTION_EXECUTE_HANDLER) {
> // bail…
> if (Buffer from paged pool) {
> MmUnmapLockedPages(buffer,mdl);
> }
> IoFreeMdl(mdl);
> return NULL;
> }
> return address;
> }
>
> The tricky part is you must unmap the memory upon the target process
> termination, otherwise system bugchecks when it frees the process address
> space. Unfortunately, you can’t handle IRP_MJ_CLEANUP in a video miniport
> driver. There’s at least one reliable way to catch process termination event
> from the display driver side (GDI) but I don’t remember how to do it. Too
> bad I must have left my work log somewhere in Toronto-:(.
>
> Bottom line is, don’t use mapping until you figure out how to unmap. You’ve
> been warned-:slight_smile:
>
> HTH, at least partially
>
> –
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
>
>
> ----- Original Message -----
> From: “Lei Zhang”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, June 01, 2005 6:39 PM
> Subject: Re: [ntdev] memory mapping in display driver
>
>
> Thanks. I am working on a mirror driver. Could you tell me how to call
> IoXxx/MmXxx routines? I don’t know how to do it. I think the miniport
> driver cannot include ntddk.h.
>
> Lei
> On 6/1/05, Calvin Guan wrote:
> > Yes, you can do this but not in the display driver,
> > rather, send an IOCTL along with the buffer to the
> > miniport driver, let the miniport do the mapping. You
> > will have to call IoXxx/MmXxx routines since video
> > port doesn’t expose such ability to miniports.
> >
> > Our of curiosity, what graphics HW are you working on?
> >
> >
> > HTH,
> > Calvin
> > –
> > Calvin Guan Windows DDK MVP
> > Staff SW Engineer, NetXtreme MINIPORT
> > Enterprise Network Controller Engineering
> > Broadcom Corporation www.broadcom.com
> >
> >
> >
> > — Lei Zhang wrote:
> >
> > > Can I map the system memory allocated in display
> > > driver to the virtual
> > > space of the user mode process? i.e. mapping the
> > > meomry block in upper
> > > 2GB space to the lower 2GB space. I saw that
> > > miniport driver can do
> > > memory mapping. But it could only deal with the
> > > physical memory.
> > >
> > > Thanks,
> > >
> > > Lei
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown
> > > lmsubst tag argument: ‘’
> > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@gmail.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Can VideoPortMapMemory help?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Calvin Guan”
To: “Windows System Software Devs Interest List”
Sent: Thursday, June 02, 2005 1:59 AM
Subject: Re: [ntdev] memory mapping in display driver

> Yes, you can do this but not in the display driver,
> rather, send an IOCTL along with the buffer to the
> miniport driver, let the miniport do the mapping. You
> will have to call IoXxx/MmXxx routines since video
> port doesn’t expose such ability to miniports.
>
> Our of curiosity, what graphics HW are you working on?
>
>
> HTH,
> Calvin
> –
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
>
> — Lei Zhang wrote:
>
> > Can I map the system memory allocated in display
> > driver to the virtual
> > space of the user mode process? i.e. mapping the
> > meomry block in upper
> > 2GB space to the lower 2GB space. I saw that
> > miniport driver can do
> > memory mapping. But it could only deal with the
> > physical memory.
> >
> > Thanks,
> >
> > Lei
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown
> > lmsubst tag argument: ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

This should be easy to do with an Mmxxx function. We did that on
our Silverhammer and Savage chip drivers (not on the miniport)
and it did work fine. It’s a great debugging tool, because it
allows you to render “by hand” writing to real video memory, for
example, if you want to compare what an OpenGL primitive
rendered against what the HCT test expects it to render. We also
used it to have a floating frames/second counter on our GL
window, which we could turn on or off from a keystroke. However,
some chips have involuted memory layouts because of
optimization-conscious design, and you must be aware of that
layout before you can use direct access to video memory in a
meaningful way. We put a couple of such back-door calls in our
display driver so that our OpenGL ICD could go in and out of the
video memory at will.

Alberto.

----- Original Message -----
From: “Calvin Guan”
To: “Windows System Software Devs Interest List”

Sent: Wednesday, June 01, 2005 5:59 PM
Subject: Re: [ntdev] memory mapping in display driver

> Yes, you can do this but not in the display driver,
> rather, send an IOCTL along with the buffer to the
> miniport driver, let the miniport do the mapping. You
> will have to call IoXxx/MmXxx routines since video
> port doesn’t expose such ability to miniports.
>
> Our of curiosity, what graphics HW are you working on?
>
>
> HTH,
> Calvin
> –
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
>
> — Lei Zhang wrote:
>
>> Can I map the system memory allocated in display
>> driver to the virtual
>> space of the user mode process? i.e. mapping the
>> meomry block in upper
>> 2GB space to the lower 2GB space. I saw that
>> miniport driver can do
>> memory mapping. But it could only deal with the
>> physical memory.
>>
>> Thanks,
>>
>> Lei
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: unknown
>> lmsubst tag argument: ‘’
>> To unsubscribe send a blank email to
>> xxxxx@lists.osr.com
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection
> around
> http://mail.yahoo.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com

VideoPortMapMemory can be used to make physical video
memory accessible to user mode, but for pool memory,
he needs IoXxx/MmXxx.

Calvin Guan Windows DDK MVP
Staff SW Engineer, NetXtreme MINIPORT
Enterprise Network Controller Engineering
Broadcom Corporation www.broadcom.com

— “Maxim S. Shatskih”
wrote:

> Can VideoPortMapMemory help?
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Calvin Guan”
> To: “Windows System Software Devs Interest List”
>
> Sent: Thursday, June 02, 2005 1:59 AM
> Subject: Re: [ntdev] memory mapping in display
> driver
>
>
> > Yes, you can do this but not in the display
> driver,
> > rather, send an IOCTL along with the buffer to the
> > miniport driver, let the miniport do the mapping.
> You
> > will have to call IoXxx/MmXxx routines since video
> > port doesn’t expose such ability to miniports.
> >
> > Our of curiosity, what graphics HW are you working
> on?
> >
> >
> > HTH,
> > Calvin
> > –
> > Calvin Guan Windows DDK MVP
> > Staff SW Engineer, NetXtreme MINIPORT
> > Enterprise Network Controller Engineering
> > Broadcom Corporation www.broadcom.com
> >
> >
> >
> > — Lei Zhang wrote:
> >
> > > Can I map the system memory allocated in display
> > > driver to the virtual
> > > space of the user mode process? i.e. mapping the
> > > meomry block in upper
> > > 2GB space to the lower 2GB space. I saw that
> > > miniport driver can do
> > > memory mapping. But it could only deal with the
> > > physical memory.
> > >
> > > Thanks,
> > >
> > > Lei
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
> unknown
> > > lmsubst tag argument: ‘’
> > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com
> > >
> >
> >
> >
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> xxxxx@storagecraft.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.ca
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

No, it’s not explicitly mentioned in the manual. It
has something to do with DirectDraw/Direct3D init and
exit.

If you have an ATI powered graphics card, set a bp at
MmUnmapLockedPages, launch and kill a ddraw and/or d3d
apps. You may find something, there will be a lot of
hits though. Well, I should had mentioned that only
works for specific type of apps. But usually, these
kind of apps (demanding a huge amount of memory for
rendering texture) need such mapping.

Well, in the worst case,
PsSetCreateProcessNotifyRoutine is aways there.

Calvin Guan Windows DDK MVP
Staff SW Engineer, NetXtreme MINIPORT
Enterprise Network Controller Engineering
Broadcom Corporation www.broadcom.com

— Lei Zhang wrote:

> You information is very helpful.
> Is there any docments that tells how to catch that
> event? :slight_smile:
>
> Lei
>
> On 6/1/05, Calvin Guan
> wrote:
> > You isolate all functions referencing kernel
> routines into a file and
> > include ntddk.h in that file.
> > The pseudo code may look like:
> > PVOID
> > MapBufferToUserMode(buffer)
> > {
> > PVOID address = NULL;
> > // allocate mdl for the buffer
> > mdl = IoAllocateMdl();
> > if ( NULL==mdl ) return NULL;
> > if (buffer is from paged pool) {
> > try {
> >
> >
> MmProbeAndLockPages(mdl,UserMode,IoModifyAccess);
> >
> > }except (EXCEPTION_EXECUTE_HANDLER){
> > // bail out
> > IoFreeMdl(mdl);
> > return NULL;
> > }
> > } else {
> > // buffer is from NpagedPool
> > MmBuildMdlForNonPagedPool(mdl);
> > }
> >
> > try {
> >
> > address =
> MmMapLockedPagesSpecifyCache(mdl,UserMode,…);
> >
> > } except (EXCEPTION_EXECUTE_HANDLER) {
> > // bail…
> > if (Buffer from paged pool) {
> > MmUnmapLockedPages(buffer,mdl);
> > }
> > IoFreeMdl(mdl);
> > return NULL;
> > }
> > return address;
> > }
> >
> > The tricky part is you must unmap the memory upon
> the target process
> > termination, otherwise system bugchecks when it
> frees the process address
> > space. Unfortunately, you can’t handle
> IRP_MJ_CLEANUP in a video miniport
> > driver. There’s at least one reliable way to catch
> process termination event
> > from the display driver side (GDI) but I don’t
> remember how to do it. Too
> > bad I must have left my work log somewhere in
> Toronto-:(.
> >
> > Bottom line is, don’t use mapping until you figure
> out how to unmap. You’ve
> > been warned-:slight_smile:
> >
> > HTH, at least partially
> >
> > –
> > Calvin Guan Windows DDK MVP
> > Staff SW Engineer, NetXtreme MINIPORT
> > Enterprise Network Controller Engineering
> > Broadcom Corporation www.broadcom.com
> >
> >
> >
> >
> > ----- Original Message -----
> > From: “Lei Zhang”
> > To: “Windows System Software Devs Interest List”
>
> > Sent: Wednesday, June 01, 2005 6:39 PM
> > Subject: Re: [ntdev] memory mapping in display
> driver
> >
> >
> > Thanks. I am working on a mirror driver. Could you
> tell me how to call
> > IoXxx/MmXxx routines? I don’t know how to do it. I
> think the miniport
> > driver cannot include ntddk.h.
> >
> > Lei
> > On 6/1/05, Calvin Guan
> wrote:
> > > Yes, you can do this but not in the display
> driver,
> > > rather, send an IOCTL along with the buffer to
> the
> > > miniport driver, let the miniport do the
> mapping. You
> > > will have to call IoXxx/MmXxx routines since
> video
> > > port doesn’t expose such ability to miniports.
> > >
> > > Our of curiosity, what graphics HW are you
> working on?
> > >
> > >
> > > HTH,
> > > Calvin
> > > –
> > > Calvin Guan Windows DDK MVP
> > > Staff SW Engineer, NetXtreme MINIPORT
> > > Enterprise Network Controller Engineering
> > > Broadcom Corporation www.broadcom.com
> > >
> > >
> > >
> > > — Lei Zhang wrote:
> > >
> > > > Can I map the system memory allocated in
> display
> > > > driver to the virtual
> > > > space of the user mode process? i.e. mapping
> the
> > > > meomry block in upper
> > > > 2GB space to the lower 2GB space. I saw that
> > > > miniport driver can do
> > > > memory mapping. But it could only deal with
> the
> > > > physical memory.
> > > >
> > > > Thanks,
> > > >
> > > > Lei
> > > >
> > > > —
> > > > Questions? First check the Kernel Driver FAQ
> at
> > > > http://www.osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as:
> unknown
> > > > lmsubst tag argument: ‘’
> > > > To unsubscribe send a blank email to
> > > > xxxxx@lists.osr.com
> > > >
> > >
> > >
> > >
>
> > > Do You Yahoo!?
> > > Tired of spam? Yahoo! Mail has the best spam
> protection around
> > > http://mail.yahoo.com
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
> xxxxx@gmail.com
> > > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> > >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown
> lmsubst tag argument: ‘’
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> xxxxx@gmail.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown
> lmsubst tag argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

I think the DirectX staff doesn’t work for me, because mirror driver
doesn’t support directX. I will try PsSetCreateProcessNotifyRoutine().
Thanks.

But why you said it is the worst case? Is it very slow?

Lei

On 6/2/05, Calvin Guan wrote:
> No, it’s not explicitly mentioned in the manual. It
> has something to do with DirectDraw/Direct3D init and
> exit.
>
> If you have an ATI powered graphics card, set a bp at
> MmUnmapLockedPages, launch and kill a ddraw and/or d3d
> apps. You may find something, there will be a lot of
> hits though. Well, I should had mentioned that only
> works for specific type of apps. But usually, these
> kind of apps (demanding a huge amount of memory for
> rendering texture) need such mapping.
>
> Well, in the worst case,
> PsSetCreateProcessNotifyRoutine is aways there.
>
> Calvin Guan Windows DDK MVP
> Staff SW Engineer, NetXtreme MINIPORT
> Enterprise Network Controller Engineering
> Broadcom Corporation www.broadcom.com
>
>
>
> — Lei Zhang wrote:
>
> > You information is very helpful.
> > Is there any docments that tells how to catch that
> > event? :slight_smile:
> >
> > Lei
> >
> > On 6/1/05, Calvin Guan
> > wrote:
> > > You isolate all functions referencing kernel
> > routines into a file and
> > > include ntddk.h in that file.
> > > The pseudo code may look like:
> > > PVOID
> > > MapBufferToUserMode(buffer)
> > > {
> > > PVOID address = NULL;
> > > // allocate mdl for the buffer
> > > mdl = IoAllocateMdl();
> > > if ( NULL==mdl ) return NULL;
> > > if (buffer is from paged pool) {
> > > try {
> > >
> > >
> > MmProbeAndLockPages(mdl,UserMode,IoModifyAccess);
> > >
> > > }except (EXCEPTION_EXECUTE_HANDLER){
> > > // bail out
> > > IoFreeMdl(mdl);
> > > return NULL;
> > > }
> > > } else {
> > > // buffer is from NpagedPool
> > > MmBuildMdlForNonPagedPool(mdl);
> > > }
> > >
> > > try {
> > >
> > > address =
> > MmMapLockedPagesSpecifyCache(mdl,UserMode,…);
> > >
> > > } except (EXCEPTION_EXECUTE_HANDLER) {
> > > // bail…
> > > if (Buffer from paged pool) {
> > > MmUnmapLockedPages(buffer,mdl);
> > > }
> > > IoFreeMdl(mdl);
> > > return NULL;
> > > }
> > > return address;
> > > }
> > >
> > > The tricky part is you must unmap the memory upon
> > the target process
> > > termination, otherwise system bugchecks when it
> > frees the process address
> > > space. Unfortunately, you can’t handle
> > IRP_MJ_CLEANUP in a video miniport
> > > driver. There’s at least one reliable way to catch
> > process termination event
> > > from the display driver side (GDI) but I don’t
> > remember how to do it. Too
> > > bad I must have left my work log somewhere in
> > Toronto-:(.
> > >
> > > Bottom line is, don’t use mapping until you figure
> > out how to unmap. You’ve
> > > been warned-:slight_smile:
> > >
> > > HTH, at least partially
> > >
> > > –
> > > Calvin Guan Windows DDK MVP
> > > Staff SW Engineer, NetXtreme MINIPORT
> > > Enterprise Network Controller Engineering
> > > Broadcom Corporation www.broadcom.com
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: “Lei Zhang”
> > > To: “Windows System Software Devs Interest List”
> >
> > > Sent: Wednesday, June 01, 2005 6:39 PM
> > > Subject: Re: [ntdev] memory mapping in display
> > driver
> > >
> > >
> > > Thanks. I am working on a mirror driver. Could you
> > tell me how to call
> > > IoXxx/MmXxx routines? I don’t know how to do it. I
> > think the miniport
> > > driver cannot include ntddk.h.
> > >
> > > Lei
> > > On 6/1/05, Calvin Guan
> > wrote:
> > > > Yes, you can do this but not in the display
> > driver,
> > > > rather, send an IOCTL along with the buffer to
> > the
> > > > miniport driver, let the miniport do the
> > mapping. You
> > > > will have to call IoXxx/MmXxx routines since
> > video
> > > > port doesn’t expose such ability to miniports.
> > > >
> > > > Our of curiosity, what graphics HW are you
> > working on?
> > > >
> > > >
> > > > HTH,
> > > > Calvin
> > > > –
> > > > Calvin Guan Windows DDK MVP
> > > > Staff SW Engineer, NetXtreme MINIPORT
> > > > Enterprise Network Controller Engineering
> > > > Broadcom Corporation www.broadcom.com
> > > >
> > > >
> > > >
> > > > — Lei Zhang wrote:
> > > >
> > > > > Can I map the system memory allocated in
> > display
> > > > > driver to the virtual
> > > > > space of the user mode process? i.e. mapping
> > the
> > > > > meomry block in upper
> > > > > 2GB space to the lower 2GB space. I saw that
> > > > > miniport driver can do
> > > > > memory mapping. But it could only deal with
> > the
> > > > > physical memory.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Lei
> > > > >
> > > > > —
> > > > > Questions? First check the Kernel Driver FAQ
> > at
> > > > > http://www.osronline.com/article.cfm?id=256
> > > > >
> > > > > You are currently subscribed to ntdev as:
> > unknown
> > > > > lmsubst tag argument: ‘’
> > > > > To unsubscribe send a blank email to
> > > > > xxxxx@lists.osr.com
> > > > >
> > > >
> > > >
> > > >
> >
> > > > Do You Yahoo!?
> > > > Tired of spam? Yahoo! Mail has the best spam
> > protection around
> > > > http://mail.yahoo.com
> > > >
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at
> > > > http://www.osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as:
> > xxxxx@gmail.com
> > > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: unknown
> > lmsubst tag argument: ‘’
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
> > xxxxx@gmail.com
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown
> > lmsubst tag argument: ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
>

> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

As a general rule for miniport driver, you don’t mess
with that much of kernel routines unless there’s
absolutely no other way around. Miniport is supposed
to use only the facilities the wrapper provides. If
you intend to ship your product with Windows, you may
need a WHQL wavier to get your driver signed. My
previous employer has a very close relationship with
MSFT, so getting a wavier is generally not a big deal.


Calvin Guan Windows DDK MVP
Staff SW Engineer, NetXtreme MINIPORT
Enterprise Network Controller Engineering
Broadcom Corporation www.broadcom.com

— Lei Zhang wrote:

> I think the DirectX staff doesn’t work for me,
> because mirror driver
> doesn’t support directX. I will try
> PsSetCreateProcessNotifyRoutine().
> Thanks.
>
> But why you said it is the worst case? Is it very
> slow?
>
> Lei
>
> On 6/2/05, Calvin Guan wrote:
> > No, it’s not explicitly mentioned in the manual.
> It
> > has something to do with DirectDraw/Direct3D init
> and
> > exit.
> >
> > If you have an ATI powered graphics card, set a
> bp at
> > MmUnmapLockedPages, launch and kill a ddraw and/or
> d3d
> > apps. You may find something, there will be a lot
> of
> > hits though. Well, I should had mentioned that
> only
> > works for specific type of apps. But usually,
> these
> > kind of apps (demanding a huge amount of memory
> for
> > rendering texture) need such mapping.
> >
> > Well, in the worst case,
> > PsSetCreateProcessNotifyRoutine is aways there.
> >
> > Calvin Guan Windows DDK MVP
> > Staff SW Engineer, NetXtreme MINIPORT
> > Enterprise Network Controller Engineering
> > Broadcom Corporation www.broadcom.com
> >
> >
> >
> > — Lei Zhang wrote:
> >
> > > You information is very helpful.
> > > Is there any docments that tells how to catch
> that
> > > event? :slight_smile:
> > >
> > > Lei
> > >
> > > On 6/1/05, Calvin Guan
> > > wrote:
> > > > You isolate all functions referencing kernel
> > > routines into a file and
> > > > include ntddk.h in that file.
> > > > The pseudo code may look like:
> > > > PVOID
> > > > MapBufferToUserMode(buffer)
> > > > {
> > > > PVOID address = NULL;
> > > > // allocate mdl for the buffer
> > > > mdl = IoAllocateMdl();
> > > > if ( NULL==mdl ) return NULL;
> > > > if (buffer is from paged pool) {
> > > > try {
> > > >
> > > >
> > >
> MmProbeAndLockPages(mdl,UserMode,IoModifyAccess);
> > > >
> > > > }except (EXCEPTION_EXECUTE_HANDLER){
> > > > // bail out
> > > > IoFreeMdl(mdl);
> > > > return NULL;
> > > > }
> > > > } else {
> > > > // buffer is from NpagedPool
> > > > MmBuildMdlForNonPagedPool(mdl);
> > > > }
> > > >
> > > > try {
> > > >
> > > > address =
> > > MmMapLockedPagesSpecifyCache(mdl,UserMode,…);
> > > >
> > > > } except (EXCEPTION_EXECUTE_HANDLER) {
> > > > // bail…
> > > > if (Buffer from paged pool) {
> > > > MmUnmapLockedPages(buffer,mdl);
> > > > }
> > > > IoFreeMdl(mdl);
> > > > return NULL;
> > > > }
> > > > return address;
> > > > }
> > > >
> > > > The tricky part is you must unmap the memory
> upon
> > > the target process
> > > > termination, otherwise system bugchecks when
> it
> > > frees the process address
> > > > space. Unfortunately, you can’t handle
> > > IRP_MJ_CLEANUP in a video miniport
> > > > driver. There’s at least one reliable way to
> catch
> > > process termination event
> > > > from the display driver side (GDI) but I don’t
> > > remember how to do it. Too
> > > > bad I must have left my work log somewhere in
> > > Toronto-:(.
> > > >
> > > > Bottom line is, don’t use mapping until you
> figure
> > > out how to unmap. You’ve
> > > > been warned-:slight_smile:
> > > >
> > > > HTH, at least partially
> > > >
> > > > –
> > > > Calvin Guan Windows DDK MVP
> > > > Staff SW Engineer, NetXtreme MINIPORT
> > > > Enterprise Network Controller Engineering
> > > > Broadcom Corporation www.broadcom.com
> > > >
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: “Lei Zhang”
> > > > To: “Windows System Software Devs Interest
> List”
> > >
> > > > Sent: Wednesday, June 01, 2005 6:39 PM
> > > > Subject: Re: [ntdev] memory mapping in display
> > > driver
> > > >
> > > >
> > > > Thanks. I am working on a mirror driver. Could
> you
> > > tell me how to call
> > > > IoXxx/MmXxx routines? I don’t know how to do
> it. I
> > > think the miniport
> > > > driver cannot include ntddk.h.
> > > >
> > > > Lei
> > > > On 6/1/05, Calvin Guan
> > > wrote:
> > > > > Yes, you can do this but not in the display
> > > driver,
> > > > > rather, send an IOCTL along with the buffer
> to
> > > the
> > > > > miniport driver, let the miniport do the
> > > mapping. You
> > > > > will have to call IoXxx/MmXxx routines since
> > > video
> > > > > port doesn’t expose such ability to
> miniports.
> > > > >
> > > > > Our of curiosity, what graphics HW are you
> > > working on?
> > > > >
> > > > >
> > > > > HTH,
> > > > > Calvin
> > > > > –
> > > > > Calvin Guan Windows DDK MVP
> > > > > Staff SW Engineer, NetXtreme MINIPORT
> > > > > Enterprise Network Controller Engineering
> > > > > Broadcom Corporation www.broadcom.com
> > > > >
> > > > >
> > > > >
> > > > > — Lei Zhang wrote:
> > > > >
> > > > > > Can I map the system memory allocated in
> > > display
> > > > > > driver to the virtual
> > > > > > space of the user mode process? i.e.
> mapping
> > > the
> > > > > > meomry block in upper
> > > > > > 2GB space to the lower 2GB space. I saw
> that
> > > > > > miniport driver can do
> > > > > > memory mapping. But it could only deal
> with
> > > the
> > > > > > physical memory.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Lei
> > > > > >
> > > > > > —
> > > > > > Questions? First check the Kernel Driver
> FAQ
> > > at
>
=== message truncated ===

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com