We had a discussion on how to ensure that data in some shared (untrusted) memory region is only accessed once, copied to local memory, and then checked and processed from there. Environment is an embedded multicore µC with shared RAM for IPC, code is written in C99.
Currently, we basically do Type local_copy = *(Type*)shared_memory_pointer; and then only operate on local_copy afterwards.
Now a colleague brought up the question, whether the compiler was allowed to not perform the copy into local memory and instead access the data at shared_memory_pointer directly in the following, which (in theory) would allow for manipulation of the data while it is used.
Is it possible that a compiler does that? If so, how can we make sure that it does not happen? If not, please explain the details.
Thanks all!
Edit: there is no OS on the core in question, it is a bare-metal system.