Hello Gurus
I have a question regarding fixing the critical code sections.
If we need to fix a segment of the code in the driver which should not be
interrupted by any Read/Writes happening in the system.
For example if i have a code like this in my Driver
//Enter the Secure Code Region
LONGLONG llOffset;
unsigned char szBytes[512];
ReadSector(Offset,szBytes);
ModifyData(szBytes);
WriteSector(Offset,szBytes);
//End of Secure Code Region
But Entering this code i shud not get any “other” IRP_MJ_WRITE so that i
make it problem free. This is because sometimes after the ReadSector is done
i get IRP_MJ_WRITE on that sector and when i do a ModifyData i am actually
using the incorrect Data (szBytes) because the Data at that sector is
changed. Is this possible?
Do we need to use critical sections?Could u guys guide me ?
Thanks
Shal
The only way to ensure that no other writes occur during this window is
for you to install a filter driver on the filesystem, volume or disk
(probably at whatever level you’re running this code) that queues the
write operations until you’ve finished what you’re doing.
-p
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Shalini
Sent: Friday, June 18, 2004 7:21 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Critical Code Sections
Hello Gurus
I have a question regarding fixing the critical code sections.
If we need to fix a segment of the code in the driver which should not
be interrupted by any Read/Writes happening in the system.
For example if i have a code like this in my Driver
//Enter the Secure Code Region
LONGLONG llOffset;
unsigned char szBytes[512];
ReadSector(Offset,szBytes);
ModifyData(szBytes);
WriteSector(Offset,szBytes);
//End of Secure Code Region
But Entering this code i shud not get any “other” IRP_MJ_WRITE so that
i make it problem free. This is because sometimes after the ReadSector
is done i get IRP_MJ_WRITE on that sector and when i do a ModifyData i
am actually using the incorrect Data (szBytes) because the Data at that
sector is changed. Is this possible?
Do we need to use critical sections?Could u guys guide me ?
Thanks
Shal
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
I dont think this is a good plan; you would have to be able to stall paged
reads and writes for system page files.
“Shalini” wrote in message news:xxxxx@ntdev…
> Hello Gurus
> I have a question regarding fixing the critical code sections.
> If we need to fix a segment of the code in the driver which should not be
> interrupted by any Read/Writes happening in the system.
>
> For example if i have a code like this in my Driver
>
> //Enter the Secure Code Region
> LONGLONG llOffset;
> unsigned char szBytes[512];
>
> ReadSector(Offset,szBytes);
> ModifyData(szBytes);
> WriteSector(Offset,szBytes);
>
> //End of Secure Code Region
>
>
> But Entering this code i shud not get any “other” IRP_MJ_WRITE so that i
> make it problem free. This is because sometimes after the ReadSector is
done
> i get IRP_MJ_WRITE on that sector and when i do a ModifyData i am actually
> using the incorrect Data (szBytes) because the Data at that sector is
> changed. Is this possible?
>
> Do we need to use critical sections?Could u guys guide me ?
>
> Thanks
> Shal
>
>
>
>
You can hold off paged operations briefly. If you in fact need to guarantee
that a specific disk sector is not modified while you perform a
read-modify-write operation, I don’t see much alternative, you are going to
lock the related sectors in some fashion, defering paging operations on
them, no matter at what level you perform the deferral. Certainly the
scsiport level, with its One Lock to Rule Them All approach to things, is
deferring operations willy-nilly.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Monday, June 21, 2004 5:48 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Critical Code Sections
I dont think this is a good plan; you would have to be able
to stall paged reads and writes for system page files.
“Shalini” wrote in message
> news:xxxxx@ntdev…
> > Hello Gurus
> > I have a question regarding fixing the critical code sections.
> > If we need to fix a segment of the code in the driver which
> should not
> > be interrupted by any Read/Writes happening in the system.
> >
> > For example if i have a code like this in my Driver
> >
> > //Enter the Secure Code Region
> > LONGLONG llOffset;
> > unsigned char szBytes[512];
> >
> > ReadSector(Offset,szBytes);
> > ModifyData(szBytes);
> > WriteSector(Offset,szBytes);
> >
> > //End of Secure Code Region
> >
> >
> > But Entering this code i shud not get any “other” IRP_MJ_WRITE so
> > that i make it problem free. This is because sometimes after the
> > ReadSector is
> done
> > i get IRP_MJ_WRITE on that sector and when i do a ModifyData i am
> > actually using the incorrect Data (szBytes) because the
> Data at that
> > sector is changed. Is this possible?
> >
> > Do we need to use critical sections?Could u guys guide me ?
> >
> > Thanks
> > Shal
> >
> >
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
Thanks a lot guys for ur suggestions guys…
I am going to try these out…
“Mark Roddy” wrote in message news:xxxxx@ntdev…
> You can hold off paged operations briefly. If you in fact need to
guarantee
> that a specific disk sector is not modified while you perform a
> read-modify-write operation, I don’t see much alternative, you are going
to
> lock the related sectors in some fashion, defering paging operations on
> them, no matter at what level you perform the deferral. Certainly the
> scsiport level, with its One Lock to Rule Them All approach to things, is
> deferring operations willy-nilly.
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
> > Sent: Monday, June 21, 2004 5:48 AM
> > To: Windows System Software Devs Interest List
> > Subject: Re:[ntdev] Critical Code Sections
> >
> > I dont think this is a good plan; you would have to be able
> > to stall paged reads and writes for system page files.
> >
> > “Shalini” wrote in message
> > news:xxxxx@ntdev…
> > > Hello Gurus
> > > I have a question regarding fixing the critical code sections.
> > > If we need to fix a segment of the code in the driver which
> > should not
> > > be interrupted by any Read/Writes happening in the system.
> > >
> > > For example if i have a code like this in my Driver
> > >
> > > //Enter the Secure Code Region
> > > LONGLONG llOffset;
> > > unsigned char szBytes[512];
> > >
> > > ReadSector(Offset,szBytes);
> > > ModifyData(szBytes);
> > > WriteSector(Offset,szBytes);
> > >
> > > //End of Secure Code Region
> > >
> > >
> > > But Entering this code i shud not get any “other” IRP_MJ_WRITE so
> > > that i make it problem free. This is because sometimes after the
> > > ReadSector is
> > done
> > > i get IRP_MJ_WRITE on that sector and when i do a ModifyData i am
> > > actually using the incorrect Data (szBytes) because the
> > Data at that
> > > sector is changed. Is this possible?
> > >
> > > Do we need to use critical sections?Could u guys guide me ?
> > >
> > > Thanks
> > > Shal
> > >
> > >
> > >
> > >
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@hollistech.com To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
>
>
>