linux - 如何在 Linux 2.6.35 上从用户模式清除和使 ARM v7 处理器缓存失效

标签 linux arm

我尝试为指令行清除和使 ARM v7 处理器缓存无效,因为指令代码可能会在执行过程中发生变化。

为了达到效果,我尝试了两种变体。他们在这里:

  1. 我使用了 GCC __clear_cache() 函数,但它没有给出所需的结果。缓存中的指令代码没有改变。

  2. 我查找了 GCC 的源代码并找到了 uclinux-eabi.h 文件,我在其中找到了下一个用于清除缓存的代码:

    /* Clear the instruction cache from `beg' to `end'.  This makes an
       inline system call to SYS_cacheflush.  */
    #undef CLEAR_INSN_CACHE
    #define CLEAR_INSN_CACHE(BEG, END)                                    \
    {                                                                     \
        register unsigned long _beg __asm ("a1") = (unsigned long) (BEG); \
        register unsigned long _end __asm ("a2") = (unsigned long) (END); \
        register unsigned long _flg __asm ("a3") = 0;                     \
        register unsigned long _scno __asm ("r7") = 0xf0002;              \
        __asm __volatile                                                  \
        (                                                                 \
            "swi 0x0    @ sys_cacheflush"                                 \
            : "=r" (_beg)                                                 \
            : "0" (_beg), "r" (_end), "r" (_flg), "r" (_scno));           \
    }
    

这个变体也没有给出结果。

也许有人知道我做错了什么?

最佳答案

我自己也遇到过类似的问题。 __clear_cache() 有效,但前提是所讨论的内存区域是使用设置了 PROT_EXEC 的 mmap() 分配的。如果您为其提供来自常规 malloc() 内存的内存范围,Linux 将不会刷新指令缓存,即使处理器似乎很乐​​意从 malloc() 内存中执行代码。

参见 https://community.arm.com/groups/processors/blog/2010/02/17/caches-and-self-modifying-code例如有关如何执行此操作的代码。

关于linux - 如何在 Linux 2.6.35 上从用户模式清除和使 ARM v7 处理器缓存失效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6046716/

相关文章:

linux - 如果未设置环境变量,如何记录?

C#/Mono - 内存映射文件问题

c - 静态可执行文件编译错误: undefined reference to

performance - ARM NEON : Tools to predict performance issues due to memory access limited bandwidth?

linux - gem5 构建失败, "error: ' printPFflags' was not declared in this scope”

c - While 循环占用大量 CPU

linux - 排序命令在 linux 终端中以无序顺序打印

C 文件描述符、轮询和线程

C 调试宏 : error: expected expression

Cortex R5 - 启动代码