是否mprotect的刷新ARM Linux上的指令缓存? [英] Does mprotect flush the instruction cache on ARM Linux?
问题描述
我写ARM Linux上的一个JIT的执行包含自修改code的指令集。该指令集没有任何高速缓存清理指令(类似于86在这方面)。
I am writing a JIT on ARM Linux that executes an instruction set that contains self-modifying code. The instruction set does not have any cache flush instructions (similar to x86 in that respect).
如果我写了一些code到一个页面,然后调用则mprotect
在该网页上,是足以指令缓存失效?或者,我还需要使用 cacheflush
系统调用在这些网页?
If I write out some code to a page and then call mprotect
on that page, is that sufficient to invalidate the instruction cache? Or do I also need to use the cacheflush
syscall on those pages?
推荐答案
您所期望的MMAP / mprotect的系统调用将建立立即更新映射,并且不需要进一步的交互使用所指定的内存范围。我看到,在内核上不确实的mprotect刷新缓存。在这种情况下,将不需要高速缓存刷新。
You'd expect that the mmap/mprotect syscalls would establish mappings that are updated immediately, and need no further interaction to use the memory ranges as specified. I see that the kernel does indeed flush caches on mprotect. In that case, no cache flush would be required.
然而,我也看到libc中的一些版本的叫 cacheflush
在则mprotect
,这将意味着某些环境中需要刷新高速缓存(或有previously)。我会采取一种猜测,这是一个解决方法的错误。
However, I also see that some versions of libc do call cacheflush
after mprotect
, which would imply that some environments would need the caches flushed (or have previously). I'd take a guess that this is a workaround to a bug.
您可以随时添加调用cacheflush;虽然它的额外的code,它不应该是有害的 - 在最坏情况下,缓存就已经被刷新。你总是可以写一个简单的测试,看看会发生什么...
You could always add the call to cacheflush; although it's extra code, it shouldn't be to harmful - at worst, the caches will already be flushed. You could always write a quick test and see what happens...
这篇关于是否mprotect的刷新ARM Linux上的指令缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!