memory leakage

Hi all,

I want to add memory leaks detection code in a driver. my driver is written
such that for allocation failures it should cleanup properly and then unload
itself. I ws wondering whether I can write a kd extension tht can work in
conjunction to the driver to make this better. My doubt is when the driver
unloads, whould the kd extension also unload? then if wnt work for me.

AP

No, the kd extension is independant of the driver.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and then
> unload
> itself. I ws wondering whether I can write a kd extension tht can work in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for me.
>
> AP
>

i was planning it this way. may be when allocate memory save some info in a
linked list and when deleted delete the info node too. so theoritically if
my cleanups and frees are correct the list should be empty once clnup is
done.

the job of teh kdext shud be to chk the list contents after driver exits.
Now here is the problem. how do i get this done beasue when the driver
exists the list shud go too!

AP

On 5/28/07, Don Burn wrote:
>
> No, the kd extension is independant of the driver.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
> “A P” wrote in message news:xxxxx@ntdev…
> > Hi all,
> >
> >
> > I want to add memory leaks detection code in a driver. my driver is
> > written
> > such that for allocation failures it should cleanup properly and then
> > unload
> > itself. I ws wondering whether I can write a kd extension tht can work
> in
> > conjunction to the driver to make this better. My doubt is when the
> > driver
> > unloads, whould the kd extension also unload? then if wnt work for me.
> >
> > AP
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Why not incorporate the list in the driver itself? Kernel debugger
extensions are generally useful for static analysis of kernel components,
not for dynamic verification. By the way driver verifier does a fair job of
tracking your resource (including memory) allocations and slapping you in
the face when you attempt to unload without releasing all of them.

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Monday, May 28, 2007 10:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] memory leakage

i was planning it this way. may be when allocate memory save some info in a
linked list and when deleted delete the info node too. so theoritically if
my cleanups and frees are correct the list should be empty once clnup is
done.

the job of teh kdext shud be to chk the list contents after driver exits.
Now here is the problem. how do i get this done beasue when the driver
exists the list shud go too!

AP

On 5/28/07, Don Burn wrote:

No, the kd extension is independant of the driver.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and then
> unload
> itself. I ws wondering whether I can write a kd extension tht can work in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for me.
>
> AP
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Driver verifier already provides memory leak detection. If verifier is
running against your driver and your driver exits with memory still
allocated, verifier will blue screen the system. The reeulting data will
have all the allocations that were not freed.

Bill Wandel


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of A P
Sent: Monday, May 28, 2007 10:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] memory leakage

i was planning it this way. may be when allocate memory save some info in a
linked list and when deleted delete the info node too. so theoritically if
my cleanups and frees are correct the list should be empty once clnup is
done.

the job of teh kdext shud be to chk the list contents after driver exits.
Now here is the problem. how do i get this done beasue when the driver
exists the list shud go too!

AP

On 5/28/07, Don Burn wrote:

No, the kd extension is independant of the driver.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and then
> unload
> itself. I ws wondering whether I can write a kd extension tht can work in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for me.
>
> AP
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

so that will happen only at unload time.

Does DV show me all allocated stuff then???

On 5/28/07, Bill Wandel wrote:
>
> Driver verifier already provides memory leak detection. If verifier is
> running against your driver and your driver exits with memory still
> allocated, verifier will blue screen the system. The reeulting data will
> have all the allocations that were not freed.
>
> Bill Wandel
>
> ------------------------------
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *A P
> Sent: Monday, May 28, 2007 10:43 AM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] memory leakage
>
> i was planning it this way. may be when allocate memory save some info in
> a linked list and when deleted delete the info node too. so theoritically if
> my cleanups and frees are correct the list should be empty once clnup is
> done.
>
> the job of teh kdext shud be to chk the list contents after driver exits.
> Now here is the problem. how do i get this done beasue when the driver
> exists the list shud go too!
>
>
> AP
>
> On 5/28/07, Don Burn wrote:
> >
> > No, the kd extension is independant of the driver.
> >
> >
> > –
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > Website: http://www.windrvr.com
> > Blog: http://msmvps.com/blogs/WinDrvr
> > Remove StopSpam to reply
> >
> > “A P” wrote in message news:xxxxx@ntdev…
> > > Hi all,
> > >
> > >
> > > I want to add memory leaks detection code in a driver. my driver is
> > > written
> > > such that for allocation failures it should cleanup properly and then
> > > unload
> > > itself. I ws wondering whether I can write a kd extension tht can work
> > in
> > > conjunction to the driver to make this better. My doubt is when the
> > > driver
> > > unloads, whould the kd extension also unload? then if wnt work for me.
> >
> > >
> > > AP
> > >
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
>
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
> Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

It is already here in the kernel, see !poolused command of WinDbg, POOLMON
tool and Driver Verifier.


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

“A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is written
> such that for allocation failures it should cleanup properly and then unload
> itself. I ws wondering whether I can write a kd extension tht can work in
> conjunction to the driver to make this better. My doubt is when the driver
> unloads, whould the kd extension also unload? then if wnt work for me.
>
> AP
>

DV will show all the allocations that were not freed.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of A P
Sent: Monday, May 28, 2007 12:16 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] memory leakage

so that will happen only at unload time.

Does DV show me all allocated stuff then???

On 5/28/07, Bill Wandel < mailto:xxxxx
xxxxx@bwandel.com> wrote:

Driver verifier already provides memory leak detection. If verifier is
running against your driver and your driver exits with memory still
allocated, verifier will blue screen the system. The reeulting data will
have all the allocations that were not freed.

Bill Wandel

_____

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of A P
Sent: Monday, May 28, 2007 10:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] memory leakage

i was planning it this way. may be when allocate memory save some info in a
linked list and when deleted delete the info node too. so theoritically if
my cleanups and frees are correct the list should be empty once clnup is
done.

the job of teh kdext shud be to chk the list contents after driver exits.
Now here is the problem. how do i get this done beasue when the driver
exists the list shud go too!

AP

On 5/28/07, Don Burn wrote:

No, the kd extension is independant of the driver.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and then
> unload
> itself. I ws wondering whether I can write a kd extension tht can work in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for me.
>
> AP
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
http:

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
http:

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer</http:></http:></mailto:xxxxx>

Actually, with !verifier in the debugger it will show all the allocations
and the address the allocation occurred at.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“Bill Wandel” wrote in message news:xxxxx@ntdev…
> DV will show all the allocations that were not freed.
>
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]
> On Behalf Of A P
> Sent: Monday, May 28, 2007 12:16 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] memory leakage
>
>
> so that will happen only at unload time.
>
> Does DV show me all allocated stuff then???
>
>
>
>
> On 5/28/07, Bill Wandel < mailto:xxxxx
> xxxxx@bwandel.com> wrote:
>
> Driver verifier already provides memory leak detection. If verifier is
> running against your driver and your driver exits with memory still
> allocated, verifier will blue screen the system. The reeulting data will
> have all the allocations that were not freed.
>
> Bill Wandel
>
>

>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]
> On Behalf Of A P
> Sent: Monday, May 28, 2007 10:43 AM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] memory leakage
>
>
>
> i was planning it this way. may be when allocate memory save some info in
> a
> linked list and when deleted delete the info node too. so theoritically
> if
> my cleanups and frees are correct the list should be empty once clnup is
> done.
>
> the job of teh kdext shud be to chk the list contents after driver exits.
> Now here is the problem. how do i get this done beasue when the driver
> exists the list shud go too!
>
>
> AP
>
>
> On 5/28/07, Don Burn wrote:
>
> No, the kd extension is independant of the driver.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
> “A P” wrote in message news:xxxxx@ntdev…
>> Hi all,
>>
>>
>> I want to add memory leaks detection code in a driver. my driver is
>> written
>> such that for allocation failures it should cleanup properly and then
>> unload
>> itself. I ws wondering whether I can write a kd extension tht can work
>> in
>> conjunction to the driver to make this better. My doubt is when the
>> driver
>> unloads, whould the kd extension also unload? then if wnt work for me.
>>
>> AP
>>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> http:
>
>
>
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
> List
> Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> http:
>
>
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
> List
> Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
></http:></http:></mailto:xxxxx>

Your driver must be leak free. Poolmon is a great tool when it comes to
detection of memory leaks. It is much better to use it in your lab before
your customers use it; I know this as a fact. Verifier is also your good
friend. Prefast might be useful. SDV might be useful. The diligent inspector
is also your friend, chances the diligent inspector is your best friend,
welcome the diligent inspector.

“A P” wrote in message news:xxxxx@ntdev…
Hi all,

I want to add memory leaks detection code in a driver. my driver is written
such that for allocation failures it should cleanup properly and then unload
itself. I ws wondering whether I can write a kd extension tht can work in
conjunction to the driver to make this better. My doubt is when the driver
unloads, whould the kd extension also unload? then if wnt work for me.

AP

In this specific case (pool usage), and most cases overall, I would
totally agree with DV, et. c. In general, I have found that there are
times where your basic idea - kd extension integrated with a driver -
does have its place, or at least works well. Generally, I have used
this to work around problems - for example, ReadMsr() failing with
certain valid MSR’s.

If I understand you correctly, the answer to your basic question is
that, no, the kd ext would not unload because the driver did.

mm

>> xxxxx@neverfailgroup.com 2007-05-28 19:10 >>>
Your driver must be leak free. Poolmon is a great tool when it comes to

detection of memory leaks. It is much better to use it in your lab
before
your customers use it; I know this as a fact. Verifier is also your
good
friend. Prefast might be useful. SDV might be useful. The diligent
inspector
is also your friend, chances the diligent inspector is your best
friend,
welcome the diligent inspector.

“A P” wrote in message news:xxxxx@ntdev…
Hi all,

I want to add memory leaks detection code in a driver. my driver is
written
such that for allocation failures it should cleanup properly and then
unload
itself. I ws wondering whether I can write a kd extension tht can work
in
conjunction to the driver to make this better. My doubt is when the
driver
unloads, whould the kd extension also unload? then if wnt work for me.

AP


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

hi all

thanks a ton for all the valuable advice.

the reason why i wanted the kd angle was i have better control. and i dont
have to wait till a third party test ends.

i have haev some thing like a registry key telling me that i need to fail
the xth memory alloc call and see whether my driver handles cleanup properly
or not.

AP

On 5/29/07, Martin O’Brien wrote:
>
> In this specific case (pool usage), and most cases overall, I would
> totally agree with DV, et. c. In general, I have found that there are
> times where your basic idea - kd extension integrated with a driver -
> does have its place, or at least works well. Generally, I have used
> this to work around problems - for example, ReadMsr() failing with
> certain valid MSR’s.
>
> If I understand you correctly, the answer to your basic question is
> that, no, the kd ext would not unload because the driver did.
>
> mm
>
> >>> xxxxx@neverfailgroup.com 2007-05-28 19:10 >>>
> Your driver must be leak free. Poolmon is a great tool when it comes to
>
> detection of memory leaks. It is much better to use it in your lab
> before
> your customers use it; I know this as a fact. Verifier is also your
> good
> friend. Prefast might be useful. SDV might be useful. The diligent
> inspector
> is also your friend, chances the diligent inspector is your best
> friend,
> welcome the diligent inspector.
>
> “A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and then
> unload
> itself. I ws wondering whether I can write a kd extension tht can work
> in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for me.
>
> AP
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

ap:

You’ve lost me. What is it you are asking/trying to do? Do you have
any further questions about KD Ext, et. c., are you all set?

mm

>> xxxxx@gmail.com 2007-05-29 09:47 >>>
hi all

thanks a ton for all the valuable advice.

the reason why i wanted the kd angle was i have better control. and i
dont
have to wait till a third party test ends.

i have haev some thing like a registry key telling me that i need to
fail
the xth memory alloc call and see whether my driver handles cleanup
properly
or not.

AP

On 5/29/07, Martin O’Brien wrote:
>
> In this specific case (pool usage), and most cases overall, I would
> totally agree with DV, et. c. In general, I have found that there
are
> times where your basic idea - kd extension integrated with a driver
-
> does have its place, or at least works well. Generally, I have used
> this to work around problems - for example, ReadMsr() failing with
> certain valid MSR’s.
>
> If I understand you correctly, the answer to your basic question is
> that, no, the kd ext would not unload because the driver did.
>
> mm
>
> >>> xxxxx@neverfailgroup.com 2007-05-28 19:10 >>>
> Your driver must be leak free. Poolmon is a great tool when it comes
to
>
> detection of memory leaks. It is much better to use it in your lab
> before
> your customers use it; I know this as a fact. Verifier is also your
> good
> friend. Prefast might be useful. SDV might be useful. The diligent
> inspector
> is also your friend, chances the diligent inspector is your best
> friend,
> welcome the diligent inspector.
>
> “A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and
then
> unload
> itself. I ws wondering whether I can write a kd extension tht can
work
> in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for
me.
>
> AP
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

well as far as the logic to use the registry key and fail certain memory
allocs, i am set.

what i am curious to find out is 9as u say) the kd ext is not unloaded when
the driver unloads (after say a possible mem alloc failure). then can i use
it to track all unallcoated mem by the driver or not?

On 5/29/07, Martin O’Brien wrote:
>
> ap:
>
> You’ve lost me. What is it you are asking/trying to do? Do you have
> any further questions about KD Ext, et. c., are you all set?
>
> mm
>
> >>> xxxxx@gmail.com 2007-05-29 09:47 >>>
> hi all
>
>
> thanks a ton for all the valuable advice.
>
> the reason why i wanted the kd angle was i have better control. and i
> dont
> have to wait till a third party test ends.
>
> i have haev some thing like a registry key telling me that i need to
> fail
> the xth memory alloc call and see whether my driver handles cleanup
> properly
> or not.
>
> AP
>
> On 5/29/07, Martin O’Brien wrote:
> >
> > In this specific case (pool usage), and most cases overall, I would
> > totally agree with DV, et. c. In general, I have found that there
> are
> > times where your basic idea - kd extension integrated with a driver
> -
> > does have its place, or at least works well. Generally, I have used
> > this to work around problems - for example, ReadMsr() failing with
> > certain valid MSR’s.
> >
> > If I understand you correctly, the answer to your basic question is
> > that, no, the kd ext would not unload because the driver did.
> >
> > mm
> >
> > >>> xxxxx@neverfailgroup.com 2007-05-28 19:10 >>>
> > Your driver must be leak free. Poolmon is a great tool when it comes
> to
> >
> > detection of memory leaks. It is much better to use it in your lab
> > before
> > your customers use it; I know this as a fact. Verifier is also your
> > good
> > friend. Prefast might be useful. SDV might be useful. The diligent
> > inspector
> > is also your friend, chances the diligent inspector is your best
> > friend,
> > welcome the diligent inspector.
> >
> > “A P” wrote in message news:xxxxx@ntdev…
> > Hi all,
> >
> >
> > I want to add memory leaks detection code in a driver. my driver is
> > written
> > such that for allocation failures it should cleanup properly and
> then
> > unload
> > itself. I ws wondering whether I can write a kd extension tht can
> work
> > in
> > conjunction to the driver to make this better. My doubt is when the
> > driver
> > unloads, whould the kd extension also unload? then if wnt work for
> me.
> >
> > AP
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

The kd extension runs on the machine hosting the kernel debugger in the debugger’s process. The driver runs on the target machine in the kernel. There are no links between the two. Are you thinking that the extension runs on the same machine as your driver (ignoring virtual machines at the moment, and even in that case, the idea is still much the same)?

This is a rather open ended question. As I think Don pointed out, the
ext and the driver do not necessarily have anything to do with each
other; if they do, that has to be your doing. So, in the end, you can
pretty much to whatever you are willing to implement in the extension
and/or driver. If you need some sort of synchronization with your
driver, it is up to you to do so. What you wish to do (the
synchronization part) sounds pretty invovled. If you haven’t written an
extension yet, I would take a look at the samples that come with WinDbg.
In particular, I would look at extcpp or exts. The former is based on
the newer EngExtCpp framework, which I personally find much more easily
useful; the later is the older DbgEng. You don’t want simplext or
anything based on the original WDbgExt framework. If you do go the
EngExtCpp framework, there are at least a couple of things to keep in
mind. The first is that the documentation, well, sucks, and
considerably more so that the documentation for DbgEng, which itself,
well, sucks. You will have to understand DbgEng as well. The other is
that, unless you enjoy all the pleasures that can be had with trying to
get something that uses MSVCRT8 to run on machine without Visual Studio
installed, I would strongly suggest that you rebuild the source for
EngExtCpp.lib (which comes with WinDbg) to use a static library.

mm

Let me just mention, once again, just to be sure, that this particular
task (allocations) could be much more easily handled by DV and some
existing tools.

mm

>> xxxxx@gmail.com 2007-05-29 10:30 >>>
well as far as the logic to use the registry key and fail certain
memory
allocs, i am set.

what i am curious to find out is 9as u say) the kd ext is not unloaded
when
the driver unloads (after say a possible mem alloc failure). then can i
use
it to track all unallcoated mem by the driver or not?

On 5/29/07, Martin O’Brien wrote:
>
> ap:
>
> You’ve lost me. What is it you are asking/trying to do? Do you
have
> any further questions about KD Ext, et. c., are you all set?
>
> mm
>
> >>> xxxxx@gmail.com 2007-05-29 09:47 >>>
> hi all
>
>
> thanks a ton for all the valuable advice.
>
> the reason why i wanted the kd angle was i have better control. and
i
> dont
> have to wait till a third party test ends.
>
> i have haev some thing like a registry key telling me that i need to
> fail
> the xth memory alloc call and see whether my driver handles cleanup
> properly
> or not.
>
> AP
>
> On 5/29/07, Martin O’Brien wrote:
> >
> > In this specific case (pool usage), and most cases overall, I
would
> > totally agree with DV, et. c. In general, I have found that there
> are
> > times where your basic idea - kd extension integrated with a
driver
> -
> > does have its place, or at least works well. Generally, I have
used
> > this to work around problems - for example, ReadMsr() failing with
> > certain valid MSR’s.
> >
> > If I understand you correctly, the answer to your basic question
is
> > that, no, the kd ext would not unload because the driver did.
> >
> > mm
> >
> > >>> xxxxx@neverfailgroup.com 2007-05-28 19:10 >>>
> > Your driver must be leak free. Poolmon is a great tool when it
comes
> to
> >
> > detection of memory leaks. It is much better to use it in your lab
> > before
> > your customers use it; I know this as a fact. Verifier is also
your
> > good
> > friend. Prefast might be useful. SDV might be useful. The diligent
> > inspector
> > is also your friend, chances the diligent inspector is your best
> > friend,
> > welcome the diligent inspector.
> >
> > “A P” wrote in message
news:xxxxx@ntdev…
> > Hi all,
> >
> >
> > I want to add memory leaks detection code in a driver. my driver
is
> > written
> > such that for allocation failures it should cleanup properly and
> then
> > unload
> > itself. I ws wondering whether I can write a kd extension tht can
> work
> > in
> > conjunction to the driver to make this better. My doubt is when
the
> > driver
> > unloads, whould the kd extension also unload? then if wnt work for
> me.
> >
> > AP
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> > http://www.osronline.com/page.cfm?name=ListServer
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I pointed this out a while back, and no the OP does not seem to
understand, thus his confusion over unload.

If we wants to track allocations independent of verifier, he needs to do
that in his driver.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Tuesday, May 29, 2007 10:48 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] memory leakage

The kd extension runs on the machine hosting the kernel debugger in the
debugger’s process. The driver runs on the target machine in the
kernel. There are no links between the two. Are you thinking that the
extension runs on the same machine as your driver (ignoring virtual
machines at the moment, and even in that case, the idea is still much
the same)?


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Robert makes an excellent point here that I was assuming that you knew.
The only coordination between the two involves whatever you establish
that basically has to boil down to blocks of memory. A lot can be done
with that, but there is definitely nothing direct.

>> xxxxx@microsoft.com 2007-05-29 10:47 >>>
The kd extension runs on the machine hosting the kernel debugger in the
debugger’s process. The driver runs on the target machine in the
kernel. There are no links between the two. Are you thinking that the
extension runs on the same machine as your driver (ignoring virtual
machines at the moment, and even in that case, the idea is still much
the same)?


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Other folks have chimed in and given you feedback, I want to address 2 things that I don’t think were answered:

How can the extension find the list of memory that was leaked after the driver has unloaded?
It can’t. Think about it. The driver must store the list of allocations somewhere in the driver’s image (or in an allocated header, but you still must store a pointer to that header in the driver somewhere). Once the driver is unloaded, the location of the header is gone. A better way to do this would be to have the driver ASSERT if there is leaked pool on unload…but better yet, just enable driver verifier and let DV do all the work.

Allocating pool with your own allocator
I would assume you did something like this, PVOID MyAllocator(POOL_TYPE Type, SIZE_T Size) and then everyone calls MyAllocator instead of ExAllocatePoolWithTag. The problem with this with respect to driver verifier is the address of the allocator. When you are under verifier, DV captures the callers address to give you a clue as to where you allocated memory but did not free it. If you have a common allocator (MyAllocator), all allocations will come from this one function and you will lose the ability for DV to give you a good clue as to where the memory was allocated from. In this case, everything that you need is given to you by DV. Don’t over engineer the solution, just use what the OS has provided for you.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Tuesday, May 29, 2007 7:30 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] memory leakage

well as far as the logic to use the registry key and fail certain memory allocs, i am set.

what i am curious to find out is 9as u say) the kd ext is not unloaded when the driver unloads (after say a possible mem alloc failure). then can i use it to track all unallcoated mem by the driver or not?

On 5/29/07, Martin O’Brien wrote:
ap:

You’ve lost me.??What is it you are asking/trying to do???Do you have
any further questions about KD Ext, et. c., are you all set?

mm

>>> xxxxx@gmail.com 2007-05-29 09:47 >>>
hi all

thanks a ton for all the valuable advice.

the reason why i wanted the kd angle was i have better control. and i
dont
have to wait till a third party test ends.

i have haev some thing like a registry key telling me that i need to
fail
the xth memory alloc call and see whether my driver handles cleanup
properly
or not.

AP

On 5/29/07, Martin O’Brien < xxxxx@evitechnology.com> wrote:
>
> In this specific case (pool usage), and most cases overall, I would
> totally agree with DV, et. c.??In general, I have found that there
are
> times where your basic idea - kd extension integrated with a driver
-
> does have its place, or at least works well.??Generally, I have used
> this to work around problems - for example, ReadMsr() failing with
> certain valid MSR’s.
>
> If I understand you correctly, the answer to your basic question is
> that, no, the kd ext would not unload because the driver did.
>
> mm
>
> >>> xxxxx@neverfailgroup.com 2007-05-28 19:10 >>>
> Your driver must be leak free. Poolmon is a great tool when it comes
to
>
> detection of memory leaks. It is much better to use it in your lab
> before
> your customers use it; I know this as a fact. Verifier is also your
> good
> friend. Prefast might be useful. SDV might be useful. The diligent
> inspector
> is also your friend, chances the diligent inspector is your best
> friend,
> welcome the diligent inspector.
>
> “A P” wrote in message news:xxxxx@ntdev…
> Hi all,
>
>
> I want to add memory leaks detection code in a driver. my driver is
> written
> such that for allocation failures it should cleanup properly and
then
> unload
> itself. I ws wondering whether I can write a kd extension tht can
work
> in
> conjunction to the driver to make this better. My doubt is when the
> driver
> unloads, whould the kd extension also unload? then if wnt work for
me.
>
> AP
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


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

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer