Reputation: 4573
Are ReadProcessMemory()
and WriteProcessMemory()
atomic when reading/writing a machine-word (32 bits under 32-bit mode and 64 bits for 64-bit mode) from/to properly aligned memory location?
PS. There is a tag 'readprocessmemory' available in SO, but no tag 'writeprocessmemory'. Perhaps it should be created by someone with enough rights?
Upvotes: 1
Views: 533
Reputation: 26171
If MSDN doesn't state that they provide atomicity on aligned machine-word reads & writes (which it doesn't), then they don't; even if they underlying implementation does, either through HW or software mechanisms you cannot rely on this, this is especially true for code that my be in the I-cache and must be flushed with FlushInstructionCache
.
If you want an atomic read/write, you need to use one explicitly, in conjunction with VirtualProtect
and possibly some additional tricks if you are writing outside your own address space (ie: into a debuggees address space).
Upvotes: 2