sc stop is hanging

When my mini-filter is loaded, I can do “sc query myfilter” with no problem.
If I do “sc stop myfilter” it calls my filter’s unload routine, I free all
my resources (at least I think I do), I return a success status, but the sc
program never finishes. It just sits there until I hit CTRL-C. After that
every sc command to my filter, including queries, hangs the same way.

Does anyone have any idea what I could be doing wrong to make this happen?
Is leaving some object referenced (object leak) a possible cause?

Is there some way to use Windbg to trace down what’s happening? Any
suggestions on chasing this would be appreciated.

Mark:

This is most likely a reference that hasn’t been de-referenced somewhere. I
know of no automated way to find them – you have to track every reference
to make sure they’re de-referenced.

In addition to the obvious FltGetxxxContext and FltSetxxxContext routines,
there are a number of routines that cause a reference that you could miss,
such as:

FltAllocateContext
FltGetFileNameInformation
FltGetDestinationFileNameInformation
FltGetDiskDeviceObject
FltGetDeviceObject

You can try ObGetObjectPointerCount() to get the reference count on objects.
Otherwise, it’s pretty manual.

Good luck,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Thursday, March 24, 2005 3:03 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] sc stop is hanging

When my mini-filter is loaded, I can do “sc query myfilter” with no problem.

If I do “sc stop myfilter” it calls my filter’s unload routine, I free all
my resources (at least I think I do), I return a success status, but the sc
program never finishes. It just sits there until I hit CTRL-C. After that
every sc command to my filter, including queries, hangs the same way.

Does anyone have any idea what I could be doing wrong to make this happen?
Is leaving some object referenced (object leak) a possible cause?

Is there some way to use Windbg to trace down what’s happening? Any
suggestions on chasing this would be appreciated.


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

The ObGetObjectPointerCount() trick sounds useful. Is there an equivalent
for contexts?

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Mark:
>
> This is most likely a reference that hasn’t been de-referenced somewhere.
> I
> know of no automated way to find them – you have to track every reference
> to make sure they’re de-referenced.
>
> In addition to the obvious FltGetxxxContext and FltSetxxxContext routines,
> there are a number of routines that cause a reference that you could miss,
> such as:
>
> FltAllocateContext
> FltGetFileNameInformation
> FltGetDestinationFileNameInformation
> FltGetDiskDeviceObject
> FltGetDeviceObject
>
> You can try ObGetObjectPointerCount() to get the reference count on
> objects.
> Otherwise, it’s pretty manual.
>
> Good luck,
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:03 PM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] sc stop is hanging
>
> When my mini-filter is loaded, I can do “sc query myfilter” with no
> problem.
>
> If I do “sc stop myfilter” it calls my filter’s unload routine, I free all
> my resources (at least I think I do), I return a success status, but the
> sc
> program never finishes. It just sits there until I hit CTRL-C. After
> that
> every sc command to my filter, including queries, hangs the same way.
>
> Does anyone have any idea what I could be doing wrong to make this happen?
> Is leaving some object referenced (object leak) a possible cause?
>
> Is there some way to use Windbg to trace down what’s happening? Any
> suggestions on chasing this would be appreciated.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

ObGetObjectPointerCount should work for contexts, although I haven’t tried
it. Any help, MS?

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Thursday, March 24, 2005 3:30 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

The ObGetObjectPointerCount() trick sounds useful. Is there an equivalent
for contexts?

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Mark:
>
> This is most likely a reference that hasn’t been de-referenced somewhere.
> I
> know of no automated way to find them – you have to track every reference
> to make sure they’re de-referenced.
>
> In addition to the obvious FltGetxxxContext and FltSetxxxContext routines,
> there are a number of routines that cause a reference that you could miss,
> such as:
>
> FltAllocateContext
> FltGetFileNameInformation
> FltGetDestinationFileNameInformation
> FltGetDiskDeviceObject
> FltGetDeviceObject
>
> You can try ObGetObjectPointerCount() to get the reference count on
> objects.
> Otherwise, it’s pretty manual.
>
> Good luck,
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:03 PM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] sc stop is hanging
>
> When my mini-filter is loaded, I can do “sc query myfilter” with no
> problem.
>
> If I do “sc stop myfilter” it calls my filter’s unload routine, I free all
> my resources (at least I think I do), I return a success status, but the
> sc
> program never finishes. It just sits there until I hit CTRL-C. After
> that
> every sc command to my filter, including queries, hangs the same way.
>
> Does anyone have any idea what I could be doing wrong to make this happen?
> Is leaving some object referenced (object leak) a possible cause?
>
> Is there some way to use Windbg to trace down what’s happening? Any
> suggestions on chasing this would be appreciated.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

Is a “context” an object in the Ob sense? If not, well,
ObGetObjectPointerCount() doesnt sound that hopeful?

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> ObGetObjectPointerCount should work for contexts, although I haven’t tried
> it. Any help, MS?
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:30 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
> The ObGetObjectPointerCount() trick sounds useful. Is there an equivalent
> for contexts?
>
> “Ken Cross” wrote in message news:xxxxx@ntfsd…
>> Mark:
>>
>> This is most likely a reference that hasn’t been de-referenced somewhere.
>> I
>> know of no automated way to find them – you have to track every
>> reference
>> to make sure they’re de-referenced.
>>
>> In addition to the obvious FltGetxxxContext and FltSetxxxContext
>> routines,
>> there are a number of routines that cause a reference that you could
>> miss,
>> such as:
>>
>> FltAllocateContext
>> FltGetFileNameInformation
>> FltGetDestinationFileNameInformation
>> FltGetDiskDeviceObject
>> FltGetDeviceObject
>>
>> You can try ObGetObjectPointerCount() to get the reference count on
>> objects.
>> Otherwise, it’s pretty manual.
>>
>> Good luck,
>> Ken
>>
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
>> Sent: Thursday, March 24, 2005 3:03 PM
>> To: Windows File Systems Devs Interest List
>> Subject: [ntfsd] sc stop is hanging
>>
>> When my mini-filter is loaded, I can do “sc query myfilter” with no
>> problem.
>>
>> If I do “sc stop myfilter” it calls my filter’s unload routine, I free
>> all
>> my resources (at least I think I do), I return a success status, but the
>> sc
>> program never finishes. It just sits there until I hit CTRL-C. After
>> that
>> every sc command to my filter, including queries, hangs the same way.
>>
>> Does anyone have any idea what I could be doing wrong to make this
>> happen?
>> Is leaving some object referenced (object leak) a possible cause?
>>
>> Is there some way to use Windbg to trace down what’s happening? Any
>> suggestions on chasing this would be appreciated.
>>
>>
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@comcast.net
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Right. The proof is in the trying…

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Thursday, March 24, 2005 4:41 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

Is a “context” an object in the Ob sense? If not, well,
ObGetObjectPointerCount() doesnt sound that hopeful?

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> ObGetObjectPointerCount should work for contexts, although I haven’t tried
> it. Any help, MS?
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:30 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
> The ObGetObjectPointerCount() trick sounds useful. Is there an equivalent
> for contexts?
>
> “Ken Cross” wrote in message news:xxxxx@ntfsd…
>> Mark:
>>
>> This is most likely a reference that hasn’t been de-referenced somewhere.
>> I
>> know of no automated way to find them – you have to track every
>> reference
>> to make sure they’re de-referenced.
>>
>> In addition to the obvious FltGetxxxContext and FltSetxxxContext
>> routines,
>> there are a number of routines that cause a reference that you could
>> miss,
>> such as:
>>
>> FltAllocateContext
>> FltGetFileNameInformation
>> FltGetDestinationFileNameInformation
>> FltGetDiskDeviceObject
>> FltGetDeviceObject
>>
>> You can try ObGetObjectPointerCount() to get the reference count on
>> objects.
>> Otherwise, it’s pretty manual.
>>
>> Good luck,
>> Ken
>>
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
>> Sent: Thursday, March 24, 2005 3:03 PM
>> To: Windows File Systems Devs Interest List
>> Subject: [ntfsd] sc stop is hanging
>>
>> When my mini-filter is loaded, I can do “sc query myfilter” with no
>> problem.
>>
>> If I do “sc stop myfilter” it calls my filter’s unload routine, I free
>> all
>> my resources (at least I think I do), I return a success status, but the
>> sc
>> program never finishes. It just sits there until I hit CTRL-C. After
>> that
>> every sc command to my filter, including queries, hangs the same way.
>>
>> Does anyone have any idea what I could be doing wrong to make this
>> happen?
>> Is leaving some object referenced (object leak) a possible cause?
>>
>> Is there some way to use Windbg to trace down what’s happening? Any
>> suggestions on chasing this would be appreciated.
>>
>>
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@comcast.net
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

My favourire saying for wndows km work these days “there are no facts, only
observations, and rumours about observations” :slight_smile:

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Right. The proof is in the trying…
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
> Sent: Thursday, March 24, 2005 4:41 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
> Is a “context” an object in the Ob sense? If not, well,
> ObGetObjectPointerCount() doesnt sound that hopeful?
>
> “Ken Cross” wrote in message news:xxxxx@ntfsd…
>> ObGetObjectPointerCount should work for contexts, although I haven’t
>> tried
>> it. Any help, MS?
>>
>> Ken
>>
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
>> Sent: Thursday, March 24, 2005 3:30 PM
>> To: Windows File Systems Devs Interest List
>> Subject: Re:[ntfsd] sc stop is hanging
>>
>> The ObGetObjectPointerCount() trick sounds useful. Is there an
>> equivalent
>> for contexts?
>>
>> “Ken Cross” wrote in message news:xxxxx@ntfsd…
>>> Mark:
>>>
>>> This is most likely a reference that hasn’t been de-referenced
>>> somewhere.
>>> I
>>> know of no automated way to find them – you have to track every
>>> reference
>>> to make sure they’re de-referenced.
>>>
>>> In addition to the obvious FltGetxxxContext and FltSetxxxContext
>>> routines,
>>> there are a number of routines that cause a reference that you could
>>> miss,
>>> such as:
>>>
>>> FltAllocateContext
>>> FltGetFileNameInformation
>>> FltGetDestinationFileNameInformation
>>> FltGetDiskDeviceObject
>>> FltGetDeviceObject
>>>
>>> You can try ObGetObjectPointerCount() to get the reference count on
>>> objects.
>>> Otherwise, it’s pretty manual.
>>>
>>> Good luck,
>>> Ken
>>>
>>>
>>> -----Original Message-----
>>> From: xxxxx@lists.osr.com
>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
>>> Sent: Thursday, March 24, 2005 3:03 PM
>>> To: Windows File Systems Devs Interest List
>>> Subject: [ntfsd] sc stop is hanging
>>>
>>> When my mini-filter is loaded, I can do “sc query myfilter” with no
>>> problem.
>>>
>>> If I do “sc stop myfilter” it calls my filter’s unload routine, I free
>>> all
>>> my resources (at least I think I do), I return a success status, but the
>>> sc
>>> program never finishes. It just sits there until I hit CTRL-C. After
>>> that
>>> every sc command to my filter, including queries, hangs the same way.
>>>
>>> Does anyone have any idea what I could be doing wrong to make this
>>> happen?
>>> Is leaving some object referenced (object leak) a possible cause?
>>>
>>> Is there some way to use Windbg to trace down what’s happening? Any
>>> suggestions on chasing this would be appreciated.
>>>
>>>
>>>
>>> —
>>> Questions? First check the IFS FAQ at
>>> https://www.osronline.com/article.cfm?id=17
>>>
>>> You are currently subscribed to ntfsd as: xxxxx@comcast.net
>>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>>
>>>
>>
>>
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@comcast.net
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

ObGetObjectPointerCount is no longer in XP and later OS. However, the
following hack will show you “contexts” reference counts: *((ULONG
*)context_ptr - 1)

HTH /ted

-----Original Message-----
From: Ken Cross [mailto:xxxxx@comcast.net]
Sent: Thursday, March 24, 2005 3:41 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] sc stop is hanging

ObGetObjectPointerCount should work for contexts, although I haven’t tried
it. Any help, MS?

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Thursday, March 24, 2005 3:30 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

The ObGetObjectPointerCount() trick sounds useful. Is there an equivalent
for contexts?

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Mark:
>
> This is most likely a reference that hasn’t been de-referenced
> somewhere.
> I
> know of no automated way to find them – you have to track every reference
> to make sure they’re de-referenced.
>
> In addition to the obvious FltGetxxxContext and FltSetxxxContext
> routines, there are a number of routines that cause a reference that
> you could miss, such as:
>
> FltAllocateContext
> FltGetFileNameInformation FltGetDestinationFileNameInformation
> FltGetDiskDeviceObject
> FltGetDeviceObject
>
> You can try ObGetObjectPointerCount() to get the reference count on
> objects.
> Otherwise, it’s pretty manual.
>
> Good luck,
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:03 PM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] sc stop is hanging
>
> When my mini-filter is loaded, I can do “sc query myfilter” with no
> problem.
>
> If I do “sc stop myfilter” it calls my filter’s unload routine, I free
> all my resources (at least I think I do), I return a success status,
> but the sc program never finishes. It just sits there until I hit
> CTRL-C. After that
> every sc command to my filter, including queries, hangs the same way.
>
> Does anyone have any idea what I could be doing wrong to make this
> happen? Is leaving some object referenced (object leak) a possible
> cause?
>
> Is there some way to use Windbg to trace down what’s happening? Any
> suggestions on chasing this would be appreciated.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net To unsubscribe
send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@livevault.com To unsubscribe
send a blank email to xxxxx@lists.osr.com

I don’t think FltAllocateContext needs a matching context release because
the docs say that the context it returns is not initialized, not even the
filter manager part. You must have been thinking of FltSetXXXContext which
does the init and needs a matching release.

So unless I’m mistaken we can say that only the “sets” and “gets” need
matching releases.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Mark:
>
> This is most likely a reference that hasn’t been de-referenced somewhere.
> I
> know of no automated way to find them – you have to track every reference
> to make sure they’re de-referenced.
>
> In addition to the obvious FltGetxxxContext and FltSetxxxContext routines,
> there are a number of routines that cause a reference that you could miss,
> such as:
>
> FltAllocateContext
> FltGetFileNameInformation
> FltGetDestinationFileNameInformation
> FltGetDiskDeviceObject
> FltGetDeviceObject
>
> You can try ObGetObjectPointerCount() to get the reference count on
> objects.
> Otherwise, it’s pretty manual.
>
> Good luck,
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:03 PM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] sc stop is hanging
>
> When my mini-filter is loaded, I can do “sc query myfilter” with no
> problem.
>
> If I do “sc stop myfilter” it calls my filter’s unload routine, I free all
> my resources (at least I think I do), I return a success status, but the
> sc
> program never finishes. It just sits there until I hit CTRL-C. After
> that
> every sc command to my filter, including queries, hangs the same way.
>
> Does anyone have any idea what I could be doing wrong to make this happen?
> Is leaving some object referenced (object leak) a possible cause?
>
> Is there some way to use Windbg to trace down what’s happening? Any
> suggestions on chasing this would be appreciated.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Nope. Look at the description of ReturnedContext for FltAllocateContext:

“The caller is responsible for calling FltReleaseContext to release this
context when it is no longer needed.”

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Thursday, March 24, 2005 6:26 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

I don’t think FltAllocateContext needs a matching context release because
the docs say that the context it returns is not initialized, not even the
filter manager part. You must have been thinking of FltSetXXXContext which
does the init and needs a matching release.

So unless I’m mistaken we can say that only the “sets” and “gets” need
matching releases.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Mark:
>
> This is most likely a reference that hasn’t been de-referenced somewhere.
> I
> know of no automated way to find them – you have to track every reference
> to make sure they’re de-referenced.
>
> In addition to the obvious FltGetxxxContext and FltSetxxxContext routines,
> there are a number of routines that cause a reference that you could miss,
> such as:
>
> FltAllocateContext
> FltGetFileNameInformation
> FltGetDestinationFileNameInformation
> FltGetDiskDeviceObject
> FltGetDeviceObject
>
> You can try ObGetObjectPointerCount() to get the reference count on
> objects.
> Otherwise, it’s pretty manual.
>
> Good luck,
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 3:03 PM
> To: Windows File Systems Devs Interest List
> Subject: [ntfsd] sc stop is hanging
>
> When my mini-filter is loaded, I can do “sc query myfilter” with no
> problem.
>
> If I do “sc stop myfilter” it calls my filter’s unload routine, I free all
> my resources (at least I think I do), I return a success status, but the
> sc
> program never finishes. It just sits there until I hit CTRL-C. After
> that
> every sc command to my filter, including queries, hangs the same way.
>
> Does anyone have any idea what I could be doing wrong to make this happen?
> Is leaving some object referenced (object leak) a possible cause?
>
> Is there some way to use Windbg to trace down what’s happening? Any
> suggestions on chasing this would be appreciated.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

That seems like a contradiction but I’ll try it. How could you pass an
uninitialized structure you got from allocate to FltReleaseContext? Maybe
it is initialized to a value of two in SetContext. Or maybe the docs are
just wrong about it not being initialized for the filter manager when
allocated. Maybe trying to make sense of these docs is a silly exercise in
general.

The logical place for me to put the matching release for the allocation call
is in context-cleanup, but doing a FltReleaseContext in context-cleanup
seems silly since it’s about to go away anyway. I wonder if the call to
context cleanup is delayed until there are no more outstanding accesses. If
so then I’ve got a big catch-22 on my hands. I’ll put a FltReleaseContext
in context-cleanup and give it a try.

The whole idea of having reference counts for context structures seems quite
redundant to me since they are obviously not needed after the object they
are linked to goes away. They make no sense for avoiding leaks since they
won’t leak if they are linked to an object that doesn’t leak.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Nope. Look at the description of ReturnedContext for FltAllocateContext:
>
> “The caller is responsible for calling FltReleaseContext to release this
> context when it is no longer needed.”
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Thursday, March 24, 2005 6:26 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
> I don’t think FltAllocateContext needs a matching context release because
> the docs say that the context it returns is not initialized, not even the
> filter manager part. You must have been thinking of FltSetXXXContext
> which
> does the init and needs a matching release.
>
> So unless I’m mistaken we can say that only the “sets” and “gets” need
> matching releases.
>
> “Ken Cross” wrote in message news:xxxxx@ntfsd…
>> Mark:
>>
>> This is most likely a reference that hasn’t been de-referenced somewhere.
>> I
>> know of no automated way to find them – you have to track every
>> reference
>> to make sure they’re de-referenced.
>>
>> In addition to the obvious FltGetxxxContext and FltSetxxxContext
>> routines,
>> there are a number of routines that cause a reference that you could
>> miss,
>> such as:
>>
>> FltAllocateContext
>> FltGetFileNameInformation
>> FltGetDestinationFileNameInformation
>> FltGetDiskDeviceObject
>> FltGetDeviceObject
>>
>> You can try ObGetObjectPointerCount() to get the reference count on
>> objects.
>> Otherwise, it’s pretty manual.
>>
>> Good luck,
>> Ken
>>
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
>> Sent: Thursday, March 24, 2005 3:03 PM
>> To: Windows File Systems Devs Interest List
>> Subject: [ntfsd] sc stop is hanging
>>
>> When my mini-filter is loaded, I can do “sc query myfilter” with no
>> problem.
>>
>> If I do “sc stop myfilter” it calls my filter’s unload routine, I free
>> all
>> my resources (at least I think I do), I return a success status, but the
>> sc
>> program never finishes. It just sits there until I hit CTRL-C. After
>> that
>> every sc command to my filter, including queries, hangs the same way.
>>
>> Does anyone have any idea what I could be doing wrong to make this
>> happen?
>> Is leaving some object referenced (object leak) a possible cause?
>>
>> Is there some way to use Windbg to trace down what’s happening? Any
>> suggestions on chasing this would be appreciated.
>>
>>
>>
>> —
>> Questions? First check the IFS FAQ at
>> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@comcast.net
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

I think you’re wrong here. Contexts returned from FltAllocateContext
should have a reference count of 1. This allows you to delete the context
with FltReleaseContext if, for example, you have a failure initialializing
the context, or you use FltSetXXXContext with
FLT_SET_CONTEXT_KEEP_IF_EXISTS and the context already exists.

In the 3790.1812 documentation of FltAllocateContext, I can not find a
statement to the effect that the Filter Manager’s portion ot the context is
uninitialized. It says:

“FltAllocateContext does not initialize the contents of the mini-filter
specific portion of the context structure.”

That refers to your portion of the context.

You should look at the ctx minifilter sample for examples of how to handle
contexts.

Maybe trying to make sense of these docs is a silly exercise in
general.

IMNSHO, the docs could use some work in their descriptions of reference
counting. I would like to see it explicitly stated that FltAllocateContext
initializes the refcount to 1, and explicit indications for other routines
indicating under what conditions they increment a reference count.

The reference counting works properly and reasonably, but the docs describe
it badly. I look forward to someday seeing the doc section IFS Kit
Documentation->Design Guide->File System Minifilter Drivers->Using Contexts.

The logical place for me to put the matching release for the allocation call
is in context-cleanup, but doing a FltReleaseContext in context-cleanup

This is not right. The context cleanup routine is called when the context
reference count goes to zero. Calling FltReleaseContext in context cleanup
would likely have no effect. You should release the context when you are
done with it.

However, while I have not verified it, I also strongly suspect that
contexts are explicitly deleted by Filter Manager when their associated
objects go away. As was discussed in another thread on this list, without
implementing some reference counting of your own, there is no good way to
know whether the close of a stream handle is the last close for that
stream, so you don’t know whether you’re done with the stream context.

Perhaps Neal or Molly would be kind enough to shed more light.

  • Dan.

At 08:05 PM 3/24/2005 -0800, you wrote:

That seems like a contradiction but I’ll try it. How could you pass an
uninitialized structure you got from allocate to FltReleaseContext? Maybe
it is initialized to a value of two in SetContext. Or maybe the docs are
just wrong about it not being initialized for the filter manager when
allocated. Maybe trying to make sense of these docs is a silly exercise in
general.

The logical place for me to put the matching release for the allocation call
is in context-cleanup, but doing a FltReleaseContext in context-cleanup
seems silly since it’s about to go away anyway. I wonder if the call to
context cleanup is delayed until there are no more outstanding accesses. If
so then I’ve got a big catch-22 on my hands. I’ll put a FltReleaseContext
in context-cleanup and give it a try.

The whole idea of having reference counts for context structures seems quite
redundant to me since they are obviously not needed after the object they
are linked to goes away. They make no sense for avoiding leaks since they
won’t leak if they are linked to an object that doesn’t leak.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> > Nope. Look at the description of ReturnedContext for FltAllocateContext:
> >
> > “The caller is responsible for calling FltReleaseContext to release this
> > context when it is no longer needed.”
> >
> > Ken
> >
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> > Sent: Thursday, March 24, 2005 6:26 PM
> > To: Windows File Systems Devs Interest List
> > Subject: Re:[ntfsd] sc stop is hanging
> >
> > I don’t think FltAllocateContext needs a matching context release because
> > the docs say that the context it returns is not initialized, not even the
> > filter manager part. You must have been thinking of FltSetXXXContext
> > which
> > does the init and needs a matching release.
> >
> > So unless I’m mistaken we can say that only the “sets” and “gets” need
> > matching releases.
> >
> > “Ken Cross” wrote in message news:xxxxx@ntfsd…
> >> Mark:
> >>
> >> This is most likely a reference that hasn’t been de-referenced somewhere.
> >> I
> >> know of no automated way to find them – you have to track every
> >> reference
> >> to make sure they’re de-referenced.
> >>
> >> In addition to the obvious FltGetxxxContext and FltSetxxxContext
> >> routines,
> >> there are a number of routines that cause a reference that you could
> >> miss,
> >> such as:
> >>
> >> FltAllocateContext
> >> FltGetFileNameInformation
> >> FltGetDestinationFileNameInformation
> >> FltGetDiskDeviceObject
> >> FltGetDeviceObject
> >>
> >> You can try ObGetObjectPointerCount() to get the reference count on
> >> objects.
> >> Otherwise, it’s pretty manual.
> >>
> >> Good luck,
> >> Ken
> >>
> >>
> >> -----Original Message-----
> >> From: xxxxx@lists.osr.com
> >> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> >> Sent: Thursday, March 24, 2005 3:03 PM
> >> To: Windows File Systems Devs Interest List
> >> Subject: [ntfsd] sc stop is hanging
> >>
> >> When my mini-filter is loaded, I can do “sc query myfilter” with no
> >> problem.
> >>
> >> If I do “sc stop myfilter” it calls my filter’s unload routine, I free
> >> all
> >> my resources (at least I think I do), I return a success status, but the
> >> sc
> >> program never finishes. It just sits there until I hit CTRL-C. After
> >> that
> >> every sc command to my filter, including queries, hangs the same way.
> >>
> >> Does anyone have any idea what I could be doing wrong to make this
> >> happen?
> >> Is leaving some object referenced (object leak) a possible cause?
> >>
> >> Is there some way to use Windbg to trace down what’s happening? Any
> >> suggestions on chasing this would be appreciated.
> >>
> >>
> >>
> >> —
> >> Questions? First check the IFS FAQ at
> >> https://www.osronline.com/article.cfm?id=17
> >>
> >> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
> >>
> >>
> >
> >
> >
> > —
> > Questions? First check the IFS FAQ at
> > https://www.osronline.com/article.cfm?id=17
> >
> > You are currently subscribed to ntfsd as: xxxxx@comcast.net
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
>—
>Questions? First check the IFS FAQ at
>https://www.osronline.com/article.cfm?id=17
>
>You are currently subscribed to ntfsd as: xxxxx@privtek.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

“Dan Kyler” wrote …

> “FltAllocateContext does not initialize the contents of the mini-filter
> specific portion of the context structure.”
> That refers to your portion of the context.

Yes, I was wrong. I misread that statement and it stuck in my mind.

>>The logical place for me to put the matching release for the allocation
>>call
>>is in context-cleanup, but doing a FltReleaseContext in context-cleanup
>
> This is not right. The context cleanup routine is called when the context
> reference count goes to zero. Calling FltReleaseContext in context
> cleanup would likely have no effect. You should release the context when
> you are done with it.

Yes, I found out the hard way that calling FltReleaseContext in context
cleanup causes the count to go negative which triggers an assertion in the
fltmgr.

> As was discussed in another thread on this list, without implementing some
> reference counting of your own, there is no good way to know whether the
> close of a stream handle is the last close for that stream, so you don’t
> know whether you’re done with the stream context.

Yes, that was my thread also. That is the catch-22 I was referring to. I’m
relying on the fltmgr to tell me when the item is no longer needed. Ideally
the fltmgr would keep a reference to the context itself and release that
when the object linked to goes away. I could leave the count at 1 and
perform my post-context work in the context-cleanup routine. Leaving the
count at 1 is the same thing as not releasing the reference from the
allocate call.

I’m afraid that leaving the count at zero will cause the context to be
deleted early, but I’ll try it both ways.

I’m not used to programming by trial and error. Maybe when I do get used to
it I while quit bugging everyone on this list.

I found out one more thing about context reference counts. If you decrement
the count to zero while the context is still attached to an object, you get
an assertion error.

So now I know that I have to keep the context ref count to a minimum of 1
all the time. This means I must not release the count added by the allocate
routine.

I sure hope that the context-cleanup routine is still called when the object
it is linked to disappears and the ref count is 1.

So my current strategy (really the only one left to me) is to not release
the reference from the allocate but dereference all others immediately after
they are incremented by a FltSetXXX or FltGetXXX. This means the context
reference count is useless.

It is tempting to just sprinkle my code with *(((ULONG) context)-1) = 1;
everywhere as a test.

Help us understand your problem better.

You’re talking about a stream context, right? I don’t think the context
cleanup gets called until everything’s done using it, i.e., the reference
count goes to zero. So I doubt if what you’re suggesting will work.

Furthermore, it’s probably a Bad Idea to do things like
“*(((ULONG)context)-1)=1;” because you don’t know what other parts of the
system (Filter Manager, file system, etc.) might be
referencing/dereferencing the context without your knowledge. I don’t know
that they do, but you should probably assume they do.

Now, why can’t you release the context in post-cleanup?

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Friday, March 25, 2005 5:36 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

I found out one more thing about context reference counts. If you decrement

the count to zero while the context is still attached to an object, you get
an assertion error.

So now I know that I have to keep the context ref count to a minimum of 1
all the time. This means I must not release the count added by the allocate

routine.

I sure hope that the context-cleanup routine is still called when the object

it is linked to disappears and the ref count is 1.

So my current strategy (really the only one left to me) is to not release
the reference from the allocate but dereference all others immediately after

they are incremented by a FltSetXXX or FltGetXXX. This means the context
reference count is useless.

It is tempting to just sprinkle my code with *(((ULONG) context)-1) = 1;
everywhere as a test.


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

> It is tempting to just sprinkle my code with *(((ULONG) context)-1) = 1;

everywhere as a test.

Very bad idea, as Ken already pointed. But at least do this by
InterlockedDecrement :slight_smile:

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

I ended up doing ASSERT( *(((ULONG)context)-1) == 1 ); everywhere (which is
much safer ) and I was able to figure out what the context ref count
rules are:

1) If you try to dereference any context still attached to an object, to a
count of zero, you get an assertion error from the filter manager.

2) When the object that the context is attached to dissapears, there is a
single decrement of the ref count done by the filter manager. This also
happens when you manually detach a context from it’s object using
FltDeleteContext.

3) The context-cleanup gets called only when the ref count goes to zero.

Using the above bits of knowledge, I was able to come up with an algorithm
that worked for me:

a) Never deref an allocate function. This leaves the ref count at one which
is balanced by the auto-decrement done by the filter manager when an object
disappears.

b) Always deref all fltmgr calls that increment the ref count after finding
out the call was successful. Once again this keeps the ref count at 1.
(Actually I keep the reference held for the brief period that I’m using it
after any call).

This method caused my contexts to have their ref count go to zero whenever a
context is detached from an object, either automatically or manually. This
caused context-cleanup to be called at that time for all objects.

So I am convinced that my code is not leaving any contexts hanging, but I am
still getting the “sc stop” hangup. I’ll start a new thread on this.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Help us understand your problem better.
>
> You’re talking about a stream context, right? I don’t think the context
> cleanup gets called until everything’s done using it, i.e., the reference
> count goes to zero. So I doubt if what you’re suggesting will work.
>
> Furthermore, it’s probably a Bad Idea to do things like
> “*(((ULONG)context)-1)=1;” because you don’t know what other parts of the
> system (Filter Manager, file system, etc.) might be
> referencing/dereferencing the context without your knowledge. I don’t
> know
> that they do, but you should probably assume they do.
>
> Now, why can’t you release the context in post-cleanup?
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Friday, March 25, 2005 5:36 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
>
> I found out one more thing about context reference counts. If you
> decrement
>
> the count to zero while the context is still attached to an object, you
> get
> an assertion error.
>
> So now I know that I have to keep the context ref count to a minimum of 1
> all the time. This means I must not release the count added by the
> allocate
>
> routine.
>
> I sure hope that the context-cleanup routine is still called when the
> object
>
> it is linked to disappears and the ref count is 1.
>
> So my current strategy (really the only one left to me) is to not release
> the reference from the allocate but dereference all others immediately
> after
>
> they are incremented by a FltSetXXX or FltGetXXX. This means the context
> reference count is useless.
>
> It is tempting to just sprinkle my code with *(((ULONG) context)-1) = 1;
> everywhere as a test.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Mark,

You have gone to a lot of work to figure out the following basic rules:

  • Whenever you allocate/get a context you must at some point release it.
  • Setting a context puts an internal residual count on the context which
    keeps it from going away
  • Deleting a context (either explicitly by calling one of the delete
    context APIs or implicitly by the object it is attached to going away)
    removes the residual count.
  • The context cleanup routine is called once the reference count goes to
    zero.

This means a deleted context will not go away until all references go
away. You should not maintain your own list of contexts just for the
purpose of deleting them at unload time. We do this for you
automatically and all you are doing is adding unnecessary overhead.

This referencing model in the filter manager works correctly and there
are no holes or problems which makes this unusable or incorrect.

It is by design that we don’t allow your filter to unload if you have
referenced objects laying around. If it does not unload it is because
you have some sort of reference counting bug.

Anytime you retrieve a filter manager object it is referenced. This
means you must do the appropriate unreference so the object can be
freed.

We will be working on verifier features that will track all of this
information so that at unload time we can tell you exactly what you have
done wrong.

If you are still having problems with this please send me the stack
backtrace of where you are hung. I want to know if it is hung unloading
an instance or unloading the filter.

Neal Christiansen
Microsoft File System Filter Group Lead
This posting is provided “AS IS” with no warranties, and confers no
Rights

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Friday, March 25, 2005 5:00 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

I ended up doing ASSERT( *(((ULONG)context)-1) == 1 ); everywhere
(which is
much safer ) and I was able to figure out what the context ref
count
rules are:

1) If you try to dereference any context still attached to an object, to
a
count of zero, you get an assertion error from the filter manager.

2) When the object that the context is attached to dissapears, there is
a
single decrement of the ref count done by the filter manager. This also

happens when you manually detach a context from it’s object using
FltDeleteContext.

3) The context-cleanup gets called only when the ref count goes to zero.

Using the above bits of knowledge, I was able to come up with an
algorithm
that worked for me:

a) Never deref an allocate function. This leaves the ref count at one
which
is balanced by the auto-decrement done by the filter manager when an
object
disappears.

b) Always deref all fltmgr calls that increment the ref count after
finding
out the call was successful. Once again this keeps the ref count at 1.
(Actually I keep the reference held for the brief period that I’m using
it
after any call).

This method caused my contexts to have their ref count go to zero
whenever a
context is detached from an object, either automatically or manually.
This
caused context-cleanup to be called at that time for all objects.

So I am convinced that my code is not leaving any contexts hanging, but
I am
still getting the “sc stop” hangup. I’ll start a new thread on this.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Help us understand your problem better.
>
> You’re talking about a stream context, right? I don’t think the
context
> cleanup gets called until everything’s done using it, i.e., the
reference
> count goes to zero. So I doubt if what you’re suggesting will work.
>
> Furthermore, it’s probably a Bad Idea to do things like
> “*(((ULONG)context)-1)=1;” because you don’t know what other parts of
the
> system (Filter Manager, file system, etc.) might be
> referencing/dereferencing the context without your knowledge. I don’t

> know
> that they do, but you should probably assume they do.
>
> Now, why can’t you release the context in post-cleanup?
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Friday, March 25, 2005 5:36 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
>
> I found out one more thing about context reference counts. If you
> decrement
>
> the count to zero while the context is still attached to an object,
you
> get
> an assertion error.
>
> So now I know that I have to keep the context ref count to a minimum
of 1
> all the time. This means I must not release the count added by the
> allocate
>
> routine.
>
> I sure hope that the context-cleanup routine is still called when the
> object
>
> it is linked to disappears and the ref count is 1.
>
> So my current strategy (really the only one left to me) is to not
release
> the reference from the allocate but dereference all others immediately

> after
>
> they are incremented by a FltSetXXX or FltGetXXX. This means the
context
> reference count is useless.
>
> It is tempting to just sprinkle my code with *(((ULONG) context)-1) =
1;
> everywhere as a test.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The only rule you don’t mention is that you will get an assertion error if
you try to reduce the ref count to zero while the context is still attached
to an object. This means I can only do one dereference after calling alloc
and attach. This leaves the ref count at one until the detach, even if I
have no interest in the context anymore.

After turning on the verifier I was able to tell what was causing the unload
problem. I’ve now fixed all my problems in that regard.

Thanks…

“Neal Christiansen” wrote in message
news:xxxxx@ntfsd…
Mark,

You have gone to a lot of work to figure out the following basic rules:

- Whenever you allocate/get a context you must at some point release it.
- Setting a context puts an internal residual count on the context which
keeps it from going away
- Deleting a context (either explicitly by calling one of the delete
context APIs or implicitly by the object it is attached to going away)
removes the residual count.
- The context cleanup routine is called once the reference count goes to
zero.

This means a deleted context will not go away until all references go
away. You should not maintain your own list of contexts just for the
purpose of deleting them at unload time. We do this for you
automatically and all you are doing is adding unnecessary overhead.

This referencing model in the filter manager works correctly and there
are no holes or problems which makes this unusable or incorrect.

It is by design that we don’t allow your filter to unload if you have
referenced objects laying around. If it does not unload it is because
you have some sort of reference counting bug.

Anytime you retrieve a filter manager object it is referenced. This
means you must do the appropriate unreference so the object can be
freed.

We will be working on verifier features that will track all of this
information so that at unload time we can tell you exactly what you have
done wrong.

If you are still having problems with this please send me the stack
backtrace of where you are hung. I want to know if it is hung unloading
an instance or unloading the filter.

Neal Christiansen
Microsoft File System Filter Group Lead
This posting is provided “AS IS” with no warranties, and confers no
Rights

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Friday, March 25, 2005 5:00 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

I ended up doing ASSERT( (((ULONG)context)-1) == 1 ); everywhere
(which is
much safer ) and I was able to figure out what the context ref
count
rules are:

1) If you try to dereference any context still attached to an object, to
a
count of zero, you get an assertion error from the filter manager.

2) When the object that the context is attached to dissapears, there is
a
single decrement of the ref count done by the filter manager. This also

happens when you manually detach a context from it’s object using
FltDeleteContext.

3) The context-cleanup gets called only when the ref count goes to zero.

Using the above bits of knowledge, I was able to come up with an
algorithm
that worked for me:

a) Never deref an allocate function. This leaves the ref count at one
which
is balanced by the auto-decrement done by the filter manager when an
object
disappears.

b) Always deref all fltmgr calls that increment the ref count after
finding
out the call was successful. Once again this keeps the ref count at 1.
(Actually I keep the reference held for the brief period that I’m using
it
after any call).

This method caused my contexts to have their ref count go to zero
whenever a
context is detached from an object, either automatically or manually.
This
caused context-cleanup to be called at that time for all objects.

So I am convinced that my code is not leaving any contexts hanging, but
I am
still getting the “sc stop” hangup. I’ll start a new thread on this.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Help us understand your problem better.
>
> You’re talking about a stream context, right? I don’t think the
context
> cleanup gets called until everything’s done using it, i.e., the
reference
> count goes to zero. So I doubt if what you’re suggesting will work.
>
> Furthermore, it’s probably a Bad Idea to do things like
> "
(((ULONG)context)-1)=1;" because you don’t know what other parts of
the
> system (Filter Manager, file system, etc.) might be
> referencing/dereferencing the context without your knowledge. I don’t

> know
> that they do, but you should probably assume they do.
>
> Now, why can’t you release the context in post-cleanup?
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Friday, March 25, 2005 5:36 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
>
> I found out one more thing about context reference counts. If you
> decrement
>
> the count to zero while the context is still attached to an object,
you
> get
> an assertion error.
>
> So now I know that I have to keep the context ref count to a minimum
of 1
> all the time. This means I must not release the count added by the
> allocate
>
> routine.
>
> I sure hope that the context-cleanup routine is still called when the
> object
>
> it is linked to disappears and the ref count is 1.
>
> So my current strategy (really the only one left to me) is to not
release
> the reference from the allocate but dereference all others immediately

> after
>
> they are incremented by a FltSetXXX or FltGetXXX. This means the
context
> reference count is useless.
>
> It is tempting to just sprinkle my code with *(((ULONG) context)-1) =
1;
> everywhere as a test.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Mark,

Though not explicitly stated I believe it is implicitly stated. You do
one release for each get/alloc. If you do more then that bad things
will happen. Why would you assume that if you get it once you should be
able to release it twice?

Once a context it attached to an object (via set) the only way to detach
it is with a delete, either implicitly (when the attached object goes
away) or explicit. So the instruction pairs are:

  • allocate/get must be followed by a release
  • set must be followed by a delete (or implicit delete by the system)

I am glad you found your referencing issues. As I stated earlier we are
working on verifier functionality that will track everything you Get and
will tell you when you unload what you did not release.

Neal

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Thursday, March 31, 2005 4:54 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

The only rule you don’t mention is that you will get an assertion error
if
you try to reduce the ref count to zero while the context is still
attached
to an object. This means I can only do one dereference after calling
alloc
and attach. This leaves the ref count at one until the detach, even if
I
have no interest in the context anymore.

After turning on the verifier I was able to tell what was causing the
unload
problem. I’ve now fixed all my problems in that regard.

Thanks…

“Neal Christiansen” wrote in message
news:xxxxx@ntfsd…
Mark,

You have gone to a lot of work to figure out the following basic rules:

- Whenever you allocate/get a context you must at some point release it.
- Setting a context puts an internal residual count on the context which
keeps it from going away
- Deleting a context (either explicitly by calling one of the delete
context APIs or implicitly by the object it is attached to going away)
removes the residual count.
- The context cleanup routine is called once the reference count goes to
zero.

This means a deleted context will not go away until all references go
away. You should not maintain your own list of contexts just for the
purpose of deleting them at unload time. We do this for you
automatically and all you are doing is adding unnecessary overhead.

This referencing model in the filter manager works correctly and there
are no holes or problems which makes this unusable or incorrect.

It is by design that we don’t allow your filter to unload if you have
referenced objects laying around. If it does not unload it is because
you have some sort of reference counting bug.

Anytime you retrieve a filter manager object it is referenced. This
means you must do the appropriate unreference so the object can be
freed.

We will be working on verifier features that will track all of this
information so that at unload time we can tell you exactly what you have
done wrong.

If you are still having problems with this please send me the stack
backtrace of where you are hung. I want to know if it is hung unloading
an instance or unloading the filter.

Neal Christiansen
Microsoft File System Filter Group Lead
This posting is provided “AS IS” with no warranties, and confers no
Rights

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
Sent: Friday, March 25, 2005 5:00 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] sc stop is hanging

I ended up doing ASSERT( (((ULONG)context)-1) == 1 ); everywhere
(which is
much safer ) and I was able to figure out what the context ref
count
rules are:

1) If you try to dereference any context still attached to an object, to
a
count of zero, you get an assertion error from the filter manager.

2) When the object that the context is attached to dissapears, there is
a
single decrement of the ref count done by the filter manager. This also

happens when you manually detach a context from it’s object using
FltDeleteContext.

3) The context-cleanup gets called only when the ref count goes to zero.

Using the above bits of knowledge, I was able to come up with an
algorithm
that worked for me:

a) Never deref an allocate function. This leaves the ref count at one
which
is balanced by the auto-decrement done by the filter manager when an
object
disappears.

b) Always deref all fltmgr calls that increment the ref count after
finding
out the call was successful. Once again this keeps the ref count at 1.
(Actually I keep the reference held for the brief period that I’m using
it
after any call).

This method caused my contexts to have their ref count go to zero
whenever a
context is detached from an object, either automatically or manually.
This
caused context-cleanup to be called at that time for all objects.

So I am convinced that my code is not leaving any contexts hanging, but
I am
still getting the “sc stop” hangup. I’ll start a new thread on this.

“Ken Cross” wrote in message news:xxxxx@ntfsd…
> Help us understand your problem better.
>
> You’re talking about a stream context, right? I don’t think the
context
> cleanup gets called until everything’s done using it, i.e., the
reference
> count goes to zero. So I doubt if what you’re suggesting will work.
>
> Furthermore, it’s probably a Bad Idea to do things like
> "
(((ULONG)context)-1)=1;" because you don’t know what other parts of
the
> system (Filter Manager, file system, etc.) might be
> referencing/dereferencing the context without your knowledge. I don’t

> know
> that they do, but you should probably assume they do.
>
> Now, why can’t you release the context in post-cleanup?
>
> Ken
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Hahn
> Sent: Friday, March 25, 2005 5:36 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] sc stop is hanging
>
>
> I found out one more thing about context reference counts. If you
> decrement
>
> the count to zero while the context is still attached to an object,
you
> get
> an assertion error.
>
> So now I know that I have to keep the context ref count to a minimum
of 1
> all the time. This means I must not release the count added by the
> allocate
>
> routine.
>
> I sure hope that the context-cleanup routine is still called when the
> object
>
> it is linked to disappears and the ref count is 1.
>
> So my current strategy (really the only one left to me) is to not
release
> the reference from the allocate but dereference all others immediately

> after
>
> they are incremented by a FltSetXXX or FltGetXXX. This means the
context
> reference count is useless.
>
> It is tempting to just sprinkle my code with *(((ULONG) context)-1) =
1;
> everywhere as a test.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@comcast.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com