mprotect 是否刷新 ARM Linux 上的指令缓存? [英] Does mprotect flush the instruction cache on ARM Linux?

查看:24
本文介绍了mprotect 是否刷新 ARM Linux 上的指令缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 ARM Linux 上编写一个 JIT,它执行一个包含自修改代码的指令集.指令集没有任何缓存刷新指令(在这方面类似于 x86).

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).

如果我向一个页面写出一些代码,然后在该页面上调用 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 确实在 mprotect 之后调用了 cacheflush,这意味着某些环境需要缓存冲洗(或以前有).我猜测这是一个错误的解决方法.

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 的调用;虽然它是额外的代码,但它不应该是有害的——最坏的情况是,缓存已经被刷新了.你总是可以编写一个快速测试,看看会发生什么......

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆