In Linux or other modern OS, each process’s memory is protected, so that a wild write in one process does not crash any other process. Now assume we have memory shared between process A and process B. Now say, due to a soft error, process A unintentionally writes something to that memory area. Is there any way to protect against this, given that both process A and process B have full write access to that memory?
Share
When you call
shm_openyou can pass it theO_RDONLYflag to the mode parameter.Alternatively you can use
mprotectto mark specific pages as (e.g.) read-only. You’ll need cooperation and trust between the two processes to do this, there is no way for B to say A can’t write to it usingmprotect.If you really want to be sure that the other process can’t interfere then communicating via pipes or sockets of some description might be a sensible idea.
You could also use
mmapto map a something (e.g. in/dev/shm?) the file permissions make impossible to write to for one of the two processes if they’re running as separate UIDs. For example if you have/dev/shm/myprocessowned by user producer and group consumer and set the file permissions to 0640 before mapping it by a process running with that UID and GID then you could prevent the second process from writing to it.