Quantcast
Viewing all articles
Browse latest Browse all 168

When exactly is FlushInstructionCache needed?

I know that it's supposed to be used, whenever you use self-modifying code, as it's likely that code that has already been run will be stored in the CPU's instruction cache. The first time code gets executed, the CPU stores that code in its instruction cache, for faster execution later (if the function containing the code is executed again). But what about code that has not yet been executed? Lets say in your program you have a placeholder for code to go, that does not get executed at all. Then after the intended code is written to that memory location it is executed. That way, it won't be run, not even once, until the intended code has been written to it. Does that guaranty that the old code does not get cached (the code hasn't been executed yet), or does Windows's process of loading an EXE file into memory also cause all of that EXE file's code to be cached by the CPU?

If I'm using a placeholder for code, and then write that code to the placeholder, before executing it, do I still need to call FlushInstructionCache? Or can I avoid using it in a situation where the CPU should not have cached the instructions (the code hasn't even been executed yet) prior to writing the intended code to that memory location?

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>