Hello,
Independent if it is against rules and prescriptions , but to understand the principes : can I reliably use the next assembler
statement on any type of Multiprocessor / Multithread systems ( Intel / AMD ) :
lock cmpxchg ecx, ebx, eax
Also , can it be reliabley used within a driver AND a ring 3 application when the destination ( ebx ) points to the same physical
memory location ?
Don’t shoot me down when I am digging up and old death cow now.
Christiaan
It can be used reliably within a driver and an app as long as there physical
memory is addresable to both. Note you do not need assembler for this, but
user and kernel have InterlockedCompareExchange(…) as a function that
becomes the instruction you are looking at.
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
“Christiaan Ghijselinck” wrote in
message news:xxxxx@ntdev…
>
> Hello,
>
> Independent if it is against rules and prescriptions , but to understand
the principes : can I reliably use the next assembler
> statement on any type of Multiprocessor / Multithread systems ( Intel /
AMD ) :
>
> lock cmpxchg ecx, ebx, eax
>
> Also , can it be reliabley used within a driver AND a ring 3 application
when the destination ( ebx ) points to the same physical
> memory location ?
>
> Don’t shoot me down when I am digging up and old death cow now.
>
> Christiaan
>
>
Why not call InterlockedCompareExchange, which will do the same reliably?
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “Christiaan Ghijselinck”
To: “Windows System Software Devs Interest List”
Sent: Monday, May 31, 2004 5:21 PM
Subject: [ntdev] A simple question about an assembler instruction
>
> Hello,
>
> Independent if it is against rules and prescriptions , but to understand the
principes : can I reliably use the next assembler
> statement on any type of Multiprocessor / Multithread systems ( Intel / AMD )
:
>
> lock cmpxchg ecx, ebx, eax
>
> Also , can it be reliabley used within a driver AND a ring 3 application
when the destination ( ebx ) points to the same physical
> memory location ?
>
> Don’t shoot me down when I am digging up and old death cow now.
>
> Christiaan
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
Yes I know, but I just want to highlight the principle, also when I use it in a user application
for the same physical address ( InterlockedCompareExchange is not meant for user App’s ).
----- Original Message -----
From: “Maxim S. Shatskih”
To: “Windows System Software Devs Interest List”
Sent: Monday, May 31, 2004 3:43 PM
Subject: Re: [ntdev] A simple question about an assembler instruction
> Why not call InterlockedCompareExchange, which will do the same reliably?
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> ----- Original Message -----
> From: “Christiaan Ghijselinck”
> To: “Windows System Software Devs Interest List”
> Sent: Monday, May 31, 2004 5:21 PM
> Subject: [ntdev] A simple question about an assembler instruction
>
>
> >
> > Hello,
> >
> > Independent if it is against rules and prescriptions , but to understand the
> principes : can I reliably use the next assembler
> > statement on any type of Multiprocessor / Multithread systems ( Intel / AMD )
> :
> >
> > lock cmpxchg ecx, ebx, eax
> >
> > Also , can it be reliabley used within a driver AND a ring 3 application
> when the destination ( ebx ) points to the same physical
> > memory location ?
> >
> > Don’t shoot me down when I am digging up and old death cow now.
> >
> > Christiaan
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
Actually, it is in the SDK as well as the DDK so it is definitely meant for
user apps!
–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
“Christiaan Ghijselinck” wrote in
message news:xxxxx@ntdev…
>
> Yes I know, but I just want to highlight the principle, also when I use
it in a user application
> for the same physical address ( InterlockedCompareExchange is not meant
for user App’s ).
>
Well at least it is documented in the Platform SDK. Which implies you
can use it in user apps.
Mat
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Christiaan
Ghijselinck
Sent: Monday, May 31, 2004 9:54 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] A simple question about an assembler instruction
Yes I know, but I just want to highlight the principle, also when I use
it in a user application
for the same physical address ( InterlockedCompareExchange is not meant
for user App’s ).
----- Original Message -----
From: “Maxim S. Shatskih”
To: “Windows System Software Devs Interest List”
Sent: Monday, May 31, 2004 3:43 PM
Subject: Re: [ntdev] A simple question about an assembler instruction
> Why not call InterlockedCompareExchange, which will do the same
reliably?
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> ----- Original Message -----
> From: “Christiaan Ghijselinck”
> To: “Windows System Software Devs Interest List”
> Sent: Monday, May 31, 2004 5:21 PM
> Subject: [ntdev] A simple question about an assembler instruction
>
>
> >
> > Hello,
> >
> > Independent if it is against rules and prescriptions , but to
understand the
> principes : can I reliably use the next assembler
> > statement on any type of Multiprocessor / Multithread systems (
Intel / AMD )
> :
> >
> > lock cmpxchg ecx, ebx, eax
> >
> > Also , can it be reliabley used within a driver AND a ring 3
application
> when the destination ( ebx ) points to the same physical
> > memory location ?
> >
> > Don’t shoot me down when I am digging up and old death cow now.
> >
> > Christiaan
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > To unsubscribe send a blank email to
xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@cvds.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Why not? The function is documented in Platform SDK.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “Christiaan Ghijselinck”
To: “Windows System Software Devs Interest List”
Sent: Monday, May 31, 2004 5:53 PM
Subject: Re: [ntdev] A simple question about an assembler instruction
>
> Yes I know, but I just want to highlight the principle, also when I use it
in a user application
> for the same physical address ( InterlockedCompareExchange is not meant for
user App’s ).
>
>
>
> ----- Original Message -----
> From: “Maxim S. Shatskih”
> To: “Windows System Software Devs Interest List”
> Sent: Monday, May 31, 2004 3:43 PM
> Subject: Re: [ntdev] A simple question about an assembler instruction
>
>
> > Why not call InterlockedCompareExchange, which will do the same
reliably?
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> >
> > ----- Original Message -----
> > From: “Christiaan Ghijselinck”
> > To: “Windows System Software Devs Interest List”
> > Sent: Monday, May 31, 2004 5:21 PM
> > Subject: [ntdev] A simple question about an assembler instruction
> >
> >
> > >
> > > Hello,
> > >
> > > Independent if it is against rules and prescriptions , but to understand
the
> > principes : can I reliably use the next assembler
> > > statement on any type of Multiprocessor / Multithread systems ( Intel /
AMD )
> > :
> > >
> > > lock cmpxchg ecx, ebx, eax
> > >
> > > Also , can it be reliabley used within a driver AND a ring 3 application
> > when the destination ( ebx ) points to the same physical
> > > memory location ?
> > >
> > > Don’t shoot me down when I am digging up and old death cow now.
> > >
> > > Christiaan
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
xxxxx@compaqnet.be
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
Ok, many thanks to all that replied to my question 
----- Original Message -----
From: “Maxim S. Shatskih”
To: “Windows System Software Devs Interest List”
Sent: Monday, May 31, 2004 4:11 PM
Subject: Re: [ntdev] A simple question about an assembler instruction
> Why not? The function is documented in Platform SDK.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> ----- Original Message -----
> From: “Christiaan Ghijselinck”
> To: “Windows System Software Devs Interest List”
> Sent: Monday, May 31, 2004 5:53 PM
> Subject: Re: [ntdev] A simple question about an assembler instruction
>
>
> >
> > Yes I know, but I just want to highlight the principle, also when I use it
> in a user application
> > for the same physical address ( InterlockedCompareExchange is not meant for
> user App’s ).
> >
> >
> >
> > ----- Original Message -----
> > From: “Maxim S. Shatskih”
> > To: “Windows System Software Devs Interest List”
> > Sent: Monday, May 31, 2004 3:43 PM
> > Subject: Re: [ntdev] A simple question about an assembler instruction
> >
> >
> > > Why not call InterlockedCompareExchange, which will do the same
> reliably?
> > >
> > > Maxim Shatskih, Windows DDK MVP
> > > StorageCraft Corporation
> > > xxxxx@storagecraft.com
> > > http://www.storagecraft.com
> > >
> > >
> > > ----- Original Message -----
> > > From: “Christiaan Ghijselinck”
> > > To: “Windows System Software Devs Interest List”
> > > Sent: Monday, May 31, 2004 5:21 PM
> > > Subject: [ntdev] A simple question about an assembler instruction
> > >
> > >
> > > >
> > > > Hello,
> > > >
> > > > Independent if it is against rules and prescriptions , but to understand
> the
> > > principes : can I reliably use the next assembler
> > > > statement on any type of Multiprocessor / Multithread systems ( Intel /
> AMD )
> > > :
> > > >
> > > > lock cmpxchg ecx, ebx, eax
> > > >
> > > > Also , can it be reliabley used within a driver AND a ring 3 application
> > > when the destination ( ebx ) points to the same physical
> > > > memory location ?
> > > >
> > > > Don’t shoot me down when I am digging up and old death cow now.
> > > >
> > > > Christiaan
> > > >
> > > >
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > > > To unsubscribe send a blank email to xxxxx@lists.osr.com
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as:
> xxxxx@compaqnet.be
> > > To unsubscribe send a blank email to xxxxx@lists.osr.com
> > >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@compaqnet.be
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> Well at least it is documented in the Platform SDK. Which implies you
can use it in user apps.
I believe there was a time that it wasn’t. But it certainly is now, along
with a number of friends that do similar things.
One thing about cmpxchg8b, nad therefore InterlockedExchange, or any
instruction that uses the Lock prefix - there are machines out there that
will effectively only lock on word boundaries, and will NOT lock if an
operand splits across two words/cache lines. Therefore, make sure that you
ALWAYS use locked instructions on their natural boundaries. If you don’t,
the machine may generate a fault, or may just not do any/some of the lock.
Loren
> ----------
From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Loren Wilton[SMTP:xxxxx@earthlink.net]
Reply To: Windows System Software Devs Interest List
Sent: Monday, May 31, 2004 8:35 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] A simple question about an assembler instruction
> Well at least it is documented in the Platform SDK. Which implies you
> can use it in user apps.
I believe there was a time that it wasn’t. But it certainly is now, along
with a number of friends that do similar things.
Currently they are even supported as compiler intrinsic functions (_InterlockedXxx; note leading underscore).
Best regards,
Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]