Can I have a KDPC object on the stack? When can I destroy or alter a KDPC?

AMD's CodeXL driver implements DPCs by declaring a local KDPC variable,
initializing it, queueing it, creating an event, and waiting for the deferred
routine to post to the event. The data passed to the deferred routine is also
in a local variable.
I assume this is safe, because AMD's product is out there. But it doesn't
follow the documented requirement that it be in a device/controller extension or
somewhere allocated from a nonpaged pool.
Is the kernel stack in nonpaged memory, too?
I made the mistake recently of creating my KDPC on the stack, but not waiting
for the deferred routine to finish, so that the KDPC would have quickly been
overwritten. This resulted in a bugcheck. So I'm putting my KDPC in the device
extension.
But that raises the question of reusing the KDPC, and synchronizing usage
between threads. Assuming that I've handled the issue of access by different
threads, I need to know how long a thread that is using the KDPC needs hold onto
it, after queueing it.
Even when the device is only being used by one user File, there may be multiple
IRPs coming from different user threads at the same time.

Message 2 of 6

12 Feb 18 01:36

Tim Roberts

xxxxxx@probo.com

Join Date: 28 Jan 2005

Posts To This List: 11800

Can I have a KDPC object on the stack? When can I destroy or alter a KDPC?

On Feb 11, 2018, at 10:00 PM, xxxxx@rolle.name wrote:
>
> AMD's CodeXL driver implements DPCs by declaring a local KDPC variable,
initializing it, queueing it, creating an event, and waiting for the deferred
routine to post to the event. The data passed to the deferred routine is also
in a local variable.
>
> I assume this is safe, because AMD's product is out there. But it doesn't
follow the documented requirement that it be in a device/controller extension or
somewhere allocated from a nonpaged pool.
>
> Is the kernel stack in nonpaged memory, too?
As long as the thread is running, or in a "kernel mode" wait, the stack is
locked into memory. The kernel stack can only be paged out if you do a wait
that specifies "user mode".
???
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Message 3 of 6

17 Feb 18 13:09

matt sykes

xxxxxx@hotmail.com

Join Date:

Posts To This List: 208

Can I have a KDPC object on the stack? When can I destroy or alter a KDPC?

If the KDPC is on the stack it gets destroyed when the function exits. Trying
to access it after wards is a recipe for disaster.
Just wait for the DPC routine to finish.

Message 4 of 6

20 Feb 18 12:19

Peter Viscarola (OSR)

xxxxxx@osr.com

Join Date:

Posts To This List: 5989

List Moderator

Can I have a KDPC object on the stack? When can I destroy or alter a KDPC?

Just wait for the DPC routine to finish.
Just don't put the DPC object on the stack! Kinda of a dumb practice.
Peter
OSR
@OSRDrivers

Message 5 of 6

Yesterday 10:10

matt sykes

xxxxxx@hotmail.com

Join Date:

Posts To This List: 208

Can I have a KDPC object on the stack? When can I destroy or alter a KDPC?

Why tell me Peter? I am quite aware of that. Why not tell the OP?

Message 6 of 6

Yesterday 17:01

Peter Viscarola (OSR)

xxxxxx@osr.com

Join Date:

Posts To This List: 5989

List Moderator

Can I have a KDPC object on the stack? When can I destroy or alter a KDPC?

>Why tell me Peter?
I wasn't speaking directly to you, Mr. Sykes. I was simply adding a "better
alternative" to waiting for the DPC routine to finish.
Turns out, ANYbody can read the threads on this forum.
Peter
OSR
@OSRDrivers

Posting Rules

You may not post new threads

You may not post replies

You may not post attachments

You must login to OSR Online AND be a member of the ntdev list to be able to post.