Reputation: 33
What I would like to do is mark a specific area of memory as being automatically shared between processes of the same image/binary, similar to __declspec(allocate)... and __pragma(section...).
I know that I can use names pipes or equivalent, but for this purpose I would like to avoid system calls or additional overhead. I'm just unsure if there is any way to inform the NT kernel to map a specific range of pages automatically for each process of an image. I haven't found anything on MSDN, though MSDN doesn't include undocumented functionally (by definition), which I am fine with using.
I also don't see any specific PE section names/flags which would indicate such, though it is possible that I am missing something.
Ed: I've noticed that there is actually a PE section flag IMAGE_SCN_MEM_SHARED, though I need to investigate how it works.
Upvotes: 1
Views: 845
Reputation: 598039
You can use #pragma comment(linker, "/SECTION:.shared,RWS")
and #pragma data_seg(".shared")
to declare things in a shared memory segment (only works in Visual Studio). See Sharing Variables Between Win32 Executables.
Otherwise, if that is not an option for you, the only other way to share memory between processes is to use a Memory Mapped File via CreateFileMapping()
and MapViewOfFile/Ex()
. See Creating Named Shared Memory.
Upvotes: 4