From: RJ on
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: Skywing [MVP] on
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 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
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: soviet_bloke on
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
> >
> >
> >