Flush caches before -running program

On some architectures, ARM for instance, the data and instruction caches
are not coherent with each other. This is a problem for the -run feature
since instructions are written in memory, and are thus written in the
data cache first and then later flushed to the main memory. If the
instructions are executed before they are pushed out of the cache, then
the processor will fetch the old content from the memory and not the
newly generated code. The solution is to flush from the data cache all
the data in the memory region containing the instructions and to
invalidate the same region in the instruction cache.
master
Thomas Preud'homme 2013-02-28 16:40:18 +01:00
parent d9dfd9cded
commit 6ed6a36a51
2 changed files with 12 additions and 0 deletions

View File

@ -689,3 +689,14 @@ void __va_end(struct __va_list_struct *ap)
}
#endif /* __x86_64__ */
/* Flushing for tccrun */
#if defined(__x86_64__) || defined(__i386__)
void __clear_cache(char *beginning, char *end)
{
}
#else
#warning __clear_cache not defined for this architecture, avoid using tcc -run
#endif

View File

@ -225,6 +225,7 @@ static void set_pages_executable(void *ptr, unsigned long length)
end = (addr_t)ptr + length;
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
__clear_cache(ptr, prog_main + length);
#endif
}