Tech Support > Microsoft Windows > Drivers > How to distinguish stack frame from dataseg?
How to distinguish stack frame from dataseg?
Posted by Duh Pohmelja on August 1st, 2003


Hi, All!

Suppose I want to check, for testing purposes, if the object was
created statically or allocated on the stack (say in the thread
function). How to do this?

For example:

struct SomeStruct
{
// shareable data.
// ...

// lock
KSPINLOCK lock;
};

BOOL InitSomeStruct(SomeStruct& someStruct)
{
ASSERT_STATICALLY_ALLOCATED(someStruct);

KeInititalizeSpinLock(&someStruct.lock);
}

I want ASSERT_STATICALLY_ALLOCATED macro not to ASSERT when someStruct
is allocated on the dataseg and ASSERT, when it is allocated on the
stack (i.e. not accessible from other threads).


Posted by Nick Ryan on August 1st, 2003


Call IoGetStackLimits() and check if the struct address is between the
two returned values.

Duh Pohmelja wrote:

--
- Nick Ryan (MVP for DDK)