locks

i have a basic doubt.

i have a global pwchar variable in my driver that is being populated by an
IOCTL to the driver.

to reduce performance impact while using spinlocks, I copy the IOCTL buffer
to a kernel mode pointer (after allocating memory) and then when everything
is done, i acquire a spinlcok for the global variable, delete teh plast
pointer pointer, and then make the global var point to the new one. then
release the lock.

this is fine.

but my doubt is, if i am going to read the contents of this variable in any
of my driver dispatcher threads, and do some operations like string
comparisons using this variable, then do i need to take th lock again or
not? i am not going to modify the contents here, just read them.

bedanto

Your driver takes the address from the global pointer and passes it to the string compare routine. Another processor runs your IOCtl to change that pointer, free the old memory, and BSOD if the timing is right. If the pointer is not atomic in all aspects with regards to the spinlock, you must keep holding the spinlock until the pointer is no longer being used or going to be used again without reacquiring the spinlock and the pointer from the global data item. Also don’t forget that is could be possible for your IOCtl routine to be running on multiple processors at the same time and all of them trying to update that global data pointer.
“Bedanto” wrote in message news:xxxxx@ntfsd…
i have a basic doubt.

i have a global pwchar variable in my driver that is being populated by an IOCTL to the driver.

to reduce performance impact while using spinlocks, I copy the IOCTL buffer to a kernel mode pointer (after allocating memory) and then when everything is done, i acquire a spinlcok for the global variable, delete teh plast pointer pointer, and then make the global var point to the new one. then release the lock.

this is fine.

but my doubt is, if i am going to read the contents of this variable in any of my driver dispatcher threads, and do some operations like string comparisons using this variable, then do i need to take th lock again or not? i am not going to modify the contents here, just read them.

bedanto

> to reduce performance impact while using spinlocks, I copy the IOCTL buffer

to a kernel mode pointer (after allocating memory)

All of this is done for you automatically by the kernel if the IOCTL is
METHOD_BUFFERED. The buffer is at Irp->AssociatedIrp.SystemBuffer.

but my doubt is, if i am going to read the contents of this variable in any
of my driver dispatcher threads, and do some operations like string
comparisons using this variable, then do i need to take th lock again or
not? i am not going to modify the contents here, just read them.

Yes you need.

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

Use resource for it. Acquire resource shared when need to read the buffer,
acquire it exclusively if you need to modify it.

L.