mirror of
https://github.com/frida/tinycc
synced 2024-12-26 06:56:49 +03:00
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.
This commit is contained in:
parent
d9dfd9cded
commit
6ed6a36a51
@ -689,3 +689,14 @@ void __va_end(struct __va_list_struct *ap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __x86_64__ */
|
#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
|
||||||
|
1
tccrun.c
1
tccrun.c
@ -225,6 +225,7 @@ static void set_pages_executable(void *ptr, unsigned long length)
|
|||||||
end = (addr_t)ptr + length;
|
end = (addr_t)ptr + length;
|
||||||
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
|
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
|
||||||
mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
|
mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||||
|
__clear_cache(ptr, prog_main + length);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user