Linux 2.6.35上的用户模式中ARM v7处理器缓存的清除和无效

Ale*_*nyk 9 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));           \
    }
    
    Run Code Online (Sandbox Code Playgroud)

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

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

Run*_*une 9

我自己也有类似的问题.__clear_cache()有效,但仅当使用设置了PROT_EXEC的mmap()分配了相关的内存区域时.如果你为它提供来自常规malloc()ed内存的内存范围,Linux将不会刷新指令缓存,即使处理器似乎乐于从malloc()ed内存执行代码.

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