Content deleted Content added
Guy Harris (talk | contribs) →Interaction of cache and self-modifying code: It's not just some ARM and MIPS cores where that's an issue; HyperSPARC, for example, also had that issue. |
Michaelmalak (talk | contribs) WL |
||
Line 150:
===Operating systems===
The [[Linux kernel]] notably makes wide use of self-modifying code; it does so to be able to distribute a single binary image for each major architecture (e.g. x86, x86-64, [[ARM architecture family|ARM]]...) while adapting the kernel code in memory during boot depending on the specific CPU model detected, e.g. to be able to take advantage of new CPU instructions or to work around hardware bugs.<ref name="linux_self_modifying_Paltsev">{{cite web |last1=Paltsev |first1=Evgeniy |title=Self Modifying Code in Linux Kernel - What, Where and How |url=https://talk.telematika.org/2019/all/self_modifying_code_in_linux_kernel_-_what_where_and_how/ |access-date=27 November 2022}}</ref><ref name="linux_self_modifying_altinstructions">{{cite web |last1=Wieczorkiewicz |first1=Pawel |title=Linux Kernel Alternatives |url=https://grsecurity.net/linux_kernel_alternatives |access-date=27 November 2022}}</ref>
Regardless, at a [[meta-level]], programs can still modify their own behavior by changing data stored elsewhere (see [[metaprogramming]]) or via use of [[type polymorphism|polymorphism]].
Line 162:
==Interaction of cache and self-modifying code==
On architectures without coupled data and instruction cache (for example, some [[SPARC]], ARM, and [[MIPS architecture|MIPS]] cores) the cache synchronization must be explicitly performed by the modifying code (flush data cache and invalidate instruction cache for the modified memory area).
In some cases short sections of self-modifying code execute more slowly on modern processors. This is because a modern processor will usually try to keep blocks of code in its cache memory. Each time the program rewrites a part of itself, the rewritten part must be loaded into the cache again, which results in a slight delay, if the modified [[codelet]] shares the same cache line with the modifying code, as is the case when the modified memory address is located within a few bytes to the one of the modifying code.
|