Hi

I have a simple function that logs information in my driver.
Most of the implementation is ZwWriteFile that is synchronize by a
kernel mutex (i use MUTEX_ACQUIRE( LogMutex ) and alike).

I have a DbgPrints befoer & after the mutex, and inside the code.
For some reason, it seems that sometims there are 2 threads in the code
section that supposed to be synchronized.. also, i somtimes get a BSOD
from ZwWriteFile and i think this is the reason.

Any idea why the mutex isn't working ?

Thanks.

Re: Urgent - Mutex does not lock by Alexander

Alexander
Wed Aug 03 08:31:22 CDT 2005

Don't try to call ZwWriteFile and any mutex acquire functins on IRQL >
APC_LEVEL.

You also don't need a mutex if you open the file in APPEND mode.

"Omer" <Omerb99@gmail.com> wrote in message
news:1123073129.787223.152380@g47g2000cwa.googlegroups.com...
> Hi
>
> I have a simple function that logs information in my driver.
> Most of the implementation is ZwWriteFile that is synchronize by a
> kernel mutex (i use MUTEX_ACQUIRE( LogMutex ) and alike).
>
> I have a DbgPrints befoer & after the mutex, and inside the code.
> For some reason, it seems that sometims there are 2 threads in the code
> section that supposed to be synchronized.. also, i somtimes get a BSOD
> from ZwWriteFile and i think this is the reason.
>
> Any idea why the mutex isn't working ?
>
> Thanks.
>



Re: Urgent - Mutex does not lock by Maxim

Maxim
Wed Aug 03 08:41:40 CDT 2005

> You also don't need a mutex if you open the file in APPEND mode.

Not necessary. Any synchronous file object a) has internal mutex to serialize
writes b) always updates CurrentByteOffset to be the end of the last IO c)
always starts the write at CurrentByteOffset.

So, opening a synchronous file for writing and seeking to its end after open is
enough for logging.

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



Re: Urgent - Mutex does not lock by Omer

Omer
Wed Aug 03 09:44:00 CDT 2005

You said "Not necessary" and then you said "has internal mutex to
serialize
writes"
So, is there a way i can open a file for logging without a mutex or not
?

>So, opening a synchronous file for writing and seeking to its end after open is
>enough for logging.

why do i need to seek to its end if the file has an internal pointer ?


Re: Urgent - Mutex does not lock by Maxim

Maxim
Wed Aug 03 10:55:07 CDT 2005

> So, is there a way i can open a file for logging without a mutex or not

No need in mutex. Each WriteFile to synchronous file is atomic.

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



Re: Urgent - Mutex does not lock by GustavoScotti

GustavoScotti
Wed Aug 03 15:55:02 CDT 2005

My 2 cents:

Most Zw* file function must be at PASSIVE_LEVEL. Anything higher than that
will fail (most of your attempts will BSOD). Be careful when you acquire an
irql with functions like Ke(Acquire|Release)SpinLock.

--
Axur Information Security - www.axur.com.br


"Maxim S. Shatskih" wrote:

> > So, is there a way i can open a file for logging without a mutex or not
>
> No need in mutex. Each WriteFile to synchronous file is atomic.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>
>

Re: Urgent - Mutex does not lock by Alexander

Alexander
Wed Aug 03 23:07:00 CDT 2005

It's correct. APPEND is only necessary for appending from separate file
objects.

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:uMOuNEDmFHA.2444@tk2msftngp13.phx.gbl...
>> You also don't need a mutex if you open the file in APPEND mode.
>
> Not necessary. Any synchronous file object a) has internal mutex to
> serialize
> writes b) always updates CurrentByteOffset to be the end of the last IO c)
> always starts the write at CurrentByteOffset.
>
> So, opening a synchronous file for writing and seeking to its end after
> open is
> enough for logging.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: Urgent - Mutex does not lock by Maxim

Maxim
Thu Aug 04 14:05:24 CDT 2005

Yes, APPEND only means - "automatic lseek to the end just before any IO,
applied with the file mutex held".

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

"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:e%23AC5nKmFHA.2472@TK2MSFTNGP15.phx.gbl...
> It's correct. APPEND is only necessary for appending from separate file
> objects.
>
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> news:uMOuNEDmFHA.2444@tk2msftngp13.phx.gbl...
> >> You also don't need a mutex if you open the file in APPEND mode.
> >
> > Not necessary. Any synchronous file object a) has internal mutex to
> > serialize
> > writes b) always updates CurrentByteOffset to be the end of the last IO c)
> > always starts the write at CurrentByteOffset.
> >
> > So, opening a synchronous file for writing and seeking to its end after
> > open is
> > enough for logging.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim@storagecraft.com
> > http://www.storagecraft.com
> >
> >
>
>



Re: Urgent - Mutex does not lock by Pavel

Pavel
Thu Aug 04 19:35:27 CDT 2005

I got a terrible suspicion... is it possible to buy the sources on the Gorbushka market?
<g>
--PA

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message news:uMOuNEDmFHA.2444@tk2msftngp13.phx.gbl...
> Not necessary. Any synchronous file object a) has internal mutex to serialize
> writes b) always updates CurrentByteOffset to be the end of the last IO c)
> always starts the write at CurrentByteOffset.
>
> So, opening a synchronous file for writing and seeking to its end after open is
> enough for logging.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: Urgent - Mutex does not lock by Maxim

Maxim
Thu Aug 04 21:36:58 CDT 2005

No, not yet :) it is possible to reverse-engineer IoCompleteRequest though.

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

"Pavel A." <pavel_a@NOwritemeNO.com> wrote in message
news:%23cbRaWVmFHA.3552@TK2MSFTNGP10.phx.gbl...
> I got a terrible suspicion... is it possible to buy the sources on the
Gorbushka market?
> <g>
> --PA
>
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:uMOuNEDmFHA.2444@tk2msftngp13.phx.gbl...
> > Not necessary. Any synchronous file object a) has internal mutex to
serialize
> > writes b) always updates CurrentByteOffset to be the end of the last IO c)
> > always starts the write at CurrentByteOffset.
> >
> > So, opening a synchronous file for writing and seeking to its end after
open is
> > enough for logging.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim@storagecraft.com
> > http://www.storagecraft.com
> >
> >
>
>