I would like to write a function that runs a copy on a page, without having to change any values on that page. Simple implementation:
void trigger_cow(char* addr){
*addr = *addr;
}
does not work because GCC optimizes the line. If I use volatile,
void trigger_cow(char* addr){
volatile char* vaddr = (volatile char*) addr;
*vaddr = *vaddr;
}
then it works under -O3.
Will this hack work under other compilers or optimization settings?
The description of volatile in most sites that I saw does not seem to describe what happens when you write to a volatile pointer, only what happens when you read it. Thanks!
source
share