PsGetCurrentThreadId - alternative for WDM?

I’m looking for a way to do something like:

if( current thread == my worker thread )
foo();
else
bar();

The driver I’m writing uses the WDM headers & libs, and
PsGetCurrentThreadId() doesn’t show up in the headers, nor does it link
when I copy the declaration from the w2k headers. Can I safely use the
result-value of KeGetCurrentThread() to test if it’s the same thread? Or
is there an even simpler way?
It’s mainly for testing/debugging and making the code better readable (by
putting things like “ASSERT( IsWorkerThread() );” or similar into
functions that may only be called from the worker-thread etc.).

Thanks,
Paul

If your worker thread is persistent thru-out the session, I dont see
problem.

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@tab.at
Sent: Thursday, September 23, 2004 8:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] PsGetCurrentThreadId - alternative for WDM?

I’m looking for a way to do something like:

if( current thread == my worker thread )
foo();
else
bar();

The driver I’m writing uses the WDM headers & libs, and
PsGetCurrentThreadId() doesn’t show up in the headers, nor does it link
when I copy the declaration from the w2k headers. Can I safely use the
result-value of KeGetCurrentThread() to test if it’s the same thread? Or
is there an even simpler way?
It’s mainly for testing/debugging and making the code better readable (by
putting things like “ASSERT( IsWorkerThread() );” or similar into
functions that may only be called from the worker-thread etc.).

Thanks,
Paul


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

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

Did not see the problem, as usual. You must be talking about the return
opaque ptr,
that might not be unique due to teb is mapping, not sure. But there are
other API.
Something might be wrong in your linking process. I know it links on win2k.
And it is
exported from ntoskrnl ( x nt!Ps* )

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:07 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

If your worker thread is persistent thru-out the session, I dont see
problem.

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@tab.at
Sent: Thursday, September 23, 2004 8:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] PsGetCurrentThreadId - alternative for WDM?

I’m looking for a way to do something like:

if( current thread == my worker thread )
foo();
else
bar();

The driver I’m writing uses the WDM headers & libs, and
PsGetCurrentThreadId() doesn’t show up in the headers, nor does it link
when I copy the declaration from the w2k headers. Can I safely use the
result-value of KeGetCurrentThread() to test if it’s the same thread? Or
is there an even simpler way?
It’s mainly for testing/debugging and making the code better readable (by
putting things like “ASSERT( IsWorkerThread() );” or similar into
functions that may only be called from the worker-thread etc.).

Thanks,
Paul


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

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


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

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

Also, as long a this compare is not run in a DPC / ISR / completion
routine, you are OK. All of this can occur on top of your worker thread
at higher IRQL.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:17 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

Did not see the problem, as usual. You must be talking about the return
opaque ptr,
that might not be unique due to teb is mapping, not sure. But there are
other API.
Something might be wrong in your linking process. I know it links on
win2k.
And it is
exported from ntoskrnl ( x nt!Ps* )

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:07 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

If your worker thread is persistent thru-out the session, I dont see
problem.

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@tab.at
Sent: Thursday, September 23, 2004 8:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] PsGetCurrentThreadId - alternative for WDM?

I’m looking for a way to do something like:

if( current thread == my worker thread )
foo();
else
bar();

The driver I’m writing uses the WDM headers & libs, and
PsGetCurrentThreadId() doesn’t show up in the headers, nor does it link
when I copy the declaration from the w2k headers. Can I safely use the
result-value of KeGetCurrentThread() to test if it’s the same thread? Or
is there an even simpler way?
It’s mainly for testing/debugging and making the code better readable
(by
putting things like “ASSERT( IsWorkerThread() );” or similar into
functions that may only be called from the worker-thread etc.).

Thanks,
Paul


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

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


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

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


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

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

Sorry again … getting back from a sever sinus infection is tough :slight_smile:

I’m not sure it is allowed or not, but a sure approach is to take the
prototype from ntddk.h, as you did, and in your src file using extern you
should be able to link this function …

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:17 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

Did not see the problem, as usual. You must be talking about the return
opaque ptr,
that might not be unique due to teb is mapping, not sure. But there are
other API.
Something might be wrong in your linking process. I know it links on win2k.
And it is
exported from ntoskrnl ( x nt!Ps* )

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:07 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

If your worker thread is persistent thru-out the session, I dont see
problem.

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@tab.at
Sent: Thursday, September 23, 2004 8:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] PsGetCurrentThreadId - alternative for WDM?

I’m looking for a way to do something like:

if( current thread == my worker thread )
foo();
else
bar();

The driver I’m writing uses the WDM headers & libs, and
PsGetCurrentThreadId() doesn’t show up in the headers, nor does it link
when I copy the declaration from the w2k headers. Can I safely use the
result-value of KeGetCurrentThread() to test if it’s the same thread? Or
is there an even simpler way?
It’s mainly for testing/debugging and making the code better readable (by
putting things like “ASSERT( IsWorkerThread() );” or similar into
functions that may only be called from the worker-thread etc.).

Thanks,
Paul


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

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


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

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


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

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

So. I’ve done some grep on the DDK directory - seems like
PsGetCurrentThreadId() is exported from ntoskrnl.lib, randlibk.lib and
wdmsec.lib. So I’m now linking to ntoskrnl.lib too - should be OK I think.
Compiles fine now.
And yes, the functions where I’ll use this will only be called from some
thread without DPC, ISR or completion-routine.

Thanks to both of you!

Paul Groke

“Doron Holan”
Gesendet von: xxxxx@lists.osr.com
23.09.2004 18:25
Bitte antworten an “Windows System Software Devs Interest List”

An: “Windows System Software Devs Interest List”

Kopie:
Thema: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

Also, as long a this compare is not run in a DPC / ISR / completion
routine, you are OK. All of this can occur on top of your worker thread
at higher IRQL.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:17 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

Did not see the problem, as usual. You must be talking about the return
opaque ptr,
that might not be unique due to teb is mapping, not sure. But there are
other API.
Something might be wrong in your linking process. I know it links on
win2k.
And it is
exported from ntoskrnl ( x nt!Ps* )

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Prokash Sinha
Sent: Thursday, September 23, 2004 9:07 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] PsGetCurrentThreadId - alternative for WDM?

If your worker thread is persistent thru-out the session, I dont see
problem.

-pro

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@tab.at
Sent: Thursday, September 23, 2004 8:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] PsGetCurrentThreadId - alternative for WDM?

I’m looking for a way to do something like:

if( current thread == my worker thread )
foo();
else
bar();

The driver I’m writing uses the WDM headers & libs, and
PsGetCurrentThreadId() doesn’t show up in the headers, nor does it link
when I copy the declaration from the w2k headers. Can I safely use the
result-value of KeGetCurrentThread() to test if it’s the same thread? Or
is there an even simpler way?
It’s mainly for testing/debugging and making the code better readable
(by
putting things like “ASSERT( IsWorkerThread() );” or similar into
functions that may only be called from the worker-thread etc.).

Thanks,
Paul


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

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


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

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


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

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


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

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

Please visit us: www.tab.at www.championsnet.net
www.silverball.com