- You could also patch the import tables of drivers that import from the
kernel. - Or you could make a copy of the 4K page that contains the code to be
patched and the update the page tables for this virtual address to point to
your new page with a single atomic write and update of the CPU caches.
There’s also the problem of write protection into driver code segments on
W2K/WXP. Since you need to get around this somehow you’ll find 2) a good way
to do this.
Klaus
-----Urspr?ngliche Nachricht-----
Von: xxxxx@3Dlabs.com [mailto:xxxxx@3Dlabs.com]
Gesendet: Mittwoch, 14. Januar 2004 11:01
An: Windows System Software Devs Interest List
Betreff: RE: [ntdev] global kernel lock
Ok, so here’s ONE idea.
Read 8 bytes at the address you’re modifying, using an MMX register. Then
write mask out the first 5 bytes, and modify. Then store the value.
Using an MMX register should make it a “singe write operation”. If the
address is aligned to 8 bytes it should not be a problem to make the bus
transaction atomic. If the address isn’t aligned to 8 bytes, there’s little
you can do about it.
Note of course that you need to save FPU contents using the
“KeSaveFloatingPointState” and restore again with
“KeRestoreFloatingPointState”.
–
Mats
-----Original Message-----
From: xxxxx@sonydadc.com [mailto:xxxxx@sonydadc.com]
Sent: Wednesday, January 14, 2004 7:45 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] global kernel lock
Mats,
Thanks for your reply.
Sorry to have to ask, but: Why?
Unless you’re building a debugger or some such, there’s really no valid
case for “Must not be interrrupt by another thread”. There’s probably
something wrong in your design if “must” >do this. You should ever only need
to block threads that are accessing the same data as your own thread.
With the debugger you are not far away from the truth. I want to hook kernel
API functions, by overwriting the 1st 5 byte of the hooked function with a
“jmp xxx”. And as such a jmp instructions is 5 byte long, it can not be
written within one intruction. (My 1st idea was simply using a lock prefix )
So I need to prevent others from calling the API function during Iam writing
the “jmp xxx”.
(In the old WIn9x days I could simply use a kernel service hook, and I did
not find a similar solution for 2K, XP)
However, if you really want to do BAD design in your driver, a
KeRaiseIRQL() call with sufficently high IRQL will do the job. Obviously
followed by KeLowerIRQL(oldIRQL). [ OldIRQL is >passed back from the Raise
function]
It’s EXTREMELY bad practice to do this, however.
>You should never do this in a production driver.
Best Regards
Michael — Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: xxxxx@3dlabs.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@ati.com
To unsubscribe send a blank email to xxxxx@lists.osr.com