From: RJ on
No, the below code is in Worker thread which is in PASSIVE LEVEL. Interrupt
routine
fills the buffer with data to be writen to file. Once buffer is full, the
worker thread is scheduled from DPC to write data to file.


"RJ" wrote:

> How can I make sure that NtWriteFile is complete?
>
> "RJ" wrote:
>
> > Here is my file create routine and file write routines. I make sure in the
> > interrupt routine that ZwWrite routine is completed. But seems it doesn't
> > mean than write operation is actually completed. I tried to use event object
> > to signal write complete as shown below. But this event object never set
> > into signaled state.
> > RJ
> >
> > status = ZwCreateFile(&(pDevExt->hFileHandle),
> > GENERIC_WRITE | SYNCHRONIZE,
> > &objAttrs,
> > &ioStatus,
> > 0,
> > FILE_ATTRIBUTE_NORMAL,
> > 0,
> > FILE_SUPERSEDE, FILE_SYNCHRONOUS_IO_ALERT,
> > NULL,
> > 0);
> >
> >
> > KeClearEvent(gpDevExt->pfileEvent);
> > status = ZwWriteFile( pDevExt->hFileHandle,
> > pDevExt->pfileEvent,
> > NULL,
> > NULL,
> > &ioStatus,
> > pucStartAddress,
> > ulNumBytes,
> > NULL,
> > NULL);
> >
> > KeWaitForSingleObject(pDevExt->pfileEvent,
> > Executive,
> > KernelMode,
> > FALSE,
> > NULL);
> >
> >
> >
> > "Skywing [MVP]" wrote:
> >
> > > Wait until either NtWriteFile returns or signals asynchronous completion.
> > > You cannot touch a buffer passed to NtReadFile/NtWriteFile while it is
> > > working on the operation.
> > >
> > > --
> > > Ken Johnson (Skywing)
> > > Windows SDK MVP
> > > http://www.nynaeve.net
> > >
> > > "RJ" <RJ(a)discussions.microsoft.com> wrote in message
> > > news:1E31915E-06C5-4721-8784-5ED892157540(a)microsoft.com...
> > > >I use ZwWriteFile function to write data from a buffer to a file in a
> > > >worker
> > > > thread. I would like to know when can I resue the input buffer again to
> > > > fill
> > > > new data. Buffer is filled in the interrupt/DPC and once the buffer is
> > > > filled, a worker thread is scheduled to write the data to file. My
> > > > interrupt
> > > > routine is trying to write new date to the buffer while NtWriteFile
> > > > routine
> > > > is still running. This creates a bugcheck.
> > > > Any help appreciated.
> > > > Thanks,
> > > > RJ
> > >
> > >
> > >
From: RJ on
Here is the stack and bug check information.
Fatal System Error: 0x00000050
(0xFEA24FFC,0x00000001,0xF4F9A1C4,0x00000000)


f8b3ff48 804f780d nt!RtlpBreakWithStatusInstruction
f8b3ff94 804f83fa nt!KiBugCheckDebugBreak+0x19
f8b40374 804f8925 nt!KeBugCheck2+0x574
f8b40394 8051bf07 nt!KeBugCheckEx+0x1b
f8b403f4 8053f6ec nt!MmAccessFault+0x8e7
f8b403f4 f4f9a1c4 nt!KiTrap0E+0xcc
f8b404b4 f4f9a5ec CAPROF!CaprofWriteRecord+0x1b2
[d:\work\cvs\cadrvr_bug\windows2.1\caisr.c @ 861]
f8b40518 f4f9ea4c CAPROF!CpuIntHandler+0x340
[d:\work\cvs\cadrvr_bug\windows2.1\caisr.c @ 287]
WARNING: Stack unwind information not available. Following frames may be
wrong.
f8b40580 f842c4e5 Ntfs+0x3a6b9
f8b405b8 f8421fb4 Ntfs+0x3a4e5
f8b405d8 f84230d8 Ntfs+0x2ffb4
f8b40650 f842326b Ntfs+0x310d8
f8b40790 f8422e52 Ntfs+0x3126b
f8b40860 f83f5dfa Ntfs+0x30e52
f8b40a64 f83f3c97 Ntfs+0x3dfa
f8b40ac8 804eddf9 Ntfs+0x1c97
f8b40bb8 80573b3a nt!IopfCallDriver+0x31
f8b40bcc 805716a2 nt!IopSynchronousServiceTail+0x60
f8b40c80 8053c808 nt!NtWriteFile+0x602


"soviet_bloke(a)hotmail.com" wrote:

> Hi mate
>
> Is it your ISR code????????
>
> You cannot call *ANY* of Zw... functions from ISR, and you cannot wait
> on synchronization objects either - at IRQL>=DISPATCH_LEVEL your
> choice is severely constrained. You have to re-design your problem -
> you cannot run the above code either as ISR or as DPC
>
> Anton Bassov
>
> RJ wrote:
> > Here is my file create routine and file write routines. I make sure in the
> > interrupt routine that ZwWrite routine is completed. But seems it doesn't
> > mean than write operation is actually completed. I tried to use event object
> > to signal write complete as shown below. But this event object never set
> > into signaled state.
> > RJ
> >
> > status = ZwCreateFile(&(pDevExt->hFileHandle),
> > GENERIC_WRITE | SYNCHRONIZE,
> > &objAttrs,
> > &ioStatus,
> > 0,
> > FILE_ATTRIBUTE_NORMAL,
> > 0,
> > FILE_SUPERSEDE, FILE_SYNCHRONOUS_IO_ALERT,
> > NULL,
> > 0);
> >
> >
> > KeClearEvent(gpDevExt->pfileEvent);
> > status = ZwWriteFile( pDevExt->hFileHandle,
> > pDevExt->pfileEvent,
> > NULL,
> > NULL,
> > &ioStatus,
> > pucStartAddress,
> > ulNumBytes,
> > NULL,
> > NULL);
> >
> > KeWaitForSingleObject(pDevExt->pfileEvent,
> > Executive,
> > KernelMode,
> > FALSE,
> > NULL);
> >
> >
> >
> > "Skywing [MVP]" wrote:
> >
> > > Wait until either NtWriteFile returns or signals asynchronous completion.
> > > You cannot touch a buffer passed to NtReadFile/NtWriteFile while it is
> > > working on the operation.
> > >
> > > --
> > > Ken Johnson (Skywing)
> > > Windows SDK MVP
> > > http://www.nynaeve.net
> > >
> > > "RJ" <RJ(a)discussions.microsoft.com> wrote in message
> > > news:1E31915E-06C5-4721-8784-5ED892157540(a)microsoft.com...
> > > >I use ZwWriteFile function to write data from a buffer to a file in a
> > > >worker
> > > > thread. I would like to know when can I resue the input buffer again to
> > > > fill
> > > > new data. Buffer is filled in the interrupt/DPC and once the buffer is
> > > > filled, a worker thread is scheduled to write the data to file. My
> > > > interrupt
> > > > routine is trying to write new date to the buffer while NtWriteFile
> > > > routine
> > > > is still running. This creates a bugcheck.
> > > > Any help appreciated.
> > > > Thanks,
> > > > RJ
> > >
> > >
> > >
>
>
From: soviet_bloke on
> How can I make sure that NtWriteFile is complete?

Well, in fact, you can do it simply like KeClearEvent() -ZwWriteFile()
- KeSetEvent() sequence in your worker thread and KeReadStateEvent() in
DPC - if event is not signalled, DPC does not write data to the buffer,
and that's it.

However, what happens if DPC needs to write data and event is not
signalled???? After all, it cannot wait, can it???
Therefore, it may well happen that you start losing data

In other words, no matter how you look at it, it just have to re-design
your problem


Anton Bassov




RJ wrote:
> How can I make sure that NtWriteFile is complete?
>
> "RJ" wrote:
>
> > Here is my file create routine and file write routines. I make sure in the
> > interrupt routine that ZwWrite routine is completed. But seems it doesn't
> > mean than write operation is actually completed. I tried to use event object
> > to signal write complete as shown below. But this event object never set
> > into signaled state.
> > RJ
> >
> > status = ZwCreateFile(&(pDevExt->hFileHandle),
> > GENERIC_WRITE | SYNCHRONIZE,
> > &objAttrs,
> > &ioStatus,
> > 0,
> > FILE_ATTRIBUTE_NORMAL,
> > 0,
> > FILE_SUPERSEDE, FILE_SYNCHRONOUS_IO_ALERT,
> > NULL,
> > 0);
> >
> >
> > KeClearEvent(gpDevExt->pfileEvent);
> > status = ZwWriteFile( pDevExt->hFileHandle,
> > pDevExt->pfileEvent,
> > NULL,
> > NULL,
> > &ioStatus,
> > pucStartAddress,
> > ulNumBytes,
> > NULL,
> > NULL);
> >
> > KeWaitForSingleObject(pDevExt->pfileEvent,
> > Executive,
> > KernelMode,
> > FALSE,
> > NULL);
> >
> >
> >
> > "Skywing [MVP]" wrote:
> >
> > > Wait until either NtWriteFile returns or signals asynchronous completion.
> > > You cannot touch a buffer passed to NtReadFile/NtWriteFile while it is
> > > working on the operation.
> > >
> > > --
> > > Ken Johnson (Skywing)
> > > Windows SDK MVP
> > > http://www.nynaeve.net
> > >
> > > "RJ" <RJ(a)discussions.microsoft.com> wrote in message
> > > news:1E31915E-06C5-4721-8784-5ED892157540(a)microsoft.com...
> > > >I use ZwWriteFile function to write data from a buffer to a file in a
> > > >worker
> > > > thread. I would like to know when can I resue the input buffer again to
> > > > fill
> > > > new data. Buffer is filled in the interrupt/DPC and once the buffer is
> > > > filled, a worker thread is scheduled to write the data to file. My
> > > > interrupt
> > > > routine is trying to write new date to the buffer while NtWriteFile
> > > > routine
> > > > is still running. This creates a bugcheck.
> > > > Any help appreciated.
> > > > Thanks,
> > > > RJ
> > >
> > >
> > >

From: RJ on
Is it possible that Zwwritefile is still using the buffer even if it returns.
I have set the
SYNCHRONIZE flag and I assume that once it returns OS is not using my
buffer any more.

"RJ" wrote:

> Here is the stack and bug check information.
> Fatal System Error: 0x00000050
> (0xFEA24FFC,0x00000001,0xF4F9A1C4,0x00000000)
>
>
> f8b3ff48 804f780d nt!RtlpBreakWithStatusInstruction
> f8b3ff94 804f83fa nt!KiBugCheckDebugBreak+0x19
> f8b40374 804f8925 nt!KeBugCheck2+0x574
> f8b40394 8051bf07 nt!KeBugCheckEx+0x1b
> f8b403f4 8053f6ec nt!MmAccessFault+0x8e7
> f8b403f4 f4f9a1c4 nt!KiTrap0E+0xcc
> f8b404b4 f4f9a5ec CAPROF!CaprofWriteRecord+0x1b2
> [d:\work\cvs\cadrvr_bug\windows2.1\caisr.c @ 861]
> f8b40518 f4f9ea4c CAPROF!CpuIntHandler+0x340
> [d:\work\cvs\cadrvr_bug\windows2.1\caisr.c @ 287]
> WARNING: Stack unwind information not available. Following frames may be
> wrong.
> f8b40580 f842c4e5 Ntfs+0x3a6b9
> f8b405b8 f8421fb4 Ntfs+0x3a4e5
> f8b405d8 f84230d8 Ntfs+0x2ffb4
> f8b40650 f842326b Ntfs+0x310d8
> f8b40790 f8422e52 Ntfs+0x3126b
> f8b40860 f83f5dfa Ntfs+0x30e52
> f8b40a64 f83f3c97 Ntfs+0x3dfa
> f8b40ac8 804eddf9 Ntfs+0x1c97
> f8b40bb8 80573b3a nt!IopfCallDriver+0x31
> f8b40bcc 805716a2 nt!IopSynchronousServiceTail+0x60
> f8b40c80 8053c808 nt!NtWriteFile+0x602
>
>
> "soviet_bloke(a)hotmail.com" wrote:
>
> > Hi mate
> >
> > Is it your ISR code????????
> >
> > You cannot call *ANY* of Zw... functions from ISR, and you cannot wait
> > on synchronization objects either - at IRQL>=DISPATCH_LEVEL your
> > choice is severely constrained. You have to re-design your problem -
> > you cannot run the above code either as ISR or as DPC
> >
> > Anton Bassov
> >
> > RJ wrote:
> > > Here is my file create routine and file write routines. I make sure in the
> > > interrupt routine that ZwWrite routine is completed. But seems it doesn't
> > > mean than write operation is actually completed. I tried to use event object
> > > to signal write complete as shown below. But this event object never set
> > > into signaled state.
> > > RJ
> > >
> > > status = ZwCreateFile(&(pDevExt->hFileHandle),
> > > GENERIC_WRITE | SYNCHRONIZE,
> > > &objAttrs,
> > > &ioStatus,
> > > 0,
> > > FILE_ATTRIBUTE_NORMAL,
> > > 0,
> > > FILE_SUPERSEDE, FILE_SYNCHRONOUS_IO_ALERT,
> > > NULL,
> > > 0);
> > >
> > >
> > > KeClearEvent(gpDevExt->pfileEvent);
> > > status = ZwWriteFile( pDevExt->hFileHandle,
> > > pDevExt->pfileEvent,
> > > NULL,
> > > NULL,
> > > &ioStatus,
> > > pucStartAddress,
> > > ulNumBytes,
> > > NULL,
> > > NULL);
> > >
> > > KeWaitForSingleObject(pDevExt->pfileEvent,
> > > Executive,
> > > KernelMode,
> > > FALSE,
> > > NULL);
> > >
> > >
> > >
> > > "Skywing [MVP]" wrote:
> > >
> > > > Wait until either NtWriteFile returns or signals asynchronous completion.
> > > > You cannot touch a buffer passed to NtReadFile/NtWriteFile while it is
> > > > working on the operation.
> > > >
> > > > --
> > > > Ken Johnson (Skywing)
> > > > Windows SDK MVP
> > > > http://www.nynaeve.net
> > > >
> > > > "RJ" <RJ(a)discussions.microsoft.com> wrote in message
> > > > news:1E31915E-06C5-4721-8784-5ED892157540(a)microsoft.com...
> > > > >I use ZwWriteFile function to write data from a buffer to a file in a
> > > > >worker
> > > > > thread. I would like to know when can I resue the input buffer again to
> > > > > fill
> > > > > new data. Buffer is filled in the interrupt/DPC and once the buffer is
> > > > > filled, a worker thread is scheduled to write the data to file. My
> > > > > interrupt
> > > > > routine is trying to write new date to the buffer while NtWriteFile
> > > > > routine
> > > > > is still running. This creates a bugcheck.
> > > > > Any help appreciated.
> > > > > Thanks,
> > > > > RJ
> > > >
> > > >
> > > >
> >
> >