Going through the gcc documentation, I stumbled into the builtin function __builtin___clear_cache
.
— Built-in Function: void __builtin___clear_cache (char *begin, char *end) This function is used to flush the processor's instruction cache for the region of memory between begin inclusive and end exclusive. Some targets require that the instruction cache be flushed, after modifying memory containing code, in order to obtain deterministic behavior.
If the target does not require instruction cache flushes, __builtin___clear_cache has no effect. Otherwise either instructions are emitted in-line to clear the instruction cache or a call to the __clear_cache function in libgcc is made.
I find this interesting, but surprising. In many cases, a large number of the instructions for the current stack is stored in the L1 cache (instruction cache). So it would seem at first glance that this builtin could corrupt significantly the flow of our program, by making it wipe out the next instructions on the stack.
Does this instruction also repopulates the part of the stack that was in the L1 cache?
This seems unlikely. If it does not, then I suppose the onus is on the user to use the right begin
and end
arguments, so as to not corrupt our process. In practice, how could one find what the right begin
and end
to use?