Hi,
I am testing some codes protection mechanism with my application by altering the shared library and restore it after the .so is loaded.
Although the application will alway run without error on my x86_64 Ubuntu, it will fail 2 out of 5 times on the Tx1, reporting either “segment fault” or “invalid instruction”.
Basically, when I found the segment of my .so before entering main(), I do this:
if(0 != mprotect(void* address, size, PROT_READ | PROT_WRITE | PROT_EXEC){
perror(" 1:“):
}
/restore the codes in address/
if(0 != mprotect(void* address, size, PROT_READ | PROT_EXEC){
perror(” 2 :"):
}
I am wondering if this is due to cache incoherence? How can I fix this?
PS: if I add a delay, i.e.usleep(50000),before calling the function in .so, then segment fault issue is gone.